/* * Developed by Torben H. Nielsen */ #include "stdafx.h" #include "h6-udlånssystem.h" #include "SearchDialog.h" #include ".\searchdialog.h" #include "CommonStorage.h" #include "DatabaseLayer.h" #include "MyTabCtrl.h" // SearchDialog dialog IMPLEMENT_DYNAMIC(SearchDialog, CDialog) SearchDialog::SearchDialog(CWnd* pParent /*=NULL*/) : CDialog(SearchDialog::IDD, pParent) { } SearchDialog::~SearchDialog() { } void SearchDialog::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); } BEGIN_MESSAGE_MAP(SearchDialog, CDialog) ON_WM_SETFOCUS() ON_BN_CLICKED(IDC_CLEAR, OnBnClickedClear) ON_BN_CLICKED(IDC_SEARCH, OnBnClickedSearch) END_MESSAGE_MAP() // SearchDialog message handlers void SearchDialog::OnOK() { //CDialog::OnOK(); } void SearchDialog::OnCancel() { //CDialog::OnCancel(); } void SearchDialog::OnSetFocus(CWnd* pOldWnd) { GetDlgItem(IDC_INITS)->EnableWindow( CommonStorage::Instance()->getAdmin() ); if (! CommonStorage::Instance()->getAdmin() ) { GetDlgItem(IDC_INITS)->SetWindowText(""); } } BOOL SearchDialog::OnInitDialog() { CDialog::OnInitDialog(); GetDlgItem(IDC_INITS)->EnableWindow(false); ((CButton*)GetDlgItem(IDC_AVAILABLE))->SetCheck(true); ((CEdit*)GetDlgItem(IDC_BARCODE))->SetLimitText(13); //max 13 chars in barcode field return TRUE; } void SearchDialog::OnBnClickedClear() { ((CButton*)GetDlgItem(IDC_AVAILABLE))->SetCheck(true); ((CButton*)GetDlgItem(IDC_RESERVED))->SetCheck(false); ((CButton*)GetDlgItem(IDC_DEPOSITED))->SetCheck(false); GetDlgItem(IDC_NAME)->SetWindowText(""); GetDlgItem(IDC_BARCODE)->SetWindowText(""); GetDlgItem(IDC_INITS)->SetWindowText(""); } void SearchDialog::OnBnClickedSearch() { CString inits,barcode,name; bool available, reserved,deposited; available = ( ((CButton*)GetDlgItem(IDC_AVAILABLE))->GetCheck() == 1); reserved = ( ((CButton*)GetDlgItem(IDC_RESERVED))->GetCheck() == 1); deposited = ( ((CButton*)GetDlgItem(IDC_DEPOSITED))->GetCheck() == 1); GetDlgItem(IDC_INITS)->GetWindowText(inits); GetDlgItem(IDC_BARCODE)->GetWindowText(barcode); GetDlgItem(IDC_NAME)->GetWindowText(name); DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer(); vector buffer = dblayer->Search(barcode, name, inits, available, reserved, deposited); CommonStorage::Instance()->setSearchResult(buffer); CommonStorage::Instance()->getTabCtrl()->SetCurSel(1); CommonStorage::Instance()->getTabCtrl()->ChangeFocus();; }