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