CShangpinCreatePageUI.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791
  1. #include "../pch/pch.h"
  2. #include "CShangpinCreatePageUI.h"
  3. #include "../control/ControlEx.h"
  4. #include "../tool/CSqlite3.h"
  5. #include "../tool/CFoodHandle.h"
  6. #include "../wnd/CMainWnd.h"
  7. #include "../wnd/CShangpinSaomaluruWnd.h"
  8. CShangpinCreatePageUI::CShangpinCreatePageUI()
  9. {
  10. }
  11. CShangpinCreatePageUI::~CShangpinCreatePageUI()
  12. {
  13. }
  14. //初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
  15. void CShangpinCreatePageUI::InitShow()
  16. {
  17. //商品名字
  18. CEditUI* pName = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_name_edit"));
  19. pName->SetText(L"");
  20. pName->SetFocus();
  21. //商品序号
  22. CEditUI* pXuhao = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_xuhao_edit"));
  23. pXuhao->SetText(L"");
  24. //初始化商品分类
  25. CComboUI* com_fenlei = static_cast<CComboUI*>(this->FindSubControl(_T("shangpin_create_page_foodtype")));
  26. com_fenlei->RemoveAll();
  27. CSqlite3 sqlite;
  28. std::vector<CFoodType> foodtypes = sqlite.GetFoodtypes();
  29. std::string first_food_name = "";
  30. int nTypeNum = 0;
  31. for (std::vector<CFoodType>::iterator it = foodtypes.begin(); it != foodtypes.end(); it++)
  32. {
  33. CListLabelElementUI* elem = new CListLabelElementUI();
  34. elem->SetText(CLewaimaiString::UTF8ToUnicode(it->name).c_str());
  35. com_fenlei->Add(elem);
  36. if (it == foodtypes.begin())
  37. {
  38. first_food_name = it->name;
  39. }
  40. nTypeNum++;
  41. m_foodtype_id_map[it->name] = it->id;
  42. }
  43. com_fenlei->SetInternVisible(true);
  44. if (nTypeNum > 0)
  45. {
  46. com_fenlei->SelectItem(0, false, false);
  47. }
  48. com_fenlei->SetText(CLewaimaiString::UTF8ToUnicode(first_food_name).c_str());
  49. //商品条码
  50. CEditUI* pTiaoma = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_barcode_edit"));
  51. pTiaoma->SetText(L"");
  52. //商品价格
  53. CEditUI* pPrice = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_price_edit"));
  54. pPrice->SetText(L"");
  55. //商品单位
  56. CEditUI* pDanwei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_unit_edit"));
  57. pDanwei->SetText(L"");
  58. //是否称重
  59. CCheckBoxUI* pChengzhong = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_chengzhong"));
  60. pChengzhong->Selected(false, false);
  61. //plu编码
  62. CEditUI* pPlu = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_plu"));
  63. pPlu->SetText(L"");
  64. //商品编码
  65. CEditUI* pShangpin = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_shangpinbianma"));
  66. pShangpin->SetText(L"");
  67. //库存类型
  68. CCheckBoxUI* pKucuntype = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_kucun_open"));
  69. pKucuntype->Selected(true, false);
  70. //当前库存
  71. CEditUI* pDangqiankucun = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_kucun_now"));
  72. pDangqiankucun->SetText(L"0");
  73. //商品状态
  74. CCheckBoxUI* pStatus = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_status_normal"));
  75. pStatus->Selected(true, false);
  76. //进货价
  77. CEditUI* pJinhuojia = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_buyingprice_edit"));
  78. pJinhuojia->SetText(L"0");
  79. //进货价模式
  80. CCheckBoxUI* pJinhuomoshi = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_jinhuojia_normal"));
  81. pJinhuomoshi->Selected(true, false);
  82. //在哪些地方显示
  83. CCheckBoxUI* pShouyinji = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_shouyinji"));
  84. CCheckBoxUI* pWaimai = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_waimai"));
  85. CCheckBoxUI* pSaomaidancan = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_saomadiancan"));
  86. pShouyinji->Selected(true, false);
  87. pWaimai->Selected(true, false);
  88. pSaomaidancan->Selected(true, false);
  89. //是否开启打包费
  90. CCheckBoxUI* pDabao = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_is_dabao"));
  91. pDabao->Selected(false, false);
  92. //打包费
  93. CEditUI* pDaobaofei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_dabao_money"));
  94. pDaobaofei->SetText(L"0");
  95. //商品加工方式
  96. CCheckBoxUI* pJiagongfangshi = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_1"));
  97. pJiagongfangshi->Selected(true, false);
  98. ShowError(L"");
  99. CVerticalLayoutUI* layout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(L"shangpin_create_page_info_layout"));
  100. SIZE pos;
  101. pos.cx = 0;
  102. pos.cy = 0;
  103. layout->SetScrollPos(pos);
  104. }
  105. //处理按钮点击类事件
  106. void CShangpinCreatePageUI::HandleClickMsg(TNotifyUI& msg)
  107. {
  108. CDuiString name = msg.pSender->GetName();
  109. if (name == L"shangpin_create_page_save_btn")
  110. {
  111. StartSave();
  112. }
  113. else if (name == L"shangpin_create_page_return_btn")
  114. {
  115. m_pMainWnd->SwitchPage(CMainWnd::SHANGPIN, false);
  116. }
  117. else if (name == L"shangpin_create_page_saoma_btn")
  118. {
  119. ShowSaomaluru();
  120. }
  121. }
  122. //处理option切换事件
  123. void CShangpinCreatePageUI::HandleSelectChangeMsg(TNotifyUI& msg)
  124. {
  125. CDuiString name = msg.pSender->GetName();
  126. COptionUI* curOption = static_cast<COptionUI*>(msg.pSender);
  127. std::wstring groupname = curOption->GetGroup();
  128. if (groupname == L"shangpin_foodtype")
  129. {
  130. }
  131. }
  132. //处理下拉框、radio的切换事件
  133. void CShangpinCreatePageUI::HandleItemSelectMsg(TNotifyUI& msg)
  134. {
  135. }
  136. //处理编辑框输入内容改变事件
  137. void CShangpinCreatePageUI::HandleTextChangedMsg(TNotifyUI& msg)
  138. {
  139. CDuiString name = msg.pSender->GetName();
  140. if (name == L"shangpin_create_page_xuhao_edit")
  141. {
  142. //只能输入数字,其他的全部删除
  143. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_xuhao_edit")));
  144. if (!m_pEdit->GetText().IsEmpty())
  145. {
  146. wstring ws_Value = m_pEdit->GetText();
  147. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  148. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  149. {
  150. unsigned char tmp = strValue.at(nIndex);
  151. if ((tmp > 57 || tmp < 48))
  152. {
  153. //ASCII码不是数字的都过滤掉
  154. strValue = strValue.substr(0, nIndex);
  155. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  156. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  157. break;
  158. }
  159. }
  160. }
  161. }
  162. else if (name == L"shangpin_create_page_barcode_edit")
  163. {
  164. //只能输入数字,其他的全部删除
  165. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_barcode_edit")));
  166. if (!m_pEdit->GetText().IsEmpty())
  167. {
  168. wstring ws_Value = m_pEdit->GetText();
  169. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  170. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  171. {
  172. unsigned char tmp = strValue.at(nIndex);
  173. if ((tmp > 57 || tmp < 48))
  174. {
  175. //ASCII码不是数字的都过滤掉
  176. strValue = strValue.substr(0, nIndex);
  177. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  178. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  179. break;
  180. }
  181. }
  182. }
  183. }
  184. else if (name == L"shangpin_create_page_price_edit")
  185. {
  186. //只能输入数字,其他的全部删除
  187. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_price_edit")));
  188. if (!m_pEdit->GetText().IsEmpty())
  189. {
  190. wstring ws_Value = m_pEdit->GetText();
  191. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  192. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  193. {
  194. unsigned char tmp = strValue.at(nIndex);
  195. if ((tmp > 57 || tmp < 48) && tmp != 46)
  196. {
  197. //ASCII码不是数字的都过滤掉
  198. strValue = strValue.substr(0, nIndex);
  199. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  200. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  201. break;
  202. }
  203. }
  204. }
  205. }
  206. else if (name == L"shangpin_create_page_buyingprice_edit")
  207. {
  208. //只能输入数字,其他的全部删除
  209. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_buyingprice_edit")));
  210. if (!m_pEdit->GetText().IsEmpty())
  211. {
  212. wstring ws_Value = m_pEdit->GetText();
  213. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  214. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  215. {
  216. unsigned char tmp = strValue.at(nIndex);
  217. if ((tmp > 57 || tmp < 48) && tmp != 46)
  218. {
  219. //ASCII码不是数字的都过滤掉
  220. strValue = strValue.substr(0, nIndex);
  221. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  222. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  223. break;
  224. }
  225. }
  226. }
  227. }
  228. else if (name == L"shangpin_create_page_plu")
  229. {
  230. //只能输入数字,其他的全部删除
  231. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_plu")));
  232. if (!m_pEdit->GetText().IsEmpty())
  233. {
  234. wstring ws_Value = m_pEdit->GetText();
  235. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  236. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  237. {
  238. unsigned char tmp = strValue.at(nIndex);
  239. if ((tmp > 57 || tmp < 48))
  240. {
  241. //ASCII码不是数字的都过滤掉
  242. strValue = strValue.substr(0, nIndex);
  243. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  244. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  245. break;
  246. }
  247. }
  248. }
  249. }
  250. else if (name == L"shangpin_create_page_shangpinbianma")
  251. {
  252. //只能输入数字,其他的全部删除
  253. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_shangpinbianma")));
  254. if (!m_pEdit->GetText().IsEmpty())
  255. {
  256. wstring ws_Value = m_pEdit->GetText();
  257. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  258. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  259. {
  260. unsigned char tmp = strValue.at(nIndex);
  261. if ((tmp > 57 || tmp < 48))
  262. {
  263. //ASCII码不是数字的都过滤掉
  264. strValue = strValue.substr(0, nIndex);
  265. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  266. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  267. break;
  268. }
  269. }
  270. }
  271. }
  272. else if (name == L"shangpin_create_page_dabao_money")
  273. {
  274. //只能输入数字,其他的全部删除
  275. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_dabao_money")));
  276. if (!m_pEdit->GetText().IsEmpty())
  277. {
  278. wstring ws_Value = m_pEdit->GetText();
  279. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  280. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  281. {
  282. unsigned char tmp = strValue.at(nIndex);
  283. if ((tmp > 57 || tmp < 48) && tmp != 46)
  284. {
  285. //ASCII码不是数字的都过滤掉
  286. strValue = strValue.substr(0, nIndex);
  287. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  288. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  289. break;
  290. }
  291. }
  292. }
  293. }
  294. else if (name == L"shangpin_create_page_kucun_now")
  295. {
  296. //只能输入数字,其他的全部删除
  297. CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_kucun_now")));
  298. if (!m_pEdit->GetText().IsEmpty())
  299. {
  300. wstring ws_Value = m_pEdit->GetText();
  301. string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
  302. for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
  303. {
  304. unsigned char tmp = strValue.at(nIndex);
  305. if ((tmp > 57 || tmp < 48))
  306. {
  307. //ASCII码不是数字的都过滤掉
  308. strValue = strValue.substr(0, nIndex);
  309. m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
  310. m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
  311. break;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. //处理扫码枪捕捉到的扫码信息
  318. void CShangpinCreatePageUI::HandleTextCapture(std::string content)
  319. {
  320. if (m_is_show_modal_wnd == true)
  321. {
  322. m_curModalWnd->HandleTextCapture(content);
  323. return;
  324. }
  325. }
  326. bool CShangpinCreatePageUI::HandleCustomMessage(UINT uMsg, WPARAM wParam, LPARAM lParam)
  327. {
  328. if (uMsg == WM_FOOD_HANDLE_SUCCESS)
  329. {
  330. //然后返回到商品页面
  331. m_pMainWnd->SwitchPage(CMainWnd::SHANGPIN);
  332. return true;
  333. }
  334. return false;
  335. }
  336. void CShangpinCreatePageUI::SetPos(RECT rc, bool bNeedInvalidate)
  337. {
  338. m_nPageWidth = rc.right - rc.left;
  339. CContainerUI::SetPos(rc, bNeedInvalidate);
  340. }
  341. void CShangpinCreatePageUI::StartSave()
  342. {
  343. //把参数一个个读出来
  344. //商品名字
  345. CEditUI* pName = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_name_edit"));
  346. std::wstring ws_name = pName->GetText();
  347. m_name = CLewaimaiString::UnicodeToUTF8(ws_name);
  348. if (m_name == "")
  349. {
  350. ShowError(L"商品名字不能为空");
  351. return;
  352. }
  353. //商品序号
  354. CEditUI* pXuhao = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_xuhao_edit"));
  355. std::wstring ws_xuhao = pXuhao->GetText();
  356. m_xuhao = CLewaimaiString::UnicodeToUTF8(ws_xuhao);
  357. if (m_xuhao == "")
  358. {
  359. m_xuhao = "0";
  360. }
  361. //初始化商品分类
  362. CComboUI* com_fenlei = static_cast<CComboUI*>(this->FindSubControl(_T("shangpin_create_page_foodtype")));
  363. std::wstring ws_type = com_fenlei->GetText();
  364. m_fenlei = CLewaimaiString::UnicodeToUTF8(ws_type);
  365. if (m_fenlei == "")
  366. {
  367. ShowError(L"商品分类不能为空,请先创建并选择商品分类");
  368. return;
  369. }
  370. //商品条码
  371. CEditUI* pTiaoma = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_barcode_edit"));
  372. std::wstring ws_tiaoma = pTiaoma->GetText();
  373. m_tiaoma = CLewaimaiString::UnicodeToUTF8(ws_tiaoma);
  374. //商品价格
  375. CEditUI* pPrice = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_price_edit"));
  376. std::wstring ws_price = pPrice->GetText();
  377. m_price = CLewaimaiString::UnicodeToUTF8(ws_price);
  378. if (m_price == "")
  379. {
  380. ShowError(L"商品价格不能为空");
  381. return;
  382. }
  383. //商品单位
  384. CEditUI* pDanwei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_unit_edit"));
  385. std::wstring ws_danwei = pDanwei->GetText();
  386. m_danwei = CLewaimaiString::UnicodeToUTF8(ws_danwei);
  387. //是否称重
  388. CCheckBoxUI* pChengzhong = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_chengzhong"));
  389. m_is_chengzhong = pChengzhong->IsSelected();
  390. //plu编码
  391. CEditUI* pPlu = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_plu"));
  392. std::wstring ws_plu = pPlu->GetText();
  393. m_plu = CLewaimaiString::UnicodeToUTF8(ws_plu);
  394. //商品编码
  395. CEditUI* pShangpin = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_shangpinbianma"));
  396. std::wstring ws_shangpin = pShangpin->GetText();
  397. m_shangpinbianma = CLewaimaiString::UnicodeToUTF8(ws_shangpin);
  398. //库存类型
  399. CCheckBoxUI* pKucuntype = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_kucun_open"));
  400. if (pKucuntype->IsSelected())
  401. {
  402. m_kucuntype = 0;
  403. }
  404. else
  405. {
  406. m_kucuntype = 1;
  407. }
  408. //当前库存
  409. CEditUI* pDangqiankucun = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_kucun_now"));
  410. std::wstring ws_dangqiankucun = pDangqiankucun->GetText();
  411. m_dangqiankucun = CLewaimaiString::UnicodeToUTF8(ws_dangqiankucun);
  412. if (m_dangqiankucun == "")
  413. {
  414. m_dangqiankucun = "0";
  415. }
  416. //商品状态
  417. CCheckBoxUI* pStatus = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_status_normal"));
  418. if (pStatus->IsSelected())
  419. {
  420. m_status = 0;
  421. }
  422. else
  423. {
  424. m_status = 1;
  425. }
  426. //进货价
  427. CEditUI* pJinhuojia = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_buyingprice_edit"));
  428. std::wstring ws_jinhuojia = pJinhuojia->GetText();
  429. m_jinhuojia = CLewaimaiString::UnicodeToUTF8(ws_jinhuojia);
  430. if (m_jinhuojia == "")
  431. {
  432. m_jinhuojia = "0";
  433. }
  434. //进货价模式
  435. CCheckBoxUI* pJinhuomoshi = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_jinhuojia_normal"));
  436. if (pJinhuomoshi->IsSelected())
  437. {
  438. m_jinhuo_type = 0;
  439. }
  440. else
  441. {
  442. m_jinhuo_type = 1;
  443. }
  444. //在哪些地方显示
  445. CCheckBoxUI* pShouyinji = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_shouyinji"));
  446. CCheckBoxUI* pWaimai = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_waimai"));
  447. CCheckBoxUI* pSaomaidancan = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_saomadiancan"));
  448. m_is_shouyinji_show = pShouyinji->IsSelected();
  449. m_is_waimai_show = pWaimai->IsSelected();
  450. m_is_saomadiancan_show = pSaomaidancan->IsSelected();
  451. //是否开启打包费
  452. CCheckBoxUI* pDabao = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_is_dabao"));
  453. m_is_dabao_fei = pDabao->IsSelected();
  454. //打包费
  455. CEditUI* pDaobaofei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_dabao_money"));
  456. std::wstring ws_dabaofei = pDaobaofei->GetText();
  457. m_dabaofei = CLewaimaiString::UnicodeToUTF8(ws_dabaofei);
  458. if (m_dabaofei == "")
  459. {
  460. m_dabaofei = "0";
  461. }
  462. //商品加工方式
  463. CCheckBoxUI* pJiagongfangshi_1 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_1"));
  464. CCheckBoxUI* pJiagongfangshi_2 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_2"));
  465. CCheckBoxUI* pJiagongfangshi_3 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_3"));
  466. if (pJiagongfangshi_1->IsSelected())
  467. {
  468. m_jiagong_type = 1;
  469. }
  470. else if (pJiagongfangshi_2->IsSelected())
  471. {
  472. m_jiagong_type = 2;
  473. }
  474. else if (pJiagongfangshi_3->IsSelected())
  475. {
  476. m_jiagong_type = 3;
  477. }
  478. ShowError(L"正在保存商品...");
  479. std::thread(&CShangpinCreatePageUI::HandleSave, this).detach();
  480. }
  481. void CShangpinCreatePageUI::HandleSave()
  482. {
  483. std::map<string, string> params;
  484. params["goods_name"] = m_name;
  485. params["goods_tag"] = m_xuhao;
  486. params["type_lv1_id"] = m_foodtype_id_map[m_fenlei];
  487. params["barcode"] = m_tiaoma;
  488. params["goods_price"] = m_price;
  489. params["unit"] = m_danwei;
  490. if (m_is_chengzhong)
  491. {
  492. params["is_weight"] = "1";
  493. }
  494. else
  495. {
  496. params["is_weight"] = "0";
  497. }
  498. params["weight_plu_code"] = m_plu;
  499. params["weight_food_code"] = m_shangpinbianma;
  500. if (m_kucuntype == 0)
  501. {
  502. params["stock_status"] = "OPEN";
  503. }
  504. else
  505. {
  506. params["stock_status"] = "CLOSED";
  507. }
  508. params["stock"] = m_dangqiankucun;
  509. if (m_status == 0)
  510. {
  511. params["goods_status"] = "NORMAL";
  512. }
  513. else
  514. {
  515. params["goods_status"] = "CLOSED";
  516. }
  517. params["buying_price"] = m_jinhuojia;
  518. params["cost_mode"] = to_string(m_jinhuo_type);
  519. //哪里显示
  520. if (m_is_shouyinji_show)
  521. {
  522. params["is_shouyinji_show"] = "1";
  523. }
  524. else
  525. {
  526. params["is_shouyinji_show"] = "0";
  527. }
  528. if (m_is_waimai_show)
  529. {
  530. params["is_waimai_show"] = "1";
  531. }
  532. else
  533. {
  534. params["is_waimai_show"] = "0";
  535. }
  536. if (m_is_saomadiancan_show)
  537. {
  538. params["is_tangshi_show"] = "1";
  539. params["is_zhengcan_show"] = "1";
  540. }
  541. else
  542. {
  543. params["is_tangshi_show"] = "0";
  544. params["is_zhengcan_show"] = "0";
  545. }
  546. if (m_is_dabao_fei)
  547. {
  548. params["is_dabao"] = "1";
  549. }
  550. else
  551. {
  552. params["is_dabao"] = "0";
  553. }
  554. params["dabao_money"] = m_dabaofei;
  555. params["jiagong_type"] = to_string(m_jiagong_type);
  556. //这下面是接口要求必传参数
  557. params["goods_img"] = "";
  558. params["open_autostock"] = "0";
  559. params["stock_warning"] = "0";
  560. std::string response;
  561. std::string url = "/goods/addgoods";
  562. bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
  563. if (ret == false)
  564. {
  565. ShowError(L"请求服务器失败,请检查网络设置!");
  566. return;
  567. }
  568. rapidjson::Document document;
  569. document.Parse(response.c_str());
  570. if (document.HasParseError())
  571. {
  572. ShowError(L"服务器错误");
  573. return;
  574. }
  575. if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
  576. {
  577. ShowError(L"服务器错误");
  578. return;
  579. }
  580. rapidjson::Value& v_errcode = document["errcode"];
  581. int errcode = v_errcode.GetInt();
  582. if (errcode != 0)
  583. {
  584. std::string v_errmsg = document["errmsg"].GetString();
  585. ShowError(CLewaimaiString::UTF8ToUnicode(v_errmsg));
  586. return;
  587. }
  588. rapidjson::Value& data = document["data"];
  589. std::string id = data["id"].GetString();
  590. //走到这里说明商品保存成功了,接着把商品的数据更新到数据库
  591. CFoodHandle::GetInstance()->UpdateOneFood(id);
  592. ::PostMessage(m_pManager->GetPaintWindow(), WM_FOOD_HANDLE_SUCCESS, 0, 0);
  593. }
  594. void CShangpinCreatePageUI::ShowError(std::wstring msg)
  595. {
  596. CLabelUI* pResult = static_cast<CLabelUI*>(this->FindSubControl(L"shangpin_create_page_save_result"));
  597. pResult->SetText(msg.c_str());
  598. if (msg == L"")
  599. {
  600. pResult->SetVisible(false);
  601. }
  602. else
  603. {
  604. pResult->SetVisible(true);
  605. }
  606. }
  607. void CShangpinCreatePageUI::ShowSaomaluru()
  608. {
  609. if (m_is_show_modal_wnd == true)
  610. {
  611. return;
  612. }
  613. CShangpinSaomaluruWnd* pMemoDlg = new CShangpinSaomaluruWnd();
  614. if (pMemoDlg != NULL)
  615. {
  616. m_is_show_modal_wnd = true;
  617. m_curModalWnd = pMemoDlg;
  618. pMemoDlg->Create(m_pManager->GetPaintWindow(), _T(""), UI_WNDSTYLE_DIALOG, WS_EX_WINDOWEDGE);
  619. pMemoDlg->SetIcon(IDI_ICON_DUILIB);
  620. pMemoDlg->CenterWindow();
  621. UINT ret = pMemoDlg->ShowModal();
  622. if (ret == IDOK)
  623. {
  624. std::string code = pMemoDlg->m_code;
  625. std::string name = pMemoDlg->m_name;
  626. std::string price = pMemoDlg->m_price;
  627. std::string unit = pMemoDlg->m_unit;
  628. std::string des = pMemoDlg->m_des;
  629. //获取到了值,初始化值
  630. CEditUI* pTiaoma = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_barcode_edit"));
  631. pTiaoma->SetText(CLewaimaiString::UTF8ToUnicode(code).c_str());
  632. CEditUI* pName = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_name_edit"));
  633. pName->SetText(CLewaimaiString::UTF8ToUnicode(name).c_str());
  634. CEditUI* pPrice = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_price_edit"));
  635. pPrice->SetText(CLewaimaiString::UTF8ToUnicode(price).c_str());
  636. CEditUI* pDanwei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_unit_edit"));
  637. pDanwei->SetText(CLewaimaiString::UTF8ToUnicode(unit).c_str());
  638. m_is_show_modal_wnd = false;
  639. delete pMemoDlg;
  640. }
  641. else
  642. {
  643. m_is_show_modal_wnd = false;
  644. delete pMemoDlg;
  645. return;
  646. }
  647. }
  648. }