19
|
1 // Filename : ccnframe.cpp
|
21
|
2 // Last Change: 23-Jul-2011.
|
17
|
3 //
|
|
4
|
19
|
5 #include "common.h"
|
21
|
6 #include "main.h"
|
19
|
7 #include "ccnframe.h"
|
21
|
8 #include "wx/wxsqlite3.h"
|
17
|
9
|
19
|
10 FrameCcn::FrameCcn( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
|
|
11 : wxFrame( parent, id, title, pos, size, style )
|
17
|
12 {
|
|
13 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
|
19
|
14 m_Panel = new wxPanel( this );
|
17
|
15
|
|
16 wxBoxSizer* bSizer;
|
|
17 bSizer = new wxBoxSizer( wxHORIZONTAL );
|
|
18
|
19
|
19 // DB表示
|
|
20 wxFlexGridSizer* fgSizer = new wxFlexGridSizer( 2, 5, 0, 0 );
|
|
21 fgSizer->AddGrowableRow(1);
|
17
|
22
|
19
|
23 m_staticText1 = new wxStaticText( m_Panel, wxID_ANY, wxT("開催年月日"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
24 fgSizer->Add( m_staticText1, 0, wxALL, 5 );
|
17
|
25
|
19
|
26 fgSizer->Add( 0, 0, 1, wxEXPAND, 5 );
|
17
|
27
|
19
|
28 m_staticText2 = new wxStaticText( m_Panel, wxID_ANY, wxT("合議体"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
29 fgSizer->Add( m_staticText2, 0, wxALL, 5 );
|
17
|
30
|
19
|
31 fgSizer->Add( 0, 0, 1, wxEXPAND, 5 );
|
17
|
32
|
19
|
33 m_staticText3 = new wxStaticText( m_Panel, wxID_ANY, wxT("被保険者"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
34 fgSizer->Add( m_staticText3, 0, wxALL, 5 );
|
17
|
35
|
21
|
36 m_listCtrlYmd = new wxListCtrl( m_Panel, ID_YMD, wxDefaultPosition, wxSize( 220, -1 ), wxLC_REPORT|wxLC_SINGLE_SEL );
|
19
|
37 fgSizer->Add( m_listCtrlYmd, 1, wxALL|wxEXPAND, 5 );
|
17
|
38
|
19
|
39 m_staticText4 = new wxStaticText( m_Panel, wxID_ANY, wxT("→"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
40 fgSizer->Add( m_staticText4, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
17
|
41
|
21
|
42 m_listCtrlCcn = new wxListCtrl( m_Panel, ID_CCN, wxDefaultPosition, wxSize( 220, -1 ), wxLC_REPORT|wxLC_SINGLE_SEL );
|
19
|
43 fgSizer->Add( m_listCtrlCcn, 1, wxALL|wxEXPAND, 5 );
|
17
|
44
|
19
|
45 m_staticText5 = new wxStaticText( m_Panel, wxID_ANY, wxT("→"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
46 fgSizer->Add( m_staticText5, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
|
17
|
47
|
21
|
48 m_listCtrlHhs = new wxListCtrl( m_Panel, ID_HHS, wxDefaultPosition, wxSize( 220, -1 ), wxLC_REPORT|wxLC_SINGLE_SEL );
|
19
|
49 fgSizer->Add( m_listCtrlHhs, 1, wxALL|wxEXPAND, 5 );
|
17
|
50
|
21
|
51 bSizer->Add( fgSizer, 1, wxEXPAND|wxALL, 5 );
|
17
|
52
|
19
|
53 // Index作成
|
|
54 wxGridBagSizer* gbSizer = new wxGridBagSizer( 0, 0 );
|
|
55 gbSizer->SetFlexibleDirection( wxVERTICAL );
|
|
56 gbSizer->SetNonFlexibleGrowMode( wxFLEX_GROWMODE_SPECIFIED );
|
|
57 gbSizer->AddGrowableRow(3);
|
17
|
58
|
19
|
59 m_btnPrevThu = new wxButton( m_Panel, ID_PRVTHU, wxT("<< 前木"), wxDefaultPosition, wxDefaultSize, 0 );
|
17
|
60 gbSizer->Add( m_btnPrevThu, wxGBPosition( 0, 0 ), wxGBSpan( 1, 1 ), wxALL, 5 );
|
|
61
|
19
|
62 m_btnNextThu = new wxButton( m_Panel, ID_NXTTHU, wxT("次木 >>"), wxDefaultPosition, wxDefaultSize, 0 );
|
17
|
63 gbSizer->Add( m_btnNextThu, wxGBPosition( 0, 1 ), wxGBSpan( 1, 1 ), wxALL, 5 );
|
|
64
|
21
|
65 m_datePicker = new wxDatePickerCtrl( m_Panel, ID_DTPICKER, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxDP_DROPDOWN|wxDP_SHOWCENTURY );
|
19
|
66 gbSizer->Add( m_datePicker, wxGBPosition( 1, 0 ), wxGBSpan( 1, 2 ), wxALIGN_CENTER|wxALL, 5 );
|
17
|
67
|
19
|
68 m_btnMkIdX = new wxButton( m_Panel, ID_MKIDX, wxT("作成"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
69 gbSizer->Add( m_btnMkIdX, wxGBPosition( 2, 1 ), wxGBSpan( 1, 1 ), wxALL, 5 );
|
17
|
70
|
19
|
71 m_btnClose = new wxButton( m_Panel, ID_CLOSE, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 );
|
|
72 gbSizer->Add( m_btnClose, wxGBPosition( 3, 1 ), wxGBSpan( 1, 1 ), wxALIGN_BOTTOM|wxALL, 5 );
|
17
|
73
|
21
|
74 bSizer->Add( gbSizer, 0, wxEXPAND|wxALL, 5 );
|
17
|
75
|
19
|
76 m_Panel->SetSizer( bSizer );
|
|
77 m_Panel->Layout();
|
17
|
78
|
21
|
79 this->SetSize( 1000, 400 );
|
17
|
80 this->Centre( wxBOTH );
|
19
|
81 InitListCtrl();
|
17
|
82 }
|
|
83
|
19
|
84 // Destructor
|
17
|
85 FrameCcn::~FrameCcn()
|
|
86 {
|
|
87 }
|
19
|
88
|
|
89 // Event Table
|
|
90 BEGIN_EVENT_TABLE( FrameCcn, wxFrame )
|
21
|
91 EVT_LIST_ITEM_SELECTED( ID_YMD, FrameCcn::OnSelectYmd )
|
|
92 EVT_LIST_ITEM_SELECTED( ID_CCN, FrameCcn::OnSelectCcn )
|
|
93 EVT_BUTTON( ID_PRVTHU, FrameCcn::OnPrevThu )
|
|
94 EVT_BUTTON( ID_NXTTHU, FrameCcn::OnNextThu )
|
|
95 EVT_BUTTON( ID_MKIDX, FrameCcn::OnMkIndex )
|
|
96 EVT_BUTTON( ID_CLOSE, FrameCcn::OnClose )
|
19
|
97 END_EVENT_TABLE()
|
|
98
|
|
99 // Event Handlers
|
21
|
100 void FrameCcn::OnSelectYmd(wxListEvent& WXUNUSED(event))
|
|
101 {
|
|
102 m_listCtrlCcn->DeleteAllItems();
|
|
103
|
|
104 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
|
|
105 wxSQLite3Database ccndb;
|
|
106 ccndb.Open( gszFile );
|
|
107
|
|
108 wxSQLite3Statement stmt = ccndb.PrepareStatement("SELECT path FROM path WHERE hhsno = ?");
|
|
109 stmt.Bind( 1, wxT("0300012345") );
|
|
110 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
111 if ( q.IsNull(0) ) {
|
|
112 return;
|
|
113 }
|
|
114 long r=0;
|
|
115 while ( q.NextRow() ) {
|
|
116 wxString ccn = q.GetString(0);
|
|
117 //wxString cnt = q.GetString(1);
|
|
118 m_listCtrlCcn->InsertItem( r, ccn );
|
|
119 //m_listCtrlCcn->SetItem( r, 1, cnt, -1 );
|
|
120 r++;
|
|
121 }
|
|
122 stmt.Finalize();
|
|
123 ccndb.Close();
|
|
124 }
|
|
125
|
|
126 void FrameCcn::OnSelectCcn(wxListEvent& WXUNUSED(event))
|
|
127 {
|
|
128 m_listCtrlHhs->DeleteAllItems();
|
|
129
|
|
130 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
|
|
131 wxSQLite3Database ccndb;
|
|
132 ccndb.Open( gszFile );
|
|
133
|
|
134 wxSQLite3Statement stmt = ccndb.PrepareStatement("SELECT ymd, MAX(time) FROM ccn GROUP BY ymd ORDER BY ymd DESC, time DESC");
|
|
135 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
136 long r=0;
|
|
137 while ( q.NextRow() ) {
|
|
138 wxString ymd = q.GetString(0);
|
|
139 wxString time = q.GetString(1);
|
|
140 m_listCtrlHhs->InsertItem( r, wxEmptyString );
|
|
141 m_listCtrlHhs->SetItemText( r, ymd );
|
|
142 r++;
|
|
143 }
|
|
144
|
|
145 stmt.Finalize();
|
|
146 ccndb.Close();
|
|
147 }
|
|
148
|
|
149 // 前木
|
|
150 void FrameCcn::OnPrevThu(wxCommandEvent& WXUNUSED(event))
|
|
151 {
|
|
152 wxDateTime dt = m_datePicker->GetValue();
|
|
153 wxDateSpan ds( 0, 0, 0, 1 );
|
|
154 dt -= ds;
|
|
155 dt.SetToPrevWeekDay( wxDateTime::Thu );
|
|
156 m_datePicker->SetValue( dt );
|
|
157
|
|
158 }
|
|
159 // 次木
|
|
160 void FrameCcn::OnNextThu(wxCommandEvent& WXUNUSED(event))
|
|
161 {
|
|
162 wxDateTime dt = m_datePicker->GetValue();
|
|
163 wxDateSpan ds( 0, 0, 0, 1 );
|
|
164 dt += ds;
|
|
165 dt.SetToNextWeekDay( wxDateTime::Thu );
|
|
166 m_datePicker->SetValue( dt );
|
|
167 }
|
|
168
|
|
169 /* インデックス作成 */
|
|
170 void FrameCcn::OnMkIndex(wxCommandEvent& WXUNUSED(event))
|
|
171 {
|
|
172 wxDateTime dt = m_datePicker->GetValue();
|
|
173 wxString month = dt.Format(wxT("%m"));
|
|
174 wxString year = dt.Format(wxT("%Y"));
|
|
175 if ( month.IsSameAs(wxT("01")) || month.IsSameAs(wxT("02")) || month.IsSameAs(wxT("03")) ) {
|
|
176 long y;
|
|
177 year.ToLong( &y, 10 );
|
|
178 y--;
|
|
179 year = wxString::Format(wxT("%d"),y);
|
|
180 }
|
|
181 wxString pathroot = wxGetApp().rootdir + wxFILE_SEP_PATH + year + dt.Format(wxT("\\%Y%m%d"));
|
|
182 wxDir rootd(pathroot);
|
|
183 if ( !wxDir::Exists(pathroot) ) {
|
|
184 wxMessageBox( wxT("フォルダが存在しません.")+pathroot );
|
|
185 return;
|
|
186 }
|
|
187
|
|
188 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 200, this, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
|
|
189 pd.SetSize( wxSize(320,140) );
|
|
190 int count=0;
|
|
191
|
|
192 wxString ccndir;
|
|
193 bool cont = rootd.GetFirst( &ccndir, wxT("*.*"), wxDIR_DIRS );
|
|
194 while ( cont ) {
|
|
195 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
|
|
196 wxSQLite3Database ccndb;
|
|
197 ccndb.Open( gszFile );
|
|
198
|
|
199 wxSQLite3Statement stmt = ccndb.PrepareStatement("INSERT OR REPLACE INTO ccn VALUES( ?, datetime('now','localtime') )");
|
|
200 stmt.Bind( 1, dt.Format(wxT("%Y-%m-%d")) );
|
|
201 stmt.ExecuteQuery();
|
|
202
|
|
203 stmt.Finalize();
|
|
204
|
|
205 wxDir ccnd( pathroot + wxFILE_SEP_PATH + ccndir );
|
|
206 if ( !ccnd.IsOpened() ) return;
|
|
207 wxString hhsdir;
|
|
208 bool c = ccnd.GetFirst( &hhsdir, wxT("*.*"), wxDIR_DIRS );
|
|
209 wxRegEx reHhs(wxT("^0[1238][0-9]{8}$")); // 被保番チェック
|
|
210 while ( c ) {
|
|
211 if ( reHhs.Matches(hhsdir) ) {
|
|
212 wxString path = pathroot + wxFILE_SEP_PATH + ccndir + wxFILE_SEP_PATH + hhsdir;
|
|
213
|
|
214 stmt = ccndb.PrepareStatement("INSERT OR REPLACE INTO path VALUES( ?, ? )");
|
|
215 stmt.Bind( 1, hhsdir );
|
|
216 stmt.Bind( 2, path );
|
|
217 stmt.ExecuteQuery();
|
|
218
|
|
219 stmt.Finalize();
|
|
220 }
|
|
221 c = ccnd.GetNext(&hhsdir);
|
|
222 pd.Update( count++, hhsdir+wxT("@")+ccndir+wxT("を処理しました.") );
|
|
223 }
|
|
224 ccndb.Close();
|
|
225
|
|
226 cont = rootd.GetNext(&ccndir);
|
|
227 }
|
|
228 wxMessageBox(wxT("インデックス作成が終了しました."));
|
|
229 }
|
|
230
|
|
231 // 閉じる
|
|
232 void FrameCcn::OnClose(wxCommandEvent& WXUNUSED(event))
|
|
233 {
|
|
234 this->Close();
|
|
235 }
|
19
|
236
|
|
237 // Functions
|
|
238 void FrameCcn::InitListCtrl()
|
|
239 {
|
|
240 wxListItem itemCol;
|
|
241 itemCol.SetText( wxT("年-月-日") );
|
|
242 m_listCtrlYmd->InsertColumn( 0, itemCol );
|
|
243 m_listCtrlYmd->SetColumnWidth( 0, 100 );
|
21
|
244 itemCol.SetText( wxT("更新時刻") );
|
|
245 m_listCtrlYmd->InsertColumn( 1, itemCol );
|
|
246 m_listCtrlYmd->SetColumnWidth( 1, 200 );
|
19
|
247
|
|
248 itemCol.SetText( wxT("合議体名") );
|
|
249 m_listCtrlCcn->InsertColumn( 0, itemCol );
|
|
250 m_listCtrlCcn->SetColumnWidth( 0, 100 );
|
|
251 itemCol.SetText( wxT("件数") );
|
|
252 m_listCtrlCcn->InsertColumn( 1, itemCol );
|
|
253 m_listCtrlCcn->SetColumnWidth( 1, 100 );
|
|
254
|
|
255 itemCol.SetText( wxT("被保険者番号") );
|
|
256 m_listCtrlHhs->InsertColumn( 0, itemCol );
|
|
257 m_listCtrlHhs->SetColumnWidth( 0, 100 );
|
|
258 itemCol.SetText( wxT("氏名") );
|
|
259 m_listCtrlHhs->InsertColumn( 1, itemCol );
|
|
260 m_listCtrlHhs->SetColumnWidth( 1, 100 );
|
|
261
|
21
|
262 // read from db
|
|
263 m_listCtrlCcn->DeleteAllItems();
|
|
264
|
|
265 wxString gszFile = wxGetCwd() + wxT("/db/ccn.db");
|
|
266 wxSQLite3Database ccndb;
|
|
267 ccndb.Open( gszFile );
|
|
268
|
|
269 wxSQLite3Statement stmt = ccndb.PrepareStatement("SELECT ymd, MAX(time) FROM ccn GROUP BY ymd ORDER BY ymd DESC, time DESC");
|
|
270 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
271 long r=0;
|
|
272 while ( q.NextRow() ) {
|
|
273 wxString ymd = q.GetString(0);
|
|
274 wxString time = q.GetString(1);
|
|
275 m_listCtrlYmd->InsertItem( r, ymd );
|
|
276 m_listCtrlYmd->SetItem( r, 1, time, -1 );
|
|
277 r++;
|
|
278 }
|
|
279
|
|
280 stmt.Finalize();
|
|
281 ccndb.Close();
|
19
|
282 }
|
|
283
|