-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExpenseItemDlg.cpp
152 lines (131 loc) · 3.49 KB
/
ExpenseItemDlg.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
/******************************************************************************
** (C) Chris Oldwood
**
** MODULE: EXPENSEITEMDLG.CPP
** COMPONENT: The Application.
** DESCRIPTION: CExpenseItemDlg class definition.
**
*******************************************************************************
*/
#include "Common.hpp"
#include "ExpenseItemDlg.hpp"
#include "ExpenseTypes.hpp"
#include "Expenses.hpp"
/******************************************************************************
** Method: Constructor.
**
** Description: .
**
** Parameters: oTypes The expense types table.
** oRow The subs table row.
** bEditing Editing or creating row?
**
** Returns: Nothing.
**
*******************************************************************************
*/
CExpenseItemDlg::CExpenseItemDlg(CExpenseTypes& oTypes, CRow& oRow, bool bEditing)
: CDialog(IDD_EXPENSE_ITEM)
, m_oRow(oRow)
, m_bEditing(bEditing)
, m_ebPaid(false, 6, 2)
, m_oTypes(oTypes)
{
DEFINE_CTRL_TABLE
CTRL(IDC_EXPENSES, &m_cbTypes)
CTRL(IDC_PAID, &m_ebPaid)
END_CTRL_TABLE
DEFINE_CTRLMSG_TABLE
CMD_CTRLMSG(IDC_EXPENSES, LBN_SELCHANGE, &CExpenseItemDlg::OnSelectType)
END_CTRLMSG_TABLE
}
/******************************************************************************
** Method: OnInitDialog()
**
** Description: Initialise the dialog.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CExpenseItemDlg::OnInitDialog()
{
// Set the dialog title.
Title((m_bEditing == true) ? TXT("Edit Expense") : TXT("Add An Expense"));
// Adding an entry?
if (!m_bEditing)
{
// Load types into combo box.
for (size_t i = 0; i < m_oTypes.RowCount(); i++)
{
CRow& oRow = m_oTypes[i];
// Add to the combo box.
int n = m_cbTypes.Add(oRow[CExpenseTypes::NAME]);
m_cbTypes.ItemData(n, i);
}
}
// Editing entry.
else
{
// Find type details.
int nType = m_oRow[CExpenses::TYPE_ID];
CRow* pType = m_oTypes.SelectRow(CExpenseTypes::ID, nType);
ASSERT(pType != NULL);
// Add to the combo box.
m_cbTypes.Add((*pType)[CExpenseTypes::NAME]);
}
// Default to first member.
m_cbTypes.CurSel(0U);
m_cbTypes.Enable(!m_bEditing);
// Initialise the paid field.
if (m_bEditing)
m_ebPaid.RealValue(m_oRow[CExpenses::PAID].GetInt() / 100.0);
else
OnSelectType();
}
/******************************************************************************
** Method: OnOk()
**
** Description: Validate the data and close the dialog.
**
** Parameters: None.
**
** Returns: true or false.
**
*******************************************************************************
*/
bool CExpenseItemDlg::OnOk()
{
// Fetch field data.
int nRow = m_cbTypes.ItemData(m_cbTypes.CurSel());
int nPaid = static_cast<int>(m_ebPaid.RealValue() * 100.0);
// Save type, if not editing.
if (!m_bEditing)
m_oRow[CExpenses::TYPE_ID] = m_oTypes[nRow][CExpenseTypes::ID];
m_oRow[CExpenses::PAID] = nPaid;
return true;
}
/******************************************************************************
** Method: OnSelectType()
**
** Description: Expense type selected.
**
** Parameters: None.
**
** Returns: Nothing.
**
*******************************************************************************
*/
void CExpenseItemDlg::OnSelectType()
{
// Only if a new entry.
if (!m_bEditing)
{
int nRow = m_cbTypes.ItemData(m_cbTypes.CurSel());
int nDefault = m_oTypes[nRow][CExpenseTypes::DEFAULT];
// Set the default value.
m_ebPaid.RealValue(nDefault / 100.0);
}
}