0
|
1 // Filename : mainframe.cpp
|
1
|
2 // Last Change: 07-Apr-2011.
|
0
|
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>");
|
1
|
229 htmlbody += wxT("<tr bgcolor=\"#ffcc33\"><th>番号</th><th>日付</th><th>フォルダ</th><th>操作</th></tr>");
|
0
|
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 }
|
1
|
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 //htmlbody += wxT("<td>") + wxT("プレビュー") + wxT("</td></tr>");
|
|
252 //htmlbody += wxT("<td>") + wxT("印刷") + wxT("</td></tr>");
|
|
253 //htmlbody += wxT("<td>") + wxT("フォルダを開く") + wxT("</td></tr>");
|
0
|
254 }
|
|
255 stmt.Finalize();
|
|
256 ccndb.Close();
|
|
257 path.Shrink();
|
|
258
|
|
259 htmlbody += wxT("</table>");
|
|
260 htmlbody += wxT("<br />");
|
|
261 htmlbody += wxT("<div>");
|
|
262 htmlbody += wxT("フォルダを開くには,番号を入力してください.<br />");
|
|
263 htmlbody += wxT("他の被保険者を検索するには,被保番を入力してください.");
|
|
264 htmlbody += wxT("</div>");
|
|
265 htmlbody += wxT("</body></html>");
|
|
266
|
|
267 hr->SetPage( htmlbody );
|
|
268
|
|
269 break;
|
|
270 }
|
|
271 // フォルダ表示
|
|
272 case 2: {
|
|
273 this->SetSelection( 0, this->GetLastPosition() );
|
|
274 long val;
|
|
275 cmd.ToLong( &val, 10 );
|
|
276 val--;
|
|
277 if ( path.IsEmpty()
|
|
278 || val < 0
|
|
279 || val > path.GetCount()-1 ) {
|
|
280 mf->m_statusBar->SetStatusText( wxT("不適切な入力です."), 0 );
|
|
281 break;
|
|
282 }
|
|
283 wxString execmd = wxT("explorer ") + path[val];
|
|
284 wxExecute( execmd );
|
|
285 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
286
|
|
287 // 検索履歴をログに保存
|
|
288 wxString logfn = wxGetCwd() + wxT("/db/log.txt");
|
|
289 wxTextFile logFile;
|
|
290 logFile.Open( logfn );
|
|
291 wxDateTime now = wxDateTime::Now();
|
|
292 wxString log = now.Format() + wxT(" " ) + cmd + wxT(" ") + path[val];
|
|
293 logFile.AddLine( log );
|
|
294 logFile.Write();
|
|
295 logFile.Close();
|
|
296
|
|
297 break;
|
|
298 }
|
|
299 // 制御用コマンド
|
|
300 case 0: {
|
|
301
|
|
302 path.Clear();
|
|
303 if ( cmd.Cmp(wxT("s")) == 0 ) {
|
|
304 hr->LoadPage( wxT("html/start.html") );
|
|
305 this->ChangeValue( wxEmptyString );
|
|
306 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
307 return;
|
|
308 }
|
|
309 if ( cmd.Cmp(wxT("c")) == 0 ) {
|
|
310 hr->LoadPage( wxT("Searcher2.conf") );
|
|
311 this->ChangeValue( wxEmptyString );
|
|
312 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
313 return;
|
|
314 }
|
|
315 if ( cmd.Cmp(wxT("t")) == 0 ) {
|
|
316 hr->LoadPage( wxT("html/todo.html") );
|
|
317 this->ChangeValue( wxEmptyString );
|
|
318 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
319 return;
|
|
320 }
|
|
321 if ( cmd.Cmp(wxT("l")) == 0 ) {
|
|
322 hr->LoadPage( wxT("db/log.txt") );
|
|
323 this->ChangeValue( wxEmptyString );
|
|
324 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
325 return;
|
|
326 }
|
|
327 if ( cmd.Cmp(wxT("**")) == 0 ) {
|
|
328 mf->m_statusBar->SetStatusText( wxT("Now Saving..."), 0 );
|
|
329 mf->Close();
|
|
330 return;
|
|
331 }
|
|
332
|
|
333 mf->m_statusBar->SetStatusText( wxT("不適切な入力です."), 0 );
|
|
334 this->SetSelection( 0, this->GetLastPosition() );
|
|
335
|
|
336 break;
|
|
337 }
|
|
338 //
|
|
339 default: {
|
|
340 break;
|
|
341 }
|
|
342 }
|
|
343 }
|
|
344
|
|
345 //////////////////////////////////////////////////////////////////////////
|
|
346 // frame constructor
|
|
347 MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title )
|
|
348 : wxFrame( parent, id, title )
|
|
349 {
|
|
350 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
|
351 // set the frame icon
|
|
352 SetIcon(wxICON(sample));
|
|
353
|
|
354 // メニューバー
|
|
355 m_menubar = new wxMenuBar();
|
|
356
|
|
357 m_menuFile = new wxMenu();
|
|
358 m_menuFile->Append( ID_MUPHHS, wxT("被保険者DB更新"), wxT("Update hhs-db") );
|
|
359 m_menuFile->Append( ID_MLSCCN, wxT("インデックス更新一覧"), wxT("List index") );
|
|
360 m_menuFile->AppendSeparator(); //----
|
|
361 wxMenu *menuMaintain = new wxMenu();
|
|
362 m_menuFile->AppendSubMenu( menuMaintain, wxT("メンテナンス") );
|
|
363 menuMaintain->Append( ID_MDBBKUP, wxT("データベースバックアップ"), wxT("Backup DBs") );
|
|
364 menuMaintain->Append( ID_MDBOPT, wxT("データベース最適化"), wxT("Optimize DBs") );
|
|
365 menuMaintain->Enable( ID_MDBOPT, false );
|
|
366 menuMaintain->Append( ID_MCHKHHS, wxT("被保者整合性チェック"), wxT("Check hhs") );
|
|
367 m_menuFile->AppendSeparator(); //----
|
|
368 wxMenu *menuOpendir = new wxMenu();
|
|
369 m_menuFile->AppendSubMenu( menuOpendir, wxT("フォルダを開く") );
|
|
370 menuOpendir->Append( ID_MOAD, wxT("アプリケーションフォルダ"), wxT("Open App Folder") );
|
|
371 menuOpendir->Append( ID_MODD, wxT("データフォルダ"), wxT("Open Data Folder") );
|
|
372 m_menuFile->AppendSeparator(); //----
|
|
373 m_menuFile->Append( wxID_EXIT, wxT("終了(&X)\tAlt-X"), wxT("Quit this program") );
|
|
374
|
|
375 m_menuHelp = new wxMenu();
|
|
376 m_menuHelp->Append( ID_MHELP, wxT("&Help"), wxT("Show help") );
|
|
377 m_menuHelp->Append( wxID_ABOUT, wxT("&About...\tF1"), wxT("Show about dialog") );
|
|
378
|
|
379 // now append the freshly created menu to the menu bar...
|
|
380 m_menubar->Append( m_menuFile, wxT("ファイル(&F)") );
|
|
381 m_menubar->Append( m_menuHelp, wxT("ヘルプ(&H)") );
|
|
382
|
|
383 this->SetMenuBar( m_menubar );
|
|
384
|
|
385 // ツールバー
|
|
386 //m_toolBar = new wxToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL|wxNO_BORDER );
|
|
387 //wxBitmap bmpPrint( print_xpm );
|
|
388 //wxBitmap bmpIndex( index_xpm );
|
|
389
|
|
390 // ステータスバー
|
|
391 int widths[] = { -1, 120, 100 };
|
|
392 m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP );
|
|
393 m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths );
|
|
394 m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
395
|
|
396 wxBoxSizer* bSizer;
|
|
397 bSizer = new wxBoxSizer( wxVERTICAL );
|
|
398
|
|
399 // controls here
|
|
400 m_panelHead = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize );
|
|
401 wxBoxSizer* bSizerHead;
|
|
402 bSizerHead = new wxBoxSizer( wxHORIZONTAL );
|
|
403
|
|
404 /* after version 2.7
|
|
405 m_staticTextHname = new wxStaticText( m_panelHead, wxID_ANY, wxT("氏名カナ検索"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
406 bSizerHead->Add( m_staticTextHname, 0, wxALL, 5 );
|
|
407
|
|
408 m_searchCtrlHname = new wxSearchCtrl( m_panelHead, ID_SRCHHHS, wxT("3字以上入力"), wxDefaultPosition, wxSize(200,20), 0 );
|
|
409 #ifndef __WXMAC__
|
|
410 m_searchCtrlHname->ShowSearchButton( true );
|
|
411 #endif
|
|
412 bSizerHead->Add( m_searchCtrlHname, 0, wxALL, 1 );
|
|
413
|
|
414 m_bitmapMkidx = new wxStaticBitmap( m_panelHead, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
|
|
415 bSizerHead->Add( m_bitmapMkidx, 0, wxALL, 1 );
|
|
416 */
|
|
417
|
|
418 bSizerHead->AddStretchSpacer( 1 ); // spacer
|
|
419
|
|
420 m_staticTextIdx = new wxStaticText( m_panelHead, wxID_ANY, wxT("インデックス"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
421 bSizerHead->Add( m_staticTextIdx, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
422
|
|
423 m_datePicker = new wxDatePickerCtrl( m_panelHead, ID_DTIDX, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_SHOWCENTURY|wxDP_DROPDOWN );
|
|
424 bSizerHead->Add( m_datePicker, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
425
|
|
426 m_buttonMkidx = new wxButton( m_panelHead, ID_MKIDX, wxT("作成"), wxDefaultPosition, wxSize(50,25), 0 );
|
|
427 bSizerHead->Add( m_buttonMkidx, 0, wxALL, 5 );
|
|
428
|
|
429 m_panelHead->SetSizer( bSizerHead );
|
|
430 m_panelHead->Layout();
|
|
431 bSizerHead->Fit( m_panelHead );
|
|
432
|
|
433 // メインペイン
|
|
434 wxBoxSizer* bSizerHtml;
|
|
435 bSizerHtml = new wxBoxSizer( wxVERTICAL );
|
|
436 m_splitter = new wxSplitterWindow( this, ID_SPLT, wxDefaultPosition, wxDefaultSize, 0 );
|
|
437
|
|
438 // 検索結果Html
|
|
439 m_html = new wxHtmlWindow( m_splitter, ID_HTML, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO );
|
|
440 m_html->LoadPage( wxT("html/start.html") );
|
|
441
|
|
442 /* after version 2.7
|
|
443 // 被保険者カナ検索Grid
|
|
444 m_gridHhs = new wxGrid( m_panelHtml, ID_HLST, wxDefaultPosition, wxDefaultSize, 0 );
|
|
445 m_gridHhs->CreateGrid( 0, 5 );
|
|
446 m_gridHhs->EnableEditing( true );
|
|
447 m_gridHhs->EnableGridLines( true );
|
|
448 m_gridHhs->EnableDragGridSize( false );
|
|
449 m_gridHhs->SetMargins( 0, 0 );
|
|
450
|
|
451 // Columns
|
|
452 m_gridHhs->AutoSizeColumns();
|
|
453 m_gridHhs->EnableDragColMove( false );
|
|
454 m_gridHhs->SetColLabelValue( 0, wxT("番号") );
|
|
455 m_gridHhs->SetColLabelValue( 1, wxT("氏名") );
|
|
456 m_gridHhs->SetColLabelValue( 2, wxT("カナ") );
|
|
457 m_gridHhs->SetColLabelValue( 3, wxT("生年月日") );
|
|
458 m_gridHhs->SetColLabelValue( 4, wxT("住所") );
|
|
459 m_gridHhs->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
|
|
460
|
|
461 // Cell Defaults
|
|
462 m_gridHhs->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_BOTTOM );
|
|
463 m_gridHhs->Hide();
|
|
464
|
|
465 bSizerHtml->Add( m_gridHhs, 0, wxALL, 5 );
|
|
466 */
|
|
467
|
|
468 // 審査会合議体表示Grid
|
|
469 m_gridCcn = new wxGrid( m_splitter, ID_CCN, wxDefaultPosition, wxDefaultSize, 0 );
|
|
470 m_gridCcn->CreateGrid( 0, 2 );
|
|
471 m_gridCcn->EnableEditing( true );
|
|
472 m_gridCcn->EnableGridLines( true );
|
|
473 m_gridCcn->EnableDragGridSize( false );
|
|
474 m_gridCcn->SetMargins( 0, 0 );
|
|
475 m_gridCcn->SetDefaultCellAlignment( wxALIGN_CENTRE, wxALIGN_BOTTOM );
|
|
476 m_gridCcn->Show(false);
|
|
477
|
|
478 // Columns
|
|
479 m_gridCcn->AutoSizeColumns();
|
|
480 m_gridCcn->EnableDragColMove( false );
|
|
481 m_gridCcn->SetColLabelValue( 0, wxT("審査会年月日") );
|
|
482 m_gridCcn->SetColLabelValue( 1, wxT("DB更新時刻") );
|
|
483 m_gridCcn->SetColSize( 0, 100 );
|
|
484 m_gridCcn->SetColSize( 1, 200 );
|
|
485 m_gridCcn->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
|
|
486
|
|
487 m_splitter->Initialize( m_html );
|
|
488 m_splitter->SetSizer( bSizerHtml );
|
|
489 m_splitter->Layout();
|
|
490 bSizerHtml->Fit( m_splitter );
|
|
491
|
|
492 // コマンドライン
|
|
493 m_panelCmd = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize );
|
|
494 wxBoxSizer* bSizerCmd;
|
|
495 bSizerCmd = new wxBoxSizer( wxHORIZONTAL );
|
|
496
|
|
497 m_staticTextCmd = new wxStaticText( m_panelCmd, wxID_ANY, wxT("コマンド?"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
498 bSizerCmd->Add( m_staticTextCmd, 0, wxALL, 5 );
|
|
499
|
|
500 m_cmdbox = new MyCmdBox( m_panelCmd, ID_CMD, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
|
|
501 bSizerCmd->Add( m_cmdbox, 1, wxALL, 3 );
|
|
502 m_cmdbox->SetFocus();
|
|
503
|
|
504 m_panelCmd->SetSizer( bSizerCmd );
|
|
505 m_panelCmd->Layout();
|
|
506 bSizerCmd->Fit( m_panelCmd );
|
|
507
|
|
508
|
|
509 bSizer->Add( m_panelHead, 0, wxEXPAND|wxTOP, 1 );
|
|
510 bSizer->Add( m_splitter, 1, wxEXPAND|wxALL, 1 );
|
|
511 bSizer->Add( m_panelCmd, 0, wxEXPAND|wxALL, 0 );
|
|
512
|
|
513 this->SetSizer( bSizer );
|
|
514 this->Layout();
|
|
515 }
|
|
516
|
|
517 // destructor
|
|
518 MyFrame::~MyFrame()
|
|
519 {
|
|
520 }
|
|
521
|
|
522 // Event Table
|
|
523 BEGIN_EVENT_TABLE( MyFrame, wxFrame )
|
|
524 EVT_MENU( wxID_EXIT, MyFrame::OnQuit )
|
|
525 EVT_MENU( wxID_ABOUT, MyFrame::OnAbout )
|
|
526 EVT_MENU( ID_MUPHHS, MyFrame::OnUpdateHhsDb )
|
|
527 EVT_MENU( ID_MLSCCN, MyFrame::OnListCcn )
|
|
528 EVT_MENU( ID_MDBBKUP, MyFrame::OnBackupDB )
|
|
529 EVT_MENU( ID_MDBOPT, MyFrame::OnOptimizeDB )
|
|
530 EVT_MENU( ID_MCHKHHS, MyFrame::OnCheckHhs )
|
|
531 EVT_MENU( ID_MOAD, MyFrame::OnOpenAppDir )
|
|
532 EVT_MENU( ID_MODD, MyFrame::OnOpenDataDir )
|
|
533 EVT_MENU( ID_MHELP, MyFrame::OnHelp )
|
|
534
|
|
535 //EVT_TEXT_ENTER( ID_SRCHHHS, MyFrame::OnHhsSearch ) after version 2.7
|
|
536 EVT_BUTTON( ID_MKIDX, MyFrame::OnMkIndex )
|
|
537
|
|
538 EVT_CLOSE( MyFrame::SaveConfig )
|
|
539 END_EVENT_TABLE()
|
|
540
|
|
541 // Event Handlers
|
|
542 /* 終了 */
|
|
543 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
544 {
|
|
545 Close(true);
|
|
546 }
|
|
547
|
|
548 /* オンラインヘルプ */
|
|
549 void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
|
|
550 {
|
|
551 HtmlHelpFrame *f = (HtmlHelpFrame*)FindWindowById( ID_HELP );
|
|
552
|
|
553 if ( f == NULL ) {
|
|
554 HtmlHelpFrame *helpframe = new HtmlHelpFrame( wxT("Online Help"), ID_HELP );
|
|
555 helpframe->Show(true);
|
|
556 }
|
|
557 else {
|
|
558 f->Raise();
|
|
559 }
|
|
560 }
|
|
561
|
|
562 /* バージョン情報 */
|
|
563 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
564 {
|
|
565 wxSQLite3Database sqlite;
|
|
566 wxMessageBox(
|
|
567 wxString::Format(
|
|
568 wxT("Version %d.%d ( build %d ) by %s\n")
|
|
569 wxT("with SQLite library %s\n")
|
|
570 wxT("running under %s."),
|
|
571 VER, REV, BLD, wxVERSION_STRING,
|
|
572 sqlite.GetVersion().c_str(),
|
|
573 wxGetOsDescription().c_str()
|
|
574 ),
|
|
575 wxT("About this program"), wxOK | wxICON_INFORMATION, this );
|
|
576 }
|
|
577
|
|
578 /* 被保険者検索 */
|
|
579 /* after version 2.7
|
|
580 void MyFrame::OnHhsSearch(wxCommandEvent& WXUNUSED(event))
|
|
581 {
|
|
582 this->m_html->Hide();
|
|
583 this->m_gridCcn->Hide();
|
|
584 this->m_gridHhs->Show(true);
|
|
585
|
|
586 wxString gszFile = wxGetCwd() + wxT("/db/hhs.db");
|
|
587 wxSQLite3Database hhsdb;
|
|
588 hhsdb.Open( gszFile );
|
|
589
|
|
590 wxSQLite3Statement stmt = hhsdb.PrepareStatement("SELECT count(*) FROM hhs_master WHERE kana LIKE ?");
|
|
591 stmt.Bind( 1, this->m_searchCtrlHname->GetValue() );
|
|
592 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
593 wxString cnt = q.GetString(0);
|
|
594
|
|
595 if ( cnt.Cmp(wxT("0")) == '0' ) {
|
|
596 wxString msg = cnt + wxT("指定した条件の被保険者はいませんでした.");
|
|
597 }
|
|
598 else {
|
|
599 wxString msg = cnt + wxT("件マッチしました.");
|
|
600 return ; // test now
|
|
601
|
|
602 stmt = hhsdb.PrepareStatement("SELECT hhs, name, kana, addr, birth, sex FROM hhs_master ORDER BY birth DESC");
|
|
603 q = stmt.ExecuteQuery();
|
|
604 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
605 while ( q.NextRow() ) {
|
|
606 wxString hhs = q.GetString(0);
|
|
607 wxString name = q.GetString(1);
|
|
608 wxString kana = q.GetString(2);
|
|
609 wxString addr = q.GetString(3);
|
|
610 wxString birth = q.GetString(4);
|
|
611 wxString sex = q.GetString(5);
|
|
612 // ここに gridに 追加するコード
|
|
613 }
|
|
614 }
|
|
615
|
|
616 stmt.Finalize();
|
|
617 hhsdb.Close();
|
|
618 }
|
|
619 */
|
|
620
|
|
621 /* インデックス作成 */
|
|
622 void MyFrame::OnMkIndex(wxCommandEvent& WXUNUSED(event))
|
|
623 {
|
|
624 wxDateTime dt = m_datePicker->GetValue();
|
|
625 wxString month = dt.Format(wxT("%m"));
|
|
626 wxString year = dt.Format(wxT("%Y"));
|
|
627 if ( month.IsSameAs(wxT("01")) || month.IsSameAs(wxT("02")) || month.IsSameAs(wxT("03")) ) {
|
|
628 long y;
|
|
629 year.ToLong( &y, 10 );
|
|
630 y--;
|
|
631 year = wxString::Format(wxT("%d"),y);
|
|
632 }
|
|
633 wxString pathroot = wxGetApp().rootdir + wxFILE_SEP_PATH + year + dt.Format(wxT("\\%Y%m%d"));
|
|
634 wxDir rootd(pathroot);
|
|
635 if ( !wxDir::Exists(pathroot) ) {
|
|
636 wxMessageBox( wxT("フォルダが存在しません.")+pathroot );
|
|
637 return;
|
|
638 }
|
|
639
|
|
640 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 200, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
|
|
641 pd.SetSize( wxSize(320,140) );
|
|
642 int count=0;
|
|
643
|
|
644 wxString ccndir;
|
|
645 bool cont = rootd.GetFirst( &ccndir, wxT("*.*"), wxDIR_DIRS );
|
|
646 while ( cont ) {
|
|
647 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
|
|
648 wxSQLite3Database ccndb;
|
|
649 ccndb.Open( gszFile );
|
|
650
|
|
651 wxSQLite3Statement stmt = ccndb.PrepareStatement("INSERT OR REPLACE INTO ccn VALUES( ?, datetime('now','localtime') )");
|
|
652 stmt.Bind( 1, dt.Format(wxT("%Y-%m-%d")) );
|
|
653 stmt.ExecuteQuery();
|
|
654
|
|
655 stmt.Finalize();
|
|
656
|
|
657 wxDir ccnd( pathroot + wxFILE_SEP_PATH + ccndir );
|
|
658 if ( !ccnd.IsOpened() ) return;
|
|
659 wxString hhsdir;
|
|
660 bool c = ccnd.GetFirst( &hhsdir, wxT("*.*"), wxDIR_DIRS );
|
|
661 wxRegEx reHhs(wxT("^0[1238][0-9]{8}$")); // 被保番チェック
|
|
662 while ( c ) {
|
|
663 if ( reHhs.Matches(hhsdir) ) {
|
|
664 wxString path = pathroot + wxFILE_SEP_PATH + ccndir + wxFILE_SEP_PATH + hhsdir;
|
|
665
|
|
666 stmt = ccndb.PrepareStatement("INSERT OR REPLACE INTO path VALUES( ?, ? )");
|
|
667 stmt.Bind( 1, hhsdir );
|
|
668 stmt.Bind( 2, path );
|
|
669 stmt.ExecuteQuery();
|
|
670
|
|
671 stmt.Finalize();
|
|
672 }
|
|
673 c = ccnd.GetNext(&hhsdir);
|
|
674 pd.Update( count++, hhsdir+wxT("@")+ccndir+wxT("を処理しました.") );
|
|
675 }
|
|
676 ccndb.Close();
|
|
677
|
|
678 cont = rootd.GetNext(&ccndir);
|
|
679 }
|
|
680 wxMessageBox(wxT("インデックス作成が終了しました."));
|
|
681 }
|
|
682
|
|
683 /* インデックス更新一覧 */
|
|
684 void MyFrame::OnListCcn(wxCommandEvent& WXUNUSED(event))
|
|
685 {
|
|
686 this->m_splitter->ReplaceWindow( this->m_html, this->m_gridCcn );
|
|
687 this->m_gridCcn->Show(true);
|
|
688 this->m_html->Show(false);
|
|
689 MyCmdBox *c = (MyCmdBox*)FindWindowById( ID_CMD );
|
|
690 c->Clear();
|
|
691
|
|
692 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
|
|
693 wxSQLite3Database ccndb;
|
|
694 ccndb.Open( gszFile );
|
|
695
|
|
696 wxSQLite3Statement stmt = ccndb.PrepareStatement("SELECT ymd, time FROM ccn ORDER BY ymd DESC, time DESC");
|
|
697 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
698 int r=0;
|
|
699 while ( q.NextRow() ) {
|
|
700 wxString ymd = q.GetString(0);
|
|
701 wxString time = q.GetString(1);
|
|
702 this->m_gridCcn->AppendRows(1);
|
|
703 this->m_gridCcn->SetCellValue(r,0,ymd);
|
|
704 this->m_gridCcn->SetCellValue(r,1,time);
|
|
705 r++;
|
|
706 }
|
|
707
|
|
708 stmt.Finalize();
|
|
709 ccndb.Close();
|
|
710 }
|
|
711
|
|
712 /* 被保険者DB更新 */
|
|
713 void MyFrame::OnUpdateHhsDb(wxCommandEvent& WXUNUSED(event))
|
|
714 {
|
|
715 FrameHhsDB *f = (FrameHhsDB*)FindWindowById( ID_HHSDB );
|
|
716
|
|
717 if ( f == NULL ) {
|
|
718 FrameHhsDB *hhsdb = new FrameHhsDB( this, ID_HHSDB );
|
|
719 hhsdb->Show(true);
|
|
720 }
|
|
721 else {
|
|
722 f->Raise();
|
|
723 }
|
|
724 return;
|
|
725 }
|
|
726
|
|
727 /* 被保険者整合性チェック */
|
|
728 void MyFrame::OnCheckHhs(wxCommandEvent& WXUNUSED(event))
|
|
729 {
|
|
730 wxString logfn = wxGetCwd() + wxT("/db/checkhhs.log");
|
|
731 wxTextFile logFile;
|
|
732 logFile.Open( logfn );
|
|
733 logFile.Clear();
|
|
734
|
|
735 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
|
|
736 wxSQLite3Database ccndb;
|
|
737 ccndb.Open( gszFile );
|
|
738 wxSQLite3Statement stmt = ccndb.PrepareStatement("ATTACH 'db/hhs.db' AS hhs");
|
|
739 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
740 stmt = ccndb.PrepareStatement("SELECT hhsno FROM path EXCEPT SELECT hhsno FROM hhs.hhs_master");
|
|
741 q = stmt.ExecuteQuery();
|
|
742
|
|
743 while ( q.NextRow() ) {
|
|
744 logFile.AddLine( q.GetString(0) );
|
|
745 }
|
|
746 stmt.Finalize();
|
|
747 ccndb.Close();
|
|
748
|
|
749 logFile.Write();
|
|
750 logFile.Close();
|
|
751
|
|
752 wxString msg = wxT("結果を ") + logfn + wxT(" に保存しました.");
|
|
753 wxMessageBox( msg );
|
|
754 return;
|
|
755 }
|
|
756
|
|
757 /* DBバックアップ */
|
|
758 void MyFrame::OnBackupDB(wxCommandEvent& WXUNUSED(event))
|
|
759 {
|
|
760 wxDateTime now = wxDateTime::Now();
|
|
761 wxString nowstr = now.Format(wxT("%Y%m%d%H%M%S"));
|
|
762
|
|
763 wxString org = wxGetCwd() + wxT("/db/ccn.db");
|
|
764 wxString bk = wxGetCwd() + wxT("/db/") + nowstr + wxT("_ccn.db");
|
|
765 wxCopyFile( org, bk, 0 );
|
|
766
|
|
767 org = wxGetCwd() + wxT("/db/hhs.db");
|
|
768 bk = wxGetCwd() + wxT("/db/") + nowstr + wxT("_hhs.db");
|
|
769 wxCopyFile( org, bk, 0 );
|
|
770
|
|
771 wxMessageBox( wxT("バックアップ終了.") );
|
|
772 return;
|
|
773 }
|
|
774
|
|
775 /* DB最適化 */
|
|
776 void MyFrame::OnOptimizeDB(wxCommandEvent& WXUNUSED(event))
|
|
777 {
|
|
778 return;
|
|
779 }
|
|
780
|
|
781 /* アプリケーションフォルダを開く */
|
|
782 void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event))
|
|
783 {
|
|
784 wxStandardPaths appdir;
|
|
785 wxString execmd = wxT("explorer ") + appdir.GetDataDir();
|
|
786 wxExecute( execmd );
|
|
787 return;
|
|
788 }
|
|
789
|
|
790 /* データフォルダを開く */
|
|
791 void MyFrame::OnOpenDataDir(wxCommandEvent& WXUNUSED(event))
|
|
792 {
|
|
793 wxString datadir = wxGetApp().rootdir;
|
|
794 wxString execmd = wxT("explorer ") + datadir;
|
|
795 wxExecute( execmd );
|
|
796 return;
|
|
797 }
|
|
798
|
|
799
|
|
800 /* 設定を保存 */
|
|
801 void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event))
|
|
802 {
|
|
803 if ( !IsIconized() && !IsMaximized() ) {
|
|
804 wxGetApp().rect = this->GetRect();
|
|
805 }
|
|
806
|
|
807 int i = m_cmdbox->hist.GetCount();
|
|
808 for ( int j=0; j<5; j++ ) {
|
|
809 wxGetApp().searchhist[j] = m_cmdbox->hist[--i];
|
|
810 }
|
|
811
|
|
812 Destroy();
|
|
813 }
|
|
814
|