Commit e55b8f0d7480752f6d71aa6c1b233b14460461be

Authored by liuye
1 parent 66b806be

feat<central_clearing_system>:调整分页功能ing

central_clearing_system/ETradeClient/hardware/hardware_cmd.cpp
@@ -5,6 +5,8 @@ @@ -5,6 +5,8 @@
5 #include <sstream> 5 #include <sstream>
6 6
7 #include <boost/algorithm/string.hpp> 7 #include <boost/algorithm/string.hpp>
  8 +#include <boost/typeof/typeof.hpp>
  9 +#include <boost/foreach.hpp>
8 10
9 #include "etradeclient/boost_patch/property_tree/json_parser.hpp" // WARNIING! Make sure to include our patched version. 11 #include "etradeclient/boost_patch/property_tree/json_parser.hpp" // WARNIING! Make sure to include our patched version.
10 #include "etradeclient/utility/logging.h" 12 #include "etradeclient/utility/logging.h"
@@ -1280,7 +1282,7 @@ StylusPrinterCmd::Reply StylusPrinterCmd::Execute(const std::string&amp; input) @@ -1280,7 +1282,7 @@ StylusPrinterCmd::Reply StylusPrinterCmd::Execute(const std::string&amp; input)
1280 do 1282 do
1281 { 1283 {
1282 LOG_TRACE(L"解析打印数据!"); 1284 LOG_TRACE(L"解析打印数据!");
1283 - ParseInput(input, comm_vector); 1285 + ParseInput(const_cast<std::string&>(input), comm_vector);
1284 Print(comm_vector); 1286 Print(comm_vector);
1285 } while (0); 1287 } while (0);
1286 1288
@@ -1288,40 +1290,43 @@ StylusPrinterCmd::Reply StylusPrinterCmd::Execute(const std::string&amp; input) @@ -1288,40 +1290,43 @@ StylusPrinterCmd::Reply StylusPrinterCmd::Execute(const std::string&amp; input)
1288 return reply; 1290 return reply;
1289 } 1291 }
1290 1292
1291 -bool StylusPrinterCmd::Print(std::vector<OrderInfo> &order_vector) 1293 +int StylusPrinterCmd::Print(std::vector<OrderInfo> &order_vector)
1292 { 1294 {
1293 CPrintDialog dlg(false); 1295 CPrintDialog dlg(false);
1294 dlg.GetDefaults(); 1296 dlg.GetDefaults();
1295 CDC dc; 1297 CDC dc;
1296 - dc.Attach(dlg.GetPrinterDC()); 1298 + dc.Attach(dlg.GetPrinterDC());
  1299 + LPDEVMODE pDevMode;
  1300 + pDevMode = (LPDEVMODE)GlobalLock(dlg.m_pd.hDevMode);
  1301 + pDevMode->dmOrientation = DMORIENT_PORTRAIT;//设置打印方向为横向
  1302 + pDevMode->dmPaperSize = DMPAPER_9X11;//设置纸张大小为A4
  1303 + dc.ResetDC(pDevMode);
1297 dc.StartDoc(L"print"); 1304 dc.StartDoc(L"print");
1298 1305
1299 CFont title_font; 1306 CFont title_font;
1300 title_font.CreatePointFont(350, L"宋体"); 1307 title_font.CreatePointFont(350, L"宋体");
1301 1308
1302 - CFont bold_font;  
1303 - bold_font.CreatePointFont(200, L"宋体");  
1304 -  
1305 CFont normal_font; 1309 CFont normal_font;
1306 normal_font.CreatePointFont(200, L"宋体"); 1310 normal_font.CreatePointFont(200, L"宋体");
1307 1311
1308 for (auto iter : order_vector) 1312 for (auto iter : order_vector)
1309 { 1313 {
  1314 + dc.StartPage();
1310 dc.SelectObject(&title_font); 1315 dc.SelectObject(&title_font);
1311 dc.TextOut(600, 50, iter.doc_name); 1316 dc.TextOut(600, 50, iter.doc_name);
1312 1317
1313 dc.SelectObject(&normal_font); 1318 dc.SelectObject(&normal_font);
1314 dc.TextOut(100, 150, StatementNoText); 1319 dc.TextOut(100, 150, StatementNoText);
1315 - dc.TextOut(150, 150, iter.statements_no); 1320 + dc.TextOut(250, 150, iter.statements_no);
1316 1321
1317 dc.TextOut(1000, 150, TradeTimeText); 1322 dc.TextOut(1000, 150, TradeTimeText);
1318 - dc.TextOut(1050, 150, iter.trade_time); 1323 + dc.TextOut(1150, 150, iter.trade_time);
1319 1324
1320 dc.TextOut(100, 200, BuyerNameText); 1325 dc.TextOut(100, 200, BuyerNameText);
1321 - dc.TextOut(150, 200, iter.buyer_name); 1326 + dc.TextOut(250, 200, iter.buyer_name);
1322 1327
1323 dc.TextOut(1000, 200, SalerNameText); 1328 dc.TextOut(1000, 200, SalerNameText);
1324 - dc.TextOut(1050, 200, iter.saler_name); 1329 + dc.TextOut(1150, 200, iter.seller_name);
1325 1330
1326 dc.MoveTo(100, 250); 1331 dc.MoveTo(100, 250);
1327 dc.LineTo(1700, 250); 1332 dc.LineTo(1700, 250);
@@ -1332,21 +1337,21 @@ bool StylusPrinterCmd::Print(std::vector&lt;OrderInfo&gt; &amp;order_vector) @@ -1332,21 +1337,21 @@ bool StylusPrinterCmd::Print(std::vector&lt;OrderInfo&gt; &amp;order_vector)
1332 dc.TextOut(1100, 280, SubtotalText); 1337 dc.TextOut(1100, 280, SubtotalText);
1333 int y_point = 280; 1338 int y_point = 280;
1334 1339
1335 - int comm_count = order_vector.size(); 1340 + int comm_count = iter.comm_vector.size();
1336 CString pagination; 1341 CString pagination;
1337 1342
1338 int page_count = 0; 1343 int page_count = 0;
1339 - if (comm_count > 5) 1344 + if (comm_count <= 5)
1340 { 1345 {
1341 page_count = 1; 1346 page_count = 1;
1342 } 1347 }
1343 else 1348 else
1344 { 1349 {
1345 - comm_count -= 6;  
1346 - page_count = comm_count / 9 + (comm_count % 9 > 0 ? 2 : 1); 1350 + //comm_count -= 6;
  1351 + page_count = (comm_count - 6) / 9 + ((comm_count - 6) % 9 > 0 ? 2 : 1);
1347 } 1352 }
1348 1353
1349 - int first_page_comm = page_count > 1 ? 6 : 5; //第一页不分页最多有5条商品,分页最多有6条商品 1354 + int first_page_comm = page_count > 1 ? 6 : comm_count; //第一页不分页最多有5条商品,分页最多有6条商品
1350 1355
1351 int comm_index = 0; 1356 int comm_index = 0;
1352 for (; comm_index < first_page_comm; ++comm_index) 1357 for (; comm_index < first_page_comm; ++comm_index)
@@ -1362,7 +1367,7 @@ bool StylusPrinterCmd::Print(std::vector&lt;OrderInfo&gt; &amp;order_vector) @@ -1362,7 +1367,7 @@ bool StylusPrinterCmd::Print(std::vector&lt;OrderInfo&gt; &amp;order_vector)
1362 { 1367 {
1363 pagination.Format(L"%d/%d", 1, page_count); 1368 pagination.Format(L"%d/%d", 1, page_count);
1364 dc.TextOut(1200, 870, pagination); 1369 dc.TextOut(1200, 870, pagination);
1365 - //dc.StartPage(); 1370 + dc.EndPage();
1366 } 1371 }
1367 1372
1368 for (int index = 1; index < page_count - 1; ++index) 1373 for (int index = 1; index < page_count - 1; ++index)
@@ -1382,7 +1387,7 @@ bool StylusPrinterCmd::Print(std::vector&lt;OrderInfo&gt; &amp;order_vector) @@ -1382,7 +1387,7 @@ bool StylusPrinterCmd::Print(std::vector&lt;OrderInfo&gt; &amp;order_vector)
1382 dc.EndPage(); 1387 dc.EndPage();
1383 } 1388 }
1384 1389
1385 - if (comm_count % 9 > 0) 1390 + if (comm_count % 9 > 0 && page_count > 1)
1386 { 1391 {
1387 dc.StartPage(); 1392 dc.StartPage();
1388 y_point = 40; 1393 y_point = 40;
@@ -1401,29 +1406,88 @@ bool StylusPrinterCmd::Print(std::vector&lt;OrderInfo&gt; &amp;order_vector) @@ -1401,29 +1406,88 @@ bool StylusPrinterCmd::Print(std::vector&lt;OrderInfo&gt; &amp;order_vector)
1401 dc.LineTo(1700, y_point); 1406 dc.LineTo(1700, y_point);
1402 1407
1403 dc.TextOut(100, y_point += 30, ClerkText); 1408 dc.TextOut(100, y_point += 30, ClerkText);
1404 - dc.TextOut(150, y_point, iter.settlement_clerk); 1409 + dc.TextOut(250, y_point, iter.settlement_clerk);
1405 1410
1406 - dc.TextOut(1200, y_point, TotalMoneyText);  
1407 - dc.TextOut(1350, y_point, iter.total_money); 1411 + dc.TextOut(1100, y_point, TotalMoneyText);
  1412 + dc.TextOut(1250, y_point, iter.total_money);
1408 1413
1409 pagination.Format(L"%d/%d", page_count, page_count); 1414 pagination.Format(L"%d/%d", page_count, page_count);
1410 dc.TextOut(1200, 870, pagination); 1415 dc.TextOut(1200, 870, pagination);
1411 - }  
1412 1416
1413 - 1417 + if (page_count == 1)
  1418 + {
  1419 + dc.EndPage();
  1420 + }
  1421 +
  1422 + }
1414 1423
1415 1424
1416 -  
1417 -  
1418 title_font.DeleteObject(); 1425 title_font.DeleteObject();
1419 - bold_font.DeleteObject();  
1420 normal_font.DeleteObject(); 1426 normal_font.DeleteObject();
1421 dc.EndDoc();//结束打印 1427 dc.EndDoc();//结束打印
1422 1428
1423 return true; 1429 return true;
1424 } 1430 }
1425 1431
1426 -bool StylusPrinterCmd::ParseInput(const std::string &input, std::vector<OrderInfo> &order_vector) 1432 +static const std::string JSON_TAG_TITLE = "title";
  1433 +static const std::string JSON_TAG_ORDERS = "orders";
  1434 +static const std::string JSON_TAG_ORDER_ID = "orderId";
  1435 +static const std::string JSON_TAG_PRODUCT_NAME = "productName";
  1436 +static const std::string JSON_TAG_PRICE = "price";
  1437 +static const std::string JSON_TAG_AMOUNT = "amount";
  1438 +static const std::string JSON_TAG_MONEY = "money";
  1439 +static const std::string JSON_TAG_STATEMENT_ID = "statementId";
  1440 +static const std::string JSON_TAG_TRADE_TIME = "tradeTime";
  1441 +static const std::string JSON_TAG_TRADE_BUYER_NAME = "buyerName";
  1442 +static const std::string JSON_TAG_TRADE_SELLER_NAME = "sellerName";
  1443 +static const std::string JSON_TAG_TRADE_USER_NAME = "userName";
  1444 +static const std::string JSON_TAG_TRADE_TOTAL_MONEY = "totalMoney";
  1445 +static const std::string JSON_TAG_TRADE_PRODUCTS = "products";
  1446 +
  1447 +
  1448 +bool StylusPrinterCmd::ParseInput(std::string &input, std::vector<OrderInfo> &order_vector)
1427 { 1449 {
1428 - return true; 1450 + int result = 0;
  1451 +
  1452 + namespace PT = boost::property_tree;
  1453 + try //Parse the configuration file
  1454 + {
  1455 + PT::ptree ptree;
  1456 + std::stringstream ss;
  1457 + ss << input;
  1458 + PT::read_json(ss, ptree);
  1459 + std::string title = ptree.get<std::string>(JSON_TAG_TITLE);
  1460 + PT::ptree order_tree = ptree.get_child(JSON_TAG_ORDERS);
  1461 +
  1462 + BOOST_FOREACH(PT::ptree::value_type &v, order_tree)
  1463 + {
  1464 + OrderInfo order;
  1465 + order.doc_name = title.c_str();
  1466 + order.statements_no = v.second.get<std::string>(JSON_TAG_STATEMENT_ID).c_str();
  1467 + order.trade_time = v.second.get<std::string>(JSON_TAG_TRADE_TIME).c_str();
  1468 + order.buyer_name = v.second.get<std::string>(JSON_TAG_TRADE_BUYER_NAME).c_str();
  1469 + order.seller_name = v.second.get<std::string>(JSON_TAG_TRADE_SELLER_NAME).c_str();
  1470 + order.settlement_clerk = v.second.get<std::string>(JSON_TAG_TRADE_USER_NAME).c_str();
  1471 + order.total_money = v.second.get<std::string>(JSON_TAG_TRADE_TOTAL_MONEY).c_str();
  1472 +
  1473 + PT::ptree products_ptree = v.second.get_child(JSON_TAG_TRADE_PRODUCTS);
  1474 + BOOST_FOREACH(PT::ptree::value_type &v, products_ptree)
  1475 + {
  1476 + CommInfo comm_info;
  1477 + comm_info.comm_id = v.second.get<std::string>(JSON_TAG_ORDER_ID).c_str();
  1478 + comm_info.comm_name = v.second.get<std::string>(JSON_TAG_PRODUCT_NAME).c_str();
  1479 + comm_info.price = v.second.get<std::string>(JSON_TAG_PRICE).c_str();
  1480 + comm_info.count = v.second.get<std::string>(JSON_TAG_AMOUNT).c_str();
  1481 + comm_info.total_money = v.second.get<std::string>(JSON_TAG_MONEY).c_str();
  1482 + order.comm_vector.push_back(comm_info);
  1483 + }
  1484 + order_vector.push_back(order);
  1485 + }
  1486 + }
  1487 + catch (...)
  1488 + {
  1489 + LOG_ERROR(L"解析服务器返回的打印信息时出错!请确认返回数据不为空,返回的数据格式为正确的Json格式!");
  1490 + result = 1000;
  1491 + }
  1492 + return result;
1429 } 1493 }
1430 \ No newline at end of file 1494 \ No newline at end of file
central_clearing_system/ETradeClient/hardware/hardware_cmd.h
@@ -101,6 +101,7 @@ class StylusPrinterCmd : public HardwareCmd @@ -101,6 +101,7 @@ class StylusPrinterCmd : public HardwareCmd
101 { 101 {
102 struct CommInfo 102 struct CommInfo
103 { 103 {
  104 + CString comm_id;
104 CString comm_name; 105 CString comm_name;
105 CString price; 106 CString price;
106 CString count; 107 CString count;
@@ -113,7 +114,7 @@ class StylusPrinterCmd : public HardwareCmd @@ -113,7 +114,7 @@ class StylusPrinterCmd : public HardwareCmd
113 CString statements_no; 114 CString statements_no;
114 CString trade_time; 115 CString trade_time;
115 CString buyer_name; 116 CString buyer_name;
116 - CString saler_name; 117 + CString seller_name;
117 CString settlement_clerk; 118 CString settlement_clerk;
118 CString total_money; 119 CString total_money;
119 std::vector<CommInfo> comm_vector; 120 std::vector<CommInfo> comm_vector;
@@ -122,8 +123,8 @@ public: @@ -122,8 +123,8 @@ public:
122 virtual Reply Execute(const std::string& input) override; 123 virtual Reply Execute(const std::string& input) override;
123 124
124 private: 125 private:
125 - bool ParseInput(const std::string &input, std::vector<OrderInfo> &order_vector);  
126 - bool Print(std::vector<OrderInfo> &order_vector); 126 + bool ParseInput(std::string &input, std::vector<OrderInfo> &order_vector);
  127 + int Print(std::vector<OrderInfo> &order_vector);
127 }; 128 };
128 // 129 //
129 130
central_clearing_system/ETradeClient/mfc_ui/pay_dlg.cpp
@@ -115,5 +115,6 @@ void PayDlg::OnBnClickedPayButtonClose() @@ -115,5 +115,6 @@ void PayDlg::OnBnClickedPayButtonClose()
115 void PayDlg::OnBnClickedPayButtonPay() 115 void PayDlg::OnBnClickedPayButtonPay()
116 { 116 {
117 auto printer_device = StylusPrinterCmd(); 117 auto printer_device = StylusPrinterCmd();
118 - HardwareCmd::Reply reply = printer_device.Execute(""); 118 +
  119 + HardwareCmd::Reply reply = printer_device.Execute("{\"title\":\"长春结地利算单\",\"orders\":[{\"statementId\":\"123456\",\"tradeTime\":\"2018/10/10\",\"buyerName\":\"大熊\",\"sellerName\":\"卖家大熊\",\"userName\":\"结算员大熊\",\"totalMoney\":\"11001.91\",\"products\":[{\"orderId\":1000,\"productName\":\"商品名称大熊\",\"price\":\"55.5\",\"amount\":\"500\",\"money\":\"1021.01\"},{\"orderId\":1000,\"productName\":\"商品名称大熊\",\"price\":\"2753\",\"amount\":\"752\",\"money\":\"1021.01\"},{\"orderId\":1000,\"productName\":\"商品名称大熊\",\"price\":\"2753\",\"amount\":\"752\",\"money\":\"1021.01\"},{\"orderId\":1000,\"productName\":\"商品名称大熊\",\"price\":\"2753\",\"amount\":\"752\",\"money\":\"1021.01\"},{\"orderId\":1000,\"productName\":\"商品名称大熊\",\"price\":\"2753\",\"amount\":\"752\",\"money\":\"1021.01\"},{\"orderId\":1000,\"productName\":\"商品名称大熊\",\"price\":\"2753\",\"amount\":\"752\",\"money\":\"1021.01\"},{\"orderId\":1000,\"productName\":\"商品名称大熊\",\"price\":\"2753\",\"amount\":\"752\",\"money\":\"1021.01\"},{\"orderId\":1000,\"productName\":\"商品名称大熊\",\"price\":\"2753\",\"amount\":\"752\",\"money\":\"1021.01\"},{\"orderId\":1000,\"productName\":\"商品名称大熊\",\"price\":\"2753\",\"amount\":\"752\",\"money\":\"1021.01\"},{\"orderId\":1000,\"productName\":\"商品名称大熊\",\"price\":\"2753\",\"amount\":\"752\",\"money\":\"1021.01\"}]}]}");
119 } 120 }