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