-
Notifications
You must be signed in to change notification settings - Fork 19
/
mainwindow.cpp
2180 lines (1763 loc) · 65.3 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 "Header/shiftlogout.h"
#include "Header/rightmgm.h"
#include "Header/tariffsetting.h"
#include "Header/dbmaintenance.h"
#include "Header/syslog.h"
#include "Header/pwdmodification.h"
#include "Header/monthlycard.h"
#include "Header/valuecard.h"
#include "Header/timecard.h"
#include "Header/publishledinfo.h"
#include "Header/deviceconfig.h"
#include "Header/syssetting.h"
#include "Header/batchsetcardaccess.h"
#include "Header/tolldiscounttypeset.h"
#include "Header/access2records.h"
#include "Header/reewalrecords.h"
#include "Header/discountsummaryreport.h"
#include "Header/printdaylyreport.h"
#include "Header/printmonthlyreport.h"
#include "Header/printyearlyreport.h"
#include "Header/handheldicprocess.h"
#include "Header/ipcvideoframe.h"
#include "Header/picturecontrast.h"
#include "Dialog/pwddialog.h"
#include "Dialog/ledinfodialog.h"
#include "Dialog/syssettingdialog.h"
#include "Header/blacklist.h"
#include "Dialog/handicdialog.h"
#include <QLabel>
#include "Dialog/passdlg.h"
#include "Dialog/recognizeparamdlg.h"
#include <Common/mytimer.h>
#include <QDebug>
#include <QDateTime>
#include <QtGui/QApplication>
#include "Common/commonfunction.h"
#include "Dialog/serialportdialog.h"
#include "SerialPort/processdata.h"
#include <QScreen>
#include <QDesktopWidget>
#include "Network/parkintranet.h"
#include "Network/ftp.h"
#include "startupthread.h"
#include <QProcess>
//#include "Lunar/SolarDate.h"
//#include "Lunar/ChineseDate.h"
#include "DbBackup/dbbackupthread.h"
#include "DbBackup/RdAutoDeleteThread.h"
#include "Network/localsvrcommunication.h"
#include "Network/localcltcommunication.h"
#include "Network/ftp.h"
#include "Dialog/dlgabout.h"
#include "Dialog/dlgmakelicense.h"
#include <QPushButton>
#include "CenterMgmt/mgmtthread.h"
#include "Dialog/dlgstaying.h"
#include "Timer/timerthread.h"
#include "Header/monitor.h"
CHeartbeatThread* g_pHeartbeatThread = NULL;
CLocalCltCommunication* g_pLocalCltComm = NULL;
CFtp* g_pFtp = NULL;
void MainWindow::SetFileCount( quint32 nCount )
{
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->SetFileCount( nCount );
}
void MainWindow::PictureRegconize( QString &strFile, int nChannel, QByteArray& byData )
{
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->PictureRegconize( strFile, nChannel, byData );
}
bool MainWindow::AllInOneIPIO(char cCan, bool bOpen)
{
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
return pMonitor->AllInOneIPIO( cCan, bOpen);
}
bool MainWindow::ShiftDlgISVisible( )
{
bool bRet = false;
if ( NULL != pDlgLogin ) {
bRet = pDlgLogin->isVisible( );
}
return bRet;
}
void MainWindow::SetDateTimeFormat( )
{
LCID localeID = ::GetSystemDefaultLCID( );
BOOL bRet = ::SetLocaleInfo( localeID, LOCALE_SSHORTDATE, L"yyyy-M-d" );
bRet = ::SetLocaleInfo( localeID, LOCALE_SDATE, L"-" );
bRet = ::SetLocaleInfo( localeID, LOCALE_STIMEFORMAT, L"H:mm:ss" );
bRet = ::SetLocaleInfo( localeID, LOCALE_STIME, L":" );
QString strFormat = "yyyy'年'M'月'd'日' dddd";
LPCWSTR lpLongFormat = ( LPCWSTR ) strFormat.utf16( );
bRet = ::SetLocaleInfo( localeID, LOCALE_SLONGDATE, lpLongFormat );
}
void MainWindow::StartupMgmt( )
{
bool bRet = pSettings->value( "Mgmt/MgmtTCP", false ).toBool( );
if ( !bRet ) {
return;
}
if ( pSettings->value( "Mgmt/StartupSenderThread", false ).toBool( ) ) {
CMgmtThread::GetThread( true );
} else if ( pSettings->value( "Mgmt/StartupReceiverThread", false ).toBool( ) ) {
CMgmtThread::GetThread( false );
}
}
void MainWindow::SetAlertMsg( const QString &strText )
{
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->SetAlertMsg( strText );
}
QString MainWindow::GetPictureName( QString strName )
{
int nWidth = width( );
int nHeight = height( );
QString strTmp = "%1x%2";
if ( 1440 == nWidth && 900== nHeight ) {
strTmp.clear( );
} else if ( 1366 == nWidth && 768 == nHeight ) {
strTmp = strTmp.arg( QString::number( nWidth ), QString::number( nHeight ) );
}
return strName.arg( strTmp );
}
void MainWindow::LoadUIImage( )
{
QString strStyle= "background-image:url(" + strIconPath + GetPictureName( "MainBG%1.jpg);" );
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->setStyleSheet( strStyle );
//QString strMenuStyle = "QMenu::item{%1padding:5px;background-color: rgb(255, 255, 255);}";
QList< QMenu* > lstMenu;
lstMenu.append( ui->menuSysMgm );
//QString strTmp =strMenuStyle.arg( "width:85px;" );
//ui->menuSysMgm->setStyleSheet( strTmp );
//strMenuStyle = strMenuStyle.arg( "" );
lstMenu.append( ui->menuCardTicketsMgm );
//ui->menuCardTicketsMgm->setStyleSheet( strMenuStyle );
lstMenu.append( ui->menuAdvSetting );
//ui->menuAdvSetting->setStyleSheet( strMenuStyle );
lstMenu.append( ui->menuQueryReport );
//ui->menuQueryReport->setStyleSheet( strMenuStyle );
lstMenu.append( ui->menuHelp );
//ui->menuHelp->setStyleSheet( strMenuStyle );
pMonitor->SetMenu( lstMenu );
pLblTime = pMonitor->GetDateTimeCtrl( );
connect( this, SIGNAL( OnPermission( bool, int ) ), pMonitor, SLOT( BtnPermission( bool, int ) ) );
}
void MainWindow::UpdateStatistics( int nNumber, int nIndex )
{
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->UpdateStatistics( nNumber, nIndex );
}
void MainWindow::SyncTime( QStringList& lstData )
{
if ( 9 > lstData.count( ) ) {
return;
}
SYSTEMTIME sysTime;
sysTime.wYear = lstData[ 1 ].toUShort( );
sysTime.wMonth = lstData[ 2 ].toUShort( );
sysTime.wDay = lstData[ 3 ].toUShort( );
sysTime.wDayOfWeek = lstData[ 4 ].toUShort( );
sysTime.wHour = lstData[ 5 ].toUShort( );
sysTime.wMinute = lstData[ 6 ].toUShort( );
sysTime.wSecond = lstData[ 7 ].toUShort( );
sysTime.wMilliseconds = lstData[ 8 ].toUShort( );
BOOL bRet = SetLocalTime( &sysTime );
QStringList lstTimeData;
lstTimeData << QString( "%1-%2-%3" ).arg( lstData[ 1 ], lstData[ 2 ], lstData[ 3 ] )
<< QString( "%1:%2:%3" ).arg( lstData[ 5 ], lstData[ 6 ], lstData[ 7 ] );
SyncLedTime( lstTimeData );
qDebug( ) << "SyncTime( ) " << ( bRet ? "Success" : "Failed" ) << endl;
}
void MainWindow::SyncLedTime( QStringList& lstData )
{
CProcessData* pProcessor = CProcessData::GetProcessor( );
if ( NULL != pProcessor ) {
char cCan = 0;
foreach ( const QString& str, lstCanAddr ) {
cCan = ( char ) str.toShort( );
pProcessor->ProcessUserRequest( CommonDataType::UserPublishLed, cCan, lstData );
}
}
}
void MainWindow::GetLocalCanAddr( )
{
QString strWhere = QString( " Where video1ip = '%1' " ).arg( CCommonFunction::GetHostIP( ) );
QString strSql = QString( "Select distinct shebeiadr from \
roadconerinfo %1" ).arg(
strWhere );
int nRows = CLogicInterface::GetInterface( )->ExecuteSql( strSql, lstCanAddr );
nRows = 0;
}
void MainWindow::SendTime( )
{
SYSTEMTIME sysTime;
GetLocalTime( &sysTime );
QStringList lstData;
lstData << QString::number( sysTime.wYear )
<< QString::number( sysTime.wMonth )
<< QString::number( sysTime.wDay )
<< QString::number( sysTime.wDayOfWeek )
<< QString::number( sysTime.wHour )
<< QString::number( sysTime.wMinute )
<< QString::number( sysTime.wSecond )
<< QString::number( sysTime.wMilliseconds );
CNetwork::Singleton( ).BroadcastDatagram( CommonDataType::DGSyncTime, lstData );
}
void MainWindow::StartSycnTime( )
{
bSyncServer = pSettings->value( "Database/Server", false ).toBool( );
double dInterval = pSettings->value( "Database/IntervalTime", 24 ).toDouble( );
if ( !bSyncServer ) {
return;
}
//CStartupProcess::GetFrame( )->UpdateInfo( "同步时间!" );
static QTimer timer;
int nInterval = int ( dInterval * 3600 * 1000 );
timer.setInterval( nInterval );
connect( &timer, SIGNAL( timeout( ) ), this, SLOT( SendTime( ) ) );
timer.start( );
SendTime( );
}
QString MainWindow::GetUserName( )
{
return strUserName;
}
void MainWindow::CheckResolution( )
{
QDesktopWidget* pDesktop = QApplication::desktop( );
QRect rect = pDesktop->screenGeometry( );
int nWidth = rect.width( );
int nHeight = rect.height( );
int nW = 1440;
int nH = 900;
if ( nW != nWidth || nH != nHeight ) {
QString strInfo = QString( "请设置屏幕分辨率为: %1 X %2" ).arg(
QString::number( nW ), QString::number( nH ) );
CCommonFunction::MsgBox( NULL, CCommonFunction::GetMsgTitle( QMessageBox::Information ),
strInfo, QMessageBox::Information );
}
}
void MainWindow::Singleton( )
{
QString strGUID = "{063F5B37-7AA6-4E90-B658-36AAFBA7B8BE}";
WCHAR cGUID[ 256 ] = { 0 };
strGUID.toWCharArray( cGUID );
HANDLE hEvent = CreateEvent( NULL, TRUE, FALSE, cGUID );
DWORD dwError = GetLastError( );
if ( NULL != hEvent && ERROR_ALREADY_EXISTS == dwError ) {
CCommonFunction::MsgBox( NULL, CCommonFunction::GetMsgTitle( QMessageBox::Information ),
"系统已启动!", QMessageBox::Information );
exit( 0 );
}
//CheckResolution( );
}
void MainWindow::RecognizePlate( QString strPlate, int nChannel, int nConfidence, bool bNocard, QByteArray byData )
{
CProcessData* pProcessor = CProcessData::GetProcessor( pSerialPort, this );
if ( NULL == pProcessor ) {
return;
}
pProcessor->RecognizePlate( strPlate, nChannel, nConfidence, bNocard, byData );
}
void MainWindow::GetParkName( QString &strName, char cCan, int nIndex )
{
// CAN / PARKINDEX / PARKNUM / PARKNAME
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->GetParkName( strName, cCan, nIndex );
}
void MainWindow::LoadCapturedImg( QString& strPath, int nChannel )
{
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->LoadCapturedImg( strPath, nChannel );
}
void MainWindow::GetInOutPixmap(QPixmap &bmpEnter, QPixmap &bmpLeave)
{
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->GetInOutPixmap( bmpEnter, bmpLeave );
}
void MainWindow::CaptureImage( QString &strFile, int nChannel, CommonDataType::CaptureImageType capType )
{
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->CaptureImage( strFile, nChannel, capType );
}
CMySqlDatabase* MainWindow::GetMysqlDb( )
{
return pMysqlDb;
}
CWinSerialPort* MainWindow::GetSerialPort( )
{
return pSerialPort;
}
bool MainWindow::SetCardNumber( QString& strNumber )
{
bool bRet = ( NULL != edtCardNumner );
if ( bRet ) {
edtCardNumner->setText( strNumber );
}
return bRet;
}
void MainWindow::SetCardControl( QLineEdit *edtCtrl )
{
edtCardNumner = edtCtrl;
}
void MainWindow::IconLoad( QWidget& frame )
{
QString strInfo = strIconPath + "Icon.PNG";
QIcon icon( strInfo );
frame.setWindowIcon( icon );
}
QPixmap& MainWindow::GetPixmap( QString& strFile )
{
static QPixmap pixmap;
QString strTmp = strFile + ".JPG";
if ( !pixmap.load( strTmp, "JPG" ) ) {
strTmp = strFile + ".PNG";
pixmap.load( strTmp, "PNG" );
}
return pixmap;
}
void MainWindow::WriteLog( QString strType, QString& strContent, CommonDataType::SysLogType logType, QDateTime& dtDateTime, char cCan )
{
QStringList lstRows;
QString strText;
CCommonFunction::DateTime2String( dtDateTime, strText );
lstRows << strUserName << strType << strContent << strText;
QString strWhere = "";
GetLogicInterface( )->OperateSysLogInfo( lstRows, logType, CommonDataType::InsertData, strWhere );
}
void MainWindow::WriteShiftLog( bool bLogin )
{
QString strContent = bLogin ? "登录系统成功" : "退出软件";
QDateTime dtDateTime = QDateTime::currentDateTime( );
WriteLog( "换班记录", strContent, CommonDataType::ShiftLog, dtDateTime );
}
void MainWindow::Permission( )
{
QStringList lstRows;
QString strWhere = QString( " Where operatorname = '%1' " ).arg( strUserName );
CLogicInterface::GetInterface( )->OperateRightInfo( lstRows, CommonDataType::SelectData, strWhere );
if ( 0 >= lstRows.count( ) ) {
return;
}
QString strFalse = "0";
// Right Mgm
int nField = 4;
bool bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actRightMgm->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actTariffSetting->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actDBMaintenance->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actSysLog->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actVideoService->setEnabled( bEnabled );
ui->actRemoteMgmt->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actPlateService->setEnabled( bEnabled );
ui->actIPC->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actConnectDb->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actSysExit->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actMonthlyCard->setEnabled( bEnabled );
emit OnPermission( bEnabled, 0 );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actValueCard->setEnabled( bEnabled );
emit OnPermission( bEnabled, 1 );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actTimeCard->setEnabled( bEnabled );
emit OnPermission( bEnabled, 2 );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actPublishLEDInfo->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actDeviceConfig->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actSysSetting->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actBatchSetCardAccess->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actTollDiscountTypeSet->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actBlacklist->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actSerialPort->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actPlateRecognizationSet->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actSyncTime->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actAccess2Records->setEnabled( bEnabled );
emit OnPermission( bEnabled, 3 );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actReewalRecords->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actDiscountSummaryReport->setEnabled( bEnabled );
//ui->actSerialPort->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
ui->actPrintDaylyReport->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ nField++ ].compare( strFalse ) );
//ui->actPrintDaylyReport->setEnabled( bEnabled );
ui->actStay->setEnabled( bEnabled );
bEnabled |= ( 0 != lstRows[ nField++ ].compare( strFalse ) );
//ui->actPrintDaylyReport->setEnabled( bEnabled );
bEnabled = ( 0 != lstRows[ 4 ].compare( strFalse ) );
ui->mainTB->actions( )[ 2 ]->setEnabled( bEnabled );
ui->mainTB->actions( )[ 3 ]->setEnabled( bEnabled );
ui->mainTB->actions( )[ 4 ]->setEnabled( bEnabled );
ui->mainTB->actions( )[ 5 ]->setEnabled( bEnabled );
}
void MainWindow::Login( bool bStart )
{
if ( bStart ) {
IconLoad( *pDlgLogin );
connect( pDlgLogin, SIGNAL( ImportLicenseData( ) ), this, SLOT( on_actLicense_triggered( ) ) );
}
pDlgLogin->HideLicenseButton( bSyncServer );
//pDlgLogin->HideCancelBtn( bStart );
pDlgLogin->GetUsers( bStart );
CCommonFunction::MySetWindowPos( pDlgLogin );
if ( bStart ) {
pDlgLogin->move( pDlgLogin->geometry( ).left( ),
pDlgLogin->geometry( ).top( ) + 10 );
}
bool bStartupPlateDilivery = pSettings->value( "PlateDilivery/StartupDilivery", false ).toBool( );
if ( bStartupPlateDilivery ) {
if ( !pDlgLogin->AutoLogin( ) ) {
if ( QDialog::Rejected == pDlgLogin->exec( ) ) {
if ( bStart ) {
exit( 0 );
} else {
return;
}
}
} else {
pDlgLogin->hide( );
}
} else {
if ( QDialog::Rejected == pDlgLogin->exec( ) ) {
if ( bStart ) {
exit( 0 );
} else {
return;
}
}
}
if ( pDlgLogin->GetIsLicense( ) ) {
GenerateLicense( strUserName, strUserPwd );
pDlgLogin->SetIsLicense( false );
exit( 0 );
}
QString strID;
pDlgLogin->GetUserPwd( strUserName, strUserPwd, strID );
emit OnUserChanged( strUserName, strID );
WriteShiftLog( true );
ReleaseCapture( );
GetCardEntityInfo( );
bool bDisplay = pSettings->value( "CommonCfg/SerialAnalog", false ).toBool( );
frmSerial.setParent( NULL );
frmSerial.setVisible( bDisplay );
}
CLogicInterface* MainWindow::GetLogicInterface( )
{
return pLogicInterface;
}
void MainWindow::GetAppInfo( CommonDataType::AppInfoType appInfo, QString &strInfo )
{
switch ( appInfo ) {
case CommonDataType::AppDirPath :
strInfo = QApplication::applicationDirPath( );
break;
case CommonDataType::AppFilePath :
strInfo = QApplication::applicationFilePath( );
break;
case CommonDataType::AppTariffFile :
strInfo = QApplication::applicationDirPath( );
strInfo += "/TariffFile.ini";
break;
case CommonDataType::AppDBMaintaince :
strInfo = QApplication::applicationDirPath( );
strInfo += "/DBMaintainceFile.ini";
break;
}
}
void MainWindow::ReconnectDatabase( )
{
bool bNeed = CLogicInterface::GetInterface( )->PingMysql( );
if ( !bNeed ) {
ControlDatabase( false );
ControlDatabase( true );
}
}
void MainWindow::ControlDatabase(bool bOpen)
{
//DbConnect( QString( "192.168.1.5" ), QString( "test" ), QString( "test" ), QString("parkadmin"), 3306 );
CCommonFunction::ShowSplashMessage( "连接数据库。" );
pLogicInterface = CLogicInterface::GetInterface( );
if ( bOpen ) {
#if false
pSettings->sync( );
QString strHost = pSettings->value( "Database/Host", QVariant( "127.0.0.1" ) ).toString( );
QString strUser = pSettings->value( "Database/User", QVariant( "test" ) ).toString( );
QString strPwd = pSettings->value( "Database/Pwd", QVariant( "test" ) ).toString( );
QString strSchema = pSettings->value( "Database/Schema", QVariant( "pms" ) ).toString( );
QString strPort = pSettings->value( "Database/Port", QVariant( "3306" ) ).toString( );
#endif
QStringList lstParams;
CCommonFunction::ConnectMySql( lstParams );
QString localLoop = "127.0.0.1";
QString strHost = CCommonFunction::GetHostIP( );
if ( lstParams[ 0 ] == strHost ) {
lstParams[ 0 ] = localLoop;
}
bool bRet = pLogicInterface->GetMysqlDb().DbConnect( lstParams[ 0 ], lstParams[ 1 ], lstParams[ 2 ], lstParams[ 3 ], lstParams[ 4 ].toUInt( ) );
if ( false == bRet ) {
CCommonFunction::ShowSplashMessage( "连接数据库失败。" );
for ( int nIndex = 0; nIndex < 10000; nIndex++ ) {
bRet = pLogicInterface->GetMysqlDb().DbConnect( lstParams[ 0 ], lstParams[ 1 ], lstParams[ 2 ], lstParams[ 3 ], lstParams[ 4 ].toUInt( ) );
if ( bRet ) {
break;
}
Sleep( 1000 );
}
if ( false == bRet ) {
CCommonFunction::MsgBox( NULL, CCommonFunction::GetMsgTitle( QMessageBox::Information ),
"数据库连接失败!", QMessageBox::Warning );
} else {
CCommonFunction::ShowSplashMessage( "连接数据库成功。" );
}
} else {
CCommonFunction::ShowSplashMessage( "连接数据库成功。" );
}
} else {
pLogicInterface->GetMysqlDb().DbDisconnect( );
}
}
void MainWindow::ControlSerial(bool bOpen)
{
if ( NULL == pSerialPort ) {
pSerialPort = new CWinSerialPort( "SerialPort", this );
}
CProcessData* pProcessor = CProcessData::GetProcessor( pSerialPort, this );
if ( NULL == pProcessor ) {
return;
}
bool bStartupPlateDilivery = pSettings->value( "PlateDilivery/StartupDilivery", false ).toBool( );
if ( bStartupPlateDilivery ) {
return;
}
if ( bOpen && !pProcessor->IsOpen( ) ) {
if ( false == pProcessor->OpenPort( ) ) {
CCommonFunction::MsgBox( NULL, CCommonFunction::GetMsgTitle( QMessageBox::Information ),
"串口打开失败!\n请检查串口是否被占用!", QMessageBox::Information );
}
} else if ( !bOpen && pProcessor->IsOpen( ) ){
pProcessor->ClosePort( );
}
}
void MainWindow::ClearAllFiles( )
{
QString strSnapshot;
CCommonFunction::GetPath( strSnapshot, CommonDataType::PathSnapshot );
CCommonFunction::ClearAllFiles( strSnapshot );
}
void MainWindow::HideCtrl( bool bVisible )
{
ui->mainTB->setVisible( bVisible );
ui->statusBar->setVisible( bVisible );
ui->menuBar->setVisible( bVisible );
ui->tbTime->setVisible( bVisible );
}
void MainWindow::SetMaxMinSize( )
{
QRect rect;
#ifdef NewUI
rect.setWidth( 1366 );
rect.setHeight( 768 );
#else
rect.setWidth( 1440 );
rect.setHeight( 900 );
#endif
setGeometry( rect );
setMaximumSize( rect.width( ), rect.height( ) );
setMinimumSize( rect.width( ), rect.height( ) );
}
MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags) :
QMainWindow( parent, flags ),
ui(new Ui::MainWindow), pDlgLogin( 0 )
{
//static CStartupThread startup( this );
//startup.start( );
//QEvent* pEvent = new QEvent( QEvent::User );
//QApplication::postEvent( &startup, pEvent );
SetMaxMinSize( );
CCommonFunction::ShowSplashMessage( "初始化时间格式开始。" );
SetDateTimeFormat( );
CCommonFunction::ShowSplashMessage( "初始化时间格式结束。" );
Singleton( );
strIconPath = "";
pSerialPort = NULL;
netServer = NULL;
ClearAllFiles( );
CCommonFunction::ShowSplashMessage( "获取参数开始。" );
CCommonFunction::GetPath( strIconPath, CommonDataType::PathUIImage );
pSettings = CCommonFunction::GetSettings( CommonDataType::CfgSystem );
strParkID = CCommonFunction::GetParkID( );
nTransferRecord = pSettings->value( "CommonCfg/TransferRecord", 4 ).toInt( );
bToInternet = pSettings->value( "CommonCfg/ToInternet", false ).toBool( );
bAlert = pSettings->value( "CommonCfg/Alert", false ).toBool( );
edtCardNumner = NULL;
CCommonFunction::ShowSplashMessage( "获取参数结束。" );
pDlgLogin = new CLoginDialog( NULL );
connect( pDlgLogin, SIGNAL( OnReconnect( ) ), this, SLOT( ReconnectDatabase( ) ) );
ControlDatabase( true );
CNetwork::Singleton( this );
ControlSerial( true );
//QReportThread::CreateReportThread( );
//GetCardEntityInfo( );
setWindowFlags( Qt::FramelessWindowHint );
CCommonFunction::ShowSplashMessage( "创建子窗体开始。" );
ui->setupUi(this);
CreateChildren( );
CCommonFunction::ShowSplashMessage( "创建子窗体结束。" );
#ifdef START_DONGLE
//2014 Dongle
pCheckThread = &CCheckThread::GetInstance( this );
#endif
CCommonFunction::ShowSplashMessage( "用户登录。" );
GetLocalCanAddr( );
StartSycnTime( );
Login( true );
StartupMgmt( );
// License
#ifdef START_DONGLE
//2014 Dongle
connect( pCheckThread, SIGNAL( ExpirationSender( QString, bool, bool ) ), this, SLOT( Expiration( QString, bool, bool ) ) );
StartLicense( );
#endif
CCommonFunction::ShowSplashMessage( "加载图片结束。" );
IconLoad( *this );
CCommonFunction::ShowSplashMessage( "加载图片结束。" );
//QWidget::setWindowState( Qt::WindowMaximized );
HideCtrl( false );
//ControlSerial( true );
ControlMonitor( true );
ModiyToobar( );
LoadUIImage( );
move( 0, 0 );
//Login( true );
CCommonFunction::ShowSplashMessage( "授权开始。" );
Permission( );
CCommonFunction::ShowSplashMessage( "授权结束。" );
//CCommonFunction::ShowSplashMessage( "同步时间开始。" );
//CCommonFunction::ShowSplashMessage( "同步时间结束。" );
ui->actPlateService->menuAction( )->setVisible( false );
ui->actVideoService->menuAction( )->setVisible( false );
QString strText = "%1%2端功能。";
CCommonFunction::ShowSplashMessage( strText.arg( "启用", bSyncServer ? "服务器" : "客户" ) );
ServerFunction( );
ClientFunction( );
RegisterAxCtrl( );
qRegisterMetaType< QAbstractSocket::SocketError >( "QAbstractSocket::SocketError" );
//pEvent = new QEvent( ( QEvent::Type ) ( QEvent::User + 1 ) );
//QApplication::postEvent( &startup, pEvent );
GatherData( );
}
void MainWindow::RegisterAxCtrl( )
{
QLibrary libLoader;
libLoader.setFileName( "SMSXControl.ocx" );
bool bRet = libLoader.load( );
if ( !bRet ) {
CCommonFunction::MsgBox( NULL, "提示", libLoader.errorString( ), QMessageBox::Information );
return;
}
typedef HRESULT __stdcall ( *DllRegisterServer ) (void);
DllRegisterServer reg = ( DllRegisterServer ) libLoader.resolve( "DllRegisterServer" );
if ( NULL != reg ) {
reg( );
}
}
void MainWindow::ProcessGateCommand( QStringList &lstData )
{
CProcessData* pProcessor = CProcessData::GetProcessor( );
if ( NULL == pProcessor ) {
return;
}
if ( 3 > lstData.count( ) ) {
return;
}
lstData.removeAt( 0 );
quint8 nItems = lstData.count( ) ;
nItems -= nItems % 2;
if ( 2 > nItems ) {
return;
}
for ( quint8 nIndex = 0; nIndex < nItems; nIndex += 2 ) {
const QString& strOp = lstData.at( nIndex );
char cCan = lstData.at( nIndex + 1 ).toShort( );
pProcessor->ControlGate( "1" == strOp, cCan );
}
// Open(1)Close(0) CANAddr
}
void MainWindow::ProcessCpuidRequest( QStringList &lstData )
{
#ifndef START_DONGLE
return; //2014 Dongle
#endif
if ( 3 > lstData.count( ) ) {
return;
}
//QString strPSN;
//CLicense::CreateSingleton( false ).GetPSN( strPSN );
QStringList lstHids;
CLicense::CreateSingleton( false ).GetPSN( lstHids );
QString strIP = CCommonFunction::GetHostIP( );
QString strAdminParkID = CCommonFunction::GetParkID( );
foreach ( const QString& strPSN, lstHids ) {
lstData.clear( );
lstData << strPSN << strIP << strAdminParkID;
CNetwork::Singleton( ).BroadcastDatagram( CommonDataType::DGCpuidResponse, lstData );
}
}
bool MainWindow::GenerateLicense( QString &strSpecialUser, QString& strSpecialPwd )
{
bool bExit = false;
if ( "Future" != strSpecialUser || "951821*Future" != strSpecialPwd ) {
;//return bExit;
}
CDlgMakeLicense license( NULL );
license.setStatusTip( strIconPath + "NewIcon/CommonMiddleBG-normal.jpg" );
//CLicense::CreateSingleton( false ).GetDongle( )->SetVerifyDate( false );
if ( !CLicense::CreateSingleton( false ).GetDongle( )->Administrator( ) ) {
CCommonFunction::MsgBox( NULL, "错误", "请插入管理员加密狗!", QMessageBox::Critical );
return bExit;
}
license.exec( );
bExit = true;
return bExit;
}
void MainWindow::StartLicense( )
{
#ifndef START_DONGLE
//2014 Dongle
return;
#endif
CLicense::CreateSingleton( false ).GetDongle( )->SetVerifyDate( true );
QString strParkID = CCommonFunction::GetParkID( );
pCheckThread->GetBlob( strParkID );
pCheckThread->start( );
}
void MainWindow::Expiration( QString strMsg, bool bExpiration, bool bRetry )
{
static int nCount = 0;
if ( bRetry ) {
QMessageBox msgBox;
msgBox.setText( strMsg );
msgBox.setWindowTitle( "软件异常" );
QPushButton* pBtn = msgBox.addButton( QMessageBox::Ok );
pBtn->setText( "重试" );
pBtn = msgBox.addButton( QMessageBox::Cancel );
pBtn->setText( "取消" );
int nRet = msgBox.exec( );
if ( QMessageBox::Ok == nRet && ( ++nCount < 5 ) ) {
CLicense::CreateSingleton( false ).GetDongle( )->Reopen( );
StartLicense( );
return;
}
}
nCount = 0;
CLogicInterface::GetInterface( )->GetMysqlDb( ).SetExpiration( bExpiration );
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->setEnabled( !bExpiration );
CCommonFunction::MsgBox( NULL, bExpiration ? "错误" : "提示", strMsg, bExpiration ? QMessageBox::Critical : QMessageBox::Information );
qDebug( ) << "Expiration:" << strMsg << endl;
if ( bExpiration ) {
exit( 0 );
}
}
void MainWindow::GatherData( )
{
bool bGather = pSettings->value( "Mgmt/Gather", false ).toBool( );
if ( !bGather ) {
return;
}
CTimerThread::GetInstance( )->start( );
}
void MainWindow::ClientFunction( )
{
if ( bSyncServer || !bToInternet ) {
return;
}
QTextCodec* pCodec = CCommonFunction::GetTextCodec( );
CNetClient::GetInstance( false, bSyncServer, pCodec, this ); // Communicate with MySQL server machine
//CNetClient::GetInstance( true, bSyncServer, pCodec, this ); // Communicate with MySQL server machine
static QTimer timer( this ); // Heartbeat
connect( &timer, SIGNAL( timeout( ) ), this, SLOT( SendStateHB( ) ) );
int nNetStateInterval = pSettings->value( "CenterServer/HeartbeatNetStateInterval", 600000 ).toInt( );
timer.start( nNetStateInterval );
}
void MainWindow::ServerFunction( )
{
if ( !bSyncServer ) {
return;
}
ui->actLicense->setVisible( bSyncServer );
ui->actLicense->setEnabled( bSyncServer );
CMonitor* pMonitor = dynamic_cast< CMonitor* >( CreateChildWnd( CommonDataType::MonitorWnd ) );
pMonitor->HideAlert( );