changeset 27:d21de4693652 v2.2dev v2.3

add hhsname
author pyon@macmini
date Sat, 05 Nov 2011 10:13:41 +0900
parents 5a934c8e1b95
children d54f1f1e583d
files image/0000000000.png image/0123456789.png image/logo.png image/notfound.png include/common.h include/marksheet.h include/myframe.h makefile src/myframe.cpp
diffstat 9 files changed, 86 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
Binary file image/0000000000.png has changed
Binary file image/0123456789.png has changed
Binary file image/logo.png has changed
Binary file image/notfound.png has changed
--- a/include/common.h	Thu Nov 03 15:48:26 2011 +0900
+++ b/include/common.h	Sat Nov 05 10:13:41 2011 +0900
@@ -1,5 +1,5 @@
 // Filename   : common.h
-// Last Change: 02-Nov-2011.
+// Last Change: 05-Nov-2011.
 //
 #ifndef __COMMON__
 #define __COMMON__
@@ -51,6 +51,7 @@
     ID_BUTTONMKDIR,
     ID_TEXTCTRLDIST,
     ID_TEXTCTRLGUESS,
+    ID_TEXTCTRLNAME,
     ID_LISTCTRLVIEW,
 
     ID_BUTTONDETECT,
--- a/include/marksheet.h	Thu Nov 03 15:48:26 2011 +0900
+++ b/include/marksheet.h	Sat Nov 05 10:13:41 2011 +0900
@@ -1,9 +1,11 @@
 // Filename   : marksheet.h
-// Last Change: 02-Nov-2011.
+// Last Change: 05-Nov-2011.
 //
 #ifndef __marksheet__
 #define __marksheet__
 
+#include "wx/wxsqlite3.h"
+
 bool IsBlack( int r, int g, int b ) 
 {
     if ( r == 0 && g == 0 && b == 0 ) {
@@ -116,15 +118,38 @@
     return false;
 };
 
+wxString GetHhsName( wxString& hhsno )
+{
+    wxString name;
+
+    wxString gszFile = wxGetCwd() + wxFILE_SEP_PATH + wxT("db") + wxFILE_SEP_PATH + wxT("hhs.db");
+    wxSQLite3Database hhsdb;
+    hhsdb.Open( gszFile );
+
+    wxSQLite3Statement stmt = hhsdb.PrepareStatement("SELECT name FROM hhs_master WHERE hhsno = ?");
+    stmt.Bind( 1, hhsno );
+    wxSQLite3ResultSet q = stmt.ExecuteQuery();
+    if ( !q.IsNull(0) ) {
+        while ( q.NextRow() ) {
+            name = q.GetString(0);
+        }
+    }
+    stmt.Finalize();
+    hhsdb.Close();
+
+    return name;
+};
+
 int IsHhsno( wxString& hhsno, wxString& name )
 {
 	wxRegEx reHhs(wxT("^0[1238][0-9]{8}$"));	// $BHoJ]HV%A%'%C%/(B
 
     if ( reHhs.Matches( hhsno) ) {
-        if ( 0 ) {  // DB$B$K$"$k(B
-            return 2;
+        name = GetHhsName( hhsno );
+        if ( name.IsEmpty() ) {  // DB$B$K$J$$(B
+            return 1;
         }
-        return 1;
+        return 2;
     }
     else {
         return 0;
--- a/include/myframe.h	Thu Nov 03 15:48:26 2011 +0900
+++ b/include/myframe.h	Sat Nov 05 10:13:41 2011 +0900
@@ -1,5 +1,5 @@
 // Filename   : myframe.h
-// Last Change: 03-Nov-2011.
+// Last Change: 05-Nov-2011.
 //
 
 #ifndef __myframe__
@@ -43,6 +43,7 @@
         wxStaticBitmap*   m_bitmapHhsno;
         wxStaticText*     m_staticTextGuess;
         wxTextCtrl*       m_textCtrlGuess;
+        wxTextCtrl*       m_textCtrlName;
 
         wxListCtrl*       m_listCtrlView;
 
--- a/makefile	Thu Nov 03 15:48:26 2011 +0900
+++ b/makefile	Sat Nov 05 10:13:41 2011 +0900
@@ -1,6 +1,6 @@
 #
 # Makefile for wxWidgets Application
-#  Last Change: 02-Nov-2011.
+#  Last Change: 03-Nov-2011.
 #  by Takayuki Mutoh
 #
 
@@ -74,7 +74,8 @@
 
 OBJ = $(OBJDIR)/main.o \
 	  $(OBJDIR)/myframe.o \
-	  $(OBJDIR)/param.o
+	  $(OBJDIR)/param.o	\
+	  $(OBJDIR)/wxsqlite3.o
 ifdef COMSPEC
 OBJMSW = $(OBJ) $(OBJDIR)/sample_rc.o
 endif
@@ -94,7 +95,7 @@
 	$(CXX) $^ -o $@ $(LIBS)
 else
 $(PROGNAME): $(OBJ)
-	$(CXX) $^ -o $@ $(LIBS)
+	$(CXX) $^ -o $@ $(LIBS) -lsqlite3
 endif
 
 
@@ -108,8 +109,8 @@
 $(OBJDIR)/param.o: param.cpp param.h common.h main.h
 	$(CXX) -c $< -o $@ $(CPPFLAGS)
 
-#$(OBJDIR)/wxsqilte3.o: wxsqlite3.cpp
-#	$(CXX) -c $< -o $@ $(CPPFLAGS)
+$(OBJDIR)/wxsqlite3.o: wxsqlite3.cpp
+	$(CXX) -c $< -o $@ $(CPPFLAGS)
 
 testtune: testtune.cpp
 	$(CXX) $< -o $@ $(CPPFLAGS) $(LIBS)
--- a/src/myframe.cpp	Thu Nov 03 15:48:26 2011 +0900
+++ b/src/myframe.cpp	Sat Nov 05 10:13:41 2011 +0900
@@ -1,5 +1,5 @@
 // Filename   : myframe.cpp
-// Last Change: 03-Nov-2011.
+// Last Change: 05-Nov-2011.
 //
 
 #include "main.h"
@@ -8,6 +8,13 @@
 #include "dndfile.h"
 #include "marksheet.h"
 
+#define LOGO_W  288
+#define LOGO_H   86
+#define HHSN_W  288
+#define HHSN_H   49
+#define THUMB_W 160
+#define THUMB_H 226
+
 // resources
 // the application icon (under Windows and OS/2 it is in resources and even
 // though we could still include the XPM here it would be unused)
@@ -106,34 +113,43 @@
 	
 	wxBoxSizer* bSizerManip = new wxBoxSizer( wxHORIZONTAL );
 	
-	wxBoxSizer* bSizerGuess = new wxBoxSizer( wxVERTICAL );
+	wxBoxSizer* bSizerRecog = new wxBoxSizer( wxVERTICAL );
 	
 	m_staticTextName = new wxStaticText( this, wxID_ANY, wxT("氏名"), wxDefaultPosition, wxDefaultSize, 0 );
-	bSizerGuess->Add( m_staticTextName, 0, wxTOP|wxLEFT, 5 );
+	bSizerRecog->Add( m_staticTextName, 0, wxTOP|wxLEFT, 5 );
     wxString logo = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("logo.png");
     wxBitmap bmp = wxBitmap( logo, wxBITMAP_TYPE_PNG );
 	m_bitmapName = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize(320,95), 0 );
-	bSizerGuess->Add( m_bitmapName, 0, wxALL, 5 );
+	bSizerRecog->Add( m_bitmapName, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
 	
 	m_staticTextHhsno = new wxStaticText( this, wxID_ANY, wxT("被保険者番号"), wxDefaultPosition, wxDefaultSize, 0 );
-	bSizerGuess->Add( m_staticTextHhsno, 0, wxTOP|wxLEFT, 5 );
+	bSizerRecog->Add( m_staticTextHhsno, 0, wxTOP|wxLEFT, 5 );
     logo = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("0123456789.png");
     bmp.LoadFile( logo, wxBITMAP_TYPE_PNG );
 	m_bitmapHhsno = new wxStaticBitmap( this, wxID_ANY, bmp, wxDefaultPosition, wxSize(320,54), 0 );
-	bSizerGuess->Add( m_bitmapHhsno, 0, wxALL, 5 );
+	bSizerRecog->Add( m_bitmapHhsno, 0, wxTOP|wxBOTTOM|wxLEFT, 5 );
 	
 	m_staticTextGuess = new wxStaticText( this, wxID_ANY, wxT("推定値"), wxDefaultPosition, wxDefaultSize, 0 );
-	bSizerGuess->Add( m_staticTextGuess, 0, wxTOP|wxLEFT, 5 );
+	bSizerRecog->Add( m_staticTextGuess, 0, wxTOP|wxLEFT, 5 );
+
+	wxBoxSizer* bSizerGuess = new wxBoxSizer( wxHORIZONTAL );
+
 	m_textCtrlGuess = new wxTextCtrl( this, ID_TEXTCTRLGUESS, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
 	m_textCtrlGuess->SetMaxLength( 10 ); 
 	bSizerGuess->Add( m_textCtrlGuess, 0, wxALL, 5 );
+
+	m_textCtrlName = new wxTextCtrl( this, ID_TEXTCTRLNAME, wxEmptyString, wxDefaultPosition, wxSize(140,-1), 0 );
+    m_textCtrlName->SetBackgroundColour(wxT("LIGHT GREY"));
+	bSizerGuess->Add( m_textCtrlName, 0, wxALL, 5 );
 	
-	bSizerManip->Add( bSizerGuess, 0, wxEXPAND, 5 );
+	bSizerRecog->Add( bSizerGuess, 0, wxEXPAND, 5 );
+
+	bSizerManip->Add( bSizerRecog, 0, wxEXPAND|wxLEFT, 5 );
 	
 	m_listCtrlView = new wxListCtrl( this, ID_LISTCTRLVIEW, wxDefaultPosition, wxDefaultSize, wxLC_ICON );
     m_listCtrlView->SetBackgroundColour(wxT("LIGHT GREY"));
-	bSizerManip->Add( m_listCtrlView, 1, wxALL|wxEXPAND, 5 );
-    m_imageList = new wxImageList( 160, 226 );
+	bSizerManip->Add( m_listCtrlView, 1, wxTOP|wxRIGHT|wxBOTTOM|wxEXPAND, 5 );
+    m_imageList = new wxImageList( THUMB_W, THUMB_H );
     m_listCtrlView->AssignImageList( m_imageList, wxIMAGE_LIST_NORMAL );
     //m_listCtrlView->SetDropTarget( new DnDFile(m_dirPickerWork) );
     this->SetDropTarget( new DnDFile(m_dirPickerWork) );
@@ -155,17 +171,20 @@
 
 	bSizerButton->Add( gSizer, 0, wxALL, 5 );
 
-	m_listCtrlHhsDir = new wxListCtrl( this, ID_LISTCTRLDIR, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL );
+	m_listCtrlHhsDir = new wxListCtrl( this, ID_LISTCTRLDIR, wxDefaultPosition, wxSize(280,-1), wxLC_REPORT|wxLC_SINGLE_SEL );
     wxListItem itemCol;
     itemCol.SetText( wxT("通番") );
     m_listCtrlHhsDir->InsertColumn( 0, itemCol );
-    m_listCtrlHhsDir->SetColumnWidth( 0, 50 );
+    m_listCtrlHhsDir->SetColumnWidth( 0, 40 );
     itemCol.SetText( wxT("被保険者番号") );
     m_listCtrlHhsDir->InsertColumn( 1, itemCol );
-    m_listCtrlHhsDir->SetColumnWidth( 1, 100 );
-    itemCol.SetText( wxT("ファイル数") );
+    m_listCtrlHhsDir->SetColumnWidth( 1, 90 );
+    itemCol.SetText( wxT("枚数") );
     m_listCtrlHhsDir->InsertColumn( 2, itemCol );
-    m_listCtrlHhsDir->SetColumnWidth( 2, 60 );
+    m_listCtrlHhsDir->SetColumnWidth( 2, 40 );
+    itemCol.SetText( wxT("氏名") );
+    m_listCtrlHhsDir->InsertColumn( 3, itemCol );
+    m_listCtrlHhsDir->SetColumnWidth( 3, 90 );
 
 	bSizerButton->Add( m_listCtrlHhsDir, 1, wxEXPAND|wxALL, 5 );
 	
@@ -379,14 +398,16 @@
         if ( i == 0 ) { // 1枚目はマークシートのはず
             wxImage marksheet( ci->fullpath, wxBITMAP_TYPE_JPEG );
 
+            // 氏名画像を表示
             wxImage name_image;
             name_image  = marksheet.GetSubImage( wxRect( wxPoint(300,550), wxSize(640,190) ) );
-            wxBitmap name_bmp  = ( name_image.Scale( 320, 95, wxIMAGE_QUALITY_HIGH ) );
+            wxBitmap name_bmp  = ( name_image.Scale( LOGO_W, LOGO_H, wxIMAGE_QUALITY_HIGH ) );
             m_bitmapName->SetBitmap( name_bmp );
 
+            // 被保険者番号画像を表示
             wxImage hhsno_image;
             hhsno_image = marksheet.GetSubImage( wxRect( wxPoint(1800,210), wxSize(594,100) ) );
-            wxBitmap hhsno_bmp = ( hhsno_image.Scale( 320, 54, wxIMAGE_QUALITY_HIGH ) );
+            wxBitmap hhsno_bmp = ( hhsno_image.Scale( HHSN_W, HHSN_H, wxIMAGE_QUALITY_HIGH ) );
             m_bitmapHhsno->SetBitmap( hhsno_bmp );
 
             wxString hhsno = GuessHhs( ci->fullpath );
@@ -394,7 +415,9 @@
             wxString name;
             int judge = IsHhsno( hhsno, name );
 	        if (      judge == 0 )  m_textCtrlGuess->SetBackgroundColour(*wxRED);       // not hhsno-style
-            //else if ( judge == 1 )  m_textCtrlGuess->SetBackgroundColour(wxT("YELLOW"));    // not in DB
+            else if ( judge == 1 )  m_textCtrlGuess->SetBackgroundColour(wxT("YELLOW"));    // not in DB
+            m_textCtrlName->SetValue( name );
+
             SetStatusText( wxString::Format(wxT("1st image : z = %f, l = %d"),ci->z,ci->l), 1 );
             m_listCtrlView->SetItemState( i, wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED );
         }
@@ -512,10 +535,10 @@
         //float z; long l; bool m = IsMarksheet( fullpath, &z, &l );
         float z; long l; bool m = IsMarksheet( fullpath, &z, &l, zmin, zmax, lmin, lmax );
         wxImage image( fullpath, wxBITMAP_TYPE_JPEG );
-        wxImage thumbnail = image.Scale( 160, 226, wxIMAGE_QUALITY_HIGH );
+        wxImage thumbnail = image.Scale( THUMB_W, THUMB_H, wxIMAGE_QUALITY_HIGH );
         wxBitmap bmp( thumbnail );
         unsigned char *data = thumbnail.GetData();
-        for ( int y=0; y<226; y++ ) for ( int x=0; x<160; x++ ) data[(y*160+x)*3+2] = 255;  // 文字色:黒(0,0,0)->青(0,0.255)
+        for ( int y=0; y<THUMB_H; y++ ) for ( int x=0; x<THUMB_W; x++ ) data[(y*THUMB_W+x)*3+2] = 255;  // 文字色:黒(0,0,0)->青(0,0.255)
         wxBitmap bmp_mask( thumbnail );
 
         ci->filename     = file;
@@ -580,14 +603,16 @@
     hhsdir.Append( m_textCtrlDist->GetValue() );
     hhsdir.Append( wxFILE_SEP_PATH );
 
-    wxListItem item = event.GetItem();
+    int i = event.GetIndex();
+    wxListItem item;
+    item.SetId(i);
+
     item.SetColumn(1);
     item.SetMask(wxLIST_MASK_TEXT);
     m_listCtrlHhsDir->GetItem( item );
     hhsdir.Append( item.GetText() );
     wxString execmd = wxT("explorer ") + hhsdir;
     wxExecute( execmd );
-    //wxMessageBox(hhsdir);
 }
 
 // 以下,定型もの