diff src/mngdb.cpp @ 13:f5ffc34f045a

manage DB.
author pyon@macmini
date Wed, 14 Nov 2018 19:43:40 +0900
parents 799b6008db8e
children c1dc1fcee7fe
line wrap: on
line diff
--- a/src/mngdb.cpp	Tue Nov 13 21:11:20 2018 +0900
+++ b/src/mngdb.cpp	Wed Nov 14 19:43:40 2018 +0900
@@ -1,13 +1,16 @@
 // Filename   : mngdeb.cpp
-// Last Change: 2018-11-09 金 13:35:54.
+// Last Change: 2018-11-14 水 13:48:58.
 //
 
+#include <wx/datetime.h>
+#include <wx/textfile.h>
 #include "id.h"
 #include "mngdb.h"
 
 ManageDBFrame::ManageDBFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) 
 	: wxFrame( parent, id, title, pos, size, style )
 {
+	this->SetBackgroundColour( wxColour( 140, 240, 140 ) );
 	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
 	
 	wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL );
@@ -19,19 +22,19 @@
 	m_staticTextDate = new wxStaticText( this, wxID_ANY, wxT( "Date" ), wxDefaultPosition, wxDefaultSize, 0 );
 	fgSizer->Add( m_staticTextDate, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 );
 	
-	m_datePicker = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY );
+	m_datePicker = new wxDatePickerCtrl( this, wxID_ANY, wxDefaultDateTime, wxDefaultPosition, wxSize( 180, -1 ), wxDP_DROPDOWN|wxDP_SHOWCENTURY );
 	fgSizer->Add( m_datePicker, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
 	
 	m_staticTextHhs = new wxStaticText( this, wxID_ANY, wxT( "HHS" ), wxDefaultPosition, wxDefaultSize, 0 );
 	fgSizer->Add( m_staticTextHhs, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxALIGN_RIGHT, 5 );
 	
-	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 );
+	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 );
 	fgSizer->Add( m_filePickerHhs, 0, wxALL|wxALIGN_CENTER_VERTICAL|wxEXPAND, 5 );
 	
 	m_staticTextCcn = new wxStaticText( this, wxID_ANY, wxT( "CCN" ), wxDefaultPosition, wxDefaultSize, 0 );
 	fgSizer->Add( m_staticTextCcn, 0, wxALL|wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL, 5 );
 	
-	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 );
+	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 );
 	fgSizer->Add( m_filePickerCcn, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
 	
 	bSizerTop->Add( fgSizer, 0, wxALIGN_CENTER_HORIZONTAL, 5 );
@@ -57,6 +60,7 @@
 	this->Layout();
 	
 	this->Centre( wxBOTH );
+	m_buttonUpld->Enable( false );
 }
 
 ManageDBFrame::~ManageDBFrame()
@@ -73,15 +77,51 @@
 // Event Handler
 void ManageDBFrame::OnBuild( wxCommandEvent& WXUNUSED(event) )
 {
+	wxString hhs = m_filePickerHhs->GetPath();
+	wxString ccn = m_filePickerCcn->GetPath();
+	wxDateTime dt = m_datePicker->GetValue();
+	wxString ymd = dt.Format( wxT( "%Y%m%d" ) );
+
+	// index.db.tmp, hhs.csv.tmp(utf-8)
+	wxArrayString args;
+	args.Add( wxT( "extsql.exe" ) );
+	args.Add( hhs );
+	args.Add( ccn );
+	args.Add( ymd );
+	wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE );
+
+	// hhs.csv(cp932)
+    wxCSConv cust( wxT( "cp932" ) );
+	wxTextFile input( wxT( "hhs.csv.tmp" ) );
+	wxTextFile output( wxT( "hhs.csv" ) );
+    input.Open();
+    output.Create();
+    for ( wxString buf = input.GetFirstLine(); !input.Eof(); buf = input.GetNextLine() )
+		output.AddLine( buf );
+    input.Close();
+	output.Write( wxTextFileType_Dos, cust );
+    output.Close();
+
+	// hhs.db(encryptoed)
+	wxString key = wxT( "12345678900123456789abcdefabcdef" );
+	args.Clear();
+	args.Add( wxT( "crypto.exe" ) );
+	args.Add( wxT( "-e" ) );
+	args.Add( wxT( "hhs.csv" ) );
+	args.Add( wxT( "-k" ) );
+	args.Add( key );
+	args.Add( wxT( "-o" ) );
+	args.Add( wxT( "hhs.db" ) );
+	wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE );
+
 	wxMessageBox( wxT( "build done." ) );
+	m_buttonUpld->Enable( true );
 }
 
 void ManageDBFrame::OnUpload( wxCommandEvent& WXUNUSED(event) )
 {
-	ClearServer();
 	Upload( wxT( "index.db" ) );
 	Upload( wxT( "hhs.db" ) );
-	UpdateDB();
 	wxMessageBox( wxT( "upload done." ) );
 }
 
@@ -96,31 +136,19 @@
 {
 	wxArrayString args;
 	args.Add( wxT( "client.exe" ) );
-	args.Add( wxT( "-a" ) );
+	args.Add( wxT( "-m" ) );
 	args.Add( m_server );
 	args.Add( file );
 
-	wxExecute( wxJoin( args, ' ', '\\' ) );
+	wxExecute( wxJoin( args, ' ', '\\' ), wxEXEC_SYNC|wxEXEC_HIDE_CONSOLE );
 }
 
-void ManageDBFrame::ClearServer( void )
+void ManageDBFrame::SetDBdir( wxString dir )
 {
-// go-server get /clean -> rm -f upload/*
-	wxArrayString args;
-	args.Add( wxT( "client.exe" ) );
-	args.Add( m_server );
-
-	wxExecute( wxJoin( args, ' ', '\\' ) );
+	wxDateTime dt;
+	dt.ParseFormat( wxT( "20160401" ), wxT( "%Y%m%d") );
+	m_datePicker->SetValue( dt );
+	m_filePickerHhs->SetPath( dir + wxFILE_SEP_PATH + wxT( "hhs.db") );
+	m_filePickerCcn->SetPath( dir + wxFILE_SEP_PATH + wxT( "ccn.db") );
 }
 
-void ManageDBFrame::UpdateDB( void )
-{
-// go-server get /mangedb -> mv upload/xxx db/index.db
-//                           mv upload/yyy db/hhs.db
-	wxArrayString args;
-	args.Add( wxT( "client.exe" ) );
-	args.Add( m_server );
-
-	wxExecute( wxJoin( args, ' ', '\\' ) );
-}
-