0
|
1 // Filename : mainframe.cpp
|
22
|
2 // Last Change: 27-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 {
|
8
|
160 wxRegEx reHhs(wxT("^0[1238][0-9]{8}$")); // 1:被保番チェック
|
|
161 wxRegEx reCno(wxT("^[0-9]{1,2}$")); // 2:開くフォルダの番号
|
14
|
162 wxRegEx rePrint(wxT("^\\+$")); // 3:印刷するフォルダの番号
|
0
|
163
|
|
164 wxString cmd;
|
|
165 cmd = this->GetLineText(0);
|
|
166 int cond = 0;
|
|
167 if ( reHhs.Matches( cmd ) )
|
|
168 cond = 1;
|
|
169 else if ( reCno.Matches( cmd ) )
|
|
170 cond = 2;
|
8
|
171 else if ( rePrint.Matches( cmd ) )
|
|
172 cond = 3;
|
0
|
173
|
|
174 wxString htmlbody;
|
|
175
|
|
176 MyFrame *mf = (MyFrame*)FindWindowById( ID_MAIN );
|
|
177 wxHtmlWindow *hr = (wxHtmlWindow*)FindWindowById( ID_HTML );
|
|
178 switch (cond) {
|
|
179 // 被保険者番号が入力されたら
|
|
180 case 1: {
|
|
181 wxString hhs = cmd;
|
|
182 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
183 this->SetSelection( 0, this->GetLastPosition() );
|
|
184
|
|
185 // 被保険者検索
|
|
186 wxString gszFile = wxGetCwd() + wxT("/db/hhs.db");
|
|
187 wxSQLite3Database hhsdb;
|
|
188 hhsdb.Open( gszFile );
|
|
189
|
|
190 wxSQLite3Statement stmt = hhsdb.PrepareStatement("SELECT name FROM hhs_master WHERE hhsno = ?");
|
|
191 stmt.Bind( 1, hhs );
|
|
192 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
193
|
|
194 wxString name = wxT("登録なし");
|
|
195 if ( q.IsNull(0) ) {
|
|
196 wxString msg = wxT("データベースに存在しない被保険者です.") + hhs;
|
|
197 mf->m_statusBar->SetStatusText( msg, 0 );
|
|
198 }
|
|
199 else {
|
|
200 name = q.GetString(0);
|
|
201 hist.Add( hhs );
|
|
202 histpos++;
|
|
203 }
|
|
204 stmt.Finalize();
|
|
205 hhsdb.Close();
|
|
206
|
|
207 // パス検索
|
|
208 gszFile = wxGetCwd() + wxT("/db/ccn.db");
|
|
209 wxSQLite3Database ccndb;
|
|
210 ccndb.Open( gszFile );
|
|
211
|
|
212 stmt = ccndb.PrepareStatement("SELECT path FROM path WHERE hhsno = ? ORDER BY path DESC");
|
|
213 stmt.Bind( 1, hhs );
|
|
214 q = stmt.ExecuteQuery();
|
|
215 if ( q.IsNull(0) ) {
|
|
216 hr->LoadPage( wxT("html/notfound.html") );
|
|
217 mf->m_statusBar->SetStatusText( wxT("データが存在しません."), 0 );
|
|
218 return;
|
|
219 }
|
|
220
|
|
221 path.Clear();
|
|
222 wxRegEx reDate(wxT("(^.*20[0-9]{2}.)(20[0-9]{2})([0-2][0-9])([0-9]{2})(.*$)"));
|
|
223
|
|
224 int i=1;
|
11
|
225 int clrflg = -1;
|
0
|
226 while ( q.NextRow() ) {
|
11
|
227 wxString filepath = q.GetString(0);
|
10
|
228 // 氏名画像生成
|
11
|
229 wxDir dir(filepath);
|
|
230 wxString file;
|
|
231 if ( !dir.IsOpened() ) return;
|
10
|
232
|
11
|
233 if ( clrflg == -1 ) {
|
10
|
234 bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES );
|
|
235 if ( cout ) {
|
|
236 wxString s = filepath + wxFILE_SEP_PATH + file;
|
|
237 wxImage img_org( s, wxBITMAP_TYPE_JPEG );
|
|
238 wxImage img_name;
|
|
239 img_name = img_org.GetSubImage( wxRect( wxPoint(328,556), wxSize(626,288) ) );
|
11
|
240 img_name = img_name.Scale( 200, 92 );
|
10
|
241 img_name.SaveFile( wxT("tmp/tmp.jpg") );
|
11
|
242
|
|
243 // HTML生成
|
|
244 htmlbody = wxT("<html><body>");
|
|
245 htmlbody += wxT("<table border=0>");
|
|
246 htmlbody += wxT("<tr bgcolor=\"#ffffcc\"><td>該当者: </td><td></td></tr>");
|
|
247 htmlbody += wxT("<tr><td><b>") + name + wxT("</b></td>");
|
|
248 htmlbody += wxT("<td> ( ") + hhs + wxT(" )") + wxT("</td></tr>");
|
|
249 htmlbody += wxT("</table><br /><br />");
|
|
250 htmlbody += wxT("<table border=0>");
|
|
251 htmlbody += wxT("<tr><td bgcolor=\"#ffffcc\">番号1の画像情報:</td></tr>");
|
|
252 htmlbody += wxT("<tr><td><img src=\"tmp/tmp.jpg\" /></td></tr>");
|
|
253 htmlbody += wxT("</table>");
|
|
254 htmlbody += wxT("<br /><br />検索結果");
|
|
255 htmlbody += wxT("<table border=1>");
|
|
256 htmlbody += wxT("<tr bgcolor=\"#ffcc33\"><th>番号</th><th>日付</th><th>フォルダ</th></tr>");
|
10
|
257 }
|
11
|
258 clrflg = 1;
|
|
259 }
|
10
|
260
|
|
261 path.Add(filepath);
|
|
262 wxString date = filepath;
|
0
|
263 reDate.ReplaceAll( &date, wxT("\\2-\\3-\\4") );
|
|
264
|
|
265 if ( clrflg ) {
|
|
266 htmlbody += wxT("<tr bgcolor=\"#ffffcc\">");
|
|
267 clrflg = 0;
|
|
268 }
|
|
269 else {
|
|
270 htmlbody += wxT("<tr bgcolor=\"#ffff99\">");
|
|
271 clrflg = 1;
|
|
272 }
|
1
|
273 htmlbody += wxT("<td align=\"center\">") + wxString::Format(wxT("%d"),i++) + wxT("</td>"); // 番号
|
|
274 htmlbody += wxT("<td>") + date + wxT("</td>"); // 日付
|
|
275 htmlbody += wxT("<td>") + q.GetString(0) + wxT("</td></tr>"); // フォルダパス
|
0
|
276 }
|
|
277 stmt.Finalize();
|
|
278 ccndb.Close();
|
|
279 path.Shrink();
|
|
280
|
|
281 htmlbody += wxT("</table>");
|
|
282 htmlbody += wxT("<br />");
|
|
283 htmlbody += wxT("<div>");
|
14
|
284 htmlbody += wxT("テンキーの「+」ボタンで番号1の画像を印刷できます.<br />");
|
0
|
285 htmlbody += wxT("フォルダを開くには,番号を入力してください.<br />");
|
|
286 htmlbody += wxT("他の被保険者を検索するには,被保番を入力してください.");
|
|
287 htmlbody += wxT("</div>");
|
|
288 htmlbody += wxT("</body></html>");
|
|
289
|
|
290 hr->SetPage( htmlbody );
|
|
291
|
|
292 break;
|
|
293 }
|
|
294 // フォルダ表示
|
|
295 case 2: {
|
|
296 this->SetSelection( 0, this->GetLastPosition() );
|
|
297 long val;
|
|
298 cmd.ToLong( &val, 10 );
|
|
299 val--;
|
|
300 if ( path.IsEmpty()
|
|
301 || val < 0
|
|
302 || val > path.GetCount()-1 ) {
|
11
|
303 mf->m_statusBar->SetStatusText( wxT("不適切な入力です.警告コード2"), 0 );
|
0
|
304 break;
|
|
305 }
|
|
306 wxString execmd = wxT("explorer ") + path[val];
|
|
307 wxExecute( execmd );
|
|
308 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
309
|
16
|
310 WriteLog( cmd, path[val] );
|
0
|
311 break;
|
|
312 }
|
8
|
313 // ファイル印刷
|
|
314 case 3: {
|
11
|
315 this->SetSelection( 0, this->GetLastPosition() );
|
|
316 if ( path.IsEmpty() ) {
|
|
317 mf->m_statusBar->SetStatusText( wxT("不適切な入力です.警告コード3"), 0 );
|
|
318 break;
|
|
319 }
|
12
|
320 PrintImages( path[0] );
|
16
|
321 WriteLog( cmd, path[0] );
|
8
|
322 break;
|
|
323 }
|
0
|
324 // 制御用コマンド
|
|
325 case 0: {
|
|
326 path.Clear();
|
|
327 if ( cmd.Cmp(wxT("s")) == 0 ) {
|
|
328 hr->LoadPage( wxT("html/start.html") );
|
|
329 this->ChangeValue( wxEmptyString );
|
|
330 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
331 return;
|
|
332 }
|
|
333 if ( cmd.Cmp(wxT("c")) == 0 ) {
|
|
334 hr->LoadPage( wxT("Searcher2.conf") );
|
|
335 this->ChangeValue( wxEmptyString );
|
|
336 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
337 return;
|
|
338 }
|
|
339 if ( cmd.Cmp(wxT("t")) == 0 ) {
|
|
340 hr->LoadPage( wxT("html/todo.html") );
|
|
341 this->ChangeValue( wxEmptyString );
|
|
342 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
343 return;
|
|
344 }
|
|
345 if ( cmd.Cmp(wxT("l")) == 0 ) {
|
10
|
346 hr->LoadPage( wxT("tmp/log.txt") );
|
0
|
347 this->ChangeValue( wxEmptyString );
|
|
348 mf->m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
349 return;
|
|
350 }
|
|
351 if ( cmd.Cmp(wxT("**")) == 0 ) {
|
|
352 mf->m_statusBar->SetStatusText( wxT("Now Saving..."), 0 );
|
|
353 mf->Close();
|
|
354 return;
|
|
355 }
|
|
356
|
|
357 mf->m_statusBar->SetStatusText( wxT("不適切な入力です."), 0 );
|
|
358 this->SetSelection( 0, this->GetLastPosition() );
|
|
359
|
|
360 break;
|
|
361 }
|
|
362 //
|
|
363 default: {
|
|
364 break;
|
|
365 }
|
|
366 }
|
|
367 }
|
|
368
|
12
|
369 // functions
|
|
370 void MyCmdBox::PrintImages( wxString& path )
|
|
371 {
|
14
|
372 wxHtmlPrintout hpout( wxT("Searcher2") );
|
|
373 hpout.SetMargins( 0,0,0,0,0 );
|
|
374 wxPrintDialogData pd;
|
|
375 wxPrinter p( &pd );
|
12
|
376
|
|
377 wxDir dir(path);
|
|
378 wxString file;
|
|
379 if ( !dir.IsOpened() ) return;
|
|
380
|
|
381 bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES );
|
14
|
382 bool mask_flg = true;
|
|
383 wxRect cmname( wxPoint(156,224), wxSize(1204,122) );
|
|
384 wxRect cmno( wxPoint(856,1024), wxSize(1060,598) );
|
12
|
385 while ( cout ) {
|
|
386 file = path + wxFILE_SEP_PATH + file;
|
|
387 file.Replace( wxT("\\"), wxT("/") );
|
|
388 wxString html;
|
|
389
|
14
|
390 if ( mask_flg ) { // 1枚目はマスクする
|
|
391 wxImage img_org( file, wxBITMAP_TYPE_JPEG );
|
|
392 img_org.SetRGB( cmname, 255, 255, 255 );
|
|
393 img_org.SetRGB( cmno, 255, 255, 255 );
|
|
394 img_org.SaveFile( wxT("tmp/tmp.jpg") );
|
|
395
|
|
396 html = html + wxT("<html><body>");
|
|
397 html = html + wxT("<img src=\"tmp/tmp.jpg\" width=\"750\" height=\"1060\"/>");
|
|
398 html = html + wxT("</body></html>");
|
|
399 hpout.SetHtmlText( html, wxEmptyString, false );
|
|
400 p.Print( NULL, &hpout, true );
|
|
401 pd = p.GetPrintDialogData();
|
|
402 mask_flg = false;
|
|
403 }
|
|
404 else {
|
|
405 html = html + wxT("<html><body>");
|
|
406 html = html + wxT("<img src=\"") + file + wxT("\" width=\"750\" height=\"1060\"/>");
|
|
407 html = html + wxT("</body></html>");
|
|
408 hpout.SetHtmlText( html, wxEmptyString, false );
|
|
409 p.Print( NULL, &hpout, false );
|
|
410 }
|
12
|
411 cout = dir.GetNext( &file );
|
|
412 }
|
|
413 return;
|
|
414 }
|
|
415
|
16
|
416 // 検索履歴をログに保存
|
|
417 void MyCmdBox::WriteLog( wxString& cmd, wxString& path )
|
|
418 {
|
|
419 wxString logfn = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("log.txt");
|
|
420 wxTextFile logFile;
|
|
421 logFile.Open( logfn );
|
|
422 wxDateTime now = wxDateTime::Now();
|
|
423 wxString log = now.Format( wxT("%Y-%m-%d %H:%M:%S") ) + wxT(" ") + cmd + wxT(" ") + path;
|
|
424 logFile.AddLine( log );
|
|
425 logFile.Write();
|
|
426 logFile.Close();
|
|
427
|
|
428 return;
|
|
429 }
|
|
430
|
0
|
431 //////////////////////////////////////////////////////////////////////////
|
|
432 // frame constructor
|
|
433 MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title )
|
|
434 : wxFrame( parent, id, title )
|
|
435 {
|
|
436 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
|
437 // set the frame icon
|
|
438 SetIcon(wxICON(sample));
|
|
439
|
|
440 // メニューバー
|
|
441 m_menubar = new wxMenuBar();
|
|
442
|
|
443 m_menuFile = new wxMenu();
|
|
444 wxMenu *menuMaintain = new wxMenu();
|
|
445 m_menuFile->AppendSubMenu( menuMaintain, wxT("メンテナンス") );
|
22
|
446 menuMaintain->Append( ID_MUPHHS, wxT("被保険者DB更新"), wxT("Update hhs-db") );
|
0
|
447 menuMaintain->Append( ID_MDBBKUP, wxT("データベースバックアップ"), wxT("Backup DBs") );
|
|
448 menuMaintain->Append( ID_MDBOPT, wxT("データベース最適化"), wxT("Optimize DBs") );
|
|
449 menuMaintain->Enable( ID_MDBOPT, false );
|
|
450 menuMaintain->Append( ID_MCHKHHS, wxT("被保者整合性チェック"), wxT("Check hhs") );
|
|
451 m_menuFile->AppendSeparator(); //----
|
|
452 wxMenu *menuOpendir = new wxMenu();
|
|
453 m_menuFile->AppendSubMenu( menuOpendir, wxT("フォルダを開く") );
|
22
|
454 menuOpendir->Append( ID_MOPAD, wxT("アプリケーションフォルダ"), wxT("Open App Folder") );
|
|
455 menuOpendir->Append( ID_MOPDD, wxT("データフォルダ"), wxT("Open Data Folder") );
|
0
|
456 m_menuFile->AppendSeparator(); //----
|
|
457 m_menuFile->Append( wxID_EXIT, wxT("終了(&X)\tAlt-X"), wxT("Quit this program") );
|
|
458
|
|
459 m_menuHelp = new wxMenu();
|
|
460 m_menuHelp->Append( ID_MHELP, wxT("&Help"), wxT("Show help") );
|
|
461 m_menuHelp->Append( wxID_ABOUT, wxT("&About...\tF1"), wxT("Show about dialog") );
|
|
462
|
|
463 // now append the freshly created menu to the menu bar...
|
|
464 m_menubar->Append( m_menuFile, wxT("ファイル(&F)") );
|
|
465 m_menubar->Append( m_menuHelp, wxT("ヘルプ(&H)") );
|
|
466
|
|
467 this->SetMenuBar( m_menubar );
|
|
468
|
|
469 // ツールバー
|
|
470 //m_toolBar = new wxToolBar( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTB_HORIZONTAL|wxNO_BORDER );
|
|
471 //wxBitmap bmpPrint( print_xpm );
|
|
472 //wxBitmap bmpIndex( index_xpm );
|
|
473
|
|
474 // ステータスバー
|
|
475 int widths[] = { -1, 120, 100 };
|
|
476 m_statusBar = this->CreateStatusBar( WXSIZEOF(widths), wxST_SIZEGRIP );
|
|
477 m_statusBar->SetStatusWidths( WXSIZEOF(widths), widths );
|
|
478 m_statusBar->SetStatusText( wxEmptyString, 0 );
|
|
479
|
|
480 wxBoxSizer* bSizer;
|
|
481 bSizer = new wxBoxSizer( wxVERTICAL );
|
22
|
482 m_panel = new wxPanel( this );
|
0
|
483
|
22
|
484 wxBoxSizer* bSizerPanel;
|
|
485 bSizerPanel = new wxBoxSizer( wxVERTICAL );
|
|
486
|
0
|
487 // controls here
|
22
|
488 m_panelHead = new wxPanel( m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize );
|
0
|
489 wxBoxSizer* bSizerHead;
|
|
490 bSizerHead = new wxBoxSizer( wxHORIZONTAL );
|
|
491
|
|
492 bSizerHead->AddStretchSpacer( 1 ); // spacer
|
|
493 m_staticTextIdx = new wxStaticText( m_panelHead, wxID_ANY, wxT("インデックス"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
494 bSizerHead->Add( m_staticTextIdx, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
22
|
495
|
|
496 m_btnLsCcn = new wxButton( m_panelHead, ID_LSCCN, wxT("一覧"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
497 bSizerHead->Add( m_btnLsCcn, 0, wxALL, 5 );
|
|
498
|
|
499 m_btnPrevThu = new wxButton( m_panelHead, ID_PRVTHU, wxT("<< 前木"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
500 bSizerHead->Add( m_btnPrevThu, 0, wxALL, 5 );
|
0
|
501
|
22
|
502 m_datePicker = new wxDatePickerCtrl( m_panelHead, ID_DTPICKER, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY );
|
|
503 bSizerHead->Add( m_datePicker, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
|
504
|
|
505 m_btnNextThu = new wxButton( m_panelHead, ID_NXTTHU, wxT("次木 >>"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
506 bSizerHead->Add( m_btnNextThu, 0, wxALL, 5 );
|
0
|
507
|
22
|
508 m_btnMkIdx = new wxButton( m_panelHead, ID_MKIDX, wxT("作成"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
509 bSizerHead->Add( m_btnMkIdx, 0, wxALL, 5 );
|
|
510
|
0
|
511 m_panelHead->SetSizer( bSizerHead );
|
|
512 m_panelHead->Layout();
|
|
513 bSizerHead->Fit( m_panelHead );
|
|
514
|
|
515 // 検索結果Html
|
22
|
516 m_html = new wxHtmlWindow( m_panel, ID_HTML, wxDefaultPosition, wxDefaultSize, wxHW_SCROLLBAR_AUTO );
|
0
|
517 m_html->LoadPage( wxT("html/start.html") );
|
|
518
|
|
519 // コマンドライン
|
22
|
520 m_panelCmd = new wxPanel( m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize );
|
0
|
521 wxBoxSizer* bSizerCmd;
|
|
522 bSizerCmd = new wxBoxSizer( wxHORIZONTAL );
|
|
523
|
|
524 m_staticTextCmd = new wxStaticText( m_panelCmd, wxID_ANY, wxT("コマンド?"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
525 bSizerCmd->Add( m_staticTextCmd, 0, wxALL, 5 );
|
|
526
|
|
527 m_cmdbox = new MyCmdBox( m_panelCmd, ID_CMD, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
|
|
528 bSizerCmd->Add( m_cmdbox, 1, wxALL, 3 );
|
|
529 m_cmdbox->SetFocus();
|
|
530
|
|
531 m_panelCmd->SetSizer( bSizerCmd );
|
|
532 m_panelCmd->Layout();
|
|
533 bSizerCmd->Fit( m_panelCmd );
|
|
534
|
22
|
535 bSizerPanel->Add( m_panelHead, 0, wxEXPAND|wxTOP, 1 );
|
|
536 bSizerPanel->Add( m_html, 1, wxEXPAND|wxALL, 1 );
|
|
537 bSizerPanel->Add( m_panelCmd, 0, wxEXPAND|wxALL, 0 );
|
|
538
|
|
539 m_panel->SetSizer( bSizerPanel );
|
|
540 m_panel->Layout();
|
|
541 bSizerPanel->Fit( m_panel );
|
0
|
542
|
22
|
543 bSizer->Add( m_panel, 1, wxEXPAND|wxALL, 0 );
|
0
|
544 this->SetSizer( bSizer );
|
|
545 this->Layout();
|
22
|
546 this->SetMinSize( wxSize( 550, 600 ) );
|
0
|
547 }
|
|
548
|
|
549 // destructor
|
|
550 MyFrame::~MyFrame()
|
|
551 {
|
|
552 }
|
|
553
|
|
554 // Event Table
|
|
555 BEGIN_EVENT_TABLE( MyFrame, wxFrame )
|
22
|
556 EVT_SIZE( MyFrame::OnSize )
|
|
557 EVT_MOVE( MyFrame::OnMove )
|
0
|
558 EVT_MENU( wxID_EXIT, MyFrame::OnQuit )
|
|
559 EVT_MENU( wxID_ABOUT, MyFrame::OnAbout )
|
|
560 EVT_MENU( ID_MUPHHS, MyFrame::OnUpdateHhsDb )
|
|
561 EVT_MENU( ID_MDBBKUP, MyFrame::OnBackupDB )
|
|
562 EVT_MENU( ID_MDBOPT, MyFrame::OnOptimizeDB )
|
|
563 EVT_MENU( ID_MCHKHHS, MyFrame::OnCheckHhs )
|
22
|
564 EVT_MENU( ID_MOPAD, MyFrame::OnOpenAppDir )
|
|
565 EVT_MENU( ID_MOPDD, MyFrame::OnOpenDataDir )
|
0
|
566 EVT_MENU( ID_MHELP, MyFrame::OnHelp )
|
22
|
567 EVT_BUTTON( ID_PRVTHU, MyFrame::OnPrevThu )
|
|
568 EVT_BUTTON( ID_NXTTHU, MyFrame::OnNextThu )
|
|
569 EVT_BUTTON( ID_MKIDX, MyFrame::OnMkIndex )
|
|
570 EVT_BUTTON( ID_LSCCN, MyFrame::OnListCcn )
|
0
|
571 EVT_CLOSE( MyFrame::SaveConfig )
|
|
572 END_EVENT_TABLE()
|
|
573
|
|
574 // Event Handlers
|
22
|
575 /* サイズ変更 */
|
|
576 void MyFrame::OnSize(wxSizeEvent& WXUNUSED(event))
|
|
577 {
|
|
578 wxRect r = this->GetRect();
|
|
579 int w = r.GetWidth();
|
|
580 int h = r.GetHeight();
|
|
581 SetStatusText( wxString::Format(wxT("%dx%d"),w,h), 2 );
|
|
582 return;
|
|
583 }
|
|
584 /* ウィンドウ移動 */
|
|
585 void MyFrame::OnMove(wxMoveEvent& WXUNUSED(event))
|
|
586 {
|
|
587 wxRect r = this->GetRect();
|
|
588 int x = r.GetX();
|
|
589 int y = r.GetY();
|
|
590 SetStatusText( wxString::Format(wxT("(%d,%d)"),x,y), 2 );
|
|
591 return;
|
|
592 }
|
0
|
593 /* 終了 */
|
|
594 void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
|
|
595 {
|
|
596 Close(true);
|
|
597 }
|
|
598
|
|
599 /* オンラインヘルプ */
|
|
600 void MyFrame::OnHelp(wxCommandEvent& WXUNUSED(event))
|
|
601 {
|
|
602 HtmlHelpFrame *f = (HtmlHelpFrame*)FindWindowById( ID_HELP );
|
|
603
|
|
604 if ( f == NULL ) {
|
|
605 HtmlHelpFrame *helpframe = new HtmlHelpFrame( wxT("Online Help"), ID_HELP );
|
14
|
606 helpframe->SetSize(600,600);
|
0
|
607 helpframe->Show(true);
|
|
608 }
|
|
609 else {
|
|
610 f->Raise();
|
|
611 }
|
|
612 }
|
|
613
|
|
614 /* バージョン情報 */
|
|
615 void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
|
|
616 {
|
|
617 wxSQLite3Database sqlite;
|
|
618 wxMessageBox(
|
|
619 wxString::Format(
|
|
620 wxT("Version %d.%d ( build %d ) by %s\n")
|
|
621 wxT("with SQLite library %s\n")
|
|
622 wxT("running under %s."),
|
|
623 VER, REV, BLD, wxVERSION_STRING,
|
|
624 sqlite.GetVersion().c_str(),
|
|
625 wxGetOsDescription().c_str()
|
|
626 ),
|
|
627 wxT("About this program"), wxOK | wxICON_INFORMATION, this );
|
|
628 }
|
|
629
|
22
|
630 // 前木
|
|
631 void MyFrame::OnPrevThu(wxCommandEvent& WXUNUSED(event))
|
0
|
632 {
|
22
|
633 wxDateTime dt = m_datePicker->GetValue();
|
|
634 wxDateSpan ds( 0, 0, 0, 1 );
|
|
635 dt -= ds;
|
|
636 dt.SetToPrevWeekDay( wxDateTime::Thu );
|
|
637 m_datePicker->SetValue( dt );
|
0
|
638 }
|
22
|
639 // 次木
|
|
640 void MyFrame::OnNextThu(wxCommandEvent& WXUNUSED(event))
|
|
641 {
|
|
642 wxDateTime dt = m_datePicker->GetValue();
|
|
643 wxDateSpan ds( 0, 0, 0, 1 );
|
|
644 dt += ds;
|
|
645 dt.SetToNextWeekDay( wxDateTime::Thu );
|
|
646 m_datePicker->SetValue( dt );
|
|
647 }
|
0
|
648
|
|
649 /* インデックス作成 */
|
|
650 void MyFrame::OnMkIndex(wxCommandEvent& WXUNUSED(event))
|
|
651 {
|
22
|
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 );
|
0
|
678
|
22
|
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);
|
0
|
707 }
|
22
|
708 wxMessageBox(wxT("インデックス作成が終了しました."));
|
0
|
709 }
|
|
710
|
22
|
711 /* インデックス一覧 */
|
0
|
712 void MyFrame::OnListCcn(wxCommandEvent& WXUNUSED(event))
|
|
713 {
|
22
|
714 FrameCcn *fc = new FrameCcn( NULL, ID_CCN, wxT("Index Viewer"), wxDefaultPosition, wxDefaultSize, wxCAPTION|wxFRAME_NO_TASKBAR|wxTAB_TRAVERSAL );
|
|
715 fc->Show(true);
|
0
|
716 }
|
|
717
|
|
718 /* 被保険者DB更新 */
|
|
719 void MyFrame::OnUpdateHhsDb(wxCommandEvent& WXUNUSED(event))
|
|
720 {
|
|
721 FrameHhsDB *f = (FrameHhsDB*)FindWindowById( ID_HHSDB );
|
|
722
|
|
723 if ( f == NULL ) {
|
|
724 FrameHhsDB *hhsdb = new FrameHhsDB( this, ID_HHSDB );
|
|
725 hhsdb->Show(true);
|
|
726 }
|
|
727 else {
|
|
728 f->Raise();
|
|
729 }
|
|
730 return;
|
|
731 }
|
|
732
|
|
733 /* 被保険者整合性チェック */
|
|
734 void MyFrame::OnCheckHhs(wxCommandEvent& WXUNUSED(event))
|
|
735 {
|
10
|
736 wxString logfn = wxGetCwd() + wxT("/tmp/checkhhs.log");
|
0
|
737 wxTextFile logFile;
|
|
738 logFile.Open( logfn );
|
|
739 logFile.Clear();
|
|
740
|
|
741 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
|
|
742 wxSQLite3Database ccndb;
|
|
743 ccndb.Open( gszFile );
|
|
744 wxSQLite3Statement stmt = ccndb.PrepareStatement("ATTACH 'db/hhs.db' AS hhs");
|
|
745 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
746 stmt = ccndb.PrepareStatement("SELECT hhsno FROM path EXCEPT SELECT hhsno FROM hhs.hhs_master");
|
|
747 q = stmt.ExecuteQuery();
|
|
748
|
|
749 while ( q.NextRow() ) {
|
|
750 logFile.AddLine( q.GetString(0) );
|
|
751 }
|
|
752 stmt.Finalize();
|
|
753 ccndb.Close();
|
|
754
|
|
755 logFile.Write();
|
|
756 logFile.Close();
|
|
757
|
|
758 wxString msg = wxT("結果を ") + logfn + wxT(" に保存しました.");
|
|
759 wxMessageBox( msg );
|
|
760 return;
|
|
761 }
|
|
762
|
|
763 /* DBバックアップ */
|
|
764 void MyFrame::OnBackupDB(wxCommandEvent& WXUNUSED(event))
|
|
765 {
|
|
766 wxDateTime now = wxDateTime::Now();
|
|
767 wxString nowstr = now.Format(wxT("%Y%m%d%H%M%S"));
|
|
768
|
|
769 wxString org = wxGetCwd() + wxT("/db/ccn.db");
|
|
770 wxString bk = wxGetCwd() + wxT("/db/") + nowstr + wxT("_ccn.db");
|
|
771 wxCopyFile( org, bk, 0 );
|
|
772
|
|
773 org = wxGetCwd() + wxT("/db/hhs.db");
|
|
774 bk = wxGetCwd() + wxT("/db/") + nowstr + wxT("_hhs.db");
|
|
775 wxCopyFile( org, bk, 0 );
|
|
776
|
|
777 wxMessageBox( wxT("バックアップ終了.") );
|
|
778 return;
|
|
779 }
|
|
780
|
|
781 /* DB最適化 */
|
|
782 void MyFrame::OnOptimizeDB(wxCommandEvent& WXUNUSED(event))
|
|
783 {
|
|
784 return;
|
|
785 }
|
|
786
|
|
787 /* アプリケーションフォルダを開く */
|
|
788 void MyFrame::OnOpenAppDir(wxCommandEvent& WXUNUSED(event))
|
|
789 {
|
|
790 wxStandardPaths appdir;
|
|
791 wxString execmd = wxT("explorer ") + appdir.GetDataDir();
|
|
792 wxExecute( execmd );
|
|
793 return;
|
|
794 }
|
|
795
|
|
796 /* データフォルダを開く */
|
|
797 void MyFrame::OnOpenDataDir(wxCommandEvent& WXUNUSED(event))
|
|
798 {
|
|
799 wxString datadir = wxGetApp().rootdir;
|
|
800 wxString execmd = wxT("explorer ") + datadir;
|
|
801 wxExecute( execmd );
|
|
802 return;
|
|
803 }
|
|
804
|
|
805
|
|
806 /* 設定を保存 */
|
|
807 void MyFrame::SaveConfig(wxCloseEvent& WXUNUSED(event))
|
|
808 {
|
|
809 if ( !IsIconized() && !IsMaximized() ) {
|
|
810 wxGetApp().rect = this->GetRect();
|
|
811 }
|
|
812
|
|
813 int i = m_cmdbox->hist.GetCount();
|
|
814 for ( int j=0; j<5; j++ ) {
|
|
815 wxGetApp().searchhist[j] = m_cmdbox->hist[--i];
|
|
816 }
|
|
817
|
|
818 Destroy();
|
|
819 }
|
|
820
|