comparison src/myframe.cpp @ 0:c174ac668e9f

First commit ! (ver2.8)
author pyon@macmini
date Tue, 05 Apr 2011 18:44:57 +0900
parents
children e0cf49906039
comparison
equal deleted inserted replaced
-1:000000000000 0:c174ac668e9f
1 // Filename : mainframe.cpp
2 // Last Change: 31-Mar-2011.
3 //
4
5 #include "symbol.h"
6 #include "common.h"
7 #include "myframe.h"
8 #include "hhsdb.h"
9 #include "htmlhelp.h"
10 #include "main.h"
11 #include "wx/wxsqlite3.h"
12
13 // resources
14 // the application icon (under Windows and OS/2 it is in resources and even
15 // though we could still include the XPM here it would be unused)
16 #if !defined(__WXMSW__) && !defined(__WXPM__)
17 #include "sample.xpm"
18 #include "print.xpm"
19 #include "index.xpm"
20 #endif
21
22 //////////////////////////////////////////////////////////////////////////
23 // control constructor
24 MyCmdBox::MyCmdBox( wxWindow *parent, wxWindowID id, const wxString value, const wxPoint pos, const wxSize size, long style )
25 : wxTextCtrl( parent, id, value, pos, size, style )
26 {
27 // for search history
28 hist = wxGetApp().searchhist;
29 histpos = 5;
30
31 // for autocomplete hhs
32 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
33 wxSQLite3Database ccndb;
34 ccndb.Open( gszFile );
35 wxSQLite3Statement stmt = ccndb.PrepareStatement("SELECT hhsno FROM path ORDER BY path DESC LIMIT 500");
36 wxSQLite3ResultSet q = stmt.ExecuteQuery();
37
38 gszFile = wxGetCwd() + wxT("/db/hhs.db");
39 wxSQLite3Database hhsdb;
40 hhsdb.Open( gszFile );
41 wxSQLite3ResultSet q2;
42
43 wxString hhsno;
44 while ( q.NextRow() ) {
45 hhsno = q.GetString(0);
46
47 recenthhs.Add(hhsno);
48
49 wxSQLite3Statement stmt2 = hhsdb.PrepareStatement("SELECT name FROM hhs_master WHERE hhsno = ?");
50 stmt2.Bind( 1, hhsno );
51 q2 = stmt2.ExecuteQuery();
52 if ( !q2.IsNull(0) ) {
53 while ( q2.NextRow() ) {
54 recentname.Add(q2.GetString(0));
55 }
56 }
57 else {
58 recentname.Add(wxEmptyString);
59 }
60 stmt2.Finalize();
61 }
62 stmt.Finalize();
63
64 hhsdb.Close();
65 ccndb.Close();
66 }
67
68 // destructor
69 MyCmdBox::~MyCmdBox()
70 {
71 }
72
73 // Event Table
74 BEGIN_EVENT_TABLE( MyCmdBox, wxTextCtrl )
75 EVT_CHAR( MyCmdBox::OnChar )
76 EVT_TEXT_ENTER( ID_CMD, MyCmdBox::OnCmd )
77 END_EVENT_TABLE()
78
79 // Event Handlers
80 void MyCmdBox::OnChar( wxKeyEvent& event )
81 {
82 if ( event.GetKeyCode() == 13 ) {
83 event.Skip();
84 return;
85 }
86
87 if ( event.GetKeyCode() == 45 ) { // テンキーの"-"キーで一文字削除
88 wxString s = this->GetStringSelection();
89 if ( s.IsEmpty() ) {
90 long p = this->GetInsertionPoint();
91 this->Remove( p-1, p );
92 }
93 else {
94 this->Cut();
95 }
96 return;
97 }
98
99 MyFrame *mf = (MyFrame*)FindWindowById( ID_MAIN );
100
101 if ( event.GetKeyCode() == WXK_UP ) { // ↑
102 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
103 histpos--;
104 if ( histpos < 0 ) histpos = 0;
105 this->ChangeValue( hist[histpos] );
106 return;
107 }
108 else if ( event.GetKeyCode() == WXK_DOWN ) { // ↓
109 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
110 histpos++;
111 if ( histpos >= hist.GetCount() ) {
112 histpos = hist.GetCount();
113 this->Clear();
114 return;
115 }
116 this->ChangeValue( hist[histpos] );
117 return;
118 }
119
120 if ( event.GetKeyCode() == WXK_ESCAPE ) { // clear by ESC
121 this->Clear();
122 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
123 return;
124 }
125
126 this->Cut();
127 int c = event.GetKeyCode();
128 if ( c >= 48 && c <= 57 ) { // [0-9]
129 c -= 48;
130 wxString input = this->GetLineText(0) + wxString::Format(wxT("%d"),c);
131 if ( input.Len() < 5 ) {
132 event.Skip();
133 return;
134 }
135 // autocomplete
136 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
137 for ( int i=0; i<recenthhs.GetCount(); i++ ) {
138 if ( recenthhs[i].StartsWith( input ) ) {
139 this->ChangeValue( recenthhs[i] );
140 this->SetSelection( input.Len(), 10 );
141
142 wxString msg = wxT("もしかして... ") + recentname[i] + wxT(" ?!");
143 mf->m_statusBar->SetStatusText( msg, 0 );
144
145 return;
146 }
147 }
148 event.Skip();
149 return;
150 }
151
152 event.Skip();
153 }
154
155 void MyCmdBox::OnCmd( wxCommandEvent& event )
156 {
157 wxHtmlWindow *h = (wxHtmlWindow*)FindWindowById( ID_HTML );
158 wxGrid *g = (wxGrid*)FindWindowById( ID_CCN );
159 wxSplitterWindow *s = (wxSplitterWindow*)FindWindowById( ID_SPLT );
160 s->ReplaceWindow( h, g );
161 h->Show(true);
162 g->Show(false);
163
164 wxRegEx reHhs(wxT("^0[1238][0-9]{8}$")); // 被保番チェック
165 wxRegEx reCno(wxT("^[0-9]{1,2}$")); // 開くフォルダの番号
166
167 wxString cmd;
168 cmd = this->GetLineText(0);
169 int cond = 0;
170 if ( reHhs.Matches( cmd ) )
171 cond = 1;
172 else if ( reCno.Matches( cmd ) )
173 cond = 2;
174
175 wxString htmlbody;
176
177 MyFrame *mf = (MyFrame*)FindWindowById( ID_MAIN );
178 wxHtmlWindow *hr = (wxHtmlWindow*)FindWindowById( ID_HTML );
179 switch (cond) {
180 // 被保険者番号が入力されたら
181 case 1: {
182 wxString hhs = cmd;
183 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
184 this->SetSelection( 0, this->GetLastPosition() );
185
186 // 被保険者検索
187 wxString gszFile = wxGetCwd() + wxT("/db/hhs.db");
188 wxSQLite3Database hhsdb;
189 hhsdb.Open( gszFile );
190
191 wxSQLite3Statement stmt = hhsdb.PrepareStatement("SELECT name FROM hhs_master WHERE hhsno = ?");
192 stmt.Bind( 1, hhs );
193 wxSQLite3ResultSet q = stmt.ExecuteQuery();
194
195 wxString name = wxT("登録なし");
196 if ( q.IsNull(0) ) {
197 wxString msg = wxT("データベースに存在しない被保険者です.") + hhs;
198 mf->m_statusBar->SetStatusText( msg, 0 );
199 }
200 else {
201 name = q.GetString(0);
202 hist.Add( hhs );
203 histpos++;
204 }
205 stmt.Finalize();
206 hhsdb.Close();
207
208 // パス検索
209 gszFile = wxGetCwd() + wxT("/db/ccn.db");
210 wxSQLite3Database ccndb;
211 ccndb.Open( gszFile );
212
213 stmt = ccndb.PrepareStatement("SELECT path FROM path WHERE hhsno = ? ORDER BY path DESC");
214 stmt.Bind( 1, hhs );
215 q = stmt.ExecuteQuery();
216 if ( q.IsNull(0) ) {
217 hr->LoadPage( wxT("html/notfound.html") );
218 mf->m_statusBar->SetStatusText( wxT("データが存在しません."), 0 );
219 return;
220 }
221
222 path.Clear();
223 htmlbody = wxT("<html><body>");
224 htmlbody += wxT("該当者: ");
225 htmlbody += wxT("<b>") + name + wxT("</b>");
226 htmlbody += wxT(" ( ") + hhs + wxT(" )");
227 htmlbody += wxT("<br /><br />検索結果");
228 htmlbody += wxT("<table border=1>");
229 htmlbody += wxT("<tr bgcolor=\"#ffcc33\"><th>番号</th><th>日付</th><th>フォルダ</th></tr>");
230
231 wxRegEx reDate(wxT("(^.*20[0-9]{2}.)(20[0-9]{2})([0-2][0-9])([0-9]{2})(.*$)"));
232
233 int i=1;
234 int clrflg = 1;
235 while ( q.NextRow() ) {
236 path.Add(q.GetString(0));
237 wxString date = q.GetString(0);
238 reDate.ReplaceAll( &date, wxT("\\2-\\3-\\4") );
239
240 if ( clrflg ) {
241 htmlbody += wxT("<tr bgcolor=\"#ffffcc\">");
242 clrflg = 0;
243 }
244 else {
245 htmlbody += wxT("<tr bgcolor=\"#ffff99\">");
246 clrflg = 1;
247 }
248 htmlbody += wxT("<td align=\"center\">") + wxString::Format(wxT("%d"),i++) + wxT("</td>");
249 htmlbody += wxT("<td>") + date + wxT("</td>");
250 htmlbody += wxT("<td>") + q.GetString(0) + wxT("</td></tr>");
251 }
252 stmt.Finalize();
253 ccndb.Close();
254 path.Shrink();
255
256 htmlbody += wxT("</table>");
257 htmlbody += wxT("<br />");
258 htmlbody += wxT("<div>");
259 htmlbody += wxT("フォルダを開くには,番号を入力してください.<br />");
260 htmlbody += wxT("他の被保険者を検索するには,被保番を入力してください.");
261 htmlbody += wxT("</div>");
262 htmlbody += wxT("</body></html>");
263
264 hr->SetPage( htmlbody );
265
266 break;
267 }
268 // フォルダ表示
269 case 2: {
270 this->SetSelection( 0, this->GetLastPosition() );
271 long val;
272 cmd.ToLong( &val, 10 );
273 val--;
274 if ( path.IsEmpty()
275 || val < 0
276 || val > path.GetCount()-1 ) {
277 mf->m_statusBar->SetStatusText( wxT("不適切な入力です."), 0 );
278 break;
279 }
280 wxString execmd = wxT("explorer ") + path[val];
281 wxExecute( execmd );
282 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
283
284 // 検索履歴をログに保存
285 wxString logfn = wxGetCwd() + wxT("/db/log.txt");
286 wxTextFile logFile;
287 logFile.Open( logfn );
288 wxDateTime now = wxDateTime::Now();
289 wxString log = now.Format() + wxT(" " ) + cmd + wxT(" ") + path[val];
290 logFile.AddLine( log );
291 logFile.Write();
292 logFile.Close();
293
294 break;
295 }
296 // 制御用コマンド
297 case 0: {
298
299 path.Clear();
300 if ( cmd.Cmp(wxT("s")) == 0 ) {
301 hr->LoadPage( wxT("html/start.html") );
302 this->ChangeValue( wxEmptyString );
303 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
304 return;
305 }
306 if ( cmd.Cmp(wxT("c")) == 0 ) {
307 hr->LoadPage( wxT("Searcher2.conf") );
308 this->ChangeValue( wxEmptyString );
309 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
310 return;
311 }
312 if ( cmd.Cmp(wxT("t")) == 0 ) {
313 hr->LoadPage( wxT("html/todo.html") );
314 this->ChangeValue( wxEmptyString );
315 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
316 return;
317 }
318 if ( cmd.Cmp(wxT("l")) == 0 ) {
319 hr->LoadPage( wxT("db/log.txt") );
320 this->ChangeValue( wxEmptyString );
321 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
322 return;
323 }
324 if ( cmd.Cmp(wxT("**")) == 0 ) {
325 mf->m_statusBar->SetStatusText( wxT("Now Saving..."), 0 );
326 mf->Close();
327 return;
328 }
329
330 mf->m_statusBar->SetStatusText( wxT("不適切な入力です."), 0 );
331 this->SetSelection( 0, this->GetLastPosition() );
332
333 break;
334 }
335 //
336 default: {
337 break;
338 }
339 }
340 }
341
342 //////////////////////////////////////////////////////////////////////////
343 // frame constructor
344 MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title )
345 : wxFrame( parent, id, title )
346 {
347 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
348 // set the frame icon
349 SetIcon(wxICON(sample));
350
351 // メニューバー
352 m_menubar = new wxMenuBar();
353
354 m_menuFile = new wxMenu();
355 m_menuFile->Append( ID_MUPHHS, wxT("被保険者DB更新"), wxT("Update hhs-db") );
356 m_menuFile->Append( ID_MLSCCN, wxT("インデックス更新一覧"), wxT("List index") );
357 m_menuFile->AppendSeparator(); //----
358 wxMenu *menuMaintain = new wxMenu();
359 m_menuFile->AppendSubMenu( menuMaintain, wxT("メンテナンス") );
360 menuMaintain->Append( ID_MDBBKUP, wxT("データベースバックアップ"), wxT("Backup DBs") );
361 menuMaintain->Append( ID_MDBOPT, wxT("データベース最適化"), wxT("Optimize DBs") );
362 menuMaintain->Enable( ID_MDBOPT, false );
363 menuMaintain->Append( ID_MCHKHHS, wxT("被保者整合性チェック"), wxT("Check hhs") );
364 m_menuFile->AppendSeparator(); //----
365 wxMenu *menuOpendir = new wxMenu();
366 m_menuFile->AppendSubMenu( menuOpendir, wxT("フォルダを開く") );
367 menuOpendir->Append( ID_MOAD, wxT("アプリケーションフォルダ"), wxT("Open App Folder") );
368 menuOpendir->Append( ID_MODD, wxT("データフォルダ"), wxT("Open Data Folder") );
369 m_menuFile->AppendSeparator(); //----
370 m_menuFile->Append( wxID_EXIT, wxT("終了(&X)\tAlt-X"), wxT("Quit this program") );
371
372 m_menuHelp = new wxMenu();
373 m_menuHelp->Append( ID_MHELP, wxT("&Help"), wxT("Show help") );
374 m_menuHelp->Append( wxID_ABOUT, wxT("&About...\tF1"), wxT("Show about dialog") );
375
376 // now append the freshly created menu to the menu bar...
377 m_menubar->Append( m_menuFile, wxT("ファイル(&F)") );
378 m_menubar->Append( m_menuHelp, wxT("ヘルプ(&H)") );
379
380 this->SetMenuBar( m_menubar );
381
382 // ツールバー
383 //m_toolBar = new wxToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL|wxNO_BORDER );
384 //wxBitmap bmpPrint( print_xpm );
385 //wxBitmap bmpIndex( index_xpm );
386
387 // ステータスバー
388 int widths[] = { -1, 120, 100 };
389 m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP );
390 m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths );
391 m_statusBar->SetStatusText( wxEmptyString, 0 );
392
393 wxBoxSizer* bSizer;
394 bSizer = new wxBoxSizer( wxVERTICAL );
395
396 // controls here
397 m_panelHead = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize );
398 wxBoxSizer* bSizerHead;
399 bSizerHead = new wxBoxSizer( wxHORIZONTAL );
400
401 /* after version 2.7
402 m_staticTextHname = new wxStaticText( m_panelHead, wxID_ANY, wxT("氏名カナ検索"), wxDefaultPosition, wxDefaultSize, 0 );
403 bSizerHead->Add( m_staticTextHname, 0, wxALL, 5 );
404
405 m_searchCtrlHname = new wxSearchCtrl( m_panelHead, ID_SRCHHHS, wxT("3字以上入力"), wxDefaultPosition, wxSize(200,20), 0 );
406 #ifndef __WXMAC__
407 m_searchCtrlHname->ShowSearchButton( true );
408 #endif
409 bSizerHead->Add( m_searchCtrlHname, 0, wxALL, 1 );
410
411 m_bitmapMkidx = new wxStaticBitmap( m_panelHead, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
412 bSizerHead->Add( m_bitmapMkidx, 0, wxALL, 1 );
413 */
414
415 bSizerHead->AddStretchSpacer( 1 ); // spacer
416
417 m_staticTextIdx = new wxStaticText( m_panelHead, wxID_ANY, wxT("インデックス"), wxDefaultPosition, wxDefaultSize, 0 );
418 bSizerHead->Add( m_staticTextIdx, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
419
420 m_datePicker = new wxDatePickerCtrl( m_panelHead, ID_DTIDX, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_SHOWCENTURY|wxDP_DROPDOWN );
421 bSizerHead->Add( m_datePicker, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
422
423 m_buttonMkidx = new wxButton( m_panelHead, ID_MKIDX, wxT("作成"), wxDefaultPosition, wxSize(50,25), 0 );
424 bSizerHead->Add( m_buttonMkidx, 0, wxALL, 5 );
425
426 m_panelHead->SetSizer( bSizerHead );
427 m_panelHead->Layout();
428 bSizerHead->Fit( m_panelHead );
429
430 // メインペイン
431 wxBoxSizer* bSizerHtml;
432 bSizerHtml = new wxBoxSizer( wxVERTICAL );
433 m_splitter = new wxSplitterWindow( this, ID_SPLT, wxDefaultPosition, wxDefaultSize, 0 );
434
435 // 検索結果Html
436 m_html = new wxHtmlWindow( m_splitter, ID_HTML, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO );
437 m_html->LoadPage( wxT("html/start.html") );
438
439 /* after version 2.7
440 // 被保険者カナ検索Grid
441 m_gridHhs = new wxGrid( m_panelHtml, ID_HLST, wxDefaultPosition, wxDefaultSize, 0 );
442 m_gridHhs->CreateGrid( 0, 5 );
443 m_gridHhs->EnableEditing( true );
444 m_gridHhs->EnableGridLines( true );
445 m_gridHhs->EnableDragGridSize( false );
446 m_gridHhs->SetMargins( 0, 0 );
447
448 // Columns
449 m_gridHhs->AutoSizeColumns();
450 m_gridHhs->EnableDragColMove( false );
451 m_gridHhs->SetColLabelValue( 0, wxT("番号") );
452 m_gridHhs->SetColLabelValue( 1, wxT("氏名") );
453 m_gridHhs->SetColLabelValue( 2, wxT("カナ") );
454 m_gridHhs->SetColLabelValue( 3, wxT("生年月日") );
455 m_gridHhs->SetColLabelValue( 4, wxT("住所") );
456 m_gridHhs->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
457
458 // Cell Defaults
459 m_gridHhs->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_BOTTOM );
460 m_gridHhs->Hide();
461
462 bSizerHtml->Add( m_gridHhs, 0, wxALL, 5 );
463 */
464
465 // 審査会合議体表示Grid
466 m_gridCcn = new wxGrid( m_splitter, ID_CCN, wxDefaultPosition, wxDefaultSize, 0 );
467 m_gridCcn->CreateGrid( 0, 2 );
468 m_gridCcn->EnableEditing( true );
469 m_gridCcn->EnableGridLines( true );
470 m_gridCcn->EnableDragGridSize( false );
471 m_gridCcn->SetMargins( 0, 0 );
472 m_gridCcn->SetDefaultCellAlignment( wxALIGN_CENTRE, wxALIGN_BOTTOM );
473 m_gridCcn->Show(false);
474
475 // Columns
476 m_gridCcn->AutoSizeColumns();
477 m_gridCcn->EnableDragColMove( false );
478 m_gridCcn->SetColLabelValue( 0, wxT("審査会年月日") );
479 m_gridCcn->SetColLabelValue( 1, wxT("DB更新時刻") );
480 m_gridCcn->SetColSize( 0, 100 );
481 m_gridCcn->SetColSize( 1, 200 );
482 m_gridCcn->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
483
484 m_splitter->Initialize( m_html );
485 m_splitter->SetSizer( bSizerHtml );
486 m_splitter->Layout();
487 bSizerHtml->Fit( m_splitter );
488
489 // コマンドライン
490 m_panelCmd = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize );
491 wxBoxSizer* bSizerCmd;
492 bSizerCmd = new wxBoxSizer( wxHORIZONTAL );
493
494 m_staticTextCmd = new wxStaticText( m_panelCmd, wxID_ANY, wxT("コマンド?"), wxDefaultPosition, wxDefaultSize, 0 );
495 bSizerCmd->Add( m_staticTextCmd, 0, wxALL, 5 );
496
497 m_cmdbox = new MyCmdBox( m_panelCmd, ID_CMD, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
498 bSizerCmd->Add( m_cmdbox, 1, wxALL, 3 );
499 m_cmdbox->SetFocus();
500
501 m_panelCmd->SetSizer( bSizerCmd );
502 m_panelCmd->Layout();
503 bSizerCmd->Fit( m_panelCmd );
504
505
506 bSizer->Add( m_panelHead, 0, wxEXPAND|wxTOP, 1 );
507 bSizer->Add( m_splitter, 1, wxEXPAND|wxALL, 1 );
508 bSizer->Add( m_panelCmd, 0, wxEXPAND|wxALL, 0 );
509
510 this->SetSizer( bSizer );
511 this->Layout();
512 }
513
514 // destructor
515 MyFrame::~MyFrame()
516 {
517 }
518
519 // Event Table
520 BEGIN_EVENT_TABLE( MyFrame, wxFrame )
521 EVT_MENU( wxID_EXIT, MyFrame::OnQuit )
522 EVT_MENU( wxID_ABOUT, MyFrame::OnAbout )
523 EVT_MENU( ID_MUPHHS, MyFrame::OnUpdateHhsDb )
524 EVT_MENU( ID_MLSCCN, MyFrame::OnListCcn )
525 EVT_MENU( ID_MDBBKUP, MyFrame::OnBackupDB )
526 EVT_MENU( ID_MDBOPT, MyFrame::OnOptimizeDB )
527 EVT_MENU( ID_MCHKHHS, MyFrame::OnCheckHhs )
528 EVT_MENU( ID_MOAD, MyFrame::OnOpenAppDir )
529 EVT_MENU( ID_MODD, MyFrame::OnOpenDataDir )
530 EVT_MENU( ID_MHELP, MyFrame::OnHelp )
531
532 //EVT_TEXT_ENTER( ID_SRCHHHS, MyFrame::OnHhsSearch ) after version 2.7
533 EVT_BUTTON( ID_MKIDX, MyFrame::OnMkIndex )
534
535 EVT_CLOSE( MyFrame::SaveConfig )
536 END_EVENT_TABLE()
537
538 // Event Handlers
539 /* 終了 */
540 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
541 {
542 Close(true);
543 }
544
545 /* オンラインヘルプ */
546 void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
547 {
548 HtmlHelpFrame *f = (HtmlHelpFrame*)FindWindowById( ID_HELP );
549
550 if ( f == NULL ) {
551 HtmlHelpFrame *helpframe = new HtmlHelpFrame( wxT("Online Help"), ID_HELP );
552 helpframe->Show(true);
553 }
554 else {
555 f->Raise();
556 }
557 }
558
559 /* バージョン情報 */
560 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
561 {
562 wxSQLite3Database sqlite;
563 wxMessageBox(
564 wxString::Format(
565 wxT("Version %d.%d ( build %d ) by %s\n")
566 wxT("with SQLite library %s\n")
567 wxT("running under %s."),
568 VER, REV, BLD, wxVERSION_STRING,
569 sqlite.GetVersion().c_str(),
570 wxGetOsDescription().c_str()
571 ),
572 wxT("About this program"), wxOK | wxICON_INFORMATION, this );
573 }
574
575 /* 被保険者検索 */
576 /* after version 2.7
577 void MyFrame::OnHhsSearch(wxCommandEvent& WXUNUSED(event))
578 {
579 this->m_html->Hide();
580 this->m_gridCcn->Hide();
581 this->m_gridHhs->Show(true);
582
583 wxString gszFile = wxGetCwd() + wxT("/db/hhs.db");
584 wxSQLite3Database hhsdb;
585 hhsdb.Open( gszFile );
586
587 wxSQLite3Statement stmt = hhsdb.PrepareStatement("SELECT count(*) FROM hhs_master WHERE kana LIKE ?");
588 stmt.Bind( 1, this->m_searchCtrlHname->GetValue() );
589 wxSQLite3ResultSet q = stmt.ExecuteQuery();
590 wxString cnt = q.GetString(0);
591
592 if ( cnt.Cmp(wxT("0")) == '0' ) {
593 wxString msg = cnt + wxT("指定した条件の被保険者はいませんでした.");
594 }
595 else {
596 wxString msg = cnt + wxT("件マッチしました.");
597 return ; // test now
598
599 stmt = hhsdb.PrepareStatement("SELECT hhs, name, kana, addr, birth, sex FROM hhs_master ORDER BY birth DESC");
600 q = stmt.ExecuteQuery();
601 wxSQLite3ResultSet q = stmt.ExecuteQuery();
602 while ( q.NextRow() ) {
603 wxString hhs = q.GetString(0);
604 wxString name = q.GetString(1);
605 wxString kana = q.GetString(2);
606 wxString addr = q.GetString(3);
607 wxString birth = q.GetString(4);
608 wxString sex = q.GetString(5);
609 // ここに gridに 追加するコード
610 }
611 }
612
613 stmt.Finalize();
614 hhsdb.Close();
615 }
616 */
617
618 /* インデックス作成 */
619 void MyFrame::OnMkIndex(wxCommandEvent& WXUNUSED(event))
620 {
621 wxDateTime dt = m_datePicker->GetValue();
622 wxString month = dt.Format(wxT("%m"));
623 wxString year = dt.Format(wxT("%Y"));
624 if ( month.IsSameAs(wxT("01")) || month.IsSameAs(wxT("02")) || month.IsSameAs(wxT("03")) ) {
625 long y;
626 year.ToLong( &y, 10 );
627 y--;
628 year = wxString::Format(wxT("%d"),y);
629 }
630 wxString pathroot = wxGetApp().rootdir + wxFILE_SEP_PATH + year + dt.Format(wxT("\\%Y%m%d"));
631 wxDir rootd(pathroot);
632 if ( !wxDir::Exists(pathroot) ) {
633 wxMessageBox( wxT("フォルダが存在しません.")+pathroot );
634 return;
635 }
636
637 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 200, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
638 pd.SetSize( wxSize(320,140) );
639 int count=0;
640
641 wxString ccndir;
642 bool cont = rootd.GetFirst( &ccndir, wxT("*.*"), wxDIR_DIRS );
643 while ( cont ) {
644 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
645 wxSQLite3Database ccndb;
646 ccndb.Open( gszFile );
647
648 wxSQLite3Statement stmt = ccndb.PrepareStatement("INSERT OR REPLACE INTO ccn VALUES( ?, datetime('now','localtime') )");
649 stmt.Bind( 1, dt.Format(wxT("%Y-%m-%d")) );
650 stmt.ExecuteQuery();
651
652 stmt.Finalize();
653
654 wxDir ccnd( pathroot + wxFILE_SEP_PATH + ccndir );
655 if ( !ccnd.IsOpened() ) return;
656 wxString hhsdir;
657 bool c = ccnd.GetFirst( &hhsdir, wxT("*.*"), wxDIR_DIRS );
658 wxRegEx reHhs(wxT("^0[1238][0-9]{8}$")); // 被保番チェック
659 while ( c ) {
660 if ( reHhs.Matches(hhsdir) ) {
661 wxString path = pathroot + wxFILE_SEP_PATH + ccndir + wxFILE_SEP_PATH + hhsdir;
662
663 stmt = ccndb.PrepareStatement("INSERT OR REPLACE INTO path VALUES( ?, ? )");
664 stmt.Bind( 1, hhsdir );
665 stmt.Bind( 2, path );
666 stmt.ExecuteQuery();
667
668 stmt.Finalize();
669 }
670 c = ccnd.GetNext(&hhsdir);
671 pd.Update( count++, hhsdir+wxT("@")+ccndir+wxT("を処理しました.") );
672 }
673 ccndb.Close();
674
675 cont = rootd.GetNext(&ccndir);
676 }
677 wxMessageBox(wxT("インデックス作成が終了しました."));
678 }
679
680 /* インデックス更新一覧 */
681 void MyFrame::OnListCcn(wxCommandEvent& WXUNUSED(event))
682 {
683 this->m_splitter->ReplaceWindow( this->m_html, this->m_gridCcn );
684 this->m_gridCcn->Show(true);
685 this->m_html->Show(false);
686 MyCmdBox *c = (MyCmdBox*)FindWindowById( ID_CMD );
687 c->Clear();
688
689 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
690 wxSQLite3Database ccndb;
691 ccndb.Open( gszFile );
692
693 wxSQLite3Statement stmt = ccndb.PrepareStatement("SELECT ymd, time FROM ccn ORDER BY ymd DESC, time DESC");
694 wxSQLite3ResultSet q = stmt.ExecuteQuery();
695 int r=0;
696 while ( q.NextRow() ) {
697 wxString ymd = q.GetString(0);
698 wxString time = q.GetString(1);
699 this->m_gridCcn->AppendRows(1);
700 this->m_gridCcn->SetCellValue(r,0,ymd);
701 this->m_gridCcn->SetCellValue(r,1,time);
702 r++;
703 }
704
705 stmt.Finalize();
706 ccndb.Close();
707 }
708
709 /* 被保険者DB更新 */
710 void MyFrame::OnUpdateHhsDb(wxCommandEvent& WXUNUSED(event))
711 {
712 FrameHhsDB *f = (FrameHhsDB*)FindWindowById( ID_HHSDB );
713
714 if ( f == NULL ) {
715 FrameHhsDB *hhsdb = new FrameHhsDB( this, ID_HHSDB );
716 hhsdb->Show(true);
717 }
718 else {
719 f->Raise();
720 }
721 return;
722 }
723
724 /* 被保険者整合性チェック */
725 void MyFrame::OnCheckHhs(wxCommandEvent& WXUNUSED(event))
726 {
727 wxString logfn = wxGetCwd() + wxT("/db/checkhhs.log");
728 wxTextFile logFile;
729 logFile.Open( logfn );
730 logFile.Clear();
731
732 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
733 wxSQLite3Database ccndb;
734 ccndb.Open( gszFile );
735 wxSQLite3Statement stmt = ccndb.PrepareStatement("ATTACH 'db/hhs.db' AS hhs");
736 wxSQLite3ResultSet q = stmt.ExecuteQuery();
737 stmt = ccndb.PrepareStatement("SELECT hhsno FROM path EXCEPT SELECT hhsno FROM hhs.hhs_master");
738 q = stmt.ExecuteQuery();
739
740 while ( q.NextRow() ) {
741 logFile.AddLine( q.GetString(0) );
742 }
743 stmt.Finalize();
744 ccndb.Close();
745
746 logFile.Write();
747 logFile.Close();
748
749 wxString msg = wxT("結果を ") + logfn + wxT(" に保存しました.");
750 wxMessageBox( msg );
751 return;
752 }
753
754 /* DBバックアップ */
755 void MyFrame::OnBackupDB(wxCommandEvent& WXUNUSED(event))
756 {
757 wxDateTime now = wxDateTime::Now();
758 wxString nowstr = now.Format(wxT("%Y%m%d%H%M%S"));
759
760 wxString org = wxGetCwd() + wxT("/db/ccn.db");
761 wxString bk = wxGetCwd() + wxT("/db/") + nowstr + wxT("_ccn.db");
762 wxCopyFile( org, bk, 0 );
763
764 org = wxGetCwd() + wxT("/db/hhs.db");
765 bk = wxGetCwd() + wxT("/db/") + nowstr + wxT("_hhs.db");
766 wxCopyFile( org, bk, 0 );
767
768 wxMessageBox( wxT("バックアップ終了.") );
769 return;
770 }
771
772 /* DB最適化 */
773 void MyFrame::OnOptimizeDB(wxCommandEvent& WXUNUSED(event))
774 {
775 return;
776 }
777
778 /* アプリケーションフォルダを開く */
779 void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event))
780 {
781 wxStandardPaths appdir;
782 wxString execmd = wxT("explorer ") + appdir.GetDataDir();
783 wxExecute( execmd );
784 return;
785 }
786
787 /* データフォルダを開く */
788 void MyFrame::OnOpenDataDir(wxCommandEvent& WXUNUSED(event))
789 {
790 wxString datadir = wxGetApp().rootdir;
791 wxString execmd = wxT("explorer ") + datadir;
792 wxExecute( execmd );
793 return;
794 }
795
796
797 /* 設定を保存 */
798 void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event))
799 {
800 if ( !IsIconized() && !IsMaximized() ) {
801 wxGetApp().rect = this->GetRect();
802 }
803
804 int i = m_cmdbox->hist.GetCount();
805 for ( int j=0; j<5; j++ ) {
806 wxGetApp().searchhist[j] = m_cmdbox->hist[--i];
807 }
808
809 Destroy();
810 }
811