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 |
|
58 |
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 |
|
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 |
checkouts->DeleteAllItems();
|
74 |
|
75 |
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 |
}
|
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 |
reservations->DeleteAllItems();
|
89 |
|
90 |
|
91 |
for (int i=0; i<m_equipment.reservations.size(); i++) {
|
92 |
CString tmp;
|
93 |
tmp.Format("%d", i+1);
|
94 |
int nItem = reservations->InsertItem(i, tmp);
|
95 |
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);
|
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 |
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());
|
143 |
GetDlgItem(IDC_CHECKOUT)->EnableWindow(CommonStorage::Instance()->getAdmin());
|
144 |
GetDlgItem(IDC_RETURN)->EnableWindow(CommonStorage::Instance()->getAdmin());
|
145 |
|
146 |
m_equipment = CommonStorage::Instance()->getDBLayer()->GetEquipment(m_barcode);
|
147 |
|
148 |
|
149 |
EnableControls();
|
150 |
LoadData();
|
151 |
LoadListControls();
|
152 |
|
153 |
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()
|
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 |
|
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 |
}
|