1 |
/*
|
2 |
* Developed by Torben H. Nielsen
|
3 |
*/
|
4 |
|
5 |
|
6 |
#include "stdafx.h"
|
7 |
#include "h6-udlånssystem.h"
|
8 |
#include "ResultDetailsDialog.h"
|
9 |
#include ".\resultdetailsdialog.h"
|
10 |
#include "CommonStorage.h"
|
11 |
#include "DatabaseLayer.h"
|
12 |
#include "CheckoutDialog.h"
|
13 |
#include "SearchDialog.h"
|
14 |
#include "ResultDialog.h"
|
15 |
#include "MyTabCtrl.h"
|
16 |
|
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 |
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 |
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 |
Equipment currentdata = CommonStorage::Instance()->getSearchResult()[m_resultIndex];
|
58 |
|
59 |
GetDlgItem(IDC_BARCODE)->SetWindowText(currentdata.barcode);
|
60 |
GetDlgItem(IDC_NAME)->SetWindowText(currentdata.name);
|
61 |
GetDlgItem(IDC_DESCRIPTION)->SetWindowText(currentdata.description);
|
62 |
GetDlgItem(IDC_PLACEMENT)->SetWindowText(currentdata.placement);
|
63 |
GetDlgItem(IDC_STATUS)->SetWindowText(currentdata.status);
|
64 |
|
65 |
m_loadingData = false;
|
66 |
}
|
67 |
|
68 |
void ResultDetailsDialog::LoadListControls(void)
|
69 |
{
|
70 |
if (CommonStorage::Instance()->getAdmin() ) {
|
71 |
Equipment currentdata = CommonStorage::Instance()->getSearchResult()[m_resultIndex];
|
72 |
|
73 |
//load Equipment::checkouts
|
74 |
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS);
|
75 |
checkouts->DeleteAllItems();
|
76 |
|
77 |
for (int i=0; i<currentdata.checkouts.size(); i++) {
|
78 |
int nItem = checkouts->InsertItem(i,currentdata.checkouts[i].inits);
|
79 |
checkouts->SetItemText(nItem,1,currentdata.checkouts[i].startdate);
|
80 |
checkouts->SetItemText(nItem,2,currentdata.checkouts[i].enddate);
|
81 |
checkouts->SetItemText(nItem,3,currentdata.checkouts[i].numdays);
|
82 |
}
|
83 |
checkouts->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
|
84 |
checkouts->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
|
85 |
checkouts->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
|
86 |
checkouts->SetColumnWidth(3,LVSCW_AUTOSIZE_USEHEADER);
|
87 |
|
88 |
// load Equipment::reservations
|
89 |
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS);
|
90 |
reservations->DeleteAllItems();
|
91 |
|
92 |
|
93 |
for (int i=0; i<currentdata.reservations.size(); i++) {
|
94 |
CString tmp;
|
95 |
tmp.Format("%d", i+1);
|
96 |
int nItem = reservations->InsertItem(i, tmp);
|
97 |
reservations->SetItemText(nItem,1, currentdata.reservations[i].inits);
|
98 |
reservations->SetItemText(nItem,2, currentdata.reservations[i].startdate);
|
99 |
|
100 |
}
|
101 |
|
102 |
if (currentdata.reservations.size() > 0)
|
103 |
GetDlgItem(IDC_DELRES)->EnableWindow(true);
|
104 |
|
105 |
|
106 |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
|
107 |
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
|
108 |
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
|
109 |
|
110 |
|
111 |
} else { // not administrator
|
112 |
GetDlgItem(IDC_CHECKOUTS)->EnableWindow(false);
|
113 |
GetDlgItem(IDC_RESERVATIONS)->EnableWindow(false);
|
114 |
}
|
115 |
}
|
116 |
|
117 |
|
118 |
BOOL ResultDetailsDialog::OnInitDialog()
|
119 |
{
|
120 |
CDialog::OnInitDialog();
|
121 |
|
122 |
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS);
|
123 |
checkouts->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
|
124 |
checkouts->InsertColumn(0,"Inits");
|
125 |
checkouts->InsertColumn(1,"Start date");
|
126 |
checkouts->InsertColumn(2,"Return date");
|
127 |
checkouts->InsertColumn(3,"Number of days");
|
128 |
checkouts->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
|
129 |
checkouts->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
|
130 |
checkouts->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
|
131 |
checkouts->SetColumnWidth(3,LVSCW_AUTOSIZE_USEHEADER);
|
132 |
|
133 |
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS);
|
134 |
reservations->SetExtendedStyle( LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT );
|
135 |
reservations->InsertColumn(0,"#");
|
136 |
reservations->InsertColumn(1,"Inits");
|
137 |
reservations->InsertColumn(2,"Reservation date");
|
138 |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER);
|
139 |
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER);
|
140 |
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER);
|
141 |
|
142 |
|
143 |
|
144 |
GetDlgItem(IDC_RESERVE)->EnableWindow(CommonStorage::Instance()->getAdmin());
|
145 |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(CommonStorage::Instance()->getAdmin());
|
146 |
GetDlgItem(IDC_RETURN)->EnableWindow(CommonStorage::Instance()->getAdmin());
|
147 |
|
148 |
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status;
|
149 |
|
150 |
if (status == "Ledig") {
|
151 |
GetDlgItem(IDC_RETURN)->EnableWindow(false);
|
152 |
GetDlgItem(IDC_RESERVE)->EnableWindow(false);
|
153 |
}
|
154 |
|
155 |
if (status == "Udlånt")
|
156 |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(false);
|
157 |
if (status == "Reserveret")
|
158 |
GetDlgItem(IDC_RETURN)->EnableWindow(false);
|
159 |
|
160 |
LoadData();
|
161 |
LoadListControls();
|
162 |
|
163 |
return TRUE;
|
164 |
}
|
165 |
|
166 |
/////////////////////////////////////////////
|
167 |
// a normal EditControl is prettier than a greyed out read-only
|
168 |
// So to simulate a read-only field, we reload the data every time the
|
169 |
// user tries to modify the data
|
170 |
void ResultDetailsDialog::OnEnChangeBarcode()
|
171 |
{
|
172 |
LoadData();
|
173 |
}
|
174 |
|
175 |
void ResultDetailsDialog::OnEnChangeName()
|
176 |
{
|
177 |
LoadData();
|
178 |
}
|
179 |
|
180 |
void ResultDetailsDialog::OnEnChangeDescription()
|
181 |
{
|
182 |
LoadData();
|
183 |
}
|
184 |
|
185 |
void ResultDetailsDialog::OnEnChangePlacement()
|
186 |
{
|
187 |
LoadData();
|
188 |
}
|
189 |
|
190 |
void ResultDetailsDialog::OnEnChangeStatus()
|
191 |
{
|
192 |
LoadData();
|
193 |
}
|
194 |
|
195 |
void ResultDetailsDialog::OnBnClickedClose()
|
196 |
{
|
197 |
OnOK();
|
198 |
}
|
199 |
|
200 |
//////////////////////////////////////////////////
|
201 |
|
202 |
void ResultDetailsDialog::OnBnClickedReturn()
|
203 |
{
|
204 |
CString barcode = CommonStorage::Instance()->getSearchResult()[m_resultIndex].barcode;
|
205 |
|
206 |
CommonStorage::Instance()->getDBLayer()->ReturnEquipment(barcode);
|
207 |
((SearchDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[0])->OnBnClickedSearch();
|
208 |
((ResultDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[1])->LoadResults();
|
209 |
OnOK();
|
210 |
}
|
211 |
|
212 |
void ResultDetailsDialog::OnBnClickedCheckout()
|
213 |
{
|
214 |
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status;
|
215 |
CheckoutDialog check;
|
216 |
|
217 |
check.m_checkoutMode = true;
|
218 |
|
219 |
|
220 |
Reservation topReservation;
|
221 |
if (status == "Reserveret") {
|
222 |
topReservation = CommonStorage::Instance()->getSearchResult()[m_resultIndex].reservations[0];
|
223 |
check.m_reservedTo = topReservation.inits;
|
224 |
}
|
225 |
|
226 |
if (check.DoModal() == IDOK)
|
227 |
{
|
228 |
DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer();
|
229 |
Person p = dblayer->GetPerson(check.m_inits);
|
230 |
|
231 |
Equipment eq;
|
232 |
GetDlgItem(IDC_BARCODE)->GetWindowText(eq.barcode);
|
233 |
|
234 |
dblayer->CheckoutEquipment(p, eq, atoi(check.m_numdays) );
|
235 |
|
236 |
if (status == "Reserveret") { //if the equipment was reserved, we must delete the reservation
|
237 |
dblayer->DeleteReservation(eq.barcode, topReservation.reservationID);
|
238 |
}
|
239 |
((SearchDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[0])->OnBnClickedSearch();
|
240 |
((ResultDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[1])->LoadResults();
|
241 |
OnOK();
|
242 |
}
|
243 |
}
|
244 |
|
245 |
void ResultDetailsDialog::OnBnClickedReserve()
|
246 |
{
|
247 |
CheckoutDialog check;
|
248 |
check.m_checkoutMode = false;
|
249 |
if (check.DoModal() == IDOK)
|
250 |
{
|
251 |
DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer();
|
252 |
Person p = dblayer->GetPerson(check.m_inits);
|
253 |
CString barcode;
|
254 |
GetDlgItem(IDC_BARCODE)->GetWindowText(barcode);
|
255 |
dblayer->EquipmentReservation(barcode,p);
|
256 |
|
257 |
((SearchDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[0])->OnBnClickedSearch();
|
258 |
((ResultDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[1])->LoadResults();
|
259 |
LoadListControls();
|
260 |
|
261 |
}
|
262 |
}
|
263 |
|
264 |
void ResultDetailsDialog::OnBnClickedDelres()
|
265 |
{
|
266 |
int sel = ((CListCtrl*)GetDlgItem(IDC_RESERVATIONS))->GetSelectionMark();
|
267 |
if (sel != -1) {
|
268 |
CString reservationID = CommonStorage::Instance()->getSearchResult()[m_resultIndex].reservations[sel].reservationID;
|
269 |
CString barcode = CommonStorage::Instance()->getSearchResult()[m_resultIndex].barcode;
|
270 |
CommonStorage::Instance()->getDBLayer()->DeleteReservation(barcode, reservationID);
|
271 |
((SearchDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[0])->OnBnClickedSearch();
|
272 |
((ResultDialog*)CommonStorage::Instance()->getTabCtrl()->m_tabs[1])->LoadResults();
|
273 |
LoadListControls();
|
274 |
} else {
|
275 |
MessageBox("No reservation is selected");
|
276 |
}
|
277 |
}
|