-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDateBasedData.cpp
132 lines (113 loc) · 3.62 KB
/
DateBasedData.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
#include "stdafx.h"
#include "DateBasedData.h"
CDateBasedData::CDateBasedData(void)
{
pItemList = new CObList();
SetEnabled(true);
}
CDateBasedData::~CDateBasedData(void)
{
ClearAll();
delete pItemList;
}
bool CDateBasedData::GetItem(int Index, DBD_ITEM& theItem)
{
bool Success = false;
if ((Index >=0) && (Index < GetCount()))
{
DBD_ITEM* pItem = (DBD_ITEM*)pItemList->GetAt(pItemList->FindIndex(Index));
theItem = *pItem; // Default assignment - requires ITEMs be made up of simple types.
Success = true;
}
return Success;
}
DBD_ITEM* CDateBasedData::GetItemPtr(int Index)
{
if (Index >= pItemList->GetCount()) return NULL;
else return (DBD_ITEM*)pItemList->GetAt(pItemList->FindIndex(Index));
}
bool CDateBasedData::GetActiveItem(COleDateTime theDate, DBD_ITEM& theItem)
{
// Needs to be rewritten - what is an active item for a Pesticide Event? Need to define. Do we even use this?
// theItem is filled with the contents of the first list item where theDate is between the DR_ITEM start date and end date,
// and the function return value is TRUE. If theDate does not fall between the date range in any
// list item, the return value is FALSE.
bool Success = false;
//DR_ITEM* pListItem;
//POSITION pos = pItemList->GetHeadPosition();
//while (pos != NULL)
//{
// pListItem = (DR_ITEM*)pItemList->GetNext(pos);
//
// COleDateTimeSpan TimeSinceStart = (COleDateTimeSpan)(theDate - pListItem->StartTime);
// COleDateTimeSpan TimeTillEnd = (COleDateTimeSpan)(pListItem->EndTime - theDate);
//
// int month = theDate.GetMonth();
// int day = theDate.GetDay();
// int year = theDate.GetYear();
//
// if ((month >= 3) && (day >= 2) && (year == 1999))
// {
// int i = 0;
//
// }
//
//
// if ((TimeSinceStart.GetDays() >= 0) && (TimeTillEnd.GetDays() >= 0))
// {
// theItem.EndTime = pListItem->EndTime;
// theItem.StartTime = pListItem->StartTime;
// theItem.Value = pListItem->Value;
// Success = true;
// break;
// }
// }
return Success;
}
void CDateBasedData::AddItem(DBD_ITEM& theItem)
{
DBD_ITEM* pItem = new DBD_ITEM();
//pItem->EndTime = theItem.EndTime;
//pItem->StartTime = theItem.StartTime;
//pItem->Value = theItem.Value;
pItemList->AddTail((CObject*)pItem);
}
void CDateBasedData::DeleteItem(int Index)
{
if (Index <0) return;
POSITION pos = pItemList->FindIndex(Index);
if (pos != NULL) // Validate that Index is valid
{
delete(DBD_ITEM*)(pItemList->GetAt(pos)); // Deletes the item
pItemList->RemoveAt(pos); // Removed item pointer from list
}
}
int CDateBasedData::GetCount()
{
if (!pItemList) return 0;
else return pItemList->GetCount();
}
void CDateBasedData::ClearAll()
{
DBD_ITEM* pItem;
if (pItemList != NULL)
{
while (pItemList->GetCount() > 0)
{
pItem = (DBD_ITEM*)pItemList->RemoveTail();
delete(pItem);
}
}
}
void CDateBasedData::Copy(CDateBasedData* pDestination)
{
if (pDestination == NULL) return;
pDestination->ClearAll();
DBD_ITEM theItem;
for (int i = 0; i < GetCount(); i++)
{
GetItem(i, theItem);
pDestination->AddItem(theItem);
}
pDestination->SetEnabled(IsEnabled());
}