comparison src/hhsdb.cpp @ 0:c174ac668e9f

First commit ! (ver2.8)
author pyon@macmini
date Tue, 05 Apr 2011 18:44:57 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:c174ac668e9f
1 // Filename : hhsdb.cpp
2 // Last Change: 07-Mar-2011.
3 //
4
5 #include "hhsdb.h"
6 #include "wx/wxsqlite3.h"
7
8 // for all others, include the necessary headers (this file is usually all you
9 // need because it includes almost all "standard" wxWidgets headers)
10 #ifndef WX_PRECOMP
11 #include "wx/utils.h"
12 #include "wx/textfile.h"
13 #include "wx/tokenzr.h"
14 #endif
15
16 // Constructor
17 FrameHhsDB::FrameHhsDB( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
18 : wxFrame( parent, id, title, pos, size, style )
19 {
20 this->SetSizeHints( wxDefaultSize, wxDefaultSize );
21
22 wxBoxSizer* bSizer;
23 bSizer = new wxBoxSizer( wxVERTICAL );
24
25 m_panel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
26
27 wxBoxSizer* bSizerPanel;
28 bSizerPanel = new wxBoxSizer( wxVERTICAL );
29
30 wxString wildcard = wxT("CSV files (*.csv) | *.csv");
31 m_filePicker = new wxFilePickerCtrl( m_panel, ID_CSVPK, wxT("CSVファイルを指定します"), wxT("Select a file"), wildcard, wxDefaultPosition, wxSize( 400,-1 ), wxFLP_DEFAULT_STYLE|wxFLP_FILE_MUST_EXIST|wxFLP_OPEN );
32 bSizerPanel->Add( m_filePicker, 0, wxEXPAND|wxALL, 5 );
33
34 m_grid = new wxGrid( m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 );
35
36 // Grid
37 m_grid->CreateGrid( 200, 6 );
38 m_grid->EnableEditing( true );
39 m_grid->EnableGridLines( true );
40 m_grid->EnableDragGridSize( false );
41 m_grid->SetMargins( 0, 0 );
42
43 // Columns
44 m_grid->EnableDragColMove( false );
45 m_grid->EnableDragColSize( true );
46 m_grid->SetColLabelSize( 30 );
47 m_grid->SetColLabelValue( 0, wxT("被保険者番号") );
48 m_grid->SetColLabelValue( 1, wxT("氏名") );
49 m_grid->SetColLabelValue( 2, wxT("カナ氏名") );
50 m_grid->SetColLabelValue( 3, wxT("住所") );
51 m_grid->SetColLabelValue( 4, wxT("生年月日") );
52 m_grid->SetColLabelValue( 5, wxT("性別") );
53 m_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE );
54
55 // Rows
56 m_grid->EnableDragRowSize( true );
57 m_grid->SetRowLabelSize( 40 );
58 m_grid->SetRowLabelAlignment( wxALIGN_RIGHT, wxALIGN_CENTRE );
59
60 // Label Appearance
61
62 // Cell Defaults
63 m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP );
64 bSizerPanel->Add( m_grid, 1, wxEXPAND|wxALL, 5 );
65
66 wxBoxSizer* bSizerBtns;
67 bSizerBtns = new wxBoxSizer( wxHORIZONTAL );
68
69 m_staticText = new wxStaticText( m_panel, wxID_ANY, wxT("パスワード"), wxDefaultPosition, wxDefaultSize, 0 );
70
71 m_textCtrlPassword = new wxTextCtrl( m_panel, ID_PSWD, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD );
72 m_textCtrlPassword->SetMaxLength( 4 );
73
74 m_btnDBUpdate = new wxButton( m_panel, ID_HHSUP, wxT("DB更新"), wxDefaultPosition, wxDefaultSize, 0 );
75 m_btnDBUpdate->Enable( false );
76
77 m_btnCancel = new wxButton( m_panel, wxID_CANCEL, wxT("キャンセル"), wxDefaultPosition, wxDefaultSize, 0 );
78 m_btnCancel->SetDefault();
79
80 bSizerBtns->Add( 0, 0, 1, wxEXPAND, 5 ); // spacer
81 bSizerBtns->Add( m_staticText, 0, wxALL, 5 );
82 bSizerBtns->Add( m_textCtrlPassword, 0, wxALL, 5 );
83 bSizerBtns->Add( m_btnDBUpdate, 0, wxALL, 5 );
84 bSizerBtns->Add( m_btnCancel, 0, wxALL, 5 );
85
86 bSizerPanel->Add( bSizerBtns, 0, wxALIGN_RIGHT|wxEXPAND, 5 );
87
88 m_panel->SetSizer( bSizerPanel );
89 m_panel->Layout();
90 bSizerPanel->Fit( m_panel );
91
92 bSizer->Add( m_panel, 1, wxEXPAND|wxALL, 0 );
93 this->SetSizer( bSizer );
94 this->Layout();
95 }
96 // Destructor
97 FrameHhsDB::~FrameHhsDB()
98 {
99 }
100
101 // Event Table
102 BEGIN_EVENT_TABLE(FrameHhsDB, wxFrame)
103 EVT_FILEPICKER_CHANGED( ID_CSVPK, FrameHhsDB::ReadCSV )
104 EVT_TEXT( ID_PSWD, FrameHhsDB::CheckPassword )
105 EVT_BUTTON( ID_HHSUP, FrameHhsDB::UpdateHhsDB )
106 EVT_BUTTON( wxID_CANCEL, FrameHhsDB::OnClose )
107 END_EVENT_TABLE()
108
109 // Event Handlers
110 void FrameHhsDB::UpdateHhsDB(wxCommandEvent& WXUNUSED(event))
111 {
112 //this->m_filePicker->
113 wxString gszFile = wxGetCwd() + wxT("/db/hhs.db");
114 wxSQLite3Database hhsdb;
115 hhsdb.Open( gszFile );
116
117 wxSQLite3Statement stmt = hhsdb.PrepareStatement("INSERT INTO hhs_master VALUES ( ?, ?, ?, ?, ?, ? )");
118
119 //stmt.Bind( 1, hhs );
120 //stmt.Bind( 2, hhs );
121 //stmt.Bind( 3, hhs );
122 //stmt.Bind( 4, hhs );
123 //stmt.Bind( 5, hhs );
124 //stmt.Bind( 6, hhs );
125 wxSQLite3ResultSet q = stmt.ExecuteQuery();
126
127 stmt.Finalize();
128 hhsdb.Close();
129 }
130
131 void FrameHhsDB::ReadCSV(wxFileDirPickerEvent& WXUNUSED(event))
132 {
133 wxString filename = m_filePicker->GetPath();
134 wxTextFile file;
135 if ( file.Open(filename) ) {
136 if ( file.GetLineCount() > 200 ) {
137 wxMessageBox(wxT("件数が200件を超えました."));
138 return;
139 }
140 for ( size_t r=0; r<file.GetLineCount(); r++ ) {
141 int c = 0;
142 wxStringTokenizer tkz( file[r], wxT(",") );
143 while ( tkz.HasMoreTokens() ) {
144 wxString token = tkz.GetNextToken();
145 m_grid->SetCellValue( r, c, token );
146 c++;
147 }
148 }
149 }
150 }
151
152 void FrameHhsDB::CheckPassword(wxCommandEvent& WXUNUSED(event))
153 {
154 wxString pw = this->m_textCtrlPassword->GetLineText(0);
155 if ( pw.IsSameAs(wxT("9999")) ) {
156 this->m_btnDBUpdate->Enable( true );
157 }
158 else {
159 this->m_btnDBUpdate->Enable( false );
160 }
161 }
162
163 void FrameHhsDB::OnClose(wxCommandEvent& WXUNUSED(event))
164 {
165 Close(true);
166 }
167