11
|
1 // Filename : mngdeb.cpp
|
13
|
2 // Last Change: 2018-11-14 水 13:48:58.
|
11
|
3 //
|
|
4
|
13
|
5 #include <wx/datetime.h>
|
|
6 #include <wx/textfile.h>
|
11
|
7 #include "id.h"
|
|
8 #include "mngdb.h"
|
|
9
|
|
10 ManageDBFrame::ManageDBFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
|
|
11 : wxFrame( parent, id, title, pos, size, style )
|
|
12 {
|
13
|
13 this->SetBackgroundColour( wxColour( 140, 240, 140 ) );
|
11
|
14 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
|
15
|
|
16 wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL );
|
|
17
|
|
18 wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 0, 2, 0, 0 );
|
|
19 fgSizer->SetFlexibleDirection( wxBOTH );
|
|
20 fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
|
|
21
|
|
22 m_staticTextDate = new wxStaticText( this, wxID_ANY, wxT( "Date" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
23 fgSizer->Add( m_staticTextDate, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 );
|
|
24
|
13
|
25 m_datePicker = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxSize( 180, -1 ), wxDP_DROPDOWN|wxDP_SHOWCENTURY );
|
11
|
26 fgSizer->Add( m_datePicker, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
27
|
|
28 m_staticTextHhs = new wxStaticText( this, wxID_ANY, wxT( "HHS" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
29 fgSizer->Add( m_staticTextHhs, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
|
|
30
|
13
|
31 m_filePickerHhs = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, wxT( "Select a file" ), wxT( "*.db" ), wxDefaultPosition, wxSize( 180, -1 ), wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_SMALL|wxFLP_USE_TEXTCTRL );
|
11
|
32 fgSizer->Add( m_filePickerHhs, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
|
|
33
|
|
34 m_staticTextCcn = new wxStaticText( this, wxID_ANY, wxT( "CCN" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
35 fgSizer->Add( m_staticTextCcn, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 );
|
|
36
|
13
|
37 m_filePickerCcn = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, wxT( "Select a file" ), wxT( "*.db" ), wxDefaultPosition, wxSize( 180, -1 ), wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_SMALL|wxFLP_USE_TEXTCTRL );
|
11
|
38 fgSizer->Add( m_filePickerCcn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
|
|
39
|
|
40 bSizerTop->Add( fgSizer, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
|
|
41
|
|
42 //---
|
|
43 m_staticline = new wxStaticLine( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLI_HORIZONTAL );
|
|
44 bSizerTop->Add( m_staticline, 0, wxEXPAND|wxALL, 5 );
|
|
45
|
|
46 wxBoxSizer* bSizerBtn = new wxBoxSizer( wxHORIZONTAL );
|
|
47
|
|
48 m_buttonBuild = new wxButton( this, ID_MNGBLD, wxT( "Build" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
49 bSizerBtn->Add( m_buttonBuild, 0, wxALL, 5 );
|
|
50
|
|
51 m_buttonUpld = new wxButton( this, ID_MNGUPLD, wxT( "Upload" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
52 bSizerBtn->Add( m_buttonUpld, 0, wxALL, 5 );
|
|
53
|
|
54 m_buttonExit = new wxButton( this, ID_MNGEXIT, wxT( "Exit" ), wxDefaultPosition, wxDefaultSize, 0 );
|
|
55 bSizerBtn->Add( m_buttonExit, 0, wxALL, 5 );
|
|
56
|
|
57 bSizerTop->Add( bSizerBtn, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
|
|
58
|
|
59 this->SetSizer( bSizerTop );
|
|
60 this->Layout();
|
|
61
|
|
62 this->Centre( wxBOTH );
|
13
|
63 m_buttonUpld->Enable( false );
|
11
|
64 }
|
|
65
|
|
66 ManageDBFrame::~ManageDBFrame()
|
|
67 {
|
|
68 }
|
|
69
|
|
70 // Event Table
|
|
71 BEGIN_EVENT_TABLE( ManageDBFrame, wxFrame )
|
|
72 EVT_BUTTON( ID_MNGBLD, ManageDBFrame::OnBuild )
|
|
73 EVT_BUTTON( ID_MNGUPLD, ManageDBFrame::OnUpload )
|
|
74 EVT_BUTTON( ID_MNGEXIT, ManageDBFrame::OnExit )
|
|
75 END_EVENT_TABLE()
|
|
76
|
|
77 // Event Handler
|
|
78 void ManageDBFrame::OnBuild( wxCommandEvent& WXUNUSED(event) )
|
|
79 {
|
13
|
80 wxString hhs = m_filePickerHhs->GetPath();
|
|
81 wxString ccn = m_filePickerCcn->GetPath();
|
|
82 wxDateTime dt = m_datePicker->GetValue();
|
|
83 wxString ymd = dt.Format( wxT( "%Y%m%d" ) );
|
|
84
|
|
85 // index.db.tmp, hhs.csv.tmp(utf-8)
|
|
86 wxArrayString args;
|
|
87 args.Add( wxT( "extsql.exe" ) );
|
|
88 args.Add( hhs );
|
|
89 args.Add( ccn );
|
|
90 args.Add( ymd );
|
|
91 wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE );
|
|
92
|
|
93 // hhs.csv(cp932)
|
|
94 wxCSConv cust( wxT( "cp932" ) );
|
|
95 wxTextFile input( wxT( "hhs.csv.tmp" ) );
|
|
96 wxTextFile output( wxT( "hhs.csv" ) );
|
|
97 input.Open();
|
|
98 output.Create();
|
|
99 for ( wxString buf = input.GetFirstLine(); !input.Eof(); buf = input.GetNextLine() )
|
|
100 output.AddLine( buf );
|
|
101 input.Close();
|
|
102 output.Write( wxTextFileType_Dos, cust );
|
|
103 output.Close();
|
|
104
|
|
105 // hhs.db(encryptoed)
|
|
106 wxString key = wxT( "12345678900123456789abcdefabcdef" );
|
|
107 args.Clear();
|
|
108 args.Add( wxT( "crypto.exe" ) );
|
|
109 args.Add( wxT( "-e" ) );
|
|
110 args.Add( wxT( "hhs.csv" ) );
|
|
111 args.Add( wxT( "-k" ) );
|
|
112 args.Add( key );
|
|
113 args.Add( wxT( "-o" ) );
|
|
114 args.Add( wxT( "hhs.db" ) );
|
|
115 wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE );
|
|
116
|
11
|
117 wxMessageBox( wxT( "build done." ) );
|
13
|
118 m_buttonUpld->Enable( true );
|
11
|
119 }
|
|
120
|
|
121 void ManageDBFrame::OnUpload( wxCommandEvent& WXUNUSED(event) )
|
|
122 {
|
|
123 Upload( wxT( "index.db" ) );
|
|
124 Upload( wxT( "hhs.db" ) );
|
|
125 wxMessageBox( wxT( "upload done." ) );
|
|
126 }
|
|
127
|
|
128 void ManageDBFrame::OnExit( wxCommandEvent& WXUNUSED(event) )
|
|
129 {
|
|
130 Close();
|
|
131 }
|
|
132
|
|
133
|
|
134 // Functions
|
|
135 void ManageDBFrame::Upload( wxString file )
|
|
136 {
|
|
137 wxArrayString args;
|
|
138 args.Add( wxT( "client.exe" ) );
|
13
|
139 args.Add( wxT( "-m" ) );
|
11
|
140 args.Add( m_server );
|
|
141 args.Add( file );
|
|
142
|
13
|
143 wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE );
|
11
|
144 }
|
|
145
|
13
|
146 void ManageDBFrame::SetDBdir( wxString dir )
|
11
|
147 {
|
13
|
148 wxDateTime dt;
|
|
149 dt.ParseFormat( wxT( "20160401" ), wxT( "%Y%m%d") );
|
|
150 m_datePicker->SetValue( dt );
|
|
151 m_filePickerHhs->SetPath( dir + wxFILE_SEP_PATH + wxT( "hhs.db") );
|
|
152 m_filePickerCcn->SetPath( dir + wxFILE_SEP_PATH + wxT( "ccn.db") );
|
11
|
153 }
|
|
154
|