FixedAdding #1

Merged
danylo_nevidomiy merged 33 commits from FixedAdding into main 2025-02-12 21:46:46 +03:00
3 changed files with 91 additions and 68 deletions
Showing only changes of commit 32a8b2f164 - Show all commits

View File

@ -24,7 +24,7 @@ MainWindow::MainWindow(QWidget *parent)
connect(dial,SIGNAL(sendText(Record*)),this,SLOT(addRecordSlot(Record*)));
connect(del, SIGNAL(trueDelete()), this, SLOT(acceptDelete()));
crypto = new SimpleCrypt(Q_UINT64_C(0x0c2ad4a4acb9f023));
// createModel();
// createModel();
ui->tableViewRecords->setEnabled(true);
ui->tableViewRecords->setVisible(true);
}
@ -63,9 +63,9 @@ bool MainWindow::initAppWithDatabaseFile(const QString &dbFileFullPath, const QS
}
connectToDatabase(dbFileFullPath);
if(isCreationNeed)
{
createDatabase(dbFileFullPath, password);
}
{
createDatabase(dbFileFullPath, password);
}
createModel();
return true;
// setUserInterfaceEnabled(true);
@ -104,8 +104,8 @@ void MainWindow::putRecord(Record* record){
Record* MainWindow::getRecord(int index)
{
QVariant x = model->record(index-1).value(0);
int id;
id = x.toInt();
int id;
id = x.toInt();
query->prepare("SELECT * FROM records WHERE id = (:id)");
query->bindValue(":id", id);
query->exec();
@ -135,17 +135,31 @@ Record* MainWindow::getRecord(int index)
}
void MainWindow::updateRecord(Record* r)
{
// query->prepare("UPDATE records SET name=:name WHERE id=:id");
// query->prepare("UPDATE records SET username=:username WHERE id=:id");
// query->prepare("UPDATE records SET password=:password WHERE id=:id");
// query->prepare("UPDATE records SET url=:url WHERE id=:id");
// query->prepare("UPDATE records SET note=:note WHERE id=:id");
// query->bindValue(":id", r->getId());
// query->bindValue(":name", r->getName());
// query->bindValue(":username", r->getUsername());
// query->bindValue(":password", r->getPassword());
// query->bindValue(":url", r->getURL());
// query->bindValue(":note", r->getNote());
int num = ui->tableViewRecords->currentIndex().row();
QVariant x = model->record(num).value(0);
int id;
id = x.toInt();
query->clear();
query->prepare("UPDATE records SET name=:name, username=:username, password=:password, url=:url, note=:note WHERE id=:id");
query->bindValue(":id", id);
query->bindValue(":name", r->getName());
// query->exec();
// query->prepare("UPDATE records SET username=:username WHERE id=:id");
// query->bindValue(":id", id);
query->bindValue(":username", r->getUsername());
// query->exec();
// query->prepare("UPDATE records SET password=:password WHERE id=:id");
// query->bindValue(":id", id);
query->bindValue(":password", crypto->encryptToString(r->getPassword()));
// query->exec();
// query->prepare("UPDATE records SET url=:url WHERE id=:id");
// query->bindValue(":id", id);
query->bindValue(":url", r->getURL());
// query->exec();
// query->prepare("UPDATE records SET note=:note WHERE id=:id");
// query->bindValue(":id", id);
query->bindValue(":note", r->getNote());
qDebug() << query->exec();
}
void MainWindow::deleteRecord()
{
@ -173,11 +187,11 @@ int MainWindow::getRecordsCount(){
int cur = max;
while(query->next())
{
cur = query->value(rec.indexOf("id")).toInt();
if(max < cur)
{
max = cur;
}
cur = query->value(rec.indexOf("id")).toInt();
if(max < cur)
{
max = cur;
}
}
qDebug() << "max" << max;
return max;
@ -194,34 +208,34 @@ void MainWindow::connectToDatabase(const QString &dbName)
void MainWindow::createDatabase(const QString &dbName, const QString &password)
{
qDebug() << "В базе не существует таблица records!";
qDebug() << "В базе не существует таблица records!";
query->clear(); // очистка запроса.
// id
// name
// username
// URL
// Note
// Time
qDebug() << "Создание таблицы records:" <<
query->exec("CREATE TABLE records(" \
" id TEXT PRIMARY KEY NOT NULL, /* идентификатор */" \
" name TEXT, /* имя */" \
" username TEXT, /* имя пользователя */" \
" password TEXT, /* пароль */" \
" url TEXT, /* web url */" \
" note TEXT, /* примечания */" \
" time INTEGER /* дата добавления */" \
");"); // исполнение запроса на добавление записи.
query->clear(); // очистка запроса.
// id
// name
// username
// URL
// Note
// Time
qDebug() << "Создание таблицы records:" <<
query->exec("CREATE TABLE records(" \
" id TEXT PRIMARY KEY NOT NULL, /* идентификатор */" \
" name TEXT, /* имя */" \
" username TEXT, /* имя пользователя */" \
" password TEXT, /* пароль */" \
" url TEXT, /* web url */" \
" note TEXT, /* примечания */" \
" time INTEGER /* дата добавления */" \
");"); // исполнение запроса на добавление записи.
delete crypto;
crypto = new SimpleCrypt(convertPassword(password));
query->exec("CREATE TABLE keys(id TEXT PRIMARY KEY NOT NULL, word TEXT);");
query->prepare("INSERT INTO keys(id, word)" \
"VALUES(:id, :word)");
query->bindValue(":id", 0);
query->bindValue(":word", crypto->encryptToString(QString::fromStdString((checkpoint))));
query->exec();
delete crypto;
crypto = new SimpleCrypt(convertPassword(password));
query->exec("CREATE TABLE keys(id TEXT PRIMARY KEY NOT NULL, word TEXT);");
query->prepare("INSERT INTO keys(id, word)" \
"VALUES(:id, :word)");
query->bindValue(":id", 0);
query->bindValue(":word", crypto->encryptToString(QString::fromStdString((checkpoint))));
query->exec();
}
bool MainWindow::checkPassoword(QString word)
@ -242,25 +256,25 @@ 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;
}
// Метод показывающий диалоговое окно для выбора файла для новой базы данных:
void MainWindow::on_actionCreateNewDatabase_triggered()
{
// std::cout << "clicked" << std::endl;
// QString dbFileFullPath = QFileDialog::getSaveFileName(this, tr("Save SQLite Database File"), "", MainWindow::fileDialogFilterString);
// initAppWithDatabaseFile(dbFileFullPath);
// model->select();
// std::cout << "clicked" << std::endl;
// QString dbFileFullPath = QFileDialog::getSaveFileName(this, tr("Save SQLite Database File"), "", MainWindow::fileDialogFilterString);
// initAppWithDatabaseFile(dbFileFullPath);
// model->select();
}
// Метод показывающий диалоговое окно для выбора файла для открытия созданной ранее базы данных:
void MainWindow::on_actionOpenDatabase_triggered()
{
// QString dbFileFullPath = QFileDialog::getOpenFileName(this, tr("Open SQLite Database File"), "", MainWindow::fileDialogFilterString);
// initAppWithDatabaseFile(dbFileFullPath);
// model->select();
// QString dbFileFullPath = QFileDialog::getOpenFileName(this, tr("Open SQLite Database File"), "", MainWindow::fileDialogFilterString);
// initAppWithDatabaseFile(dbFileFullPath);
// model->select();
}
@ -361,7 +375,7 @@ void MainWindow::addRecordSlot(Record *r)
// qDebug() << "id: " << getRecordsCount();
qDebug() << "id here:";
// r->setId(ui->tableViewRecords->model()->rowCount() + 1);
// r->setId(ui->tableViewRecords->model()->rowCount() + 1);
// r->setId(ui->tableViewRecords->selectionModel()->selection().indexes().at(0).row());
qDebug() << "id here:";
r->setId(getRecordsCount()+1);
@ -421,6 +435,15 @@ void MainWindow::on_pushButton_4_clicked()
void MainWindow::on_pushButton_6_clicked()
{
Record* r = new Record();
r->setName(ui->lineEdit_name->text());
r->setUsername(ui->lineEdit_username->text());
r->setPassword(ui->lineEdit_password->text());
r->setURL(ui->lineEdit_url->text());
r->setNote(ui->lineEdit_note->text());
qDebug() << "updating initramfs...";
updateRecord(r);
model->select();
ui->stackedWidget->setCurrentIndex(0);
}
@ -431,11 +454,11 @@ void MainWindow::on_addCard_clicked()
}
void MainWindow::on_pushButton_13_clicked()
{
std::cout << "addc" << std::endl;
addc.show();
}
//void MainWindow::on_pushButton_13_clicked()
//{
// std::cout << "addc" << std::endl;
// addc.show();
//}
void MainWindow::on_PW_Button_clicked()
{
@ -451,12 +474,12 @@ void MainWindow::on_CardButton_clicked()
void MainWindow::on_pushButton_3_clicked()
{
qDebug() << "filtering...";
// model->setFilter(QString("USERNAME="+ ui->lineEdit_7->text() +"OR PASSWORD="+ ui->lineEdit_7->text()));
// model->setFilter(QString("USERNAME="+ ui->lineEdit_7->text() +"OR PASSWORD="+ ui->lineEdit_7->text()));
QString f = QString("name LIKE '%");
f+= ui->lineEdit_7->text() + QString("%'");
f+= ui->lineEdit_7->text() + QString("%'") + QString(" OR username LIKE '%") + ui->lineEdit_7->text() + QString("%'");
qDebug() << f;
model->setFilter(f);
model->select();
model->select();
}

View File

@ -93,7 +93,7 @@ private slots:
void on_addCard_clicked();
void on_pushButton_13_clicked();
// void on_pushButton_13_clicked();
void on_PW_Button_clicked();
void on_CardButton_clicked();
void on_pushButton_3_clicked();

View File

@ -31,7 +31,7 @@
<bool>false</bool>
</property>
<property name="currentIndex">
<number>1</number>
<number>0</number>
</property>
<widget class="QWidget" name="page">
<widget class="QTableView" name="tableViewRecords">
@ -960,7 +960,7 @@
<x>0</x>
<y>0</y>
<width>804</width>
<height>22</height>
<height>23</height>
</rect>
</property>
<widget class="QMenu" name="menu">