adding accounts has been fixed

This commit is contained in:
Daniil Neizvestniy 2022-01-08 15:50:31 +03:00
parent 796a3e4dc3
commit 5605e1e333
3 changed files with 21 additions and 23 deletions

View File

@ -71,6 +71,7 @@ void AddDialog::on_pushButton_2_clicked()
void AddDialog::on_pushButton_3_clicked()
{
qDebug() << "addAccount button in dialog clicked";
emit sendText(new Account(ui->nameLine->text(), ui->usernameLine->text(), ui->createPassword->text(), ui->createURL->text(), ui->noteLine->text()));//отправляет сигнал с текстом
//m->putRecord(new Record(ui->nameLine->text(), ui->usernameLine->text(), ui->createPassword->text(), ui->urlLine->text(), ui->noteLine->text()));
ui->nameLine->setText("");

View File

@ -24,12 +24,14 @@ MainWindow::MainWindow(QWidget *parent)
// manager = new Manager();
dial = new AddDialog();
del = new Del();
connect(dial,SIGNAL(sendText(Record*)),this,SLOT(addRecordSlot(Record*)));
connect(dial,SIGNAL(sendText(Account*)),this,SLOT(addRecordSlot(Account*)));
connect(del, SIGNAL(trueDelete()), this, SLOT(acceptDelete()));
crypto = new SimpleCrypt(Q_UINT64_C(0x0c2ad4a4acb9f023));
// createModel();
ui->tableViewRecords->setEnabled(true);
ui->tableViewRecords->setVisible(true);
ui->tableViewCards->setEnabled(true);
ui->tableViewCards->setVisible(true);
}
Ui::MainWindow* MainWindow::getUI()
@ -59,7 +61,7 @@ void MainWindow::createModels()
// recordsCount = ui->tableViewRecords->model()->rowCount();
cardModel = new QSqlTableModel(this, m_db);
cardModel->setTable("credentials");
cardModel->setTable(cards);
cardModel->select();
cardModel->setEditStrategy(QSqlTableModel::OnFieldChange);
ui->tableViewCards->setModel(cardModel);
@ -106,12 +108,14 @@ void MainWindow::putRecord(Record* record){
query->bindValue(":url", account->getURL());
query->bindValue(":note", account->getNote());
query->bindValue(":time", account->getTime());
qDebug() << query->exec();
accountModel->select();
}
else if(typeid (*record) == typeid (Card))
{
Card *card = dynamic_cast<Card*>(record);
q+=cards + "(id, title, number, name, month, year, cvv, pin, time)" \
"VALUES(:id, :title, :number, :name, :month, :year, :cvv, :pin, :time)";
"VALUES(:id, :title, :number, :name, :month, :year, :cvv, :pin, :time)";
query->prepare(q);
query->bindValue(":id", card->getId());
query->bindValue(":title", card->getTitle());
@ -122,18 +126,11 @@ void MainWindow::putRecord(Record* record){
query->bindValue(":cvv", crypto->encryptToString(card->getCVV()));
query->bindValue(":pin", crypto->encryptToString(card->getPIN()));
query->bindValue(":time", card->getTime());
qDebug() << query->exec();
cardModel->select();
}
query->clear();
// qDebug() << "Добавление строки:" <<
// query->prepare("INSERT INTO " + accounts + "(id, name, username, password, url, note, time)" \
// "VALUES(:id, :name, :username, :password, :url, :note, :time)");
// // query->prepare("INSERT INTO employees(id, last_name, first_name, occupation, year_of_admission) " \
// // "VALUES(:id, :last_name, :first_name, :occupation, :year_of_admission)");
query->exec();
accountModel->select();
}
Account* MainWindow::getRecord(int index)
@ -212,14 +209,14 @@ void MainWindow::createDatabase(const QString &dbName, const QString &password)
// Time
qDebug() << "Создание таблицы " + accounts + ":" <<
query->exec("CREATE TABLE " + accounts + "(" \
" id TEXT PRIMARY KEY NOT NULL, /* идентификатор */" \
" name TEXT, /* имя */" \
" username TEXT, /* имя пользователя */" \
" password TEXT, /* пароль */" \
" url TEXT, /* web url */" \
" note TEXT, /* примечания */" \
" time INTEGER /* дата добавления */" \
");"); // исполнение запроса на добавление записи.
" id TEXT PRIMARY KEY NOT NULL, /* идентификатор */" \
" name TEXT, /* имя */" \
" username TEXT, /* имя пользователя */" \
" password TEXT, /* пароль */" \
" url TEXT, /* web url */" \
" note TEXT, /* примечания */" \
" time INTEGER /* дата добавления */" \
");"); // исполнение запроса на добавление записи.
query->clear(); // очистка запроса.
qDebug() << "Создание таблицы credentials:" <<
@ -264,7 +261,7 @@ bool MainWindow::checkPassoword(QString word)
qDebug() << "crypto->decryptToString(check) = " << crypto->decryptToString(check);
if(QString::compare(QString::fromStdString(checkpoint), crypto->decryptToString(check)) == 0)
{
return true;
return true;
}
return false;
}

View File

@ -26,9 +26,9 @@ public:
~MainWindow();
Ui::MainWindow* getUI();
void createModels();
void putRecord(Account* record);
void putRecord(Record* record);
Account* getRecord(int index);
void deleteRecord();
void deleteRecord(int index, QSqlTableModel* model, QString recordType);
int getRecordsCount();
void putCard(Card* card);