/[H6]/CheckoutDialog.cpp
ViewVC logotype

Contents of /CheckoutDialog.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 45 - (show annotations) (download)
Wed Sep 6 19:00:37 2006 UTC (17 years, 6 months ago) by torben
File size: 3127 byte(s)
Fixed a bug in the user selection.
1 /*
2 * Developed by Torben H. Nielsen
3 */
4
5 #include "stdafx.h"
6 #include "h6-udlånssystem.h"
7 #include "CheckoutDialog.h"
8 #include ".\checkoutdialog.h"
9
10 #include "CommonStorage.h"
11 #include "DatabaseLayer.h"
12 #include "Containers.h"
13
14
15
16 // CheckoutDialog dialog
17
18 IMPLEMENT_DYNAMIC(CheckoutDialog, CDialog)
19 CheckoutDialog::CheckoutDialog(CWnd* pParent /*=NULL*/)
20 : CDialog(CheckoutDialog::IDD, pParent)
21 {
22 }
23
24 CheckoutDialog::~CheckoutDialog()
25 {
26 }
27
28 void CheckoutDialog::DoDataExchange(CDataExchange* pDX)
29 {
30 CDialog::DoDataExchange(pDX);
31 }
32
33
34 BEGIN_MESSAGE_MAP(CheckoutDialog, CDialog)
35 ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST, OnLvnItemchangedList)
36 ON_BN_CLICKED(IDOK, OnBnClickedOk)
37 ON_NOTIFY(NM_CLICK, IDC_LIST, OnNMClickList)
38 END_MESSAGE_MAP()
39
40
41 // CheckoutDialog message handlers
42
43 BOOL CheckoutDialog::OnInitDialog()
44 {
45 CDialog::OnInitDialog();
46
47 if (m_checkoutMode == true) {
48 this->SetWindowText("Checkout");
49 GetDlgItem(IDC_NUMDAYS)->SetWindowText("30");
50
51 if (m_reservedTo != "") {
52 GetDlgItem(IDC_INITS)->SetWindowText(m_reservedTo);
53 GetDlgItem(IDC_INITS)->EnableWindow(false);
54 GetDlgItem(IDC_LIST)->EnableWindow(false);
55 }
56
57 } else {//reservation
58 this->SetWindowText("Reservation");
59 GetDlgItem(IDC_NUMDAYS)->EnableWindow(false);
60 }
61
62 CListCtrl *list = (CListCtrl *) GetDlgItem(IDC_LIST);
63 list->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
64 list->InsertColumn(0,"Inits");
65 list->InsertColumn(1,"Name");
66
67 m_persons = CommonStorage::Instance()->getDBLayer()->GetPersonAll();
68
69 for (int i=0; i<m_persons.size(); i++) {
70 int nItem = list->InsertItem(i, m_persons[i].inits);
71 list->SetItemText(nItem, 1, m_persons[i].name);
72 }
73 list->SetColumnWidth(0,50);
74 list->SetColumnWidth(1, LVSCW_AUTOSIZE);
75
76 ((CEdit*)GetDlgItem(IDC_INITS))->SetLimitText(4);
77
78 return TRUE;
79 }
80
81 void CheckoutDialog::OnLvnItemchangedList(NMHDR *pNMHDR, LRESULT *pResult)
82 {
83 LPNMLISTVIEW pNMLV = reinterpret_cast<LPNMLISTVIEW>(pNMHDR);
84
85 LoadInits();
86 *pResult = 0;
87 }
88
89 void CheckoutDialog::OnBnClickedOk()
90 {
91 GetDlgItem(IDC_INITS)->GetWindowText(m_inits);
92 GetDlgItem(IDC_NUMDAYS)->GetWindowText(m_numdays);
93 bool foundInits = false;
94
95 if (m_inits == "") {
96 MessageBox("You must fill out the initials field");
97 return;
98 }
99
100 if (m_checkoutMode == true && m_numdays == "") {
101 MessageBox("You must enter number of days");
102 return;
103 }
104
105 for (int i=0; i<m_persons.size(); i++) {
106 if (m_persons[i].inits.MakeLower() == m_inits.MakeLower()) {
107 foundInits = true;
108 break;
109 }
110 }
111
112 if (foundInits == false) {
113 MessageBox("You must enter a valid set of initials");
114 return;
115 }
116
117 OnOK();
118 }
119
120 void CheckoutDialog::OnNMClickList(NMHDR *pNMHDR, LRESULT *pResult)
121 {
122 // TODO: Add your control notification handler code here
123
124 LoadInits();
125 *pResult = 0;
126 }
127
128
129 void CheckoutDialog::LoadInits(void)
130 {
131 CListCtrl* list = (CListCtrl*) GetDlgItem(IDC_LIST);
132 int selected = list->GetSelectionMark();
133 CString inits = list->GetItemText(selected,0);
134
135 GetDlgItem(IDC_INITS)->SetWindowText(inits);
136
137 }

  ViewVC Help
Powered by ViewVC 1.1.20