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