【VC开源代码栏目提醒】:以下是网学会员为您推荐的VC开源代码-CheckDlg.cpp,希望本篇文章对您学习有所帮助。
// CheckDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MyPos.h"
#include "CheckDlg.h"
#include "PosDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCheckDlg dialog
extern CMyPosApp theApp;
CCheckDlg::CCheckDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCheckDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCheckDlg)
//}}AFX_DATA_INIT
}
void CCheckDlg::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_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCheckDlg message handlers
BOOL CCheckDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//设置list控件的文字和背景颜色
m_oChecklist.SetBkColor(RGB(255,255,255));
m_oChecklist.SetTextBkColor(RGB(161,223,212));
//清空list控件的数据
for(int delcolumn=100;delcolumn>=0;delcolumn--)
m_oChecklist.DeleteColumn(delcolumn);
//设置list对话框的列
DWORD dwStyle;
RECT rect;
LV_COLUMN lvc;
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("消费金额");
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("结帐金额");
lvc.cx = 90;
m_oChecklist.InsertColumn(5,&lvc);
//Add paymode to combobox.
_RecordsetPtr m_pRecordset;
CString sql="select * from PAYMODE";
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);//Select the 1st string of combobox.
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("[结帐]读取付款方式到组合框出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
//Read class consume to list.
ReadtoList(theApp.scallid);
//Sum bill Items money from database.
CString stotal;
float ftotal=0;
sql="Select SUM(ITEMTOTAL) as SSS from SALEDETAIL where BILLID='"+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_t vtemp = 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_error e)///捕捉异常
{
CString temp;
temp.Format("[结帐]计算单据商品金额出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCheckDlg::OnButtonCheckok()
{
CString stotal,sbilltotal,spayID,sql,spaymode,snowtime;
long lpayID;
_RecordsetPtr m_pRecordset;
m_oConsume.GetWindowText(stotal);
m_oTotalm.GetWindowText(sbilltotal);
int nselect=m_oCombopay.GetCurSel();
m_oCombopay.GetLBText(nselect,spaymode);
lpayID=GetPaymodeID(spaymode);
spayID.Format("%d",lpayID);
if(fchange<0)
return;
//得到系统时间
CTime now=CTime::GetCurrentTime();
snowtime=now.Format(_T("%Y-%m-%d %H:%M:%S"));
sql="Update SALEBILL set ENDDATE='"+snowtime+"',SALES='"+theApp.name+"',TOTAL="
+stotal+",ACTTOTAL="+sbilltotal+",STATUS='已结帐',PAYMODE="+spayID+" where ID='"+theApp.scallid+"'";
try
{
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("[结帐]单据头更新数据库出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
//output the checkout time and paymode to the print.
theApp.snowtimep=snowtime;
theApp.spaymodep=spaymode;
theApp.sconsume=stotal;
theApp.sactsum=sbilltotal;
//Insert data into PAYDETAIL.
CString sclass,scontotal,sdiscount,sacttotal,svaltotal;
int nItemCount=m_oChecklist.GetItemCount();//表项总数
for(int i=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);
float fvaltotal=atof(scontotal)-atof(sacttotal);
svaltotal.Format("%.2f",fvaltotal);
sql="Insert into PAYDETAIL(BILLID,CLASS,TOTAL,DISCOUNT,ACTTOTAL,VALTOTAL) values('"+theApp.scallid+
"','"+sclass+"',"+scontotal+",'"+sdiscount+"',"+sacttotal+","+svaltotal+")";
try
{
_variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("[结帐]付款明细(PAYDETAIL)插入数据出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
}
//When the c
上一篇:
CheckBorrowDlg.cpp
下一篇:
还记得,那年的风车吗?