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