CMainWnd.cpp 61 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051
  1. #include "../pch/pch.h"
  2. #include "CMainWnd.h"
  3. #include "CLoginWnd.h"
  4. #include "CChufangSettingWnd.h"
  5. #include "../control/ControlEx.h"
  6. #include "../control/CWaimaiOrderInfoUI.h"
  7. #include "../network/CMessagePush.h"
  8. #include "CWaimaiOrderFailReasonWnd.h"
  9. void CMainWnd::Init()
  10. {
  11. m_pCloseBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("closebtn")));
  12. m_pMaxBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("maxbtn")));
  13. m_pRestoreBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("restorebtn")));
  14. m_pMinBtn = static_cast<CButtonUI*>(m_pm.FindControl(_T("minbtn")));
  15. //初始化外卖订单列表
  16. COptionUI* waimai_tab = static_cast<COptionUI*>(m_pm.FindControl(_T("main_waimai")));
  17. if(waimai_tab->IsSelected())
  18. {
  19. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  20. orderlist->Refresh();
  21. }
  22. //初始化设置中心的状态
  23. InitSettingStatus();
  24. //登录成功,启动消息和任务处理
  25. m_push = new CMessagePush(m_hWnd);
  26. m_push->Start();
  27. }
  28. LRESULT CMainWnd::OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  29. {
  30. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  31. styleValue &= ~WS_CAPTION;
  32. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  33. m_pm.Init(m_hWnd);
  34. CDialogBuilder builder;
  35. CDialogBuilderCallbackEx cb;
  36. CControlUI* pRoot = builder.Create(_T("main.xml"), (UINT)0, &cb, &m_pm);
  37. ASSERT(pRoot && "Failed to parse XML");
  38. m_pm.AttachDialog(pRoot);
  39. m_pm.AddNotifier(this);
  40. Init();
  41. return 0;
  42. }
  43. void CMainWnd::Notify(TNotifyUI& msg)
  44. {
  45. if(msg.sType == _T("windowinit"))
  46. {
  47. OnPrepare();
  48. }
  49. else if(msg.sType == _T("click"))
  50. {
  51. HandleClickMsg(msg);
  52. }
  53. else if(msg.sType == _T("selectchanged"))
  54. {
  55. HandleSelectChangeMsg(msg);
  56. }
  57. else if(msg.sType == _T("itemclick"))
  58. {
  59. }
  60. else if(msg.sType == _T("itemactivate"))
  61. {
  62. }
  63. else if(msg.sType == _T("itemselect"))
  64. {
  65. HandleItemSelectMsg(msg);
  66. }
  67. }
  68. void CMainWnd::HandleClickMsg(TNotifyUI& msg)
  69. {
  70. if(msg.pSender == m_pCloseBtn)
  71. {
  72. if(CSetting::GetParam("setting_is_close_min") == "1")
  73. {
  74. AddTrayIcon();
  75. }
  76. else
  77. {
  78. PostQuitMessage(0);
  79. }
  80. return;
  81. }
  82. else if(msg.pSender == m_pMinBtn)
  83. {
  84. SendMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0);
  85. return;
  86. }
  87. else if(msg.pSender == m_pMaxBtn)
  88. {
  89. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
  90. return;
  91. }
  92. else if(msg.pSender == m_pRestoreBtn)
  93. {
  94. SendMessage(WM_SYSCOMMAND, SC_RESTORE, 0);
  95. return;
  96. }
  97. CDuiString name = msg.pSender->GetName();
  98. if(name == _T("quitbtn"))
  99. {
  100. /*Close()*/PostQuitMessage(0); // 因为activex的原因,使用close可能会出现错误
  101. }
  102. else if(name == _T("waimai_order_list_print"))
  103. {
  104. CWaimaiOrderItemUI* item = static_cast<CWaimaiOrderItemUI*>(msg.pSender->GetParent()->GetParent());
  105. std::string waimai_order_id = item->getOrderID();
  106. std::string waimai_order_no = item->getOrderNo();
  107. m_push->AddPinter(waimai_order_id, waimai_order_no, 2);
  108. }
  109. else if(name == _T("waimai_order_list_confirme"))
  110. {
  111. CWaimaiOrderItemUI* item = static_cast<CWaimaiOrderItemUI*>(msg.pSender->GetParent()->GetParent());
  112. std::string waimai_order_id = item->getOrderID();
  113. CWaimaiOrder order;
  114. bool ret = order.ConfirmeOrder(waimai_order_id);
  115. if(ret)
  116. {
  117. //如果确认成功,将被确认的订单删除掉
  118. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  119. int index = orderlist->GetItemIndex(item);
  120. orderlist->RemoveAt(index);
  121. }
  122. }
  123. else if(name == _T("waimai_order_list_success"))
  124. {
  125. CWaimaiOrderItemUI* item = static_cast<CWaimaiOrderItemUI*>(msg.pSender->GetParent()->GetParent());
  126. std::string waimai_order_id = item->getOrderID();
  127. CWaimaiOrder order;
  128. bool ret = order.SuccessOrder(waimai_order_id);
  129. if(ret)
  130. {
  131. //如果确认成功,将被确认的订单删除掉
  132. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  133. int index = orderlist->GetItemIndex(item);
  134. orderlist->RemoveAt(index);
  135. }
  136. }
  137. else if(name == _T("waimai_order_list_fail"))
  138. {
  139. //外卖订单的打印
  140. CWaimaiOrderItemUI* item = static_cast<CWaimaiOrderItemUI*>(msg.pSender->GetParent()->GetParent());
  141. std::string waimai_order_id = item->getOrderID();
  142. CWaimaiOrderFailReasonWnd* pWaimaiFailFrame = new CWaimaiOrderFailReasonWnd();
  143. pWaimaiFailFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  144. pWaimaiFailFrame->SetIcon(IDI_ICON_DUILIB);
  145. pWaimaiFailFrame->CenterWindow();
  146. UINT ret = pWaimaiFailFrame->ShowModal();
  147. if(ret == IDOK)
  148. {
  149. std::string sReason = pWaimaiFailFrame->getReason();
  150. CWaimaiOrder order;
  151. bool ret = order.FailOrder(waimai_order_id, sReason);
  152. if(ret)
  153. {
  154. //如果设为失败成功,将被设为失败的订单删除掉
  155. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  156. int index = orderlist->GetItemIndex(item);
  157. orderlist->RemoveAt(index);
  158. }
  159. }
  160. delete pWaimaiFailFrame;
  161. }
  162. else if(name == _T("waimai_order_list_agree"))
  163. {
  164. CWaimaiOrderItemUI* item = static_cast<CWaimaiOrderItemUI*>(msg.pSender->GetParent()->GetParent());
  165. std::string waimai_order_id = item->getOrderID();
  166. CWaimaiOrder order;
  167. bool ret = order.AgreeRefund(waimai_order_id);
  168. if(ret)
  169. {
  170. //同意退款之后,订单变为失败状态
  171. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  172. int index = orderlist->GetItemIndex(item);
  173. orderlist->RemoveAt(index);
  174. }
  175. }
  176. else if(name == _T("waimai_order_list_disagree"))
  177. {
  178. CWaimaiOrderItemUI* item = static_cast<CWaimaiOrderItemUI*>(msg.pSender->GetParent()->GetParent());
  179. std::string waimai_order_id = item->getOrderID();
  180. CWaimaiOrder order;
  181. bool ret = order.DisagreeRefund(waimai_order_id);
  182. if(ret)
  183. {
  184. //不同意退款,订单还是退款中,等待第三方客服处理
  185. //OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  186. //int index = orderlist->GetItemIndex(item);
  187. //orderlist->RemoveAt(index);
  188. }
  189. }
  190. else if(name == _T("waimai_order_list_info"))
  191. {
  192. CWaimaiOrderItemUI* item = static_cast<CWaimaiOrderItemUI*>(msg.pSender->GetParent()->GetParent());
  193. std::string waimai_order_id = item->getOrderID();
  194. std::string waimai_order_no = item->getOrderNo();
  195. //请求服务器,获取订单数据
  196. CWaimaiOrder order;
  197. order.InitData(waimai_order_id, waimai_order_no);
  198. //刷新订单详情页数据
  199. CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
  200. order_info_page->SetDate(order);
  201. order_info_page->Refresh(order);
  202. //显示订单详情页的内容
  203. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  204. if(pControl && pControl->GetCurSel() != 1)
  205. {
  206. pControl->SelectItem(1);
  207. }
  208. }
  209. else if(name == _T("waimai_order_list_last"))
  210. {
  211. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  212. orderlist->LastPage();
  213. }
  214. else if(name == _T("waimai_order_list_next"))
  215. {
  216. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  217. orderlist->NextPage();
  218. }
  219. else if(name == _T("waimai_order_list_refresh"))
  220. {
  221. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  222. orderlist->Refresh();
  223. }
  224. else if(name == _T("waimai_order_info_page_return"))
  225. {
  226. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  227. if(pControl && pControl->GetCurSel() != 0)
  228. {
  229. pControl->SelectItem(0);
  230. }
  231. //刷新当前列表
  232. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  233. orderlist->Refresh();
  234. }
  235. else if(name == _T("waimai_order_info_page_print"))
  236. {
  237. CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
  238. m_push->AddPinter(order_info_page->m_order.m_order_id, order_info_page->m_order.m_order_no, 2);
  239. }
  240. else if(name == _T("waimai_order_info_page_confirme"))
  241. {
  242. CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
  243. std::string waimai_order_id = order_info_page->m_order.m_order_id;
  244. std::string waimai_order_no = order_info_page->m_order.m_order_no;
  245. CWaimaiOrder order;
  246. bool ret = order.ConfirmeOrder(waimai_order_id);
  247. if(ret)
  248. {
  249. //确认成功,这里怎么处理
  250. //请求服务器,获取订单数据
  251. CWaimaiOrder new_order;
  252. new_order.InitData(waimai_order_id, waimai_order_no);
  253. //刷新订单详情页数据
  254. order_info_page->SetDate(new_order);
  255. order_info_page->Refresh(new_order);
  256. }
  257. }
  258. else if(name == _T("waimai_order_info_page_success"))
  259. {
  260. CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
  261. std::string waimai_order_id = order_info_page->m_order.m_order_id;
  262. std::string waimai_order_no = order_info_page->m_order.m_order_no;
  263. CWaimaiOrder order;
  264. bool ret = order.SuccessOrder(waimai_order_id);
  265. if(ret)
  266. {
  267. //订单设为成功,这里怎么处理
  268. //请求服务器,获取订单数据
  269. CWaimaiOrder new_order;
  270. new_order.InitData(waimai_order_id, waimai_order_no);
  271. //刷新订单详情页数据
  272. order_info_page->SetDate(new_order);
  273. order_info_page->Refresh(new_order);
  274. }
  275. }
  276. else if(name == _T("waimai_order_info_page_fail"))
  277. {
  278. CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
  279. std::string waimai_order_id = order_info_page->m_order.m_order_id;
  280. std::string waimai_order_no = order_info_page->m_order.m_order_no;
  281. CWaimaiOrderFailReasonWnd* pWaimaiFailFrame = new CWaimaiOrderFailReasonWnd();
  282. pWaimaiFailFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  283. pWaimaiFailFrame->SetIcon(IDI_ICON_DUILIB);
  284. pWaimaiFailFrame->CenterWindow();
  285. UINT ret = pWaimaiFailFrame->ShowModal();
  286. if(ret == IDOK)
  287. {
  288. std::string sReason = pWaimaiFailFrame->getReason();
  289. CWaimaiOrder order;
  290. bool ret = order.FailOrder(waimai_order_id, sReason);
  291. if(ret)
  292. {
  293. //订单设为失败,这里怎么处理
  294. //请求服务器,获取订单数据
  295. CWaimaiOrder new_order;
  296. new_order.InitData(waimai_order_id, waimai_order_no);
  297. //刷新订单详情页数据
  298. order_info_page->SetDate(new_order);
  299. order_info_page->Refresh(new_order);
  300. }
  301. }
  302. delete pWaimaiFailFrame;
  303. }
  304. else if(name == _T("waimai_order_info_page_agree"))
  305. {
  306. CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
  307. std::string waimai_order_id = order_info_page->m_order.m_order_id;
  308. std::string waimai_order_no = order_info_page->m_order.m_order_no;
  309. CWaimaiOrder order;
  310. bool ret = order.AgreeRefund(waimai_order_id);
  311. if(ret)
  312. {
  313. //订单设为成功,这里怎么处理
  314. //请求服务器,获取订单数据
  315. CWaimaiOrder new_order;
  316. new_order.InitData(waimai_order_id, waimai_order_no);
  317. //刷新订单详情页数据
  318. order_info_page->SetDate(new_order);
  319. order_info_page->Refresh(new_order);
  320. }
  321. }
  322. else if(name == _T("waimai_order_info_page_disagree"))
  323. {
  324. CWaimaiOrderInfoUI* order_info_page = static_cast<CWaimaiOrderInfoUI*>(m_pm.FindControl(_T("waimaiorder_info_page")));
  325. std::string waimai_order_id = order_info_page->m_order.m_order_id;
  326. std::string waimai_order_no = order_info_page->m_order.m_order_no;
  327. CWaimaiOrder order;
  328. bool ret = order.DisagreeRefund(waimai_order_id);
  329. if(ret)
  330. {
  331. //订单设为成功,这里怎么处理
  332. //请求服务器,获取订单数据
  333. CWaimaiOrder new_order;
  334. new_order.InitData(waimai_order_id, waimai_order_no);
  335. //刷新订单详情页数据
  336. order_info_page->SetDate(new_order);
  337. order_info_page->Refresh(new_order);
  338. }
  339. }
  340. //开始处理设置页面的
  341. else if(name == _T("setting_is_new_waimai_voice"))
  342. {
  343. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_voice")));
  344. //注意这里的IsSelected如果为true,表示的是点击前为true,而不是点击后为true,所以这里设置状态要反过来
  345. if(box->IsSelected())
  346. {
  347. CSetting::SetParam("setting_is_new_waimai_voice", "0");
  348. }
  349. else
  350. {
  351. CSetting::SetParam("setting_is_new_waimai_voice", "1");
  352. }
  353. }
  354. else if(name == _T("setting_is_new_waimai_autoconfirm"))
  355. {
  356. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_autoconfirm")));
  357. if(box->IsSelected())
  358. {
  359. CSetting::SetParam("setting_is_new_waimai_autoconfirm", "0");
  360. }
  361. else
  362. {
  363. CSetting::SetParam("setting_is_new_waimai_autoconfirm", "1");
  364. }
  365. }
  366. else if(name == _T("setting_is_new_waimai_dialog"))
  367. {
  368. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_dialog")));
  369. if(box->IsSelected())
  370. {
  371. CSetting::SetParam("setting_is_new_waimai_dialog", "0");
  372. }
  373. else
  374. {
  375. CSetting::SetParam("setting_is_new_waimai_dialog", "1");
  376. }
  377. }
  378. else if(name == _T("setting_is_new_waimai_printer"))
  379. {
  380. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_printer")));
  381. if(box->IsSelected())
  382. {
  383. CSetting::SetParam("setting_is_new_waimai_printer", "0");
  384. }
  385. else
  386. {
  387. CSetting::SetParam("setting_is_new_waimai_printer", "1");
  388. }
  389. }
  390. else if(name == _T("setting_printer_wangkouk_save_btn"))
  391. {
  392. CEditUI* wangkou_ip = static_cast<CEditUI*>(m_pm.FindControl(_T("setting_printer_wangkou_ip")));
  393. wstring ip = wangkou_ip->GetText();
  394. CSetting::SetParam("setting_printer_wangkou_ip", CLewaimaiString::UnicodeToUTF8(ip));
  395. }
  396. else if(name == _T("setting_printer_quhuo_big"))
  397. {
  398. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_quhuo_big")));
  399. if(box->IsSelected())
  400. {
  401. CSetting::SetParam("setting_printer_quhuo_big", "0");
  402. }
  403. else
  404. {
  405. CSetting::SetParam("setting_printer_quhuo_big", "1");
  406. }
  407. }
  408. else if(name == _T("setting_printer_dingdanhao_big"))
  409. {
  410. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_dingdanhao_big")));
  411. if(box->IsSelected())
  412. {
  413. CSetting::SetParam("setting_printer_dingdanhao_big", "0");
  414. }
  415. else
  416. {
  417. CSetting::SetParam("setting_printer_dingdanhao_big", "1");
  418. }
  419. }
  420. else if(name == _T("setting_printer_xiadanshijian_big"))
  421. {
  422. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_xiadanshijian_big")));
  423. if(box->IsSelected())
  424. {
  425. CSetting::SetParam("setting_printer_xiadanshijian_big", "0");
  426. }
  427. else
  428. {
  429. CSetting::SetParam("setting_printer_xiadanshijian_big", "1");
  430. }
  431. }
  432. else if(name == _T("setting_printer_peisongshijian_big"))
  433. {
  434. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_peisongshijian_big")));
  435. if(box->IsSelected())
  436. {
  437. CSetting::SetParam("setting_printer_peisongshijian_big", "0");
  438. }
  439. else
  440. {
  441. CSetting::SetParam("setting_printer_peisongshijian_big", "1");
  442. }
  443. }
  444. else if(name == _T("setting_printer_name_big"))
  445. {
  446. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_name_big")));
  447. if(box->IsSelected())
  448. {
  449. CSetting::SetParam("setting_printer_name_big", "0");
  450. }
  451. else
  452. {
  453. CSetting::SetParam("setting_printer_name_big", "1");
  454. }
  455. }
  456. else if(name == _T("setting_printer_phone_big"))
  457. {
  458. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_phone_big")));
  459. if(box->IsSelected())
  460. {
  461. CSetting::SetParam("setting_printer_phone_big", "0");
  462. }
  463. else
  464. {
  465. CSetting::SetParam("setting_printer_phone_big", "1");
  466. }
  467. }
  468. else if(name == _T("setting_printer_address_big"))
  469. {
  470. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_address_big")));
  471. if(box->IsSelected())
  472. {
  473. CSetting::SetParam("setting_printer_address_big", "0");
  474. }
  475. else
  476. {
  477. CSetting::SetParam("setting_printer_address_big", "1");
  478. }
  479. }
  480. else if(name == _T("setting_printer_shangpin_big"))
  481. {
  482. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_shangpin_big")));
  483. if(box->IsSelected())
  484. {
  485. CSetting::SetParam("setting_printer_shangpin_big", "0");
  486. }
  487. else
  488. {
  489. CSetting::SetParam("setting_printer_shangpin_big", "1");
  490. }
  491. }
  492. else if(name == _T("setting_printer_memo_big"))
  493. {
  494. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_memo_big")));
  495. if(box->IsSelected())
  496. {
  497. CSetting::SetParam("setting_printer_memo_big", "0");
  498. }
  499. else
  500. {
  501. CSetting::SetParam("setting_printer_memo_big", "1");
  502. }
  503. }
  504. else if(name == _T("setting_printer_price_big"))
  505. {
  506. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_price_big")));
  507. if(box->IsSelected())
  508. {
  509. CSetting::SetParam("setting_printer_price_big", "0");
  510. }
  511. else
  512. {
  513. CSetting::SetParam("setting_printer_price_big", "1");
  514. }
  515. }
  516. else if(name == _T("setting_printer_pay_big"))
  517. {
  518. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_pay_big")));
  519. if(box->IsSelected())
  520. {
  521. CSetting::SetParam("setting_printer_pay_big", "0");
  522. }
  523. else
  524. {
  525. CSetting::SetParam("setting_printer_pay_big", "1");
  526. }
  527. }
  528. else if(name == _T("setting_is_new_waimai_chufang_printer"))
  529. {
  530. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_chufang_printer")));
  531. if(box->IsSelected())
  532. {
  533. CSetting::SetParam("setting_is_new_waimai_chufang_printer", "0");
  534. }
  535. else
  536. {
  537. CSetting::SetParam("setting_is_new_waimai_chufang_printer", "1");
  538. }
  539. }
  540. else if(name == _T("setting_new_chufang_printer_btn"))
  541. {
  542. CChufangSettingWnd* pChufangFrame = new CChufangSettingWnd(1);
  543. if(pChufangFrame != NULL)
  544. {
  545. pChufangFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  546. pChufangFrame->SetIcon(IDI_ICON_DUILIB);
  547. pChufangFrame->CenterWindow();
  548. UINT ret = pChufangFrame->ShowModal();
  549. if(ret == IDOK)
  550. {
  551. //这个时候是点击保存返回了,厨房打印机的数据已经建立好了,这个时候刷新表格的显示
  552. CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
  553. //把最后一个厨房打印机取出来
  554. ChufangPrinter newPrinter = CSetting::getLastChufangPrinter();
  555. CDialogBuilder builder;
  556. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("setting_chufang_printer_item.xml"), (UINT)0, NULL, &m_pm));
  557. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_name")));
  558. pName->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.name).c_str());
  559. CLabelUI* pIP = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_ip")));
  560. pIP->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.ip).c_str());
  561. CLabelUI* pGuige = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_guige")));
  562. if(newPrinter.guige == "58")
  563. {
  564. pGuige->SetText(L"58mm");
  565. }
  566. else
  567. {
  568. pGuige->SetText(L"80mm");
  569. }
  570. CLabelUI* pFendan = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_fendan")));
  571. if(newPrinter.fendan == "1")
  572. {
  573. pFendan->SetText(L"是");
  574. }
  575. else
  576. {
  577. pFendan->SetText(L"否");
  578. }
  579. CLabelUI* pFenlei = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei")));
  580. if(newPrinter.fenlei == "1")
  581. {
  582. pFenlei->SetText(L"是");
  583. }
  584. else
  585. {
  586. pFenlei->SetText(L"否");
  587. }
  588. std::string foodtypeNames = "";
  589. std::string foodtype_ids = newPrinter.fenlei_ids;
  590. std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
  591. for (std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
  592. {
  593. std::string name = CSetting::getFoodtypeName((*it));
  594. std::wstring ws_name = CLewaimaiString::UTF8ToUnicode(name);
  595. if (name == "zhipuzi_not_found_xxx")
  596. {
  597. //这种情况是以前保存的分类后来被删掉了
  598. }
  599. else
  600. {
  601. foodtypeNames += name + " ";
  602. }
  603. }
  604. foodtypeNames = foodtypeNames.substr(0, foodtypeNames.size() - 1);
  605. std::wstring ws_foodtypeNames = CLewaimaiString::UTF8ToUnicode(foodtypeNames);
  606. CLabelUI* pFenleiIds = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei_ids")));
  607. pFenleiIds->SetText(ws_foodtypeNames.c_str());
  608. pEle->AddCustomAttribute(L"date", CLewaimaiString::UTF8ToUnicode(newPrinter.date).c_str());
  609. pPrinterList->Add(pEle);
  610. }
  611. }
  612. }
  613. else if(name == _T("setting_is_auto_start"))
  614. {
  615. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_auto_start")));
  616. if(box->IsSelected())
  617. {
  618. CSetting::SetParam("setting_is_auto_start", "0");
  619. CSystem::cancelAutoStart();
  620. }
  621. else
  622. {
  623. CSetting::SetParam("setting_is_auto_start", "1");
  624. CSystem::autostart();
  625. }
  626. }
  627. else if(name == _T("setting_is_auto_login"))
  628. {
  629. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_auto_login")));
  630. if(box->IsSelected())
  631. {
  632. CSetting::SetParam("setting_is_auto_login", "0");
  633. }
  634. else
  635. {
  636. CSetting::SetParam("setting_is_auto_login", "1");
  637. }
  638. }
  639. else if(name == _T("setting_is_close_min"))
  640. {
  641. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_close_min")));
  642. if(box->IsSelected())
  643. {
  644. CSetting::SetParam("setting_is_close_min", "0");
  645. }
  646. else
  647. {
  648. CSetting::SetParam("setting_is_close_min", "1");
  649. }
  650. }
  651. else if(name == _T("setting_chufang_printer_item_update_btn"))
  652. {
  653. CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
  654. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(msg.pSender->GetParent()->GetParent()->GetParent());
  655. wstring date = pEle->GetCustomAttribute(L"date");
  656. CChufangSettingWnd* pChufangFrame = new CChufangSettingWnd(2);
  657. pChufangFrame->SetPrinterDate(CLewaimaiString::UnicodeToUTF8(date));
  658. if(pChufangFrame != NULL)
  659. {
  660. pChufangFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  661. pChufangFrame->SetIcon(IDI_ICON_DUILIB);
  662. pChufangFrame->CenterWindow();
  663. UINT ret = pChufangFrame->ShowModal();
  664. if(ret == IDOK)
  665. {
  666. //这个时候是点击保存返回了,厨房打印机的数据已经建立好了,这个时候刷新表格的显示
  667. CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
  668. ChufangPrinter newPrinter = CSetting::GetChufangPrinter(CLewaimaiString::UnicodeToUTF8(date));
  669. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_name")));
  670. pName->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.name).c_str());
  671. CLabelUI* pIP = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_ip")));
  672. pIP->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.ip).c_str());
  673. CLabelUI* pGuige = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_guige")));
  674. if(newPrinter.guige == "58")
  675. {
  676. pGuige->SetText(L"58mm");
  677. }
  678. else
  679. {
  680. pGuige->SetText(L"80mm");
  681. }
  682. CLabelUI* pFendan = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_fendan")));
  683. if(newPrinter.fendan == "1")
  684. {
  685. pFendan->SetText(L"是");
  686. }
  687. else
  688. {
  689. pFendan->SetText(L"否");
  690. }
  691. CLabelUI* pFenlei = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei")));
  692. if(newPrinter.fenlei == "1")
  693. {
  694. pFenlei->SetText(L"是");
  695. }
  696. else
  697. {
  698. pFenlei->SetText(L"否");
  699. }
  700. std::string foodtypeNames = "";
  701. std::string foodtype_ids = newPrinter.fenlei_ids;
  702. std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
  703. for(std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
  704. {
  705. std::string name = CSetting::getFoodtypeName((*it));
  706. std::wstring ws_name = CLewaimaiString::UTF8ToUnicode(name);
  707. if(name == "zhipuzi_not_found_xxx")
  708. {
  709. //这种情况是以前保存的分类后来被删掉了
  710. }
  711. else
  712. {
  713. foodtypeNames += name + " ";
  714. }
  715. }
  716. foodtypeNames = foodtypeNames.substr(0, foodtypeNames.size() - 1);
  717. std::wstring ws_foodtypeNames = CLewaimaiString::UTF8ToUnicode(foodtypeNames);
  718. CLabelUI* pFenleiIds = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei_ids")));
  719. pFenleiIds->SetText(ws_foodtypeNames.c_str());
  720. }
  721. }
  722. }
  723. else if(name == _T("setting_chufang_printer_item_delete_btn"))
  724. {
  725. CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
  726. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(msg.pSender->GetParent()->GetParent()->GetParent());
  727. wstring date = pEle->GetCustomAttribute(L"date");
  728. //获得了ID,这个时候从内存和数据库中分别删除对应的记录
  729. CSetting::DelChufangPrinter(CLewaimaiString::UnicodeToUTF8(date));
  730. pPrinterList->Remove(pEle);
  731. }
  732. else if(name == _T("setting_logout"))
  733. {
  734. //退出登录
  735. CSetting::SetParam("setting_is_auto_login", "0", true);
  736. CLoginWnd* pLogin = new CLoginWnd();
  737. if(pLogin == NULL)
  738. {
  739. return;
  740. }
  741. pLogin->Create(NULL, _T("智铺子收银软件登录"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
  742. pLogin->SetIcon(IDI_ICON_DUILIB);
  743. pLogin->CenterWindow();
  744. ::ShowWindow(*pLogin, SW_SHOWNORMAL);
  745. Close();
  746. }
  747. }
  748. void CMainWnd::HandleSelectChangeMsg(TNotifyUI& msg)
  749. {
  750. CDuiString name = msg.pSender->GetName();
  751. //先判断主页面的tab
  752. if(name == _T("main_waimai"))
  753. {
  754. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  755. if(pControl && pControl->GetCurSel() != 0)
  756. {
  757. pControl->SelectItem(0);
  758. }
  759. }
  760. else if(name == _T("main_setting"))
  761. {
  762. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  763. if(pControl && pControl->GetCurSel() != 2)
  764. {
  765. pControl->SelectItem(2);
  766. }
  767. }
  768. else if(name == _T("main_contact"))
  769. {
  770. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  771. if(pControl && pControl->GetCurSel() != 3)
  772. {
  773. pControl->SelectItem(3);
  774. }
  775. }
  776. //判断外卖的tab
  777. else if(name == _T("waimai_open_switch") || name == _T("waimai_confirmed_switch") || name == _T("waimai_delivery_switch") || name == _T("waimai_success_switch") || name == _T("waimai_fail_switch") || name == _T("waimai_cancel_switch") || name == _T("waimai_refund_switch"))
  778. {
  779. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  780. //切换状态全部重新开始从第1页
  781. orderlist->SetPage(1);
  782. if(name == _T("waimai_open_switch"))
  783. {
  784. orderlist->SetStatus(1);
  785. }
  786. else if(name == _T("waimai_confirmed_switch"))
  787. {
  788. orderlist->SetStatus(2);
  789. }
  790. else if(name == _T("waimai_delivery_switch"))
  791. {
  792. orderlist->SetStatus(3);
  793. }
  794. else if(name == _T("waimai_success_switch"))
  795. {
  796. orderlist->SetStatus(4);
  797. }
  798. else if(name == _T("waimai_fail_switch"))
  799. {
  800. orderlist->SetStatus(5);
  801. }
  802. else if(name == _T("waimai_cancel_switch"))
  803. {
  804. orderlist->SetStatus(6);
  805. }
  806. else if(name == _T("waimai_refund_switch"))
  807. {
  808. orderlist->SetStatus(7);
  809. }
  810. orderlist->Refresh();
  811. }
  812. //判断设置中心的tab
  813. else if(name == _T("setting_waimai_order_switch"))
  814. {
  815. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("setting_switch")));
  816. pControl->SelectItem(0);
  817. }
  818. else if(name == _T("setting_printer_switch"))
  819. {
  820. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("setting_switch")));
  821. pControl->SelectItem(1);
  822. }
  823. else if(name == _T("setting_chufang_printer_switch"))
  824. {
  825. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("setting_switch")));
  826. pControl->SelectItem(2);
  827. }
  828. else if(name == _T("setting_system_switch"))
  829. {
  830. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("setting_switch")));
  831. pControl->SelectItem(3);
  832. }
  833. else if(name == _T("setting_system_about"))
  834. {
  835. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("setting_switch")));
  836. pControl->SelectItem(4);
  837. }
  838. }
  839. void CMainWnd::HandleItemSelectMsg(TNotifyUI& msg)
  840. {
  841. CDuiString name = msg.pSender->GetName();
  842. if(name == _T("setting_printer_guige"))
  843. {
  844. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_guige")));
  845. if(com->GetCurSel() == 0)
  846. {
  847. CSetting::SetParam("setting_printer_guige", "58");
  848. }
  849. else
  850. {
  851. CSetting::SetParam("setting_printer_guige", "80");
  852. }
  853. }
  854. else if(name == _T("setting_printer_lianshu"))
  855. {
  856. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_lianshu")));
  857. if(com->GetCurSel() == 0)
  858. {
  859. CSetting::SetParam("setting_printer_lianshu", "1");
  860. }
  861. else if(com->GetCurSel() == 1)
  862. {
  863. CSetting::SetParam("setting_printer_lianshu", "2");
  864. }
  865. else if(com->GetCurSel() == 2)
  866. {
  867. CSetting::SetParam("setting_printer_lianshu", "3");
  868. }
  869. else if(com->GetCurSel() == 3)
  870. {
  871. CSetting::SetParam("setting_printer_lianshu", "4");
  872. }
  873. }
  874. else if(name == _T("setting_printer_leixing"))
  875. {
  876. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_leixing")));
  877. CHorizontalLayoutUI* usb_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_usb_layout")));
  878. CHorizontalLayoutUI* wangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_wangkou_layout")));
  879. if(com->GetCurSel() == 0)
  880. {
  881. CSetting::SetParam("setting_printer_leixing", "auto");
  882. usb_layout->SetVisible(false);
  883. wangkou_layout->SetVisible(false);
  884. }
  885. else if(com->GetCurSel() == 1)
  886. {
  887. CSetting::SetParam("setting_printer_leixing", "usb");
  888. //显示usb布局
  889. usb_layout->SetVisible(true);
  890. wangkou_layout->SetVisible(false);
  891. //usb下拉框默认选中
  892. CComboUI* com_usb = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_usb")));
  893. com_usb->RemoveAll();
  894. //数据库中保存的之前的设置
  895. std::string setting_printer_usb = CSetting::GetParam("setting_printer_usb");
  896. std::wstring ws_setting_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_printer_usb);
  897. CPosPrinter printer;
  898. printer.InitUsb();
  899. std::vector<std::wstring> usb_devices = printer.getUsbDevices();
  900. int i = 0;
  901. int nSelect = -1;
  902. for(std::vector<std::wstring>::iterator it = usb_devices.begin(); it != usb_devices.end(); it++)
  903. {
  904. CListLabelElementUI* elem = new CListLabelElementUI();
  905. elem->SetText((*it).c_str());
  906. com_usb->Add(elem);
  907. if(*it == ws_setting_printer_usb)
  908. {
  909. nSelect = i;
  910. }
  911. i++;
  912. }
  913. com_usb->SetInternVisible(true);
  914. com_usb->SelectItem(nSelect, false, false);
  915. com_usb->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_usb).c_str());
  916. }
  917. else if(com->GetCurSel() == 2)
  918. {
  919. CSetting::SetParam("setting_printer_leixing", "bingkou");
  920. usb_layout->SetVisible(false);
  921. wangkou_layout->SetVisible(false);
  922. }
  923. else if(com->GetCurSel() == 3)
  924. {
  925. CSetting::SetParam("setting_printer_leixing", "chuankou");
  926. usb_layout->SetVisible(false);
  927. wangkou_layout->SetVisible(false);
  928. }
  929. else if(com->GetCurSel() == 4)
  930. {
  931. CSetting::SetParam("setting_printer_leixing", "wangkou");
  932. usb_layout->SetVisible(false);
  933. wangkou_layout->SetVisible(true);
  934. std::string setting_printer_wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
  935. CEditUI* ip_edit = static_cast<CEditUI*>(m_pm.FindControl(_T("setting_printer_wangkou_ip")));
  936. ip_edit->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_wangkou_ip).c_str());
  937. }
  938. }
  939. else if(name == _T("setting_printer_usb"))
  940. {
  941. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_usb")));
  942. wstring usb_device = com->GetText();
  943. CSetting::SetParam("setting_printer_usb", CLewaimaiString::UnicodeToUTF8(usb_device));
  944. }
  945. }
  946. LRESULT CMainWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  947. {
  948. LRESULT lRes = 0;
  949. BOOL bHandled = TRUE;
  950. switch(uMsg)
  951. {
  952. case WM_CREATE:
  953. lRes = OnCreate(uMsg, wParam, lParam, bHandled);
  954. break;
  955. case WM_CLOSE:
  956. lRes = OnClose(uMsg, wParam, lParam, bHandled);
  957. break;
  958. case WM_DESTROY:
  959. lRes = OnDestroy(uMsg, wParam, lParam, bHandled);
  960. break;
  961. case WM_NCACTIVATE:
  962. lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
  963. break;
  964. case WM_NCCALCSIZE:
  965. lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
  966. break;
  967. case WM_NCPAINT:
  968. lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
  969. break;
  970. case WM_NCHITTEST:
  971. lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
  972. break;
  973. case WM_SIZE:
  974. lRes = OnSize(uMsg, wParam, lParam, bHandled);
  975. break;
  976. case WM_GETMINMAXINFO:
  977. lRes = OnGetMinMaxInfo(uMsg, wParam, lParam, bHandled);
  978. break;
  979. case WM_SYSCOMMAND:
  980. lRes = OnSysCommand(uMsg, wParam, lParam, bHandled);
  981. break;
  982. case WM_SHOWTASK:
  983. lRes = OnTrayIcon(uMsg, wParam, lParam, bHandled);
  984. break;
  985. case WM_ORDERLIST_REFRESH:
  986. lRes = OnOrderlistRefresh(uMsg, wParam, lParam, bHandled);
  987. break;
  988. case WM_LOGIN_AGAIN_OUT:
  989. lRes = OnLoginOut(uMsg, wParam, lParam, bHandled);
  990. break;
  991. default:
  992. bHandled = FALSE;
  993. }
  994. if(bHandled)
  995. {
  996. return lRes;
  997. }
  998. if(m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
  999. {
  1000. return lRes;
  1001. }
  1002. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  1003. }
  1004. LRESULT CMainWnd::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1005. {
  1006. // 有时会在收到WM_NCDESTROY后收到wParam为SC_CLOSE的WM_SYSCOMMAND
  1007. if(wParam == SC_CLOSE)
  1008. {
  1009. ::PostQuitMessage(0L);
  1010. bHandled = TRUE;
  1011. return 0;
  1012. }
  1013. BOOL bZoomed = ::IsZoomed(*this);
  1014. LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  1015. if(::IsZoomed(*this) != bZoomed)
  1016. {
  1017. if(!bZoomed)
  1018. {
  1019. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
  1020. if(pControl)
  1021. {
  1022. pControl->SetVisible(false);
  1023. }
  1024. pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
  1025. if(pControl)
  1026. {
  1027. pControl->SetVisible(true);
  1028. }
  1029. }
  1030. else
  1031. {
  1032. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
  1033. if(pControl)
  1034. {
  1035. pControl->SetVisible(true);
  1036. }
  1037. pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
  1038. if(pControl)
  1039. {
  1040. pControl->SetVisible(false);
  1041. }
  1042. }
  1043. }
  1044. return lRes;
  1045. }
  1046. LRESULT CMainWnd::OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1047. {
  1048. int primaryMonitorWidth = ::GetSystemMetrics(SM_CXSCREEN);
  1049. int primaryMonitorHeight = ::GetSystemMetrics(SM_CYSCREEN);
  1050. MONITORINFO oMonitor = {};
  1051. oMonitor.cbSize = sizeof(oMonitor);
  1052. ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);
  1053. CDuiRect rcWork = oMonitor.rcWork;
  1054. rcWork.Offset(-oMonitor.rcMonitor.left, -oMonitor.rcMonitor.top);
  1055. if(rcWork.right > primaryMonitorWidth)
  1056. {
  1057. rcWork.right = primaryMonitorWidth;
  1058. }
  1059. if(rcWork.bottom > primaryMonitorHeight)
  1060. {
  1061. rcWork.right = primaryMonitorHeight;
  1062. }
  1063. LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
  1064. lpMMI->ptMaxPosition.x = rcWork.left;
  1065. lpMMI->ptMaxPosition.y = rcWork.top;
  1066. lpMMI->ptMaxSize.x = rcWork.right;
  1067. lpMMI->ptMaxSize.y = rcWork.bottom;
  1068. bHandled = FALSE;
  1069. return 0;
  1070. }
  1071. LRESULT CMainWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1072. {
  1073. SIZE szRoundCorner = m_pm.GetRoundCorner();
  1074. if(!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
  1075. {
  1076. CDuiRect rcWnd;
  1077. ::GetWindowRect(*this, &rcWnd);
  1078. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  1079. rcWnd.right++;
  1080. rcWnd.bottom++;
  1081. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  1082. ::SetWindowRgn(*this, hRgn, TRUE);
  1083. ::DeleteObject(hRgn);
  1084. }
  1085. bHandled = FALSE;
  1086. return 0;
  1087. }
  1088. LRESULT CMainWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1089. {
  1090. bHandled = FALSE;
  1091. return 0;
  1092. }
  1093. /*
  1094. *这个是窗口被销毁的时候调用的
  1095. **/
  1096. LRESULT CMainWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1097. {
  1098. //直接退出程序,或者退出登录都会执行这个
  1099. m_push->Stop();
  1100. bHandled = FALSE;
  1101. return 0;
  1102. }
  1103. LRESULT CMainWnd::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1104. {
  1105. if(::IsIconic(*this))
  1106. {
  1107. bHandled = FALSE;
  1108. }
  1109. return (wParam == 0) ? TRUE : FALSE;
  1110. }
  1111. LRESULT CMainWnd::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1112. {
  1113. return 0;
  1114. }
  1115. LRESULT CMainWnd::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1116. {
  1117. return 0;
  1118. }
  1119. LRESULT CMainWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1120. {
  1121. POINT pt;
  1122. pt.x = GET_X_LPARAM(lParam);
  1123. pt.y = GET_Y_LPARAM(lParam);
  1124. ::ScreenToClient(*this, &pt);
  1125. RECT rcClient;
  1126. ::GetClientRect(*this, &rcClient);
  1127. if(!::IsZoomed(*this))
  1128. {
  1129. RECT rcSizeBox = m_pm.GetSizeBox();
  1130. if(pt.y < rcClient.top + rcSizeBox.top)
  1131. {
  1132. if(pt.x < rcClient.left + rcSizeBox.left)
  1133. {
  1134. return HTTOPLEFT;
  1135. }
  1136. if(pt.x > rcClient.right - rcSizeBox.right)
  1137. {
  1138. return HTTOPRIGHT;
  1139. }
  1140. return HTTOP;
  1141. }
  1142. else if(pt.y > rcClient.bottom - rcSizeBox.bottom)
  1143. {
  1144. if(pt.x < rcClient.left + rcSizeBox.left)
  1145. {
  1146. return HTBOTTOMLEFT;
  1147. }
  1148. if(pt.x > rcClient.right - rcSizeBox.right)
  1149. {
  1150. return HTBOTTOMRIGHT;
  1151. }
  1152. return HTBOTTOM;
  1153. }
  1154. if(pt.x < rcClient.left + rcSizeBox.left)
  1155. {
  1156. return HTLEFT;
  1157. }
  1158. if(pt.x > rcClient.right - rcSizeBox.right)
  1159. {
  1160. return HTRIGHT;
  1161. }
  1162. }
  1163. RECT rcCaption = m_pm.GetCaptionRect();
  1164. if(pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  1165. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
  1166. {
  1167. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  1168. if(pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0 &&
  1169. _tcscmp(pControl->GetClass(), DUI_CTR_OPTION) != 0 &&
  1170. _tcscmp(pControl->GetClass(), DUI_CTR_TEXT) != 0)
  1171. {
  1172. return HTCAPTION;
  1173. }
  1174. }
  1175. return HTCLIENT;
  1176. }
  1177. void CMainWnd::AddTrayIcon()
  1178. {
  1179. memset(&m_trayIcon, 0, sizeof(NOTIFYICONDATA));
  1180. m_trayIcon.cbSize = sizeof(NOTIFYICONDATA);
  1181. m_trayIcon.hIcon = ::LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON_DUILIB));
  1182. m_trayIcon.hWnd = m_hWnd;
  1183. lstrcpy(m_trayIcon.szTip, _T("智铺子收银软件"));
  1184. m_trayIcon.uCallbackMessage = WM_SHOWTASK;
  1185. m_trayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  1186. Shell_NotifyIcon(NIM_ADD, &m_trayIcon);
  1187. ShowWindow(SW_HIDE);
  1188. }
  1189. LRESULT CMainWnd::OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1190. {
  1191. //如果在图标中单击左键则还原
  1192. if(lParam == WM_LBUTTONDOWN)
  1193. {
  1194. //删除托盘图标
  1195. Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
  1196. //显示主窗口
  1197. ShowWindow(SW_SHOWNORMAL);
  1198. //窗口最大化
  1199. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
  1200. }
  1201. //如果在图标中单击右键则弹出声明式菜单
  1202. if(lParam == WM_RBUTTONDOWN)
  1203. {
  1204. //获取鼠标坐标
  1205. POINT pt;
  1206. GetCursorPos(&pt);
  1207. //右击后点别地可以清除“右击出来的菜单”
  1208. SetForegroundWindow(m_hWnd);
  1209. //托盘菜单 win32程序使用的是HMENU,如果是MFC程序可以使用CMenu
  1210. HMENU hMenu;
  1211. //生成托盘菜单
  1212. hMenu = CreatePopupMenu();
  1213. //添加菜单,关键在于设置的一个标识符 WM_ONCLOSE 点击后会用到
  1214. AppendMenu(hMenu, MF_STRING, WM_ONCLOSE, _T("退出"));
  1215. //弹出菜单,并把用户所选菜单项的标识符返回
  1216. int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, NULL, m_hWnd, NULL);
  1217. //如果标识符是WM_ONCLOSE则关闭
  1218. if(cmd == WM_ONCLOSE)
  1219. {
  1220. m_trayIcon.hIcon = NULL;
  1221. Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
  1222. //退出程序
  1223. ::PostQuitMessage(0);
  1224. }
  1225. }
  1226. bHandled = true;
  1227. return 0;
  1228. }
  1229. LRESULT CMainWnd::OnOrderlistRefresh(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1230. {
  1231. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  1232. orderlist->DoRefresh();
  1233. return 1;
  1234. }
  1235. LRESULT CMainWnd::OnLoginOut(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1236. {
  1237. LoginOut(2);
  1238. bHandled = true;
  1239. return 1;
  1240. }
  1241. void CMainWnd::InitSettingStatus()
  1242. {
  1243. CLabelUI* name_version = static_cast<CLabelUI*>(m_pm.FindControl(_T("main_name_version")));
  1244. name_version->SetText((L"智铺子收银软件 " + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
  1245. CLabelUI* version = static_cast<CLabelUI*>(m_pm.FindControl(_T("setting_version")));
  1246. version->SetText((L"版本号:" + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
  1247. CCheckBoxUI* box = NULL;
  1248. CComboUI* com = NULL;
  1249. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_voice")));
  1250. if(CSetting::GetParam("setting_is_new_waimai_voice") == "1")
  1251. {
  1252. box->Selected(true, false);
  1253. }
  1254. else
  1255. {
  1256. box->Selected(false, false);
  1257. }
  1258. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_autoconfirm")));
  1259. if(CSetting::GetParam("setting_is_new_waimai_autoconfirm") == "1")
  1260. {
  1261. box->Selected(true, false);
  1262. }
  1263. else
  1264. {
  1265. box->Selected(false, false);
  1266. }
  1267. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_dialog")));
  1268. if(CSetting::GetParam("setting_is_new_waimai_dialog") == "1")
  1269. {
  1270. box->Selected(true, false);
  1271. }
  1272. else
  1273. {
  1274. box->Selected(false, false);
  1275. }
  1276. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_printer")));
  1277. if(CSetting::GetParam("setting_is_new_waimai_printer") == "1")
  1278. {
  1279. box->Selected(true, false);
  1280. }
  1281. else
  1282. {
  1283. box->Selected(false, false);
  1284. }
  1285. com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_guige")));
  1286. if(CSetting::GetParam("setting_printer_guige") == "58")
  1287. {
  1288. com->SetInternVisible(true);
  1289. com->SelectItem(0, false, false);
  1290. }
  1291. else
  1292. {
  1293. com->SetInternVisible(true);
  1294. com->SelectItem(1, false, false);
  1295. }
  1296. com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_lianshu")));
  1297. std::string setting_printer_lianshu = CSetting::GetParam("setting_printer_lianshu");
  1298. if(setting_printer_lianshu == "1")
  1299. {
  1300. com->SetInternVisible(true);
  1301. com->SelectItem(0, false, false);
  1302. com->SetText(L"1联");
  1303. }
  1304. else if(setting_printer_lianshu == "2")
  1305. {
  1306. com->SetInternVisible(true);
  1307. com->SelectItem(1, false, false);
  1308. com->SetText(L"2联");
  1309. }
  1310. else if(setting_printer_lianshu == "3")
  1311. {
  1312. com->SetInternVisible(true);
  1313. com->SelectItem(2, false, false);
  1314. com->SetText(L"3联");
  1315. }
  1316. else if(setting_printer_lianshu == "4")
  1317. {
  1318. com->SetInternVisible(true);
  1319. com->SelectItem(3, false, false);
  1320. com->SetText(L"4联");
  1321. }
  1322. com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_leixing")));
  1323. std::string setting_printer_leixing = CSetting::GetParam("setting_printer_leixing");
  1324. CHorizontalLayoutUI* usb_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_usb_layout")));
  1325. CHorizontalLayoutUI* wangkou_layout = static_cast<CHorizontalLayoutUI*>(m_pm.FindControl(_T("setting_printer_wangkou_layout")));
  1326. if(setting_printer_leixing == "auto")
  1327. {
  1328. com->SetInternVisible(true);
  1329. com->SelectItem(0, false, false);
  1330. com->SetText(L"智能识别模式");
  1331. //智能识别模式隐藏这2个
  1332. usb_layout->SetVisible(false);
  1333. wangkou_layout->SetVisible(false);
  1334. }
  1335. else if(setting_printer_leixing == "usb")
  1336. {
  1337. com->SetInternVisible(true);
  1338. com->SelectItem(1, false, false);
  1339. com->SetText(L"usb");
  1340. //显示usb布局
  1341. usb_layout->SetVisible(true);
  1342. wangkou_layout->SetVisible(false);
  1343. //usb下拉框默认选中
  1344. CComboUI* com_usb = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_usb")));
  1345. com_usb->RemoveAll();
  1346. //数据库中保存的之前的设置
  1347. std::string setting_printer_usb = CSetting::GetParam("setting_printer_usb");
  1348. std::wstring ws_setting_printer_usb = CLewaimaiString::UTF8ToUnicode(setting_printer_usb);
  1349. CPosPrinter printer;
  1350. printer.InitUsb();
  1351. std::vector<std::wstring> usb_devices = printer.getUsbDevices();
  1352. int i = 0;
  1353. int nSelect = -1;
  1354. for(std::vector<std::wstring>::iterator it = usb_devices.begin(); it != usb_devices.end(); it++)
  1355. {
  1356. CListLabelElementUI* elem = new CListLabelElementUI();
  1357. elem->SetText((*it).c_str());
  1358. com_usb->Add(elem);
  1359. if(*it == ws_setting_printer_usb)
  1360. {
  1361. nSelect = i;
  1362. }
  1363. i++;
  1364. }
  1365. com_usb->SetInternVisible(true);
  1366. com_usb->SelectItem(nSelect, false, false);
  1367. com_usb->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_usb).c_str());
  1368. }
  1369. else if(setting_printer_leixing == "bingkou")
  1370. {
  1371. com->SetInternVisible(true);
  1372. com->SelectItem(2, false, false);
  1373. com->SetText(L"并口");
  1374. usb_layout->SetVisible(false);
  1375. wangkou_layout->SetVisible(false);
  1376. }
  1377. else if(setting_printer_leixing == "chuankou")
  1378. {
  1379. com->SetInternVisible(true);
  1380. com->SelectItem(3, false, false);
  1381. com->SetText(L"串口");
  1382. usb_layout->SetVisible(false);
  1383. wangkou_layout->SetVisible(false);
  1384. }
  1385. else if(setting_printer_leixing == "wangkou")
  1386. {
  1387. com->SetInternVisible(true);
  1388. com->SelectItem(4, false, false);
  1389. com->SetText(L"网口");
  1390. usb_layout->SetVisible(false);
  1391. wangkou_layout->SetVisible(true);
  1392. std::string setting_printer_wangkou_ip = CSetting::GetParam("setting_printer_wangkou_ip");
  1393. CEditUI* ip_edit = static_cast<CEditUI*>(m_pm.FindControl(_T("setting_printer_wangkou_ip")));
  1394. ip_edit->SetText(CLewaimaiString::UTF8ToUnicode(setting_printer_wangkou_ip).c_str());
  1395. }
  1396. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_quhuo_big")));
  1397. if(CSetting::GetParam("setting_printer_quhuo_big") == "1")
  1398. {
  1399. box->Selected(true, false);
  1400. }
  1401. else
  1402. {
  1403. box->Selected(false, false);
  1404. }
  1405. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_dingdanhao_big")));
  1406. if(CSetting::GetParam("setting_printer_dingdanhao_big") == "1")
  1407. {
  1408. box->Selected(true, false);
  1409. }
  1410. else
  1411. {
  1412. box->Selected(false, false);
  1413. }
  1414. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_xiadanshijian_big")));
  1415. if(CSetting::GetParam("setting_printer_xiadanshijian_big") == "1")
  1416. {
  1417. box->Selected(true, false);
  1418. }
  1419. else
  1420. {
  1421. box->Selected(false, false);
  1422. }
  1423. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_peisongshijian_big")));
  1424. if(CSetting::GetParam("setting_printer_peisongshijian_big") == "1")
  1425. {
  1426. box->Selected(true, false);
  1427. }
  1428. else
  1429. {
  1430. box->Selected(false, false);
  1431. }
  1432. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_name_big")));
  1433. if(CSetting::GetParam("setting_printer_name_big") == "1")
  1434. {
  1435. box->Selected(true, false);
  1436. }
  1437. else
  1438. {
  1439. box->Selected(false, false);
  1440. }
  1441. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_phone_big")));
  1442. if(CSetting::GetParam("setting_printer_phone_big") == "1")
  1443. {
  1444. box->Selected(true, false);
  1445. }
  1446. else
  1447. {
  1448. box->Selected(false, false);
  1449. }
  1450. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_address_big")));
  1451. if(CSetting::GetParam("setting_printer_address_big") == "1")
  1452. {
  1453. box->Selected(true, false);
  1454. }
  1455. else
  1456. {
  1457. box->Selected(false, false);
  1458. }
  1459. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_shangpin_big")));
  1460. if(CSetting::GetParam("setting_printer_shangpin_big") == "1")
  1461. {
  1462. box->Selected(true, false);
  1463. }
  1464. else
  1465. {
  1466. box->Selected(false, false);
  1467. }
  1468. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_memo_big")));
  1469. if(CSetting::GetParam("setting_printer_memo_big") == "1")
  1470. {
  1471. box->Selected(true, false);
  1472. }
  1473. else
  1474. {
  1475. box->Selected(false, false);
  1476. }
  1477. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_price_big")));
  1478. if(CSetting::GetParam("setting_printer_price_big") == "1")
  1479. {
  1480. box->Selected(true, false);
  1481. }
  1482. else
  1483. {
  1484. box->Selected(false, false);
  1485. }
  1486. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_pay_big")));
  1487. if(CSetting::GetParam("setting_printer_pay_big") == "1")
  1488. {
  1489. box->Selected(true, false);
  1490. }
  1491. else
  1492. {
  1493. box->Selected(false, false);
  1494. }
  1495. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_chufang_printer")));
  1496. if(CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
  1497. {
  1498. box->Selected(true, false);
  1499. }
  1500. else
  1501. {
  1502. box->Selected(false, false);
  1503. }
  1504. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_auto_start")));
  1505. if(CSetting::GetParam("setting_is_auto_start") == "1")
  1506. {
  1507. box->Selected(true, false);
  1508. }
  1509. else
  1510. {
  1511. box->Selected(false, false);
  1512. }
  1513. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_auto_login")));
  1514. if(CSetting::GetParam("setting_is_auto_login") == "1")
  1515. {
  1516. box->Selected(true, false);
  1517. }
  1518. else
  1519. {
  1520. box->Selected(false, false);
  1521. }
  1522. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_close_min")));
  1523. if(CSetting::GetParam("setting_is_close_min") == "1")
  1524. {
  1525. box->Selected(true, false);
  1526. }
  1527. else
  1528. {
  1529. box->Selected(false, false);
  1530. }
  1531. //这里开始,初始化厨房打印机的设置
  1532. CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
  1533. //获取当前店铺的商品分类信息,用于设置厨房打印机的分类打印
  1534. std::map<string, string> params;
  1535. std::string response;
  1536. std::string url = "/goodstype/getgoodstypelist";
  1537. CZhipuziHttpClient::Request(url.c_str(), params, response);
  1538. rapidjson::Document document;
  1539. document.Parse(response.c_str());
  1540. if(document.HasParseError())
  1541. {
  1542. LOG_INFO("parse response error!");
  1543. return;
  1544. }
  1545. if(!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
  1546. {
  1547. LOG_INFO("json error!");
  1548. return;
  1549. }
  1550. rapidjson::Value& v_errcode = document["errcode"];
  1551. int errcode = v_errcode.GetInt();
  1552. if(errcode != 0)
  1553. {
  1554. LOG_INFO("response failed! message:" << document["errmsg"].GetString());
  1555. return;
  1556. }
  1557. //获得数据成功,把分类信息保存起来
  1558. rapidjson::Value& data = document["data"];
  1559. rapidjson::Value& v_rows = data["goods_types"];
  1560. for(rapidjson::SizeType i = 0; i < v_rows.Size(); ++i)
  1561. {
  1562. rapidjson::Value& v_row_i = v_rows[i];
  1563. std::string type_id = v_row_i["type_id"].GetString();
  1564. std::string name = v_row_i["name"].GetString();
  1565. CSetting::AddFoodtype(name, type_id);
  1566. }
  1567. //获取厨房打印机的集合
  1568. std::vector<ChufangPrinter> printers = CSetting::getChufangPrints();
  1569. for(std::vector<ChufangPrinter>::iterator it = printers.begin(); it != printers.end(); it++)
  1570. {
  1571. ChufangPrinter newPrinter = *it;
  1572. CDialogBuilder builder;
  1573. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("setting_chufang_printer_item.xml"), (UINT)0, NULL, &m_pm));
  1574. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_name")));
  1575. pName->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.name).c_str());
  1576. CLabelUI* pIP = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_ip")));
  1577. pIP->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.ip).c_str());
  1578. CLabelUI* pGuige = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_guige")));
  1579. if(newPrinter.guige == "58")
  1580. {
  1581. pGuige->SetText(L"58mm");
  1582. }
  1583. else
  1584. {
  1585. pGuige->SetText(L"80mm");
  1586. }
  1587. CLabelUI* pFendan = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_fendan")));
  1588. if(newPrinter.fendan == "1")
  1589. {
  1590. pFendan->SetText(L"是");
  1591. }
  1592. else
  1593. {
  1594. pFendan->SetText(L"否");
  1595. }
  1596. CLabelUI* pFenlei = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei")));
  1597. if(newPrinter.fenlei == "1")
  1598. {
  1599. pFenlei->SetText(L"是");
  1600. }
  1601. else
  1602. {
  1603. pFenlei->SetText(L"否");
  1604. }
  1605. std::string foodtypeNames = "";
  1606. std::string foodtype_ids = newPrinter.fenlei_ids;
  1607. //这个是删除掉不存在的type_id之后的
  1608. std::string new_foodtype_ids = "";
  1609. std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
  1610. for(std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
  1611. {
  1612. std::string name = CSetting::getFoodtypeName((*it));
  1613. if(name == "zhipuzi_not_found_xxx")
  1614. {
  1615. //这种情况是以前保存的分类后来被删掉了
  1616. }
  1617. else
  1618. {
  1619. foodtypeNames += name + " ";
  1620. new_foodtype_ids += (*it) + ",";
  1621. }
  1622. }
  1623. //删掉不存在的type_id,更新内存和数据库
  1624. new_foodtype_ids = new_foodtype_ids.substr(0, new_foodtype_ids.length() - 1);
  1625. if(new_foodtype_ids.compare(foodtype_ids) != 0)
  1626. {
  1627. CSetting::UpdateChufangPrinter(newPrinter.date, newPrinter.name, newPrinter.ip, newPrinter.guige, newPrinter.fendan, newPrinter.fenlei, new_foodtype_ids, true);
  1628. }
  1629. foodtypeNames = foodtypeNames.substr(0, foodtypeNames.size() - 1);
  1630. std::wstring ws_foodtypeNames = CLewaimaiString::UTF8ToUnicode(foodtypeNames);
  1631. CLabelUI* pFenleiIds = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei_ids")));
  1632. pFenleiIds->SetText(ws_foodtypeNames.c_str());
  1633. //设置标记属性,用于修改时候匹配
  1634. pEle->AddCustomAttribute(L"date", CLewaimaiString::UTF8ToUnicode(newPrinter.date).c_str());
  1635. pPrinterList->Add(pEle);
  1636. }
  1637. }
  1638. void CMainWnd::LoginOut(int mode)
  1639. {
  1640. CSetting::SetParam("setting_is_auto_login", "0", true);
  1641. CLoginWnd* pLogin = new CLoginWnd();
  1642. if(pLogin == NULL)
  1643. {
  1644. return;
  1645. }
  1646. //设置模式
  1647. pLogin->SetMode(mode);
  1648. pLogin->Create(NULL, _T("乐外卖接单软件登录"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
  1649. pLogin->SetIcon(IDI_ICON_DUILIB);
  1650. pLogin->CenterWindow();
  1651. ::ShowWindow(*pLogin, SW_SHOWNORMAL);
  1652. Close();
  1653. }