/
typedocform.cpp
170 lines (148 loc) · 5.14 KB
/
typedocform.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#include <QtSql>
#include "numprefix.h"
#include "fordelete.h"
#include "typedocform.h"
TypeDocForm::TypeDocForm(QString id, QWidget *parent, bool onlyForRead) :
QDialog(parent)
{
exchangeFile.setFileName("Message.txt");
if(!exchangeFile.isOpen()){
exchangeFile.open(QIODevice::ReadWrite);
}
indexTemp = id;
QFile file(":/ToolButtonStyle.txt");
file.open(QFile::ReadOnly);
//QString styleSheetString = QLatin1String(file.readAll());
labelName = new QLabel(trUtf8("Prichina Obuch:"));
editName = new LineEdit;
editName->setReadOnly(onlyForRead);
QRegExp regExp("[\\x0410-\\x044f 0-9 ()\" -]{150}");
editName->setValidator(new QRegExpValidator(regExp,this));
labelName->setBuddy(editName);
savePushButton = new QPushButton(trUtf8("Save"));
connect(savePushButton,SIGNAL(clicked()),this,SLOT(editRecord()));
savePushButton->setToolTip(trUtf8("Save And Close Button"));
cancelPushButton = new QPushButton(trUtf8("Cancel"));
cancelPushButton->setDefault(true);
cancelPushButton->setStyleSheet("QPushButton:hover {color: red}");
connect(cancelPushButton,SIGNAL(clicked()),this,SLOT(accept()));
cancelPushButton->setToolTip(trUtf8("Cancel Button"));
buttonBox = new QDialogButtonBox;
buttonBox->addButton(cancelPushButton,QDialogButtonBox::ActionRole);
buttonBox->addButton(savePushButton,QDialogButtonBox::ActionRole);
if(indexTemp != ""){
QSqlQuery query;
query.prepare("SELECT typedocname FROM typedoc WHERE typedocid = :typedocid");
query.bindValue(":typedocid",indexTemp);
query.exec();
while(query.next()){
editName->setText(query.value(0).toString());
}
}else{
editName->clear();
}
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addWidget(labelName,0,0);
mainLayout->addWidget(editName,0,1);
if(!onlyForRead){
mainLayout->addWidget(buttonBox,1,1);
editName->selectAll();
}
setLayout(mainLayout);
setWindowTitle(trUtf8("Type doc"));
readSettings();
}
void TypeDocForm::done(int result)
{
writeSettings();
QDialog::done(result);
}
void TypeDocForm::editRecord()
{
QTextStream stream(&exchangeFile);
QString line;
while(!stream.atEnd()){
stream.readLine();
}
if(indexTemp != ""){
QSqlQuery query;
query.prepare("UPDATE typedoc SET "
"typedocname = :typedocname "
"WHERE typedocid = :typedocid");
query.bindValue(":typedocid",indexTemp);
query.bindValue(":typedocname",editName->text().simplified());
query.exec();
if(!query.isActive()){
QMessageBox::warning(this,QObject::trUtf8("Type Doc, UPDATE ERROR!"),query.lastError().text());
return;
}
line += "UPDATE typedoc SET typedocname = '";
line += indexTemp.toUtf8();
line += "' WHERE typedocid = '";
line += editName->text().simplified().toUtf8();
line += "'";
line += "\r\n";
stream<<line;
}else{
NumPrefix numPrefix;
indexTemp = numPrefix.getPrefix("typedoc");
QSqlQuery queryInsert;
queryInsert.prepare("INSERT INTO typedoc ("
"typedocid, "
"typedocname"
") VALUES(:id, "
":name"
");");
queryInsert.bindValue(":id",indexTemp);
queryInsert.bindValue(":name",editName->text().simplified());
queryInsert.exec();
if(!queryInsert.isActive()){
QMessageBox::warning(this,QObject::trUtf8("Type Doc, INSERT ERROR!"),queryInsert.lastError().text());
return;
}
line += "INSERT INTO typedoc (typedocid, typedocname) VALUES('";
line += indexTemp.toUtf8();
line += "', '";
line += editName->text().simplified().toUtf8();
line += "')";
line += "\r\n";
stream<<line;
}
emit accept();
close();
}
void TypeDocForm::deleteRecord()
{
QTextStream stream(&exchangeFile);
QString line;
while(!stream.atEnd()){
stream.readLine();
}
ForDelete forDelete(indexTemp,"typedoc",this);
forDelete.exec();
int k = QMessageBox::warning(this,trUtf8("Attention!!!"),trUtf8("Delete item?"),
QMessageBox::No|QMessageBox::Yes,QMessageBox::No);
if(k == QMessageBox::Yes){
forDelete.deleteOnDefault();
QSqlQuery query;
query.prepare("DELETE FROM typedoc WHERE typedocid = :typedocid");
query.bindValue(":typedocid",indexTemp);
query.exec();
query.next();
line += "DELETE FROM typedoc WHERE typedocid = '";
line += indexTemp.toUtf8();
line += "'";
line += "\r\n";
stream<<line;
}
}
void TypeDocForm::readSettings()
{
QSettings settings("AO_Batrakov_Inc.", "EmployeeClient");
restoreGeometry(settings.value("TypeDocForm").toByteArray());
}
void TypeDocForm::writeSettings()
{
QSettings settings("AO_Batrakov_Inc.", "EmployeeClient");
settings.setValue("TypeDocForm", saveGeometry());
}