1 |
// ResultDetailsDialog.cpp : implementation file |
/* |
2 |
// |
* Developed by Torben H. Nielsen |
3 |
|
*/ |
4 |
|
|
5 |
|
|
6 |
#include "stdafx.h" |
#include "stdafx.h" |
7 |
#include "h6-udlånssystem.h" |
#include "h6-udlånssystem.h" |
8 |
#include "ResultDetailsDialog.h" |
#include "ResultDetailsDialog.h" |
9 |
#include ".\resultdetailsdialog.h" |
#include ".\resultdetailsdialog.h" |
10 |
#include "CommonStorage.h" |
#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 |
// ResultDetailsDialog dialog |
18 |
|
|
40 |
ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement) |
ON_EN_CHANGE(IDC_PLACEMENT, OnEnChangePlacement) |
41 |
ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus) |
ON_EN_CHANGE(IDC_STATUS, OnEnChangeStatus) |
42 |
ON_BN_CLICKED(IDC_CLOSE, OnBnClickedClose) |
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() |
END_MESSAGE_MAP() |
48 |
|
|
49 |
|
|
54 |
if (m_loadingData == true) |
if (m_loadingData == true) |
55 |
return; |
return; |
56 |
m_loadingData = true; |
m_loadingData = true; |
|
Equipment currentdata = CommonStorage::Instance()->getSearchResult()[m_resultIndex]; |
|
57 |
|
|
58 |
GetDlgItem(IDC_BARCODE)->SetWindowText(currentdata.barcode); |
GetDlgItem(IDC_BARCODE)->SetWindowText(m_equipment.barcode); |
59 |
GetDlgItem(IDC_NAME)->SetWindowText(currentdata.name); |
GetDlgItem(IDC_NAME)->SetWindowText(m_equipment.name); |
60 |
GetDlgItem(IDC_DESCRIPTION)->SetWindowText(currentdata.description); |
GetDlgItem(IDC_DESCRIPTION)->SetWindowText(m_equipment.description); |
61 |
GetDlgItem(IDC_PLACEMENT)->SetWindowText(currentdata.placement); |
GetDlgItem(IDC_PLACEMENT)->SetWindowText(m_equipment.placement); |
62 |
GetDlgItem(IDC_STATUS)->SetWindowText(currentdata.status); |
GetDlgItem(IDC_STATUS)->SetWindowText(m_equipment.status); |
63 |
|
|
64 |
m_loadingData = false; |
m_loadingData = false; |
65 |
} |
} |
67 |
void ResultDetailsDialog::LoadListControls(void) |
void ResultDetailsDialog::LoadListControls(void) |
68 |
{ |
{ |
69 |
if (CommonStorage::Instance()->getAdmin() ) { |
if (CommonStorage::Instance()->getAdmin() ) { |
|
Equipment currentdata = CommonStorage::Instance()->getSearchResult()[m_resultIndex]; |
|
70 |
|
|
71 |
//load Equipment::checkouts |
//load Equipment::checkouts |
72 |
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS); |
CListCtrl *checkouts = (CListCtrl*) GetDlgItem(IDC_CHECKOUTS); |
73 |
checkouts->InsertColumn(0,"Inits"); |
checkouts->DeleteAllItems(); |
|
checkouts->InsertColumn(1,"Start date"); |
|
|
checkouts->InsertColumn(2,"Return date"); |
|
|
checkouts->InsertColumn(3,"Number of days"); |
|
74 |
|
|
75 |
for (int i=0; i<currentdata.checkouts.size(); i++) { |
for (int i=0; i<m_equipment.checkouts.size(); i++) { |
76 |
int nItem = checkouts->InsertItem(i,currentdata.checkouts[i].inits); |
int nItem = checkouts->InsertItem(i, m_equipment.checkouts[i].inits); |
77 |
checkouts->SetItemText(nItem,1,currentdata.checkouts[i].startdate); |
checkouts->SetItemText(nItem,1, m_equipment.checkouts[i].startdate); |
78 |
checkouts->SetItemText(nItem,2,currentdata.checkouts[i].enddate); |
checkouts->SetItemText(nItem,2, m_equipment.checkouts[i].enddate); |
79 |
checkouts->SetItemText(nItem,3,currentdata.checkouts[i].numdays); |
checkouts->SetItemText(nItem,3, m_equipment.checkouts[i].numdays); |
80 |
} |
} |
81 |
checkouts->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
checkouts->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
82 |
checkouts->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
checkouts->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
85 |
|
|
86 |
// load Equipment::reservations |
// load Equipment::reservations |
87 |
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS); |
CListCtrl *reservations = (CListCtrl*) GetDlgItem(IDC_RESERVATIONS); |
88 |
reservations->InsertColumn(0,"Inits"); |
reservations->DeleteAllItems(); |
89 |
reservations->InsertColumn(1,"Start date"); |
|
90 |
reservations->InsertColumn(2,"Number of days"); |
|
91 |
|
for (int i=0; i<m_equipment.reservations.size(); i++) { |
92 |
for (int i=0; i<currentdata.reservations.size(); i++) { |
CString tmp; |
93 |
int nItem = reservations->InsertItem(i, currentdata.reservations[i].inits); |
tmp.Format("%d", i+1); |
94 |
reservations->SetItemText(nItem,1, currentdata.reservations[i].startdate); |
int nItem = reservations->InsertItem(i, tmp); |
95 |
reservations->SetItemText(nItem,2, currentdata.reservations[i].numdays); |
reservations->SetItemText(nItem, 1, m_equipment.reservations[i].inits); |
96 |
|
reservations->SetItemText(nItem, 2, m_equipment.reservations[i].startdate); |
97 |
|
|
98 |
} |
} |
99 |
|
|
100 |
|
if (m_equipment.reservations.size() > 0) |
101 |
|
GetDlgItem(IDC_DELRES)->EnableWindow(true); |
102 |
|
|
103 |
|
|
104 |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(0,LVSCW_AUTOSIZE_USEHEADER); |
105 |
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(1,LVSCW_AUTOSIZE_USEHEADER); |
106 |
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); |
reservations->SetColumnWidth(2,LVSCW_AUTOSIZE_USEHEADER); |
117 |
{ |
{ |
118 |
CDialog::OnInitDialog(); |
CDialog::OnInitDialog(); |
119 |
|
|
120 |
|
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 |
GetDlgItem(IDC_RESERVE)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
GetDlgItem(IDC_RESERVE)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
143 |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
144 |
GetDlgItem(IDC_RETURN)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
GetDlgItem(IDC_RETURN)->EnableWindow(CommonStorage::Instance()->getAdmin()); |
145 |
|
|
146 |
CString status = CommonStorage::Instance()->getSearchResult()[m_resultIndex].status; |
m_equipment = CommonStorage::Instance()->getDBLayer()->GetEquipment(m_barcode); |
|
|
|
|
if (status == "Ledig") |
|
|
GetDlgItem(IDC_RETURN)->EnableWindow(false); |
|
|
if (status == "Udlånt") |
|
|
GetDlgItem(IDC_CHECKOUT)->EnableWindow(false); |
|
|
if (status == "Reserveret") |
|
|
GetDlgItem(IDC_RETURN)->EnableWindow(false); |
|
147 |
|
|
148 |
|
|
149 |
|
EnableControls(); |
150 |
LoadData(); |
LoadData(); |
151 |
LoadListControls(); |
LoadListControls(); |
152 |
|
|
153 |
return TRUE; |
return TRUE; |
154 |
} |
} |
155 |
|
|
156 |
|
///////////////////////////////////////////// |
157 |
|
// 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 |
void ResultDetailsDialog::OnEnChangeBarcode() |
void ResultDetailsDialog::OnEnChangeBarcode() |
161 |
{ |
{ |
162 |
LoadData(); |
LoadData(); |
177 |
LoadData(); |
LoadData(); |
178 |
} |
} |
179 |
|
|
|
|
|
|
|
|
180 |
void ResultDetailsDialog::OnEnChangeStatus() |
void ResultDetailsDialog::OnEnChangeStatus() |
181 |
{ |
{ |
182 |
LoadData(); |
LoadData(); |
183 |
} |
} |
184 |
|
|
|
|
|
185 |
void ResultDetailsDialog::OnBnClickedClose() |
void ResultDetailsDialog::OnBnClickedClose() |
186 |
{ |
{ |
187 |
OnOK(); |
OnOK(); |
188 |
} |
} |
189 |
|
|
190 |
|
////////////////////////////////////////////////// |
191 |
|
|
192 |
|
void ResultDetailsDialog::OnBnClickedReturn() |
193 |
|
{ |
194 |
|
|
195 |
|
DatabaseLayer *dblayer = CommonStorage::Instance()->getDBLayer(); |
196 |
|
dblayer->ReturnEquipment(m_barcode); |
197 |
|
this->ReloadData(); |
198 |
|
} |
199 |
|
|
200 |
|
void ResultDetailsDialog::OnBnClickedCheckout() |
201 |
|
{ |
202 |
|
CheckoutDialog check; |
203 |
|
|
204 |
|
check.m_checkoutMode = true; |
205 |
|
|
206 |
|
Reservation topReservation; |
207 |
|
if (m_equipment.status == "Reserveret") { |
208 |
|
|
209 |
|
topReservation = m_equipment.reservations[0]; |
210 |
|
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 |
|
|
221 |
|
dblayer->CheckoutEquipment(p, eq, atoi(check.m_numdays) ); |
222 |
|
|
223 |
|
if (m_equipment.status == "Reserveret") { //if the equipment was reserved, we must delete the reservation |
224 |
|
dblayer->DeleteReservation(eq.barcode, topReservation.reservationID); |
225 |
|
} |
226 |
|
this->ReloadData(); |
227 |
|
} |
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 |
|
|
242 |
|
this->ReloadData(); |
243 |
|
} |
244 |
|
} |
245 |
|
|
246 |
|
void ResultDetailsDialog::OnBnClickedDelres() |
247 |
|
{ |
248 |
|
int sel = ((CListCtrl*)GetDlgItem(IDC_RESERVATIONS))->GetSelectionMark(); |
249 |
|
if (sel != -1) { |
250 |
|
CString reservationID = m_equipment.reservations[sel].reservationID; |
251 |
|
CString barcode = m_equipment.barcode; |
252 |
|
CommonStorage::Instance()->getDBLayer()->DeleteReservation(barcode, reservationID); |
253 |
|
this->ReloadData(); |
254 |
|
|
255 |
|
} else { |
256 |
|
MessageBox("No reservation is selected"); |
257 |
|
} |
258 |
|
} |
259 |
|
|
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 |
|
if (m_equipment.status == "Ledig") { |
275 |
|
GetDlgItem(IDC_CHECKOUT)->EnableWindow(true); |
276 |
|
GetDlgItem(IDC_RETURN)->EnableWindow(false); |
277 |
|
GetDlgItem(IDC_RESERVE)->EnableWindow(false); |
278 |
|
} else if (m_equipment.status == "Udlånt") { |
279 |
|
GetDlgItem(IDC_CHECKOUT)->EnableWindow(false); |
280 |
|
GetDlgItem(IDC_RETURN)->EnableWindow(true); |
281 |
|
GetDlgItem(IDC_RESERVE)->EnableWindow(true); |
282 |
|
} else { //m_equipment.status == "Reserveret" |
283 |
|
GetDlgItem(IDC_CHECKOUT)->EnableWindow(true); |
284 |
|
GetDlgItem(IDC_RETURN)->EnableWindow(false); |
285 |
|
GetDlgItem(IDC_RESERVE)->EnableWindow(true); |
286 |
|
} |
287 |
|
} |
288 |
|
} |