CChufangSettingWnd.h 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. void Notify(TNotifyUI& msg)
  117. {
  118. if(msg.sType == _T("click"))
  119. {
  120. DuiLib::CDuiString senderName = msg.pSender->GetName();
  121. if(senderName == _T("chufang_setting_closebtn"))
  122. {
  123. Close(IDCANCEL);
  124. return;
  125. }
  126. else if(senderName == _T("chufang_setting_save"))
  127. {
  128. //开始保存厨房打印机的数据
  129. CEditUI* pName = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
  130. wstring wsName = pName->GetText();
  131. CEditUI* pIP = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_ip")));
  132. wstring wsIP = pIP->GetText();
  133. //判断IP的格式是否合法
  134. if (CLewaimaiString::isIPAddressValid(CLewaimaiString::UnicodeToUTF8(wsIP).c_str()) == false)
  135. {
  136. //如果IP格式不合法,就提示
  137. CLabelUI* ip_error = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_ip_error")));
  138. ip_error->SetVisible(true);
  139. return;
  140. }
  141. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
  142. wstring wsGuige;
  143. if(com->GetCurSel() == 0)
  144. {
  145. wsGuige = L"58";
  146. }
  147. else
  148. {
  149. wsGuige = L"80";
  150. }
  151. CCheckBoxUI* pFendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
  152. wstring wsFendan;
  153. if(pFendan->IsSelected())
  154. {
  155. wsFendan = L"1";
  156. }
  157. else
  158. {
  159. wsFendan = L"0";
  160. }
  161. CCheckBoxUI* pFenlei = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fenlei")));
  162. wstring wsFenlei;
  163. if(pFenlei->IsSelected())
  164. {
  165. wsFenlei = L"1";
  166. }
  167. else
  168. {
  169. wsFenlei = L"0";
  170. }
  171. //保存数据到数据库
  172. std::string date = to_string(time(NULL));
  173. std::string name = CLewaimaiString::UnicodeToUTF8(wsName);
  174. std::string ip = CLewaimaiString::UnicodeToUTF8(wsIP);
  175. std::string guige = CLewaimaiString::UnicodeToUTF8(wsGuige);
  176. std::string fendan = CLewaimaiString::UnicodeToUTF8(wsFendan);
  177. std::string fenlei = CLewaimaiString::UnicodeToUTF8(wsFenlei);
  178. std::string fenlei_ids = "";
  179. if (m_mode == 1)
  180. {
  181. CSetting::AddChufangPrinter(date, name, ip, guige, fendan, fenlei, fenlei_ids, true);
  182. }
  183. else
  184. {
  185. CSetting::UpdateChufangPrinter(m_printer_date, name, ip, guige, fendan, fenlei, fenlei_ids, true);
  186. }
  187. Close(IDOK);
  188. return;
  189. }
  190. }
  191. }
  192. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  193. {
  194. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  195. styleValue &= ~WS_CAPTION;
  196. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  197. // 把自己的窗口句柄与窗口绘制管理器挂接在一起
  198. m_pm.Init(m_hWnd);
  199. m_pm.AddPreMessageFilter(this);
  200. CDialogBuilder builder;
  201. CControlUI* pRoot = builder.Create(_T("chufang_printer_setting.xml"), (UINT)0, NULL, &m_pm);
  202. ASSERT(pRoot && "Failed to parse XML");
  203. // 把这些控件绘制到本窗口上
  204. m_pm.AttachDialog(pRoot);
  205. // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
  206. m_pm.AddNotifier(this);
  207. Init();
  208. return 0;
  209. }
  210. LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  211. {
  212. if(::IsIconic(*this))
  213. {
  214. bHandled = FALSE;
  215. }
  216. return (wParam == 0) ? TRUE : FALSE;
  217. }
  218. LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  219. {
  220. return 0;
  221. }
  222. LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  223. {
  224. return 0;
  225. }
  226. LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  227. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  228. LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
  229. LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
  230. public:
  231. CPaintManagerUI m_pm;
  232. int m_mode; //为1表示新建,为2表示修改
  233. std::string m_printer_date; //修改模式下的打印机的日期
  234. };