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