-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMembers.cpp
139 lines (125 loc) · 4.07 KB
/
Members.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
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: MEMBERS.CPP
** COMPONENT: The Application.
** DESCRIPTION: CMembers class definition.
**
*******************************************************************************
*/
#include "Common.hpp"
#include "Members.hpp"
#include <MDBL/ResultSet.hpp>
#include <MDBL/WhereCmp.hpp>
#include "Subs.hpp"
/******************************************************************************
** Method: Constructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CMembers::CMembers()
: CTable(TXT("Members"))
{
// Create the table schema.
AddColumn(TXT("ID"), MDCT_IDENTITY, 0, CColumn::IDENTITY);
AddColumn(TXT("Surname"), MDCT_FXDSTR, SURNAME_LEN, CColumn::DEFAULTS);
AddColumn(TXT("Forename"), MDCT_FXDSTR, FORENAME_LEN, CColumn::DEFAULTS);
AddColumn(TXT("PostalAddr"), MDCT_VARSTR, POSTAL_LEN, CColumn::DEFAULTS);
AddColumn(TXT("StdPhone"), MDCT_FXDSTR, PHONE_LEN, CColumn::DEFAULTS);
AddColumn(TXT("AltPhone"), MDCT_FXDSTR, PHONE_LEN, CColumn::DEFAULTS);
AddColumn(TXT("EmailAddr"), MDCT_FXDSTR, EMAIL_LEN, CColumn::DEFAULTS);
AddColumn(TXT("IsRegistered"), MDCT_BOOL, 0, CColumn::DEFAULTS);
AddColumn(TXT("IsSenior"), MDCT_BOOL, 0, CColumn::DEFAULTS);
AddColumn(TXT("UsualTeam"), MDCT_INT, 0, CColumn::DEFAULTS);
AddColumn(TXT("UsualPosition"), MDCT_INT, 0, CColumn::DEFAULTS);
AddColumn(TXT("IsAvailable"), MDCT_BOOL, 0, CColumn::DEFAULTS);
AddColumn(TXT("UnavailReason"), MDCT_INT, 0, CColumn::DEFAULTS);
AddColumn(TXT("Notes"), MDCT_VARSTR, NOTES_LEN, CColumn::DEFAULTS);
AddColumn(TXT("Balance"), MDCT_INT, 0, CColumn::DEFAULTS);
}
/******************************************************************************
** Method: Destructor.
**
** Description: .
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
CMembers::~CMembers()
{
}
/******************************************************************************
** Method: CreateRow()
**
** Description: Creates a new row and initialises it.
**
** Parameters: None.
**
** Returns: The new row.
**
*******************************************************************************
*/
CRow& CMembers::CreateRow()
{
CRow& oRow = CTable::CreateRow();
// oRow[ID] = 0;
oRow[SURNAME] = TXT("");
oRow[FORENAME] = TXT("");
oRow[POSTAL_ADDRESS] = TXT("");
oRow[STANDARD_PHONE] = TXT("");
oRow[ALTERNATE_PHONE] = TXT("");
oRow[EMAIL_ADDRESS] = TXT("");
oRow[IS_REGISTERED] = false;
oRow[IS_SENIOR] = false;
oRow[USUAL_TEAM] = 0;
oRow[USUAL_POSITION] = 0;
oRow[IS_AVAILABLE] = true;
oRow[UNAVAIL_REASON] = 0;
oRow[NOTES] = TXT("");
oRow[BALANCE] = 0;
return oRow;
}
/******************************************************************************
** Method: UpdateBalances()
**
** Description: Updates the balances for all members, if changed.
**
** Parameters: oSubs The members subs table.
** aoModified The vector used to return to the rows modified.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CMembers::UpdateBalances(CSubs& oSubs, RowList& aoModified)
{
// Clear the output vector.
aoModified.clear();
// For all members.
for (size_t i = 0; i < RowCount(); i++)
{
// Find all subs for the member.
CRow& oRow = Row(i);
CResultSet oRS = oSubs.Select(CWhereCmp(CSubs::MEMBER_ID, CWhereCmp::EQUALS, oRow[ID].ToValue()));
// Calculate the fees, paid and balance.
int nFees = oRS.Sum(CSubs::FEE ).m_iValue;
int nPaid = oRS.Sum(CSubs::PAID).m_iValue;
int nNewBal = nPaid - nFees;
int nCurBal = oRow[BALANCE];
// Modified?
if (nNewBal != nCurBal)
{
oRow[BALANCE] = nNewBal;
aoModified.push_back(&oRow);
}
}
}