📄 dreserve.cpp
字号:
// DReserve.cpp : implementation file
//
#include "stdafx.h"
#include "商品销售管理系统.h"
#include "DReserve.h"
#include "externDllHeader.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "MyDoc.h"
#include "MainPrint.h" // main SDI frame window
#include "MyView.h"
/////////////////////////////////////////////////////////////////////////////
// CDReserve dialog
extern CMyApp theApp;
CDReserve::CDReserve(CWnd* pParent /*=NULL*/)
: CDialog(CDReserve::IDD, pParent)
{
//{{AFX_DATA_INIT(CDReserve)
//}}AFX_DATA_INIT
}
void CDReserve::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDReserve)
DDX_Control(pDX, IDC_BUTExt, m_ButExit);
DDX_Control(pDX, IDC_STABigSum, m_StaBigSum);
DDX_Control(pDX, IDC_STASumNumber, m_StaSumNumber);
DDX_Control(pDX, IDC_STASmallSum, m_StaSmallSum);
DDX_Control(pDX, IDC_BUTCleck, m_ButCleck);
DDX_Control(pDX, IDC_List, m_Grid);
DDX_Control(pDX, IDC_EDTCLIECT, m_EdtCliect);
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_STADate, m_StaDate);
DDX_Control(pDX, IDC_STAID, m_StaID);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDReserve, CDialog)
//{{AFX_MSG_MAP(CDReserve)
ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTCleck, OnBUTCleck)
ON_WM_CTLCOLOR()
ON_BN_CLICKED(IDC_BUTSave, OnBUTSave)
ON_BN_CLICKED(IDC_BUTPrint, OnBUTPrint)
ON_BN_CLICKED(IDC_BUTUndo, OnBUTUndo)
ON_BN_CLICKED(IDC_BUTExt, OnBUTExt)
//}}AFX_MSG_MAP
ON_MESSAGE(DIY_KILLFOCUS,OnCellKillFocus)
ON_MESSAGE(DIY_SETFOCUS,OnCellSetFocus)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDReserve message handlers
void CDReserve::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CDReserve::OnButton1()
{
}
void CDReserve::OnPaint()
{
CPaintDC dc(this); // device context for painting
CDC MemDC;
CBitmap * pbit,bit;
CRect rect;
bit.LoadBitmap(IDB_BITMAP2);
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);
}
void CDReserve::OnBUTCleck()
{
CTime time;
CString cTime,NewID;
m_EdtCliect.EnableWindow(true);
m_ButCleck.EnableWindow(false);
m_ButSave.EnableWindow(true);
m_ButUndo.EnableWindow(true);
m_ButExit.EnableWindow(false);
this->m_EdtCliect.SetFocus();
NewID=ado.AutoNumber("订货信息表","票号","DH",3);
this->m_StaID.SetWindowText(NewID);
time=time.GetCurrentTime();
cTime=CTimeToCString(time);
this->m_StaDate.SetWindowText(cTime);
this->clear();
}
BOOL CDReserve::OnInitDialog()
{
CDialog::OnInitDialog();
rst.Open("SELECT * from 客户信息表",adCmdText);
this->m_EdtCliect.Initialize(this->GetParent());
this->m_EdtCliect.StartUpAssciation=true;
this->m_EdtCliect.SetRecordset(rst);
this->m_EdtCliect.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]);
}
if(m_Grid.m_Edit.Initialize(this->GetParent())==false)
return false;
return TRUE;
}
BOOL CDReserve::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYDOWN&& pMsg->wParam==VK_ESCAPE)
pMsg->wParam=VK_CONTROL;
if(pMsg->hwnd==this->m_EdtCliect.GetSafeHwnd()&& pMsg->message==WM_KEYDOWN && pMsg->wParam==9)
{
m_Grid.SetCol(0);
m_Grid.SetRow(0);
m_Grid.InsertItem(0,"");
m_Grid.BeginEdit(0,0);
rst.Close();
rst.Open("SELECT DISTINCT 名称,简称 from 商品信息表",adCmdText);
m_Grid.m_Edit.StartUpAssciation=true;
m_Grid.m_Edit.SetRecordset(rst);
m_Grid.m_Edit.SetSelectField("名称");
pMsg->wParam=VK_CONTROL ;
}
return CDialog::PreTranslateMessage(pMsg);
}
void CDReserve::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);
}
if(m_Grid.GetCol()==6)
m_Grid.m_Edit.NumberOnly(false);
}
void CDReserve::OnCellSetFocus()
{
CString sSQL,sName,sSpec,sUnit;
if(m_Grid.GetCol()==1)
{
m_Grid.m_Edit.NumberOnly(false);
sName=m_Grid.GetItemText(m_Grid.GetRow(),0);
m_Grid.m_Edit.ClearAll();
sSQL.Format("SELECT DISTINCT 名称,规格 from 商品信息表 WHERE 名称='%s'",sName);
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()==2)
{
m_Grid.m_Edit.NumberOnly(false);
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.NumberOnly(false);
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)
{
m_Grid.m_Edit.ClearAll();
m_Grid.m_Edit.NumberOnly(true);
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.NumberOnly(true);
m_Grid.m_Edit.EnterNumber=0;
m_Grid.m_Edit.ClearAll();
rst.Open("SELECT DISTINCT 名称,简称 from 商品信息表",adCmdText);
m_Grid.m_Edit.StartUpAssciation=true;
m_Grid.m_Edit.SetRecordset(rst);
m_Grid.m_Edit.SetSelectField("名称");
m_Grid.m_Edit.AutoPosition();
}
}
HBRUSH CDReserve::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 CDReserve::OnBUTSave()
{
if(MessageBox("确定要保存此订货单吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)==1)
{
RxRecordset rst;
CString sSQL,sID,sWare,sSpec,sWareID,sAddr,sDate,sCliect,sCliectID,sSumNumber,sSumMoney,OPID,sPrice,sNumber;
this->m_StaID.GetWindowText(sID);
this->m_StaDate.GetWindowText(sDate);
this->m_StaSmallSum.GetWindowText(sSumMoney);
this->m_StaSumNumber.GetWindowText(sSumNumber);
this->m_EdtCliect.GetWindowText(sCliect);
sCliectID=ado.FieldToOtherField("客户信息表","名称",sCliect,"编号",1);
OPID=ado.FieldToOtherField("操作员信息表","名称",OP,"编号",1);
//插入到订货信息表中
sSQL.Format("INSERT INTO 订货信息表 VALUES('%s','%s','%s',%s,%s,%s,%d)",sID,sCliectID,sDate,sSumNumber,sSumMoney,OPID,0);
rst.Open(sSQL,adCmdText);
//插入到订货明细表中
for(int m=0;m<m_Grid.GetItemCount()-1;m++)
{
sPrice=this->m_Grid.GetItemText(m,5);
sNumber=this->m_Grid.GetItemText(m,4);
//取出商品编号
sWare=this->m_Grid.GetItemText(m,0);
sSpec=this->m_Grid.GetItemText(m,1);
sAddr=this->m_Grid.GetItemText(m,2);
sSQL.Format("SELECT * FROM 商品信息表 WHERE 名称='%s' AND 规格='%s'AND 产地='%s'",sWare,sSpec,sAddr);
rst.Open(sSQL,adCmdText);
rst.MoveFirst();
sWareID=rst.GetFieldValue("编号");
rst.Close();
sSQL.Format("INSERT INTO 订货明细表 VALUES('%s','%s',%s,%s)",sID,sWareID,sPrice,sNumber);
rst.Open(sSQL,adCmdText);
}
m_EdtCliect.EnableWindow(false);
m_ButCleck.EnableWindow(true);
m_ButSave.EnableWindow(false);
m_ButUndo.EnableWindow(false);
m_ButExit.EnableWindow(true);
this->m_ButPrint.SetFocus();
}
}
void CDReserve::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.MainCaption=sName;
m_ps.DeckCaptionNumber=3;
m_ps.DeckCaptions[0]="订货编号:"+sID;
m_ps.DeckCaptions[1]="订货日期:"+sDate;
m_ps.DeckCaptions[2]="客户:"+sCliect;
m_ps.Grid=&m_Grid;
m_ps.TotalNumber=3;
m_ps.Totals[1]="合计金额(小写):"+sSumMoney;
m_ps.Totals[0]="合计数量:"+sSumNumber;
m_ps.Totals[2]="合计金额(大写)"+sBigMoney;
theApp.Print();
}
void CDReserve::clear()
{
this->m_StaBigSum.SetWindowText("零元");
this->m_StaSmallSum.SetWindowText("0");
this->m_StaSumNumber.SetWindowText("0");
m_Grid.DeleteAllItems();
}
void CDReserve::OnBUTUndo()
{
if(MessageBox("确定要撤消操作吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)==1)
{
m_StaID.SetWindowText("DH040403-000001");
m_StaDate.SetWindowText("2004-04-03");
m_EdtCliect.EnableWindow(false);
m_ButCleck.EnableWindow(true);
m_ButSave.EnableWindow(false);
m_ButUndo.EnableWindow(false);
m_ButExit.EnableWindow(true);
m_ButCleck.SetFocus();
this->clear();
}
}
void CDReserve::OnBUTExt()
{
this->OnCancel();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -