Mercurial > mercurial > hgweb_searcher2.cgi
view src/myframe.cpp @ 22:05f76f9f9186
index buttons move to main-frame.
author | pyon@macmini |
---|---|
date | Wed, 27 Jul 2011 19:01:09 +0900 |
parents | eb3f5c7c990f |
children | a10c2fe880f8 |
line wrap: on
line source
// Filename : mainframe.cpp // Last Change: 27-Jul-2011. // #include "wx/html/htmprint.h" #include "wx/print.h" #include "symbol.h" #include "common.h" #include "myframe.h" #include "ccnframe.h" #include "hhsdb.h" #include "htmlhelp.h" #include "main.h" #include "wx/wxsqlite3.h" // resources // the application icon (under Windows and OS/2 it is in resources and even // though we could still include the XPM here it would be unused) #if !defined(__WXMSW__) && !defined(__WXPM__) #include "sample.xpm" #include "print.xpm" #include "index.xpm" #endif ////////////////////////////////////////////////////////////////////////// // control constructor MyCmdBox::MyCmdBox( wxWindow *parent, wxWindowID id, const wxString value, const wxPoint pos, const wxSize size, long style ) : wxTextCtrl( parent, id, value, pos, size, style ) { // for search history hist = wxGetApp().searchhist; histpos = 10; // for autocomplete hhs wxString gszFile = wxGetCwd() + wxT("/db/ccn.db"); wxSQLite3Database ccndb; ccndb.Open( gszFile ); wxSQLite3Statement stmt = ccndb.PrepareStatement("SELECT hhsno FROM path ORDER BY path DESC LIMIT 500"); wxSQLite3ResultSet q = stmt.ExecuteQuery(); gszFile = wxGetCwd() + wxT("/db/hhs.db"); wxSQLite3Database hhsdb; hhsdb.Open( gszFile ); wxSQLite3ResultSet q2; wxString hhsno; while ( q.NextRow() ) { hhsno = q.GetString(0); recenthhs.Add(hhsno); wxSQLite3Statement stmt2 = hhsdb.PrepareStatement("SELECT name FROM hhs_master WHERE hhsno = ?"); stmt2.Bind( 1, hhsno ); q2 = stmt2.ExecuteQuery(); if ( !q2.IsNull(0) ) { while ( q2.NextRow() ) { recentname.Add(q2.GetString(0)); } } else { recentname.Add(wxEmptyString); } stmt2.Finalize(); } stmt.Finalize(); hhsdb.Close(); ccndb.Close(); } // destructor MyCmdBox::~MyCmdBox() { } // Event Table BEGIN_EVENT_TABLE( MyCmdBox, wxTextCtrl ) EVT_CHAR( MyCmdBox::OnChar ) EVT_TEXT_ENTER( ID_CMD, MyCmdBox::OnCmd ) END_EVENT_TABLE() // Event Handlers void MyCmdBox::OnChar( wxKeyEvent& event ) { if ( event.GetKeyCode() == 13 ) { event.Skip(); return; } if ( event.GetKeyCode() == 45 ) { // テンキーの"-"キーで一文字削除 wxString s = this->GetStringSelection(); if ( s.IsEmpty() ) { long p = this->GetInsertionPoint(); this->Remove( p-1, p ); } else { this->Cut(); } return; } MyFrame *mf = (MyFrame*)FindWindowById( ID_MAIN ); if ( event.GetKeyCode() == WXK_UP ) { // ↑ mf->m_statusBar->SetStatusText( wxEmptyString, 0 ); histpos--; if ( histpos < 0 ) histpos = 0; this->ChangeValue( hist[histpos] ); return; } else if ( event.GetKeyCode() == WXK_DOWN ) { // ↓ mf->m_statusBar->SetStatusText( wxEmptyString, 0 ); histpos++; if ( histpos >= hist.GetCount() ) { histpos = hist.GetCount(); this->Clear(); return; } this->ChangeValue( hist[histpos] ); return; } if ( event.GetKeyCode() == WXK_ESCAPE ) { // clear by ESC this->Clear(); mf->m_statusBar->SetStatusText( wxEmptyString, 0 ); return; } this->Cut(); int c = event.GetKeyCode(); if ( c >= 48 && c <= 57 ) { // [0-9] c -= 48; wxString input = this->GetLineText(0) + wxString::Format(wxT("%d"),c); if ( input.Len() < 5 ) { event.Skip(); return; } // autocomplete mf->m_statusBar->SetStatusText( wxEmptyString, 0 ); for ( int i=0; i<recenthhs.GetCount(); i++ ) { if ( recenthhs[i].StartsWith( input ) ) { this->ChangeValue( recenthhs[i] ); this->SetSelection( input.Len(), 10 ); wxString msg = wxT("もしかして... ") + recentname[i] + wxT(" ?!"); mf->m_statusBar->SetStatusText( msg, 0 ); return; } } event.Skip(); return; } event.Skip(); } void MyCmdBox::OnCmd( wxCommandEvent& event ) { wxRegEx reHhs(wxT("^0[1238][0-9]{8}$")); // 1:被保番チェック wxRegEx reCno(wxT("^[0-9]{1,2}$")); // 2:開くフォルダの番号 wxRegEx rePrint(wxT("^\\+$")); // 3:印刷するフォルダの番号 wxString cmd; cmd = this->GetLineText(0); int cond = 0; if ( reHhs.Matches( cmd ) ) cond = 1; else if ( reCno.Matches( cmd ) ) cond = 2; else if ( rePrint.Matches( cmd ) ) cond = 3; wxString htmlbody; MyFrame *mf = (MyFrame*)FindWindowById( ID_MAIN ); wxHtmlWindow *hr = (wxHtmlWindow*)FindWindowById( ID_HTML ); switch (cond) { // 被保険者番号が入力されたら case 1: { wxString hhs = cmd; mf->m_statusBar->SetStatusText( wxEmptyString, 0 ); this->SetSelection( 0, this->GetLastPosition() ); // 被保険者検索 wxString gszFile = wxGetCwd() + wxT("/db/hhs.db"); wxSQLite3Database hhsdb; hhsdb.Open( gszFile ); wxSQLite3Statement stmt = hhsdb.PrepareStatement("SELECT name FROM hhs_master WHERE hhsno = ?"); stmt.Bind( 1, hhs ); wxSQLite3ResultSet q = stmt.ExecuteQuery(); wxString name = wxT("登録なし"); if ( q.IsNull(0) ) { wxString msg = wxT("データベースに存在しない被保険者です.") + hhs; mf->m_statusBar->SetStatusText( msg, 0 ); } else { name = q.GetString(0); hist.Add( hhs ); histpos++; } stmt.Finalize(); hhsdb.Close(); // パス検索 gszFile = wxGetCwd() + wxT("/db/ccn.db"); wxSQLite3Database ccndb; ccndb.Open( gszFile ); stmt = ccndb.PrepareStatement("SELECT path FROM path WHERE hhsno = ? ORDER BY path DESC"); stmt.Bind( 1, hhs ); q = stmt.ExecuteQuery(); if ( q.IsNull(0) ) { hr->LoadPage( wxT("html/notfound.html") ); mf->m_statusBar->SetStatusText( wxT("データが存在しません."), 0 ); return; } path.Clear(); wxRegEx reDate(wxT("(^.*20[0-9]{2}.)(20[0-9]{2})([0-2][0-9])([0-9]{2})(.*$)")); int i=1; int clrflg = -1; while ( q.NextRow() ) { wxString filepath = q.GetString(0); // 氏名画像生成 wxDir dir(filepath); wxString file; if ( !dir.IsOpened() ) return; if ( clrflg == -1 ) { bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES ); if ( cout ) { wxString s = filepath + wxFILE_SEP_PATH + file; wxImage img_org( s, wxBITMAP_TYPE_JPEG ); wxImage img_name; img_name = img_org.GetSubImage( wxRect( wxPoint(328,556), wxSize(626,288) ) ); img_name = img_name.Scale( 200, 92 ); img_name.SaveFile( wxT("tmp/tmp.jpg") ); // HTML生成 htmlbody = wxT("<html><body>"); htmlbody += wxT("<table border=0>"); htmlbody += wxT("<tr bgcolor=\"#ffffcc\"><td>該当者: </td><td></td></tr>"); htmlbody += wxT("<tr><td><b>") + name + wxT("</b></td>"); htmlbody += wxT("<td> ( ") + hhs + wxT(" )") + wxT("</td></tr>"); htmlbody += wxT("</table><br /><br />"); htmlbody += wxT("<table border=0>"); htmlbody += wxT("<tr><td bgcolor=\"#ffffcc\">番号1の画像情報:</td></tr>"); htmlbody += wxT("<tr><td><img src=\"tmp/tmp.jpg\" /></td></tr>"); htmlbody += wxT("</table>"); htmlbody += wxT("<br /><br />検索結果"); htmlbody += wxT("<table border=1>"); htmlbody += wxT("<tr bgcolor=\"#ffcc33\"><th>番号</th><th>日付</th><th>フォルダ</th></tr>"); } clrflg = 1; } path.Add(filepath); wxString date = filepath; reDate.ReplaceAll( &date, wxT("\\2-\\3-\\4") ); if ( clrflg ) { htmlbody += wxT("<tr bgcolor=\"#ffffcc\">"); clrflg = 0; } else { htmlbody += wxT("<tr bgcolor=\"#ffff99\">"); clrflg = 1; } htmlbody += wxT("<td align=\"center\">") + wxString::Format(wxT("%d"),i++) + wxT("</td>"); // 番号 htmlbody += wxT("<td>") + date + wxT("</td>"); // 日付 htmlbody += wxT("<td>") + q.GetString(0) + wxT("</td></tr>"); // フォルダパス } stmt.Finalize(); ccndb.Close(); path.Shrink(); htmlbody += wxT("</table>"); htmlbody += wxT("<br />"); htmlbody += wxT("<div>"); htmlbody += wxT("テンキーの「+」ボタンで番号1の画像を印刷できます.<br />"); htmlbody += wxT("フォルダを開くには,番号を入力してください.<br />"); htmlbody += wxT("他の被保険者を検索するには,被保番を入力してください."); htmlbody += wxT("</div>"); htmlbody += wxT("</body></html>"); hr->SetPage( htmlbody ); break; } // フォルダ表示 case 2: { this->SetSelection( 0, this->GetLastPosition() ); long val; cmd.ToLong( &val, 10 ); val--; if ( path.IsEmpty() || val < 0 || val > path.GetCount()-1 ) { mf->m_statusBar->SetStatusText( wxT("不適切な入力です.警告コード2"), 0 ); break; } wxString execmd = wxT("explorer ") + path[val]; wxExecute( execmd ); mf->m_statusBar->SetStatusText( wxEmptyString, 0 ); WriteLog( cmd, path[val] ); break; } // ファイル印刷 case 3: { this->SetSelection( 0, this->GetLastPosition() ); if ( path.IsEmpty() ) { mf->m_statusBar->SetStatusText( wxT("不適切な入力です.警告コード3"), 0 ); break; } PrintImages( path[0] ); WriteLog( cmd, path[0] ); break; } // 制御用コマンド case 0: { path.Clear(); if ( cmd.Cmp(wxT("s")) == 0 ) { hr->LoadPage( wxT("html/start.html") ); this->ChangeValue( wxEmptyString ); mf->m_statusBar->SetStatusText( wxEmptyString, 0 ); return; } if ( cmd.Cmp(wxT("c")) == 0 ) { hr->LoadPage( wxT("Searcher2.conf") ); this->ChangeValue( wxEmptyString ); mf->m_statusBar->SetStatusText( wxEmptyString, 0 ); return; } if ( cmd.Cmp(wxT("t")) == 0 ) { hr->LoadPage( wxT("html/todo.html") ); this->ChangeValue( wxEmptyString ); mf->m_statusBar->SetStatusText( wxEmptyString, 0 ); return; } if ( cmd.Cmp(wxT("l")) == 0 ) { hr->LoadPage( wxT("tmp/log.txt") ); this->ChangeValue( wxEmptyString ); mf->m_statusBar->SetStatusText( wxEmptyString, 0 ); return; } if ( cmd.Cmp(wxT("**")) == 0 ) { mf->m_statusBar->SetStatusText( wxT("Now Saving..."), 0 ); mf->Close(); return; } mf->m_statusBar->SetStatusText( wxT("不適切な入力です."), 0 ); this->SetSelection( 0, this->GetLastPosition() ); break; } // default: { break; } } } // functions void MyCmdBox::PrintImages( wxString& path ) { wxHtmlPrintout hpout( wxT("Searcher2") ); hpout.SetMargins( 0,0,0,0,0 ); wxPrintDialogData pd; wxPrinter p( &pd ); wxDir dir(path); wxString file; if ( !dir.IsOpened() ) return; bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES ); bool mask_flg = true; wxRect cmname( wxPoint(156,224), wxSize(1204,122) ); wxRect cmno( wxPoint(856,1024), wxSize(1060,598) ); while ( cout ) { file = path + wxFILE_SEP_PATH + file; file.Replace( wxT("\\"), wxT("/") ); wxString html; if ( mask_flg ) { // 1枚目はマスクする wxImage img_org( file, wxBITMAP_TYPE_JPEG ); img_org.SetRGB( cmname, 255, 255, 255 ); img_org.SetRGB( cmno, 255, 255, 255 ); img_org.SaveFile( wxT("tmp/tmp.jpg") ); html = html + wxT("<html><body>"); html = html + wxT("<img src=\"tmp/tmp.jpg\" width=\"750\" height=\"1060\"/>"); html = html + wxT("</body></html>"); hpout.SetHtmlText( html, wxEmptyString, false ); p.Print( NULL, &hpout, true ); pd = p.GetPrintDialogData(); mask_flg = false; } else { html = html + wxT("<html><body>"); html = html + wxT("<img src=\"") + file + wxT("\" width=\"750\" height=\"1060\"/>"); html = html + wxT("</body></html>"); hpout.SetHtmlText( html, wxEmptyString, false ); p.Print( NULL, &hpout, false ); } cout = dir.GetNext( &file ); } return; } // 検索履歴をログに保存 void MyCmdBox::WriteLog( wxString& cmd, wxString& path ) { wxString logfn = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("log.txt"); wxTextFile logFile; logFile.Open( logfn ); wxDateTime now = wxDateTime::Now(); wxString log = now.Format( wxT("%Y-%m-%d %H:%M:%S") ) + wxT(" ") + cmd + wxT(" ") + path; logFile.AddLine( log ); logFile.Write(); logFile.Close(); return; } ////////////////////////////////////////////////////////////////////////// // frame constructor MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title ) : wxFrame( parent, id, title ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); // set the frame icon SetIcon(wxICON(sample)); // メニューバー m_menubar = new wxMenuBar(); m_menuFile = new wxMenu(); wxMenu *menuMaintain = new wxMenu(); m_menuFile->AppendSubMenu( menuMaintain, wxT("メンテナンス") ); menuMaintain->Append( ID_MUPHHS, wxT("被保険者DB更新"), wxT("Update hhs-db") ); menuMaintain->Append( ID_MDBBKUP, wxT("データベースバックアップ"), wxT("Backup DBs") ); menuMaintain->Append( ID_MDBOPT, wxT("データベース最適化"), wxT("Optimize DBs") ); menuMaintain->Enable( ID_MDBOPT, false ); menuMaintain->Append( ID_MCHKHHS, wxT("被保者整合性チェック"), wxT("Check hhs") ); m_menuFile->AppendSeparator(); //---- wxMenu *menuOpendir = new wxMenu(); m_menuFile->AppendSubMenu( menuOpendir, wxT("フォルダを開く") ); menuOpendir->Append( ID_MOPAD, wxT("アプリケーションフォルダ"), wxT("Open App Folder") ); menuOpendir->Append( ID_MOPDD, wxT("データフォルダ"), wxT("Open Data Folder") ); m_menuFile->AppendSeparator(); //---- m_menuFile->Append( wxID_EXIT, wxT("終了(&X)\tAlt-X"), wxT("Quit this program") ); m_menuHelp = new wxMenu(); m_menuHelp->Append( ID_MHELP, wxT("&Help"), wxT("Show help") ); m_menuHelp->Append( wxID_ABOUT, wxT("&About...\tF1"), wxT("Show about dialog") ); // now append the freshly created menu to the menu bar... m_menubar->Append( m_menuFile, wxT("ファイル(&F)") ); m_menubar->Append( m_menuHelp, wxT("ヘルプ(&H)") ); this->SetMenuBar( m_menubar ); // ツールバー //m_toolBar = new wxToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL|wxNO_BORDER ); //wxBitmap bmpPrint( print_xpm ); //wxBitmap bmpIndex( index_xpm ); // ステータスバー int widths[] = { -1, 120, 100 }; m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP ); m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths ); m_statusBar->SetStatusText( wxEmptyString, 0 ); wxBoxSizer* bSizer; bSizer = new wxBoxSizer( wxVERTICAL ); m_panel = new wxPanel( this ); wxBoxSizer* bSizerPanel; bSizerPanel = new wxBoxSizer( wxVERTICAL ); // controls here m_panelHead = new wxPanel( m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize ); wxBoxSizer* bSizerHead; bSizerHead = new wxBoxSizer( wxHORIZONTAL ); bSizerHead->AddStretchSpacer( 1 ); // spacer m_staticTextIdx = new wxStaticText( m_panelHead, wxID_ANY, wxT("インデックス"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerHead->Add( m_staticTextIdx, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); m_btnLsCcn = new wxButton( m_panelHead, ID_LSCCN, wxT("一覧"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerHead->Add( m_btnLsCcn, 0, wxALL, 5 ); m_btnPrevThu = new wxButton( m_panelHead, ID_PRVTHU, wxT("<< 前木"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerHead->Add( m_btnPrevThu, 0, wxALL, 5 ); m_datePicker = new wxDatePickerCtrl( m_panelHead, ID_DTPICKER, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY ); bSizerHead->Add( m_datePicker, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 ); m_btnNextThu = new wxButton( m_panelHead, ID_NXTTHU, wxT("次木 >>"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerHead->Add( m_btnNextThu, 0, wxALL, 5 ); m_btnMkIdx = new wxButton( m_panelHead, ID_MKIDX, wxT("作成"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerHead->Add( m_btnMkIdx, 0, wxALL, 5 ); m_panelHead->SetSizer( bSizerHead ); m_panelHead->Layout(); bSizerHead->Fit( m_panelHead ); // 検索結果Html m_html = new wxHtmlWindow( m_panel, ID_HTML, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO ); m_html->LoadPage( wxT("html/start.html") ); // コマンドライン m_panelCmd = new wxPanel( m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize ); wxBoxSizer* bSizerCmd; bSizerCmd = new wxBoxSizer( wxHORIZONTAL ); m_staticTextCmd = new wxStaticText( m_panelCmd, wxID_ANY, wxT("コマンド?"), wxDefaultPosition, wxDefaultSize, 0 ); bSizerCmd->Add( m_staticTextCmd, 0, wxALL, 5 ); m_cmdbox = new MyCmdBox( m_panelCmd, ID_CMD, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER ); bSizerCmd->Add( m_cmdbox, 1, wxALL, 3 ); m_cmdbox->SetFocus(); m_panelCmd->SetSizer( bSizerCmd ); m_panelCmd->Layout(); bSizerCmd->Fit( m_panelCmd ); bSizerPanel->Add( m_panelHead, 0, wxEXPAND|wxTOP, 1 ); bSizerPanel->Add( m_html, 1, wxEXPAND|wxALL, 1 ); bSizerPanel->Add( m_panelCmd, 0, wxEXPAND|wxALL, 0 ); m_panel->SetSizer( bSizerPanel ); m_panel->Layout(); bSizerPanel->Fit( m_panel ); bSizer->Add( m_panel, 1, wxEXPAND|wxALL, 0 ); this->SetSizer( bSizer ); this->Layout(); this->SetMinSize( wxSize( 550, 600 ) ); } // destructor MyFrame::~MyFrame() { } // Event Table BEGIN_EVENT_TABLE( MyFrame, wxFrame ) EVT_SIZE( MyFrame::OnSize ) EVT_MOVE( MyFrame::OnMove ) EVT_MENU( wxID_EXIT, MyFrame::OnQuit ) EVT_MENU( wxID_ABOUT, MyFrame::OnAbout ) EVT_MENU( ID_MUPHHS, MyFrame::OnUpdateHhsDb ) EVT_MENU( ID_MDBBKUP, MyFrame::OnBackupDB ) EVT_MENU( ID_MDBOPT, MyFrame::OnOptimizeDB ) EVT_MENU( ID_MCHKHHS, MyFrame::OnCheckHhs ) EVT_MENU( ID_MOPAD, MyFrame::OnOpenAppDir ) EVT_MENU( ID_MOPDD, MyFrame::OnOpenDataDir ) EVT_MENU( ID_MHELP, MyFrame::OnHelp ) EVT_BUTTON( ID_PRVTHU, MyFrame::OnPrevThu ) EVT_BUTTON( ID_NXTTHU, MyFrame::OnNextThu ) EVT_BUTTON( ID_MKIDX, MyFrame::OnMkIndex ) EVT_BUTTON( ID_LSCCN, MyFrame::OnListCcn ) EVT_CLOSE( MyFrame::SaveConfig ) END_EVENT_TABLE() // Event Handlers /* サイズ変更 */ void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event)) { wxRect r = this->GetRect(); int w = r.GetWidth(); int h = r.GetHeight(); SetStatusText( wxString::Format(wxT("%dx%d"),w,h), 2 ); return; } /* ウィンドウ移動 */ void MyFrame::OnMove(wxMoveEvent& WXUNUSED(event)) { wxRect r = this->GetRect(); int x = r.GetX(); int y = r.GetY(); SetStatusText( wxString::Format(wxT("(%d,%d)"),x,y), 2 ); return; } /* 終了 */ void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event)) { Close(true); } /* オンラインヘルプ */ void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event)) { HtmlHelpFrame *f = (HtmlHelpFrame*)FindWindowById( ID_HELP ); if ( f == NULL ) { HtmlHelpFrame *helpframe = new HtmlHelpFrame( wxT("Online Help"), ID_HELP ); helpframe->SetSize(600,600); helpframe->Show(true); } else { f->Raise(); } } /* バージョン情報 */ void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event)) { wxSQLite3Database sqlite; wxMessageBox( wxString::Format( wxT("Version %d.%d ( build %d ) by %s\n") wxT("with SQLite library %s\n") wxT("running under %s."), VER, REV, BLD, wxVERSION_STRING, sqlite.GetVersion().c_str(), wxGetOsDescription().c_str() ), wxT("About this program"), wxOK | wxICON_INFORMATION, this ); } // 前木 void MyFrame::OnPrevThu(wxCommandEvent& WXUNUSED(event)) { wxDateTime dt = m_datePicker->GetValue(); wxDateSpan ds( 0, 0, 0, 1 ); dt -= ds; dt.SetToPrevWeekDay( wxDateTime::Thu ); m_datePicker->SetValue( dt ); } // 次木 void MyFrame::OnNextThu(wxCommandEvent& WXUNUSED(event)) { wxDateTime dt = m_datePicker->GetValue(); wxDateSpan ds( 0, 0, 0, 1 ); dt += ds; dt.SetToNextWeekDay( wxDateTime::Thu ); m_datePicker->SetValue( dt ); } /* インデックス作成 */ void MyFrame::OnMkIndex(wxCommandEvent& WXUNUSED(event)) { wxDateTime dt = m_datePicker->GetValue(); wxString month = dt.Format(wxT("%m")); wxString year = dt.Format(wxT("%Y")); if ( month.IsSameAs(wxT("01")) || month.IsSameAs(wxT("02")) || month.IsSameAs(wxT("03")) ) { long y; year.ToLong( &y, 10 ); y--; year = wxString::Format(wxT("%d"),y); } wxString pathroot = wxGetApp().rootdir + wxFILE_SEP_PATH + year + dt.Format(wxT("\\%Y%m%d")); wxDir rootd(pathroot); if ( !wxDir::Exists(pathroot) ) { wxMessageBox( wxT("フォルダが存在しません.")+pathroot ); return; } wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 200, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE ); pd.SetSize( wxSize(320,140) ); int count=0; wxString ccndir; bool cont = rootd.GetFirst( &ccndir, wxT("*.*"), wxDIR_DIRS ); while ( cont ) { wxString gszFile = wxGetCwd() + wxT("/db/ccn.db"); wxSQLite3Database ccndb; ccndb.Open( gszFile ); wxSQLite3Statement stmt = ccndb.PrepareStatement("INSERT OR REPLACE INTO ccn VALUES( ?, datetime('now','localtime') )"); stmt.Bind( 1, dt.Format(wxT("%Y-%m-%d")) ); stmt.ExecuteQuery(); stmt.Finalize(); wxDir ccnd( pathroot + wxFILE_SEP_PATH + ccndir ); if ( !ccnd.IsOpened() ) return; wxString hhsdir; bool c = ccnd.GetFirst( &hhsdir, wxT("*.*"), wxDIR_DIRS ); wxRegEx reHhs(wxT("^0[1238][0-9]{8}$")); // 被保番チェック while ( c ) { if ( reHhs.Matches(hhsdir) ) { wxString path = pathroot + wxFILE_SEP_PATH + ccndir + wxFILE_SEP_PATH + hhsdir; stmt = ccndb.PrepareStatement("INSERT OR REPLACE INTO path VALUES( ?, ? )"); stmt.Bind( 1, hhsdir ); stmt.Bind( 2, path ); stmt.ExecuteQuery(); stmt.Finalize(); } c = ccnd.GetNext(&hhsdir); pd.Update( count++, hhsdir+wxT("@")+ccndir+wxT("を処理しました.") ); } ccndb.Close(); cont = rootd.GetNext(&ccndir); } wxMessageBox(wxT("インデックス作成が終了しました.")); } /* インデックス一覧 */ void MyFrame::OnListCcn(wxCommandEvent& WXUNUSED(event)) { FrameCcn *fc = new FrameCcn( NULL, ID_CCN, wxT("Index Viewer"), wxDefaultPosition, wxDefaultSize, wxCAPTION|wxFRAME_NO_TASKBAR|wxTAB_TRAVERSAL ); fc->Show(true); } /* 被保険者DB更新 */ void MyFrame::OnUpdateHhsDb(wxCommandEvent& WXUNUSED(event)) { FrameHhsDB *f = (FrameHhsDB*)FindWindowById( ID_HHSDB ); if ( f == NULL ) { FrameHhsDB *hhsdb = new FrameHhsDB( this, ID_HHSDB ); hhsdb->Show(true); } else { f->Raise(); } return; } /* 被保険者整合性チェック */ void MyFrame::OnCheckHhs(wxCommandEvent& WXUNUSED(event)) { wxString logfn = wxGetCwd() + wxT("/tmp/checkhhs.log"); wxTextFile logFile; logFile.Open( logfn ); logFile.Clear(); wxString gszFile = wxGetCwd() + wxT("/db/ccn.db"); wxSQLite3Database ccndb; ccndb.Open( gszFile ); wxSQLite3Statement stmt = ccndb.PrepareStatement("ATTACH 'db/hhs.db' AS hhs"); wxSQLite3ResultSet q = stmt.ExecuteQuery(); stmt = ccndb.PrepareStatement("SELECT hhsno FROM path EXCEPT SELECT hhsno FROM hhs.hhs_master"); q = stmt.ExecuteQuery(); while ( q.NextRow() ) { logFile.AddLine( q.GetString(0) ); } stmt.Finalize(); ccndb.Close(); logFile.Write(); logFile.Close(); wxString msg = wxT("結果を ") + logfn + wxT(" に保存しました."); wxMessageBox( msg ); return; } /* DBバックアップ */ void MyFrame::OnBackupDB(wxCommandEvent& WXUNUSED(event)) { wxDateTime now = wxDateTime::Now(); wxString nowstr = now.Format(wxT("%Y%m%d%H%M%S")); wxString org = wxGetCwd() + wxT("/db/ccn.db"); wxString bk = wxGetCwd() + wxT("/db/") + nowstr + wxT("_ccn.db"); wxCopyFile( org, bk, 0 ); org = wxGetCwd() + wxT("/db/hhs.db"); bk = wxGetCwd() + wxT("/db/") + nowstr + wxT("_hhs.db"); wxCopyFile( org, bk, 0 ); wxMessageBox( wxT("バックアップ終了.") ); return; } /* DB最適化 */ void MyFrame::OnOptimizeDB(wxCommandEvent& WXUNUSED(event)) { return; } /* アプリケーションフォルダを開く */ void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event)) { wxStandardPaths appdir; wxString execmd = wxT("explorer ") + appdir.GetDataDir(); wxExecute( execmd ); return; } /* データフォルダを開く */ void MyFrame::OnOpenDataDir(wxCommandEvent& WXUNUSED(event)) { wxString datadir = wxGetApp().rootdir; wxString execmd = wxT("explorer ") + datadir; wxExecute( execmd ); return; } /* 設定を保存 */ void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event)) { if ( !IsIconized() && !IsMaximized() ) { wxGetApp().rect = this->GetRect(); } int i = m_cmdbox->hist.GetCount(); for ( int j=0; j<5; j++ ) { wxGetApp().searchhist[j] = m_cmdbox->hist[--i]; } Destroy(); }