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