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