Commit 66b806bec08d7d0fa78798c20ad00c630f74a688
1 parent
6ba22507
feat<central_clearing_system>:打印模板开发完成
Showing
3 changed files
with
176 additions
and
135 deletions
central_clearing_system/ETradeClient/hardware/hardware_cmd.cpp
... | ... | @@ -1259,48 +1259,171 @@ ReadPINPadCmd::Reply ReadDILIAndBankCardNumCmd::Execute(const std::string& input |
1259 | 1259 | return reply; |
1260 | 1260 | } |
1261 | 1261 | |
1262 | +const CString StatementNoText = L"结算单号:"; | |
1263 | +const CString TradeTimeText = L"交易时间:"; | |
1264 | +const CString BuyerNameText = L"买家姓名:"; | |
1265 | +const CString SalerNameText = L"卖家姓名:"; | |
1266 | +const CString CommNameText = L"商品名称"; | |
1267 | +const CString PriceText = L"单价"; | |
1268 | +const CString CountText = L"数量"; | |
1269 | +const CString SubtotalText = L"小计/元"; | |
1270 | +const CString ClerkText = L"结算员:"; | |
1271 | +const CString TotalMoneyText = L"总计:"; | |
1272 | + | |
1273 | + | |
1262 | 1274 | StylusPrinterCmd::Reply StylusPrinterCmd::Execute(const std::string& input) |
1263 | 1275 | { |
1264 | 1276 | LOG_TRACE(L"开始打印"); |
1265 | 1277 | Reply reply; |
1266 | - CString doc_name; | |
1267 | - CString statements_no; | |
1268 | - CString trade_time; | |
1269 | - CString buyer_name; | |
1270 | - CString saler_name; | |
1271 | - CString settlement_clerk; | |
1272 | - CString total_money; | |
1273 | - | |
1274 | - struct CommInfo | |
1275 | - { | |
1276 | - CString comm_name; | |
1277 | - CString price; | |
1278 | - CString count; | |
1279 | - CString total_money; | |
1280 | - }; | |
1281 | - std::vector<CommInfo> comm_vector; | |
1282 | 1278 | |
1279 | + std::vector<OrderInfo> comm_vector; | |
1283 | 1280 | do |
1284 | 1281 | { |
1285 | 1282 | LOG_TRACE(L"解析打印数据!"); |
1286 | - | |
1287 | - | |
1283 | + ParseInput(input, comm_vector); | |
1284 | + Print(comm_vector); | |
1288 | 1285 | } while (0); |
1289 | 1286 | |
1290 | 1287 | |
1291 | - CPrintDialog dlg(false); //定义打印机对话框 | |
1292 | - dlg.GetDefaults(); //获取打印机默认值 | |
1288 | + return reply; | |
1289 | +} | |
1290 | + | |
1291 | +bool StylusPrinterCmd::Print(std::vector<OrderInfo> &order_vector) | |
1292 | +{ | |
1293 | + CPrintDialog dlg(false); | |
1294 | + dlg.GetDefaults(); | |
1293 | 1295 | CDC dc; |
1294 | - dc.Attach(dlg.GetPrinterDC()); //关联打印机 | |
1295 | - dc.StartDoc(L"print"); //开始打印 | |
1296 | + dc.Attach(dlg.GetPrinterDC()); | |
1297 | + dc.StartDoc(L"print"); | |
1296 | 1298 | |
1297 | - CFont font; | |
1298 | - font.CreatePointFont(500, L"宋体"); | |
1299 | - dc.SelectObject(&font); | |
1300 | - dc.TextOut(350, 150, L"长春地利结算单"); //输出内容 | |
1301 | - font.DeleteObject(); | |
1299 | + CFont title_font; | |
1300 | + title_font.CreatePointFont(350, L"宋体"); | |
1301 | + | |
1302 | + CFont bold_font; | |
1303 | + bold_font.CreatePointFont(200, L"宋体"); | |
1304 | + | |
1305 | + CFont normal_font; | |
1306 | + normal_font.CreatePointFont(200, L"宋体"); | |
1307 | + | |
1308 | + for (auto iter : order_vector) | |
1309 | + { | |
1310 | + dc.SelectObject(&title_font); | |
1311 | + dc.TextOut(600, 50, iter.doc_name); | |
1312 | + | |
1313 | + dc.SelectObject(&normal_font); | |
1314 | + dc.TextOut(100, 150, StatementNoText); | |
1315 | + dc.TextOut(150, 150, iter.statements_no); | |
1316 | + | |
1317 | + dc.TextOut(1000, 150, TradeTimeText); | |
1318 | + dc.TextOut(1050, 150, iter.trade_time); | |
1319 | + | |
1320 | + dc.TextOut(100, 200, BuyerNameText); | |
1321 | + dc.TextOut(150, 200, iter.buyer_name); | |
1322 | + | |
1323 | + dc.TextOut(1000, 200, SalerNameText); | |
1324 | + dc.TextOut(1050, 200, iter.saler_name); | |
1325 | + | |
1326 | + dc.MoveTo(100, 250); | |
1327 | + dc.LineTo(1700, 250); | |
1328 | + | |
1329 | + dc.TextOut(200, 280, CommNameText); | |
1330 | + dc.TextOut(500, 280, PriceText); | |
1331 | + dc.TextOut(800, 280, CountText); | |
1332 | + dc.TextOut(1100, 280, SubtotalText); | |
1333 | + int y_point = 280; | |
1334 | + | |
1335 | + int comm_count = order_vector.size(); | |
1336 | + CString pagination; | |
1337 | + | |
1338 | + int page_count = 0; | |
1339 | + if (comm_count > 5) | |
1340 | + { | |
1341 | + page_count = 1; | |
1342 | + } | |
1343 | + else | |
1344 | + { | |
1345 | + comm_count -= 6; | |
1346 | + page_count = comm_count / 9 + (comm_count % 9 > 0 ? 2 : 1); | |
1347 | + } | |
1348 | + | |
1349 | + int first_page_comm = page_count > 1 ? 6 : 5; //第一页不分页最多有5条商品,分页最多有6条商品 | |
1350 | + | |
1351 | + int comm_index = 0; | |
1352 | + for (; comm_index < first_page_comm; ++comm_index) | |
1353 | + { | |
1354 | + y_point += 80; | |
1355 | + dc.TextOut(200, y_point, iter.comm_vector[comm_index].comm_name); | |
1356 | + dc.TextOut(500, y_point, iter.comm_vector[comm_index].price); | |
1357 | + dc.TextOut(800, y_point, iter.comm_vector[comm_index].count); | |
1358 | + dc.TextOut(1100, y_point, iter.comm_vector[comm_index].total_money); | |
1359 | + } | |
1360 | + | |
1361 | + if (page_count > 1) | |
1362 | + { | |
1363 | + pagination.Format(L"%d/%d", 1, page_count); | |
1364 | + dc.TextOut(1200, 870, pagination); | |
1365 | + //dc.StartPage(); | |
1366 | + } | |
1367 | + | |
1368 | + for (int index = 1; index < page_count - 1; ++index) | |
1369 | + { | |
1370 | + dc.StartPage(); | |
1371 | + y_point = 40; | |
1372 | + for (int comm = 0; comm < 9; ++comm, ++comm_index) | |
1373 | + { | |
1374 | + y_point += 80; | |
1375 | + dc.TextOut(200, y_point, iter.comm_vector[comm_index].comm_name); | |
1376 | + dc.TextOut(500, y_point, iter.comm_vector[comm_index].price); | |
1377 | + dc.TextOut(800, y_point, iter.comm_vector[comm_index].count); | |
1378 | + dc.TextOut(1100, y_point, iter.comm_vector[comm_index].total_money); | |
1379 | + } | |
1380 | + pagination.Format(L"%d/%d", index + 1, page_count); | |
1381 | + dc.TextOut(1200, 870, pagination); | |
1382 | + dc.EndPage(); | |
1383 | + } | |
1384 | + | |
1385 | + if (comm_count % 9 > 0) | |
1386 | + { | |
1387 | + dc.StartPage(); | |
1388 | + y_point = 40; | |
1389 | + for (; comm_index < comm_count; ++comm_index) | |
1390 | + { | |
1391 | + y_point += 80; | |
1392 | + dc.TextOut(200, y_point, iter.comm_vector[comm_index].comm_name); | |
1393 | + dc.TextOut(500, y_point, iter.comm_vector[comm_index].price); | |
1394 | + dc.TextOut(800, y_point, iter.comm_vector[comm_index].count); | |
1395 | + dc.TextOut(1100, y_point, iter.comm_vector[comm_index].total_money); | |
1396 | + } | |
1397 | + dc.EndPage(); | |
1398 | + } | |
1399 | + | |
1400 | + dc.MoveTo(100, y_point += 80); | |
1401 | + dc.LineTo(1700, y_point); | |
1402 | + | |
1403 | + dc.TextOut(100, y_point += 30, ClerkText); | |
1404 | + dc.TextOut(150, y_point, iter.settlement_clerk); | |
1405 | + | |
1406 | + dc.TextOut(1200, y_point, TotalMoneyText); | |
1407 | + dc.TextOut(1350, y_point, iter.total_money); | |
1408 | + | |
1409 | + pagination.Format(L"%d/%d", page_count, page_count); | |
1410 | + dc.TextOut(1200, 870, pagination); | |
1411 | + } | |
1302 | 1412 | |
1303 | - dc.EndDoc();//结束打印 | |
1304 | 1413 | |
1305 | - return reply; | |
1414 | + | |
1415 | + | |
1416 | + | |
1417 | + | |
1418 | + title_font.DeleteObject(); | |
1419 | + bold_font.DeleteObject(); | |
1420 | + normal_font.DeleteObject(); | |
1421 | + dc.EndDoc();//结束打印 | |
1422 | + | |
1423 | + return true; | |
1424 | +} | |
1425 | + | |
1426 | +bool StylusPrinterCmd::ParseInput(const std::string &input, std::vector<OrderInfo> &order_vector) | |
1427 | +{ | |
1428 | + return true; | |
1306 | 1429 | } |
1307 | 1430 | \ No newline at end of file | ... | ... |
central_clearing_system/ETradeClient/hardware/hardware_cmd.h
... | ... | @@ -4,6 +4,7 @@ |
4 | 4 | #include <string> |
5 | 5 | |
6 | 6 | #include <boost/property_tree/ptree.hpp> |
7 | +#include <vector> | |
7 | 8 | |
8 | 9 | class HardwareCmd |
9 | 10 | { |
... | ... | @@ -98,8 +99,31 @@ public: |
98 | 99 | //Õëʽ´òÓ¡»ú½Ó¿Ú |
99 | 100 | class StylusPrinterCmd : public HardwareCmd |
100 | 101 | { |
102 | + struct CommInfo | |
103 | + { | |
104 | + CString comm_name; | |
105 | + CString price; | |
106 | + CString count; | |
107 | + CString total_money; | |
108 | + }; | |
109 | + | |
110 | + struct OrderInfo | |
111 | + { | |
112 | + CString doc_name; | |
113 | + CString statements_no; | |
114 | + CString trade_time; | |
115 | + CString buyer_name; | |
116 | + CString saler_name; | |
117 | + CString settlement_clerk; | |
118 | + CString total_money; | |
119 | + std::vector<CommInfo> comm_vector; | |
120 | + }; | |
101 | 121 | public: |
102 | 122 | virtual Reply Execute(const std::string& input) override; |
123 | + | |
124 | +private: | |
125 | + bool ParseInput(const std::string &input, std::vector<OrderInfo> &order_vector); | |
126 | + bool Print(std::vector<OrderInfo> &order_vector); | |
103 | 127 | }; |
104 | 128 | // |
105 | 129 | ... | ... |
central_clearing_system/ETradeClient/mfc_ui/GridMemDC.h deleted
100644 → 0
1 | -#if !defined(AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_) | |
2 | -#define AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_ | |
3 | - | |
4 | -#if _MSC_VER >= 1000 | |
5 | -#pragma once | |
6 | -#endif // _MSC_VER >= 1000 | |
7 | -// MemDC.h : header file | |
8 | -// | |
9 | - | |
10 | -////////////////////////////////////////////////// | |
11 | -// CGridMemDC - memory DC | |
12 | -// | |
13 | -// Author: Keith Rule | |
14 | -// Email: keithr@europa.com | |
15 | -// Copyright 1996-1997, Keith Rule | |
16 | -// | |
17 | -// You may freely use or modify this code provided this | |
18 | -// Copyright is included in all derived versions. | |
19 | -// | |
20 | -// History - 10/3/97 Fixed scrolling bug. | |
21 | -// Added print support. | |
22 | -// 25 feb 98 - fixed minor assertion bug | |
23 | -// | |
24 | -// This class implements a memory Device Context | |
25 | - | |
26 | -class CGridMemDC : public CDC | |
27 | -{ | |
28 | -public: | |
29 | - | |
30 | - // constructor sets up the memory DC | |
31 | - CGridMemDC(CDC* pDC) : CDC() | |
32 | - { | |
33 | - ASSERT(pDC != NULL); | |
34 | - | |
35 | - m_pDC = pDC; | |
36 | - m_pOldBitmap = NULL; | |
37 | -#ifndef _WIN32_WCE_NO_PRINTING | |
38 | - m_bMemDC = !pDC->IsPrinting(); | |
39 | -#else | |
40 | - m_bMemDC = FALSE; | |
41 | -#endif | |
42 | - | |
43 | - if (m_bMemDC) // Create a Memory DC | |
44 | - { | |
45 | - pDC->GetClipBox(&m_rect); | |
46 | - CreateCompatibleDC(pDC); | |
47 | - m_bitmap.CreateCompatibleBitmap(pDC, m_rect.Width(), m_rect.Height()); | |
48 | - m_pOldBitmap = SelectObject(&m_bitmap); | |
49 | -#ifndef _WIN32_WCE | |
50 | - SetWindowOrg(m_rect.left, m_rect.top); | |
51 | -#endif | |
52 | - // EFW - Bug fix - Fill background in case the user has overridden | |
53 | - // WM_ERASEBKGND. We end up with garbage otherwise. | |
54 | - // CJM - moved to fix a bug in the fix. | |
55 | - FillSolidRect(m_rect, pDC->GetBkColor()); | |
56 | - } | |
57 | - else // Make a copy of the relevent parts of the current DC for printing | |
58 | - { | |
59 | -#if !defined(_WIN32_WCE) || ((_WIN32_WCE > 201) && !defined(_WIN32_WCE_NO_PRINTING)) | |
60 | - m_bPrinting = pDC->m_bPrinting; | |
61 | -#endif | |
62 | - m_hDC = pDC->m_hDC; | |
63 | - m_hAttribDC = pDC->m_hAttribDC; | |
64 | - } | |
65 | - | |
66 | - } | |
67 | - | |
68 | - // Destructor copies the contents of the mem DC to the original DC | |
69 | - ~CGridMemDC() | |
70 | - { | |
71 | - if (m_bMemDC) | |
72 | - { | |
73 | - // Copy the offscreen bitmap onto the screen. | |
74 | - m_pDC->BitBlt(m_rect.left, m_rect.top, m_rect.Width(), m_rect.Height(), | |
75 | - this, m_rect.left, m_rect.top, SRCCOPY); | |
76 | - | |
77 | - //Swap back the original bitmap. | |
78 | - SelectObject(m_pOldBitmap); | |
79 | - } else { | |
80 | - // All we need to do is replace the DC with an illegal value, | |
81 | - // this keeps us from accidently deleting the handles associated with | |
82 | - // the CDC that was passed to the constructor. | |
83 | - m_hDC = m_hAttribDC = NULL; | |
84 | - } | |
85 | - } | |
86 | - | |
87 | - // Allow usage as a pointer | |
88 | - CGridMemDC* operator->() {return this;} | |
89 | - | |
90 | - // Allow usage as a pointer | |
91 | - operator CGridMemDC*() {return this;} | |
92 | - | |
93 | -private: | |
94 | - CBitmap m_bitmap; // Offscreen bitmap | |
95 | - CBitmap* m_pOldBitmap; // bitmap originally found in CGridMemDC | |
96 | - CDC* m_pDC; // Saves CDC passed in constructor | |
97 | - CRect m_rect; // Rectangle of drawing area. | |
98 | - BOOL m_bMemDC; // TRUE if CDC really is a Memory DC. | |
99 | -}; | |
100 | - | |
101 | -///////////////////////////////////////////////////////////////////////////// | |
102 | - | |
103 | -//{{AFX_INSERT_LOCATION}} | |
104 | -// Microsoft Developer Studio will insert additional declarations immediately before the previous line. | |
105 | - | |
106 | -#endif // !defined(AFX_MEMDC_H__CA1D3541_7235_11D1_ABBA_00A0243D1382__INCLUDED_) |