view src/myframe.cpp @ 6:76db82822e73

Implement kana fuzzy search. Implement batch print log.
author pyon@macmini
date Wed, 18 Sep 2013 18:20:40 +0900
parents bc2e2b304095
children 7ac7d28699af
line wrap: on
line source

// Filename   : myframe.cpp
// Last Change: 13-Sep-2013.
//
#include "main.h"
#include "db.h"
#include "about.h"
#include "kana.h"
#include "hist.h"
#include "index.h"
#include "param.h"
#include "marksheet.h"
#include "myframe.h"
#include "bprint.h"

///////////////////////////////////////////////////////////////
// カスタム検索ボックス
MySearchBox::MySearchBox( wxWindow* parent, wxWindowID id, const wxString& value, const wxPoint& pos, const wxSize& size, long style )
    : wxSearchCtrl( parent, id, value, pos, size, style )
{
}
 
MySearchBox::~MySearchBox()
{
}

// Event Table
BEGIN_EVENT_TABLE( MySearchBox, wxSearchCtrl )
    EVT_CHAR( MySearchBox::OnKey )
END_EVENT_TABLE()

// Event Handlers & Functions
void MySearchBox::OnKey( wxKeyEvent& event )
{
    wxString s = GetValue();
    // statustext( s.Len() );

    if ( event.GetKeyCode() == 45 ) {   // テンキーの '-' キーで1文字削除
        wxString t = GetStringSelection();
        if ( t.IsEmpty() ) {
            long p = GetInsertionPoint();
            if ( p > 0 ) Remove( p - 1, p );
        }
        else {
            Cut();
        }
        return;
    }

    if ( event.GetKeyCode() == WXK_ESCAPE ) {    // clear by ESC
        this->Clear();
        return;
    }

    event.Skip();
}


///////////////////////////////////////////////////////////////
// メインフレーム
#define WINL_W 480
#define LOGO_W 200
#define LOGO_H  92

// resources
#if !defined(__WXMSW__) && !defined(__WXPM__)
    #include "sample.xpm"
#endif

MyFrame::MyFrame( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style )
    : wxFrame( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxSize( WINL_W, 500 ), wxDefaultSize );
	this->SetMinSize( wxSize( WINL_W, 500 ) );
	this->SetBackgroundColour( wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER ) );
    //this->SetBackgroundColour( wxColour(wxT("WHEAT")) );
	
    // set the frame icon
    SetIcon(wxICON(sample));
	
    // メニューバー Menu
	m_menubar = new wxMenuBar( 0 );
	m_menuFile = new wxMenu();

	wxMenuItem* m_menuItemBPrintMode = new wxMenuItem( m_menuFile, ID_MNBPNT, wxString( wxT("バッチ印刷モード\tF12") ) , wxT("Batch Print Mode"), wxITEM_NORMAL );
	m_menuFile->Append( m_menuItemBPrintMode );

	wxMenuItem* m_menuItemIndex = new wxMenuItem( m_menuFile, ID_MNINDEX, wxString( wxT("インデックス\tF11") ) , wxT("Update index"), wxITEM_NORMAL );
	m_menuFile->Append( m_menuItemIndex );

    m_menuFile->AppendSeparator(); // ----

	wxMenuItem* m_menuItemViewStyle = new wxMenuItem( m_menuFile, ID_MNVIEW, wxString( wxT("ビュースタイル\tF10") ) , wxT("Toggle ViewStyle"), wxITEM_CHECK );
	m_menuFile->Append( m_menuItemViewStyle );

    m_menuFile->AppendSeparator(); // ----

	wxMenuItem* m_menuItemBkup = new wxMenuItem( m_menuFile, ID_MNDBBKUP, wxString( wxT("DBバックアップ(&B)") ) , wxT("Backup databases"), wxITEM_NORMAL );
	m_menuFile->Append( m_menuItemBkup );

    // params
	m_menuParam = new wxMenu();
	wxMenuItem* m_menuItemMask = new wxMenuItem( m_menuParam, ID_MNMASKPARAM, wxString( wxT("マスク(&M)") ) , wxT("Setup mask parameters"), wxITEM_NORMAL );
	m_menuParam->Append( m_menuItemMask );

	wxMenuItem* m_menuItemMark = new wxMenuItem( m_menuParam, ID_MNMARKPARAM, wxString( wxT("マークシート(&S)") ) , wxT("Setup marksheet parameters"), wxITEM_NORMAL );
	m_menuParam->Append( m_menuItemMark );

	m_menuFile->Append( -1, wxT("パラメータ(&P)"), m_menuParam );

    //
	wxMenuItem* m_menuItemAppDir = new wxMenuItem( m_menuFile, ID_MNAPPDIR, wxString( wxT("アプリケーションフォルダを開く(&O)") ) , wxT("Open application directory"), wxITEM_NORMAL );
	m_menuFile->Append( m_menuItemAppDir );
	
    m_menuFile->AppendSeparator(); // ----
	
	wxMenuItem* m_menuItemAbout = new wxMenuItem( m_menuFile, ID_MNABOUT, wxString( wxT("&About...\tF1") ) , wxT("Show about dialog"), wxITEM_NORMAL );
	m_menuFile->Append( m_menuItemAbout );
	
	m_menubar->Append( m_menuFile, wxT("ファイル(&F)") ); 
	
	this->SetMenuBar( m_menubar );
	
    //
	wxBoxSizer* bSizerTop = new wxBoxSizer( wxVERTICAL );
	
	m_splitter = new wxSplitterWindow( this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_3D );
	wxBoxSizer* bSizerMain = new wxBoxSizer( wxVERTICAL );
	
    // left-pane
	m_panelMain = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	
    wxString logo = wxGetCwd() + wxFILE_SEP_PATH + wxT("image") + wxFILE_SEP_PATH + wxT("logo.png");
    wxBitmap bmp = wxBitmap( logo, wxBITMAP_TYPE_PNG );
	m_bitmap = new wxStaticBitmap( m_panelMain, wxID_ANY, bmp, wxDefaultPosition, wxSize( LOGO_W, LOGO_H ), 0 );
	bSizerMain->Add( m_bitmap, 0, wxALL, 5 );
	
	m_textCtrlName = new wxTextCtrl( m_panelMain, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 200, -1 ), 0 );
	bSizerMain->Add( m_textCtrlName, 0, wxALL, 5 );
	
	m_textCtrlAddr = new wxTextCtrl( m_panelMain, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( 380, -1 ), 0 );
	bSizerMain->Add( m_textCtrlAddr, 0, wxALL, 5 );
	
	m_listCtrl = new wxListCtrl( m_panelMain, ID_LIST, wxDefaultPosition, wxDefaultSize, wxLC_REPORT );
    wxListItem itemCol;
    itemCol.SetText( wxT("通番") );
    m_listCtrl->InsertColumn( 0, itemCol );
    m_listCtrl->SetColumnWidth( 0, 50 );
    itemCol.SetText( wxT("年月日") );
    m_listCtrl->InsertColumn( 1, itemCol );
    m_listCtrl->SetColumnWidth( 1, 80 );
    itemCol.SetText( wxT("場所") );
    m_listCtrl->InsertColumn( 2, itemCol );
    m_listCtrl->SetColumnWidth( 2, 300 );
	bSizerMain->Add( m_listCtrl, 1, wxALL|wxEXPAND, 5 );
	
	wxBoxSizer* bSizerCmd = new wxBoxSizer( wxHORIZONTAL );
	
	m_staticText = new wxStaticText( m_panelMain, wxID_ANY, wxT("コマンド?"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerCmd->Add( m_staticText, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );
	
	m_searchBox = new MySearchBox( m_panelMain, ID_SEARCH, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER );
	#ifndef __WXMAC__
	m_searchBox->ShowSearchButton( true );
	#endif
	m_searchBox->ShowCancelButton( false );
    m_searchBox->SetFocus();
	bSizerCmd->Add( m_searchBox, 1, wxALL|wxEXPAND|wxALIGN_CENTER_VERTICAL, 5 );
	
	m_buttonKana = new wxButton( m_panelMain, ID_KANA, wxT("カナ検索"), wxDefaultPosition, wxSize( 65, -1 ), 0 );
	bSizerCmd->Add( m_buttonKana, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 20 );
	
	m_buttonHist = new wxButton( m_panelMain, ID_HIST, wxT("検索履歴"), wxDefaultPosition, wxSize( 65, -1 ), 0 );
	bSizerCmd->Add( m_buttonHist, 0, wxALL, 5 );
	
	bSizerMain->Add( bSizerCmd, 0, wxEXPAND, 5 );
	
	m_panelMain->SetSizer( bSizerMain );
	m_panelMain->Layout();
	bSizerMain->Fit( m_panelMain );

    // right-pane
	m_panelView = new wxPanel( m_splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL );
	wxBoxSizer* bSizerView = new wxBoxSizer( wxHORIZONTAL );

	m_bitmapView = new wxStaticBitmap( m_panelView, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
	bSizerView->Add( m_bitmapView, 1, wxALL|wxEXPAND, 5 );
	
	m_listCtrlThumb = new wxListCtrl( m_panelView, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_ICON );
	bSizerView->Add( m_listCtrlThumb, 0, wxALL|wxEXPAND, 5 );
	
	m_panelView->SetSizer( bSizerView );
	m_panelView->Layout();
	bSizerView->Fit( m_panelView );

    m_panelView->Show( false );
    //
    m_splitter->Initialize( m_panelMain );
	bSizerTop->Add( m_splitter, 1, wxEXPAND, 5 );
	
	this->SetSizer( bSizerTop );
	this->Layout();

    // ステータスバー Statusbar
	m_statusBar = new  wxStatusBar( this, wxID_ANY, wxST_SIZEGRIP );
    int widths[] = { 200, -1, 10, 90 };
    m_statusBar->SetFieldsCount( 4, widths );
    this->SetStatusBar( m_statusBar );
    SetStatusText( wxT("被保番を入力してスタート!") );
	
	this->Centre( wxBOTH );
    LoadParam();
}

MyFrame::~MyFrame()
{
}

// Event Table
BEGIN_EVENT_TABLE( MyFrame, wxFrame )
    EVT_MENU( ID_MNABOUT, MyFrame::OnAbout )
    EVT_MENU( wxID_EXIT, MyFrame::OnQuit )
    EVT_MENU( ID_MNBPNT, MyFrame::OnBPrintMode )
    EVT_MENU( ID_MNVIEW, MyFrame::OnViewStyle )
    EVT_MENU( ID_MNINDEX, MyFrame::OnIndex )
    EVT_MENU( ID_MNDBBKUP, MyFrame::OnDBBackup )
    EVT_MENU( ID_MNMASKPARAM, MyFrame::OnMaskParam )
    EVT_MENU( ID_MNMARKPARAM, MyFrame::OnMarkParam )
    EVT_MENU( ID_MNAPPDIR, MyFrame::OnOpenAppDir )
    EVT_LIST_ITEM_ACTIVATED( ID_LIST, MyFrame::OnSelectHhsDir )
    EVT_BUTTON( ID_KANA, MyFrame::OnKana )
    EVT_BUTTON( ID_HIST, MyFrame::OnHistory )
    EVT_SIZE( MyFrame::OnWinSize )
    EVT_MOVE( MyFrame::OnWinMove )
    EVT_CLOSE( MyFrame::SaveConfig )
    EVT_TEXT_ENTER( ID_SEARCH, MyFrame::OnCommand )
END_EVENT_TABLE()

// Event Handlers & Functions
/* エンターキーフック */
void MyFrame::OnCommand( wxCommandEvent& event )
{
    wxString s = m_searchBox->GetValue();

    if ( s.IsSameAs( wxT("99") ) ) {
        Close();
        return;
    }

    if ( s.IsSameAs( wxT("+") ) ) {
        PrintImages( m_hhsno );
        return;
    }

    wxRegEx reHhs( wxT("^0[1238][0-9]{8}$") );
    if ( reHhs.Matches( s ) ) {
        m_hhsno = s;
        UpdateList( m_hhsno );
        return;
    }

    wxRegEx reNo( wxT("^[0-9]{1,2}$") );
    if ( reNo.Matches( s ) ) {
        long n;
        s.ToLong( &n, 10 );
        n--;
        OpenHhsDir( (int)n );
        return;
    }

    SetStatusMessage( wxT("不適切な入力です."), 0 );
    return;

    event.Skip();
}
/* パラメータを設定ファイルから読み込む */
void MyFrame::LoadParam( void )
{
    conf_file = wxGetCwd() + wxFILE_SEP_PATH + wxT("app.conf");
    config = new wxFileConfig( wxT("MyApp"), wxT("T.Mutoh"), conf_file, wxEmptyString, wxCONFIG_USE_LOCAL_FILE );

    int x, y, w, h;

    config->SetPath( wxT("/Mask") );

    config->Read( wxT("x1"), &x );
    config->Read( wxT("y1"), &y );
    config->Read( wxT("w1"), &w );
    config->Read( wxT("h1"), &h );
    m_mask1.SetPosition( wxPoint( x, y ) );
    m_mask1.SetSize( wxSize( w, h ) );

    config->Read( wxT("x2"), &x );
    config->Read( wxT("y2"), &y );
    config->Read( wxT("w2"), &w );
    config->Read( wxT("h2"), &h );
    m_mask2.SetPosition( wxPoint( x, y ) );
    m_mask2.SetSize( wxSize( w, h ) );

    config->Read( wxT("x3"), &x );
    config->Read( wxT("y3"), &y );
    config->Read( wxT("w3"), &w );
    config->Read( wxT("h3"), &h );
    m_mask3.SetPosition( wxPoint( x, y ) );
    m_mask3.SetSize( wxSize( w, h ) );

    config->Read( wxT("x1o"), &x );
    config->Read( wxT("y1o"), &y );
    config->Read( wxT("w1o"), &w );
    config->Read( wxT("h1o"), &h );
    m_mask1old.SetPosition( wxPoint( x, y ) );
    m_mask1old.SetSize( wxSize( w, h ) );

    config->Read( wxT("x2o"), &x );
    config->Read( wxT("y2o"), &y );
    config->Read( wxT("w2o"), &w );
    config->Read( wxT("h2o"), &h );
    m_mask2old.SetPosition( wxPoint( x, y ) );
    m_mask2old.SetSize( wxSize( w, h ) );

    config->Read( wxT("x3o"), &x );
    config->Read( wxT("y3o"), &y );
    config->Read( wxT("w3o"), &w );
    config->Read( wxT("h3o"), &h );
    m_mask3old.SetPosition( wxPoint( x, y ) );
    m_mask3old.SetSize( wxSize( w, h ) );

    //
    config->SetPath( wxT("/Marksheet") );

    config->Read( wxT("lmin"), &lmin );
    config->Read( wxT("lmax"), &lmax );
    config->Read( wxT("zmin"), &zmin );
    config->Read( wxT("zmax"), &zmax );
}
/* 印刷 */
void MyFrame::PrintImages( wxString hhsno )
{
    // 印刷用の html を作成
    wxArrayString path = GetPathByHhsNo( hhsno );
    if ( path.IsEmpty() ) return;

    wxDir dir( path[0] );
    if ( !dir.IsOpened() ) return;

    wxString html;
    html = html + wxT("<html><body>\n");

    wxString file;
    bool cout = dir.GetFirst( &file, wxT("*.jpg"), wxDIR_FILES );
    bool notyet_mask = true;
    int n = 0;
    wxString tmpdir = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH;
    while ( cout ) {
        file = path[0] + wxFILE_SEP_PATH + file;
        file.Replace( wxFILE_SEP_PATH, wxT("/") );
        wxString tmpjpg = wxString::Format( wxT("%stmp%d.jpg"), tmpdir, n );

        if ( notyet_mask && IsMarksheet( file, zmin, zmax, lmin, lmax ) ) {  // マークシート表面をマスクする
            wxImage img_org( file, wxBITMAP_TYPE_JPEG );
            int ver = GetMarksheetVersion( file );
            if ( ver == 2 ) {
                img_org.SetRGB( m_mask1, 255, 255, 255 );   // cm name
                img_org.SetRGB( m_mask2, 255, 255, 255 );   // cm no.
                img_org.SetRGB( m_mask3, 255, 255, 255 );   // barcode
            }
            else {  // 古いマークシート ver == 1
                img_org.SetRGB( m_mask1old, 255, 255, 255 );   // cm name
                img_org.SetRGB( m_mask2old, 255, 255, 255 );   // cm no.
                img_org.SetRGB( m_mask3old, 255, 255, 255 );   // barcode
            }
            img_org.SaveFile( tmpjpg );
            notyet_mask = false;
        }
        else {
            wxCopyFile( file, tmpjpg, true );
        }
        html = html + wxT("<img src=\"") + tmpjpg + wxT("\" width=\"750\" height=\"1060\"/>");
        cout = dir.GetNext( &file );
        n++;
    }
    html = html + wxT("</body></html>");

    // start printing
    wxHtmlPrintout hpout( wxT("Searcher03") );
    hpout.SetMargins( 0, 0, 0, 0, 0 );
    wxPrintDialogData pd;
    wxPrinter p( &pd );

    hpout.SetHtmlText( html, wxEmptyString, false );
    p.Print( NULL, &hpout, true );

    // end
    SetStatusMessage( wxT("被保番かフォルダ番号を."), 0 );
}
/* 一括印刷モード */
void MyFrame::OnBPrintMode( wxCommandEvent& WXUNUSED(event) )
{
    FrameBatchPrint* bp = new FrameBatchPrint( this, wxID_ANY, wxT("一括印刷"), wxDefaultPosition, wxSize( 680, 600 ), wxCAPTION|wxFRAME_NO_TASKBAR );
    bp->SetMask1( m_mask1 );
    bp->SetMask2( m_mask2 );
    bp->SetMask3( m_mask3 );
    bp->SetMask1Old( m_mask1old );
    bp->SetMask2Old( m_mask2old );
    bp->SetMask3Old( m_mask3old );
    bp->SetMark( lmin, lmax, zmin, zmax );
    bp->Show( true );
}
/* インデックス作成ダイアログ */
void MyFrame::OnIndex( wxCommandEvent& WXUNUSED(event) )
{
    wxString rootdir;
    config->SetPath( wxT("/Index") );
    config->Read( wxT("rootdir"), &rootdir );

    IndexDialog* index = new IndexDialog( this, wxID_ANY, wxT("インデックス作成"), wxDefaultPosition, wxSize( 700, 600 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL );
    index->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM );
    index->SetRootdir( rootdir );
    index->ShowModal();
}
/* マークシートパラメータ設定ダイアログ */
void MyFrame::OnMarkParam( wxCommandEvent& WXUNUSED(event) )
{
    SetParams( 2 );
}
/* マスクパラメータ設定ダイアログ */
void MyFrame::OnMaskParam( wxCommandEvent& WXUNUSED(event) )
{
    SetParams( 0 );
}
/* 設定を保存 */
void MyFrame::SetParams( int tab ) 
{
    ParamDialog* param = new ParamDialog( this, wxID_ANY, wxT("各種パラメータの指定"), wxDefaultPosition, wxSize( 350, 250 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL );
    param->SetMask1( m_mask1 );
    param->SetMask2( m_mask2 );
    param->SetMask3( m_mask3 );
    param->SetMask1Old( m_mask1old );
    param->SetMask2Old( m_mask2old );
    param->SetMask3Old( m_mask3old );
    param->SetMark( lmin, lmax, zmin, zmax );
    param->LoadParams();
    param->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM );
    param->SelectTAb( tab );

    if ( param->ShowModal() == wxID_OK ) {
        m_mask1    = param->GetMask1();
        m_mask2    = param->GetMask2();
        m_mask3    = param->GetMask3();
        m_mask1old = param->GetMask1Old();
        m_mask2old = param->GetMask2Old();
        m_mask3old = param->GetMask3Old();
        lmin       = param->GetLmin();
        lmax       = param->GetLmax();
        zmin       = param->GetZmin();
        zmax       = param->GetZmax();

        config->SetPath( wxT("/Mask") );

        config->Write( wxT("x1"), m_mask1.GetX() );
        config->Write( wxT("y1"), m_mask1.GetY() );
        config->Write( wxT("w1"), m_mask1.GetWidth() );
        config->Write( wxT("h1"), m_mask1.GetHeight() );

        config->Write( wxT("x2"), m_mask2.GetX() );
        config->Write( wxT("y2"), m_mask2.GetY() );
        config->Write( wxT("w2"), m_mask2.GetWidth() );
        config->Write( wxT("h2"), m_mask2.GetHeight() );

        config->Write( wxT("x3"), m_mask3.GetX() );
        config->Write( wxT("y3"), m_mask3.GetY() );
        config->Write( wxT("w3"), m_mask3.GetWidth() );
        config->Write( wxT("h3"), m_mask3.GetHeight() );

        config->Write( wxT("x1o"), m_mask1old.GetX() );
        config->Write( wxT("y1o"), m_mask1old.GetY() );
        config->Write( wxT("w1o"), m_mask1old.GetWidth() );
        config->Write( wxT("h1o"), m_mask1old.GetHeight() );

        config->Write( wxT("x2o"), m_mask2old.GetX() );
        config->Write( wxT("y2o"), m_mask2old.GetY() );
        config->Write( wxT("w2o"), m_mask2old.GetWidth() );
        config->Write( wxT("h2o"), m_mask2old.GetHeight() );

        config->Write( wxT("x3o"), m_mask3old.GetX() );
        config->Write( wxT("y3o"), m_mask3old.GetY() );
        config->Write( wxT("w3o"), m_mask3old.GetWidth() );
        config->Write( wxT("h3o"), m_mask3old.GetHeight() );

        config->SetPath( wxT("/Marksheet") );

        config->Write( wxT("lmin"), lmin );
        config->Write( wxT("lmax"), lmax );
        config->Write( wxT("zmin"), zmin );
        config->Write( wxT("zmax"), zmax );

        config->Flush( false );
    }
}
/* データベースファイルのバックアップ */
void MyFrame::OnDBBackup( wxCommandEvent& WXUNUSED(event) )
{
    wxDateTime now = wxDateTime::Now();
    wxString str = now.Format( wxT("%Y%m%d%H%M%S") );

    wxString org, bk;
    wxString dbdir = wxGetCwd() + wxFILE_SEP_PATH + wxT("db");

    org = dbdir + wxFILE_SEP_PATH + wxT("hhs.db");
    bk  = dbdir + wxFILE_SEP_PATH + str + wxT("_hhs.db");
    wxCopyFile( org, bk, false );

    org = dbdir + wxFILE_SEP_PATH + wxT("ccn.db");
    bk  = dbdir + wxFILE_SEP_PATH + str + wxT("_ccn.db");
    wxCopyFile( org, bk, false );
    
    wxMessageBox( wxT("バックアップ終了.") );
    return;
}
/* アプリフォルダを開く */
void MyFrame::OnOpenAppDir( wxCommandEvent& WXUNUSED(event) )
{
    wxString appdir = wxGetCwd();
    wxString execmd = wxT("explorer ") + appdir;
    wxExecute( execmd );
}
/* ビューの切替え */
void MyFrame::OnViewStyle( wxCommandEvent& event )
{
    if ( event.IsChecked() ) {
        int x, y;
        GetSize( &x, &y );
        SetSize( WINL_W + 500, y );
        m_splitter->SplitVertically( m_panelMain, m_panelView, 0 );
    }
    else {
        m_splitter->Unsplit();
        SetSize( WINL_W, -1 );
    }
}
/* 被保険者フォルダを開く */
void MyFrame::OnSelectHhsDir( wxListEvent& event )
{
    int i = event.GetIndex();
    OpenHhsDir( i );
}
/* 番号で指定したフォルダを開く */
void MyFrame::OpenHhsDir( int n )
{
    wxListItem item;
    item.SetId( n );
    item.SetColumn( 2 );
    item.SetMask( wxLIST_MASK_TEXT );
    m_listCtrl->GetItem( item );
    wxString dir = item.GetText();
    wxString execmd = wxT("explorer ") + dir;
    wxExecute( execmd );
}

/* カナ検索ダイアログ */
void MyFrame::OnKana( wxCommandEvent& WXUNUSED(event) )
{
    KanaDialog* kana = new KanaDialog( this, wxID_ANY, wxT("カナ氏名で被保番を検索"), wxDefaultPosition, wxSize( 640, 600 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxRESIZE_BORDER|wxSTAY_ON_TOP|wxTAB_TRAVERSAL );
    kana->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM );

    if ( kana->ShowModal() == wxID_OK ) {
        m_hhsno = kana->GetHhsNo();
        UpdateList( m_hhsno );
    }
}
/* 検索履歴検索ダイアログ */
void MyFrame::OnHistory( wxCommandEvent& WXUNUSED(event) )
{
	HistDialog* hist = new HistDialog( this, wxID_ANY, wxT("検索履歴"), wxDefaultPosition, wxSize( 600, 500 ), wxCAPTION|wxFRAME_NO_TASKBAR|wxSTAY_ON_TOP|wxTAB_TRAVERSAL );
    hist->ShowWithEffect( wxSHOW_EFFECT_SLIDE_TO_BOTTOM );

    if ( hist->ShowModal() == wxID_OK ) {
        m_hhsno = hist->GetHhsNo();
        UpdateList( m_hhsno );
    }
}

/* 検索結果をリストアップ */
void MyFrame::UpdateList( wxString hhsno )
{
    m_listCtrl->DeleteAllItems();
    for ( int i = 0; i < m_statusBar->GetFieldsCount(); i++ ) {
        SetStatusMessage( wxEmptyString, i );
    }

    //
    wxArrayString s = wxSplit( GetHhsInfoByHhsNo( hhsno ), '_', '\\' );
    wxString history;
    if ( s.IsEmpty() ) {
        SetStatusMessage( wxT("データベースに存在しない被保険者です."), 0 );
        history = hhsno + wxT("###");
    }
    else {
        m_textCtrlName->SetValue( s[0] );
        m_textCtrlAddr->SetValue( s[1] );
        history = hhsno + wxT("#") + s[0] + wxT("#") + s[1] + wxT("#");
    }
    m_searchBox->SetValue( hhsno );
    m_searchBox->SelectAll();
    m_searchBox->SetFocus();

    wxArrayString path = GetPathByHhsNo( hhsno );
    if ( path.IsEmpty() ) {
        SetStatusMessage( wxT("審査会履歴がありません."), 1 );
        return;
    }

    wxRegEx reDate(wxT("(^.*20[0-9]{2}.)(20[0-9]{2})([0-2][0-9])([0-9]{2})(.*$)"));
    for ( int i = 0; i < path.GetCount(); i++ ) {
        wxString date = path[i];
        reDate.ReplaceAll( &date, wxT("\\2-\\3-\\4") );

        m_listCtrl->InsertItem( i, -1 );
        m_listCtrl->SetItem( i, 0,wxString::Format( wxT("%d"), i + 1 ) , -1 ); // No
        m_listCtrl->SetItem( i, 1, date, -1 );
        m_listCtrl->SetItem( i, 2, path[i], -1 );

        if ( i % 2 ) m_listCtrl->SetItemBackgroundColour( i, wxColour( wxT("WHEAT") ) );
    }

    SetStatusMessage( wxT("「+」キーで通番1を印刷."), 0 );

    //
    wxString filename = wxGetCwd() + wxFILE_SEP_PATH + wxT("tmp") + wxFILE_SEP_PATH + wxT("history");
    wxDateTime now = wxDateTime::Now();
    history = history + now.Format( wxT("%Y-%m-%d %H:%M:%S") );

    wxTextFile hist( filename );
    hist.Open();
    hist.RemoveLine( 20 );
    hist.InsertLine( history, 0 );
    hist.Write();
    hist.Close();
}
/* ステータスバーにメッセージを出力 */
void MyFrame::SetStatusMessage( wxString msg, long n )
{
    if ( GetStatusBar() ) 
        SetStatusText( msg, n );
}

/* サイズ変更 */
void MyFrame::OnWinSize( wxSizeEvent& event )
{
    this->Refresh( true, NULL );
    TellLocation();
    event.Skip();
}
/* ウィンドウ移動 */
void MyFrame::OnWinMove( wxMoveEvent& WXUNUSED(event) )
{
    TellLocation();
    return;
}
/* ウィンドウ位置とサイズを表示 */
void MyFrame::TellLocation( void ) 
{
    wxRect r = this->GetRect();
    int x = r.GetX();
    int y = r.GetY();
    int w = r.GetWidth();
    int h = r.GetHeight();

    if ( GetStatusBar() ) 
        SetStatusText( wxString::Format(wxT( "(%d,%d) %dx%d"),x,y,w,h ), 3 );
}
/* 終了 */
void MyFrame::OnQuit( wxCommandEvent& WXUNUSED(event) )
{
    Close( true );
}
/* 設定を保存 */
void MyFrame::SaveConfig( wxCloseEvent& WXUNUSED(event) )
{
    if ( !IsIconized() && !IsMaximized() ) {
        wxGetApp().rect = this->GetRect();
    }
    Destroy();
}
/* アバウトダイアログ */
void MyFrame::OnAbout( wxCommandEvent& WXUNUSED(event) )
{
    AboutDialog* aboutDlg = new AboutDialog( this, wxID_ANY, wxT("About this Software"), wxDefaultPosition, wxSize(320,280), wxDEFAULT_DIALOG_STYLE|wxSTAY_ON_TOP ); 
    aboutDlg->ShowModal();
}