#pragma once #include "../pch/pch.h" #include "CMainWnd.h" class CChufangSettingWnd : public CWindowWnd, public INotifyUI, public IMessageFilterUI { public: CChufangSettingWnd(int mode) { m_mode = mode; } void SetPrinterDate(std::string date) { m_printer_date = date; } LPCTSTR GetWindowClassName() const { return _T("UILoginFrame"); }; UINT GetClassStyle() const { return UI_CLASSSTYLE_DIALOG; }; void OnFinalMessage(HWND /*hWnd*/) { //WindowImplBase::OnFinalMessage(hWnd); m_pm.RemovePreMessageFilter(this); delete this; }; void Init() { CLabelUI* ip_error = static_cast(m_pm.FindControl(_T("chufang_setting_ip_error"))); ip_error->SetVisible(false); CLabelUI* title = static_cast(m_pm.FindControl(_T("chufang_setting_title"))); if (m_mode == 1) { title->SetText(L"新建厨房打印机"); } else { title->SetText(L"修改厨房打印机"); } CEditUI* name = static_cast(m_pm.FindControl(_T("chufang_setting_name"))); if (m_mode == 1) { name->SetText(L""); } else { ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date); name->SetText(CLewaimaiString::UTF8ToUnicode(updatePrinter.name).c_str()); } CEditUI* ip = static_cast(m_pm.FindControl(_T("chufang_setting_ip"))); if (m_mode == 1) { ip->SetText(L""); } else { ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date); ip->SetText(CLewaimaiString::UTF8ToUnicode(updatePrinter.ip).c_str()); } CComboUI* com = static_cast(m_pm.FindControl(_T("chufang_setting_guige"))); if (m_mode == 1) { com->SelectItem(0, false, false); } else { ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date); if (updatePrinter.guige == "58") { com->SetInternVisible(true); com->SelectItem(0, false, false); } else { com->SetInternVisible(true); com->SelectItem(1, false, false); } } CCheckBoxUI* fendan = static_cast(m_pm.FindControl(_T("chufang_setting_fendan"))); if (m_mode == 1) { fendan->Selected(false, false); } else { ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date); if (updatePrinter.fendan == "1") { fendan->Selected(true, false); } else { fendan->Selected(false, false); } } CCheckBoxUI* fenlei = static_cast(m_pm.FindControl(_T("chufang_setting_fenlei"))); if (m_mode == 1) { fenlei->Selected(false, false); } else { ChufangPrinter updatePrinter = CSetting::GetChufangPrinter(m_printer_date); if (updatePrinter.fenlei == "1") { fenlei->Selected(true, false); } else { fenlei->Selected(false, false); } } //把所有分类显示出来 CVerticalLayoutUI* pLayout = static_cast(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze_area"))); pLayout->RemoveAll(); ChufangPrinter updatePrinter; //这个map用于后面判断每个分类ID是否被选中 std::map ids_map; if (m_mode == 2) { updatePrinter = CSetting::GetChufangPrinter(m_printer_date); std::string foodtype_ids = updatePrinter.fenlei_ids; std::vector ids = CLewaimaiString::Split(foodtype_ids, ","); for (std::vector::iterator it = ids.begin(); it != ids.end(); it++) { ids_map[(*it)] = true; } } std::vector foodtypes = CSetting::GetFoodtype(); for (std::vector::iterator it = foodtypes.begin(); it != foodtypes.end(); it++) { CDialogBuilder builder; CListContainerElementUI* pEle = static_cast(builder.Create(_T("chufang_printer_setting_fenlei_select.xml"), (UINT)0, NULL, &m_pm)); CCheckBoxUI* pCheck = static_cast(pEle->FindSubControl(_T("chufang_setting_fenleli_xuanze_checkbox"))); pCheck->AddCustomAttribute(L"type_id", CLewaimaiString::UTF8ToUnicode((*it).type_id).c_str()); if (m_mode == 2) { if (ids_map.find((*it).type_id) != ids_map.end()) { pCheck->Selected(true, false); } } CLabelUI* pName = static_cast(pEle->FindSubControl(_T("chufang_setting_fenleli_xuanze_name"))); pName->SetText(CLewaimaiString::UTF8ToUnicode((*it).name).c_str()); pLayout->Add(pEle); } CVerticalLayoutUI* pOutLayout = static_cast(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze"))); pOutLayout->SetFixedHeight(foodtypes.size() * 30 + 30); } void Notify(TNotifyUI& msg) { if(msg.sType == _T("click")) { DuiLib::CDuiString senderName = msg.pSender->GetName(); if(senderName == _T("chufang_setting_closebtn")) { Close(IDCANCEL); return; } else if(senderName == _T("chufang_setting_save")) { //开始保存厨房打印机的数据 CEditUI* pName = static_cast(m_pm.FindControl(_T("chufang_setting_name"))); wstring wsName = pName->GetText(); CEditUI* pIP = static_cast(m_pm.FindControl(_T("chufang_setting_ip"))); wstring wsIP = pIP->GetText(); //判断IP的格式是否合法 if (CLewaimaiString::isIPAddressValid(CLewaimaiString::UnicodeToUTF8(wsIP).c_str()) == false) { //如果IP格式不合法,就提示 CLabelUI* ip_error = static_cast(m_pm.FindControl(_T("chufang_setting_ip_error"))); ip_error->SetVisible(true); return; } CComboUI* com = static_cast(m_pm.FindControl(_T("chufang_setting_guige"))); wstring wsGuige; if(com->GetCurSel() == 0) { wsGuige = L"58"; } else { wsGuige = L"80"; } CCheckBoxUI* pFendan = static_cast(m_pm.FindControl(_T("chufang_setting_fendan"))); wstring wsFendan; if(pFendan->IsSelected()) { wsFendan = L"1"; } else { wsFendan = L"0"; } CCheckBoxUI* pFenlei = static_cast(m_pm.FindControl(_T("chufang_setting_fenlei"))); wstring wsFenlei; if(pFenlei->IsSelected()) { wsFenlei = L"1"; } else { wsFenlei = L"0"; } std::string fenlei_ids = ""; CVerticalLayoutUI* pLayout = static_cast(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze_area"))); CDuiPtrArray* pArray = m_pm.FindSubControlsByClass(pLayout, _T("CheckBox")); int size = pArray->GetSize(); for (int i = 0; i < size; i++) { CCheckBoxUI* pBox = static_cast(pArray->GetAt(i)); if (pBox->IsSelected()) { std::wstring ws_type_id = pBox->GetCustomAttribute(_T("type_id")); std::string type_id = CLewaimaiString::UnicodeToUTF8(ws_type_id); fenlei_ids += type_id + ","; } } fenlei_ids = fenlei_ids.substr(0, fenlei_ids.size() - 1); //保存数据到数据库 std::string date = to_string(time(NULL)); std::string name = CLewaimaiString::UnicodeToUTF8(wsName); std::string ip = CLewaimaiString::UnicodeToUTF8(wsIP); std::string guige = CLewaimaiString::UnicodeToUTF8(wsGuige); std::string fendan = CLewaimaiString::UnicodeToUTF8(wsFendan); std::string fenlei = CLewaimaiString::UnicodeToUTF8(wsFenlei); if (m_mode == 1) { CSetting::AddChufangPrinter(date, name, ip, guige, fendan, fenlei, fenlei_ids, true); } else { CSetting::UpdateChufangPrinter(m_printer_date, name, ip, guige, fendan, fenlei, fenlei_ids, true); } Close(IDOK); return; } } } LRESULT OnCreate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { LONG styleValue = ::GetWindowLong(*this, GWL_STYLE); styleValue &= ~WS_CAPTION; ::SetWindowLong(*this, GWL_STYLE, styleValue | WS_CLIPSIBLINGS | WS_CLIPCHILDREN); // 把自己的窗口句柄与窗口绘制管理器挂接在一起 m_pm.Init(m_hWnd); m_pm.AddPreMessageFilter(this); CDialogBuilder builder; CControlUI* pRoot = builder.Create(_T("chufang_printer_setting.xml"), (UINT)0, NULL, &m_pm); ASSERT(pRoot && "Failed to parse XML"); // 把这些控件绘制到本窗口上 m_pm.AttachDialog(pRoot); // 把自己加入到CPaintManagerUI的m_aNotifiers数组中,用于处理Notify函数 m_pm.AddNotifier(this); Init(); return 0; } LRESULT OnNcActivate(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { if(::IsIconic(*this)) { bHandled = FALSE; } return (wParam == 0) ? TRUE : FALSE; } LRESULT OnNcCalcSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { return 0; } LRESULT OnNcPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled) { return 0; } LRESULT OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled); LRESULT HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam); LRESULT MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled); public: CPaintManagerUI m_pm; int m_mode; //为1表示新建,为2表示修改 std::string m_printer_date; //修改模式下的打印机的日期 };