/[H6]/ResultDetailsDialog.cpp
ViewVC logotype

Annotation of /ResultDetailsDialog.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (hide annotations) (download)
Sun Sep 3 10:10:19 2006 UTC (17 years, 7 months ago) by torben
File size: 7608 byte(s)
Added author/developer comments
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 21
14     // ResultDetailsDialog dialog
15    
16     IMPLEMENT_DYNAMIC(ResultDetailsDialog, CDialog)
17     ResultDetailsDialog::ResultDetailsDialog(CWnd* pParent /*=NULL*/)
18     : CDialog(ResultDetailsDialog::IDD, pParent)
19     {
20     m_loadingData = false;
21     }
22    
23     ResultDetailsDialog::~ResultDetailsDialog()
24     {
25     }
26    
27     void ResultDetailsDialog::DoDataExchange(CDataExchange* pDX)
28     {
29     CDialog::DoDataExchange(pDX);
30     }
31    
32    
33     BEGIN_MESSAGE_MAP(ResultDetailsDialog, CDialog)
34     ON_EN_CHANGE(IDC_BARCODE, OnEnChangeBarcode)
35     ON_EN_CHANGE(IDC_NAME, OnEnChangeName)
36     ON_EN_CHANGE(IDC_DESCRIPTION, OnEnChangeDescription)
37     ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement)
38     ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus)
39     ON_BN_CLICKED(IDC_CLOSE, OnBnClickedClose)
40 torben 29 ON_BN_CLICKED(IDC_RETURN, OnBnClickedReturn)
41     ON_BN_CLICKED(IDC_CHECKOUT, OnBnClickedCheckout)
42     ON_BN_CLICKED(IDC_RESERVE, OnBnClickedReserve)
43     ON_BN_CLICKED(IDC_DELRES, OnBnClickedDelres)
44 torben 21 END_MESSAGE_MAP()
45    
46    
47     // ResultDetailsDialog message handlers
48    
49     void ResultDetailsDialog::LoadData(void)
50     {
51     if (m_loadingData == true)
52     return;
53     m_loadingData = true;
54     Equipment currentdata = CommonStorage::Instance()->getSearchResult()[m_resultIndex];
55    
56     GetDlgItem(IDC_BARCODE)->SetWindowText(currentdata.barcode);
57     GetDlgItem(IDC_NAME)->SetWindowText(currentdata.name);
58     GetDlgItem(IDC_DESCRIPTION)->SetWindowText(currentdata.description);
59     GetDlgItem(IDC_PLACEMENT)->SetWindowText(currentdata.placement);
60     GetDlgItem(IDC_STATUS)->SetWindowText(currentdata.status);
61    
62     m_loadingData = false;
63     }
64    
65     void ResultDetailsDialog::LoadListControls(void)
66     {
67     if (CommonStorage::Instance()->getAdmin() ) {
68     Equipment currentdata = CommonStorage::Instance()->getSearchResult()[m_resultIndex];
69    
70     //load Equipment::checkouts
71     CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS);
72 torben 29 checkouts->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
73 torben 21 checkouts->InsertColumn(0,"Inits");
74     checkouts->InsertColumn(1,"Start date");
75     checkouts->InsertColumn(2,"Return date");
76     checkouts->InsertColumn(3,"Number of days");
77    
78     for (int i=0; i<currentdata.checkouts.size(); i++) {
79     int nItem = checkouts->InsertItem(i,currentdata.checkouts[i].inits);
80     checkouts->SetItemText(nItem,1,currentdata.checkouts[i].startdate);
81     checkouts->SetItemText(nItem,2,currentdata.checkouts[i].enddate);
82     checkouts->SetItemText(nItem,3,currentdata.checkouts[i].numdays);
83     }
84     checkouts->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
85     checkouts->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
86     checkouts->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
87     checkouts->SetColumnWidth(3,LVSCW_AUTOSIZE_USEHEADER);
88    
89     // load Equipment::reservations
90     CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS);
91 torben 29 reservations->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
92     reservations->InsertColumn(0,"#");
93     reservations->InsertColumn(1,"Inits");
94     reservations->InsertColumn(2,"Reservation date");
95 torben 21
96 torben 29
97 torben 21 for (int i=0; i<currentdata.reservations.size(); i++) {
98 torben 29 CString tmp;
99     tmp.Format("%d", i+1);
100     int nItem = reservations->InsertItem(i, tmp);
101     reservations->SetItemText(nItem,1, currentdata.reservations[i].inits);
102     reservations->SetItemText(nItem,2, currentdata.reservations[i].startdate);
103    
104 torben 21 }
105    
106 torben 29 if (currentdata.reservations.size() > 0)
107     GetDlgItem(IDC_DELRES)->EnableWindow(true);
108    
109    
110 torben 21 reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
111     reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
112     reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
113    
114    
115     } else { // not administrator
116     GetDlgItem(IDC_CHECKOUTS)->EnableWindow(false);
117     GetDlgItem(IDC_RESERVATIONS)->EnableWindow(false);
118     }
119     }
120    
121    
122     BOOL ResultDetailsDialog::OnInitDialog()
123     {
124     CDialog::OnInitDialog();
125    
126    
127     GetDlgItem(IDC_RESERVE)->EnableWindow(CommonStorage::Instance()->getAdmin());
128     GetDlgItem(IDC_CHECKOUT)->EnableWindow(CommonStorage::Instance()->getAdmin());
129     GetDlgItem(IDC_RETURN)->EnableWindow(CommonStorage::Instance()->getAdmin());
130    
131     CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status;
132    
133 torben 29 if (status == "Ledig") {
134 torben 21 GetDlgItem(IDC_RETURN)->EnableWindow(false);
135 torben 29 GetDlgItem(IDC_RESERVE)->EnableWindow(false);
136     }
137    
138 torben 21 if (status == "Udlånt")
139     GetDlgItem(IDC_CHECKOUT)->EnableWindow(false);
140     if (status == "Reserveret")
141     GetDlgItem(IDC_RETURN)->EnableWindow(false);
142    
143     LoadData();
144     LoadListControls();
145    
146     return TRUE;
147     }
148    
149 torben 29 /////////////////////////////////////////////
150 torben 24 // a normal EditControl is prettier than a greyed out read-only
151     // So to simulate a read-only field, we reload the data every time the
152     // user tries to modify the data
153 torben 21 void ResultDetailsDialog::OnEnChangeBarcode()
154     {
155     LoadData();
156     }
157    
158     void ResultDetailsDialog::OnEnChangeName()
159     {
160     LoadData();
161     }
162    
163     void ResultDetailsDialog::OnEnChangeDescription()
164     {
165     LoadData();
166     }
167    
168     void ResultDetailsDialog::OnEnChangePlacement()
169     {
170     LoadData();
171     }
172    
173     void ResultDetailsDialog::OnEnChangeStatus()
174     {
175     LoadData();
176     }
177    
178     void ResultDetailsDialog::OnBnClickedClose()
179     {
180     OnOK();
181     }
182 torben 29
183     //////////////////////////////////////////////////
184    
185     void ResultDetailsDialog::OnBnClickedReturn()
186     {
187     CString barcode = CommonStorage::Instance()->getSearchResult()[m_resultIndex].barcode;
188    
189     CommonStorage::Instance()->getDBLayer()->ReturnEquipment(barcode);
190     MessageBox("The Item is returned, but the changes won't show until the next query");
191     OnOK();
192     }
193    
194     void ResultDetailsDialog::OnBnClickedCheckout()
195     {
196     CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status;
197     CheckoutDialog check;
198    
199     check.m_checkoutMode = true;
200    
201    
202     Reservation topReservation;
203     if (status == "Reserveret") {
204     topReservation = CommonStorage::Instance()->getSearchResult()[m_resultIndex].reservations[0];
205     check.m_reservedTo = topReservation.inits;
206     }
207    
208     if (check.DoModal() == IDOK)
209     {
210     DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer();
211     Person p = dblayer->GetPerson(check.m_inits);
212    
213     Equipment eq;
214     GetDlgItem(IDC_BARCODE)->GetWindowText(eq.barcode);
215    
216     dblayer->CheckoutEquipment(p, eq, atoi(check.m_numdays) );
217    
218     if (status == "Reserveret") { //if the equipment was reserved, we must delete the reservation
219     dblayer->DeleteReservation(eq.barcode, topReservation.reservationID);
220     }
221    
222     OnOK();
223     }
224     }
225    
226     void ResultDetailsDialog::OnBnClickedReserve()
227     {
228     CheckoutDialog check;
229     check.m_checkoutMode = false;
230     if (check.DoModal() == IDOK)
231     {
232     DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer();
233     Person p = dblayer->GetPerson(check.m_inits);
234     CString barcode;
235     GetDlgItem(IDC_BARCODE)->GetWindowText(barcode);
236     dblayer->EquipmentReservation(barcode,p);
237     OnOK();
238     }
239     }
240    
241     void ResultDetailsDialog::OnBnClickedDelres()
242     {
243     int sel = ((CListCtrl*)GetDlgItem(IDC_RESERVATIONS))->GetSelectionMark();
244     if (sel != -1) {
245     CString reservationID = CommonStorage::Instance()->getSearchResult()[m_resultIndex].reservations[sel].reservationID;
246     CString barcode = CommonStorage::Instance()->getSearchResult()[m_resultIndex].barcode;
247     CommonStorage::Instance()->getDBLayer()->DeleteReservation(barcode, reservationID);
248     MessageBox("Reservation deleted, but won't show until next search");
249     } else {
250     MessageBox("No reservation is selected");
251     }
252     }

  ViewVC Help
Powered by ViewVC 1.1.20