⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsellware.cpp

📁 用VC+SQL实现的物流管理系统 “RxMediaPlayer” 文件夹中存放《物流综合管理系统》中《媒体播放平台》源程序 “数据库设置”文件夹中存放《物流综合管理系统》辅助工具《数据库设置》源程
💻 CPP
字号:
// DSellWare.cpp : implementation file
//

#include "stdafx.h"
#include "MyProject.h"
#include "DSellWare.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
#include "ExternDllHeader.h"
/////////////////////////////////////////////////////////////////////////////
// CDSellWare dialog


CDSellWare::CDSellWare(CString Caption,CWnd* pParent /*=NULL*/)
	: CDialog(CDSellWare::IDD, pParent)
{
	this->m_sCaption=Caption;
	//{{AFX_DATA_INIT(CDSellWare)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CDSellWare::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDSellWare)
	DDX_Control(pDX, IDC_STATITLE, m_StaTitle);
	DDX_Control(pDX, IDC_STASELLID, m_StaSellID);
	DDX_Control(pDX, IDC_STAOP, m_StaOP);
	DDX_Control(pDX, IDC_STADATE, m_StaDate);
	DDX_Control(pDX, IDC_STASUMMONEY, m_StaSumMoney);
	DDX_Control(pDX, IDC_STASUMNUMBER1, m_StaSumNumber);
	DDX_Control(pDX, IDC_STATEXT, m_StaText);

	DDX_Control(pDX, IDC_LIST1, m_Grid);
	DDX_Control(pDX, IDC_EDTUNIT, m_EdtUnit);
	DDX_Control(pDX, IDC_EDTSPEC, m_EdtSpec);
	DDX_Control(pDX, IDC_EDTPRICE, m_EdtPrice);
	DDX_Control(pDX, IDC_EDTNUMBER, m_EdtNumber);
	DDX_Control(pDX, IDC_EDTNAME, m_EdtName);
	DDX_Control(pDX, IDC_EDTMONEY, m_EdtMoney);
	DDX_Control(pDX, IDC_EDTMAN, m_EdtMan);
	DDX_Control(pDX, IDC_EDTJNAME, m_EdtJName);
	DDX_Control(pDX, IDC_EDTINNERID, m_EdtInnerID);
	DDX_Control(pDX, IDC_EDTCODE, m_EdtCode);
	DDX_Control(pDX, IDC_EDTCLIECT, m_EdtCliect);
	DDX_Control(pDX, IDC_EDTADDR, m_EdtAddr);
	DDX_Control(pDX, IDC_BUTUNDO, m_ButUndo);
	DDX_Control(pDX, IDC_BUTSAVE2, m_ButSave);
	DDX_Control(pDX, IDC_BUTPRINT, m_ButPrint);
	DDX_Control(pDX, IDC_BUTEXIT, m_ButExit);
	DDX_Control(pDX, IDC_BUTENROL2, m_Enrol);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDSellWare, CDialog)
	//{{AFX_MSG_MAP(CDSellWare)
	ON_EN_KILLFOCUS(IDC_EDTCODE, OnKillfocusEdtcode)
	ON_EN_KILLFOCUS(IDC_EDTNUMBER, OnKillfocusEdtnumber)
	ON_BN_CLICKED(IDC_BUTSAVE2, OnButsave)
	ON_BN_CLICKED(IDC_BUTENROL2, OnButenrol)
	ON_BN_CLICKED(IDC_BUTUNDO, OnButundo)
	ON_NOTIFY(LVN_ITEMCHANGED, IDC_LIST1, OnItemchangedList1)
	ON_BN_CLICKED(IDC_BUTEXIT, OnButexit)
	ON_BN_CLICKED(IDC_BUTPRINT, OnButprint)
	ON_NOTIFY(NM_CLICK, IDC_LIST1, OnClickList1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDSellWare message handlers

void CDSellWare::OnOK() 
{
	// TODO: Add extra validation here
	
//	CDialog::OnOK();
}

void CDSellWare::OnCancel() 
{
	// TODO: Add extra cleanup here
	
	CDialog::OnCancel();
}

BOOL CDSellWare::OnInitDialog() 
{	
	CDialog::OnInitDialog();
	this->ShowWindow(SW_SHOWMAXIMIZED);	
	this->SetWindowText(m_sCaption);
	this->m_StaTitle.SetWindowText(m_sCaption);
	this->Invalidate();
	//记录开票时间
	CTime time;
	time=time.GetCurrentTime();
	CString sTime;
	sTime=CTimeToCString(time);
	this->m_StaDate.SetWindowText(sTime);
	this->m_Grid.m_Edit.Initialize(this->GetParent());
	this->m_Grid.m_bReadOnly=true;
	this->Init();


	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDSellWare::OnButenrol() 
{
}

void CDSellWare::Enabled(bool bEnbled)
{
	m_EdtCliect.EnableWindow(bEnbled);
	m_EdtNumber.EnableWindow(bEnbled);	
	m_EdtMan.EnableWindow(bEnbled);
	m_EdtCode.EnableWindow(bEnbled);
	m_EdtInnerID.EnableWindow(bEnbled);	
	m_ButUndo.EnableWindow(bEnbled);
	m_ButSave.EnableWindow(bEnbled);
	m_ButPrint.EnableWindow(!bEnbled);
	m_ButExit.EnableWindow(!bEnbled);
	m_Enrol.EnableWindow(!bEnbled);
}

void CDSellWare::SetGridHeader(CString sHeaderNameList)
{
	int nPost=0,nOldPost=0;
	CString sHeaderName;
	int nColID=0;
	while(nPost!=-1)
	{
		nColID++;
		nOldPost=nPost;
		nPost=sHeaderNameList.Find(",",nOldPost+1);
		if(nPost!=-1)
			if(nOldPost==0)
				sHeaderName=sHeaderNameList.Mid(nOldPost,nPost);
			else
				sHeaderName=sHeaderNameList.Mid(nOldPost+1,nPost-nOldPost-1);
		else
			sHeaderName=sHeaderNameList.Mid(nOldPost+1,sHeaderNameList.GetLength());
		m_Grid.InsertColumn(nColID,sHeaderName);
	}
}

void CDSellWare::SetHeadersWidth(CString sHeadersWidthList)
{
	int nPost=0,nOldPost=0;
	CString sHeaderWidth;
	int nColID=0;
	while(nPost!=-1)
	{
		nOldPost=nPost;
		nPost=sHeadersWidthList.Find(",",nOldPost+1);
		if(nPost!=-1)
			if(nOldPost==0)
				sHeaderWidth=sHeadersWidthList.Mid(nOldPost,nPost);
			else
				sHeaderWidth=sHeadersWidthList.Mid(nOldPost+1,nPost-nOldPost-1);
		else
			sHeaderWidth=sHeadersWidthList.Mid(nOldPost+1,sHeadersWidthList.GetLength());
		m_Grid.SetColumnWidth(nColID,atoi(sHeaderWidth));
		nColID++;
	}	
}

void CDSellWare::OnKillfocusEdtcode() 
{
	CString sCode,sSQL;
	m_EdtCode.GetWindowText(sCode);
	if(sCode.IsEmpty()==true)
		return;
	RxRecordset rst;
	sSQL.Format("SELECT * FROM 商品信息表 WHERE 条形码='%s'",sCode);
	rst.Open(sSQL,adCmdText);
	if(rst.GetRecordCount()<1)
	{
		this->m_EdtCode.SetWindowText("");
		this->m_EdtCode.SetFocus();
		return;
	}
	m_EdtUnit.SetWindowText(rst.GetFieldValue("计量单位"));
	m_EdtSpec.SetWindowText(rst.GetFieldValue("规格"));
	m_EdtPrice.SetWindowText(rst.GetFieldValue("销售价格"));
	CString sNumber;
	m_EdtNumber.GetWindowText(sNumber);
	if(sNumber.IsEmpty())
		m_EdtNumber.SetWindowText("1");
	m_EdtName.SetWindowText(rst.GetFieldValue("名称"));
	m_EdtMoney.SetWindowText(rst.GetFieldValue("销售价格"));
	m_EdtJName.SetWindowText(rst.GetFieldValue("简称"));
	m_EdtAddr.SetWindowText(rst.GetFieldValue("产地"));
	CString sName,sJName,sSpec,sAddr,sUnit,sPrice,sMoney;
	m_EdtCode.GetWindowText(sCode);
	if(sCode.IsEmpty()==true)
	{
		m_EdtCode.SetFocus();
		return;
	}
	CString sMem;
	int nNumber=0,nMem=0;
	float fMem,fPrice,fMoney;
	//是否表格中已存在商品记录
	for(int i=0;i<m_Grid.GetItemCount();i++)
	{
		sMem=m_Grid.GetItemText(i,0);
		if(sMem==sCode)
		{
			nMem=0;
			sNumber.Empty();
			sNumber=m_Grid.GetItemText(i,5);
			nMem=atoi(sNumber);
			m_EdtNumber.GetWindowText(sNumber);
			nNumber=atoi(sNumber);
			nNumber=nMem+nNumber;
			sNumber.Format("%d",nNumber);
			m_Grid.SetItemText(i,5,sNumber);
			//计算合计金额
			sPrice=m_Grid.GetItemText(i,6);
			fPrice=atof(sPrice);
			fMoney=fPrice*nNumber;
			sMoney.Format("%f",fMoney);
			m_Grid.SetItemText(i,7,sMoney);
			this->m_EdtCode.SetWindowText("");
			this->m_EdtCode.SetFocus();
			Total();
			return;
		}
	}
	m_EdtName.GetWindowText(sName);
	m_EdtSpec.GetWindowText(sSpec);
	m_EdtAddr.GetWindowText(sAddr);
	m_EdtUnit.GetWindowText(sUnit);
	m_EdtNumber.GetWindowText(sNumber);
	m_EdtPrice.GetWindowText(sPrice);
	m_EdtMoney.GetWindowText(sMoney);

	m_Grid.InsertItem(m_Grid.GetItemCount(),"");
	m_Grid.SetItemText(m_Grid.GetItemCount()-1,0,sCode);
	m_Grid.SetItemText(m_Grid.GetItemCount()-1,1,sName);
	m_Grid.SetItemText(m_Grid.GetItemCount()-1,2,sSpec);
	m_Grid.SetItemText(m_Grid.GetItemCount()-1,3,sAddr);
	m_Grid.SetItemText(m_Grid.GetItemCount()-1,4,sUnit);
	m_Grid.SetItemText(m_Grid.GetItemCount()-1,5,sNumber);
	m_Grid.SetItemText(m_Grid.GetItemCount()-1,6,sPrice);
	m_Grid.SetItemText(m_Grid.GetItemCount()-1,7,sMoney);
	Total();
	this->m_EdtCode.SetWindowText("");
	this->m_EdtCode.SetFocus();
}

void CDSellWare::OnKillfocusEdtnumber() 
{
	CString sID,sName,sAddr,sUnit,sSpec,sSQL,sNumber;
	m_EdtName.GetWindowText(sName);
	m_EdtAddr.GetWindowText(sAddr);
	m_EdtUnit.GetWindowText(sUnit);
	m_EdtSpec.GetWindowText(sSpec);
	sSQL.Format("SELECT* FROM 商品信息表 WHERE 名称='%s'AND 规格='%s' AND 产地='%s' AND 计量单位='%s'",sName,sSpec,sAddr,sUnit);
	RxRecordset rst;
	rst.Open(sSQL,adCmdText);
	if(rst.GetRecordCount()<1)
		return;
	sID=rst.GetFieldValue("条形码");
	LVFINDINFO findInfo;
	findInfo.flags =LVFI_STRING;
	findInfo.psz=sID.GetBuffer(sID.GetLength());
	
	int nItem=this->m_Grid.FindItem(&findInfo);
	this->m_EdtNumber.GetWindowText(sNumber);
	this->m_Grid.SetItemText(nItem,5,sNumber);
	CString sPrice,sTotal;
	sPrice=this->m_Grid.GetItemText(nItem,6);
	sTotal.Format("%d",atoi(sPrice)*atoi(sNumber));

	this->m_Grid.SetItemText(nItem,7,sTotal);
	Total();
	this->m_EdtNumber.SetWindowText("1");
	this->m_EdtCode.SetFocus();

}

void CDSellWare::OnButsave() 
{
	
}


void CDSellWare::Total()
{
	CString sNumber,sMoney;
	int nNumber=0;
	float fMoney=0;
	for(int i=0;i<m_Grid.GetItemCount();i++)
	{
		sNumber=m_Grid.GetItemText(i,5);
		nNumber=nNumber+atoi(sNumber);

		//合计金额
		sMoney=m_Grid.GetItemText(i,7);
		fMoney=fMoney+atof(sMoney);
	}
	sNumber.Format("%d",nNumber);
	sMoney.Format("%f",fMoney);
	this->m_StaSumMoney.SetWindowText(sMoney);
	this->m_StaSumNumber.SetWindowText(sNumber);
}

void CDSellWare::OnItemchangedList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
	NM_LISTVIEW* pNMListView = (NM_LISTVIEW*)pNMHDR;

	*pResult = 0;
}

void CDSellWare::OnButundo()
{
	if(MessageBox("确定要撤消操作吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
		return;
	this->Enabled(false);
	this->Format();	
}

void CDSellWare::OnButexit()
{
	this->OnCancel();
}

void CDSellWare::OnButprint()
{
	m_ps.MainCaptionFontSize=400;
	m_ps.DeckCaptionFontSize=180;
	m_ps.MainCaption=m_sCaption+"单据";

	m_ps.DeckCaptionNumber=5;
	CString sMem;
	this->m_StaSellID.GetWindowText(sMem);
	m_ps.DeckCaptions[0]="票号:"+sMem;
	this->m_StaDate.GetWindowText(sMem);
	m_ps.DeckCaptions[1]="开票日期:"+sMem;
	this->m_EdtInnerID.GetWindowText(sMem);
	CString sText;
	this->m_StaText.GetWindowText(sText);
	m_ps.DeckCaptions[2]=sText+sMem;

	this->m_EdtCliect.GetWindowText(sMem);
	m_ps.DeckCaptions[3]="客户:"+sMem;
	this->m_EdtMan.GetWindowText(sMem);
	m_ps.DeckCaptions[4]="经手人:"+sMem;

	m_ps.TotalNumber=4;
	this->m_StaSumNumber.GetWindowText(sMem);
	m_ps.Totals[0]="合计数量:"+sMem;
	this->m_StaSumMoney.GetWindowText(sMem);
	m_ps.Totals[1]="合计金额:"+sMem;
	sMem=MoneyToChineseCode(sMem);
	m_ps.Totals[2]="大    写:"+sMem;
	m_ps.Totals[3]="操 作 员:"+OP;

	m_ps.Grid=&m_Grid;
	CMyApp* theApp;
	theApp=(CMyApp*)::AfxGetApp();
	theApp->Print();
}

void CDSellWare::Format()
{
	m_EdtCliect.IsShowing=true;
	m_EdtCliect.SetWindowText("");
	m_EdtCliect.IsShowing=false;

	m_EdtMan.IsShowing=true;
	m_EdtMan.SetWindowText("");
	m_EdtMan.IsShowing=false;

	m_EdtInnerID.IsShowing=true;
	m_EdtInnerID.SetWindowText("");
	m_EdtInnerID.IsShowing=false;

	m_EdtUnit.SetWindowText("");
	m_EdtSpec.SetWindowText("");
	m_EdtNumber.SetWindowText("");
	m_EdtPrice.SetWindowText("");
	m_EdtName.SetWindowText("");
	m_EdtMoney.SetWindowText("");
	m_EdtJName.SetWindowText("");
	m_EdtAddr.SetWindowText("");
	m_Grid.DeleteAllItems();
}


void CDSellWare::Display()
{
	if(m_Grid.GetSelectionMark()<0)
		return;
	CString sCode,sName,sSpec,sAddr,sUnit,sNumber,sPrice,sMoney;
	sCode=m_Grid.GetItemText(m_Grid.GetSelectionMark(),0);
	sName=m_Grid.GetItemText(m_Grid.GetSelectionMark(),1);
	sSpec=m_Grid.GetItemText(m_Grid.GetSelectionMark(),2);
	sAddr=m_Grid.GetItemText(m_Grid.GetSelectionMark(),3);
	sUnit=m_Grid.GetItemText(m_Grid.GetSelectionMark(),4);
	sNumber=m_Grid.GetItemText(m_Grid.GetSelectionMark(),5);
	sPrice=m_Grid.GetItemText(m_Grid.GetSelectionMark(),6);
	sMoney=m_Grid.GetItemText(m_Grid.GetSelectionMark(),7);
	CString sSQL;
	sSQL.Format("SELECT * FROM 商品信息表 WHERE 条形码='%s'",sCode);
	RxRecordset rst;
	rst.Open(sSQL,adCmdText);
	m_EdtJName.SetWindowText(rst.GetFieldValue("简称"));
	//m_EdtCode.SetWindowText(sCode);
	m_EdtName.SetWindowText(sName);
	m_EdtSpec.SetWindowText(sSpec);
	m_EdtAddr.SetWindowText(sAddr);
	m_EdtUnit.SetWindowText(sUnit);
	m_EdtNumber.SetWindowText(sNumber);
	m_EdtPrice.SetWindowText(sPrice);
	m_EdtMoney.SetWindowText(sMoney);
}

void CDSellWare::OnClickList1(NMHDR* pNMHDR, LRESULT* pResult) 
{
		Display();
	
	*pResult = 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -