📄 dsellback.cpp
字号:
// DSellBack.cpp : implementation file
//
#include "stdafx.h"
#include "商品销售管理系统.h"
#include "DSellBack.h"
#include "RxEdit.h"
#include "MyDoc.h"
#include "MainPrint.h"
#include "MyView.h"
#include "externDllHeader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDSellBack dialog
CDSellBack::CDSellBack(CWnd* pParent /*=NULL*/)
: CDialog(CDSellBack::IDD, pParent)
{
//{{AFX_DATA_INIT(CDSellBack)
//}}AFX_DATA_INIT
}
void CDSellBack::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDSellBack)
DDX_Control(pDX, IDC_STANOTPAY, m_StaNotPay);
DDX_Control(pDX, IDC_STAGIVECHANGE, m_StaGiveChange);
DDX_Control(pDX, IDC_EDTPAY, m_EdtPay);
DDX_Control(pDX, IDC_STASumNumber, m_StaSumNumber);
DDX_Control(pDX, IDC_STASmallSum, m_StaSmallSum);
DDX_Control(pDX, IDC_STAID, m_StaID);
DDX_Control(pDX, IDC_STADate, m_StaDate);
DDX_Control(pDX, IDC_STABigSum, m_StaBigSum);
DDX_Control(pDX, IDC_List, m_Grid);
DDX_Control(pDX, IDC_EDTDEALMAN, m_EdtDealMan);
DDX_Control(pDX, IDC_EDTCLIECT, m_EdtCliect);
DDX_Control(pDX, IDC_COMRID, m_ComRID);
DDX_Control(pDX, IDC_BUTUndo, m_ButUndo);
DDX_Control(pDX, IDC_BUTSave, m_ButSave);
DDX_Control(pDX, IDC_BUTPrint, m_ButPrint);
DDX_Control(pDX, IDC_BUTExit, m_ButExit);
DDX_Control(pDX, IDC_BUTCleck, m_ButCleck);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDSellBack, CDialog)
//{{AFX_MSG_MAP(CDSellBack)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTCleck, OnBUTCleck)
ON_CBN_SETFOCUS(IDC_COMRID, OnSetfocusComrid)
ON_CBN_KILLFOCUS(IDC_COMRID, OnKillfocusComrid)
ON_BN_CLICKED(IDC_BUTPrint, OnBUTPrint)
ON_BN_CLICKED(IDC_BUTSave, OnBUTSave)
ON_BN_CLICKED(IDC_BUTUndo, OnBUTUndo)
ON_BN_CLICKED(IDC_BUTExit, OnBUTExit)
ON_WM_CTLCOLOR()
ON_EN_CHANGE(IDC_EDTPAY, OnChangeEdtpay)
//}}AFX_MSG_MAP
ON_MESSAGE(DIY_KILLFOCUS,OnCellKillFocus)
ON_MESSAGE(DIY_SETFOCUS,OnCellSetFocus)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDSellBack message handlers
void CDSellBack::OnOK()
{
}
BOOL CDSellBack::OnInitDialog()
{
CDialog::OnInitDialog();
bool isInit;
rst.Open("SELECT * from 客户信息表",adCmdText);
isInit=this->m_EdtCliect.Initialize(this->GetParent());
this->m_EdtCliect.StartUpAssciation=true;
this->m_EdtCliect.SetRecordset(rst);
this->m_EdtCliect.SetSelectField("名称");
rst.Open("SELECT * from 员工信息表",adCmdText);
isInit=this->m_EdtDealMan.Initialize(this->GetParent());
this->m_EdtDealMan.StartUpAssciation=true;
this->m_EdtDealMan.SetRecordset(rst);
this->m_EdtDealMan.SetSelectField("名称");
CString Fields[]={"商品名称","规格","产地","计量单位","退货数量","单价","合计"};
int ColWidth[]={140,70,140,70,70,70,70};
for(int m=0;m<7;m++)
{
m_Grid.InsertColumn(m,Fields[m]);
m_Grid.SetColumnWidth(m,ColWidth[m]);
}
m_Grid.m_Edit.Initialize(this->GetParent());
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDSellBack::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC MemDC;
CBitmap * pbit,bit;
CRect rect;
bit.LoadBitmap(IDB_BITMAP5);
MemDC.CreateCompatibleDC(this->GetDC());
pbit=MemDC.SelectObject(&bit);
this->GetClientRect(&rect);
dc.BitBlt(0,0,rect.Width(),rect.Height(),&MemDC,0,0,SRCCOPY);
MemDC.DeleteDC();
::DeleteObject(&bit);
::DeleteObject(pbit);
// Do not call CDialog::OnPaint() for painting messages
}
void CDSellBack::OnBUTCleck()
{
CTime time;
CString cTime,NewID;
this->Enabled(true);
this->m_EdtCliect.SetFocus();
NewID=ado.AutoNumber("退货信息表","票号","XT",3);
this->m_StaID.SetWindowText(NewID);
time=time.GetCurrentTime();
cTime=CTimeToCString(time);
this->m_StaDate.SetWindowText(cTime);
this->clear();
}
void CDSellBack::Enabled(bool bEnabled)
{
m_EdtCliect.EnableWindow(bEnabled);
m_EdtDealMan.EnableWindow(bEnabled);
m_ButCleck.EnableWindow(!bEnabled);
m_ButSave.EnableWindow(bEnabled);
m_ButUndo.EnableWindow(bEnabled);
m_ButExit.EnableWindow(!bEnabled);
m_ComRID.EnableWindow(bEnabled);
m_EdtPay.EnableWindow(bEnabled);
}
void CDSellBack::clear()
{
this->m_ComRID.SetWindowText("");
this->m_StaBigSum.SetWindowText("零元");
this->m_StaSmallSum.SetWindowText("0");
this->m_StaSumNumber.SetWindowText("0");
m_Grid.DeleteAllItems();
}
void CDSellBack::OnSetfocusComrid()
{
CString sCliectID,sCliect,sSQL;
m_EdtCliect.GetWindowText(sCliect);
sCliectID=ado.FieldToOtherField("客户信息表","名称",sCliect,"编号",1);
sSQL.Format("SELECT * FROM 销售信息表 WHERE 客户编号='%s'",sCliectID);
rst.Open(sSQL,adCmdText);
m_ComRID.SetRecordset(rst,"票号");
}
void CDSellBack::OnKillfocusComrid()
{
CString sText,sName,sID,sSQL;
this->m_ComRID.GetWindowText(sText);
sSQL.Format("SELECT * FROM 销售视图 WHERE 票号='%s'",sText);
m_MainSQL=sSQL;
m_Grid.SetCol(0);
m_Grid.SetRow(0);
m_Grid.InsertItem(0,"");
m_Grid.BeginEdit(0,0);
sSQL.Format("SELECT DISTINCT 商品名称,简称 from( %s ) DERIVEDTBL",m_MainSQL);
rst.Open(sSQL,adCmdText);
m_Grid.m_Edit.StartUpAssciation=true;
m_Grid.m_Edit.SetRecordset(rst);
m_Grid.m_Edit.SetSelectField("商品名称");
}
void CDSellBack::OnCellKillFocus()
{
CString sNumber,sPrice,sTotal;
float fTotal;
if(m_Grid.GetCol()==5)
{
sNumber=m_Grid.GetItemText(m_Grid.GetRow(),4);
sPrice=m_Grid.GetItemText(m_Grid.GetRow(),5);
fTotal=atof(sNumber)*atof(sPrice);
sTotal.Format("%f",fTotal);
m_Grid.SetItemText(m_Grid.GetRow(),6,sTotal);
int nRecordCount,nSumNumber=0;
float fSumTotal=0.00;
nRecordCount=m_Grid.GetItemCount();
for(int m=0;m<nRecordCount;m++)
{
sNumber=m_Grid.GetItemText(m,4);
sPrice=m_Grid.GetItemText(m,5);
fTotal=atof(sNumber)*atof(sPrice);
nSumNumber=nSumNumber+atoi(sNumber);
fSumTotal=fSumTotal+fTotal;
}
sNumber.Format("%d",nSumNumber);
sTotal.Format("%f",fSumTotal);
this->m_StaSumNumber.SetWindowText(sNumber);
this->m_StaSmallSum.SetWindowText(sTotal);
CString BigTotal;
BigTotal=MoneyToChineseCode(sTotal);
this->m_StaBigSum.SetWindowText(BigTotal);
this->m_StaNotPay.SetWindowText(sTotal);
}
if(m_Grid.GetCol()==6)
m_Grid.m_Edit.NumberOnly(false);
}
void CDSellBack::OnCellSetFocus()
{
CString sSQL,sName,sSpec,sUnit;
if(m_Grid.GetCol()==1)
{
sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
m_Grid.m_Edit.ClearAll();
sSQL.Format("SELECT DISTINCT 商品名称,规格 FROM (%s) DERIVEDTBL WHERE 商品名称='%s'",m_MainSQL,sName);
rst.Open(sSQL,adCmdText);
m_Grid.m_Edit.SetRecordset(rst);
m_Grid.m_Edit.SetSelectField("规格");
m_Grid.m_Edit.StartUpAssciation=false;
m_Grid.m_Edit.AutoPosition();
}
if(m_Grid.GetCol()==2)
{
m_Grid.m_Edit.ClearAll();
sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
sSpec=m_Grid.GetItemText(m_Grid.GetRow(),1);
sSQL.Format("SELECT DISTINCT 名称,产地 FROM 商品信息表 WHERE 名称='%s' and 规格='%s'",sName,sSpec);
rst.Close();
rst.Open(sSQL,adCmdText);
m_Grid.m_Edit.SetRecordset(rst);
m_Grid.m_Edit.SetSelectField("产地");
m_Grid.m_Edit.StartUpAssciation=false;
m_Grid.m_Edit.AutoPosition();
}
if(m_Grid.GetCol()==3)
{
m_Grid.m_Edit.ClearAll();
sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
sSpec=m_Grid.GetItemText(m_Grid.GetRow(),1);
sUnit=m_Grid.GetItemText(m_Grid.GetRow(),2);
sSQL.Format("SELECT DISTINCT 名称,计量单位 FROM 商品信息表 WHERE 名称='%s' and 规格='%s'and 产地='%s'",sName,sSpec,sUnit);
rst.Close();
rst.Open(sSQL,adCmdText);
m_Grid.m_Edit.SetRecordset(rst);
m_Grid.m_Edit.SetSelectField("计量单位");
m_Grid.m_Edit.StartUpAssciation=false;
m_Grid.m_Edit.AutoPosition();
m_Grid.m_Edit.PopHide=true;
m_Grid.m_Edit.EnterNumber=0;
}
if(m_Grid.GetCol()==4)
{
m_Grid.m_Edit.EnterNumber=0;
m_Grid.m_Edit.PopHide=false;
m_Grid.m_Edit.NumberOnly(true);
}
if(m_Grid.GetCol()==5)
{
sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
sSpec=m_Grid.GetItemText(m_Grid.GetRow(),1);
sUnit=m_Grid.GetItemText(m_Grid.GetRow(),2);
sSQL.Format("SELECT DISTINCT 商品名称,数量 FROM (%s )DERIVEDTBL WHERE 商品名称='%s' and 规格='%s'and 产地='%s'",m_MainSQL,sName,sSpec,sUnit);
rst.MoveFirst();
rst.Open(sSQL,adCmdText);
CString nNum=m_Grid.GetItemText(m_Grid.GetRow(),4);
CString nNum2=rst.GetFieldValue("数量");
if(atoi(nNum)>atoi(nNum2))
m_Grid.SetItemText(m_Grid.GetRow(),4,nNum2);
m_Grid.m_Edit.ClearAll();
sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
sSpec=m_Grid.GetItemText(m_Grid.GetRow(),1);
sUnit=m_Grid.GetItemText(m_Grid.GetRow(),2);
sSQL.Format("SELECT DISTINCT 名称,销售价格 as 单价 FROM 商品信息表 WHERE 名称='%s' and 规格='%s'and 产地='%s'",sName,sSpec,sUnit);
rst.Close();
rst.Open(sSQL,adCmdText);
m_Grid.m_Edit.SetRecordset(rst);
m_Grid.m_Edit.SetSelectField("单价");
m_Grid.m_Edit.StartUpAssciation=false;
m_Grid.m_Edit.AutoPosition();
}
if(m_Grid.GetCol()==6)
{
m_Grid.m_Edit.EnterNumber=0;
m_Grid.m_Edit.ClearAll();
sSQL.Format("SELECT DISTINCT 商品名称,简称 from( %s ) DERIVEDTBL",m_MainSQL);
rst.Open(sSQL,adCmdText);
m_Grid.m_Edit.StartUpAssciation=true;
m_Grid.m_Edit.SetRecordset(rst);
m_Grid.m_Edit.SetSelectField("商品名称");
m_Grid.m_Edit.AutoPosition();
}
}
void CDSellBack::OnBUTPrint()
{
CString sName,sDate,sCliect,sSumMoney,sBigMoney,sSumNumber,sID;
RxRecordset brst;
brst.Open("系统设置表");
sName=brst.GetFieldValue("公司名称");
sName=sName+"销售退货发票";
this->m_StaDate.GetWindowText(sDate);
this->m_EdtCliect.GetWindowText(sCliect);
this->m_StaSmallSum.GetWindowText(sSumMoney);
this->m_StaBigSum.GetWindowText(sBigMoney);
this->m_StaSumNumber.GetWindowText(sSumNumber);
this->m_StaID.GetWindowText(sID);
m_ps.MainCaptionFontSize=400;
m_ps.DeckCaptionFontSize=180;
m_ps.DeckCaptionNumber=3;
m_ps.DeckCaptions[0]="退货编号:"+sID;
m_ps.DeckCaptions[1]="退货日期:"+sDate;
m_ps.DeckCaptions[2]="客户:"+sCliect;
m_ps.MainCaption=sName;
m_ps.Grid=&m_Grid;
m_ps.TotalNumber=3;
m_ps.Totals[0]="合计金额(小写):"+sSumMoney;
m_ps.Totals[1]="合计数量:"+sSumNumber;
m_ps.Totals[2]="合计金额(大写):"+sBigMoney;
theApp.Print();
}
void CDSellBack::OnBUTSave()
{
if(MessageBox("确定要保存此销售退货单吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
return;
CString sSQL,sPay,sNotPay,sGiveChange,sWare,sWareID,sStoreNUM,sSpec,sPrice,sNumber,sAddr,sCID,sDate,sCliectName,sCliectID,sDeal,sStyle,sRID,sSumMoney,sSumNumber,OPID;
this->m_StaID.GetWindowText(sCID);
sCID.TrimLeft();
sCID.TrimRight();
this->m_EdtPay.GetWindowText(sPay);
if(sPay.IsEmpty())
{
MessageBox("还没有结款!","系统提示",MB_OK|MB_ICONSTOP);
this->m_EdtPay.SetFocus();
return;
}
this->m_StaNotPay.GetWindowText(sNotPay);
this->m_StaGiveChange.GetWindowText(sGiveChange);
this->m_StaDate.GetWindowText(sDate);
this->m_EdtCliect.GetWindowText(sCliectName);
sCliectID=ado.FieldToOtherField("客户信息表","名称",sCliectName,"编号",1);
this->m_EdtDealMan.GetWindowText(sDeal);
this->m_ComRID.GetWindowText(sRID);
this->m_StaSmallSum.GetWindowText(sSumMoney);
this->m_StaSumNumber.GetWindowText(sSumNumber);
OPID=ado.FieldToOtherField("操作员信息表","名称",OP,"编号",1);
//插入退货信息表
sSQL.Format("INSERT INTO 退货信息表 values('%s','%s','%s',%s,%s,%s,'%s',%s,%s,%s)",sCID,sDate,sCliectID,sSumNumber,sSumMoney,OPID,sDeal,sPay,sNotPay,sGiveChange);
rst.Open(sSQL,adCmdText);
//添加退货明细表
for(int i=0;i<m_Grid.GetItemCount();i++)
{
//名称、规格、产地三个字段才能指定唯一的商品
sWare=this->m_Grid.GetItemText(i,0);
sSpec=this->m_Grid.GetItemText(i,1);
sAddr=this->m_Grid.GetItemText(i,2);
sPrice=this->m_Grid.GetItemText(i,5);
sNumber=this->m_Grid.GetItemText(i,4);
if(sWare.IsEmpty())
break;
sSQL.Format("SELECT * FROM 商品信息表 WHERE 名称='%s' AND 规格='%s' AND 产地='%s'",sWare,sSpec,sAddr);
rst.Open(sSQL,adCmdText);
rst.MoveFirst();
sWareID=rst.GetFieldValue("编号");
sSQL.Format("INSERT INTO 退货明细表 VALUES('%s','%s',%s,%s)",sCID,sWareID,sPrice,sNumber);
rst.Open(sSQL,adCmdText);
//更新库存信息表
sSQL.Format("SELECT * FROM 库存信息表 WHERE 商品编号='%s'",sWareID);
rst.Open(sSQL,adCmdText);
if(rst.GetRecordCount()<1)//没有此种商品的库存信息
sSQL.Format("INSERT INTO 库存信息表 VALUES('%s',%s)",sWareID,sNumber);
else
{
sStoreNUM=rst.GetFieldValue("库存数量");
sSQL.Format("UPDATE 库存信息表 SET 库存数量=%d WHERE 商品编号='%s'",atoi(sStoreNUM)+atoi(sNumber),sWareID);
}
rst.Open(sSQL,adCmdText);
}
this->Enabled(false);
this->m_ButPrint.SetFocus();
}
void CDSellBack::OnBUTUndo()
{
if(MessageBox("确定要撤消操作吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)==1)
{
m_StaID.SetWindowText("XT040403-000001");
m_StaDate.SetWindowText("2004-04-03");
this->Enabled(false);
m_ButCleck.SetFocus();
this->clear();
}
}
void CDSellBack::OnBUTExit()
{
this->OnCancel();
}
HBRUSH CDSellBack::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
if(pWnd==&m_StaBigSum ||pWnd==&m_StaSmallSum||pWnd==&m_StaSumNumber)
pDC->SetTextColor(RGB(255,0,0));
// TODO: Return a different brush if the default is not desired
return hbr;
}
void CDSellBack::OnChangeEdtpay()
{
CString sSmallSum,sPay,sMoney;
int nMoney;
m_EdtPay.GetWindowText(sPay);
this->m_StaSmallSum.GetWindowText(sSmallSum);
if(atoi(sPay)>=atoi(sSmallSum))
{
this->m_StaNotPay.SetWindowText("0");
nMoney=atoi(sPay)-atoi(sSmallSum);
sMoney.Format("%d",nMoney);
this->m_StaGiveChange.SetWindowText(sMoney);
}
else
{
this->m_StaGiveChange.SetWindowText("0");
nMoney=atoi(sSmallSum)-atoi(sPay);
sMoney.Format("%d",nMoney);
this->m_StaNotPay.SetWindowText(sMoney);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -