--- SearchDialog.cpp 2006/08/30 08:19:13 5 +++ SearchDialog.cpp 2006/08/31 15:58:20 14 @@ -6,6 +6,10 @@ #include "SearchDialog.h" #include ".\searchdialog.h" +#include "CommonStorage.h" +#include "DatabaseLayer.h" + +#include "MyTabCtrl.h" // SearchDialog dialog @@ -26,6 +30,9 @@ BEGIN_MESSAGE_MAP(SearchDialog, CDialog) + ON_WM_SETFOCUS() + ON_BN_CLICKED(IDC_CLEAR, OnBnClickedClear) + ON_BN_CLICKED(IDC_SEARCH, OnBnClickedSearch) END_MESSAGE_MAP() @@ -33,14 +40,65 @@ void SearchDialog::OnOK() { - // TODO: Add your specialized code here and/or call the base class - //CDialog::OnOK(); } void SearchDialog::OnCancel() { - // TODO: Add your specialized code here and/or call the base class - //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); + + 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();; + +} + +