版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
#if!defined(AFX_CLASSDLG_H__B6736001_C0BF_47D8_8A7A_A2540CC35379__INCLUDED_)#defineAFX_CLASSDLG_H__B6736001_C0BF_47D8_8A7A_A2540CC35379__INCLUDED_#if_MSC_VER>1000#pragmaonce#endif//_MSC_VER>1000//ClassDlg.h:headerfile/////////////////////////////////////////////////////////////////////////////////CClassDlgdialogclassCClassDlg:publicCDialog{//Constructionpublic: intCountMateriel(CStringsclassid); CClassDlg(CWnd*pParent=NULL);//standardconstructor staticCStringVariantToCString(VARIANTvar); staticintTreeSumRecordCount(CStringstrFieldValue);//DialogData //{{AFX_DATA(CClassDlg) enum{IDD=IDD_DIALOG_CLASS}; CButton m_oRadiodiscount; CEdit m_oClassname; CTreeCtrl m_oTreeclass; CString m_classname; int m_radiodiscount; long m_tempid; //}}AFX_DATA//Overrides //ClassWizardgeneratedvirtualfunctionoverrides //{{AFX_VIRTUAL(CClassDlg) protected: virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport //}}AFX_VIRTUAL//Implementationprotected: //Generatedmessagemapfunctions //{{AFX_MSG(CClassDlg) afx_msgvoidOnSelchangedTreeClass(NMHDR*pNMHDR,LRESULT*pResult); virtualBOOLOnInitDialog(); afx_msgvoidOnButtonAddsame(); afx_msgvoidOnButtonAddsub(); afx_msgvoidOnButtonDel(); afx_msgvoidOnButtonSave(); //}}AFX_MSG DECLARE_MESSAGE_MAP()private: intGenNewID();//GenerateanewrecordID. voidAddSubTree(CStringParTree,HTREEITEMhPartItem); voidAddTree(); BOOLbRepeat(CStringstrFieldValue); HTREEITEMhCurrentItem,hParentItem; CStringCurpar;};//{{AFX_INSERT_LOCATION}}//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.#endif//!defined(AFX_CLASSDLG_H__B6736001_C0BF_47D8_8A7A_A2540CC35379__INCLUDED_)//ClassDlg.cpp:implementationfile//#include"stdafx.h"#include"MyPos.h"#include"ClassDlg.h"#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CClassDlgdialogexternCMyPosApptheApp;CClassDlg::CClassDlg(CWnd*pParent/*=NULL*/) :CDialog(CClassDlg::IDD,pParent){ //{{AFX_DATA_INIT(CClassDlg) m_classname=_T(""); m_radiodiscount=-1; m_tempid=0; //}}AFX_DATA_INIT}voidCClassDlg::DoDataExchange(CDataExchange*pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CClassDlg) DDX_Control(pDX,IDC_RADIO1_DISCOUNT,m_oRadiodiscount); DDX_Control(pDX,IDC_EDIT_CLASSNAME,m_oClassname); DDX_Control(pDX,IDC_TREE_CLASS,m_oTreeclass); DDX_Text(pDX,IDC_EDIT_CLASSNAME,m_classname); DDX_Radio(pDX,IDC_RADIO1_DISCOUNT,m_radiodiscount); DDX_Text(pDX,IDC_TEMPID,m_tempid); //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CClassDlg,CDialog) //{{AFX_MSG_MAP(CClassDlg) ON_NOTIFY(TVN_SELCHANGED,IDC_TREE_CLASS,OnSelchangedTreeClass) ON_BN_CLICKED(IDC_BUTTON_ADDSAME,OnButtonAddsame) ON_BN_CLICKED(IDC_BUTTON_ADDSUB,OnButtonAddsub) ON_BN_CLICKED(IDC_BUTTON_DEL,OnButtonDel) ON_BN_CLICKED(IDC_BUTTON_SAVE,OnButtonSave) //}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CClassDlgmessagehandlersvoidCClassDlg::OnSelchangedTreeClass(NMHDR*pNMHDR,LRESULT*pResult){ NM_TREEVIEW*pNMTreeView=(NM_TREEVIEW*)pNMHDR; CStringsql; CStringcurtext; _RecordsetPtrm_pRecordset;//Mustdefineitinfunction!!! HTREEITEMhCurItem; hCurItem=m_oTreeclass.GetSelectedItem();//GetCurrentitemanditssubitems. curtext=m_oTreeclass.GetItemText(hCurItem);//Readcurrentitemtextintoeditcontrol. m_classname=curtext; sql="SELECT*FROMMATERIELCLASSwhereNAME='"+curtext+"'"; try { m_tempid=0; m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText); if(!m_pRecordset->adoEOF) { m_tempid=(long)(m_pRecordset->GetCollect("ID")); Curpar=VariantToCString(m_pRecordset->GetCollect("PARENT")); if((float)(m_pRecordset->GetCollect("DISCOUNT"))==0) m_radiodiscount=0; if((float)(m_pRecordset->GetCollect("DISCOUNT"))==1) m_radiodiscount=1; } m_pRecordset->Close(); } catch(_com_errore)///捕捉異常 { CStringerrormessage; MessageBox("讀取單選按鈕出錯(cuò)!",m_classname); } UpdateData(false); *pResult=0;}voidCClassDlg::AddSubTree(CStringParTree,HTREEITEMhPartItem){ HTREEITEMhCurrent; CStringsql; CStringcurID; _RecordsetPtrm_pTRecordset;//Mustdefineitinfunction!!!BecoursethisisaRECURSIONfunction. sql="SELECT*FROMMATERIELCLASSwherePARENT='"; sql=sql+ParTree+"'";//The1sttimePartree="1". try { m_pTRecordset.CreateInstance("ADODB.Recordset"); m_pTRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText); m_pTRecordset->MoveFirst(); if(!m_pTRecordset->adoEOF) { while(!m_pTRecordset->adoEOF) { hCurrent=m_oTreeclass.InsertItem((LPCTSTR)(_bstr_t)(m_pTRecordset->GetCollect("NAME")),hPartItem,NULL);//Insertanitemintocurrentparent. curID=VariantToCString(m_pTRecordset->GetCollect("ID")); if(TreeSumRecordCount(curID)>0) AddSubTree(VariantToCString(m_pTRecordset->GetCollect("ID")),hCurrent);//Recursion. if(!m_pTRecordset->adoEOF) m_pTRecordset->MoveNext(); } } m_pTRecordset->Close(); } catch(_com_errore)///捕捉異常 { CStringerrormessage; MessageBox("讀取類別子樹出錯(cuò)!",ParTree); }}voidCClassDlg::AddTree(){ TVINSERTSTRUCTtvInsert; HTREEITEMhParent; _RecordsetPtrm_pTRecordset;//Mustdefineitinfunction!!!BecoursethisisaRECURSIONfunction. CStringsroot,sql; tvInsert.hParent=NULL; tvInsert.hInsertAfter=NULL; tvInsert.item.mask=TVIF_TEXT; sql="SELECT*FROMMATERIELCLASSwhereID=1"; try { m_pTRecordset.CreateInstance("ADODB.Recordset"); m_pTRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText); if(!m_pTRecordset->adoEOF) sroot=(LPTSTR)(_bstr_t)m_pTRecordset->GetCollect("NAME");//Insertanitemintocurrentparent. m_pTRecordset->Close(); } catch(_com_errore)///捕捉異常 { CStringerrormessage; errormessage.Format("讀取類別樹出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(errormessage); }// tvInsert.item.pszText=_T("root"); if(sroot!="") {// tvInsert.item.pszText=_T("");//Userthislinetogivethetreeasumroot. hParent=m_oTreeclass.InsertItem(&tvInsert);//HTREEITEMofroot.// AddSubTree("1",hParent);//HerestrChildTreejustmustnotequal"root",canbeanyotherstring. AddSubTree("RootClass",hParent);//HerestrChildTreejustmustnotequal"root",canbeanyotherstring. } m_oTreeclass.Expand(hParent,TVE_EXPAND);}intCClassDlg::TreeSumRecordCount(CStringstrFieldValue){ intSum=0; CStringsql; _RecordsetPtrm_pRecordset;//Mustdefineitinfunction!!!! sql="SELECT*FROMMATERIELCLASSwherePARENT='"; sql=sql+strFieldValue+"'"; try { m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText); if(!m_pRecordset->BOF)//Ifcurrentrecordisnotthefirstrecord. { m_pRecordset->MoveFirst(); while(!m_pRecordset->adoEOF) { Sum+=1; m_pRecordset->MoveNext(); } } m_pRecordset->Close(); } catch(_com_errore)///捕捉異常 { CStringstemp; stemp.Format("計(jì)算類別總數(shù)出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(stemp); } returnSum;}CStringCClassDlg::VariantToCString(VARIANTvar){ CStringstrValue; _variant_tvar_t; _bstr_tbst_t; time_tcur_time; CTimetime_value; COleCurrencyvar_currency; switch(var.vt) { caseVT_EMPTY:strValue=_T("");break; caseVT_UI1:strValue.Format("%d",var.bVal);break; caseVT_I2:strValue.Format("%d",var.iVal);break; caseVT_I4:strValue.Format("%d",var.lVal);break; caseVT_R4:strValue.Format("%f",var.fltVal);break; caseVT_R8:strValue.Format("%f",var.dblVal);break; caseVT_CY: var_currency=var; strValue=var_currency.Format(0); break; caseVT_BSTR: var_t=var; bst_t=var_t; strValue.Format("%s",(constchar*)bst_t); break; caseVT_NULL:strValue=_T("");break; caseVT_DATE: cur_time=var.date; time_value=cur_time; strValue=time_value.Format("%A,%B%d,%Y"); break; caseVT_BOOL:strValue.Format("%d",var.boolVal);break; default:strValue=_T("");break; } returnstrValue;}BOOLCClassDlg::OnInitDialog(){ CDialog::OnInitDialog(); AddTree(); returnTRUE;//returnTRUEunlessyousetthefocustoacontrol //EXCEPTION:OCXPropertyPagesshouldreturnFALSE}voidCClassDlg::OnButtonAddsame(){ CStringsql; CStringnewclassname,Newpar,snewid; longlNewID;//Getnewrecordid. _RecordsetPtrm_pRecordset;//Mustdefineitinfunction!!!! hParentItem=m_oTreeclass.GetParentItem(m_oTreeclass.GetSelectedItem());//Getparentitemhandle. lNewID=GenNewID();//Callthe"GenNewID"functiontogetanewID. snewid.Format("%d",lNewID); Newpar=Curpar; newclassname.Format("新類別%d",lNewID); try { _variant_tRecordsAffected; sql="InsertintoMATERIELCLASS(ID,NAME,DISCOUNT,PARENT)VALUES('"+snewid+"','"+newclassname+"','0','"+Newpar+"')"; if(lNewID==1) sql="InsertintoMATERIELCLASS(ID,NAME,DISCOUNT,PARENT)VALUES(1,'"+newclassname+"','0','RootClass')"; theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText); } catch(_com_errore)///捕捉異常 { CStringerrormessage; errormessage.Format("增加同級(jí)分類出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(errormessage); } m_oClassname.SetWindowText(newclassname); m_oTreeclass.InsertItem((LPCTSTR)(_bstr_t)(newclassname),hParentItem,NULL);//Insertanitemintocurrentparent.}voidCClassDlg::OnButtonAddsub(){ CStringsql; CStringnewclassname,Newpar,snewid; longlNewID; _RecordsetPtrm_pRecordset;//Mustdefineitinfunction!!!! hCurrentItem=m_oTreeclass.GetSelectedItem();//Getcurrentitemhandleassub'sparent. lNewID=GenNewID(); snewid.Format("%d",lNewID); Newpar.Format("%d",m_tempid); newclassname.Format("新類別%d",lNewID); try { _variant_tRecordsAffected; sql="InsertintoMATERIELCLASS(ID,NAME,DISCOUNT,PARENT)VALUES('"+snewid+"','"+newclassname+"','0','"+Newpar+"')"; if(lNewID==1) sql="InsertintoMATERIELCLASS(ID,NAME,DISCOUNT,PARENT)VALUES(1,'"+newclassname+"','0','RootClass')"; theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText); } catch(_com_errore)///捕捉異常 { CStringerrormessage; errormessage.Format("增加下級(jí)分類出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(errormessage); } m_oClassname.SetWindowText(newclassname); m_oTreeclass.InsertItem((LPCTSTR)(_bstr_t)(newclassname),hCurrentItem,NULL);//Insertanitemintocurrentparent.}voidCClassDlg::OnButtonDel(){ CStringsql,curID; _RecordsetPtrm_pRecordset;//Mustdefineitinfunction!!!! HTREEITEMhCurItem; hCurItem=m_oTreeclass.GetSelectedItem();//GetCurrentitemanditssubitems. sql="SELECT*FROMMATERIELCLASSwhereNAME='"; sql=sql+m_classname+"'"; if(AfxMessageBox("確定刪除此類別嗎?",MB_YESNO)==IDYES) { try { m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockPessimistic,adCmdText); if(!m_pRecordset->BOF)//Ifcurrentrecordisnotthefirstrecord. { curID=VariantToCString(m_pRecordset->GetCollect("ID")); if(atol(curID)==1) { MessageBox("不能刪除ID為1的類別!",m_classname); return; } if(TreeSumRecordCount(curID)==0) { if(CountMateriel(curID)>0) MessageBox("此類別下已有商品,不能刪除!"); else { m_pRecordset->Delete(adAffectCurrent);///刪除當(dāng)前記錄 m_oTreeclass.DeleteItem(hCurItem); } } if(TreeSumRecordCount(curID)>0) MessageBox("不能刪除結(jié)點(diǎn)類別!",m_classname); } m_pRecordset->Update(); m_pRecordset->Close(); } catch(_com_errore)///捕捉異常 { CStringerrormessage; MessageBox("刪除類別出錯(cuò)!",m_classname); } }}voidCClassDlg::OnButtonSave(){ CStringsql,parent,name,sdiscount;//,stempid longdiscount; UpdateData(); //檢查數(shù)據(jù)完整性 if(m_classname.IsEmpty()) { AfxMessageBox("類別名稱不能為空!"); return; } m_oClassname.GetWindowText(name);//Getthecurrenttextinedit. if(bRepeat(name)==TRUE) { AfxMessageBox("類別名稱重復(fù)!請(qǐng)重新輸入!"); return; } if(AfxMessageBox("確定要保存修改嗎?",MB_YESNO)==IDYES) { intnDiscount=GetCheckedRadioButton(IDC_RADIO1_DISCOUNT,IDC_RADIO2_DISCOUNT); switch(nDiscount)//Getifitisdiscount. { caseIDC_RADIO1_DISCOUNT: discount=0; break; caseIDC_RADIO2_DISCOUNT: discount=1; break; default: break; } sdiscount.Format("%d",discount);// stempid.Format("%d",m_tempid); try { _variant_tRecordsAffected;// sql="UpdateMATERIELCLASSsetNAME='"+name+"',DISCOUNT='"+sdiscount+"'whereID='"+stempid+"'"; sql.Format("UpdateMATERIELCLASSsetNAME='%s',DISCOUNT=%dwhereID=%d",name,discount,m_tempid);//Mustadd''!!! theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText); hCurrentItem=m_oTreeclass.GetSelectedItem();//Getcurrentitemhandleassub'sparent. m_oTreeclass.SetItemText(hCurrentItem,(LPCTSTR)(_bstr_t)(name)); } catch(_com_errore)///捕捉異常 { CStringstemp; stemp.Format("修改類別出錯(cuò):%s",e.ErrorMessage());// AfxMessageBox(stemp); return; } }}BOOLCClassDlg::bRepeat(CStringstrFieldValue){ CStringsql; BOOLbr; _RecordsetPtrm_pRecordset;//Mustdefineitinfunction!!!! sql="SELECT*FROMMATERIELCLASSWHERENAME='"; sql=sql+strFieldValue+"'"; try { m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); if(m_pRecordset->adoEOF) br=FALSE; if(!m_pRecordset->adoEOF) br=TRUE; m_pRecordset->Close(); } catch(_com_errore)///捕捉異常 { CStringstemp; stemp.Format("查找類別名稱出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(stemp); } returnbr;}intCClassDlg::GenNewID(){ CStringsql; intNewID; _RecordsetPtrm_pRecordset;//Mustdefineitinfunction!!!! sql="SELECTMax(ID)FROMMATERIELCLASS"; try { m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); _variant_tvIndex=(long)0;//Howtogetfieldvalueinonly1recordand1fieldcondition. _variant_tvtemp=m_pRecordset->GetCollect(vIndex); if(vtemp.lVal>0) NewID=(long)(m_pRecordset->GetCollect(vIndex))+1;///取得第一個(gè)字段的值(MAXID)加1后放入id變量. else NewID=1; m_pRecordset->Close(); } catch(_com_errore)///捕捉異常 { CStringstemp; stemp.Format("獲取類別ID最大值出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(stemp); } returnNewID;}intCClassDlg::CountMateriel(CStringsclassid){ CStringsql; intncount; _RecordsetPtrm_pRecordset;//Mustdefineitinfunction!!!! sql="SELECTcount(*)asXXXFROMMATERIELwhereclassid="+sclassid+""; try { m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); ncount=(long)m_pRecordset->GetCollect("XXX"); m_pRecordset->Close(); } catch(_com_errore)///捕捉異常 { CStringstemp; stemp.Format("計(jì)算類別下商品數(shù)量出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(stemp); } returnncount;}#if!defined(AFX_CHECKDLG_H__308FEC04_0401_46B6_B7DB_78EB89ABB23A__INCLUDED_)#defineAFX_CHECKDLG_H__308FEC04_0401_46B6_B7DB_78EB89ABB23A__INCLUDED_#if_MSC_VER>1000#pragmaonce#endif//_MSC_VER>1000//CheckDlg.h:headerfile/////////////////////////////////////////////////////////////////////////////////CCheckDlgdialogclassCCheckDlg:publicCDialog{//Constructionpublic: longGetPaymodeID(CStringpayname); CCheckDlg(CWnd*pParent=NULL);//standardconstructor//DialogData //{{AFX_DATA(CCheckDlg) enum{IDD=IDD_DIALOG_CHECK}; CEdit m_oConsume; CEdit m_oCdiscount; CEdit m_oReceive; CEdit m_oChange; CEdit m_oTotalm; CComboBox m_oCombopay; CListCtrl m_oChecklist; //}}AFX_DATA//Overrides //ClassWizardgeneratedvirtualfunctionoverrides //{{AFX_VIRTUAL(CCheckDlg) protected: virtualvoidDoDataExchange(CDataExchange*pDX);//DDX/DDVsupport //}}AFX_VIRTUAL//Implementationprotected: //Generatedmessagemapfunctions //{{AFX_MSG(CCheckDlg) virtualBOOLOnInitDialog(); afx_msgvoidOnButtonCheckok(); afx_msgvoidOnChangeEditReceive(); afx_msgvoidOnClickListChecklist(NMHDR*pNMHDR,LRESULT*pResult); afx_msgvoidOnChangeEditCdiscount(); afx_msgvoidOnButtonRf(); afx_msgvoidOnButtonHang(); //}}AFX_MSG DECLARE_MESSAGE_MAP()private: CStringGetClassName(longlclassid); longVerifyDicsount(); voidReadtoList(CStringsbillid); floatfchange;};//{{AFX_INSERT_LOCATION}}//MicrosoftVisualC++willinsertadditionaldeclarationsimmediatelybeforethepreviousline.#endif//!defined(AFX_CHECKDLG_H__308FEC04_0401_46B6_B7DB_78EB89ABB23A__INCLUDED_)//CheckDlg.cpp:implementationfile//#include"stdafx.h"#include"MyPos.h"#include"CheckDlg.h"#include"PosDlg.h"#ifdef_DEBUG#definenewDEBUG_NEW#undefTHIS_FILEstaticcharTHIS_FILE[]=__FILE__;#endif///////////////////////////////////////////////////////////////////////////////CCheckDlgdialogexternCMyPosApptheApp;CCheckDlg::CCheckDlg(CWnd*pParent/*=NULL*/) :CDialog(CCheckDlg::IDD,pParent){ //{{AFX_DATA_INIT(CCheckDlg) //}}AFX_DATA_INIT}voidCCheckDlg::DoDataExchange(CDataExchange*pDX){ CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CCheckDlg) DDX_Control(pDX,IDC_EDIT_CONSUME,m_oConsume); DDX_Control(pDX,IDC_EDIT_CDISCOUNT,m_oCdiscount); DDX_Control(pDX,IDC_EDIT_RECEIVE,m_oReceive); DDX_Control(pDX,IDC_EDIT_CHANGE,m_oChange); DDX_Control(pDX,IDC_EDIT_TOTALM,m_oTotalm); DDX_Control(pDX,IDC_COMBO_PAYMODE,m_oCombopay); DDX_Control(pDX,IDC_LIST_CHECKLIST,m_oChecklist); //}}AFX_DATA_MAP}BEGIN_MESSAGE_MAP(CCheckDlg,CDialog) //{{AFX_MSG_MAP(CCheckDlg) ON_BN_CLICKED(IDC_BUTTON_CHECKOK,OnButtonCheckok) ON_EN_CHANGE(IDC_EDIT_RECEIVE,OnChangeEditReceive) ON_NOTIFY(NM_CLICK,IDC_LIST_CHECKLIST,OnClickListChecklist) ON_EN_CHANGE(IDC_EDIT_CDISCOUNT,OnChangeEditCdiscount) ON_BN_CLICKED(IDC_BUTTON_RF,OnButtonRf) ON_BN_CLICKED(IDC_BUTTON_HANG,OnButtonHang) //}}AFX_MSG_MAPEND_MESSAGE_MAP()///////////////////////////////////////////////////////////////////////////////CCheckDlgmessagehandlersBOOLCCheckDlg::OnInitDialog(){ CDialog::OnInitDialog(); //設(shè)置list控件的文字和背景顏色 m_oChecklist.SetBkColor(RGB(255,255,255)); m_oChecklist.SetTextBkColor(RGB(161,223,212)); //清空list控件的數(shù)據(jù) for(intdelcolumn=100;delcolumn>=0;delcolumn--) m_oChecklist.DeleteColumn(delcolumn); //設(shè)置list對(duì)話框的列 DWORDdwStyle; RECTrect; LV_COLUMNlvc; dwStyle=m_oChecklist.GetStyle(); dwStyle|=LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_SHOWSELALWAYS; m_oChecklist.SetExtendedStyle(dwStyle); m_oChecklist.GetClientRect(&rect); lvc.mask=LVCF_TEXT|LVCF_SUBITEM|LVCF_WIDTH|LVCF_FMT; lvc.fmt=LVCFMT_LEFT; lvc.iSubItem=0; lvc.pszText=_T("商品類別"); lvc.cx=110; m_oChecklist.InsertColumn(1,&lvc); lvc.iSubItem=1; lvc.pszText=_T("消費(fèi)金額"); lvc.cx=90; m_oChecklist.InsertColumn(2,&lvc); lvc.iSubItem=2; lvc.pszText=_T("可折扣金額"); lvc.cx=90; m_oChecklist.InsertColumn(3,&lvc); lvc.iSubItem=3; lvc.pszText=_T("折扣%"); lvc.cx=60; m_oChecklist.InsertColumn(4,&lvc); lvc.iSubItem=4; lvc.pszText=_T("結(jié)帳金額"); lvc.cx=90; m_oChecklist.InsertColumn(5,&lvc); //Addpaymodetocombobox. _RecordsetPtrm_pRecordset; CStringsql="select*fromPAYMODE"; try { m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); while(!m_pRecordset->adoEOF) { m_oCombopay.AddString((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("NAME")); m_pRecordset->MoveNext(); } m_pRecordset->Close(); m_oCombopay.SetCurSel(0);//Selectthe1ststringofcombobox. } catch(_com_errore)///捕捉異常 { CStringtemp; temp.Format("[結(jié)帳]讀取付款方式到組合框出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(temp); } //Readclassconsumetolist. ReadtoList(theApp.scallid); //SumbillItemsmoneyfromdatabase. CStringstotal; floatftotal=0; sql="SelectSUM(ITEMTOTAL)asSSSfromSALEDETAILwhereBILLID='"+theApp.scallid+"'"; try { m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); _variant_tvtemp=m_pRecordset->GetCollect("SSS"); if(vtemp.dblVal>0) ftotal=(float)m_pRecordset->GetCollect("SSS"); else ftotal=0; stotal.Format("%.2f",ftotal); m_oTotalm.SetWindowText(stotal); m_oConsume.SetWindowText(stotal); } catch(_com_errore)///捕捉異常 { CStringtemp; temp.Format("[結(jié)帳]計(jì)算單據(jù)商品金額出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(temp); } returnTRUE;//returnTRUEunlessyousetthefocustoacontrol //EXCEPTION:OCXPropertyPagesshouldreturnFALSE}voidCCheckDlg::OnButtonCheckok(){ CStringstotal,sbilltotal,spayID,sql,spaymode,snowtime; longlpayID; _RecordsetPtrm_pRecordset; m_oConsume.GetWindowText(stotal); m_oTotalm.GetWindowText(sbilltotal); intnselect=m_oCombopay.GetCurSel(); m_oCombopay.GetLBText(nselect,spaymode); lpayID=GetPaymodeID(spaymode); spayID.Format("%d",lpayID); if(fchange<0) return; //得到系統(tǒng)時(shí)間 CTimenow=CTime::GetCurrentTime(); snowtime=now.Format(_T("%Y-%m-%d%H:%M:%S")); sql="UpdateSALEBILLsetENDDATE='"+snowtime+"',SALES='"+theA+"',TOTAL=" +stotal+",ACTTOTAL="+sbilltotal+",STATUS='已結(jié)帳',PAYMODE="+spayID+"whereID='"+theApp.scallid+"'"; try { _variant_tRecordsAffected; theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText); } catch(_com_errore)///捕捉異常 { CStringtemp; temp.Format("[結(jié)帳]單據(jù)頭更新數(shù)據(jù)庫(kù)出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(temp); return; } //outputthecheckouttimeandpaymodetotheprint. theApp.snowtimep=snowtime; theApp.spaymodep=spaymode; theApp.sconsume=stotal; theApp.sactsum=sbilltotal; //InsertdataintoPAYDETAIL. CStringsclass,scontotal,sdiscount,sacttotal,svaltotal; intnItemCount=m_oChecklist.GetItemCount();//表項(xiàng)總數(shù) for(inti=0;i<nItemCount;i++) { sclass=m_oChecklist.GetItemText(i,0); scontotal=m_oChecklist.GetItemText(i,1); sdiscount=m_oChecklist.GetItemText(i,3); sacttotal=m_oChecklist.GetItemText(i,4); floatfvaltotal=atof(scontotal)-atof(sacttotal); svaltotal.Format("%.2f",fvaltotal); sql="InsertintoPAYDETAIL(BILLID,CLASS,TOTAL,DISCOUNT,ACTTOTAL,VALTOTAL)values('"+theApp.scallid+ "','"+sclass+"',"+scontotal+",'"+sdiscount+"',"+sacttotal+","+svaltotal+")"; try { _variant_tRecordsAffected; theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText); } catch(_com_errore)///捕捉異常 { CStringtemp; temp.Format("[結(jié)帳]付款明細(xì)(PAYDETAIL)插入數(shù)據(jù)出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(temp); return; } } //Whenthecheckbuttonisclickdown,sendamessage(WM_CHECKOUT)totheCPosDlg. LRESULTRes=::SendMessage(theApp.pWnd,WM_CHECKOUT,0,0); CDialog::OnOK();}longCCheckDlg::GetPaymodeID(CStringpayname){ longpaymodeID; _RecordsetPtrm_pRecordset; CStringsql="Select*fromPAYMODEwhereNAME='"+payname+"'"; try { m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); paymodeID=(long)m_pRecordset->GetCollect("ID"); } catch(_com_errore)///捕捉異常 { CStringtemp; temp.Format("[結(jié)帳]獲取付款方式ID出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(temp); } returnpaymodeID;}voidCCheckDlg::OnChangeEditReceive(){ //TODO:IfthisisaRICHEDITcontrol,thecontrolwillnot //sendthisnotificationunlessyouoverridetheCDialog::OnInitDialog() //functionandcallCRichEditCtrl().SetEventMask() //withtheENM_CHANGEflagORedintothemask. CStringsreceive,schange,stotal; m_oChange.SetWindowText(""); m_oReceive.GetWindowText(sreceive); m_oTotalm.GetWindowText(stotal); fchange=atof(sreceive)-atof(stotal); if(fchange>=0) { schange.Format("%.2f",fchange); m_oChange.SetWindowText(schange); }}voidCCheckDlg::ReadtoList(CStringsbillid){ _RecordsetPtrm_pRecordset;//Mustdefineitinfunction!!!! CStringsql,sclassname,sclassname1,sctotal; longlclassid; floatfctotal=0; sql="SelectSum(ITEMTOTAL)asXXX,CLASSIDfromSALEDETAILwhereBILLID='"+sbillid+"'groupbyCLASSID"; //刪除所有l(wèi)ist中的數(shù)據(jù)。 m_oChecklist.DeleteAllItems(); intnumline=0; try { m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); LV_ITEMlvitem; lvitem.pszText=""; lvitem.mask=LVIF_TEXT; lvitem.iSubItem=0; while(!m_pRecordset->adoEOF) { lvitem.iItem=numline; m_oChecklist.InsertItem(&lvitem); //讀出數(shù)據(jù)寫入到list中 lclassid=(long)m_pRecordset->GetCollect("CLASSID"); sclassname=GetClassName(lclassid); sclassname1=sclassname.Left(sclassname.GetLength()-4); m_oChecklist.SetItemText(numline,0,sclassname1);//Readclassnameto0column. fctotal=(float)m_pRecordset->GetCollect("XXX"); sctotal.Format("%.2f",fctotal); m_oChecklist.SetItemText(numline,1,sctotal);//Readclassconsumetotalto1stcolumn. if(sclassname.Right(1)=="0") m_oChecklist.SetItemText(numline,2,"0.00");//Readclassconsumediscounttotalto2ndcolumn. else m_oChecklist.SetItemText(numline,2,sctotal); m_oChecklist.SetItemText(numline,3,"100"); m_oChecklist.SetItemText(numline,4,sctotal);//Readclassconsumeacttotalto4thcolumn. numline++; m_pRecordset->MoveNext(); } m_pRecordset->Close(); } catch(_com_errore)///捕捉異常 { CStringtemp; temp.Format("[結(jié)帳]列表讀入商品出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(temp); return; }}CStringCCheckDlg::GetClassName(longlclassid){ _RecordsetPtrm_pRecordset;//Mustdefineitinfunction!!!! CStringsql,sclassid,sname,sdiscount; sclassid.Format("%d",lclassid); sql="SelectNAME,DISCOUNTfromMATERIELCLASSwhereID="+sclassid+""; try { m_pRecordset.CreateInstance("ADODB.Recordset"); m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText); if(!m_pRecordset->adoEOF) { sname=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("NAME"); sdiscount=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("DISCOUNT"); sname=sname+"xxx"+sdiscount; } } catch(_com_errore)///捕捉異常 { CStringtemp; temp.Format("[結(jié)帳]獲取類別名稱出錯(cuò):%s",e.ErrorMessage()); AfxMessageBox(temp); } returnsname;}voidCCheckDlg::OnClickListChecklist(NMHDR*pNMHDR,LRESULT*pResult){ //得到當(dāng)前選中的行 POSITIONpos=m_oChecklist.GetFirstSelectedItemPosition(); //如果選中一行 if(pos) { intnItem=m_oChecklist.GetNextSelectedItem(pos); CString sdiscount=m_oChecklist.GetItemText(nItem,3); m_oCdiscount.SetWindowText(sdiscount); } *pResult=0;}voidCCheckDlg::OnChangeEditCdiscount(){ //TODO:IfthisisaRICHEDITcontrol,thecontrolwillnot //sendthisnotificationunlessyouoverridetheCDialog::OnInitDialog() //functionandcallCRichEditCtrl().SetEventMask() //withtheENM_CHANGEflagORedintothemask. CStringsdiscountsum,sdiscount,ssum; floatfdiscountsum,fsum; longldiscount; LV_ITEMlvitem; lvitem.pszText=""; lvitem.mask=LVIF_TEXT; //得到當(dāng)前選中的行 POSITIONpos=m_oChecklist.GetFirstSelectedItemPosition(); //如果選中一行 if(pos) { intnItem=m_oChecklist.GetNextSelected
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 2025版?zhèn)€人房產(chǎn)買賣合同違約責(zé)任范本4篇
- 二零二五版智能倉(cāng)儲(chǔ)物流系統(tǒng)安裝與優(yōu)化合同3篇
- 二零二五版環(huán)保節(jié)能改造項(xiàng)目工程合同4篇
- 2025年度個(gè)人房產(chǎn)交易安全評(píng)估及買賣合同大全3篇
- 2025年度留學(xué)學(xué)術(shù)誠(chéng)信教育合同4篇
- 2025版企業(yè)職工失業(yè)保險(xiǎn)補(bǔ)貼資金支付合同3篇
- 2025年校園樂器維護(hù)保養(yǎng)及采購(gòu)代理服務(wù)合同2篇
- 濟(jì)南2025版房屋買賣合同產(chǎn)權(quán)登記與稅務(wù)申報(bào)指南3篇
- 互聯(lián)網(wǎng)客服專員2025年度績(jī)效合同2篇
- 2025年度海洋運(yùn)輸貨物保險(xiǎn)合同保險(xiǎn)責(zé)任與保險(xiǎn)合同效力3篇
- 二零二五年度無人駕駛車輛測(cè)試合同免責(zé)協(xié)議書
- 2025年湖北華中科技大學(xué)招聘實(shí)驗(yàn)技術(shù)人員52名歷年高頻重點(diǎn)提升(共500題)附帶答案詳解
- 高三日語一輪復(fù)習(xí)助詞「と」的用法課件
- 毛渣采購(gòu)合同范例
- 2023中華護(hù)理學(xué)會(huì)團(tuán)體標(biāo)準(zhǔn)-注射相關(guān)感染預(yù)防與控制
- 五年級(jí)上冊(cè)小數(shù)遞等式計(jì)算200道及答案
- 2024年廣東高考政治真題考點(diǎn)分布匯 總- 高考政治一輪復(fù)習(xí)
- 燃?xì)夤艿滥甓葯z驗(yàn)報(bào)告
- GB/T 44052-2024液壓傳動(dòng)過濾器性能特性的標(biāo)識(shí)
- FZ/T 81013-2016寵物狗服裝
- JB∕T 14089-2020 袋式除塵器 濾袋運(yùn)行維護(hù)技術(shù)規(guī)范
評(píng)論
0/150
提交評(píng)論