-
Notifications
You must be signed in to change notification settings - Fork 0
/
warehouse.cpp
258 lines (227 loc) · 8.96 KB
/
warehouse.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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
#include "warehouse.h"
#include "connectDB.h"
#include "newproduct.h"
#include "adding.h"
#include "collecting.h"
#include "setlanguage.h"
#include <QApplication>
#include <qobject.h>
#include <QItemSelectionModel>
#include <QSettings>
#include <QShortcut>
#include <QtWidgets>
#include <QDateTime>
connectDB CDB;
QSqlTableModel model;
QModelIndexList indexes;
QTranslator translator;
QLabel *label;
QTableView *view;
QModelIndex index;
QLabel *dates_in;
QLabel *dates_out;
QItemSelectionModel *selected;
QModelIndex *m_in;
QLineEdit *searchWord;
QString d1,d2,d3,d4,d5,d6;
QSettings settings("MySoft", "baza");
char i=0;
int inr=0;
int k=0;
int id;
char lan=0;
warehouse::warehouse(const QString &tableName, QWidget *parent) : QWidget(parent)
{
model = new QSqlTableModel(this);
model->setTable(tableName);
model->setEditStrategy(QSqlTableModel::OnFieldChange);
model->select();
model->setHeaderData(2, Qt::Horizontal, tr("quantiny"));
model->setHeaderData(3, Qt::Horizontal, tr("name"));
model->setHeaderData(4, Qt::Horizontal, tr("group1"));
model->setHeaderData(5, Qt::Horizontal, tr("group2"));
model->setHeaderData(6, Qt::Horizontal, tr("place"));
model->setHeaderData(7, Qt::Horizontal, tr("condition"));
view = new QTableView;
view->setModel(model);
view->hideColumn(0);
view->hideColumn(8);
view->hideColumn(9);
view->hideColumn(10);
view->hideColumn(11);
view->hideColumn(12);
view->hideColumn(13);
view->setSortingEnabled(TRUE);
view->setEditTriggers(QAbstractItemView::NoEditTriggers);
view->setSelectionBehavior(QAbstractItemView::SelectRows);
view->selectRow(0);
view->setColumnWidth(7, settings.value("view/c7",view->width()/5).toInt());
view->setColumnWidth(6, settings.value("view/c6",view->width()/4).toInt());
view->setColumnWidth(5, settings.value("view/c5",view->width()/3).toInt());
view->setColumnWidth(4, settings.value("view/c4",view->width()/3).toInt());
view->setColumnWidth(3, settings.value("view/c3",view->width()/2).toInt());
view->setColumnWidth(2, settings.value("view/c2",view->width()/5).toInt());
view->setColumnWidth(1, settings.value("view/c1",view->width()/6).toInt());
QHeaderView *headerview = view->horizontalHeader();
QItemSelectionModel *select = view->selectionModel();
QPushButton *add_new = new QPushButton(tr(" add new "), this);
QPushButton *add = new QPushButton(tr(" add "), this);
QPushButton *minus = new QPushButton(tr(" minus "), this);//remove one piece of item only
QPushButton *collect = new QPushButton(tr(" collect "), this);//remove more
QPushButton *searchButton = new QPushButton(tr(" search "), this);
buttonBox = new QDialogButtonBox(Qt::Horizontal);
buttonBox->addButton(add_new, QDialogButtonBox::ActionRole);
buttonBox->addButton(add, QDialogButtonBox::ActionRole);
buttonBox->addButton(minus, QDialogButtonBox::ActionRole);
buttonBox->addButton(collect, QDialogButtonBox::ActionRole);
QShortcut *shortcutN = new QShortcut(QKeySequence("N"),this);
QShortcut *shortcutA = new QShortcut(QKeySequence("A"),this);
QShortcut *shortcutC = new QShortcut(QKeySequence("C"),this);
QShortcut *shortcutM = new QShortcut(QKeySequence("M"),this);
QShortcut *shortcutReturn = new QShortcut(QKeySequence(Qt::Key_Return),this);//Enter button
QShortcut *shortcutEnter = new QShortcut(QKeySequence(Qt::Key_Enter),this);
QShortcut *shortcutEsc = new QShortcut(QKeySequence(Qt::Key_Escape),this);
QShortcut *shortcutL = new QShortcut(QKeySequence(Qt::Key_L),this);
connect(shortcutN, SIGNAL(activated()), this, SLOT(new_product()));
connect(shortcutA, SIGNAL(activated()), this, SLOT(add()));
connect(shortcutC, SIGNAL(activated()), this, SLOT(min_more()));
connect(shortcutM, SIGNAL(activated()), this, SLOT(min()));
connect(shortcutEnter, SIGNAL(activated()), this, SLOT(search()));
connect(shortcutReturn, SIGNAL(activated()), this, SLOT(search()));
connect(shortcutEsc, SIGNAL(activated()), this, SLOT(CancelSearch()));
connect(shortcutL, SIGNAL(activated()), this, SLOT(slotLanguageChanged()));
connect(add_new, SIGNAL(clicked()), this, SLOT(new_product()));
connect(add, SIGNAL(clicked()), this, SLOT(add()));
connect(minus, SIGNAL(clicked()), this, SLOT(min()));
connect(collect, SIGNAL(clicked()), this, SLOT(min_more()));
connect(searchButton, SIGNAL(clicked()), this, SLOT(search()));
connect(view, SIGNAL(clicked(const QModelIndex&)), this, SLOT(recordSelected()));
connect(headerview, SIGNAL(sectionResized(int,int,int)),this, SLOT(column_change()));
connect(select, SIGNAL(selectionChanged(QItemSelection,QItemSelection)), this, SLOT(recordSelected()));
searchWord = new QLineEdit;
QHBoxLayout *top= new QHBoxLayout;
top->addWidget(buttonBox,0,Qt::AlignLeft);
top->addWidget(searchWord);
top->addWidget(searchButton);
QHBoxLayout *dates= new QHBoxLayout;
dates_in = new QLabel;
dates_out = new QLabel;
dates->addWidget(dates_in);
dates->addWidget(dates_out);
label= new QLabel;
label->setText(" ");
label->setStyleSheet("QLabel { color : red; }");
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(top);
mainLayout->addWidget(view);
mainLayout->addLayout(dates);
mainLayout->addWidget(label);
setLayout(mainLayout);
showMaximized();
translator.load(QString("baza_") + settings.value("language","en").toString());
qApp->installTranslator(&translator);
setWindowTitle(tr("warehouse"));
}
void warehouse::recordSelected()
{
index = view->currentIndex();
QSqlRecord record;
k = index.row();
label->setText(tr(""));
inr=view->model()->data(view->model()->index(k,0)).toInt();
d1=view->model()->data(view->model()->index(k,8)).toString();
d2=view->model()->data(view->model()->index(k,9)).toString();
d3=view->model()->data(view->model()->index(k,10)).toString();
d4=view->model()->data(view->model()->index(k,11)).toString();
d5=view->model()->data(view->model()->index(k,12)).toString();
d6=view->model()->data(view->model()->index(k,13)).toString();
dates_in->setText(tr("added:")+" \n"+d1+"\n"+d2+"\n"+d3);
dates_out->setText(tr("collected:")+" \n"+d4+"\n"+d5+"\n"+d6);
}
void warehouse::column_change()
{
settings.setValue("view/c1",view->columnWidth(1));
settings.setValue("view/c2",view->columnWidth(2));
settings.setValue("view/c3",view->columnWidth(3));
settings.setValue("view/c4",view->columnWidth(4));
settings.setValue("view/c5",view->columnWidth(5));
settings.setValue("view/c6",view->columnWidth(6));
settings.setValue("view/c7",view->columnWidth(7));
}
void warehouse::new_product()
{
newproduct *nw;
nw = new newproduct;
nw->exec();
if(nw->accepted)
{
id = settings.value("id",48).toInt();
id++;
settings.setValue("id",id);
settings.sync();
nw->datein1=QDateTime::currentDateTime().toString("hh:mm:ss dd.MM.yyyy");
CDB.add_product(id,nw->PLU,nw->quantiny,nw->name,nw->group1,
nw->group2,nw->place,nw->condition,nw->datein1,
nw->datein2,nw->datein3,nw->dateout1,
nw->dateout2,nw->dateout3);
upd();
label->setText(tr("added new product!"));
}
}
void warehouse::min()
{
CDB.manipulate(inr,0,1,QDateTime::currentDateTime().toString("hh:mm:ss dd.MM.yyyy"));
upd();
label->setText(tr("collected!"));
}
void warehouse::add()
{
adding dod(view->model()->data(view->model()->index(k,3)).toString());
dod.exec();
if(dod.new_amount==0)return;
CDB.manipulate(inr,dod.new_amount,0,QDateTime::currentDateTime().toString("hh:mm:ss dd.MM.yyyy"));
upd();
label->setText(tr("added!"));
}
void warehouse::min_more()
{
collecting od(view->model()->data(view->model()->index(k,3)).toString());
od.exec();
if(od.new_amount==0&&od.everything==0)return;
if(od.everything)
CDB.manipulate(inr,1,1,QDateTime::currentDateTime().toString("hh:mm:ss dd.MM.yyyy"));
else
CDB.manipulate(inr,0,od.new_amount,QDateTime::currentDateTime().toString("hh:mm:ss dd.MM.yyyy"));
upd();
label->setText(tr("collected!"));
}
void warehouse::CancelSearch()
{
searchWord->setText("");
search();
}
void warehouse::search()
{
model->setFilter( QString("nazwa LIKE '%%1%' "
"OR PLU LIKE '%%1%' "
"OR quantiny LIKE '%%1%' "
"OR miejsce LIKE '%%1%' "
"OR grupa1 LIKE '%%1%' "
"OR grupa2 LIKE '%%1%' ").arg( searchWord->text() ));
}
void warehouse::upd()
{
model->select();
view->setModel(model);
view->setFocus();
view->selectRow(k);
model->submit();
}
void warehouse::slotLanguageChanged()
{
SetLanguage *sl;
sl= new SetLanguage;
sl->exec();
settings.setValue("language",sl->cl);
label->setText(tr("language changed to ")+" "+sl->cl);
}