Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mainwindow.h"
- #include "login.h"
- #include "ui_mainwindow.h"
- #include <QStandardItem>
- MainWindow::MainWindow(QWidget *parent) :
- QMainWindow(parent),
- ui(new Ui::MainWindow)
- {
- Login log_in;
- log_in.exec();
- ui->setupUi(this);
- connect(this->ui->treeWidget,SIGNAL(itemClicked(QTreeWidgetItem*,int)),this,SLOT(MenuItemClicked(QTreeWidgetItem*,int)));
- QTreeWidgetItem *manage = new QTreeWidgetItem(ItemType1);
- manage->setText(0,"Zarzadzaj");
- new_acc = new QTreeWidgetItem(ItemType2);
- new_acc->setText(0,"Dodaj nowe konto");
- del_acc = new QTreeWidgetItem(ItemType2);
- del_acc->setText(0,"Usun konto");
- pass_acc = new QTreeWidgetItem(ItemType2);
- pass_acc->setText(0,"Zmien haslo");
- perm_acc = new QTreeWidgetItem(ItemType2);
- perm_acc->setText(0,"Uprawnienia");
- ui->treeWidget->addTopLevelItem(manage);
- manage->addChild(new_acc);
- manage->addChild(del_acc);
- manage->addChild(pass_acc);
- manage->addChild(perm_acc);
- finder_acc = new QTreeWidgetItem(ItemType2);
- finder_acc->setText(0,"Wyszukaj w bazie danych");
- ui->treeWidget->addTopLevelItem(finder_acc);
- content_add_acc = new content(this);
- ui->container->addWidget(content_add_acc);
- content_chg_pwd = new change_password(this);
- ui->container->addWidget(content_chg_pwd);
- content_del_acc = new change_password(this);
- ui->container->addWidget(content_del_acc);
- content_finder = new find_acc(this);
- ui->container->addWidget(content_finder);
- QObject::connect(content_add_acc, SIGNAL(user_data_changed(bool)), this, SLOT(user_data_changed_reciver(bool)));
- connect(content_chg_pwd, SIGNAL(password_changed()), this, SLOT(password_change_reciver()));
- connect(content_del_acc, SIGNAL(delete_account()), this, SLOT(account_delete_reciver()));
- connect(content_finder, SIGNAL(find_pressed()), this, SLOT(finder_recived()));
- QSqlDatabase db = QSqlDatabase::addDatabase("QODBC");
- db.setHostName("localhost");
- db.setDatabaseName("l2dsn");
- db.setUserName("L2USER");
- db.setPassword("lineage");
- if (!db.open())
- {
- QMessageBox::critical(0, QObject::tr("Database Error"),
- db.lastError().text());
- }
- query = new QSqlQuery();
- //query->exec("select * from Konto");
- model = new QSqlQueryModel() ;
- model->setQuery(*query);
- ui->tableView->setModel(model);
- ui->tableView->resizeColumnsToContents();
- }
- MainWindow::~MainWindow()
- {
- delete query;
- delete model;
- delete ui;
- }
- void MainWindow::MenuItemClicked(QTreeWidgetItem *item, int)
- {
- if(item==new_acc)
- {
- ui->container->setCurrentWidget(content_add_acc);
- }
- if(item==pass_acc)
- {
- ui->container->setCurrentWidget(content_chg_pwd);
- content_chg_pwd->set_tittle_label(QString("Zmień hasło"));
- content_chg_pwd->set_layout_delete_account(false);
- }
- if(item==del_acc)
- {
- ui->container->setCurrentWidget(content_del_acc);
- content_del_acc->set_tittle_label(QString("Usuń konto"));
- content_del_acc->set_layout_delete_account(true);
- }
- if(item==finder_acc)
- {
- ui->container->setCurrentWidget(content_finder);
- }
- }
- void MainWindow::manage_create_user()
- {
- }
- void MainWindow::user_data_changed_reciver(bool flaga)
- {
- if(flaga==true)
- {
- QSqlQueryModel model;
- QSqlQuery query;
- query.prepare("INSERT INTO Konto (ID_KONTO, LOGIN, HASLO, STATUS_DOSTEPU, E_MAIL) "
- "VALUES (SEQ_KONTO.nextval, :LOGIN, :HASLO, :STATUS_DOSTEPU, :E_MAIL)");
- QString temp_login, temp_password, temp_repassword, temp_email, temp_access_level;
- temp_login=content_add_acc->get_login();
- temp_password=content_add_acc->get_password();
- temp_repassword=content_add_acc->get_repassword();
- temp_email=content_add_acc->get_email();
- temp_access_level=content_add_acc->get_access();
- if(temp_password!=temp_repassword)
- {
- set_status_label("Wystapil blad! Podane hasła nie są ze sobą zgodne ",true);
- return;
- }
- query.bindValue( ":LOGIN", temp_login );
- query.bindValue( ":HASLO", temp_password );
- query.bindValue( ":STATUS_DOSTEPU", temp_access_level );
- query.bindValue( ":E_MAIL", temp_email );
- if(!query.exec())
- set_status_label("Wystapil blad: " + query.lastError().text(),true);
- else{
- set_status_label("Uzytkownik dodany pomyslnie",false);
- QSqlQuery recently_added;
- recently_added.prepare("SELECT * FROM KONTO WHERE LOGIN = :PODANY_LOGIN" );
- recently_added.bindValue(":PODANY_LOGIN",temp_login);
- recently_added.exec();
- this->model->setQuery(recently_added);
- ui->tableView->setModel(this->model);
- }
- }
- }
- void MainWindow::password_change_reciver()
- {
- QString temp_login, temp_old_pwd, temp_new_pwd, temp_new_re_pwd;
- temp_login= content_chg_pwd-> get_login();
- temp_old_pwd= content_chg_pwd -> get_oldpassword();
- temp_new_pwd= content_chg_pwd-> get_new_password();
- temp_new_re_pwd=content_chg_pwd-> get_new_repassword();
- if(temp_login.isEmpty() || temp_new_pwd.isEmpty() || temp_new_re_pwd.isEmpty() ||temp_old_pwd.isEmpty())
- {
- set_status_label("Prosze uzupelnic wszystkie pola",true);
- return;
- }
- QSqlQuery query;
- QString user_passowrd;
- query.prepare("SELECT HASLO FROM KONTO WHERE LOGIN = :LOGIN");
- query.bindValue(":LOGIN",temp_login);
- if(!query.exec())
- {
- set_status_label("Blad polaczenia z baza danych",true);
- return;
- }
- query.next();
- user_passowrd=query.value(0).toString();
- qDebug() << user_passowrd;
- //qDebug() << query.lastError();
- if(user_passowrd!=temp_old_pwd)
- {
- set_status_label("Podane haslo jest nieprawidlowe",true);
- return;
- }
- if(temp_new_pwd!=temp_new_re_pwd)
- {
- set_status_label("Upewnij sie ze podane nowe haslo zostalo wprowadzone dwukrotnie identycznie",true);
- return;
- }
- QSqlQuery change_pwd;
- change_pwd.prepare("Update KONTO SET HASLO = :NOWE_HASLO WHERE LOGIN = :LOGIN");
- change_pwd.bindValue(":NOWE_HASLO", temp_new_pwd);
- change_pwd.bindValue(":LOGIN",temp_login);
- if(!change_pwd.exec())
- {
- set_status_label("Nie udalo sie przeprowadzic aktualizacji w bazie danych",true);
- return;
- }
- else
- {
- set_status_label("Haslo zostalo pomyslnie zmienione",false);
- QSqlQuery recently_added;
- recently_added.prepare("SELECT * FROM KONTO WHERE LOGIN = :PODANY_LOGIN" );
- recently_added.bindValue(":PODANY_LOGIN",temp_login);
- recently_added.exec();
- this->model->setQuery(recently_added);
- ui->tableView->setModel(this->model);
- }
- }
- void MainWindow::account_delete_reciver()
- {
- QSqlQuery query;
- QString user_passowrd;
- QString login, password, repassword;
- content_del_acc->set_layout_delete_account(true);
- login= content_del_acc->get_login();
- password=content_del_acc->get_oldpassword();
- repassword = content_del_acc-> get_new_password();
- if ( login.isEmpty() || password.isEmpty() || repassword.isEmpty())
- {
- set_status_label("Prosze uzupelnic wszystkie pola",true);
- return;
- }
- if(password!=repassword)
- if(user_passowrd!=password)
- {
- set_status_label("Podane hasła nie sa ze sobą zgodne",true);
- return;
- }
- query.prepare("SELECT HASLO FROM KONTO WHERE LOGIN = :LOGIN");
- query.bindValue(":LOGIN",login);
- if(!query.exec())
- {
- set_status_label("Zapytanie jest niepoprawne",true);
- return;
- }
- query.next();
- user_passowrd=query.value(0).toString();
- if(user_passowrd!=password)
- {
- set_status_label("Podane hasło jest nieprawidłowe",true);
- return;
- }
- QSqlQuery delete_account;
- delete_account.prepare("DELETE FROM KONTO WHERE LOGIN = :LOGIN AND HASLO = :HASLO");
- delete_account.bindValue(":HASLO", password);
- delete_account.bindValue(":LOGIN",login);
- if(!delete_account.exec())
- {
- set_status_label("Nie udalo sie przeprowadzic aktualizacji w bazie danych",true);
- return;
- }
- else {
- set_status_label("Usunieto konto: " +login,false);
- return;
- }
- }
- void MainWindow::finder_recived()
- {
- int operation=content_finder->get_current_item();
- QString value=content_finder->get_line_value();
- if(value.isEmpty())
- {
- set_status_label("Nazwa wyszukiwanego elementu jest pusta!",true);
- return;
- }
- if(operation==0)
- {
- qDebug() << "Operacja 0: Znajdz konto po numerze id";
- }
- if(operation==1)
- {
- qDebug() << "Operacja 1: Znajdz konto po nazwie gracza";
- }
- if(operation==2)
- {
- qDebug() << "Operacja 2: Znajadz gracza posiadajacego przedmiot";
- }
- if(operation==3)
- {
- qDebug() << "Operacja 3: Znajdz graczy o podanym poziomie uprawnienia";
- }
- if(operation==4)
- {
- qDebug() << "Operacja 4: Znajdz postacie na podanym koncie";
- }
- }
- void MainWindow::set_status_label(QString tresc, bool is_error)
- {
- ui->status_label->setText("Status: " +tresc);
- if(is_error==true)
- {
- ui->status_label->setStyleSheet("QLabel { color : red; }");
- }
- else
- {
- ui->status_label->setStyleSheet("QLabel { color : green; }");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement