CMainWnd.cpp 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838
  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_quhuo_big"))
  391. {
  392. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_quhuo_big")));
  393. if(box->IsSelected())
  394. {
  395. CSetting::SetParam("setting_printer_quhuo_big", "0");
  396. }
  397. else
  398. {
  399. CSetting::SetParam("setting_printer_quhuo_big", "1");
  400. }
  401. }
  402. else if(name == _T("setting_printer_dingdanhao_big"))
  403. {
  404. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_dingdanhao_big")));
  405. if(box->IsSelected())
  406. {
  407. CSetting::SetParam("setting_printer_dingdanhao_big", "0");
  408. }
  409. else
  410. {
  411. CSetting::SetParam("setting_printer_dingdanhao_big", "1");
  412. }
  413. }
  414. else if(name == _T("setting_printer_xiadanshijian_big"))
  415. {
  416. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_xiadanshijian_big")));
  417. if(box->IsSelected())
  418. {
  419. CSetting::SetParam("setting_printer_xiadanshijian_big", "0");
  420. }
  421. else
  422. {
  423. CSetting::SetParam("setting_printer_xiadanshijian_big", "1");
  424. }
  425. }
  426. else if(name == _T("setting_printer_peisongshijian_big"))
  427. {
  428. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_peisongshijian_big")));
  429. if(box->IsSelected())
  430. {
  431. CSetting::SetParam("setting_printer_peisongshijian_big", "0");
  432. }
  433. else
  434. {
  435. CSetting::SetParam("setting_printer_peisongshijian_big", "1");
  436. }
  437. }
  438. else if(name == _T("setting_printer_name_big"))
  439. {
  440. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_name_big")));
  441. if(box->IsSelected())
  442. {
  443. CSetting::SetParam("setting_printer_name_big", "0");
  444. }
  445. else
  446. {
  447. CSetting::SetParam("setting_printer_name_big", "1");
  448. }
  449. }
  450. else if(name == _T("setting_printer_phone_big"))
  451. {
  452. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_phone_big")));
  453. if(box->IsSelected())
  454. {
  455. CSetting::SetParam("setting_printer_phone_big", "0");
  456. }
  457. else
  458. {
  459. CSetting::SetParam("setting_printer_phone_big", "1");
  460. }
  461. }
  462. else if(name == _T("setting_printer_address_big"))
  463. {
  464. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_address_big")));
  465. if(box->IsSelected())
  466. {
  467. CSetting::SetParam("setting_printer_address_big", "0");
  468. }
  469. else
  470. {
  471. CSetting::SetParam("setting_printer_address_big", "1");
  472. }
  473. }
  474. else if(name == _T("setting_printer_shangpin_big"))
  475. {
  476. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_shangpin_big")));
  477. if(box->IsSelected())
  478. {
  479. CSetting::SetParam("setting_printer_shangpin_big", "0");
  480. }
  481. else
  482. {
  483. CSetting::SetParam("setting_printer_shangpin_big", "1");
  484. }
  485. }
  486. else if(name == _T("setting_printer_memo_big"))
  487. {
  488. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_memo_big")));
  489. if(box->IsSelected())
  490. {
  491. CSetting::SetParam("setting_printer_memo_big", "0");
  492. }
  493. else
  494. {
  495. CSetting::SetParam("setting_printer_memo_big", "1");
  496. }
  497. }
  498. else if(name == _T("setting_printer_price_big"))
  499. {
  500. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_price_big")));
  501. if(box->IsSelected())
  502. {
  503. CSetting::SetParam("setting_printer_price_big", "0");
  504. }
  505. else
  506. {
  507. CSetting::SetParam("setting_printer_price_big", "1");
  508. }
  509. }
  510. else if(name == _T("setting_printer_pay_big"))
  511. {
  512. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_pay_big")));
  513. if(box->IsSelected())
  514. {
  515. CSetting::SetParam("setting_printer_pay_big", "0");
  516. }
  517. else
  518. {
  519. CSetting::SetParam("setting_printer_pay_big", "1");
  520. }
  521. }
  522. else if(name == _T("setting_is_new_waimai_chufang_printer"))
  523. {
  524. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_chufang_printer")));
  525. if(box->IsSelected())
  526. {
  527. CSetting::SetParam("setting_is_new_waimai_chufang_printer", "0");
  528. }
  529. else
  530. {
  531. CSetting::SetParam("setting_is_new_waimai_chufang_printer", "1");
  532. }
  533. }
  534. else if(name == _T("setting_new_chufang_printer_btn"))
  535. {
  536. CChufangSettingWnd* pChufangFrame = new CChufangSettingWnd(1);
  537. if(pChufangFrame != NULL)
  538. {
  539. pChufangFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  540. pChufangFrame->SetIcon(IDI_ICON_DUILIB);
  541. pChufangFrame->CenterWindow();
  542. UINT ret = pChufangFrame->ShowModal();
  543. if(ret == IDOK)
  544. {
  545. //这个时候是点击保存返回了,厨房打印机的数据已经建立好了,这个时候刷新表格的显示
  546. CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
  547. //把最后一个厨房打印机取出来
  548. ChufangPrinter newPrinter = CSetting::getLastChufangPrinter();
  549. CDialogBuilder builder;
  550. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("setting_chufang_printer_item.xml"), (UINT)0, NULL, &m_pm));
  551. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_name")));
  552. pName->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.name).c_str());
  553. CLabelUI* pIP = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_ip")));
  554. pIP->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.ip).c_str());
  555. CLabelUI* pGuige = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_guige")));
  556. if(newPrinter.guige == "58")
  557. {
  558. pGuige->SetText(L"58mm");
  559. }
  560. else
  561. {
  562. pGuige->SetText(L"80mm");
  563. }
  564. CLabelUI* pFendan = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_fendan")));
  565. if(newPrinter.fendan == "1")
  566. {
  567. pFendan->SetText(L"是");
  568. }
  569. else
  570. {
  571. pFendan->SetText(L"否");
  572. }
  573. CLabelUI* pFenlei = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei")));
  574. if(newPrinter.fenlei == "1")
  575. {
  576. pFenlei->SetText(L"是");
  577. }
  578. else
  579. {
  580. pFenlei->SetText(L"否");
  581. }
  582. pEle->AddCustomAttribute(L"date", CLewaimaiString::UTF8ToUnicode(newPrinter.date).c_str());
  583. pPrinterList->Add(pEle);
  584. }
  585. }
  586. }
  587. else if(name == _T("setting_is_auto_start"))
  588. {
  589. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_auto_start")));
  590. if(box->IsSelected())
  591. {
  592. CSetting::SetParam("setting_is_auto_start", "0");
  593. CSystem::cancelAutoStart();
  594. }
  595. else
  596. {
  597. CSetting::SetParam("setting_is_auto_start", "1");
  598. CSystem::autostart();
  599. }
  600. }
  601. else if(name == _T("setting_is_auto_login"))
  602. {
  603. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_auto_login")));
  604. if(box->IsSelected())
  605. {
  606. CSetting::SetParam("setting_is_auto_login", "0");
  607. }
  608. else
  609. {
  610. CSetting::SetParam("setting_is_auto_login", "1");
  611. }
  612. }
  613. else if(name == _T("setting_is_close_min"))
  614. {
  615. CCheckBoxUI* box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_close_min")));
  616. if(box->IsSelected())
  617. {
  618. CSetting::SetParam("setting_is_close_min", "0");
  619. }
  620. else
  621. {
  622. CSetting::SetParam("setting_is_close_min", "1");
  623. }
  624. }
  625. else if(name == _T("setting_chufang_printer_item_update_btn"))
  626. {
  627. CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
  628. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(msg.pSender->GetParent()->GetParent()->GetParent());
  629. wstring date = pEle->GetCustomAttribute(L"date");
  630. CChufangSettingWnd* pChufangFrame = new CChufangSettingWnd(2);
  631. pChufangFrame->SetPrinterDate(CLewaimaiString::UnicodeToUTF8(date));
  632. if(pChufangFrame != NULL)
  633. {
  634. pChufangFrame->Create(this->GetHWND(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  635. pChufangFrame->SetIcon(IDI_ICON_DUILIB);
  636. pChufangFrame->CenterWindow();
  637. UINT ret = pChufangFrame->ShowModal();
  638. if(ret == IDOK)
  639. {
  640. //这个时候是点击保存返回了,厨房打印机的数据已经建立好了,这个时候刷新表格的显示
  641. CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
  642. ChufangPrinter newPrinter = CSetting::GetChufangPrinter(CLewaimaiString::UnicodeToUTF8(date));
  643. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_name")));
  644. pName->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.name).c_str());
  645. CLabelUI* pIP = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_ip")));
  646. pIP->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.ip).c_str());
  647. CLabelUI* pGuige = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_guige")));
  648. if(newPrinter.guige == "58")
  649. {
  650. pGuige->SetText(L"58mm");
  651. }
  652. else
  653. {
  654. pGuige->SetText(L"80mm");
  655. }
  656. CLabelUI* pFendan = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_fendan")));
  657. if(newPrinter.fendan == "1")
  658. {
  659. pFendan->SetText(L"是");
  660. }
  661. else
  662. {
  663. pFendan->SetText(L"否");
  664. }
  665. CLabelUI* pFenlei = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei")));
  666. if(newPrinter.fenlei == "1")
  667. {
  668. pFenlei->SetText(L"是");
  669. }
  670. else
  671. {
  672. pFenlei->SetText(L"否");
  673. }
  674. std::string foodtypeNames = "";
  675. std::string foodtype_ids = newPrinter.fenlei_ids;
  676. std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
  677. for(std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
  678. {
  679. std::string name = CSetting::getFoodtypeName((*it));
  680. std::wstring ws_name = CLewaimaiString::UTF8ToUnicode(name);
  681. if(name == "zhipuzi_not_found_xxx")
  682. {
  683. //这种情况是以前保存的分类后来被删掉了
  684. }
  685. else
  686. {
  687. foodtypeNames += name + " ";
  688. }
  689. }
  690. foodtypeNames = foodtypeNames.substr(0, foodtypeNames.size() - 1);
  691. std::wstring ws_foodtypeNames = CLewaimaiString::UTF8ToUnicode(foodtypeNames);
  692. CLabelUI* pFenleiIds = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei_ids")));
  693. pFenleiIds->SetText(ws_foodtypeNames.c_str());
  694. }
  695. }
  696. }
  697. else if(name == _T("setting_chufang_printer_item_delete_btn"))
  698. {
  699. CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
  700. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(msg.pSender->GetParent()->GetParent()->GetParent());
  701. wstring date = pEle->GetCustomAttribute(L"date");
  702. //获得了ID,这个时候从内存和数据库中分别删除对应的记录
  703. CSetting::DelChufangPrinter(CLewaimaiString::UnicodeToUTF8(date));
  704. pPrinterList->Remove(pEle);
  705. }
  706. else if(name == _T("setting_logout"))
  707. {
  708. //退出登录
  709. CSetting::SetParam("setting_is_auto_login", "0", true);
  710. CLoginWnd* pLogin = new CLoginWnd();
  711. if(pLogin == NULL)
  712. {
  713. return;
  714. }
  715. pLogin->Create(NULL, _T("智铺子收银软件登录"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
  716. pLogin->SetIcon(IDI_ICON_DUILIB);
  717. pLogin->CenterWindow();
  718. ::ShowWindow(*pLogin, SW_SHOWNORMAL);
  719. Close();
  720. }
  721. }
  722. void CMainWnd::HandleSelectChangeMsg(TNotifyUI& msg)
  723. {
  724. CDuiString name = msg.pSender->GetName();
  725. //先判断主页面的tab
  726. if(name == _T("main_waimai"))
  727. {
  728. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  729. if(pControl && pControl->GetCurSel() != 0)
  730. {
  731. pControl->SelectItem(0);
  732. }
  733. }
  734. else if(name == _T("main_setting"))
  735. {
  736. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  737. if(pControl && pControl->GetCurSel() != 2)
  738. {
  739. pControl->SelectItem(2);
  740. }
  741. }
  742. else if(name == _T("main_contact"))
  743. {
  744. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("switch")));
  745. if(pControl && pControl->GetCurSel() != 3)
  746. {
  747. pControl->SelectItem(3);
  748. }
  749. }
  750. //判断外卖的tab
  751. 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"))
  752. {
  753. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  754. //切换状态全部重新开始从第1页
  755. orderlist->SetPage(1);
  756. if(name == _T("waimai_open_switch"))
  757. {
  758. orderlist->SetStatus(1);
  759. }
  760. else if(name == _T("waimai_confirmed_switch"))
  761. {
  762. orderlist->SetStatus(2);
  763. }
  764. else if(name == _T("waimai_delivery_switch"))
  765. {
  766. orderlist->SetStatus(3);
  767. }
  768. else if(name == _T("waimai_success_switch"))
  769. {
  770. orderlist->SetStatus(4);
  771. }
  772. else if(name == _T("waimai_fail_switch"))
  773. {
  774. orderlist->SetStatus(5);
  775. }
  776. else if(name == _T("waimai_cancel_switch"))
  777. {
  778. orderlist->SetStatus(6);
  779. }
  780. else if(name == _T("waimai_refund_switch"))
  781. {
  782. orderlist->SetStatus(7);
  783. }
  784. orderlist->Refresh();
  785. }
  786. //判断设置中心的tab
  787. else if(name == _T("setting_waimai_order_switch"))
  788. {
  789. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("setting_switch")));
  790. pControl->SelectItem(0);
  791. }
  792. else if(name == _T("setting_printer_switch"))
  793. {
  794. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("setting_switch")));
  795. pControl->SelectItem(1);
  796. }
  797. else if(name == _T("setting_chufang_printer_switch"))
  798. {
  799. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("setting_switch")));
  800. pControl->SelectItem(2);
  801. }
  802. else if(name == _T("setting_system_switch"))
  803. {
  804. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("setting_switch")));
  805. pControl->SelectItem(3);
  806. }
  807. else if(name == _T("setting_system_about"))
  808. {
  809. CTabLayoutUI* pControl = static_cast<CTabLayoutUI*>(m_pm.FindControl(_T("setting_switch")));
  810. pControl->SelectItem(4);
  811. }
  812. }
  813. void CMainWnd::HandleItemSelectMsg(TNotifyUI& msg)
  814. {
  815. CDuiString name = msg.pSender->GetName();
  816. if(name == _T("setting_printer_guige"))
  817. {
  818. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_guige")));
  819. if(com->GetCurSel() == 0)
  820. {
  821. CSetting::SetParam("setting_printer_guige", "58");
  822. }
  823. else
  824. {
  825. CSetting::SetParam("setting_printer_guige", "80");
  826. }
  827. }
  828. else if(name == _T("setting_printer_lianshu"))
  829. {
  830. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_lianshu")));
  831. if(com->GetCurSel() == 0)
  832. {
  833. CSetting::SetParam("setting_printer_lianshu", "1");
  834. }
  835. else if(com->GetCurSel() == 1)
  836. {
  837. CSetting::SetParam("setting_printer_lianshu", "2");
  838. }
  839. else if(com->GetCurSel() == 2)
  840. {
  841. CSetting::SetParam("setting_printer_lianshu", "3");
  842. }
  843. else if(com->GetCurSel() == 3)
  844. {
  845. CSetting::SetParam("setting_printer_lianshu", "4");
  846. }
  847. }
  848. }
  849. LRESULT CMainWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  850. {
  851. LRESULT lRes = 0;
  852. BOOL bHandled = TRUE;
  853. switch(uMsg)
  854. {
  855. case WM_CREATE:
  856. lRes = OnCreate(uMsg, wParam, lParam, bHandled);
  857. break;
  858. case WM_CLOSE:
  859. lRes = OnClose(uMsg, wParam, lParam, bHandled);
  860. break;
  861. case WM_DESTROY:
  862. lRes = OnDestroy(uMsg, wParam, lParam, bHandled);
  863. break;
  864. case WM_NCACTIVATE:
  865. lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
  866. break;
  867. case WM_NCCALCSIZE:
  868. lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
  869. break;
  870. case WM_NCPAINT:
  871. lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
  872. break;
  873. case WM_NCHITTEST:
  874. lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
  875. break;
  876. case WM_SIZE:
  877. lRes = OnSize(uMsg, wParam, lParam, bHandled);
  878. break;
  879. case WM_GETMINMAXINFO:
  880. lRes = OnGetMinMaxInfo(uMsg, wParam, lParam, bHandled);
  881. break;
  882. case WM_SYSCOMMAND:
  883. lRes = OnSysCommand(uMsg, wParam, lParam, bHandled);
  884. break;
  885. case WM_SHOWTASK:
  886. lRes = OnTrayIcon(uMsg, wParam, lParam, bHandled);
  887. break;
  888. case WM_ORDERLIST_REFRESH:
  889. lRes = OnOrderlistRefresh(uMsg, wParam, lParam, bHandled);
  890. break;
  891. case WM_LOGIN_AGAIN_OUT:
  892. lRes = OnLoginOut(uMsg, wParam, lParam, bHandled);
  893. break;
  894. default:
  895. bHandled = FALSE;
  896. }
  897. if(bHandled)
  898. {
  899. return lRes;
  900. }
  901. if(m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
  902. {
  903. return lRes;
  904. }
  905. return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  906. }
  907. LRESULT CMainWnd::OnSysCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  908. {
  909. // 有时会在收到WM_NCDESTROY后收到wParam为SC_CLOSE的WM_SYSCOMMAND
  910. if(wParam == SC_CLOSE)
  911. {
  912. ::PostQuitMessage(0L);
  913. bHandled = TRUE;
  914. return 0;
  915. }
  916. BOOL bZoomed = ::IsZoomed(*this);
  917. LRESULT lRes = CWindowWnd::HandleMessage(uMsg, wParam, lParam);
  918. if(::IsZoomed(*this) != bZoomed)
  919. {
  920. if(!bZoomed)
  921. {
  922. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
  923. if(pControl)
  924. {
  925. pControl->SetVisible(false);
  926. }
  927. pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
  928. if(pControl)
  929. {
  930. pControl->SetVisible(true);
  931. }
  932. }
  933. else
  934. {
  935. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("maxbtn")));
  936. if(pControl)
  937. {
  938. pControl->SetVisible(true);
  939. }
  940. pControl = static_cast<CControlUI*>(m_pm.FindControl(_T("restorebtn")));
  941. if(pControl)
  942. {
  943. pControl->SetVisible(false);
  944. }
  945. }
  946. }
  947. return lRes;
  948. }
  949. LRESULT CMainWnd::OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  950. {
  951. int primaryMonitorWidth = ::GetSystemMetrics(SM_CXSCREEN);
  952. int primaryMonitorHeight = ::GetSystemMetrics(SM_CYSCREEN);
  953. MONITORINFO oMonitor = {};
  954. oMonitor.cbSize = sizeof(oMonitor);
  955. ::GetMonitorInfo(::MonitorFromWindow(*this, MONITOR_DEFAULTTOPRIMARY), &oMonitor);
  956. CDuiRect rcWork = oMonitor.rcWork;
  957. rcWork.Offset(-oMonitor.rcMonitor.left, -oMonitor.rcMonitor.top);
  958. if(rcWork.right > primaryMonitorWidth)
  959. {
  960. rcWork.right = primaryMonitorWidth;
  961. }
  962. if(rcWork.bottom > primaryMonitorHeight)
  963. {
  964. rcWork.right = primaryMonitorHeight;
  965. }
  966. LPMINMAXINFO lpMMI = (LPMINMAXINFO)lParam;
  967. lpMMI->ptMaxPosition.x = rcWork.left;
  968. lpMMI->ptMaxPosition.y = rcWork.top;
  969. lpMMI->ptMaxSize.x = rcWork.right;
  970. lpMMI->ptMaxSize.y = rcWork.bottom;
  971. bHandled = FALSE;
  972. return 0;
  973. }
  974. LRESULT CMainWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  975. {
  976. SIZE szRoundCorner = m_pm.GetRoundCorner();
  977. if(!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
  978. {
  979. CDuiRect rcWnd;
  980. ::GetWindowRect(*this, &rcWnd);
  981. rcWnd.Offset(-rcWnd.left, -rcWnd.top);
  982. rcWnd.right++;
  983. rcWnd.bottom++;
  984. HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
  985. ::SetWindowRgn(*this, hRgn, TRUE);
  986. ::DeleteObject(hRgn);
  987. }
  988. bHandled = FALSE;
  989. return 0;
  990. }
  991. LRESULT CMainWnd::OnClose(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  992. {
  993. bHandled = FALSE;
  994. return 0;
  995. }
  996. /*
  997. *这个是窗口被销毁的时候调用的
  998. **/
  999. LRESULT CMainWnd::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1000. {
  1001. //直接退出程序,或者退出登录都会执行这个
  1002. m_push->Stop();
  1003. bHandled = FALSE;
  1004. return 0;
  1005. }
  1006. LRESULT CMainWnd::OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1007. {
  1008. if(::IsIconic(*this))
  1009. {
  1010. bHandled = FALSE;
  1011. }
  1012. return (wParam == 0) ? TRUE : FALSE;
  1013. }
  1014. LRESULT CMainWnd::OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1015. {
  1016. return 0;
  1017. }
  1018. LRESULT CMainWnd::OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1019. {
  1020. return 0;
  1021. }
  1022. LRESULT CMainWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1023. {
  1024. POINT pt;
  1025. pt.x = GET_X_LPARAM(lParam);
  1026. pt.y = GET_Y_LPARAM(lParam);
  1027. ::ScreenToClient(*this, &pt);
  1028. RECT rcClient;
  1029. ::GetClientRect(*this, &rcClient);
  1030. if(!::IsZoomed(*this))
  1031. {
  1032. RECT rcSizeBox = m_pm.GetSizeBox();
  1033. if(pt.y < rcClient.top + rcSizeBox.top)
  1034. {
  1035. if(pt.x < rcClient.left + rcSizeBox.left)
  1036. {
  1037. return HTTOPLEFT;
  1038. }
  1039. if(pt.x > rcClient.right - rcSizeBox.right)
  1040. {
  1041. return HTTOPRIGHT;
  1042. }
  1043. return HTTOP;
  1044. }
  1045. else if(pt.y > rcClient.bottom - rcSizeBox.bottom)
  1046. {
  1047. if(pt.x < rcClient.left + rcSizeBox.left)
  1048. {
  1049. return HTBOTTOMLEFT;
  1050. }
  1051. if(pt.x > rcClient.right - rcSizeBox.right)
  1052. {
  1053. return HTBOTTOMRIGHT;
  1054. }
  1055. return HTBOTTOM;
  1056. }
  1057. if(pt.x < rcClient.left + rcSizeBox.left)
  1058. {
  1059. return HTLEFT;
  1060. }
  1061. if(pt.x > rcClient.right - rcSizeBox.right)
  1062. {
  1063. return HTRIGHT;
  1064. }
  1065. }
  1066. RECT rcCaption = m_pm.GetCaptionRect();
  1067. if(pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
  1068. && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
  1069. {
  1070. CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
  1071. if(pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0 &&
  1072. _tcscmp(pControl->GetClass(), DUI_CTR_OPTION) != 0 &&
  1073. _tcscmp(pControl->GetClass(), DUI_CTR_TEXT) != 0)
  1074. {
  1075. return HTCAPTION;
  1076. }
  1077. }
  1078. return HTCLIENT;
  1079. }
  1080. void CMainWnd::AddTrayIcon()
  1081. {
  1082. memset(&m_trayIcon, 0, sizeof(NOTIFYICONDATA));
  1083. m_trayIcon.cbSize = sizeof(NOTIFYICONDATA);
  1084. m_trayIcon.hIcon = ::LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON_DUILIB));
  1085. m_trayIcon.hWnd = m_hWnd;
  1086. lstrcpy(m_trayIcon.szTip, _T("智铺子收银软件"));
  1087. m_trayIcon.uCallbackMessage = WM_SHOWTASK;
  1088. m_trayIcon.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
  1089. Shell_NotifyIcon(NIM_ADD, &m_trayIcon);
  1090. ShowWindow(SW_HIDE);
  1091. }
  1092. LRESULT CMainWnd::OnTrayIcon(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1093. {
  1094. //如果在图标中单击左键则还原
  1095. if(lParam == WM_LBUTTONDOWN)
  1096. {
  1097. //删除托盘图标
  1098. Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
  1099. //显示主窗口
  1100. ShowWindow(SW_SHOWNORMAL);
  1101. //窗口最大化
  1102. SendMessage(WM_SYSCOMMAND, SC_MAXIMIZE, 0);
  1103. }
  1104. //如果在图标中单击右键则弹出声明式菜单
  1105. if(lParam == WM_RBUTTONDOWN)
  1106. {
  1107. //获取鼠标坐标
  1108. POINT pt;
  1109. GetCursorPos(&pt);
  1110. //右击后点别地可以清除“右击出来的菜单”
  1111. SetForegroundWindow(m_hWnd);
  1112. //托盘菜单 win32程序使用的是HMENU,如果是MFC程序可以使用CMenu
  1113. HMENU hMenu;
  1114. //生成托盘菜单
  1115. hMenu = CreatePopupMenu();
  1116. //添加菜单,关键在于设置的一个标识符 WM_ONCLOSE 点击后会用到
  1117. AppendMenu(hMenu, MF_STRING, WM_ONCLOSE, _T("退出"));
  1118. //弹出菜单,并把用户所选菜单项的标识符返回
  1119. int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, pt.x, pt.y, NULL, m_hWnd, NULL);
  1120. //如果标识符是WM_ONCLOSE则关闭
  1121. if(cmd == WM_ONCLOSE)
  1122. {
  1123. m_trayIcon.hIcon = NULL;
  1124. Shell_NotifyIcon(NIM_DELETE, &m_trayIcon);
  1125. //退出程序
  1126. ::PostQuitMessage(0);
  1127. }
  1128. }
  1129. bHandled = true;
  1130. return 0;
  1131. }
  1132. LRESULT CMainWnd::OnOrderlistRefresh(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1133. {
  1134. OrderListUI* orderlist = static_cast<OrderListUI*>(m_pm.FindControl(_T("orderlist")));
  1135. orderlist->DoRefresh();
  1136. return 1;
  1137. }
  1138. LRESULT CMainWnd::OnLoginOut(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  1139. {
  1140. LoginOut(2);
  1141. bHandled = true;
  1142. return 1;
  1143. }
  1144. void CMainWnd::InitSettingStatus()
  1145. {
  1146. CLabelUI* name_version = static_cast<CLabelUI*>(m_pm.FindControl(_T("main_name_version")));
  1147. name_version->SetText((L"智铺子收银软件 " + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
  1148. CLabelUI* version = static_cast<CLabelUI*>(m_pm.FindControl(_T("setting_version")));
  1149. version->SetText((L"版本号:" + CLewaimaiString::UTF8ToUnicode(CSystem::GetVersion())).c_str());
  1150. CCheckBoxUI* box = NULL;
  1151. CComboUI* com = NULL;
  1152. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_voice")));
  1153. if(CSetting::GetParam("setting_is_new_waimai_voice") == "1")
  1154. {
  1155. box->Selected(true, false);
  1156. }
  1157. else
  1158. {
  1159. box->Selected(false, false);
  1160. }
  1161. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_autoconfirm")));
  1162. if(CSetting::GetParam("setting_is_new_waimai_autoconfirm") == "1")
  1163. {
  1164. box->Selected(true, false);
  1165. }
  1166. else
  1167. {
  1168. box->Selected(false, false);
  1169. }
  1170. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_dialog")));
  1171. if(CSetting::GetParam("setting_is_new_waimai_dialog") == "1")
  1172. {
  1173. box->Selected(true, false);
  1174. }
  1175. else
  1176. {
  1177. box->Selected(false, false);
  1178. }
  1179. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_printer")));
  1180. if(CSetting::GetParam("setting_is_new_waimai_printer") == "1")
  1181. {
  1182. box->Selected(true, false);
  1183. }
  1184. else
  1185. {
  1186. box->Selected(false, false);
  1187. }
  1188. com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_guige")));
  1189. if(CSetting::GetParam("setting_printer_guige") == "58")
  1190. {
  1191. com->SetInternVisible(true);
  1192. com->SelectItem(0, false, false);
  1193. }
  1194. else
  1195. {
  1196. com->SetInternVisible(true);
  1197. com->SelectItem(1, false, false);
  1198. }
  1199. com = static_cast<CComboUI*>(m_pm.FindControl(_T("setting_printer_lianshu")));
  1200. std::string setting_printer_lianshu = CSetting::GetParam("setting_printer_lianshu");
  1201. if(setting_printer_lianshu == "1")
  1202. {
  1203. com->SetInternVisible(true);
  1204. com->SelectItem(0, false, false);
  1205. com->SetText(L"1联");
  1206. }
  1207. else if(setting_printer_lianshu == "2")
  1208. {
  1209. com->SetInternVisible(true);
  1210. com->SelectItem(1, false, false);
  1211. com->SetText(L"2联");
  1212. }
  1213. else if(setting_printer_lianshu == "3")
  1214. {
  1215. com->SetInternVisible(true);
  1216. com->SelectItem(2, false, false);
  1217. com->SetText(L"3联");
  1218. }
  1219. else if(setting_printer_lianshu == "4")
  1220. {
  1221. com->SetInternVisible(true);
  1222. com->SelectItem(3, false, false);
  1223. com->SetText(L"4联");
  1224. }
  1225. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_quhuo_big")));
  1226. if(CSetting::GetParam("setting_printer_quhuo_big") == "1")
  1227. {
  1228. box->Selected(true, false);
  1229. }
  1230. else
  1231. {
  1232. box->Selected(false, false);
  1233. }
  1234. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_dingdanhao_big")));
  1235. if(CSetting::GetParam("setting_printer_dingdanhao_big") == "1")
  1236. {
  1237. box->Selected(true, false);
  1238. }
  1239. else
  1240. {
  1241. box->Selected(false, false);
  1242. }
  1243. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_xiadanshijian_big")));
  1244. if(CSetting::GetParam("setting_printer_xiadanshijian_big") == "1")
  1245. {
  1246. box->Selected(true, false);
  1247. }
  1248. else
  1249. {
  1250. box->Selected(false, false);
  1251. }
  1252. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_peisongshijian_big")));
  1253. if(CSetting::GetParam("setting_printer_peisongshijian_big") == "1")
  1254. {
  1255. box->Selected(true, false);
  1256. }
  1257. else
  1258. {
  1259. box->Selected(false, false);
  1260. }
  1261. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_name_big")));
  1262. if(CSetting::GetParam("setting_printer_name_big") == "1")
  1263. {
  1264. box->Selected(true, false);
  1265. }
  1266. else
  1267. {
  1268. box->Selected(false, false);
  1269. }
  1270. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_phone_big")));
  1271. if(CSetting::GetParam("setting_printer_phone_big") == "1")
  1272. {
  1273. box->Selected(true, false);
  1274. }
  1275. else
  1276. {
  1277. box->Selected(false, false);
  1278. }
  1279. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_address_big")));
  1280. if(CSetting::GetParam("setting_printer_address_big") == "1")
  1281. {
  1282. box->Selected(true, false);
  1283. }
  1284. else
  1285. {
  1286. box->Selected(false, false);
  1287. }
  1288. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_shangpin_big")));
  1289. if(CSetting::GetParam("setting_printer_shangpin_big") == "1")
  1290. {
  1291. box->Selected(true, false);
  1292. }
  1293. else
  1294. {
  1295. box->Selected(false, false);
  1296. }
  1297. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_memo_big")));
  1298. if(CSetting::GetParam("setting_printer_memo_big") == "1")
  1299. {
  1300. box->Selected(true, false);
  1301. }
  1302. else
  1303. {
  1304. box->Selected(false, false);
  1305. }
  1306. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_price_big")));
  1307. if(CSetting::GetParam("setting_printer_price_big") == "1")
  1308. {
  1309. box->Selected(true, false);
  1310. }
  1311. else
  1312. {
  1313. box->Selected(false, false);
  1314. }
  1315. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_printer_pay_big")));
  1316. if(CSetting::GetParam("setting_printer_pay_big") == "1")
  1317. {
  1318. box->Selected(true, false);
  1319. }
  1320. else
  1321. {
  1322. box->Selected(false, false);
  1323. }
  1324. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_new_waimai_chufang_printer")));
  1325. if(CSetting::GetParam("setting_is_new_waimai_chufang_printer") == "1")
  1326. {
  1327. box->Selected(true, false);
  1328. }
  1329. else
  1330. {
  1331. box->Selected(false, false);
  1332. }
  1333. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_auto_start")));
  1334. if(CSetting::GetParam("setting_is_auto_start") == "1")
  1335. {
  1336. box->Selected(true, false);
  1337. }
  1338. else
  1339. {
  1340. box->Selected(false, false);
  1341. }
  1342. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_auto_login")));
  1343. if(CSetting::GetParam("setting_is_auto_login") == "1")
  1344. {
  1345. box->Selected(true, false);
  1346. }
  1347. else
  1348. {
  1349. box->Selected(false, false);
  1350. }
  1351. box = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("setting_is_close_min")));
  1352. if(CSetting::GetParam("setting_is_close_min") == "1")
  1353. {
  1354. box->Selected(true, false);
  1355. }
  1356. else
  1357. {
  1358. box->Selected(false, false);
  1359. }
  1360. //这里开始,初始化厨房打印机的设置
  1361. CListUI* pPrinterList = static_cast<CListUI*>(m_pm.FindControl(_T("setting_chufang_printer_list")));
  1362. //获取当前店铺的商品分类信息,用于设置厨房打印机的分类打印
  1363. std::map<string, string> params;
  1364. std::string response;
  1365. std::string url = "/goodstype/getgoodstypelist";
  1366. CZhipuziHttpClient::RequestOld(url.c_str(), params, response);
  1367. rapidjson::Document document;
  1368. document.Parse(response.c_str());
  1369. if(document.HasParseError())
  1370. {
  1371. LOG_INFO("parse response error!");
  1372. return;
  1373. }
  1374. if(!document.HasMember("errcode") || !document.HasMember("errmsg") || !document.HasMember("data"))
  1375. {
  1376. LOG_INFO("json error!");
  1377. return;
  1378. }
  1379. rapidjson::Value& v_errcode = document["errcode"];
  1380. int errcode = v_errcode.GetInt();
  1381. if(errcode != 0)
  1382. {
  1383. LOG_INFO("response failed! message:" << document["errmsg"].GetString());
  1384. return;
  1385. }
  1386. //获得数据成功,把分类信息保存起来
  1387. rapidjson::Value& data = document["data"];
  1388. rapidjson::Value& v_rows = data["goods_types"];
  1389. for(rapidjson::SizeType i = 0; i < v_rows.Size(); ++i)
  1390. {
  1391. rapidjson::Value& v_row_i = v_rows[i];
  1392. std::string type_id = v_row_i["type_id"].GetString();
  1393. std::string name = v_row_i["name"].GetString();
  1394. CSetting::AddFoodtype(name, type_id);
  1395. }
  1396. //获取厨房打印机的集合
  1397. std::vector<ChufangPrinter> printers = CSetting::getChufangPrints();
  1398. for(std::vector<ChufangPrinter>::iterator it = printers.begin(); it != printers.end(); it++)
  1399. {
  1400. ChufangPrinter newPrinter = *it;
  1401. CDialogBuilder builder;
  1402. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("setting_chufang_printer_item.xml"), (UINT)0, NULL, &m_pm));
  1403. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_name")));
  1404. pName->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.name).c_str());
  1405. CLabelUI* pIP = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_ip")));
  1406. pIP->SetText(CLewaimaiString::UTF8ToUnicode(newPrinter.ip).c_str());
  1407. CLabelUI* pGuige = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_guige")));
  1408. if(newPrinter.guige == "58")
  1409. {
  1410. pGuige->SetText(L"58mm");
  1411. }
  1412. else
  1413. {
  1414. pGuige->SetText(L"80mm");
  1415. }
  1416. CLabelUI* pFendan = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_fendan")));
  1417. if(newPrinter.fendan == "1")
  1418. {
  1419. pFendan->SetText(L"是");
  1420. }
  1421. else
  1422. {
  1423. pFendan->SetText(L"否");
  1424. }
  1425. CLabelUI* pFenlei = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei")));
  1426. if(newPrinter.fenlei == "1")
  1427. {
  1428. pFenlei->SetText(L"是");
  1429. }
  1430. else
  1431. {
  1432. pFenlei->SetText(L"否");
  1433. }
  1434. std::string foodtypeNames = "";
  1435. std::string foodtype_ids = newPrinter.fenlei_ids;
  1436. //这个是删除掉不存在的type_id之后的
  1437. std::string new_foodtype_ids = "";
  1438. std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
  1439. for(std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
  1440. {
  1441. std::string name = CSetting::getFoodtypeName((*it));
  1442. if(name == "zhipuzi_not_found_xxx")
  1443. {
  1444. //这种情况是以前保存的分类后来被删掉了
  1445. }
  1446. else
  1447. {
  1448. foodtypeNames += name + " ";
  1449. new_foodtype_ids += (*it) + ",";
  1450. }
  1451. }
  1452. //删掉不存在的type_id,更新内存和数据库
  1453. new_foodtype_ids = new_foodtype_ids.substr(0, new_foodtype_ids.length() - 1);
  1454. if(new_foodtype_ids.compare(foodtype_ids) != 0)
  1455. {
  1456. CSetting::UpdateChufangPrinter(newPrinter.date, newPrinter.name, newPrinter.ip, newPrinter.guige, newPrinter.fendan, newPrinter.fenlei, new_foodtype_ids, true);
  1457. }
  1458. foodtypeNames = foodtypeNames.substr(0, foodtypeNames.size() - 1);
  1459. std::wstring ws_foodtypeNames = CLewaimaiString::UTF8ToUnicode(foodtypeNames);
  1460. CLabelUI* pFenleiIds = static_cast<CLabelUI*>(pEle->FindSubControl(_T("setting_chufang_printer_item_fenlei_ids")));
  1461. pFenleiIds->SetText(ws_foodtypeNames.c_str());
  1462. //设置标记属性,用于修改时候匹配
  1463. pEle->AddCustomAttribute(L"date", CLewaimaiString::UTF8ToUnicode(newPrinter.date).c_str());
  1464. pPrinterList->Add(pEle);
  1465. }
  1466. }
  1467. void CMainWnd::LoginOut(int mode)
  1468. {
  1469. CSetting::SetParam("setting_is_auto_login", "0", true);
  1470. CLoginWnd* pLogin = new CLoginWnd();
  1471. if(pLogin == NULL)
  1472. {
  1473. return;
  1474. }
  1475. //设置模式
  1476. pLogin->SetMode(mode);
  1477. pLogin->Create(NULL, _T("乐外卖接单软件登录"), UI_WNDSTYLE_DIALOG, 0, 0, 0, 0, 0, NULL);
  1478. pLogin->SetIcon(IDI_ICON_DUILIB);
  1479. pLogin->CenterWindow();
  1480. ::ShowWindow(*pLogin, SW_SHOWNORMAL);
  1481. Close();
  1482. }