Mercurial > mercurial > hgweb_searcher2.cgi
view src/hhsdb.cpp @ 23:a10c2fe880f8
fix sizers.
author | pyon@macmini |
---|---|
date | Wed, 27 Jul 2011 21:27:56 +0900 |
parents | c174ac668e9f |
children |
line wrap: on
line source
// Filename : hhsdb.cpp // Last Change: 07-Mar-2011. // #include "hhsdb.h" #include "wx/wxsqlite3.h" // for all others, include the necessary headers (this file is usually all you // need because it includes almost all "standard" wxWidgets headers) #ifndef WX_PRECOMP #include "wx/utils.h" #include "wx/textfile.h" #include "wx/tokenzr.h" #endif // Constructor FrameHhsDB::FrameHhsDB( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) : wxFrame( parent, id, title, pos, size, style ) { this->SetSizeHints( wxDefaultSize, wxDefaultSize ); wxBoxSizer* bSizer; bSizer = new wxBoxSizer( wxVERTICAL ); m_panel = new wxPanel( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL ); wxBoxSizer* bSizerPanel; bSizerPanel = new wxBoxSizer( wxVERTICAL ); wxString wildcard = wxT("CSV files (*.csv) | *.csv"); 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 ); bSizerPanel->Add( m_filePicker, 0, wxEXPAND|wxALL, 5 ); m_grid = new wxGrid( m_panel, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 ); // Grid m_grid->CreateGrid( 200, 6 ); m_grid->EnableEditing( true ); m_grid->EnableGridLines( true ); m_grid->EnableDragGridSize( false ); m_grid->SetMargins( 0, 0 ); // Columns m_grid->EnableDragColMove( false ); m_grid->EnableDragColSize( true ); m_grid->SetColLabelSize( 30 ); m_grid->SetColLabelValue( 0, wxT("被保険者番号") ); m_grid->SetColLabelValue( 1, wxT("氏名") ); m_grid->SetColLabelValue( 2, wxT("カナ氏名") ); m_grid->SetColLabelValue( 3, wxT("住所") ); m_grid->SetColLabelValue( 4, wxT("生年月日") ); m_grid->SetColLabelValue( 5, wxT("性別") ); m_grid->SetColLabelAlignment( wxALIGN_CENTRE, wxALIGN_CENTRE ); // Rows m_grid->EnableDragRowSize( true ); m_grid->SetRowLabelSize( 40 ); m_grid->SetRowLabelAlignment( wxALIGN_RIGHT, wxALIGN_CENTRE ); // Label Appearance // Cell Defaults m_grid->SetDefaultCellAlignment( wxALIGN_LEFT, wxALIGN_TOP ); bSizerPanel->Add( m_grid, 1, wxEXPAND|wxALL, 5 ); wxBoxSizer* bSizerBtns; bSizerBtns = new wxBoxSizer( wxHORIZONTAL ); m_staticText = new wxStaticText( m_panel, wxID_ANY, wxT("パスワード"), wxDefaultPosition, wxDefaultSize, 0 ); m_textCtrlPassword = new wxTextCtrl( m_panel, ID_PSWD, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PASSWORD ); m_textCtrlPassword->SetMaxLength( 4 ); m_btnDBUpdate = new wxButton( m_panel, ID_HHSUP, wxT("DB更新"), wxDefaultPosition, wxDefaultSize, 0 ); m_btnDBUpdate->Enable( false ); m_btnCancel = new wxButton( m_panel, wxID_CANCEL, wxT("キャンセル"), wxDefaultPosition, wxDefaultSize, 0 ); m_btnCancel->SetDefault(); bSizerBtns->Add( 0, 0, 1, wxEXPAND, 5 ); // spacer bSizerBtns->Add( m_staticText, 0, wxALL, 5 ); bSizerBtns->Add( m_textCtrlPassword, 0, wxALL, 5 ); bSizerBtns->Add( m_btnDBUpdate, 0, wxALL, 5 ); bSizerBtns->Add( m_btnCancel, 0, wxALL, 5 ); bSizerPanel->Add( bSizerBtns, 0, wxALIGN_RIGHT|wxEXPAND, 5 ); m_panel->SetSizer( bSizerPanel ); m_panel->Layout(); bSizerPanel->Fit( m_panel ); bSizer->Add( m_panel, 1, wxEXPAND|wxALL, 0 ); this->SetSizer( bSizer ); this->Layout(); } // Destructor FrameHhsDB::~FrameHhsDB() { } // Event Table BEGIN_EVENT_TABLE(FrameHhsDB, wxFrame) EVT_FILEPICKER_CHANGED( ID_CSVPK, FrameHhsDB::ReadCSV ) EVT_TEXT( ID_PSWD, FrameHhsDB::CheckPassword ) EVT_BUTTON( ID_HHSUP, FrameHhsDB::UpdateHhsDB ) EVT_BUTTON( wxID_CANCEL, FrameHhsDB::OnClose ) END_EVENT_TABLE() // Event Handlers void FrameHhsDB::UpdateHhsDB(wxCommandEvent& WXUNUSED(event)) { //this->m_filePicker-> wxString gszFile = wxGetCwd() + wxT("/db/hhs.db"); wxSQLite3Database hhsdb; hhsdb.Open( gszFile ); wxSQLite3Statement stmt = hhsdb.PrepareStatement("INSERT INTO hhs_master VALUES ( ?, ?, ?, ?, ?, ? )"); //stmt.Bind( 1, hhs ); //stmt.Bind( 2, hhs ); //stmt.Bind( 3, hhs ); //stmt.Bind( 4, hhs ); //stmt.Bind( 5, hhs ); //stmt.Bind( 6, hhs ); wxSQLite3ResultSet q = stmt.ExecuteQuery(); stmt.Finalize(); hhsdb.Close(); } void FrameHhsDB::ReadCSV(wxFileDirPickerEvent& WXUNUSED(event)) { wxString filename = m_filePicker->GetPath(); wxTextFile file; if ( file.Open(filename) ) { if ( file.GetLineCount() > 200 ) { wxMessageBox(wxT("件数が200件を超えました.")); return; } for ( size_t r=0; r<file.GetLineCount(); r++ ) { int c = 0; wxStringTokenizer tkz( file[r], wxT(",") ); while ( tkz.HasMoreTokens() ) { wxString token = tkz.GetNextToken(); m_grid->SetCellValue( r, c, token ); c++; } } } } void FrameHhsDB::CheckPassword(wxCommandEvent& WXUNUSED(event)) { wxString pw = this->m_textCtrlPassword->GetLineText(0); if ( pw.IsSameAs(wxT("9999")) ) { this->m_btnDBUpdate->Enable( true ); } else { this->m_btnDBUpdate->Enable( false ); } } void FrameHhsDB::OnClose(wxCommandEvent& WXUNUSED(event)) { Close(true); }