| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- #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<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_ip_error")));
- ip_error->SetVisible(false);
- CLabelUI* title = static_cast<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_title")));
- if (m_mode == 1)
- {
- title->SetText(L"新建厨房打印机");
- }
- else
- {
- title->SetText(L"修改厨房打印机");
- }
- CEditUI* name = static_cast<CEditUI*>(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<CEditUI*>(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<CComboUI*>(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<CCheckBoxUI*>(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<CCheckBoxUI*>(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<CVerticalLayoutUI*>(m_pm.FindControl(_T("chufang_setting_fenlei_xuanze_area")));
- pLayout->RemoveAll();
- ChufangPrinter updatePrinter;
- //这个map用于后面判断每个分类ID是否被选中
- std::map<string, bool> ids_map;
- if (m_mode == 2)
- {
- updatePrinter = CSetting::GetChufangPrinter(m_printer_date);
- std::string foodtype_ids = updatePrinter.fenlei_ids;
- std::vector<string> ids = CLewaimaiString::Split(foodtype_ids, ",");
- for (std::vector<string>::iterator it = ids.begin(); it != ids.end(); it++)
- {
- ids_map[(*it)] = true;
- }
- }
- std::vector<FoodType> foodtypes = CSetting::GetFoodtype();
- for (std::vector<FoodType>::iterator it = foodtypes.begin(); it != foodtypes.end(); it++)
- {
- CDialogBuilder builder;
- CListContainerElementUI* pEle = static_cast<CListContainerElementUI*>(builder.Create(_T("chufang_printer_setting_fenlei_select.xml"), (UINT)0, NULL, &m_pm));
- CCheckBoxUI* pCheck = static_cast<CCheckBoxUI*>(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<CLabelUI*>(pEle->FindSubControl(_T("chufang_setting_fenleli_xuanze_name")));
- pName->SetText(CLewaimaiString::UTF8ToUnicode((*it).name).c_str());
- pLayout->Add(pEle);
- }
- CVerticalLayoutUI* pOutLayout = static_cast<CVerticalLayoutUI*>(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<CEditUI*>(m_pm.FindControl(_T("chufang_setting_name")));
- wstring wsName = pName->GetText();
- CEditUI* pIP = static_cast<CEditUI*>(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<CLabelUI*>(m_pm.FindControl(_T("chufang_setting_ip_error")));
- ip_error->SetVisible(true);
- return;
- }
- CComboUI* com = static_cast<CComboUI*>(m_pm.FindControl(_T("chufang_setting_guige")));
- wstring wsGuige;
- if(com->GetCurSel() == 0)
- {
- wsGuige = L"58";
- }
- else
- {
- wsGuige = L"80";
- }
- CCheckBoxUI* pFendan = static_cast<CCheckBoxUI*>(m_pm.FindControl(_T("chufang_setting_fendan")));
- wstring wsFendan;
- if(pFendan->IsSelected())
- {
- wsFendan = L"1";
- }
- else
- {
- wsFendan = L"0";
- }
- CCheckBoxUI* pFenlei = static_cast<CCheckBoxUI*>(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<CVerticalLayoutUI*>(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<CCheckBoxUI*>(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; //修改模式下的打印机的日期
- };
|