CShangpinUpdatePageUI.cpp 23 KB

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