/[H6]/ResultDetailsDialog.cpp
ViewVC logotype

Annotation of /ResultDetailsDialog.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 55 - (hide annotations) (download)
Tue Sep 12 10:15:12 2006 UTC (17 years, 7 months ago) by torben
File size: 8618 byte(s)
In the dialogs, work on status id instead of status text, which is much more safe in case the status text changes
1 torben 31 /*
2     * Developed by Torben H. Nielsen
3     */
4 torben 21
5 torben 31
6 torben 21 #include "stdafx.h"
7     #include "h6-udlånssystem.h"
8     #include "ResultDetailsDialog.h"
9     #include ".\resultdetailsdialog.h"
10     #include "CommonStorage.h"
11 torben 29 #include "DatabaseLayer.h"
12     #include "CheckoutDialog.h"
13 torben 37 #include "SearchDialog.h"
14     #include "ResultDialog.h"
15     #include "MyTabCtrl.h"
16 torben 21
17     // ResultDetailsDialog dialog
18    
19     IMPLEMENT_DYNAMIC(ResultDetailsDialog, CDialog)
20     ResultDetailsDialog::ResultDetailsDialog(CWnd* pParent /*=NULL*/)
21     : CDialog(ResultDetailsDialog::IDD, pParent)
22     {
23     m_loadingData = false;
24     }
25    
26     ResultDetailsDialog::~ResultDetailsDialog()
27     {
28     }
29    
30     void ResultDetailsDialog::DoDataExchange(CDataExchange* pDX)
31     {
32     CDialog::DoDataExchange(pDX);
33     }
34    
35    
36     BEGIN_MESSAGE_MAP(ResultDetailsDialog, CDialog)
37     ON_EN_CHANGE(IDC_BARCODE, OnEnChangeBarcode)
38     ON_EN_CHANGE(IDC_NAME, OnEnChangeName)
39     ON_EN_CHANGE(IDC_DESCRIPTION, OnEnChangeDescription)
40     ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement)
41     ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus)
42     ON_BN_CLICKED(IDC_CLOSE, OnBnClickedClose)
43 torben 29 ON_BN_CLICKED(IDC_RETURN, OnBnClickedReturn)
44     ON_BN_CLICKED(IDC_CHECKOUT, OnBnClickedCheckout)
45     ON_BN_CLICKED(IDC_RESERVE, OnBnClickedReserve)
46     ON_BN_CLICKED(IDC_DELRES, OnBnClickedDelres)
47 torben 21 END_MESSAGE_MAP()
48    
49    
50     // ResultDetailsDialog message handlers
51    
52     void ResultDetailsDialog::LoadData(void)
53     {
54     if (m_loadingData == true)
55     return;
56     m_loadingData = true;
57    
58 torben 54 GetDlgItem(IDC_BARCODE)->SetWindowText(m_equipment.barcode);
59     GetDlgItem(IDC_NAME)->SetWindowText(m_equipment.name);
60     GetDlgItem(IDC_DESCRIPTION)->SetWindowText(m_equipment.description);
61     GetDlgItem(IDC_PLACEMENT)->SetWindowText(m_equipment.placement);
62     GetDlgItem(IDC_STATUS)->SetWindowText(m_equipment.status);
63 torben 21
64     m_loadingData = false;
65     }
66    
67     void ResultDetailsDialog::LoadListControls(void)
68     {
69     if (CommonStorage::Instance()->getAdmin() ) {
70    
71     //load Equipment::checkouts
72     CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS);
73 torben 37 checkouts->DeleteAllItems();
74 torben 21
75 torben 54 for (int i=0; i<m_equipment.checkouts.size(); i++) {
76     int nItem = checkouts->InsertItem(i, m_equipment.checkouts[i].inits);
77     checkouts->SetItemText(nItem,1, m_equipment.checkouts[i].startdate);
78     checkouts->SetItemText(nItem,2, m_equipment.checkouts[i].enddate);
79     checkouts->SetItemText(nItem,3, m_equipment.checkouts[i].numdays);
80 torben 21 }
81     checkouts->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
82     checkouts->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
83     checkouts->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
84     checkouts->SetColumnWidth(3,LVSCW_AUTOSIZE_USEHEADER);
85    
86     // load Equipment::reservations
87     CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS);
88 torben 37 reservations->DeleteAllItems();
89 torben 21
90 torben 29
91 torben 54 for (int i=0; i<m_equipment.reservations.size(); i++) {
92 torben 29 CString tmp;
93     tmp.Format("%d", i+1);
94     int nItem = reservations->InsertItem(i, tmp);
95 torben 54 reservations->SetItemText(nItem, 1, m_equipment.reservations[i].inits);
96     reservations->SetItemText(nItem, 2, m_equipment.reservations[i].startdate);
97 torben 29
98 torben 21 }
99    
100 torben 54 if (m_equipment.reservations.size() > 0)
101 torben 29 GetDlgItem(IDC_DELRES)->EnableWindow(true);
102    
103    
104 torben 21 reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
105     reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
106     reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
107    
108    
109     } else { // not administrator
110     GetDlgItem(IDC_CHECKOUTS)->EnableWindow(false);
111     GetDlgItem(IDC_RESERVATIONS)->EnableWindow(false);
112     }
113     }
114    
115    
116     BOOL ResultDetailsDialog::OnInitDialog()
117     {
118     CDialog::OnInitDialog();
119    
120 torben 37 CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS);
121     checkouts->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
122     checkouts->InsertColumn(0,"Inits");
123     checkouts->InsertColumn(1,"Start date");
124     checkouts->InsertColumn(2,"Return date");
125     checkouts->InsertColumn(3,"Number of days");
126     checkouts->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
127     checkouts->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
128     checkouts->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
129     checkouts->SetColumnWidth(3,LVSCW_AUTOSIZE_USEHEADER);
130    
131     CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS);
132     reservations->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
133     reservations->InsertColumn(0,"#");
134     reservations->InsertColumn(1,"Inits");
135     reservations->InsertColumn(2,"Reservation date");
136     reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
137     reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
138     reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
139    
140    
141    
142 torben 21 GetDlgItem(IDC_RESERVE)->EnableWindow(CommonStorage::Instance()->getAdmin());
143     GetDlgItem(IDC_CHECKOUT)->EnableWindow(CommonStorage::Instance()->getAdmin());
144     GetDlgItem(IDC_RETURN)->EnableWindow(CommonStorage::Instance()->getAdmin());
145    
146 torben 54 m_equipment = CommonStorage::Instance()->getDBLayer()->GetEquipment(m_barcode);
147 torben 21
148 torben 54
149     EnableControls();
150 torben 21 LoadData();
151     LoadListControls();
152    
153     return TRUE;
154     }
155    
156 torben 29 /////////////////////////////////////////////
157 torben 24 // a normal EditControl is prettier than a greyed out read-only
158     // So to simulate a read-only field, we reload the data every time the
159     // user tries to modify the data
160 torben 21 void ResultDetailsDialog::OnEnChangeBarcode()
161     {
162     LoadData();
163     }
164    
165     void ResultDetailsDialog::OnEnChangeName()
166     {
167     LoadData();
168     }
169    
170     void ResultDetailsDialog::OnEnChangeDescription()
171     {
172     LoadData();
173     }
174    
175     void ResultDetailsDialog::OnEnChangePlacement()
176     {
177     LoadData();
178     }
179    
180     void ResultDetailsDialog::OnEnChangeStatus()
181     {
182     LoadData();
183     }
184    
185     void ResultDetailsDialog::OnBnClickedClose()
186     {
187     OnOK();
188     }
189 torben 29
190     //////////////////////////////////////////////////
191    
192     void ResultDetailsDialog::OnBnClickedReturn()
193     {
194    
195 torben 54 DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer();
196     dblayer->ReturnEquipment(m_barcode);
197     this->ReloadData();
198 torben 29 }
199    
200     void ResultDetailsDialog::OnBnClickedCheckout()
201     {
202     CheckoutDialog check;
203    
204 torben 54 check.m_checkoutMode = true;
205 torben 29
206     Reservation topReservation;
207 torben 55 if (m_equipment.statusid == StatusReserved) {
208 torben 54
209     topReservation = m_equipment.reservations[0];
210 torben 29 check.m_reservedTo = topReservation.inits;
211     }
212    
213     if (check.DoModal() == IDOK)
214     {
215     DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer();
216     Person p = dblayer->GetPerson(check.m_inits);
217    
218     Equipment eq;
219     GetDlgItem(IDC_BARCODE)->GetWindowText(eq.barcode);
220 torben 55
221 torben 29 dblayer->CheckoutEquipment(p, eq, atoi(check.m_numdays) );
222    
223 torben 55 if (m_equipment.statusid == StatusReserved) { //if the equipment was reserved, we must delete the reservation
224 torben 29 dblayer->DeleteReservation(eq.barcode, topReservation.reservationID);
225     }
226 torben 54 this->ReloadData();
227 torben 29 }
228     }
229    
230     void ResultDetailsDialog::OnBnClickedReserve()
231     {
232     CheckoutDialog check;
233     check.m_checkoutMode = false;
234     if (check.DoModal() == IDOK)
235     {
236     DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer();
237     Person p = dblayer->GetPerson(check.m_inits);
238     CString barcode;
239     GetDlgItem(IDC_BARCODE)->GetWindowText(barcode);
240     dblayer->EquipmentReservation(barcode,p);
241 torben 37
242 torben 54 this->ReloadData();
243 torben 29 }
244     }
245    
246     void ResultDetailsDialog::OnBnClickedDelres()
247     {
248     int sel = ((CListCtrl*)GetDlgItem(IDC_RESERVATIONS))->GetSelectionMark();
249     if (sel != -1) {
250 torben 54 CString reservationID = m_equipment.reservations[sel].reservationID;
251     CString barcode = m_equipment.barcode;
252 torben 29 CommonStorage::Instance()->getDBLayer()->DeleteReservation(barcode, reservationID);
253 torben 54 this->ReloadData();
254    
255 torben 29 } else {
256     MessageBox("No reservation is selected");
257     }
258     }
259 torben 54
260     void ResultDetailsDialog::ReloadData(void)
261     {
262     m_equipment = CommonStorage::Instance()->getDBLayer()->GetEquipment(m_barcode);
263     this->LoadData();
264     this->LoadListControls();
265     this->EnableControls();
266    
267     ((SearchDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[0])->OnBnClickedSearch();
268     ((ResultDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[1])->LoadResults();
269     }
270    
271     void ResultDetailsDialog::EnableControls(void)
272     {
273     if (CommonStorage::Instance()->getAdmin() ) {
274 torben 55 if (m_equipment.statusid == StatusAvailable) {
275 torben 54 GetDlgItem(IDC_CHECKOUT)->EnableWindow(true);
276     GetDlgItem(IDC_RETURN)->EnableWindow(false);
277     GetDlgItem(IDC_RESERVE)->EnableWindow(false);
278 torben 55 } else if (m_equipment.statusid == StatusCheckedout) {
279 torben 54 GetDlgItem(IDC_CHECKOUT)->EnableWindow(false);
280     GetDlgItem(IDC_RETURN)->EnableWindow(true);
281     GetDlgItem(IDC_RESERVE)->EnableWindow(true);
282 torben 55 } else { //m_equipment.statusid == StatusReserved
283 torben 54 GetDlgItem(IDC_CHECKOUT)->EnableWindow(true);
284     GetDlgItem(IDC_RETURN)->EnableWindow(false);
285     GetDlgItem(IDC_RESERVE)->EnableWindow(true);
286     }
287     }
288     }

  ViewVC Help
Powered by ViewVC 1.1.20