-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmainwindow.cpp
1789 lines (1451 loc) · 56.4 KB
/
mainwindow.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
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QMainWindow>
#include <QMessageBox>
#include "addnewitem.h"
#include "addnewequipment.h"
#include "updatecalverdatedlg.h"
#include <qaction.h>
#include "logindlg.h"
#include <QModelIndex>
#include <QFileDialog>
#include "moreinfordlg.h"
#include "main.h"
#include <QStandardItemModel>
#include <QTcpSocket>
#include <QThread>
#include <iostream>
#include "xlsx/xlsxdocument.h"
#include "xlsxformat.h"
#include "xlsxabstractsheet.h"
#include "xlsxworkbook.h"
#include "xlsxworksheet.h"
//#include "./smtp/SmtpMime.h"
#include "smtp/smtpmime.h"
#include "smtp/smtpclient.h"
extern bool RemoteDB;
MainWindow::MainWindow(int userlevel,QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
setCentralWidget(ui->centralWidget);
setIconSize(QSize(64, 64));
//setWindowIcon(QIcon(".\\images\\Title.png"));
setWindowIcon(QIcon(":/images/Title.bmp"));
QMenu *menu = QMainWindow::createPopupMenu();
QList<QAction*> list = menu->actions();
list.at(0)->setText(tr("Display/Hide ToolBar"));
UserLevel = userlevel;
qDebug() << UserLevel;
B_SendMail = false;
QString strMainWindowTitle = tr("Fluke IG Lab Equipments Management ---");
if(UserLevel == 1)// admin: add menu user
{
strMainWindowTitle = strMainWindowTitle + tr(" ---Admin user");
//setWindowTitle("Fluke IG Lab Equipments Management ---Admin user");
}
else if(UserLevel == 3)// R USER, include Guest
{
strMainWindowTitle = strMainWindowTitle + tr(" ---Read only user");
//setWindowTitle("Fluke IG Lab Equipments Management ---Read only user");
//ui->menuUser_Management->setDisabled(true);
ui->actionAdd_New_User->setDisabled(true);
ui->actionDelete_User->setDisabled(true);
ui->actionModify_User_Level->setDisabled(true);
ui->actionView_all_user_info->setDisabled(true);
ui->AddnewEquipment->setDisabled(true);
ui->actionAddNew->setDisabled(true);
ui->actionAdd_new_Equipment->setDisabled(true);
ui->DeleteButton->setDisabled(true);
ui->actionDelete_Equipment->setDisabled(true);
ui->actionDeleteRecord->setDisabled(true);
ui->ModifyButton->setDisabled(true);
ui->actionModify_Ewuipment_information->setDisabled(true);
ui->actionModifyRecord->setDisabled(true);
ui->actionEquipment_lent_Register->setDisabled(true);
ui->actionEquipment_Return_Register->setDisabled(true);
}
else if(UserLevel == 2)// R+W USER
{
strMainWindowTitle = strMainWindowTitle + tr(" ---Read and Write user");
//setWindowTitle("Fluke IG Lab Equipments Management ---Read and Write user");
//ui->menuUser_Management->setDisabled(true);
ui->actionAdd_New_User->setDisabled(true);
ui->actionDelete_User->setDisabled(true);
ui->actionModify_User_Level->setDisabled(true);
}
if(RemoteDB)
{
strMainWindowTitle = strMainWindowTitle + tr(" ---Remote DB");
}
else
{
strMainWindowTitle = strMainWindowTitle + tr(" ---Local DB");
}
setWindowTitle(strMainWindowTitle);
TableModel = new QStandardItemModel;
db = QSqlDatabase::addDatabase("QSQLITE");
if(RemoteDB)
{
QString DBString ="Q:\\Asia\\Shanghai\\workgrps\\Engineering\\public\\test report\\LabEquipmentsDatabase\\Equipments.db";
db.setDatabaseName(DBString);
}
else
{
db.setDatabaseName("Equipments.db"); // 鏁版嵁搴撳悕涓庤矾寰?, 姝ゆ椂鏄斁鍦ㄥ悓鐩綍涓?
}
SQLString_ConsumableMaterial = "select * from ConsumablesMaterial";
SQLString_EquipmentAll = "select EquipmentName,ModelName,IG_SN,Mfg_SN,Caldate,DueDate,Status,Spec_Description,InternalCatergory,CalOrVerify from SummaryTable";
SQLString_EquipmentCAL = "select EquipmentName,ModelName,IG_SN,Mfg_SN,Caldate,DueDate,Status,Spec_Description,InternalCatergory,CalOrVerify from SummaryTable where CalOrVerify = 'CAL'";
SQLString_EquipmentVER = "select EquipmentName,ModelName,IG_SN,Mfg_SN,Caldate,DueDate,Status,Spec_Description,InternalCatergory,CalOrVerify from SummaryTable where CalOrVerify = 'VER'";
SQLString_EquipmentOther = "select EquipmentName,ModelName,IG_SN,Mfg_SN,Caldate,DueDate,Status,Spec_Description,InternalCatergory,CalOrVerify from SummaryTable where CalOrVerify NOT IN('CAL','VER')";
ui->listView->setSpacing(2);
QStringList Equipments;
Equipments += tr("All Equipments");
Equipments += tr("Equipments(Calibration)");
Equipments += tr("Equipments(Verification)");
Listmodel = new QStringListModel(Equipments);
ui->listView->setModel(Listmodel); //useList鏄釜QListView
Equipments += tr("Consumable Materials");
Equipments += tr("Other equipments");
Listmodel->setStringList(Equipments);
QModelIndex listviewindex;
listviewindex = Listmodel->index(0,0,QModelIndex());
//QModelIndex::QModelIndex();
ui->listView->setCurrentIndex(listviewindex);
//---------------------------------------------------------------------------------
// 1. 涓�寮�濮嬫樉绀篴ll equipment鐨則able锛?
dbOpen();
QString SQLString = SQLString_EquipmentAll;
updateData2Tableview(SQLString);
dbClose();
ui->statusBar->showMessage(tr("All equipments were showed on the right table grid."));
ui->mainToolBar->setIconSize(QSize(48,48));
//--------------------------------------------------------------------------------------------------------
// Button
connect(ui->listView,SIGNAL(clicked(const QModelIndex &)),this,SLOT(ListView_itemClicked()));
connect(ui->AddnewEquipment,SIGNAL(clicked()),this,SLOT(Addnew_itemClicked()));
connect(ui->ModifyButton,SIGNAL(clicked()),this,SLOT(Modify_itemClicked()));
connect(ui->DeleteButton,SIGNAL(clicked()),this,SLOT(Delete_Clicked()));
connect(ui->listView,SIGNAL(clicked(const QModelIndex &)),this,SLOT(ListView_itemClicked()));
connect(ui->tableView,SIGNAL(clicked(const QModelIndex &)),this,SLOT(TableView_itemClicked()));
connect(ui->tableView,SIGNAL(doubleClicked(const QModelIndex &)),this,SLOT(Modify_itemClicked()));
connect(ui->UpdateCalVerDate,SIGNAL(clicked()),this,SLOT(UpdateVerCalDate_ButtonClicked()));
connect(ui->pushButton_Search,SIGNAL(clicked()),this,SLOT(Search_ButtonClicked()));
// 閾炬帴QAction--ToolBar
connect(ui->actionAddNew,SIGNAL(triggered()),this,SLOT(Addnew_itemClicked()));
connect(ui->actionModifyRecord,SIGNAL(triggered()),this,SLOT(Modify_itemClicked()));
connect(ui->actionDeleteRecord,SIGNAL(triggered()),this,SLOT(Delete_Clicked()));
connect(ui->actionUpdateDate,SIGNAL(triggered()),this,SLOT(UpdateVerCalDate_ButtonClicked()));
connect(ui->actionSearch,SIGNAL(triggered()),this,SLOT(Search_ButtonClicked()));
connect(ui->actionExporttoExcel,SIGNAL(triggered()),this,SLOT(on_pushButton_Export_clicked()));
connect(ui->actionAbout,SIGNAL(triggered()),this,SLOT(AboutThis()));
connect(ui->actionView_More_information_of_Equipment,SIGNAL(triggered()),this,SLOT(on_pushButton_ViewMoreInfo_clicked()));
// 閾炬帴QAction--menu
connect(ui->actionAdd_new_Equipment,SIGNAL(triggered()),this,SLOT(Addnew_itemClicked()));
connect(ui->actionModify_Ewuipment_information,SIGNAL(triggered()),this,SLOT(Modify_itemClicked()));
connect(ui->actionDelete_Equipment,SIGNAL(triggered()),this,SLOT(Delete_Clicked()));
connect(ui->actionView_Calibration_verificatin_date,SIGNAL(triggered()),this,SLOT(UpdateVerCalDate_ButtonClicked()));
connect(ui->actionAbout_this_Program,SIGNAL(triggered()),this,SLOT(AboutThis()));
connect(ui->actionChinese,SIGNAL(triggered()),this,SLOT(Translate_to_Chinese()));
connect(ui->actionEnglish,SIGNAL(triggered()),this,SLOT(Translate_to_English()));
connect(ui->actionSearch_2,SIGNAL(triggered()),this,SLOT(Search_ButtonClicked()));
connect(ui->actionExport_to_Excel,SIGNAL(triggered()),this,SLOT(on_pushButton_Export_clicked()));
ui->retranslateUi(this);
}
MainWindow::~MainWindow()
{
dbClose();
delete ui;
}
void MainWindow::Translate_to_Chinese()
{
ui->actionEnglish->setChecked(false);
ui->actionChinese->setChecked(true);
QMessageBox::information(this,tr("info"),tr("LANGUAGE: Chinese"));
trans.load(":/translations/IGLabAM_cn.qm");
qApp->installTranslator(&trans);
ui->retranslateUi(this);
}
void MainWindow::Translate_to_English()
{
ui->actionEnglish->setChecked(true);
ui->actionChinese->setChecked(false);
QMessageBox::information(this,"info","LANGUAGE: English");
qApp->removeTranslator(&trans);
ui->retranslateUi(this);
}
void MainWindow::dbOpen()
{
if(!db.open())
{
qDebug("鏁版嵁搴撲笉鑳芥墦寮�");
}
}
void MainWindow::dbClose()
{
if(db.isOpen())
{
db.close();
}
}
void MainWindow::updateData2Tableview(QString SQLString)
{
ui->tableView->setModel(TableModel);//閫氳繃setModel鏉ョ粦瀹氭暟鎹簮
QSqlQuery query(db);
TableModel->clear();
if(query.exec(SQLString))
{
qDebug() << SQLString;
qDebug("SQL exec: successful!");
}
else
{
qDebug("SQL exec: Failed!");
}
int columnNum = query.record().count(); //鑾峰彇姣忔潯璁板綍涓睘鎬э紙鍗冲垪锛夌殑涓暟
//璁剧疆鍒楁暟
TableModel->setColumnCount(columnNum);
//璁剧疆鏍囬
int i = 0,j = 0;
for(i = 0;i < columnNum; i++)
{
TableModel->setHeaderData(i,Qt::Horizontal,query.record().fieldName(i));
}
QStandardItem *item[columnNum];
QList <QStandardItem*>ItemList;
while((bool)query.next())
{ //澧炲姞椤瑰埌妯″瀷
for(i = 0;i < columnNum; i++)
{
item[i] = new QStandardItem(query.value(i).toString());//鍙栧綋鍓嶈褰曠i涓瓧娈?(浠?0寮�濮嬭鏁?)鐨勫唴瀹?
ItemList << item[i];
}
TableModel->appendRow(ItemList);
ItemList.clear();
}
//8.璁剧疆妯″瀷鍒癡iew
ui->tableView->setModel(TableModel);//閫氳繃setModel鏉ョ粦瀹氭暟鎹簮
ui->tableView->resizeColumnsToContents();
ui->tableView->setColumnWidth(8,110);
ui->tableView->setColumnWidth(9,110);
// judge the Duedate
int RowNum = TableModel->rowCount(QModelIndex());
qDebug() << RowNum;
// TableModel->item(0,0)->setBackground(QBrush(QColor(255, 0, 0)));
int tableIndex = ui->listView->currentIndex().row();
if((tableIndex ==0)||(tableIndex ==1)||(tableIndex ==2))
{
QString CellValue;
QDate Duedate,CurDate;
CurDate = QDate::currentDate();
QModelIndex indextemp;
qDebug() << "The Following equipment will overdue the calibration:";
QString txt = "The Following equipment will overdue the calibration:\r\n";
int duedate_Equip_Idx = 0;
for(i = 0;i < RowNum ; i++ )
{
CellValue = TableModel->item(i,9)->data(Qt::DisplayRole).toString();
//qDebug() << CellValue;
if((CellValue == "CAL")||(CellValue == "VER"))
{
//Duedate = TableModel->item(i,5)->data().toDate();
indextemp = TableModel->index(i,5);
Duedate = TableModel->data(indextemp).toDate();
if((Duedate.addDays(30) < CurDate))
{
qDebug() << duedate_Equip_Idx + 1 << ":\t"<< QString(TableModel->item(i,2)->data(Qt::DisplayRole).toString()) <<"\t"<< TableModel->item(i,1)->data(Qt::DisplayRole).toString() <<"\t\t"<< "Duedate:" << TableModel->data(indextemp).toString();
txt.append(QString::number(duedate_Equip_Idx + 1));//index
txt.append(":\t");
txt.append(QString(TableModel->item(i,2)->data(Qt::DisplayRole).toString()));//IG_SN
txt.append("\tDuedate:");
txt.append(TableModel->data(indextemp).toString());//duedate
txt.append("\t");
txt.append(TableModel->item(i,1)->data(Qt::DisplayRole).toString());//Model Name
txt.append("\t\t");
txt.append(TableModel->item(i,0)->data(Qt::DisplayRole).toString());//equipment Name
txt.append("\r\n");
duedate_Equip_Idx++;
//qDebug("send email true");
B_SendMail = true;
}
if(Duedate < CurDate)
{
for(j = 0;j<columnNum ;j++)
{
TableModel->item(i,j)->setBackground(QBrush(QColor(255, 0, 0)));//set row color of tableview
//update status ziduan to tingyong
}
}
}
}
FileName_ATTACH = "EquipmentList";
FileName_ATTACH.append(CurDate.toString("yyyy_MM_dd"));
FileName_ATTACH.append(".txt");
QFile outFile(FileName_ATTACH);
if(outFile.exists())
{
outFile.remove();
}
outFile.open(QIODevice::WriteOnly | QIODevice::Append|QIODevice::Text);
QTextStream ts(&outFile);
ts << txt << endl;
}
}
void MainWindow::TableView_itemClicked()
{
// int row = TableIndex.row();//褰撳墠閫変腑琛?
int ListCurROW,TableCurRow;
ListCurROW = ui->listView->currentIndex().row();
TableCurRow = ui->tableView->currentIndex().row();
int col = 3;
switch(ListCurROW)
{
case 0://
case 4:
case 1://
case 2: col = 2; //IGSN COL;
break;
case 3: col = 1; //Asset SN COL;
break;
}
QString CellText;
//method 3 鑾峰緱褰撳墠琛岀殑IGSN
QAbstractItemModel *modessl = ui->tableView->model();
QModelIndex indextemp = modessl->index(TableCurRow,col);//閬嶅巻绗瑀ow琛岀殑3鍒?
QVariant datatemp = modessl->data(indextemp);//杩欎釜鏄崟鍏冩牸鐨勫�?
CellText = datatemp.toString();
ui->lineEdit->setText(tr(CellText.toLatin1()));
if(ListCurROW == 0)//Allequipment table,鎵惧埌CAL锛孷ER瀛楁鍒ゆ柇鏄痗al杩樻槸ver
{
col = 9;
indextemp = modessl->index(TableCurRow,col);
datatemp = modessl->data(indextemp);//杩欎釜鏄崟鍏冩牸鐨勫�?
CellText = datatemp.toString();
if(CellText == "CAL")
{
CalVerCat = Calibration_Equipment;
}
else if(CellText == "VER")
{
CalVerCat = Verify_Equipment;
}
else
{
}
}
}
void MainWindow::ListView_itemClicked()
{
QModelIndex ListIndex = ui->listView->currentIndex();
qDebug() << ListIndex;
QString SQLString;
int n = ListIndex.row();
switch(n)
{
case 0://All equipments
SQLString = SQLString_EquipmentAll;
ui->statusBar->showMessage(tr("All equipments will be showed on the right table grid."));
break;
case 1://Calibration equipments
SQLString = SQLString_EquipmentCAL;
ui->statusBar->showMessage(tr("Calibration equipments will be showed on the right table grid."));
break;
case 2://Verificatioin equipments
SQLString = SQLString_EquipmentVER;
ui->statusBar->showMessage(tr("Verificatioin equipments will be showed on the right table grid."));
break;
case 3://consumable material
SQLString = SQLString_ConsumableMaterial;
ui->statusBar->showMessage(tr("consumable material will be showed on the right table grid."));
break;
case 4://Other equipments
SQLString = SQLString_EquipmentOther;
ui->statusBar->showMessage(tr("Other equipments will be showed on the right table grid."));
break;
}
dbOpen();
updateData2Tableview(SQLString);
dbClose();
}
void MainWindow::Addnew_itemClicked()
{
if((ui->listView->currentIndex().row())== -1)
{
QMessageBox Msg_warning;
Msg_warning.setWindowTitle(tr("Warning!"));
Msg_warning.setText(tr("Please select a Database first!"));
Msg_warning.setStandardButtons(QMessageBox::Ok);
Msg_warning.setIcon(QMessageBox::Warning);
Msg_warning.exec();
}
else if((ui->listView->currentIndex().row())== 3)//add new material item,should operate ConsumableMaterial table
{
addNewItem* Addnewitemdialog;
Addnewitemdialog = new addNewItem(this);
QObject::connect(Addnewitemdialog,SIGNAL(Signal_addItem(int ,QList <QString>)),this,SLOT(updateSQLdb_AddnewItem(int,QList <QString>)));
Addnewitemdialog->exec();
}
else//add new equipment,should operate summaryTable
{
addNewEquipment* AddnewEquipment_dialog;
AddnewEquipment_dialog = new addNewEquipment(this);
QObject::connect(AddnewEquipment_dialog,SIGNAL(Signal_addEquipment(int,QList<QStandardItem*>)),this,SLOT(updateSQLdb_AddnewEquipment(int,QList <QStandardItem*>)));
AddnewEquipment_dialog->exec();
}
}
void MainWindow::Modify_itemClicked()
{
if((ui->listView->currentIndex().row())== -1)
{
QMessageBox Msg_warning;
Msg_warning.setWindowTitle(tr("Warning!"));
Msg_warning.setText(tr("Please select a Database first!"));
Msg_warning.setStandardButtons(QMessageBox::Ok);
Msg_warning.setIcon(QMessageBox::Warning);
Msg_warning.exec();
}
else
{
int CurRow = ui->tableView->currentIndex().row();//褰撳墠閫変腑琛?
if (CurRow == -1)
{
QMessageBox Msg_warning;
Msg_warning.setWindowTitle(tr("Warning!"));
Msg_warning.setText(tr("Please select a item first!"));
Msg_warning.setStandardButtons(QMessageBox::Ok);
Msg_warning.setIcon(QMessageBox::Warning);
Msg_warning.exec();
}
else
{
QList <QString> ItemList;
QString ItemString[16];
QAbstractItemModel *modessl;
QModelIndex indextemp;
QVariant datatemp;
int i;
if((ui->listView->currentIndex().row())== 3)//add new material item,should operate ConsumableMaterial table
{
addNewItem* ModifyItemsdialog;
ModifyItemsdialog = new addNewItem(this);
ModifyItemsdialog->setWindowTitle(tr("Modify the selected Material information"));
//閬嶅巻tableview锛屽苟灏嗘暟鎹啓鍒癐temList涓?,閫氳繃淇″彿鍙戦�佺粰dialog
modessl = ui->tableView->model();
for( i = 0;i < 6; i++)
{
indextemp = modessl->index(CurRow,i);//閬嶅巻绗瑀ow琛岀殑0鍒?
datatemp = modessl->data(indextemp);//杩欎釜鏄崟鍏冩牸鐨勫�?
ItemString[i] = datatemp.toString();
ItemList << ItemString[i];
}
QObject::connect(this,SIGNAL(Signal_ModifyUI_Item(QList <QString>,DB_Update_Catgroy)),ModifyItemsdialog,SLOT(updateUI_items(QList <QString>,DB_Update_Catgroy)));
emit Signal_ModifyUI_Item(ItemList,Modify);
QObject::connect(ModifyItemsdialog,SIGNAL(Signal_ModifyItem(int ,QList <QString>)),this,SLOT(updateSQLdb_ModifyItem(int,QList <QString>)));
ModifyItemsdialog->exec();
}
else
{
addNewEquipment* ModifyEquipmentdialog;
ModifyEquipmentdialog = new addNewEquipment(this);
ModifyEquipmentdialog->setWindowTitle(tr("Modify the selected equipment information"));
QString SQLString;
if(ui->listView->currentIndex().row() == 0)
{
SQLString = "SELECT * FROM SummaryTable";
}
else if(ui->listView->currentIndex().row() == 1)
{
SQLString = "SELECT * FROM SummaryTable where CalOrVerify = 'CAL'";
}
else if(ui->listView->currentIndex().row() == 2)
{
SQLString = "SELECT * FROM SummaryTable where CalOrVerify = 'VER'";
}
else
{
SQLString = "SELECT * FROM SummaryTable where CalOrVerify NOT IN('CAL','VER')";
}
QStandardItemModel *TableModel2;
TableModel2 = new QStandardItemModel;
dbOpen();
QSqlQuery query(db);
TableModel2->clear();
if(query.exec(SQLString))
{
qDebug() << SQLString;
qDebug("SQL exec: successful!");
}
else
{
qDebug("SQL exec: Failed!");
}
int columnNum = query.record().count(); //鑾峰彇姣忔潯璁板綍涓睘鎬э紙鍗冲垪锛夌殑涓暟
//璁剧疆鍒楁暟
TableModel2->setColumnCount(columnNum);
//璁剧疆鏍囬
int i = 0;
for(i = 0;i < columnNum; i++)
{
TableModel2->setHeaderData(i,Qt::Horizontal,query.record().fieldName(i));
}
QStandardItem *item[columnNum];
QList <QStandardItem*>ItemList2;
while((bool)query.next())
{ //澧炲姞椤瑰埌妯″瀷
for(i = 0;i < columnNum; i++)
{
item[i] = new QStandardItem(query.value(i).toString());//鍙栧綋鍓嶈褰曠i涓瓧娈?(浠?0寮�濮嬭鏁?)鐨勫唴瀹?
ItemList2 << item[i];
}
TableModel2->appendRow(ItemList2);
ItemList2.clear();
}
modessl = TableModel2;
for( i = 0;i < 15; i++)
{
indextemp = modessl->index(CurRow,i);//閬嶅巻绗瑀ow琛岀殑i鍒?
datatemp = modessl->data(indextemp);//杩欎釜鏄崟鍏冩牸鐨勫�?
ItemString[i] = datatemp.toString();
ItemList << ItemString[i];
}
dbClose();
QObject::connect(this,SIGNAL(Signal_ModifyUI_Equipment(QList <QString>,DB_Update_Catgroy)),ModifyEquipmentdialog,SLOT(updateUI_Equipment(QList <QString>,DB_Update_Catgroy)));
emit Signal_ModifyUI_Equipment(ItemList,Modify);
QObject::connect(ModifyEquipmentdialog,SIGNAL(Signal_ModifyEquipment(int,QList <QStandardItem*>)),this,SLOT(updateSQLdb_ModifyEquipment(int, QList <QStandardItem*>)));
ModifyEquipmentdialog->exec();
}
}
}
}
void MainWindow::UpdateVerCalDate_ButtonClicked()
{
int ListCurROW,TableCurRow;
ListCurROW = ui->listView->currentIndex().row();
TableCurRow = ui->tableView->currentIndex().row();
QString IGSN = ui->lineEdit->text();
//if((((ListCurROW == 0) || (ListCurROW == 1) || (ListCurROW == 2)) && (TableCurRow !=-1)))
if((ListCurROW == 0) || (ListCurROW == 1) || (ListCurROW == 2))
{
if(TableCurRow !=-1)
{
if(ListCurROW == 1)// cal
{
CalVerCat = Calibration_Equipment;
}
else if(ListCurROW == 2)//ver
{
CalVerCat = Verify_Equipment;
}
else if(ListCurROW == 0)//All table, 鍒ゆ柇calorver
{
}
qDebug() << CalVerCat;
UpdateCalVerDateDlg* UpdateCalVerDateDialog;
UpdateCalVerDateDialog = new UpdateCalVerDateDlg(this);
QObject::connect(this,SIGNAL(Signal_UpdateDateUI(CalOrVer,QString,int)),UpdateCalVerDateDialog,SLOT(update_UpdateDateUI(CalOrVer,QString,int)));//绌块�佹暟鎹埌UI
QObject::connect(UpdateCalVerDateDialog,SIGNAL(Signal_UpdateTableViewfromCalVerDateDlg()),this,SLOT(Slot_UpdateTableViewfromCalVerDateDlg()));//浼犲洖鏉ュ瓨鍏ユ暟鎹簱锛屼笉鐢紝鐩存帴鍦║I鐣岄潰瀛樺偍锛屽洜涓哄湪UI鐣岄潰浼氬紑涓�涓暟鎹簱鐨?
emit Signal_UpdateDateUI(CalVerCat,IGSN,UserLevel);
UpdateCalVerDateDialog->exec();
}
else
{
QMessageBox Msg_warning;
Msg_warning.setWindowTitle(tr("Warning!"));
Msg_warning.setText(tr("Please select a Calibration or Verification Record first!"));
Msg_warning.setStandardButtons(QMessageBox::Ok);
Msg_warning.setIcon(QMessageBox::Warning);
Msg_warning.exec();
}
}
else
{
QMessageBox Msg_warning;
Msg_warning.setWindowTitle(tr("Warning!"));
Msg_warning.setText(tr("Please select a Calibration or Verification Database first!"));
Msg_warning.setStandardButtons(QMessageBox::Ok);
Msg_warning.setIcon(QMessageBox::Warning);
Msg_warning.exec();
}
}
void MainWindow::Delete_Clicked()//鐢ㄤ簬鍒犻櫎鏌愪竴鏉¤褰?
{
//纭畾鍒犵殑鏄偅涓猼able锛屽啀纭畾鏄偅涓�鏉¤鍒?
int CurRow_Listview = ui->listView->currentIndex().row();
QString String_Key;
QString SQLString,SQLString2;
String_Key = ui->lineEdit->text();
qDebug() << String_Key;
if(String_Key.isEmpty())
{
QMessageBox Msg_warning;
Msg_warning.setWindowTitle(tr("Warning!"));
Msg_warning.setText(tr("Please select a item first!"));
Msg_warning.setStandardButtons(QMessageBox::Ok);
Msg_warning.setIcon(QMessageBox::Warning);
Msg_warning.exec();
}
else
{
QMessageBox Msg_deletewarning;
Msg_deletewarning.setWindowTitle(tr("Warning!"));
Msg_deletewarning.setText(tr("A equipment will be deleted from the database!"));
Msg_deletewarning.setInformativeText(tr("Do you really want to delete this item?"));
Msg_deletewarning.setStandardButtons(QMessageBox::Yes | QMessageBox::Cancel);
Msg_deletewarning.setDefaultButton(QMessageBox::Cancel);
Msg_deletewarning.setIcon(QMessageBox::Warning);
int ret = Msg_deletewarning.exec();
if(ret ==QMessageBox::Yes )
{
qDebug("Yes");
/*
QModelIndex TableIndex = ui->tableView->currentIndex();
int CurRow = TableIndex.row();//褰撳墠閫変腑琛?
int CurCol;
TableModel->removeRow(CurRow);//浠巘ableview涓垹闄や簡浣嗘槸鏁版嵁搴撹繕鍦?
qDebug("Delete from tableview");
QAbstractItemModel *modessl = ui->tableView->model();
switch(CurRow_Listview)
{
case 0://
case 4:
case 1://
case 2: CurCol = 3; //IGSN COL;
break;
case 3: CurCol = 1; //Asset SN COL;
break;
}
QModelIndex indextemp = modessl->index(CurRow,CurCol);//閬嶅巻绗瑀ow琛岀殑3鍒?
QVariant datatemp = modessl->data(indextemp);//杩欎釜鏄崟鍏冩牸鐨勫�?
String_Key = datatemp.toString();
*/
switch(CurRow_Listview)
{
case 0://all Equipments----Summary table
SQLString = "DELETE FROM SummaryTable WHERE IG_SN = ";
break;
case 1://Calibration Equipments----cal date table & Summary table
SQLString = "DELETE FROM SummaryTable WHERE IG_SN = ";
SQLString2 = "DELETE FROM CalEquipments WHERE IG_SN = ";
break;
case 2://Verification Equipments----Summary table & verification table
SQLString = "DELETE FROM SummaryTable WHERE IG_SN = ";
SQLString2 = "DELETE FROM VerifyEquipments WHERE IG_SN = ";
break;
case 3://Consumable material---- Consumable table
SQLString = "DELETE FROM ConsumablesMaterial WHERE Asset_Number = ";
break;
case 4://Other equipments---- Summary table(except CAL AND VER)
SQLString = "DELETE FROM SummaryTable WHERE IG_SN = ";
break;
}
SQLString.append("'");
SQLString.append(String_Key);
SQLString.append("'");
// 鎵ц鏁版嵁搴撴搷浣?
dbOpen();
QSqlQuery query(db);
if(query.exec(SQLString))
{
qDebug("SQL exec for delete item successful!");
}
else
{
qDebug("SQL exec for delete item failed!");
}
if(!SQLString2.isEmpty())
{
SQLString2.append("'");
SQLString2.append(String_Key);
SQLString2.append("'");
qDebug() << SQLString2;
if(query.exec(SQLString2))
{
qDebug("SQL exec for delete item from database successful!");
}
else
{
qDebug("SQL exec for delete item from database failed!");
}
}
SQLString.clear();
SQLString2.clear();
qDebug("Delete from Sqlite OK!");
QString temp;
switch(CurRow_Listview)
{
case 0: temp = SQLString_EquipmentAll;break;
case 1: temp = SQLString_EquipmentAll;break;
case 2: temp = SQLString_EquipmentVER;break;
case 3: temp = SQLString_ConsumableMaterial;break;
case 4: temp = SQLString_EquipmentOther;break;
}
updateData2Tableview(temp);
dbClose();
}
else
{
qDebug("No,CANCEL");
}
}
}
void MainWindow::updateSQLdb_AddnewItem(int database,QList <QString>ItemList)
{
qDebug("add new item");
int a;
a = database;
QString SQLString_Insert;
SQLString_Insert = "INSERT INTO ConsumablesMaterial VALUES('";
for(a = 0;a < 5 ;a++)
{
SQLString_Insert.append(ItemList.at(a));
SQLString_Insert.append("','");
}
SQLString_Insert.append(ItemList.at(5));
SQLString_Insert.append("')");
// 鎵ц鏁版嵁搴撴搷浣?
dbOpen();
QSqlQuery query(db);
if(query.exec(SQLString_Insert))
{
qDebug("SQL exec for add NEW item TO database successful!");
}
else
{
qDebug("SQL exec for ADD NEW item TO database FAILED!");
}
updateData2Tableview(SQLString_ConsumableMaterial);
dbClose();
}
void MainWindow::updateSQLdb_AddnewEquipment(int database, QList<QStandardItem*> ItemList)
{
qDebug("add new equipment");
int a;
a = database;
QString SQLString_Insert;
SQLString_Insert = "INSERT INTO SummaryTable VALUES('";
for(a = 0;a < 4 ;a++)
{
SQLString_Insert.append(ItemList.at(a)->data(Qt::DisplayRole).toString());
SQLString_Insert.append("','");
}
SQLString_Insert.append(ItemList.at(4)->data(Qt::DisplayRole).toString());
SQLString_Insert.append("',DATE('");
// qDebug() << ItemList.at(5)->data();//QVariant(QDate, QDate("2014-07-28") )
// qDebug() << ItemList.at(5)->data().toDate();//QDate("2014-07-28")
// qDebug() << ItemList.at(5)->data().toDate().toString("yyyy-MM-dd");//"2014-07-28"
qDebug() << ItemList.at(5)->data().toString();//"2014-07-28"
SQLString_Insert.append(ItemList.at(5)->data().toString());
SQLString_Insert.append("'),DATE('");
SQLString_Insert.append(ItemList.at(6)->data().toString());
SQLString_Insert.append("'),'");
SQLString_Insert.append(ItemList.at(7)->data(Qt::DisplayRole).toString());
SQLString_Insert.append("','");
SQLString_Insert.append(ItemList.at(8)->data(Qt::DisplayRole).toString());
SQLString_Insert.append("',DATE('");
SQLString_Insert.append(ItemList.at(9)->data().toString());
SQLString_Insert.append("'),'");
for(a = 10;a < 14 ;a++)
{
SQLString_Insert.append(ItemList.at(a)->data(Qt::DisplayRole).toString());
SQLString_Insert.append("','");
}
SQLString_Insert.append(ItemList.at(14)->data(Qt::DisplayRole).toString());
SQLString_Insert.append("')");
qDebug() << SQLString_Insert;
// 鎵ц鏁版嵁搴撴搷浣?
dbOpen();
QSqlQuery query(db);
if(query.exec(SQLString_Insert))
{
qDebug("SQL exec :Insert equipments successful!");
}
else
{
qDebug("SQL exec :Insert equipments Failed!");
}
SQLString_Insert.clear();
if((ui->listView->currentIndex().row())== 0)
{
SQLString_Insert = SQLString_EquipmentAll;
}
else if((ui->listView->currentIndex().row())== 1)
{
SQLString_Insert = SQLString_EquipmentCAL;
}
else if((ui->listView->currentIndex().row())== 2)
{
SQLString_Insert = SQLString_EquipmentVER;
}
else if((ui->listView->currentIndex().row())== 4)
{
SQLString_Insert = SQLString_EquipmentOther;
}
updateData2Tableview(SQLString_Insert);
dbClose();
SQLString_Insert.clear();
//濡傛灉鏄疌AL 鎴朧ER 鐨勮澶囷紝鍒欓渶瑕佸悓鏃舵洿鏂? cal鍜寁er鐨? cal/ver date,due date 鍒癱alequipment鍜寁erequipment table涓?
// SQLString_Insert = "INSERT INTO SummaryTable VALUES('";
QString CALVERString;
CALVERString = ItemList.at(13)->data(Qt::DisplayRole).toString();
if( (CALVERString == "CAL") ||(CALVERString == "VER"))
{
if(CALVERString == "CAL")
{
SQLString_Insert = "INSERT INTO CalEquipments VALUES('";
}
else if(CALVERString == "VER")
{
SQLString_Insert = "INSERT INTO VerifyEquipments VALUES('";
}
SQLString_Insert.append(ItemList.at(3)->data(Qt::DisplayRole).toString());
SQLString_Insert.append("',DATE('");
SQLString_Insert.append(ItemList.at(5)->data().toString());
SQLString_Insert.append("'),DATE('");
SQLString_Insert.append(ItemList.at(6)->data().toString());
SQLString_Insert.append("'),'");
SQLString_Insert.append(ItemList.at(15)->data(Qt::DisplayRole).toString());
SQLString_Insert.append("')");
qDebug() << SQLString_Insert;
dbOpen();
QSqlQuery query2(db);
if(query2.exec(SQLString_Insert))
{
qDebug("Insert cal/ver equipments date successful!");
}
else
{
qDebug("Insert cal/ver equipments date Failed!");
}
dbClose();
}
else //Other, No need to update the database
{