CChufangSettingWnd.h 6.4 KB

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