CShangpinPageUI.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  1. #include "../pch/pch.h"
  2. #include "CShangpinPageUI.h"
  3. #include "../control/ControlEx.h"
  4. #include "../tool/CSqlite3.h"
  5. #include "../wnd/CMainWnd.h"
  6. #include "../wnd/CShangpinNewTypeWnd.h"
  7. CShangpinPageUI::CShangpinPageUI()
  8. {
  9. }
  10. CShangpinPageUI::~CShangpinPageUI()
  11. {
  12. }
  13. //初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
  14. void CShangpinPageUI::InitShow()
  15. {
  16. //先初始化商品分类
  17. this->InitFoodtypeShow();
  18. //再初始化商品显示
  19. this->InitFoodShow();
  20. }
  21. void CShangpinPageUI::RefreshShow()
  22. {
  23. //初始化商品显示(因为这里要刷新商品库存状态)
  24. this->InitFoodShow();
  25. }
  26. void CShangpinPageUI::InitFoodtypeShow()
  27. {
  28. //初始化商品渲染相关的信息
  29. m_foodtype_mutex.lock();
  30. m_foodtypeLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout")));
  31. m_foodtypeLayout->RemoveAll();
  32. CSqlite3 sqlite;
  33. m_types = sqlite.GetFoodtypes(); //只包含收银机显示的分类
  34. if (m_types.size() > 0)
  35. {
  36. m_cur_type_id = m_types[0].id;
  37. }
  38. m_curFoodtypeOption = NULL;
  39. //接下来开始处理商品分类
  40. for (std::vector<CFoodType>::iterator it = m_types.begin(); it != m_types.end(); it++)
  41. {
  42. CFoodType type = *it;
  43. CDialogBuilder builder;
  44. CDialogBuilderCallbackEx cb;
  45. CFoodtypeOptionUI* pItem = static_cast<CFoodtypeOptionUI*>(builder.Create(_T("foodtype_option.xml"), (UINT)0, &cb, m_pManager));
  46. pItem->SetName(CLewaimaiString::UTF8ToUnicode(type.name));
  47. pItem->SetTypeId(type.id);
  48. pItem->SetGroup(L"shangpin_foodtype");
  49. m_foodtypeLayout->Add(pItem);
  50. if (m_cur_type_id == type.id)
  51. {
  52. m_curFoodtypeOption = pItem;
  53. }
  54. }
  55. m_foodtype_mutex.unlock();
  56. if (m_curFoodtypeOption != NULL)
  57. {
  58. m_curFoodtypeOption->SetBkColor(0xFF3CB371);
  59. }
  60. //如果不是一个分类都没有,选中第一个分类
  61. if (m_cur_type_id != "")
  62. {
  63. CFoodtypeOptionUI* curTypeUI = static_cast<CFoodtypeOptionUI*>(m_foodtypeLayout->GetItemAt(0));
  64. curTypeUI->Selected(true, false);
  65. }
  66. UpdateFoodtypePos();
  67. }
  68. void CShangpinPageUI::UpdateFoodtypePos()
  69. {
  70. int nFoodtypeNum = m_types.size();
  71. //添加支付方式
  72. int nWidth = m_nPageWidth;
  73. if (nWidth == 0)
  74. {
  75. return;
  76. }
  77. //根据宽度计算每行显示的数量
  78. int nMeihangNum = (nWidth - 321) / 140;
  79. int num = 0;
  80. m_foodtype_mutex.lock();
  81. CHorizontalLayoutUI* pFenleiLayout = static_cast<CHorizontalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout")));
  82. for (int i = 0; i < nFoodtypeNum; i++)
  83. {
  84. CButtonUI* curItem = static_cast<CButtonUI*>(pFenleiLayout->GetItemAt(i));
  85. int curRow = num / nMeihangNum + 1;
  86. int curCol = num % nMeihangNum + 1;
  87. RECT rect;
  88. rect.left = (curCol - 1) * 140 + 10;
  89. rect.right = rect.left + 130;
  90. rect.top = (curRow - 1) * 52 + 10;
  91. rect.bottom = rect.top + 42;
  92. // 强制设置固定大小和位置
  93. SIZE size;
  94. size.cx = rect.left;
  95. size.cy = rect.top;
  96. curItem->SetFixedXY(size);
  97. curItem->SetFixedWidth(rect.right - rect.left);
  98. curItem->SetFixedHeight(rect.bottom - rect.top);
  99. num++;
  100. }
  101. m_foodtype_mutex.unlock();
  102. //调整区域高度
  103. int lastRow = (num - 1) / nMeihangNum + 1;
  104. pFenleiLayout->SetFixedHeight(lastRow * 52 + 10);
  105. //处理滚动条问题
  106. CVerticalLayoutUI* pFenleiScrollLayout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout_scrolllayout")));
  107. if (lastRow > 2)
  108. {
  109. lastRow = 2;
  110. }
  111. pFenleiScrollLayout->SetFixedHeight(lastRow * 52 + 10);
  112. SIZE size;
  113. size.cx = 0;
  114. size.cy = 0;
  115. pFenleiScrollLayout->SetScrollPos(size);
  116. }
  117. void CShangpinPageUI::InitFoodShow()
  118. {
  119. bool is_youtu;
  120. if (CSetting::GetInstance()->GetParam("setting_xianshi_is_youtu") == "1")
  121. {
  122. is_youtu = true;
  123. }
  124. else
  125. {
  126. is_youtu = false;
  127. }
  128. m_foodLayout = static_cast<CTileLayoutUI*>(this->FindSubControl(_T("shangpin_foodlist")));
  129. m_foodLayout->RemoveAll();
  130. std::wstring xml_name;
  131. if (is_youtu)
  132. {
  133. SIZE itemsize;
  134. itemsize.cx = 140;
  135. itemsize.cy = 230;
  136. m_foodLayout->SetItemSize(itemsize);
  137. xml_name = _T("shangpin_fooditem.xml");
  138. }
  139. else
  140. {
  141. SIZE itemsize;
  142. itemsize.cx = 140;
  143. itemsize.cy = 100;
  144. m_foodLayout->SetItemSize(itemsize);
  145. xml_name = _T("shangpin_fooditem_wutu.xml");
  146. }
  147. //如果当前一个分类都没有,那么就不处理了
  148. if (m_cur_type_id == "")
  149. {
  150. return;
  151. }
  152. else if (m_cur_type_id == "sousuo")
  153. {
  154. if (CLewaimaiString::is_only_number(m_sousuo_foodname))
  155. {
  156. //说明是纯数字,按商品条码来搜索
  157. CSqlite3 sqlite;
  158. CFood food;
  159. bool ret = sqlite.GetFoodByBarcode(m_sousuo_foodname, food);
  160. if (ret)
  161. {
  162. CDialogBuilder builder;
  163. CDialogBuilderCallbackEx cb;
  164. CShangpinFoodItemUI* pItem = static_cast<CShangpinFoodItemUI*>(builder.Create(xml_name.c_str(), (UINT)0, &cb, m_pManager));
  165. pItem->SetYoutuModel(is_youtu);
  166. pItem->SetFoodInfo(food);
  167. pItem->UpdateShow();
  168. m_foodLayout->Add(pItem);
  169. }
  170. }
  171. else
  172. {
  173. //当商品名字来搜索
  174. CSqlite3 sqlite;
  175. std::vector<CFood> foodlist = sqlite.GetFoodByFoodname(m_sousuo_foodname);
  176. for (std::vector<CFood>::iterator it = foodlist.begin(); it != foodlist.end(); it++)
  177. {
  178. CFood food = *it;
  179. CDialogBuilder builder;
  180. CDialogBuilderCallbackEx cb;
  181. CShangpinFoodItemUI* pItem = static_cast<CShangpinFoodItemUI*>(builder.Create(xml_name.c_str(), (UINT)0, &cb, m_pManager));
  182. pItem->SetYoutuModel(is_youtu);
  183. pItem->SetFoodInfo(food);
  184. pItem->UpdateShow();
  185. m_foodLayout->Add(pItem);
  186. }
  187. }
  188. }
  189. else
  190. {
  191. //选择的是普通商品分类
  192. CSqlite3 sqlite;
  193. std::vector<CFood> foodlist = sqlite.GetFoodByTypeid(m_cur_type_id);
  194. for (std::vector<CFood>::iterator it = foodlist.begin(); it != foodlist.end(); it++)
  195. {
  196. CFood food = *it;
  197. CDialogBuilder builder;
  198. CDialogBuilderCallbackEx cb;
  199. CShangpinFoodItemUI* pItem = static_cast<CShangpinFoodItemUI*>(builder.Create(xml_name.c_str(), (UINT)0, &cb, m_pManager));
  200. pItem->SetYoutuModel(is_youtu);
  201. pItem->SetFoodInfo(food);
  202. pItem->UpdateShow();
  203. m_foodLayout->Add(pItem);
  204. }
  205. }
  206. }
  207. //处理按钮点击类事件
  208. void CShangpinPageUI::HandleClickMsg(TNotifyUI& msg)
  209. {
  210. CDuiString name = msg.pSender->GetName();
  211. if (name == L"shangpin_fooditem")
  212. {
  213. CShangpinFoodItemUI* fooditemUI = static_cast<CShangpinFoodItemUI*>(msg.pSender);
  214. m_cur_click_food_item = fooditemUI;
  215. this->ClickFoodAction();
  216. }
  217. else if (name == L"shangpin_food_search_clear")
  218. {
  219. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_food_search_edit")));
  220. m_pEdit->SetText(L"");
  221. StopSerachFood();
  222. }
  223. else if (name == L"shangpin_page_add_btn")
  224. {
  225. CShangpinCreatePageUI* page = static_cast<CShangpinCreatePageUI*>(m_pMainWnd->GetPage(CMainWnd::SHANGPIN_CREATE));
  226. m_pMainWnd->SwitchPage(CMainWnd::SHANGPIN_CREATE);
  227. }
  228. else if (name == L"shangpin_page_add_type_btn")
  229. {
  230. ShowNewtype();
  231. }
  232. }
  233. //处理option切换事件
  234. void CShangpinPageUI::HandleSelectChangeMsg(TNotifyUI& msg)
  235. {
  236. CDuiString name = msg.pSender->GetName();
  237. COptionUI* curOption = static_cast<COptionUI*>(msg.pSender);
  238. std::wstring groupname = curOption->GetGroup();
  239. if (groupname == L"shangpin_foodtype")
  240. {
  241. //商品分类切换
  242. CFoodtypeOptionUI* typeUI = static_cast<CFoodtypeOptionUI*>(curOption);
  243. std::string id = typeUI->GetTypeId();
  244. if (m_cur_type_id != id)
  245. {
  246. //切换了商品分类
  247. m_curFoodtypeOption->SetBkColor(0xFFECECEC);
  248. msg.pSender->SetBkColor(0xFF3CB371);
  249. m_curFoodtypeOption = static_cast<CControlUI*>(msg.pSender);
  250. m_cur_type_id = id;
  251. this->InitFoodShow();
  252. return;
  253. }
  254. }
  255. }
  256. //处理下拉框、radio的切换事件
  257. void CShangpinPageUI::HandleItemSelectMsg(TNotifyUI& msg)
  258. {
  259. }
  260. //处理编辑框输入内容改变事件
  261. void CShangpinPageUI::HandleTextChangedMsg(TNotifyUI& msg)
  262. {
  263. CDuiString name = msg.pSender->GetName();
  264. if (name == L"shangpin_food_search_edit")
  265. {
  266. //商品搜索框的输入事件
  267. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_food_search_edit")));
  268. std::wstring ws_Value = m_pEdit->GetText();
  269. std::string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  270. if (strValue.length() == 0)
  271. {
  272. //搜索词被清空了,退出搜索
  273. this->StopSerachFood();
  274. }
  275. else
  276. {
  277. //搜索词没清空,进入搜索
  278. this->StartSearchFood(strValue);
  279. }
  280. }
  281. }
  282. //处理扫码枪捕捉到的扫码信息
  283. void CShangpinPageUI::HandleTextCapture(std::string content)
  284. {
  285. }
  286. void CShangpinPageUI::ClickFoodAction()
  287. {
  288. //点击普通商品之后的处理逻辑
  289. CFood foodinfo = m_cur_click_food_item->GetFoodInfo();
  290. //点击了这个商品,进入商品修改页面
  291. CShangpinUpdatePageUI* page = static_cast<CShangpinUpdatePageUI*>(m_pMainWnd->GetPage(CMainWnd::SHANGPIN_UPDATE));
  292. page->SetFoodinfo(foodinfo);
  293. m_pMainWnd->SwitchPage(CMainWnd::SHANGPIN_UPDATE);
  294. }
  295. //开始搜索某个商品名字
  296. void CShangpinPageUI::StartSearchFood(std::string foodname)
  297. {
  298. //展示删除按钮
  299. CButtonUI* pClear = static_cast<CButtonUI*>(this->FindSubControl(_T("shangpin_food_search_clear")));
  300. pClear->SetVisible(true);
  301. //隐藏商品分类展示
  302. CVerticalLayoutUI* pFoodtype = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout_scrolllayout")));
  303. pFoodtype->SetVisible(false);
  304. if (m_cur_type_id != "sousuo")
  305. {
  306. m_type_id_before_sousuo = m_cur_type_id;
  307. }
  308. m_cur_type_id = "sousuo";
  309. m_sousuo_foodname = foodname;
  310. CLabelUI* pTishi = static_cast<CLabelUI*>(this->FindSubControl(_T("shangpin_food_search_tishi")));
  311. pTishi->SetVisible(false);
  312. this->InitFoodShow();
  313. }
  314. //停止搜索商品
  315. void CShangpinPageUI::StopSerachFood()
  316. {
  317. //隐藏删除按钮
  318. CButtonUI* pClear = static_cast<CButtonUI*>(this->FindSubControl(_T("shangpin_food_search_clear")));
  319. pClear->SetVisible(false);
  320. //展示商品分类展示
  321. CVerticalLayoutUI* pFoodtype = static_cast<CVerticalLayoutUI*>(this->FindSubControl(_T("shangpin_fenlei_layout_scrolllayout")));
  322. pFoodtype->SetVisible(true);
  323. m_cur_type_id = m_type_id_before_sousuo;
  324. CLabelUI* pTishi = static_cast<CLabelUI*>(this->FindSubControl(_T("shangpin_food_search_tishi")));
  325. pTishi->SetVisible(true);
  326. this->InitFoodShow();
  327. }
  328. void CShangpinPageUI::SetPos(RECT rc, bool bNeedInvalidate)
  329. {
  330. m_nPageWidth = rc.right - rc.left;
  331. //更新分类位置
  332. UpdateFoodtypePos();
  333. CContainerUI::SetPos(rc, bNeedInvalidate);
  334. }
  335. void CShangpinPageUI::ShowNewtype()
  336. {
  337. if (m_is_show_modal_wnd == true)
  338. {
  339. return;
  340. }
  341. CShangpinNewTypeWnd* pMemoDlg = new CShangpinNewTypeWnd();
  342. if (pMemoDlg != NULL)
  343. {
  344. m_is_show_modal_wnd = true;
  345. m_curModalWnd = pMemoDlg;
  346. pMemoDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  347. pMemoDlg->SetIcon(IDI_ICON_DUILIB);
  348. pMemoDlg->CenterWindow();
  349. UINT ret = pMemoDlg->ShowModal();
  350. if (ret == IDOK)
  351. {
  352. //这里表示添加分类成功了,刷新分类显示
  353. InitFoodtypeShow();
  354. m_is_show_modal_wnd = false;
  355. delete pMemoDlg;
  356. }
  357. else
  358. {
  359. m_is_show_modal_wnd = false;
  360. delete pMemoDlg;
  361. return;
  362. }
  363. }
  364. }