CChufangSettingWnd.h 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. #pragma once
  2. #include "../pch/pch.h"
  3. #include "CMainWnd.h"
  4. class CChufangSettingWnd : public CWindowWnd, public INotifyUI, public IMessageFilterUI
  5. {
  6. public:
  7. CChufangSettingWnd(int mode)
  8. {
  9. m_mode = mode;
  10. }
  11. void SetPrinterDate(std::string date)
  12. {
  13. m_printer_date = date;
  14. }
  15. LPCTSTR GetWindowClassName() const
  16. {
  17. return _T("UILoginFrame");
  18. };
  19. UINT GetClassStyle() const
  20. {
  21. return UI_CLASSSTYLE_DIALOG;
  22. };
  23. void OnFinalMessage(HWND /*hWnd*/)
  24. {
  25. //WindowImplBase::OnFinalMessage(hWnd);
  26. m_pm.RemovePreMessageFilter(this);
  27. delete this;
  28. };
  29. void Init()
  30. {
  31. CLabelUI* ip_error = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_ip_error")));
  32. ip_error->SetVisible(false);
  33. CLabelUI* title = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_title")));
  34. if (m_mode == 1)
  35. {
  36. title->SetText(L"新建厨房打印机");
  37. }
  38. else
  39. {
  40. title->SetText(L"修改厨房打印机");
  41. }
  42. CEditUI* name = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
  43. if (m_mode == 1)
  44. {
  45. name->SetText(L"");
  46. }
  47. else
  48. {
  49. ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  50. name->SetText(CLewaimaiString::UTF8ToUnicode(updatePrinter.name).c_str());
  51. }
  52. CEditUI* ip = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_ip")));
  53. if (m_mode == 1)
  54. {
  55. ip->SetText(L"");
  56. }
  57. else
  58. {
  59. ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  60. ip->SetText(CLewaimaiString::UTF8ToUnicode(updatePrinter.ip).c_str());
  61. }
  62. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
  63. if (m_mode == 1)
  64. {
  65. com->SelectItem(0, false, false);
  66. }
  67. else
  68. {
  69. ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  70. if (updatePrinter.guige == "58")
  71. {
  72. com->SetInternVisible(true);
  73. com->SelectItem(0, false, false);
  74. }
  75. else
  76. {
  77. com->SetInternVisible(true);
  78. com->SelectItem(1, false, false);
  79. }
  80. }
  81. CCheckBoxUI* fendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
  82. if (m_mode == 1)
  83. {
  84. fendan->Selected(false, false);
  85. }
  86. else
  87. {
  88. ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  89. if (updatePrinter.fendan == "1")
  90. {
  91. fendan->Selected(true, false);
  92. }
  93. else
  94. {
  95. fendan->Selected(false, false);
  96. }
  97. }
  98. CCheckBoxUI* fenlei = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fenlei")));
  99. if (m_mode == 1)
  100. {
  101. fenlei->Selected(false, false);
  102. }
  103. else
  104. {
  105. ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  106. if (updatePrinter.fenlei == "1")
  107. {
  108. fenlei->Selected(true, false);
  109. }
  110. else
  111. {
  112. fenlei->Selected(false, false);
  113. }
  114. }
  115. //把所有分类显示出来
  116. CVerticalLayoutUI* pLayout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze_area")));
  117. pLayout->RemoveAll();
  118. ChufangPrinter updatePrinter;
  119. //这个map用于后面判断每个分类ID是否被选中
  120. std::map<string, bool> ids_map;
  121. if (m_mode == 2)
  122. {
  123. updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  124. std::string foodtype_ids = updatePrinter.fenlei_ids;
  125. std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
  126. for (std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
  127. {
  128. ids_map[(*it)] = true;
  129. }
  130. }
  131. std::vector<FoodType> foodtypes = CSetting::GetFoodtype();
  132. for (std::vector<FoodType>::iterator it = foodtypes.begin(); it != foodtypes.end(); it++)
  133. {
  134. CDialogBuilder builder;
  135. CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("chufang_printer_setting_fenlei_select.xml"), (UINT)0, NULL, &m_pm));
  136. CCheckBoxUI* pCheck = static_cast<CCheckBoxUI*>(pEle->FindSubControl(_T("chufang_setting_fenleli_xuanze_checkbox")));
  137. pCheck->AddCustomAttribute(L"type_id", CLewaimaiString::UTF8ToUnicode((*it).type_id).c_str());
  138. if (m_mode == 2)
  139. {
  140. if (ids_map.find((*it).type_id) != ids_map.end())
  141. {
  142. pCheck->Selected(true, false);
  143. }
  144. }
  145. CLabelUI* pName = static_cast<CLabelUI*>(pEle->FindSubControl(_T("chufang_setting_fenleli_xuanze_name")));
  146. pName->SetText(CLewaimaiString::UTF8ToUnicode((*it).name).c_str());
  147. pLayout->Add(pEle);
  148. }
  149. CVerticalLayoutUI* pOutLayout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze")));
  150. pOutLayout->SetFixedHeight(foodtypes.size() * 30 + 30);
  151. }
  152. void Notify(TNotifyUI& msg)
  153. {
  154. if(msg.sType == _T("click"))
  155. {
  156. DuiLib::CDuiString senderName = msg.pSender->GetName();
  157. if(senderName == _T("chufang_setting_closebtn"))
  158. {
  159. Close(IDCANCEL);
  160. return;
  161. }
  162. else if(senderName == _T("chufang_setting_save"))
  163. {
  164. //开始保存厨房打印机的数据
  165. CEditUI* pName = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
  166. wstring wsName = pName->GetText();
  167. CEditUI* pIP = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_ip")));
  168. wstring wsIP = pIP->GetText();
  169. //判断IP的格式是否合法
  170. if (CLewaimaiString::isIPAddressValid(CLewaimaiString::UnicodeToUTF8(wsIP).c_str()) == false)
  171. {
  172. //如果IP格式不合法,就提示
  173. CLabelUI* ip_error = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_ip_error")));
  174. ip_error->SetVisible(true);
  175. return;
  176. }
  177. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
  178. wstring wsGuige;
  179. if(com->GetCurSel() == 0)
  180. {
  181. wsGuige = L"58";
  182. }
  183. else
  184. {
  185. wsGuige = L"80";
  186. }
  187. CCheckBoxUI* pFendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
  188. wstring wsFendan;
  189. if(pFendan->IsSelected())
  190. {
  191. wsFendan = L"1";
  192. }
  193. else
  194. {
  195. wsFendan = L"0";
  196. }
  197. CCheckBoxUI* pFenlei = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fenlei")));
  198. wstring wsFenlei;
  199. if(pFenlei->IsSelected())
  200. {
  201. wsFenlei = L"1";
  202. }
  203. else
  204. {
  205. wsFenlei = L"0";
  206. }
  207. std::string fenlei_ids = "";
  208. CVerticalLayoutUI* pLayout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze_area")));
  209. CDuiPtrArray* pArray = m_pm.FindSubControlsByClass(pLayout, _T("CheckBox"));
  210. int size = pArray->GetSize();
  211. for (int i = 0; i < size; i++)
  212. {
  213. CCheckBoxUI* pBox = static_cast<CCheckBoxUI*>(pArray->GetAt(i));
  214. if (pBox->IsSelected())
  215. {
  216. std::wstring ws_type_id = pBox->GetCustomAttribute(_T("type_id"));
  217. std::string type_id = CLewaimaiString::UnicodeToUTF8(ws_type_id);
  218. fenlei_ids += type_id + ",";
  219. }
  220. }
  221. fenlei_ids = fenlei_ids.substr(0, fenlei_ids.size() - 1);
  222. //保存数据到数据库
  223. std::string date = to_string(time(NULL));
  224. std::string name = CLewaimaiString::UnicodeToUTF8(wsName);
  225. std::string ip = CLewaimaiString::UnicodeToUTF8(wsIP);
  226. std::string guige = CLewaimaiString::UnicodeToUTF8(wsGuige);
  227. std::string fendan = CLewaimaiString::UnicodeToUTF8(wsFendan);
  228. std::string fenlei = CLewaimaiString::UnicodeToUTF8(wsFenlei);
  229. if (m_mode == 1)
  230. {
  231. CSetting::AddChufangPrinter(date, name, ip, guige, fendan, fenlei, fenlei_ids, true);
  232. }
  233. else
  234. {
  235. CSetting::UpdateChufangPrinter(m_printer_date, name, ip, guige, fendan, fenlei, fenlei_ids, true);
  236. }
  237. Close(IDOK);
  238. return;
  239. }
  240. }
  241. }
  242. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  243. {
  244. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  245. styleValue &= ~WS_CAPTION;
  246. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  247. // 把自己的窗口句柄与窗口绘制管理器挂接在一起
  248. m_pm.Init(m_hWnd);
  249. m_pm.AddPreMessageFilter(this);
  250. CDialogBuilder builder;
  251. CControlUI* pRoot = builder.Create(_T("chufang_printer_setting.xml"), (UINT)0, NULL, &m_pm);
  252. ASSERT(pRoot && "Failed to parse XML");
  253. // 把这些控件绘制到本窗口上
  254. m_pm.AttachDialog(pRoot);
  255. // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
  256. m_pm.AddNotifier(this);
  257. Init();
  258. return 0;
  259. }
  260. LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  261. {
  262. if(::IsIconic(*this))
  263. {
  264. bHandled = FALSE;
  265. }
  266. return (wParam == 0) ? TRUE : FALSE;
  267. }
  268. LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  269. {
  270. return 0;
  271. }
  272. LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  273. {
  274. return 0;
  275. }
  276. LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  277. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  278. LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
  279. LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
  280. public:
  281. CPaintManagerUI m_pm;
  282. int m_mode; //为1表示新建,为2表示修改
  283. std::string m_printer_date; //修改模式下的打印机的日期
  284. };