/
SuggestSuspension.cpp
369 lines (320 loc) · 8.48 KB
/
SuggestSuspension.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
// SuggestSuspension.cpp : implementation file
//
#include "stdafx.h"
extern "C"{
#include "TMSHeader.h"
} // EXTERN C
#include "TMS.h"
#include "AddDialogs.h"
#include "AddDiscipline.h"
#include "Discipline.h"
#include "DisciplineLetter.h"
#include "SuggestSuspension.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSuggestSuspension dialog
CSuggestSuspension::CSuggestSuspension(CWnd* pParent /*=NULL*/, long* pDRIVERSrecordID, long* pStartDate)
: CDialog(CSuggestSuspension::IDD, pParent)
{
m_pStartDate = pStartDate;
m_pDRIVERSrecordID = pDRIVERSrecordID;
//{{AFX_DATA_INIT(CSuggestSuspension)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CSuggestSuspension::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSuggestSuspension)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSuggestSuspension, CDialog)
//{{AFX_MSG_MAP(CSuggestSuspension)
ON_WM_CLOSE()
ON_BN_CLICKED(IDHELP, OnHelp)
ON_NOTIFY(NM_DBLCLK, SUGGESTSUSPENSION_LIST, OnDblclkList)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSuggestSuspension message handlers
BOOL CSuggestSuspension::OnInitDialog()
{
CDialog::OnInitDialog();
//
// Set up pointers to the controls
//
pListCtrlLIST = (CListCtrl *)GetDlgItem(SUGGESTSUSPENSION_LIST);
DWORD dwExStyles = pListCtrlLIST->GetExtendedStyle();
pListCtrlLIST->SetExtendedStyle(dwExStyles | LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES | LVS_EX_INFOTIP);
//
// Show the hourgalss
//
HCURSOR hSaveCursor = SetCursor(hCursorWait);
//
// Set up the columns on the list control
//
//
// Set up the list controls
//
LVCOLUMN LVC;
LVC.mask = LVCF_FMT | LVCF_TEXT | LVCF_WIDTH;
LVC.cx = 120;
LVC.fmt = LVCFMT_CENTER;
LVC.pszText = "Date";
pListCtrlLIST->InsertColumn(0, &LVC);
LVC.cx = 60;
LVC.pszText = "Run #";
pListCtrlLIST->InsertColumn(1, &LVC);
LVC.cx = 60;
LVC.pszText = "On at";
pListCtrlLIST->InsertColumn(2, &LVC);
LVC.cx = 60;
LVC.pszText = "Off at";
pListCtrlLIST->InsertColumn(3, &LVC);
LVC.cx = 60;
LVC.pszText = "Pay";
pListCtrlLIST->InsertColumn(4, &LVC);
//
// Get his data from the roster
//
typedef struct RosterPayStruct
{
int num;
long RUNSrecordIDs[10];
long runNumber[10];
long onTime[10];
long offTime[10];
long payTime[10];
long flags[10];
} RosterPayDef;
RosterPayDef RD[7];
int nI, nJ;
for(nI = 0; nI < 7; nI++)
{
RD[nI].num = 0;
}
int rcode2;
ROSTERKey1.DIVISIONSrecordID = m_DivisionRecordID;
ROSTERKey1.rosterNumber = NO_RECORD;
rcode2 = btrieve(B_GETGREATER, TMS_ROSTER, &ROSTER, &ROSTERKey1, 1);
while(rcode2 == 0 &&
ROSTER.DIVISIONSrecordID == m_DivisionRecordID)
{
if(ROSTER.DRIVERSrecordID == *m_pDRIVERSrecordID)
{
for(nI = 0; nI < 7; nI++)
{
if(ROSTER.WEEK[m_RosterWeek].RUNSrecordIDs[nI] == NO_RECORD)
{
continue;
}
nJ = RD[nI].num;
RD[nI].RUNSrecordIDs[nJ] = ROSTER.WEEK[m_RosterWeek].RUNSrecordIDs[nI];
RD[nI].flags[nJ] = ROSTER.WEEK[m_RosterWeek].flags;
RD[nI].num++;
}
}
rcode2 = btrieve(B_GETNEXT, TMS_ROSTER, &ROSTER, &ROSTERKey1, 1);
}
//
// Fill up the rest of the structure with run details
//
PROPOSEDRUNDef PROPOSEDRUN;
COSTDef COST;
int numPieces;
for(nI = 0; nI < 7; nI++)
{
for(nJ = 0; nJ < RD[nI].num; nJ++)
{
RUNSKey0.recordID = RD[nI].RUNSrecordIDs[nJ];
btrieve(B_GETEQUAL, TMS_RUNS, &RUNS, &RUNSKey0, 0);
btrieve(B_GETPOSITION, TMS_RUNS, &RUNS, &RUNSKey0, 0);
btrieve(B_GETDIRECT, TMS_RUNS, &RUNS, &RUNSKey1, 1);
RD[nI].runNumber[nJ] = RUNS.runNumber;
numPieces = GetRunElements(hWndMain, &RUNS, &PROPOSEDRUN, &COST, TRUE);
RD[nI].onTime[nJ] = RUNSVIEW[0].runOnTime;
RD[nI].offTime[nJ] = RUNSVIEW[numPieces - 1].runOffTime;
RD[nI].payTime[nJ] = COST.TOTAL.payTime;
}
}
//
// Start with today
//
long yyyy, mm, dd;
int indexToRoster[7] = {6, 0, 1, 2, 3, 4, 5};
CTime firstDay = CTime::GetCurrentTime();
long day = firstDay.GetDay();
long month = firstDay.GetMonth();
long year = firstDay.GetYear();
long fDay = year * 10000 + month * 100 + day;
//
// End with the "until date" on this pick
//
GetYMD(untilDate, &yyyy, &mm, &dd);
CTime lastDay(yyyy, mm, dd, 0, 0, 0);
//
// Go through the assignments for each day
//
CTime currentDate = firstDay;
currentDate -= CTimeSpan(1, 0, 0, 0);
//
// Display up until the untilDate
//
LVITEM LVI;
int iItem;
CString s;
int today;
for(;;)
{
currentDate += CTimeSpan(1, 0, 0, 0);
day = currentDate.GetDay();
month = currentDate.GetMonth();
year = currentDate.GetYear();
LVI.lParam = year * 10000 + month * 100 + day;
if(LVI.lParam > untilDate)
{
break;
}
today = indexToRoster[currentDate.GetDayOfWeek() - 1];
s = currentDate.Format(_T("%d-%b-%Y (%a)"));
//
// Cycle through the number of Roster entries for today (typically 1)
//
for(nI = 0; nI < RD[today].num; nI++)
{
//
// Output the date
//
strcpy(tempString, s);
if(IsHeAwayToday(LVI.lParam))
{
strcat(tempString, " *");
}
iItem = pListCtrlLIST->GetItemCount();
LVI.mask = LVIF_TEXT | LVIF_PARAM;
LVI.iItem = iItem;
LVI.iSubItem = 0;
LVI.pszText = tempString;
LVI.iItem = pListCtrlLIST->InsertItem(&LVI);
//
// Run number
//
sprintf(tempString, "%ld", RD[today].runNumber[nI]);
LVI.mask = LVIF_TEXT;
LVI.iItem = iItem;
LVI.iSubItem = 1;
LVI.pszText = tempString;
LVI.iItem = pListCtrlLIST->SetItem(&LVI);
//
// On time
//
strcpy(tempString, Tchar(RD[today].onTime[nI]));
LVI.mask = LVIF_TEXT;
LVI.iItem = iItem;
LVI.iSubItem = 2;
LVI.pszText = tempString;
LVI.iItem = pListCtrlLIST->SetItem(&LVI);
//
// Off time
//
strcpy(tempString, Tchar(RD[today].offTime[nI]));
LVI.mask = LVIF_TEXT;
LVI.iItem = iItem;
LVI.iSubItem = 3;
LVI.pszText = tempString;
LVI.iItem = pListCtrlLIST->SetItem(&LVI);
//
// Pay time
//
strcpy(tempString, chhmm(RD[today].payTime[nI]));
LVI.mask = LVIF_TEXT;
LVI.iItem = iItem;
LVI.iSubItem = 4;
LVI.pszText = tempString;
LVI.iItem = pListCtrlLIST->SetItem(&LVI);
}
}
//
// Restore the cursor
//
SetCursor(hSaveCursor);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSuggestSuspension::OnClose()
{
OnCancel();
}
void CSuggestSuspension::OnCancel()
{
// TODO: Add extra cleanup here
CDialog::OnCancel();
}
void CSuggestSuspension::OnHelp()
{
// TODO: Add your control notification handler code here
}
void CSuggestSuspension::OnOK()
{
int nI = pListCtrlLIST->GetNextItem(-1, LVNI_ALL | LVNI_SELECTED);
if(nI < 0)
{
return;
}
LVITEM LVI;
LVI.mask = LVIF_PARAM;
LVI.iItem = nI;
LVI.iSubItem = 0;
pListCtrlLIST->GetItem(&LVI);
*m_pStartDate = LVI.lParam;
CDialog::OnOK();
}
void CSuggestSuspension::OnDblclkList(NMHDR* pNMHDR, LRESULT* pResult)
{
*pResult = 0;
OnOK();
}
BOOL CSuggestSuspension::IsHeAwayToday(long date)
{
//
// See if he's away for a regularly scheduled date, or portion thereof
//
CTime time = CTime::GetCurrentTime();
long day = time.GetDay();
long month = time.GetMonth();
long year = time.GetYear();
int rcode2;
DAILYOPSKey1.recordTypeFlag = DAILYOPS_FLAG_ABSENCE;
DAILYOPSKey1.pertainsToDate = (year - 1) * 10000 + month * 100 + day;
DAILYOPSKey1.pertainsToTime = 0;
DAILYOPSKey1.recordFlags = 0;
rcode2 = btrieve(B_GETGREATER, TMS_DAILYOPS, &DAILYOPS, &DAILYOPSKey1, 1);
while(rcode2 == 0 &&
(DAILYOPS.pertainsToDate <= date) &&
(DAILYOPS.recordTypeFlag & DAILYOPS_FLAG_ABSENCE))
{
//
// Examine just those records with the date in question
//
if(DAILYOPS.DRIVERSrecordID == *m_pDRIVERSrecordID &&
date >= DAILYOPS.pertainsToDate &&
date <= DAILYOPS.DOPS.Absence.untilDate &&
(DAILYOPS.recordFlags & DAILYOPS_FLAG_ABSENCEREGISTER))
{
if(!ANegatedRecord(DAILYOPS.recordID, 1))
{
return(TRUE);
}
}
rcode2 = btrieve(B_GETPREVIOUS, TMS_DAILYOPS, &DAILYOPS, &DAILYOPSKey1, 1);
}
//
// All done
//
return(FALSE);
}