-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui_dailyreport.cpp
423 lines (382 loc) · 12.7 KB
/
ui_dailyreport.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
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
#include "ui_dailyreport.h"
#include "m8cash.h"
#include "ui_calendar.h"
#include <cMzCommon.h>
using namespace cMzCommon;
#define MZ_IDC_TOOLBAR_ABOUT 101
#define MZ_IDC_CAPTION_DATE 102
#define MZ_IDC_BUTTON_PRE_DATE 103
#define MZ_IDC_BUTTON_NEXT_DATE 104
#define MZ_IDC_LIST 105
void DailyRecordList::DrawItem(HDC hdcDst, int nIndex, RECT* prcItem, RECT *prcWin, RECT *prcUpdate) {
// draw the text
if(idlist == 0) return;
// draw the high-light background for the selected item
if (nIndex == GetSelectedIndex()) {
MzDrawSelectedBg(hdcDst, prcItem);
}
wchar_t str[128];
COLORREF cr = RGB(128,128,128);
HFONT hf;
RECT rcText = *prcItem;
RECT RectText;
int lineHeight = rcText.bottom - rcText.top;
lineHeight /= 2;
CASH_TRANSACT_t rec;
if(!cash_db.recordById(idlist[nIndex],&rec)) return;
CASH_CATEGORY_ptr cat = cash_db.categoryById(rec.categoryid);
CASH_ACCOUNT_ptr acnt = cash_db.accountById(rec.accountid);
CASH_ACCOUNT_ptr toacnt = 0;
if(cat->type == CT_TRANSFER){
toacnt = cash_db.accountById(rec.toaccountid);
}
::SetTextColor( hdcDst , cr );
hf = FontHelper::GetFont( 17 );
SelectObject( hdcDst , hf );
CMzString cmzs;
//第一行第一列
cmzs = L"[";
cmzs = cmzs + cat->name + L"]";
if(rec.isTransfer){
wsprintf(str,L" [%s]→[%s]",acnt->name,toacnt->name);
}else{
wsprintf(str,L" [%s]",acnt->name);
}
cmzs = cmzs + str;
RectText.left = rcText.left + 10;
RectText.top = rcText.top;
RectText.right = rcText.right - 200;
RectText.bottom = rcText.top + lineHeight;
MzDrawText( hdcDst , cmzs.C_Str(), &RectText , DT_LEFT|DT_SINGLELINE|DT_VCENTER|DT_END_ELLIPSIS );
//第二行第一列
RectText.left = rcText.left + 10;
RectText.top = rcText.top + lineHeight;
RectText.right = rcText.right - 200;
RectText.bottom = rcText.bottom;
MzDrawText( hdcDst , rec.note, &RectText , DT_LEFT|DT_SINGLELINE|DT_VCENTER|DT_END_ELLIPSIS );
//金额
wsprintf(str,L"%.2f", (double)rec.amount/100);
if(cat->type == CT_INCOME){
cr = RGB(64,128,64);
}else if(cat->type == CT_OUTGOING){
cr = RGB(128,64,64);
}else{
cr = RGB(64,64,128);
}
::SetTextColor( hdcDst , cr );
hf = FontHelper::GetFont( 25 );
SelectObject( hdcDst , hf );
//第一行第二列
RectText.top = rcText.top;
RectText.bottom = rcText.bottom;
RectText.left = rcText.right - 200;
RectText.right = rcText.right - 20;
MzDrawText( hdcDst , str, &RectText , DT_RIGHT|DT_SINGLELINE|DT_VCENTER );
DeleteObject( hf );
}
MZ_IMPLEMENT_DYNAMIC(Ui_DailyReportWnd);
Ui_DailyReportWnd::Ui_DailyReportWnd(void)
{
_seletedIndex = 0;
idarray = 0;
}
Ui_DailyReportWnd::~Ui_DailyReportWnd(void)
{
}
void Ui_DailyReportWnd::setDetailIndex(int i) {
_seletedIndex = i;
CASH_TRANSACT_t r;
if(!cash_db.recordById(_seletedIndex,&r)) return;
t = DateTime::StrToDate(r.date);
}
BOOL Ui_DailyReportWnd::OnInitDialog() {
// Must all the Init of parent class first!
if (!CMzWndEx::OnInitDialog()) {
return FALSE;
}
// Then init the controls & other things in the window
int y = 0;
//日期
m_CaptionDate.SetPos(0, y, GetWidth(), USER_DEF_HEIGHT + 20);
m_CaptionDate.SetID(MZ_IDC_CAPTION_DATE);
m_CaptionDate.EnableNotifyMessage(true);
AddUiWin(&m_CaptionDate);
int bw = pimg[IDB_PNG_L_RRELEASE - IDB_PNG_CALC]->GetImageWidth();
int bh = pimg[IDB_PNG_L_RRELEASE - IDB_PNG_CALC]->GetImageHeight();
m_BtnLeft.SetPos(5, (m_CaptionDate.GetHeight() - bh)/2, bw, bh);
m_BtnLeft.SetImage_Normal(pimg[IDB_PNG_L_LRELEASE - IDB_PNG_CALC]);
m_BtnLeft.SetImage_Pressed(pimg[IDB_PNG_L_LPRESS - IDB_PNG_CALC]);
m_BtnLeft.SetID(MZ_IDC_BUTTON_PRE_DATE);
m_CaptionDate.AddChild(&m_BtnLeft);
m_BtnRight.SetPos(m_CaptionDate.GetWidth() - bw, (m_CaptionDate.GetHeight() - bh)/2, bw, bh);
m_BtnRight.SetImage_Normal(pimg[IDB_PNG_L_RRELEASE - IDB_PNG_CALC]);
m_BtnRight.SetImage_Pressed(pimg[IDB_PNG_L_RPRESS - IDB_PNG_CALC]);
m_BtnRight.SetID(MZ_IDC_BUTTON_NEXT_DATE);
m_CaptionDate.AddChild(&m_BtnRight);
y += USER_DEF_HEIGHT + 20;
//内容
m_TextStatics.SetPos(0, y, GetWidth(), MZM_HEIGHT_SINGLELINE_EDIT);
m_TextStatics.SetTextSize(20);
m_TextStatics.SetEnable(false);
AddUiWin(&m_TextStatics);
y += MZM_HEIGHT_SINGLELINE_EDIT;
m_CaptionList.SetPos(0, y, GetWidth(), MZM_HEIGHT_HEADINGBAR);
m_CaptionList.SetText(LOADSTRING(IDS_STR_TRANS_LIST).C_Str());
AddUiWin(&m_CaptionList);
y += MZM_HEIGHT_HEADINGBAR;
m_ListDetail.SetPos(0, y, GetWidth(), GetHeight() - y - USER_DEF_HEIGHT/2 - MZM_HEIGHT_SINGLELINE_EDIT*3 - MZM_HEIGHT_TEXT_TOOLBAR);
m_ListDetail.SetItemHeight(60);
m_ListDetail.SetID(MZ_IDC_LIST);
m_ListDetail.EnableNotifyMessage(true);
AddUiWin(&m_ListDetail);
y += m_ListDetail.GetHeight();
m_CaptionDetail.SetPos(0, y, GetWidth(), MZM_HEIGHT_HEADINGBAR);
m_CaptionDetail.SetText(LOADSTRING(IDS_STR_TRANS_DETAIL).C_Str());
AddUiWin(&m_CaptionDetail);
y += MZM_HEIGHT_HEADINGBAR;
m_TextDetail.SetPos(0, y, GetWidth(), MZM_HEIGHT_SINGLELINE_EDIT*3);
m_TextDetail.SetEnable(false);
AddUiWin(&m_TextDetail);
m_Toolbar.SetPos(0, GetHeight() - MZM_HEIGHT_TEXT_TOOLBAR, GetWidth(), MZM_HEIGHT_TEXT_TOOLBAR);
m_Toolbar.SetButton(0, true, true, LOADSTRING(IDS_STR_RETURN).C_Str());
m_Toolbar.EnableLeftArrow(true);
m_Toolbar.SetID(MZ_IDC_TOOLBAR_ABOUT);
AddUiWin(&m_Toolbar);
updateDetail();
return TRUE;
}
UINT weekdayID[] = {
IDS_STR_WEEKDAY_NAME1,IDS_STR_WEEKDAY_NAME2,
IDS_STR_WEEKDAY_NAME3,IDS_STR_WEEKDAY_NAME4,
IDS_STR_WEEKDAY_NAME5,IDS_STR_WEEKDAY_NAME6,
IDS_STR_WEEKDAY_NAME0
};
void Ui_DailyReportWnd::updateDetail(){
wchar_t s[128];
CMzString cmzs;
wsprintf(s,LOADSTRING(IDS_STR_YYYYMMDD).C_Str(),t.wYear,t.wMonth,t.wDay);
cmzs = s;
cmzs = cmzs + L"[";
cmzs = cmzs + LOADSTRING(weekdayID[ DateTime::getWeekDay(t.wYear,t.wMonth,t.wDay)]);
cmzs = cmzs + L"]";
m_CaptionDate.SetText(cmzs.C_Str());
//无数据的情况
m_TextStatics.SetText(LOADSTRING(IDS_STR_NO_TRANSACTION).C_Str());
m_ListDetail.RemoveAll();
m_ListDetail.SetVisible(false);
m_CaptionList.SetVisible(false);
m_CaptionDetail.SetVisible(false);
m_TextDetail.SetVisible(false);
RECORDATE_t date;
date.Year = t.wYear;
date.Month = t.wMonth;
date.Day = t.wDay;
if(cash_db.getTransactionsByDate(&date,&date)){
int sz = cash_db.list_search_record.size();
if(idarray){
delete idarray;
idarray = 0;
}
if(sz > 0){
idarray = new int[sz];
list<CASH_TRANSACT_ptr>::iterator i = cash_db.list_search_record.begin();
int cnt = 0;
double in = 0;
double out = 0;
for(; i != cash_db.list_search_record.end(); i++){
CASH_TRANSACT_ptr r = *i;
idarray[cnt++] = r->transid;
m_ListDetail.AddItem(ListItem());
CASH_CATEGORY_ptr c = cash_db.categoryById(r->categoryid);
if(c->type == CT_INCOME){
in += r->amount;
}else if(c->type == CT_OUTGOING){
out += r->amount;
}
}
m_ListDetail.setupList(idarray);
//今日收入,支出,盈余
wsprintf(s,LOADSTRING(IDS_STR_SUM_INEX).C_Str(),in/100,out/100,(in-out)/100);
cmzs = s;
m_TextStatics.SetText(cmzs.C_Str());
m_ListDetail.SetSelectedIndex(0);
updateDetailText();
m_ListDetail.SetVisible(true);
m_CaptionList.SetVisible(true);
m_CaptionDetail.SetVisible(true);
m_TextDetail.SetVisible(true);
}
}
m_CaptionList.Invalidate();
m_CaptionDetail.Invalidate();
m_CaptionDate.Invalidate();
m_TextStatics.Invalidate();
m_ListDetail.Invalidate();
}
void Ui_DailyReportWnd::updateDetailText(){
if(idarray == 0) {
m_TextDetail.SetText(L"");
m_TextDetail.Invalidate();
return;
}
int idx = m_ListDetail.GetSelectedIndex();
if(idx == -1){
m_TextDetail.SetTextSize(30);
m_TextDetail.SetText(LOADSTRING(IDS_STR_DAILY_TIP).C_Str());
m_TextDetail.Invalidate();
return;
}
CASH_TRANSACT_t rec;
if(!cash_db.recordById(idarray[idx],&rec)){
m_TextDetail.SetTextSize(30);
m_TextDetail.SetText(L"错误,不存在此记录");
m_TextDetail.Invalidate();
return;
}
CASH_CATEGORY_ptr c = cash_db.categoryById(rec.categoryid);
if(c == 0){
m_TextDetail.SetTextSize(30);
m_TextDetail.SetText(L"错误,不存在此记录的分类");
m_TextDetail.Invalidate();
return;
}
wchar_t s[256];
m_TextDetail.SetTextSize(20);
//类别
CMzString cmzs;
//此类别今日共收入/支出 xx
cmzs = LOADSTRING(IDS_STR_CATEGORY);
cmzs = cmzs + L" [" + cash_db.getCategoryFullNameById(rec.categoryid) + L"]";
if(rec.isTransfer){
cmzs = cmzs + L"\n";
}else{
cmzs = cmzs + (c->type == CT_INCOME ? LOADSTRING(IDS_STR_INCOME) : LOADSTRING(IDS_STR_EXPENSE));
cmzs = cmzs + L": ";
double amount = 0;
RECORDATE_t date;
date.Year = t.wYear;
date.Month = t.wMonth;
date.Day = t.wDay;
if(cash_db.getTransactionsByDate(&date,&date)){
list<CASH_TRANSACT_ptr>::iterator i = cash_db.list_search_record.begin();
for(; i != cash_db.list_search_record.end(); i++){
CASH_TRANSACT_ptr rs = *i;
if(rs->categoryid == rec.categoryid || cash_db.isChildCategory(rs->categoryid,rec.categoryid)){
amount += rs->amount;
}
}
}
wsprintf(s,L"%.2f\n",amount/100);
cmzs = cmzs + s;
}
//账户
cmzs = cmzs + LOADSTRING(IDS_STR_ACCOUNT);
cmzs = cmzs + L"[" + cash_db.getAccountNameById(rec.accountid) + L"]\n";
double in = 0;
double out = 0;
RECORDATE_t date;
date.Year = t.wYear;
date.Month = t.wMonth;
date.Day = t.wDay;
if(cash_db.getTransactionsByAccount(rec.accountid,&date,&date)){
list<CASH_TRANSACT_ptr>::iterator i = cash_db.list_search_record.begin();
for(; i != cash_db.list_search_record.end(); i++){
CASH_TRANSACT_ptr r = *i;
if(r->isTransfer){ //转出
out += r->amount;
}else{
CASH_CATEGORY_ptr c = cash_db.categoryById(r->categoryid);
if(c->type == CT_INCOME){
in += r->amount;
}else{
out += r->amount;
}
}
}
}
if(cash_db.getTransactionsByToAccount(rec.accountid,&date,&date)){
list<CASH_TRANSACT_ptr>::iterator i = cash_db.list_search_record.begin();
for(; i != cash_db.list_search_record.end(); i++){
CASH_TRANSACT_ptr r = *i;
in += r->amount;
}
}
wsprintf(s,LOADSTRING(IDS_STR_SUM_INOUT).C_Str(),in/100,out/100,(in-out)/100);
cmzs = cmzs + s;
//此账户今日共流入,流出,差额,余额
m_TextDetail.SetText(cmzs.C_Str());
m_TextDetail.Invalidate();
}
void Ui_DailyReportWnd::OnMzCommand(WPARAM wParam, LPARAM lParam) {
UINT_PTR id = LOWORD(wParam);
switch (id) {
case MZ_IDC_BUTTON_PRE_DATE:
{
DateTime::OneDayDate(t,true);
updateDetail();
updateDetailText();
break;
}
case MZ_IDC_BUTTON_NEXT_DATE:
{
DateTime::OneDayDate(t);
updateDetail();
updateDetailText();
break;
}
case MZ_IDC_TOOLBAR_ABOUT:
{
int nIndex = lParam;
if (nIndex == 0) {
// exit the modal dialog
EndModal(ID_OK);
return;
}
}
}
}
LRESULT Ui_DailyReportWnd::MzDefWndProc(UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case MZ_WM_MOUSE_NOTIFY:
{
int nID = LOWORD(wParam);
int nNotify = HIWORD(wParam);
int x = LOWORD(lParam);
int y = HIWORD(lParam);
//列表
if (nID == MZ_IDC_LIST && nNotify == MZ_MN_LBUTTONDOWN) {
if (!m_ListDetail.IsMouseDownAtScrolling() && !m_ListDetail.IsMouseMoved()) {
int nIndex = m_ListDetail.CalcIndexOfPos(x, y);
m_ListDetail.SetSelectedIndex(nIndex);
m_ListDetail.Invalidate();
updateDetailText();
}
return 0;
}
if (nID == MZ_IDC_LIST && nNotify == MZ_MN_MOUSEMOVE) {
m_ListDetail.SetSelectedIndex(-1);
m_ListDetail.Invalidate();
updateDetailText();
return 0;
}
if(nID == MZ_IDC_CAPTION_DATE && nNotify == MZ_MN_LBUTTONUP){ //双击 显示全部
// GetLocalTime(&t);
Ui_CalendarWnd calendardlg;
RECT rcWork = MzGetWorkArea();
calendardlg.Create(rcWork.left, rcWork.top, RECT_WIDTH(rcWork), RECT_HEIGHT(rcWork),
m_hWnd, 0, WS_POPUP);
// set the animation of the window
calendardlg.SetAnimateType_Show(MZ_ANIMTYPE_SCROLL_RIGHT_TO_LEFT_2);
calendardlg.SetAnimateType_Hide(MZ_ANIMTYPE_SCROLL_LEFT_TO_RIGHT_1);
int nRet = calendardlg.DoModal();
if (nRet == ID_OK) {
t = DateTime::StrToDate(calendardlg.getDate().C_Str());
updateDetail();
updateDetailText();
}
return 0;
}
}
}
return CMzWndEx::MzDefWndProc(message, wParam, lParam);
}