📄 posdlg.cpp
字号:
// PosDlg.cpp : implementation file
//
#include "stdafx.h"
#include "MyPos.h"
#include "PosDlg.h"
#include "SelectDlg.h"
#include "ModifyqaDlg.h"
#include "CallDlg.h"
#include "CheckDlg.h"
#include "OffdutyDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CPosDlg dialog
extern CMyPosApp theApp;
CPosDlg::CPosDlg(CWnd* pParent /*=NULL*/)
: CDialog(CPosDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CPosDlg)
//}}AFX_DATA_INIT
}
void CPosDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CPosDlg)
DDX_Control(pDX, IDC_EDIT_ACTTOTAL, m_oActtotal);
DDX_Control(pDX, IDC_EDIT_TOTAL, m_oTotal);
DDX_Control(pDX, IDC_BUTTON_SELMATERIEL, m_oButton);
DDX_Control(pDX, IDC_LIST_FORM, m_oFormlist);
DDX_Control(pDX, IDC_EDIT_BEGINTIME, m_oBegintime);
DDX_Control(pDX, IDC_EDIT_ENDTIME, m_oEndtime);
DDX_Control(pDX, IDC_EDIT_CKECK, m_oCheck);
DDX_Control(pDX, IDC_EDIT_STATUS, m_oStatus);
DDX_Control(pDX, IDC_EDIT_PEASONS, m_oPeasons);
DDX_Control(pDX, IDC_EDIT_TABLENO, m_oTableno);
DDX_Control(pDX, IDC_LIST_BILL, m_oListbill);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CPosDlg, CDialog)
//{{AFX_MSG_MAP(CPosDlg)
ON_BN_CLICKED(IDC_BUTTON_ADDF, OnButtonAddf)
ON_LBN_SELCHANGE(IDC_LIST_BILL, OnSelchangeListBill)
ON_BN_CLICKED(IDC_BUTTON_SELMATERIEL, OnButtonSelmateriel)
ON_NOTIFY(NM_DBLCLK, IDC_LIST_FORM, OnDblclkListForm)
ON_BN_CLICKED(IDC_BUTTON_CALLF, OnButtonCallf)
ON_BN_CLICKED(IDC_BUTTON_DELF, OnButtonDelf)
ON_BN_CLICKED(IDC_BUTTON_HIDEF, OnButtonHidef)
ON_BN_CLICKED(IDC_BUTTON_CHECKF, OnButtonCheckf)
ON_EN_KILLFOCUS(IDC_EDIT_TABLENO, OnKillfocusEditTableno)
ON_EN_KILLFOCUS(IDC_EDIT_PEASONS, OnKillfocusEditPeasons)
ON_BN_CLICKED(IDC_BUTTON_OFF, OnButtonOff)
ON_BN_CLICKED(IDC_BUTTON_FINDF, OnButtonFindf)
ON_BN_CLICKED(IDC_BUTTON_LOCALP, OnButtonLocalp)
//}}AFX_MSG_MAP
ON_MESSAGE(WM_APPLY,OnMyMessage)//Map WM_APPLY message to OnMyMessage function.
ON_MESSAGE(WM_CHECKOUT,OnMyCheckMessage)//Map WM_CHECKOUT message to OnMyMessage function.
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CPosDlg message handlers
BOOL CPosDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//设置list控件的文字和背景颜色
m_oFormlist.SetBkColor(RGB(255,255,255));
m_oFormlist.SetTextBkColor(RGB(161,223,212));
//清空list控件的数据
for(int delcolumn=100;delcolumn>=0;delcolumn--)
m_oFormlist.DeleteColumn(delcolumn);
//设置list对话框的列
DWORD dwStyle;
RECT rect;
LV_COLUMN lvc;
dwStyle = m_oFormlist.GetStyle();
dwStyle |= LVS_EX_GRIDLINES |LVS_EX_FULLROWSELECT |LVS_SHOWSELALWAYS |LVS_EDITLABELS ;
m_oFormlist.SetExtendedStyle(dwStyle);
m_oFormlist.GetClientRect(&rect);
lvc.mask = LVCF_TEXT | LVCF_SUBITEM | LVCF_WIDTH |LVCF_FMT;
lvc.fmt=LVCFMT_LEFT;
lvc.iSubItem = 0;
lvc.pszText = _T("序号");
lvc.cx = 70;
m_oFormlist.InsertColumn(1,&lvc);
lvc.iSubItem = 1;
lvc.pszText = _T("名称");
lvc.cx = 220;
m_oFormlist.InsertColumn(2,&lvc);
lvc.iSubItem = 2;
lvc.pszText = _T("数量");
lvc.cx = 80;
m_oFormlist.InsertColumn(3,&lvc);
lvc.iSubItem = 3;
lvc.pszText = _T("金额");
lvc.cx = 120;
m_oFormlist.InsertColumn(4,&lvc);
//Add all bill whos state is "等待" to listbill.
CString sql="Select * from SALEBILL where STATUS<>'已结帐'";
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
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_oListbill.AddString((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ID"));
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString stemp;
stemp.Format("[初始化]读取 '等待' 单据出错:%s",e.ErrorMessage());
AfxMessageBox(stemp);
}
//Select the last billid in listbox and read its items to listctrl and head to edit.
int ncount=m_oListbill.GetCount();
if(ncount>0)
{
CString sbillid;
int nselect;
nselect=m_oListbill.SetCurSel(ncount-1);
m_oListbill.GetText(nselect,sbillid);
ReadBillHead(sbillid);
ReadToFormlist(sbillid);
}
else
{
//Put the button to the first list row.
//将button移到合适的位置并设置其大小
m_oFormlist.GetWindowRect(&rect);
m_oButton.MoveWindow(440,95, rect.right/33, rect.bottom/25);
m_oButton.BringWindowToTop();
m_oButton.ShowWindow(SW_SHOW);//从隐藏变为显示
}
theApp.pWnd=GetSafeHwnd();//Initialize pWnd;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CPosDlg::OnButtonAddf()
{
CString snowtime,sfloor,snewid,sbillno;
CString sql;
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
sfloor=GetCompanyFloor(FALSE);
//Clear the edit ctrl.
m_oTableno.SetWindowText("");
m_oPeasons.SetWindowText("");
//得到系统时间
CTime now=CTime::GetCurrentTime();
snowtime=now.Format(_T("%Y-%m-%d %H:%M:%S"));
sbillno=GenNewBillID();
sql="Insert into SALEBILL (ID,BEGINDATE,STATUS,TOTAL,ACTTOTAL,PAYMODE,FLOOR) values ('"+sbillno+"','"+snowtime+"','等待',0,0,1,'"+sfloor+"')";
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;
}
m_oStatus.SetWindowText("等待");
m_oBegintime.SetWindowText(snowtime);
m_oTotal.SetWindowText("0.00");
m_oActtotal.SetWindowText("0.00");
m_oListbill.AddString(sbillno);
m_oListbill.SelectString(-1,sbillno);
theApp.scallid=sbillno;//Get current bill id.
m_oFormlist.DeleteAllItems();
RECT rect;
m_oFormlist.GetWindowRect(&rect);
m_oButton.MoveWindow(440,95, rect.right/40, rect.bottom/35);
m_oButton.BringWindowToTop();
m_oButton.ShowWindow(SW_SHOW);//从隐藏变为显示
}
CString CPosDlg::GenNewBillID()
{
CString sql,snowtime;
CString sNewID,scurid,snewid;
long lnewid,lcount;
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
//得到系统时间
CTime now=CTime::GetCurrentTime();
snowtime=now.Format(_T("%Y%m%d"));
sql="Select count(*) as XXX from SALEBILL where ID like '"+snowtime+"%""'";
lcount=GetRecordCount(sql);
if(lcount==0)
{
sNewID.Format("%s-00001",snowtime);
return sNewID;
}
sql="Select Max(ID) as AAA from SALEBILL where ID like '"+snowtime+"%""'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText);
scurid=(LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("AAA");
lnewid=atol(scurid.Right(5))+1;
snewid.Format("-%05d",lnewid);
sNewID=snowtime+snewid;
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString stemp;
stemp.Format("获取最大单据编号出错:%s",e.ErrorMessage());
AfxMessageBox(stemp);
}
return sNewID;
}
void CPosDlg::OnSelchangeListBill()
{
CString stemp,sql,sbillid;
int iOption;
_RecordsetPtr m_pRecordset;
iOption = m_oListbill.GetCurSel();
m_oListbill.GetText(iOption, sbillid);//得到选中项的文本
theApp.scallid=sbillid;//Get current bill id.
//Clear the edit ctrl.
m_oTableno.SetWindowText("");
m_oPeasons.SetWindowText("");
sql="select * from SALEBILL where ID='"+sbillid+"'";
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)
{
m_oTableno.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("TABLENO"));
m_oPeasons.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("PEOPLES"));
m_oCheck.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("SALES"));
m_oStatus.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("STATUS"));
m_oBegintime.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("BEGINDATE"));
m_oEndtime.SetWindowText((LPCTSTR)(_bstr_t)m_pRecordset->GetCollect("ENDDATE"));
float ftotal=(float)m_pRecordset->GetCollect("TOTAL");
CString stotal;
stotal.Format("%.2f",ftotal);
m_oTotal.SetWindowText(stotal);
ftotal=(float)m_pRecordset->GetCollect("ACTTOTAL");
stotal.Format("%.2f",ftotal);
m_oActtotal.SetWindowText(stotal);
}
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("读取单据头到编辑框出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
ReadToFormlist(sbillid);//Get bill items from database.
int i=m_oFormlist.GetItemCount();
RECT rect;
m_oFormlist.GetWindowRect(&rect);
m_oButton.MoveWindow(440,95+i*15, rect.right/40, rect.bottom/35);
m_oButton.BringWindowToTop();
m_oButton.ShowWindow(SW_SHOW);//从隐藏变为显示
}
BEGIN_EVENTSINK_MAP(CPosDlg, CDialog)
//{{AFX_EVENTSINK_MAP(CPosDlg)
//}}AFX_EVENTSINK_MAP
END_EVENTSINK_MAP()
void CPosDlg::OnMyMessage()
{
//When CPosDlgDlg received the WM_APPLY message from CSelectDlg
//it call the AddItemToList() to fill list.
AddItemToList();
//-------------------------------------------------//
CString smID,sqa,ssum,sno,sql,stotal,sbillid;
CString sclassid;
long lrowno;
int iOption;
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
iOption = m_oListbill.GetCurSel();
m_oListbill.GetText(iOption, sbillid);//得到选中项的文本
lrowno=GetRowNo(sbillid);
sno.Format("%d",lrowno); //rowno.
ssum=theApp.sprice;
//Get class ID.
sql="Select CLASSID from materiel where ID="+theApp.smID+"";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
long lclassid=(long)m_pRecordset->GetCollect("CLASSID");//How to get field value in only 1 record and 1 field condition.
sclassid.Format("%d",lclassid);
m_pRecordset->Close();
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("[选择商品]读取商品类别ID出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
sql="Insert into SALEDETAIL (BILLID,MATERIELID,ITEMCOUNT,ITEMTOTAL,CLASSID,ROWNO,ACTPRICE) values ('"+sbillid+"',"
+theApp.smID+",1,"+ssum+","+sclassid+","+sno+","+ssum+")";
try
{ _variant_t RecordsAffected;
theApp.m_pConnection->Execute((_bstr_t)sql,&RecordsAffected,adCmdText);
UpdateData(FALSE);
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("[选择商品]插入商品到数据库出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
return;
}
stotal=SumItemtotal(sbillid);
sql="Update SALEBILL set TOTAL="+stotal+" where ID='"+sbillid+"'";
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;
}
m_oTotal.SetWindowText(stotal);
// ReadToFormlist(sbillid);
}
void CPosDlg::AddItemToList()
{
CString snumline;
int numline=0,nmax;
LV_ITEM lvitem;
lvitem.pszText="";
lvitem.mask=LVIF_TEXT;
lvitem.iSubItem=0;
numline=m_oFormlist.GetItemCount();
lvitem.iItem=numline;
snumline=m_oFormlist.GetItemText(numline-1,0);
nmax=atoi(snumline)+1;
snumline.Format("%d",nmax);
m_oFormlist.InsertItem(&lvitem);
//读出数据写入到list中
m_oFormlist.SetItemText(numline,0,snumline);
m_oFormlist.SetItemText(numline,1,theApp.smname);
m_oFormlist.SetItemText(numline,2,"1");
m_oFormlist.SetItemText(numline,3,theApp.sprice);
//Move the select button to next line.
RECT rect;
m_oFormlist.GetWindowRect(&rect);
m_oButton.MoveWindow(440,110+numline*15, rect.right/40, rect.bottom/35);
m_oButton.BringWindowToTop();
m_oButton.ShowWindow(SW_SHOW);//从隐藏变为显示
}
long CPosDlg::GetRowNo(CString sbillid)
{
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
CString sql,sname;
long lrowno,lcount;
sql="Select Count(*) AS XXX from SALEDETAIL where BILLID='"+sbillid+"'";
lcount=GetRecordCount(sql);
if(lcount==0)
{
lrowno=1;
return lrowno;
}
sql="Select MAX(ROWNO) AS RRR from SALEDETAIL where BILLID='"+sbillid+"'";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenDynamic,adLockOptimistic,adCmdText);
lrowno=(long)m_pRecordset->GetCollect("RRR")+1;//How to get field value in only 1 record and 1 field condition.
}
catch(_com_error e)///捕捉异常
{
CString temp;
temp.Format("[单据]读取商品序号出错:%s",e.ErrorMessage());
AfxMessageBox(temp);
}
return lrowno;
}
CString CPosDlg::GetMaterielName(long materielid)
{
_RecordsetPtr m_pRecordset; //Must define it in function!!!!
CString sql,smaterielid,sname;
smaterielid.Format("%d",materielid);
sql="Select NAME from MATERIEL where ID="+smaterielid+"";
try
{
m_pRecordset.CreateInstance("ADODB.Recordset");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -