CChufangSettingWnd.h 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  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* title = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_title")));
  32. if (m_mode == 1)
  33. {
  34. title->SetText(L"新建厨房打印机");
  35. }
  36. else
  37. {
  38. title->SetText(L"修改厨房打印机");
  39. }
  40. CEditUI* name = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
  41. if (m_mode == 1)
  42. {
  43. name->SetText(L"");
  44. }
  45. else
  46. {
  47. ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  48. name->SetText(CLewaimaiString::UTF8ToUnicode(updatePrinter.name).c_str());
  49. }
  50. CEditUI* ip = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_ip")));
  51. if (m_mode == 1)
  52. {
  53. ip->SetText(L"");
  54. }
  55. else
  56. {
  57. ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  58. ip->SetText(CLewaimaiString::UTF8ToUnicode(updatePrinter.ip).c_str());
  59. }
  60. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
  61. if (m_mode == 1)
  62. {
  63. com->SelectItem(0, false, false);
  64. }
  65. else
  66. {
  67. ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  68. if (updatePrinter.guige == "58")
  69. {
  70. com->SetInternVisible(true);
  71. com->SelectItem(0, false, false);
  72. }
  73. else
  74. {
  75. com->SetInternVisible(true);
  76. com->SelectItem(1, false, false);
  77. }
  78. }
  79. CCheckBoxUI* fendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
  80. if (m_mode == 1)
  81. {
  82. fendan->Selected(false, false);
  83. }
  84. else
  85. {
  86. ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  87. if (updatePrinter.fendan == "1")
  88. {
  89. fendan->Selected(true, false);
  90. }
  91. else
  92. {
  93. fendan->Selected(false, false);
  94. }
  95. }
  96. CCheckBoxUI* fenlei = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fenlei")));
  97. if (m_mode == 1)
  98. {
  99. fenlei->Selected(false, false);
  100. }
  101. else
  102. {
  103. ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
  104. if (updatePrinter.fenlei == "1")
  105. {
  106. fenlei->Selected(true, false);
  107. }
  108. else
  109. {
  110. fenlei->Selected(false, false);
  111. }
  112. }
  113. }
  114. void Notify(TNotifyUI& msg)
  115. {
  116. if(msg.sType == _T("click"))
  117. {
  118. DuiLib::CDuiString senderName = msg.pSender->GetName();
  119. if(senderName == _T("chufang_setting_closebtn"))
  120. {
  121. Close(IDCANCEL);
  122. return;
  123. }
  124. else if(senderName == _T("chufang_setting_save"))
  125. {
  126. //开始保存厨房打印机的数据
  127. CEditUI* pName = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
  128. wstring wsName = pName->GetText();
  129. CEditUI* pIP = static_cast<CEditUI*>(m_pm.FindControl(_T("chufang_setting_ip")));
  130. wstring wsIP = pIP->GetText();
  131. CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
  132. wstring wsGuige;
  133. if(com->GetCurSel() == 0)
  134. {
  135. wsGuige = L"58";
  136. }
  137. else
  138. {
  139. wsGuige = L"80";
  140. }
  141. CCheckBoxUI* pFendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
  142. wstring wsFendan;
  143. if(pFendan->IsSelected())
  144. {
  145. wsFendan = L"1";
  146. }
  147. else
  148. {
  149. wsFendan = L"0";
  150. }
  151. CCheckBoxUI* pFenlei = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fenlei")));
  152. wstring wsFenlei;
  153. if(pFenlei->IsSelected())
  154. {
  155. wsFenlei = L"1";
  156. }
  157. else
  158. {
  159. wsFenlei = L"0";
  160. }
  161. //保存数据到数据库
  162. std::string date = to_string(time(NULL));
  163. std::string name = CLewaimaiString::UnicodeToUTF8(wsName);
  164. std::string ip = CLewaimaiString::UnicodeToUTF8(wsIP);
  165. std::string guige = CLewaimaiString::UnicodeToUTF8(wsGuige);
  166. std::string fendan = CLewaimaiString::UnicodeToUTF8(wsFendan);
  167. std::string fenlei = CLewaimaiString::UnicodeToUTF8(wsFenlei);
  168. std::string fenlei_ids = "";
  169. if (m_mode == 1)
  170. {
  171. CSetting::AddChufangPrinter(date, name, ip, guige, fendan, fenlei, fenlei_ids, true);
  172. }
  173. else
  174. {
  175. CSetting::UpdateChufangPrinter(m_printer_date, name, ip, guige, fendan, fenlei, fenlei_ids, true);
  176. }
  177. Close(IDOK);
  178. return;
  179. }
  180. }
  181. }
  182. LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  183. {
  184. LONG styleValue = ::GetWindowLong(*this, GWL_STYLE);
  185. styleValue &= ~WS_CAPTION;
  186. ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN);
  187. // 把自己的窗口句柄与窗口绘制管理器挂接在一起
  188. m_pm.Init(m_hWnd);
  189. m_pm.AddPreMessageFilter(this);
  190. CDialogBuilder builder;
  191. CControlUI* pRoot = builder.Create(_T("chufang_printer_setting.xml"), (UINT)0, NULL, &m_pm);
  192. ASSERT(pRoot && "Failed to parse XML");
  193. // 把这些控件绘制到本窗口上
  194. m_pm.AttachDialog(pRoot);
  195. // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数
  196. m_pm.AddNotifier(this);
  197. Init();
  198. return 0;
  199. }
  200. LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  201. {
  202. if(::IsIconic(*this))
  203. {
  204. bHandled = FALSE;
  205. }
  206. return (wParam == 0) ? TRUE : FALSE;
  207. }
  208. LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  209. {
  210. return 0;
  211. }
  212. LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
  213. {
  214. return 0;
  215. }
  216. LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  217. LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
  218. LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam);
  219. LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled);
  220. public:
  221. CPaintManagerUI m_pm;
  222. int m_mode; //为1表示新建,为2表示修改
  223. std::string m_printer_date; //修改模式下的打印机的日期
  224. };