0
|
1 // Filename : db.cpp
|
2
|
2 // Last Change: 23-Aug-2013.
|
0
|
3 //
|
|
4
|
|
5 #include "db.h"
|
|
6 #include "wx/wxsqlite3.h"
|
|
7
|
2
|
8 //********** HHS-DB **********//
|
|
9 /* 被保番で被保険者情報を取得 */
|
1
|
10 wxString GetHhsInfoByHhsNo( wxString hhsno )
|
0
|
11 {
|
1
|
12 wxString name, addr;
|
0
|
13
|
|
14 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("hhs.db");
|
|
15 wxSQLite3Database hhsdb;
|
|
16 hhsdb.Open( gszFile );
|
|
17
|
2
|
18 wxSQLite3Statement stmt = hhsdb.PrepareStatement( "SELECT name, addr FROM hhs_master WHERE hhsno = ?" );
|
0
|
19 stmt.Bind( 1, hhsno );
|
|
20 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
21 if ( !q.IsNull(0) ) {
|
|
22 while ( q.NextRow() ) {
|
|
23 name = q.GetString(0);
|
1
|
24 addr = q.GetString(1);
|
0
|
25 }
|
|
26 }
|
|
27 stmt.Finalize();
|
|
28 hhsdb.Close();
|
|
29
|
1
|
30 if ( name.IsEmpty() ) {
|
|
31 return wxEmptyString;
|
|
32 }
|
|
33 else {
|
|
34 return name + wxT("_") + addr;
|
|
35 }
|
0
|
36 }
|
1
|
37
|
2
|
38 // 氏名カナで被保険者情報を検索
|
1
|
39 wxArrayString GetHhsInfoByKana( wxString kana, bool fuzzy )
|
0
|
40 {
|
|
41 wxArrayString data;
|
|
42
|
|
43 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("hhs.db");
|
|
44 wxSQLite3Database hhsdb;
|
|
45 hhsdb.Open( gszFile );
|
|
46
|
1
|
47 wxString sql = wxT( "SELECT hhsno, kana, name, birth, addr FROM hhs_master WHERE kana = ? ORDER BY kana, birth;" );
|
|
48 //if ( fuzzy ) ;//*****
|
|
49
|
|
50 wxSQLite3Statement stmt = hhsdb.PrepareStatement( sql );
|
0
|
51 stmt.Bind( 1, kana );
|
|
52 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
53
|
|
54 if ( !q.IsNull(0) ) {
|
|
55 wxString str;
|
|
56 while ( q.NextRow() ) {
|
|
57 str = q.GetString(0);
|
|
58 for ( int i=1; i<5; i++ ) {
|
|
59 str += "_" + q.GetString(i);
|
|
60 }
|
|
61 data.Add( str );
|
|
62 }
|
|
63 }
|
|
64 stmt.Finalize();
|
|
65 hhsdb.Close();
|
|
66
|
|
67 return data;
|
|
68 }
|
|
69
|
2
|
70 //********** CCN-DB **********//
|
|
71 /* 被保険者番号からファイルパスを取得 */
|
0
|
72 wxArrayString GetPathByHhsNo( wxString hhsno )
|
|
73 {
|
2
|
74 wxArrayString path;
|
0
|
75
|
|
76 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("ccn.db");
|
|
77 wxSQLite3Database ccndb;
|
|
78 ccndb.Open( gszFile );
|
|
79
|
2
|
80 wxString sql = wxT( "SELECT path FROM path WHERE hhsno = ? ORDER BY path DESC;" );
|
|
81 wxSQLite3Statement stmt = ccndb.PrepareStatement( sql );
|
0
|
82 stmt.Bind( 1, hhsno );
|
|
83 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
84
|
|
85 if ( !q.IsNull(0) ) {
|
|
86 while ( q.NextRow() ) {
|
2
|
87 path.Add( q.GetString(0) );
|
0
|
88 }
|
|
89 }
|
|
90 stmt.Finalize();
|
|
91 ccndb.Close();
|
|
92
|
2
|
93 return path;
|
0
|
94 }
|
|
95
|
2
|
96 /* 被保険者が審査会にかかったかどうか */
|
|
97 bool IsHhsJudged( wxString hhsno )
|
|
98 {
|
|
99 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("ccn.db");
|
|
100 wxSQLite3Database ccndb;
|
|
101 ccndb.Open( gszFile );
|
|
102
|
|
103 wxString sql = wxT( "SELECT path FROM path WHERE hhsno = ?;" );
|
|
104 wxSQLite3Statement stmt = ccndb.PrepareStatement( sql );
|
|
105 stmt.Bind( 1, hhsno );
|
|
106 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
107
|
|
108 bool ret = true;
|
|
109 if ( q.IsNull(0) ) ret = false;
|
|
110
|
|
111 stmt.Finalize();
|
|
112 ccndb.Close();
|
|
113
|
|
114 return ret;
|
|
115 }
|
|
116
|
|
117 /* 合議体開催日を取得 */
|
0
|
118 wxArrayString GetCcnDate( void )
|
|
119 {
|
|
120 wxArrayString date_cnt;
|
|
121
|
|
122 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("ccn.db");
|
|
123 wxSQLite3Database ccndb;
|
|
124 ccndb.Open( gszFile );
|
|
125
|
2
|
126 wxSQLite3Statement stmt = ccndb.PrepareStatement( "SELECT date, count(*) FROM ccn GROUP BY date ORDER BY date desc" );
|
0
|
127 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
128
|
|
129 wxString str;
|
|
130 if ( !q.IsNull(0) ) {
|
|
131 while ( q.NextRow() ) {
|
|
132 str = q.GetString(0) + "_" + q.GetString(1);
|
|
133 date_cnt.Add( str );
|
|
134 }
|
|
135 }
|
|
136 stmt.Finalize();
|
|
137 ccndb.Close();
|
|
138
|
|
139 return date_cnt;
|
|
140 }
|
|
141
|
2
|
142 /* 日付から審査会を取得 */
|
0
|
143 wxArrayString GetCcnByDate( wxString date )
|
|
144 {
|
2
|
145 wxArrayString data;
|
0
|
146
|
|
147 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("ccn.db");
|
|
148 wxSQLite3Database ccndb;
|
|
149 ccndb.Open( gszFile );
|
|
150
|
2
|
151 wxSQLite3Statement stmt = ccndb.PrepareStatement( "SELECT hhsno, path, date FROM path WHERE date = ? ORDER BY path" );
|
0
|
152 stmt.Bind( 1, date );
|
|
153 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
154
|
|
155 wxString str;
|
|
156 if ( !q.IsNull(0) ) {
|
|
157 while ( q.NextRow() ) {
|
2
|
158 str = q.GetString(0) + "_" + q.GetString(1) + "_" + q.GetString(2);
|
|
159 data.Add( str );
|
0
|
160 }
|
|
161 }
|
|
162 stmt.Finalize();
|
|
163 ccndb.Close();
|
|
164
|
2
|
165 return data;
|
0
|
166 }
|
|
167
|
2
|
168 /* 合議体から被保険者番号を取得 */
|
0
|
169 wxArrayString GetHhsNoByCcn( wxString ccn, wxString date )
|
|
170 {
|
|
171 wxArrayString hhsno;
|
|
172
|
|
173 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("ccn.db");
|
|
174 wxSQLite3Database ccndb;
|
|
175 ccndb.Open( gszFile );
|
|
176
|
2
|
177 wxSQLite3Statement stmt = ccndb.PrepareStatement( "SELECT hhsno FROM ccn WHERE ccn = ? AND date = ? ORDER BY hhsno" );
|
0
|
178 stmt.Bind( 1, ccn );
|
|
179 stmt.Bind( 2, date );
|
|
180 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
181
|
|
182 if ( !q.IsNull(0) ) {
|
|
183 while ( q.NextRow() ) {
|
|
184 hhsno.Add( q.GetString(0) );
|
|
185 }
|
|
186 }
|
|
187 stmt.Finalize();
|
|
188 ccndb.Close();
|
|
189
|
|
190 return hhsno;
|
|
191 }
|
|
192
|
2
|
193 /* インデックスを更新 */
|
|
194 void UpdateIndex( wxString datedir, wxString date )
|
0
|
195 {
|
|
196 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("ccn.db");
|
|
197 wxSQLite3Database ccndb;
|
|
198 ccndb.Open( gszFile );
|
|
199
|
2
|
200 wxSQLite3Statement stmt = ccndb.PrepareStatement( "DELETE FROM path WHERE date = ?;" );
|
|
201 stmt.Bind( 1, date );
|
|
202 stmt.ExecuteQuery();
|
|
203 stmt.Finalize();
|
0
|
204
|
2
|
205 wxString ccndir;
|
|
206 wxDir dated( datedir );
|
|
207 if ( !dated.IsOpened() ) {
|
|
208 return;
|
0
|
209 }
|
|
210
|
2
|
211 wxRegEx reSinsei( wxT("^00000") );
|
|
212 bool cont = dated.GetFirst( &ccndir, wxEmptyString, wxDIR_DIRS );
|
|
213
|
|
214 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), 240, NULL, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
|
|
215 pd.SetSize( wxSize( 320, 140 ) );
|
|
216 int count = 0;
|
|
217
|
|
218 while ( cont ) {
|
|
219
|
|
220 wxDir ccnd( datedir + wxFILE_SEP_PATH + ccndir );
|
|
221 if ( !ccnd.IsOpened() ) return;
|
|
222 wxString hhsdir;
|
|
223 bool c = ccnd.GetFirst( &hhsdir, wxEmptyString, wxDIR_DIRS );
|
|
224
|
|
225 while ( c ) {
|
|
226 if ( ! reSinsei.Matches( hhsdir ) ) {
|
|
227
|
|
228 wxString path = datedir + wxFILE_SEP_PATH + ccndir + wxFILE_SEP_PATH + hhsdir;
|
|
229
|
|
230 stmt = ccndb.PrepareStatement( "INSERT INTO path VALUES( ?, ?, ?, datetime( 'now', 'localtime' ) );" );
|
|
231 stmt.Bind( 1, hhsdir );
|
|
232 stmt.Bind( 2, path );
|
|
233 stmt.Bind( 3, date );
|
|
234 stmt.ExecuteQuery();
|
|
235 stmt.Finalize();
|
|
236 pd.Update( count++, hhsdir + wxT("@") + ccndir + wxT("を処理しました.") );
|
|
237 }
|
|
238 c = ccnd.GetNext( &hhsdir );
|
|
239 }
|
|
240
|
|
241 cont = dated.GetNext( &ccndir );
|
|
242 }
|
0
|
243 ccndb.Close();
|
|
244 }
|
|
245
|
2
|
246 /* DB整合性チェック */
|
|
247 wxArrayString CheckDBs( void )
|
|
248 {
|
|
249 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("ccn.db");
|
|
250 wxSQLite3Database ccndb;
|
|
251 ccndb.Open( gszFile );
|
|
252
|
|
253 wxString sql = wxT("ATTACH 'db/hhs.db' AS hhs");
|
|
254 wxSQLite3Statement stmt = ccndb.PrepareStatement( sql );
|
|
255 wxSQLite3ResultSet q = stmt.ExecuteQuery();
|
|
256
|
|
257 sql = wxT("SELECT hhsno FROM path EXCEPT SELECT hhsno FROM hhs.hhs_master");
|
|
258 stmt = ccndb.PrepareStatement( sql );
|
|
259 q = stmt.ExecuteQuery();
|
|
260
|
|
261 wxArrayString result;
|
|
262 while ( q.NextRow() ) {
|
|
263 result.Add( q.GetString(0) );
|
|
264 }
|
|
265
|
|
266 stmt.Finalize();
|
|
267 ccndb.Close();
|
|
268
|
|
269 return result;
|
|
270 }
|
|
271
|