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