comparison src/db.cpp @ 13:bbd65edf71d4

Implement Hhs DB update dialog.
author pyon@macmini
date Sat, 24 May 2014 10:25:13 +0900
parents dfcf8c973219
children a2ad87cad48b
comparison
equal deleted inserted replaced
12:52958cd4a073 13:bbd65edf71d4
1 // Filename : db.cpp 1 // Filename : db.cpp
2 // Last Change: 02-May-2014. 2 // Last Change: 23-May-2014.
3 // 3 //
4 4
5 #include <wx/tokenzr.h>
5 #include "db.h" 6 #include "db.h"
6 #include "wx/wxsqlite3.h" 7 #include "wx/wxsqlite3.h"
7 8
8 //********** HHS-DB **********// 9 //********** HHS-DB **********//
10 /* 被保険者台帳を更新 */
11 void UpdateHhs( wxArrayString info )
12 {
13 long n = info.GetCount();
14
15 wxProgressDialog pd( wxT("進行状況"), wxT("処理開始..."), n, NULL, wxPD_APP_MODAL|wxPD_REMAINING_TIME|wxPD_AUTO_HIDE );
16 pd.SetSize( wxSize( 320, 140 ) );
17
18 wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("hhs.db");
19 wxRemoveFile( gszFile );
20
21 wxSQLite3Database hhsdb;
22 hhsdb.Open( gszFile );
23 hhsdb.Begin();
24
25 wxString sql = wxT( "PRAGMA foregin_keys=OFF" );
26 wxSQLite3Statement stmt = hhsdb.PrepareStatement( sql );
27 wxSQLite3ResultSet q = stmt.ExecuteQuery();
28
29 sql = wxT( "CREATE TABLE 'hhs_master' ( hhsno text PRIMARY KEY, birth text, name text, kana text, addr text, sex text )" );
30 stmt = hhsdb.PrepareStatement( sql );
31 q = stmt.ExecuteQuery();
32
33 wxString hhsno, birth, name, kana, addr, sex;
34 for ( long i = 0; i < n; i++ ) {
35
36 info[i].Replace( wxT("\""), wxEmptyString, true );
37
38 wxStringTokenizer token( info[i], wxT(",") );
39 hhsno = token.GetNextToken();
40 birth = token.GetNextToken();
41 name = token.GetNextToken();
42 kana = token.GetNextToken();
43 addr = token.GetNextToken();
44 sex = token.GetNextToken();
45
46 stmt = hhsdb.PrepareStatement( "INSERT INTO hhs_master VALUES( ?, ?, ?, ?, ?, ? );" );
47 stmt.Bind( 1, hhsno );
48 stmt.Bind( 2, birth );
49 stmt.Bind( 3, name );
50 stmt.Bind( 4, kana );
51 stmt.Bind( 5, addr );
52 stmt.Bind( 6, sex );
53 stmt.ExecuteQuery();
54 stmt.Finalize();
55
56 if ( i % 1000 == 0 ) {
57 pd.Update( i, wxString::Format( wxT("%d / %d done."), i, n ) );
58 }
59 }
60
61 hhsdb.Commit();
62 hhsdb.Close();
63 }
64
9 /* 被保番で被保険者情報を取得 */ 65 /* 被保番で被保険者情報を取得 */
10 wxString GetHhsInfoByHhsNo( wxString hhsno ) 66 wxString GetHhsInfoByHhsNo( wxString hhsno )
11 { 67 {
12 wxString name, addr; 68 wxString name, addr;
13 69