view src/index.cpp @ 22:92188f60323d default tip

Implement Masking function on Preview Dialog.
author pyon@macmini
date Sat, 04 Apr 2015 17:23:46 +0900
parents 52958cd4a073
children
line wrap: on
line source

// Filename   : index.cpp
// Last Change: 12-May-2014.
//

#include "index.h"
#include "db.h"
#include "wx/wxsqlite3.h"

IndexDialog::IndexDialog( wxWindow* parent, wxWindowID id, const wxString& title, const wxPoint& pos, const wxSize& size, long style ) 
    : wxDialog( parent, id, title, pos, size, style )
{
	this->SetSizeHints( wxDefaultSize, wxDefaultSize );
	
	wxBoxSizer* bSizerTop = new wxBoxSizer( wxHORIZONTAL );
	
	m_listCtrl = new wxListCtrl( this, wxID_ANY, 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, 60 );
    itemCol.SetText( wxT("被保険者番号") );
    m_listCtrl->InsertColumn( 3, itemCol );
    m_listCtrl->SetColumnWidth( 3, 100 );
    itemCol.SetText( wxT("氏名") );
    m_listCtrl->InsertColumn( 4, itemCol );
    m_listCtrl->SetColumnWidth( 4, 120 );

	bSizerTop->Add( m_listCtrl, 1, wxALL|wxEXPAND, 5 );
	
	wxBoxSizer* bSizerR = new wxBoxSizer( wxVERTICAL );
	
	m_calendar = new wxCalendarCtrl( this, ID_CALNENDER, wxDefaultDateTime, wxDefaultPosition, wxDefaultSize, wxCAL_SHOW_HOLIDAYS );
	bSizerR->Add( m_calendar, 0, wxALL, 5 );
	
	m_buttonMake = new wxButton( this, ID_MKINDEX, wxT("作成"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerR->Add( m_buttonMake, 0, wxALIGN_RIGHT|wxALL, 5 );
	
	bSizerR->Add( 0, 300, 1, wxEXPAND, 5 );

	m_richText = new wxRichTextCtrl( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxSize( -1, 160 ), wxVSCROLL|wxBORDER_NONE|wxWANTS_CHARS );
	bSizerR->Add( m_richText, 0, wxEXPAND|wxALL, 5 );

	m_buttonClose = new wxButton( this, wxID_CANCEL, wxT("閉じる"), wxDefaultPosition, wxDefaultSize, 0 );
	bSizerR->Add( m_buttonClose, 0, wxALIGN_RIGHT|wxALL, 5 );
	
	bSizerTop->Add( bSizerR, 0, wxALIGN_RIGHT, 5 );
	
	this->SetSizer( bSizerTop );
	this->Layout();
	
	this->Centre( wxBOTH );

    CheckHhs();
}

IndexDialog::~IndexDialog()
{
}

// Event Table
BEGIN_EVENT_TABLE( IndexDialog, wxDialog )
    EVT_CALENDAR_PAGE_CHANGED( ID_CALNENDER, IndexDialog::OnPage )
    EVT_CALENDAR( ID_CALNENDER, IndexDialog::OnSelect )
    EVT_BUTTON( ID_MKINDEX, IndexDialog::OnMakeIndex )
END_EVENT_TABLE()

// Event Handlers & Functions
void IndexDialog::OnSelect( wxCalendarEvent& WXUNUSED(event) )	
{
    UpdateList();
}

void IndexDialog::OnMakeIndex( wxCommandEvent& WXUNUSED(event) )
{
	wxDateTime dt = m_calendar->GetDate();
    wxString month = dt.Format( wxT("%m") );
    wxString year  = dt.Format( wxT("%Y") );
    if ( month.IsSameAs( wxT("01") ) || month.IsSameAs( wxT("02") ) || month.IsSameAs( wxT("03") ) ) {
        long y;
        year.ToLong( &y, 10 );
        y--;
        year = wxString::Format( wxT("%d"), y );
    }


    wxString date = dt.Format( wxT("%Y%m%d") );
    wxString datadir = m_rootdir + wxFILE_SEP_PATH + year + wxFILE_SEP_PATH + date;
    if ( !wxDir::Exists( datadir ) ) {
        wxMessageBox( wxT("フォルダが存在しません.") + datadir );
        return;
    }

    UpdateIndex( datadir, date );

    UpdateList();
    wxMessageBox( wxT("インデックス作成が終了しました.") );
}

void IndexDialog::OnPage( wxCalendarEvent& WXUNUSED(event) ) {}

void IndexDialog::UpdateList( void )
{
    wxDateTime dt = m_calendar->GetDate();
    wxString ymd = dt.Format( wxT("%Y%m%d") );

    wxArrayString ccn = GetCcnByDate( ymd );

    m_listCtrl->DeleteAllItems();

    wxString buf;
    for ( int i = 0; i < ccn.GetCount(); i++ ) {
        m_listCtrl->InsertItem( i, -1 );
        buf.Printf( wxT("%03d"), i + 1 );
        m_listCtrl->SetItem( i, 0, buf, -1 ); // No

        wxArrayString ary = wxSplit( ccn[i], '_', '\\' ); // hhsno, path, date
        buf = GetHhsInfoByHhsNo( ary[0] );
        wxString name = buf.BeforeFirst( '_' );
        wxString ccnn  = ary[1].Mid( 17, 3 );

        m_listCtrl->SetItem( i, 1, ary[2], -1 ); // date
        m_listCtrl->SetItem( i, 2, ccnn,   -1 ); // ccn
        m_listCtrl->SetItem( i, 3, ary[0], -1 ); // hhsno
        m_listCtrl->SetItem( i, 4, name,   -1 ); // name

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

void IndexDialog::CheckHhs( void )
{
    wxArrayString date   = GetLastUpdate();
    wxArrayString result = CheckDBs();

    m_richText->BeginBold();
    m_richText->WriteText( wxT("最終更新年月日") );
    m_richText->EndBold();
    m_richText->Newline();
    m_richText->BeginTextColour( wxColour( 0, 0, 255 ) );
    m_richText->WriteText( wxT("インデックス:") );
    m_richText->EndTextColour();
    m_richText->WriteText( date[0] );
    m_richText->Newline();

    m_richText->BeginTextColour( wxColour( 0, 0, 255 ) );
    m_richText->WriteText( wxT("被保険者情報:") );
    m_richText->EndTextColour();
    m_richText->WriteText( date[1] );
    m_richText->Newline();
    m_richText->Newline();

    for ( int i = 0; i < result.GetCount(); i++ ) {
        m_richText->WriteText( wxT("チェック対象 : ") );
        m_richText->BeginTextColour( wxColour( 255, 0, 0 ) );
        m_richText->WriteText( result[i] );
        m_richText->EndTextColour();
        m_richText->Newline();
    }
    m_richText->SetEditable( false );
}