CShangpinUpdatePageUI.cpp 21 KB

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