|
|
@@ -0,0 +1,302 @@
|
|
|
+#include "../pch/pch.h"
|
|
|
+#include "CZhengcanSaomadiancanWnd.h"
|
|
|
+
|
|
|
+#include "../page/CDiandanPageUI.h"
|
|
|
+
|
|
|
+LRESULT CZhengcanSaomadiancanWnd::OnNcHitTest(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
+{
|
|
|
+ POINT pt;
|
|
|
+ pt.x = GET_X_LPARAM(lParam);
|
|
|
+ pt.y = GET_Y_LPARAM(lParam);
|
|
|
+ ::ScreenToClient(*this, &pt);
|
|
|
+
|
|
|
+ RECT rcClient;
|
|
|
+ ::GetClientRect(*this, &rcClient);
|
|
|
+
|
|
|
+ RECT rcCaption = m_pm.GetCaptionRect();
|
|
|
+ if (pt.x >= rcClient.left + rcCaption.left && pt.x < rcClient.right - rcCaption.right \
|
|
|
+ && pt.y >= rcCaption.top && pt.y < rcCaption.bottom)
|
|
|
+ {
|
|
|
+ CControlUI* pControl = static_cast<CControlUI*>(m_pm.FindControl(pt));
|
|
|
+ if (pControl && _tcscmp(pControl->GetClass(), DUI_CTR_BUTTON) != 0)
|
|
|
+ {
|
|
|
+ return HTCAPTION;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return HTCLIENT;
|
|
|
+}
|
|
|
+
|
|
|
+LRESULT CZhengcanSaomadiancanWnd::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
|
|
|
+{
|
|
|
+ SIZE szRoundCorner = m_pm.GetRoundCorner();
|
|
|
+ if (!::IsIconic(*this) && (szRoundCorner.cx != 0 || szRoundCorner.cy != 0))
|
|
|
+ {
|
|
|
+ CDuiRect rcWnd;
|
|
|
+ ::GetWindowRect(*this, &rcWnd);
|
|
|
+ rcWnd.Offset(-rcWnd.left, -rcWnd.top);
|
|
|
+ rcWnd.right++;
|
|
|
+ rcWnd.bottom++;
|
|
|
+ HRGN hRgn = ::CreateRoundRectRgn(rcWnd.left, rcWnd.top, rcWnd.right, rcWnd.bottom, szRoundCorner.cx, szRoundCorner.cy);
|
|
|
+ ::SetWindowRgn(*this, hRgn, TRUE);
|
|
|
+ ::DeleteObject(hRgn);
|
|
|
+ }
|
|
|
+
|
|
|
+ bHandled = FALSE;
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+LRESULT CZhengcanSaomadiancanWnd::HandleMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
|
|
|
+{
|
|
|
+ LRESULT lRes = 0;
|
|
|
+ BOOL bHandled = TRUE;
|
|
|
+ switch (uMsg)
|
|
|
+ {
|
|
|
+ case WM_CREATE:
|
|
|
+ lRes = OnCreate(uMsg, wParam, lParam, bHandled);
|
|
|
+ break;
|
|
|
+ case WM_NCACTIVATE:
|
|
|
+ lRes = OnNcActivate(uMsg, wParam, lParam, bHandled);
|
|
|
+ break;
|
|
|
+ case WM_NCCALCSIZE:
|
|
|
+ lRes = OnNcCalcSize(uMsg, wParam, lParam, bHandled);
|
|
|
+ break;
|
|
|
+ case WM_NCPAINT:
|
|
|
+ lRes = OnNcPaint(uMsg, wParam, lParam, bHandled);
|
|
|
+ break;
|
|
|
+ case WM_NCHITTEST:
|
|
|
+ lRes = OnNcHitTest(uMsg, wParam, lParam, bHandled);
|
|
|
+ break;
|
|
|
+ case WM_SIZE:
|
|
|
+ lRes = OnSize(uMsg, wParam, lParam, bHandled);
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ bHandled = FALSE;
|
|
|
+ }
|
|
|
+ if (bHandled)
|
|
|
+ {
|
|
|
+ return lRes;
|
|
|
+ }
|
|
|
+ if (m_pm.MessageHandler(uMsg, wParam, lParam, lRes))
|
|
|
+ {
|
|
|
+ return lRes;
|
|
|
+ }
|
|
|
+ return CWindowWnd::HandleMessage(uMsg, wParam, lParam);
|
|
|
+}
|
|
|
+
|
|
|
+LRESULT CZhengcanSaomadiancanWnd::MessageHandler(UINT uMsg, WPARAM wParam, LPARAM lParam, bool& bHandled)
|
|
|
+{
|
|
|
+ if (uMsg == WM_KEYDOWN)
|
|
|
+ {
|
|
|
+ if (wParam == VK_RETURN)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ else if (wParam == VK_ESCAPE)
|
|
|
+ {
|
|
|
+ Close(IDCANCEL);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return false;
|
|
|
+}
|
|
|
+
|
|
|
+LRESULT CZhengcanSaomadiancanWnd::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("zhengcan_saomadiancan_wnd.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;
|
|
|
+}
|
|
|
+
|
|
|
+void CZhengcanSaomadiancanWnd::Notify(TNotifyUI& msg)
|
|
|
+{
|
|
|
+ if (msg.sType == _T("click"))
|
|
|
+ {
|
|
|
+ DuiLib::CDuiString senderName = msg.pSender->GetName();
|
|
|
+
|
|
|
+ if (senderName == _T("closebtn"))
|
|
|
+ {
|
|
|
+ Close(IDCANCEL);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ else if (senderName == _T("save"))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (senderName == _T("zhengcan_saomadiancanorder_delete"))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+ else if (senderName == _T("zhengcan_saomadiancanorder_queren"))
|
|
|
+ {
|
|
|
+
|
|
|
+
|
|
|
+ Close(IDOK);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (msg.sType == _T("textchanged"))
|
|
|
+ {
|
|
|
+
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CZhengcanSaomadiancanWnd::Init()
|
|
|
+{
|
|
|
+ RefreshOrder();
|
|
|
+}
|
|
|
+
|
|
|
+void CZhengcanSaomadiancanWnd::RefreshOrder()
|
|
|
+{
|
|
|
+ //请求服务器获取所有未处理的订单信息
|
|
|
+ std::map<string, string> params;
|
|
|
+
|
|
|
+ params["order_id"] = "0";
|
|
|
+
|
|
|
+ std::string response;
|
|
|
+
|
|
|
+ std::string url = "/dinnercash/getnothandleorderlist";
|
|
|
+ bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
|
|
|
+ if (ret == false)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ rapidjson::Document document;
|
|
|
+ document.Parse(response.c_str());
|
|
|
+
|
|
|
+ if (document.HasParseError())
|
|
|
+ {
|
|
|
+ LOG_INFO("parse response error!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
|
|
|
+ {
|
|
|
+ LOG_INFO("json error!");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ rapidjson::Value& v_errcode = document["errcode"];
|
|
|
+ int errcode = v_errcode.GetInt();
|
|
|
+ if (errcode != 0)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!document.HasMember("data"))
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ rapidjson::Value& data = document["data"];
|
|
|
+
|
|
|
+ rapidjson::Value& v_rows = data["rows"];
|
|
|
+
|
|
|
+ //这个是用来展示所有订单的区域
|
|
|
+ CVerticalLayoutUI* pOrderLayout = static_cast<CVerticalLayoutUI*>(m_pm.FindControl(_T("zhengcan_saomadiancan_wnd_layout")));
|
|
|
+ pOrderLayout->RemoveAll();
|
|
|
+
|
|
|
+ for (rapidjson::SizeType j = 0; j < v_rows.Size(); ++j)
|
|
|
+ {
|
|
|
+ rapidjson::Value& orderinfo = v_rows[j];
|
|
|
+
|
|
|
+ std::string table_name = CLewaimaiJson::ToString(orderinfo["table_name"]);
|
|
|
+ std::string init_time = CLewaimaiJson::ToString(orderinfo["init_time"]);
|
|
|
+ std::string order_id = CLewaimaiJson::ToString(orderinfo["order_id"]);
|
|
|
+ std::string jiacai_no = CLewaimaiJson::ToString(orderinfo["jiacai_no"]);
|
|
|
+
|
|
|
+ CDialogBuilder builder;
|
|
|
+
|
|
|
+ //一个pEle就是一个订单的区域
|
|
|
+ CHorizontalLayoutUI* pEle = static_cast<CHorizontalLayoutUI*>(builder.Create(_T("zhengcan_saomadiancan_wnd_order_item.xml"), (UINT)0, NULL, &m_pm));
|
|
|
+ pOrderLayout->Add(pEle);
|
|
|
+
|
|
|
+ rapidjson::Value& food_list = orderinfo["item"]["food_list"];
|
|
|
+ rapidjson::Value& foodpackage_array = orderinfo["item"]["foodpackage_array"];
|
|
|
+
|
|
|
+ //这个是订单内部的展示商品的区域
|
|
|
+ CVerticalLayoutUI* pFoodLayout = static_cast<CVerticalLayoutUI*>(pEle->FindSubControl(_T("zhengcan_saomadiancanfoodlist_layout")));
|
|
|
+ pFoodLayout->SetFixedHeight((food_list.Size() + foodpackage_array.Size()) * 40);
|
|
|
+
|
|
|
+ pEle->SetFixedHeight((food_list.Size() + foodpackage_array.Size()) * 40 + 112);
|
|
|
+
|
|
|
+ //先添加普通商品的详情
|
|
|
+ for (rapidjson::SizeType i = 0; i < food_list.Size(); ++j)
|
|
|
+ {
|
|
|
+ rapidjson::Value& food_list_item = food_list[i];
|
|
|
+
|
|
|
+ CDialogBuilder builder1;
|
|
|
+
|
|
|
+ //这个是某一行商品
|
|
|
+ CHorizontalLayoutUI* pFoodEle = static_cast<CHorizontalLayoutUI*>(builder1.Create(_T("zhengcan_saomadiancan_wnd_food_item.xml"), (UINT)0, NULL, &m_pm));
|
|
|
+ pFoodLayout->Add(pFoodEle);
|
|
|
+
|
|
|
+ std::string food_name = CLewaimaiJson::ToString(food_list_item["food_name"]);
|
|
|
+ std::string num = CLewaimaiJson::ToString(food_list_item["quantity"]);
|
|
|
+ std::string price = CLewaimaiString::DoubleToString(atof(CLewaimaiJson::ToString(food_list_item["single_price"]).c_str()) * atof(num.c_str()), 2);
|
|
|
+
|
|
|
+ pFoodEle->FindSubControl(L"food_name")->SetText(CLewaimaiString::UTF8ToUnicode(food_name).c_str());
|
|
|
+ pFoodEle->FindSubControl(L"food_num")->SetText(CLewaimaiString::UTF8ToUnicode(num).c_str());
|
|
|
+ pFoodEle->FindSubControl(L"food_price")->SetText(CLewaimaiString::UTF8ToUnicode(price).c_str());
|
|
|
+ }
|
|
|
+
|
|
|
+ //再添加套餐的详情
|
|
|
+ for (rapidjson::SizeType i = 0; i < foodpackage_array.Size(); ++j)
|
|
|
+ {
|
|
|
+ rapidjson::Value& food_list_item = food_list[i];
|
|
|
+
|
|
|
+ CDialogBuilder builder1;
|
|
|
+
|
|
|
+ //这个是某一行商品
|
|
|
+ CHorizontalLayoutUI* pFoodEle = static_cast<CHorizontalLayoutUI*>(builder1.Create(_T("zhengcan_saomadiancan_wnd_food_item.xml"), (UINT)0, NULL, &m_pm));
|
|
|
+ pFoodLayout->Add(pFoodEle);
|
|
|
+
|
|
|
+ std::string food_name = CLewaimaiJson::ToString(food_list_item["food_name"]);
|
|
|
+ std::string num = CLewaimaiJson::ToString(food_list_item["quantity"]);
|
|
|
+ std::string price = CLewaimaiString::DoubleToString(atof(CLewaimaiJson::ToString(food_list_item["single_price"]).c_str()) * atof(num.c_str()), 2);
|
|
|
+
|
|
|
+ pFoodEle->FindSubControl(L"food_name")->SetText(CLewaimaiString::UTF8ToUnicode(food_name).c_str());
|
|
|
+ pFoodEle->FindSubControl(L"food_num")->SetText(CLewaimaiString::UTF8ToUnicode(num).c_str());
|
|
|
+ pFoodEle->FindSubControl(L"food_price")->SetText(CLewaimaiString::UTF8ToUnicode(price).c_str());
|
|
|
+ }
|
|
|
+
|
|
|
+ CLabelUI* pTime = static_cast<CLabelUI*>(pEle->FindSubControl(_T("zhengcan_saomadiancanorder_time")));
|
|
|
+ pTime->SetText(CLewaimaiString::UTF8ToUnicode(init_time).c_str());
|
|
|
+
|
|
|
+ //给按钮加属性,点击的时候好判断并且处理
|
|
|
+ CButtonUI* pDelete = static_cast<CButtonUI*>(pEle->FindSubControl(_T("zhengcan_saomadiancanorder_delete")));
|
|
|
+ pDelete->AddCustomAttribute(L"order_id", CLewaimaiString::UTF8ToUnicode(order_id).c_str());
|
|
|
+ pDelete->AddCustomAttribute(L"jiacai_no", CLewaimaiString::UTF8ToUnicode(jiacai_no).c_str());
|
|
|
+
|
|
|
+ CButtonUI* pQueren = static_cast<CButtonUI*>(pEle->FindSubControl(_T("zhengcan_saomadiancanorder_queren")));
|
|
|
+ pQueren->AddCustomAttribute(L"order_id", CLewaimaiString::UTF8ToUnicode(order_id).c_str());
|
|
|
+ pQueren->AddCustomAttribute(L"jiacai_no", CLewaimaiString::UTF8ToUnicode(jiacai_no).c_str());
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CZhengcanSaomadiancanWnd::SetTitle(std::wstring title)
|
|
|
+{
|
|
|
+ CLabelUI* pLabel = static_cast<CLabelUI*>(m_pm.FindControl(_T("memo_dlg_title")));
|
|
|
+ pLabel->SetText(title.c_str());
|
|
|
+}
|