| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837 |
- #include "../pch/pch.h"
- #include "CShangpinUpdatePageUI.h"
- #include "../control/ControlEx.h"
- #include "../tool/CSqlite3.h"
- #include "../tool/CFoodHandle.h"
- #include "../wnd/CMainWnd.h"
- #include "../print/CPosPrinter.h"
- CShangpinUpdatePageUI::CShangpinUpdatePageUI()
- {
- }
- CShangpinUpdatePageUI::~CShangpinUpdatePageUI()
- {
- }
- //初始化当前页面的展示,处理默认展示效果,在页面被加载的时候调用
- void CShangpinUpdatePageUI::InitShow()
- {
- //商品名字
- CEditUI* pName = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_name_edit"));
- pName->SetText(CLewaimaiString::UTF8ToUnicode(m_foodinfo.name).c_str());
- //商品序号
- CEditUI* pXuhao = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_xuhao_edit"));
- pXuhao->SetText(CLewaimaiString::UTF8ToUnicode(m_foodinfo.tag).c_str());
- //初始化商品分类
- CComboUI* com_fenlei = static_cast<CComboUI*>(this->FindSubControl(_T("shangpin_create_page_foodtype")));
- com_fenlei->RemoveAll();
- CSqlite3 sqlite;
- std::vector<CFoodType> foodtypes = sqlite.GetFoodtypes();
- int nSelectType = -1;
- int nCurNum = 0;
- std::string select_foodtype_name;
- for (std::vector<CFoodType>::iterator it = foodtypes.begin(); it != foodtypes.end(); it++)
- {
- CListLabelElementUI* elem = new CListLabelElementUI();
- elem->SetText(CLewaimaiString::UTF8ToUnicode(it->name).c_str());
- com_fenlei->Add(elem);
- if (it->id == m_foodinfo.type_id)
- {
- nSelectType = nCurNum;
- select_foodtype_name = it->name;
- }
- nCurNum++;
- m_foodtype_id_map[it->name] = it->id;
- }
- com_fenlei->SetInternVisible(true);
- if (nSelectType != -1)
- {
- com_fenlei->SelectItem(nSelectType, false, false);
- }
- com_fenlei->SetText(CLewaimaiString::UTF8ToUnicode(select_foodtype_name).c_str());
- //商品条码
- CEditUI* pTiaoma = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_barcode_edit"));
- pTiaoma->SetText(CLewaimaiString::UTF8ToUnicode(m_foodinfo.barcode).c_str());
- //商品价格
- CEditUI* pPrice = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_price_edit"));
- pPrice->SetText(CLewaimaiString::UTF8ToUnicode(m_foodinfo.price).c_str());
- //商品单位
- CEditUI* pDanwei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_unit_edit"));
- pDanwei->SetText(CLewaimaiString::UTF8ToUnicode(m_foodinfo.unit).c_str());
- //是否称重
- CCheckBoxUI* pChengzhong = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_chengzhong"));
- if (m_foodinfo.is_weight == "1")
- {
- pChengzhong->Selected(true, false);
- }
- else
- {
- pChengzhong->Selected(false, false);
- }
- //plu编码
- CEditUI* pPlu = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_plu"));
- pPlu->SetText(CLewaimaiString::UTF8ToUnicode(m_foodinfo.weight_plu_code).c_str());
- //商品编码
- CEditUI* pShangpin = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_shangpinbianma"));
- pShangpin->SetText(CLewaimaiString::UTF8ToUnicode(m_foodinfo.weight_food_code).c_str());
- //库存类型
- CCheckBoxUI* pKucuntypeOpen = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_kucun_open"));
- CCheckBoxUI* pKucuntypeWuxian = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_kucun_wuxian"));
- if (m_foodinfo.stockvalid == "1")
- {
- pKucuntypeOpen->Selected(true, false);
- pKucuntypeWuxian->Selected(false, false);
- }
- else
- {
- pKucuntypeOpen->Selected(false, false);
- pKucuntypeWuxian->Selected(true, false);
- }
- //当前库存
- CEditUI* pDangqiankucun = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_kucun_now"));
- pDangqiankucun->SetText(CLewaimaiString::UTF8ToUnicode(m_foodinfo.stock).c_str());
- //商品状态
- CCheckBoxUI* pStatusNormal = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_status_normal"));
- CCheckBoxUI* pStatusXiajia = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_status_xiajia"));
- if (m_foodinfo.status == "NORMAL")
- {
- pStatusNormal->Selected(true, false);
- pStatusXiajia->Selected(false, false);
- }
- else
- {
- pStatusNormal->Selected(false, false);
- pStatusXiajia->Selected(true, false);
- }
- //进货价
- CEditUI* pJinhuojia = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_buyingprice_edit"));
- pJinhuojia->SetText(CLewaimaiString::UTF8ToUnicode(m_foodinfo.buying_price).c_str());
- //进货价模式
- CCheckBoxUI* pJinhuomoshiNormal = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_jinhuojia_normal"));
- CCheckBoxUI* pJinhuomoshiJiaquan = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_jinhuojia_jiaquan"));
- if (m_foodinfo.cost_mode == "0")
- {
- pJinhuomoshiNormal->Selected(true, false);
- pJinhuomoshiJiaquan->Selected(false, false);
- }
- else
- {
- pJinhuomoshiNormal->Selected(false, false);
- pJinhuomoshiJiaquan->Selected(true, false);
- }
- //在哪些地方显示
- CCheckBoxUI* pShouyinji = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_shouyinji"));
- CCheckBoxUI* pWaimai = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_waimai"));
- CCheckBoxUI* pSaomaidancan = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_saomadiancan"));
- if (m_foodinfo.is_shouyinji_show == "1")
- {
- pShouyinji->Selected(true, false);
- }
- else
- {
- pShouyinji->Selected(false, false);
- }
- if (m_foodinfo.is_waimai_show == "1")
- {
- pWaimai->Selected(true, false);
- }
- else
- {
- pWaimai->Selected(false, false);
- }
- if (m_foodinfo.is_tangshi_show == "1")
- {
- pSaomaidancan->Selected(true, false);
- }
- else
- {
- pSaomaidancan->Selected(false, false);
- }
- //是否开启打包费
- CCheckBoxUI* pDabao = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_is_dabao"));
- if (m_foodinfo.is_dabao == "1")
- {
- pDabao->Selected(true, false);
- }
- else
- {
- pDabao->Selected(false, false);
- }
- //打包费
- CEditUI* pDaobaofei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_dabao_money"));
- pDaobaofei->SetText(CLewaimaiString::UTF8ToUnicode(m_foodinfo.dabao_money).c_str());
- //商品加工方式
- CCheckBoxUI* pJiagongfangshi_1 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_1"));
- CCheckBoxUI* pJiagongfangshi_2 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_2"));
- CCheckBoxUI* pJiagongfangshi_3 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_3"));
- if (m_foodinfo.jiagong_type == "1")
- {
- pJiagongfangshi_1->Selected(true, false);
- }
- else if (m_foodinfo.jiagong_type == "2")
- {
- pJiagongfangshi_2->Selected(true, false);
- }
- else if (m_foodinfo.jiagong_type == "3")
- {
- pJiagongfangshi_3->Selected(true, false);
- }
- ShowError(L"");
- CVerticalLayoutUI* layout = static_cast<CVerticalLayoutUI*>(this->FindSubControl(L"shangpin_create_page_info_layout"));
- SIZE pos;
- pos.cx = 0;
- pos.cy = 0;
- layout->SetScrollPos(pos);
- }
- //处理按钮点击类事件
- void CShangpinUpdatePageUI::HandleClickMsg(TNotifyUI& msg)
- {
- CDuiString name = msg.pSender->GetName();
- if (name == L"shangpin_create_page_save_btn")
- {
- StartSave();
- }
- else if (name == L"shangpin_create_page_return_btn")
- {
- m_pMainWnd->SwitchPage(CMainWnd::SHANGPIN, false);
- }
- else if (name == L"shangpin_create_page_delete_btn")
- {
- StartDelete();
- }
- else if (name == L"shangpin_create_page_print_btn")
- {
- PrintShangpinTiaoma();
- }
- }
- //处理option切换事件
- void CShangpinUpdatePageUI::HandleSelectChangeMsg(TNotifyUI& msg)
- {
- CDuiString name = msg.pSender->GetName();
- COptionUI* curOption = static_cast<COptionUI*>(msg.pSender);
- std::wstring groupname = curOption->GetGroup();
- if (groupname == L"shangpin_foodtype")
- {
- }
- }
- //处理下拉框、radio的切换事件
- void CShangpinUpdatePageUI::HandleItemSelectMsg(TNotifyUI& msg)
- {
- }
- //处理编辑框输入内容改变事件
- void CShangpinUpdatePageUI::HandleTextChangedMsg(TNotifyUI& msg)
- {
- CDuiString name = msg.pSender->GetName();
- if (name == L"shangpin_create_page_xuhao_edit")
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_xuhao_edit")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if ((tmp > 57 || tmp < 48))
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- else if (name == L"shangpin_create_page_barcode_edit")
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_barcode_edit")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if ((tmp > 57 || tmp < 48))
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- else if (name == L"shangpin_create_page_price_edit")
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_price_edit")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if ((tmp > 57 || tmp < 48) && tmp != 46)
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- else if (name == L"shangpin_create_page_buyingprice_edit")
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_buyingprice_edit")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if ((tmp > 57 || tmp < 48) && tmp != 46)
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- else if (name == L"shangpin_create_page_plu")
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_plu")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if ((tmp > 57 || tmp < 48))
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- else if (name == L"shangpin_create_page_shangpinbianma")
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_shangpinbianma")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if ((tmp > 57 || tmp < 48))
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- else if (name == L"shangpin_create_page_dabao_money")
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_dabao_money")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if ((tmp > 57 || tmp < 48) && tmp != 46)
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- else if (name == L"shangpin_create_page_kucun_now")
- {
- //只能输入数字,其他的全部删除
- CEditUI* m_pEdit = static_cast<CEditUI*>(m_pManager->FindControl(_T("shangpin_create_page_kucun_now")));
- if (!m_pEdit->GetText().IsEmpty())
- {
- wstring ws_Value = m_pEdit->GetText();
- string strValue = CLewaimaiString::UnicodeToUTF8(ws_Value);
- for (size_t nIndex = 0; nIndex < strValue.length(); nIndex++)
- {
- unsigned char tmp = strValue.at(nIndex);
- if ((tmp > 57 || tmp < 48))
- {
- //ASCII码不是数字的都过滤掉
- strValue = strValue.substr(0, nIndex);
- m_pEdit->SetText(CLewaimaiString::UTF8ToUnicode(strValue).c_str());
- m_pEdit->SetSel(strValue.length(), strValue.length());//重设给光标设置位置
- break;
- }
- }
- }
- }
- }
- //处理扫码枪捕捉到的扫码信息
- void CShangpinUpdatePageUI::HandleTextCapture(std::string content)
- {
- }
- void CShangpinUpdatePageUI::SetPos(RECT rc, bool bNeedInvalidate)
- {
- m_nPageWidth = rc.right - rc.left;
- CContainerUI::SetPos(rc, bNeedInvalidate);
- }
- void CShangpinUpdatePageUI::StartSave()
- {
- //把参数一个个读出来
- //商品名字
- CEditUI* pName = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_name_edit"));
- std::wstring ws_name = pName->GetText();
- m_name = CLewaimaiString::UnicodeToUTF8(ws_name);
- //商品序号
- CEditUI* pXuhao = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_xuhao_edit"));
- std::wstring ws_xuhao = pXuhao->GetText();
- m_xuhao = CLewaimaiString::UnicodeToUTF8(ws_xuhao);
- //初始化商品分类
- CComboUI* com_fenlei = static_cast<CComboUI*>(this->FindSubControl(_T("shangpin_create_page_foodtype")));
- std::wstring ws_type = com_fenlei->GetText();
- m_fenlei = CLewaimaiString::UnicodeToUTF8(ws_type);
- //商品条码
- CEditUI* pTiaoma = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_barcode_edit"));
- std::wstring ws_tiaoma = pTiaoma->GetText();
- m_tiaoma = CLewaimaiString::UnicodeToUTF8(ws_tiaoma);
- //商品价格
- CEditUI* pPrice = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_price_edit"));
- std::wstring ws_price = pPrice->GetText();
- m_price = CLewaimaiString::UnicodeToUTF8(ws_price);
- //商品单位
- CEditUI* pDanwei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_unit_edit"));
- std::wstring ws_danwei = pDanwei->GetText();
- m_danwei = CLewaimaiString::UnicodeToUTF8(ws_danwei);
- //是否称重
- CCheckBoxUI* pChengzhong = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_chengzhong"));
- m_is_chengzhong = pChengzhong->IsSelected();
- //plu编码
- CEditUI* pPlu = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_plu"));
- std::wstring ws_plu = pPlu->GetText();
- m_plu = CLewaimaiString::UnicodeToUTF8(ws_plu);
- //商品编码
- CEditUI* pShangpin = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_shangpinbianma"));
- std::wstring ws_shangpin = pShangpin->GetText();
- m_shangpinbianma = CLewaimaiString::UnicodeToUTF8(ws_shangpin);
- //库存类型
- CCheckBoxUI* pKucuntype = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_kucun_open"));
- if (pKucuntype->IsSelected())
- {
- m_kucuntype = 0;
- }
- else
- {
- m_kucuntype = 1;
- }
- //当前库存
- CEditUI* pDangqiankucun = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_kucun_now"));
- std::wstring ws_dangqiankucun = pDangqiankucun->GetText();
- m_dangqiankucun = CLewaimaiString::UnicodeToUTF8(ws_dangqiankucun);
- //商品状态
- CCheckBoxUI* pStatus = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_status_normal"));
- if (pStatus->IsSelected())
- {
- m_status = 0;
- }
- else
- {
- m_status = 1;
- }
- //进货价
- CEditUI* pJinhuojia = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_buyingprice_edit"));
- std::wstring ws_jinhuojia = pJinhuojia->GetText();
- m_jinhuojia = CLewaimaiString::UnicodeToUTF8(ws_jinhuojia);
- //进货价模式
- CCheckBoxUI* pJinhuomoshi = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_jinhuojia_normal"));
- if (pJinhuomoshi->IsSelected())
- {
- m_jinhuo_type = 0;
- }
- else
- {
- m_jinhuo_type = 1;
- }
- //在哪些地方显示
- CCheckBoxUI* pShouyinji = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_shouyinji"));
- CCheckBoxUI* pWaimai = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_waimai"));
- CCheckBoxUI* pSaomaidancan = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_showplace_saomadiancan"));
- m_is_shouyinji_show = pShouyinji->IsSelected();
- m_is_waimai_show = pWaimai->IsSelected();
- m_is_saomadiancan_show = pSaomaidancan->IsSelected();
- //是否开启打包费
- CCheckBoxUI* pDabao = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_is_dabao"));
- m_is_dabao_fei = pDabao->IsSelected();
- //打包费
- CEditUI* pDaobaofei = static_cast<CEditUI*>(this->FindSubControl(L"shangpin_create_page_dabao_money"));
- std::wstring ws_dabaofei = pDaobaofei->GetText();
- m_dabaofei = CLewaimaiString::UnicodeToUTF8(ws_dabaofei);
- //商品加工方式
- CCheckBoxUI* pJiagongfangshi_1 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_1"));
- CCheckBoxUI* pJiagongfangshi_2 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_2"));
- CCheckBoxUI* pJiagongfangshi_3 = static_cast<CCheckBoxUI*>(this->FindSubControl(L"shangpin_create_page_fangan_3"));
- if (pJiagongfangshi_1->IsSelected())
- {
- m_jiagong_type = 0;
- }
- else if (pJiagongfangshi_2->IsSelected())
- {
- m_jiagong_type = 1;
- }
- else if (pJiagongfangshi_3->IsSelected())
- {
- m_jiagong_type = 2;
- }
- ShowError(L"正在保存商品...");
- std::thread(&CShangpinUpdatePageUI::HandleSave, this).detach();
- }
- void CShangpinUpdatePageUI::HandleSave()
- {
- std::map<string, string> params;
- params["goods_id"] = m_foodinfo.id;
- params["goods_name"] = m_name;
- params["goods_tag"] = m_xuhao;
- params["type_lv1_id"] = m_foodtype_id_map[m_fenlei];
- params["barcode"] = m_tiaoma;
- params["goods_price"] = m_price;
- params["unit"] = m_danwei;
- if (m_is_chengzhong)
- {
- params["is_weight"] = "1";
- }
- else
- {
- params["is_weight"] = "0";
- }
- params["weight_plu_code"] = m_plu;
- params["weight_food_code"] = m_shangpinbianma;
- if (m_kucuntype == 0)
- {
- params["stock_status"] = "OPEN";
- }
- else
- {
- params["stock_status"] = "CLOSED";
- }
- params["stock"] = m_dangqiankucun;
- if (m_status == 0)
- {
- params["goods_status"] = "NORMAL";
- }
- else
- {
- params["goods_status"] = "CLOSED";
- }
- params["buying_price"] = m_jinhuojia;
- //这里目前缺少一个进货价模式
- if (m_is_shouyinji_show)
- {
- params["is_shouyinji_show"] = "1";
- }
- else
- {
- params["is_shouyinji_show"] = "0";
- }
- if (m_is_waimai_show)
- {
- params["is_waimai_show"] = "1";
- }
- else
- {
- params["is_waimai_show"] = "0";
- }
- if (m_is_saomadiancan_show)
- {
- params["is_tangshi_show"] = "1";
- params["is_zhengcan_show"] = "1";
- }
- else
- {
- params["is_tangshi_show"] = "0";
- params["is_zhengcan_show"] = "0";
- }
- if (m_is_dabao_fei)
- {
- params["is_dabao"] = "1";
- }
- else
- {
- params["is_dabao"] = "0";
- }
- params["dabao_money"] = m_dabaofei;
- params["jiagong_type"] = to_string(m_jiagong_type);
-
- //这下面是接口要求必传参数
- params["goods_img"] = m_foodinfo.goods_img;
- params["goods_thumb_img"] = m_foodinfo.goods_img;
- params["open_autostock"] = "0";
- params["stock_warning"] = "0";
- std::string response;
- std::string url = "/goods/updategoods";
- bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
- if (ret == false)
- {
- ShowError(L"请求服务器失败,请检查网络设置!");
- return;
- }
- rapidjson::Document document;
- document.Parse(response.c_str());
- if (document.HasParseError())
- {
- ShowError(L"服务器错误");
- return;
- }
- if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
- {
- ShowError(L"服务器错误");
- return;
- }
- rapidjson::Value& v_errcode = document["errcode"];
- int errcode = v_errcode.GetInt();
- if (errcode != 0)
- {
- std::string v_errmsg = document["errmsg"].GetString();
- ShowError(CLewaimaiString::UTF8ToUnicode(v_errmsg));
- return;
- }
- rapidjson::Value& data = document["data"];
- std::string id = data["goods_id"].GetString();
- //走到这里说明商品保存成功了,接着把商品的数据更新到数据库
- CFoodHandle::GetInstance()->UpdateOneFood(id);
- //然后返回到商品页面
- m_pMainWnd->SwitchPage(CMainWnd::SHANGPIN);
- }
- void CShangpinUpdatePageUI::StartDelete()
- {
- std::thread(&CShangpinUpdatePageUI::HandleDelete, this).detach();
- }
- void CShangpinUpdatePageUI::HandleDelete()
- {
- std::map<string, string> params;
- params["goods_id"] = m_foodinfo.id;
- std::string response;
- std::string url = "/goods/deletegoods";
- bool ret = CZhipuziHttpClient::GetInstance()->Request(url.c_str(), params, response);
- if (ret == false)
- {
- ShowError(L"请求服务器失败,请检查网络设置!");
- return;
- }
- rapidjson::Document document;
- document.Parse(response.c_str());
- if (document.HasParseError())
- {
- ShowError(L"服务器错误");
- return;
- }
- if (!document.HasMember("errcode") || !document.HasMember("errmsg"))
- {
- ShowError(L"服务器错误");
- return;
- }
- rapidjson::Value& v_errcode = document["errcode"];
- int errcode = v_errcode.GetInt();
- if (errcode != 0)
- {
- std::string v_errmsg = document["errmsg"].GetString();
- ShowError(CLewaimaiString::UTF8ToUnicode(v_errmsg));
- return;
- }
- //本地数据库删除这个商品
- CFoodHandle::GetInstance()->DeleteOndeFood(m_foodinfo.id);
- //然后返回到商品页面
- m_pMainWnd->SwitchPage(CMainWnd::SHANGPIN);
- }
- void CShangpinUpdatePageUI::ShowError(std::wstring msg)
- {
- CLabelUI* pResult = static_cast<CLabelUI*>(this->FindSubControl(L"shangpin_create_page_save_result"));
- pResult->SetText(msg.c_str());
- if (msg == L"")
- {
- pResult->SetVisible(false);
- }
- else
- {
- pResult->SetVisible(true);
- }
- }
- void CShangpinUpdatePageUI::PrintShangpinTiaoma()
- {
- CPosPrinter printer;
- printer.PrintShangpinTiaoma(m_foodinfo);
- }
|