Mercurial > mercurial > hgweb_rsearcher.cgi
comparison src/mngdb.cpp @ 13:f5ffc34f045a
manage DB.
| author | pyon@macmini |
|---|---|
| date | Wed, 14 Nov 2018 19:43:40 +0900 |
| parents | 799b6008db8e |
| children | c1dc1fcee7fe |
comparison
equal
deleted
inserted
replaced
| 12:240752cbe11b | 13:f5ffc34f045a |
|---|---|
| 1 // Filename : mngdeb.cpp | 1 // Filename : mngdeb.cpp |
| 2 // Last Change: 2018-11-09 金 13:35:54. | 2 // Last Change: 2018-11-14 水 13:48:58. |
| 3 // | 3 // |
| 4 | 4 |
| 5 #include <wx/datetime.h> | |
| 6 #include <wx/textfile.h> | |
| 5 #include "id.h" | 7 #include "id.h" |
| 6 #include "mngdb.h" | 8 #include "mngdb.h" |
| 7 | 9 |
| 8 ManageDBFrame::ManageDBFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) | 10 ManageDBFrame::ManageDBFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) |
| 9 : wxFrame( parent, id, title, pos, size, style ) | 11 : wxFrame( parent, id, title, pos, size, style ) |
| 10 { | 12 { |
| 13 this->SetBackgroundColour( wxColour( 140, 240, 140 ) ); | |
| 11 this->SetSizeHints( wxDefaultSize, wxDefaultSize ); | 14 this->SetSizeHints( wxDefaultSize, wxDefaultSize ); |
| 12 | 15 |
| 13 wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); | 16 wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL ); |
| 14 | 17 |
| 15 wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 0, 2, 0, 0 ); | 18 wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 0, 2, 0, 0 ); |
| 17 fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); | 20 fgSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED ); |
| 18 | 21 |
| 19 m_staticTextDate = new wxStaticText( this, wxID_ANY, wxT( "Date" ), wxDefaultPosition, wxDefaultSize, 0 ); | 22 m_staticTextDate = new wxStaticText( this, wxID_ANY, wxT( "Date" ), wxDefaultPosition, wxDefaultSize, 0 ); |
| 20 fgSizer->Add( m_staticTextDate, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 ); | 23 fgSizer->Add( m_staticTextDate, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 ); |
| 21 | 24 |
| 22 m_datePicker = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY ); | 25 m_datePicker = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxSize( 180, -1 ), wxDP_DROPDOWN|wxDP_SHOWCENTURY ); |
| 23 fgSizer->Add( m_datePicker, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | 26 fgSizer->Add( m_datePicker, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); |
| 24 | 27 |
| 25 m_staticTextHhs = new wxStaticText( this, wxID_ANY, wxT( "HHS" ), wxDefaultPosition, wxDefaultSize, 0 ); | 28 m_staticTextHhs = new wxStaticText( this, wxID_ANY, wxT( "HHS" ), wxDefaultPosition, wxDefaultSize, 0 ); |
| 26 fgSizer->Add( m_staticTextHhs, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); | 29 fgSizer->Add( m_staticTextHhs, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 ); |
| 27 | 30 |
| 28 m_filePickerHhs = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, wxT( "Select a file" ), wxT( "*.db" ), wxDefaultPosition, wxDefaultSize, wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_SMALL|wxFLP_USE_TEXTCTRL ); | 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 ); |
| 29 fgSizer->Add( m_filePickerHhs, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); | 32 fgSizer->Add( m_filePickerHhs, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 ); |
| 30 | 33 |
| 31 m_staticTextCcn = new wxStaticText( this, wxID_ANY, wxT( "CCN" ), wxDefaultPosition, wxDefaultSize, 0 ); | 34 m_staticTextCcn = new wxStaticText( this, wxID_ANY, wxT( "CCN" ), wxDefaultPosition, wxDefaultSize, 0 ); |
| 32 fgSizer->Add( m_staticTextCcn, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 ); | 35 fgSizer->Add( m_staticTextCcn, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 ); |
| 33 | 36 |
| 34 m_filePickerCcn = new wxFilePickerCtrl( this, wxID_ANY, wxEmptyString, wxT( "Select a file" ), wxT( "*.db" ), wxDefaultPosition, wxDefaultSize, wxFLP_FILE_MUST_EXIST|wxFLP_OPEN|wxFLP_SMALL|wxFLP_USE_TEXTCTRL ); | 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 ); |
| 35 fgSizer->Add( m_filePickerCcn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); | 38 fgSizer->Add( m_filePickerCcn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 ); |
| 36 | 39 |
| 37 bSizerTop->Add( fgSizer, 0, wxALIGN_CENTER_HORIZONTAL, 5 ); | 40 bSizerTop->Add( fgSizer, 0, wxALIGN_CENTER_HORIZONTAL, 5 ); |
| 38 | 41 |
| 39 //--- | 42 //--- |
| 55 | 58 |
| 56 this->SetSizer( bSizerTop ); | 59 this->SetSizer( bSizerTop ); |
| 57 this->Layout(); | 60 this->Layout(); |
| 58 | 61 |
| 59 this->Centre( wxBOTH ); | 62 this->Centre( wxBOTH ); |
| 63 m_buttonUpld->Enable( false ); | |
| 60 } | 64 } |
| 61 | 65 |
| 62 ManageDBFrame::~ManageDBFrame() | 66 ManageDBFrame::~ManageDBFrame() |
| 63 { | 67 { |
| 64 } | 68 } |
| 71 END_EVENT_TABLE() | 75 END_EVENT_TABLE() |
| 72 | 76 |
| 73 // Event Handler | 77 // Event Handler |
| 74 void ManageDBFrame::OnBuild( wxCommandEvent& WXUNUSED(event) ) | 78 void ManageDBFrame::OnBuild( wxCommandEvent& WXUNUSED(event) ) |
| 75 { | 79 { |
| 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 | |
| 76 wxMessageBox( wxT( "build done." ) ); | 117 wxMessageBox( wxT( "build done." ) ); |
| 118 m_buttonUpld->Enable( true ); | |
| 77 } | 119 } |
| 78 | 120 |
| 79 void ManageDBFrame::OnUpload( wxCommandEvent& WXUNUSED(event) ) | 121 void ManageDBFrame::OnUpload( wxCommandEvent& WXUNUSED(event) ) |
| 80 { | 122 { |
| 81 ClearServer(); | |
| 82 Upload( wxT( "index.db" ) ); | 123 Upload( wxT( "index.db" ) ); |
| 83 Upload( wxT( "hhs.db" ) ); | 124 Upload( wxT( "hhs.db" ) ); |
| 84 UpdateDB(); | |
| 85 wxMessageBox( wxT( "upload done." ) ); | 125 wxMessageBox( wxT( "upload done." ) ); |
| 86 } | 126 } |
| 87 | 127 |
| 88 void ManageDBFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) | 128 void ManageDBFrame::OnExit( wxCommandEvent& WXUNUSED(event) ) |
| 89 { | 129 { |
| 94 // Functions | 134 // Functions |
| 95 void ManageDBFrame::Upload( wxString file ) | 135 void ManageDBFrame::Upload( wxString file ) |
| 96 { | 136 { |
| 97 wxArrayString args; | 137 wxArrayString args; |
| 98 args.Add( wxT( "client.exe" ) ); | 138 args.Add( wxT( "client.exe" ) ); |
| 99 args.Add( wxT( "-a" ) ); | 139 args.Add( wxT( "-m" ) ); |
| 100 args.Add( m_server ); | 140 args.Add( m_server ); |
| 101 args.Add( file ); | 141 args.Add( file ); |
| 102 | 142 |
| 103 wxExecute( wxJoin( args, ' ', '\\' ) ); | 143 wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE ); |
| 104 } | 144 } |
| 105 | 145 |
| 106 void ManageDBFrame::ClearServer( void ) | 146 void ManageDBFrame::SetDBdir( wxString dir ) |
| 107 { | 147 { |
| 108 // go-server get /clean -> rm -f upload/* | 148 wxDateTime dt; |
| 109 wxArrayString args; | 149 dt.ParseFormat( wxT( "20160401" ), wxT( "%Y%m%d") ); |
| 110 args.Add( wxT( "client.exe" ) ); | 150 m_datePicker->SetValue( dt ); |
| 111 args.Add( m_server ); | 151 m_filePickerHhs->SetPath( dir + wxFILE_SEP_PATH + wxT( "hhs.db") ); |
| 112 | 152 m_filePickerCcn->SetPath( dir + wxFILE_SEP_PATH + wxT( "ccn.db") ); |
| 113 wxExecute( wxJoin( args, ' ', '\\' ) ); | |
| 114 } | 153 } |
| 115 | 154 |
| 116 void ManageDBFrame::UpdateDB( void ) | |
| 117 { | |
| 118 // go-server get /mangedb -> mv upload/xxx db/index.db | |
| 119 // mv upload/yyy db/hhs.db | |
| 120 wxArrayString args; | |
| 121 args.Add( wxT( "client.exe" ) ); | |
| 122 args.Add( m_server ); | |
| 123 | |
| 124 wxExecute( wxJoin( args, ' ', '\\' ) ); | |
| 125 } | |
| 126 |
