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

📄 dlgsell.cpp

📁 小商店管理助手软件
💻 CPP
字号:
// DlgSell.cpp : implementation file
//

#include "stdafx.h"
#include "Project.h"
#include "DlgSell.h"
#include "DlgLogin.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CString GetTime();
/////////////////////////////////////////////////////////////////////////////
// CDlgSell dialog
static int i = 0;
static 	BOOL stocknum;

CDlgSell::CDlgSell(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgSell::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgSell)
	m_SellNumber   = 0;
	m_SellDiscount = 0;
	m_Salesman = _T("");
	stocknum = TRUE;
	bIfAdd =   FALSE;
	m_SellPrice = 0.0f;
	//}}AFX_DATA_INIT
}


void CDlgSell::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgSell)
	//DDX_Control(pDX, IDC_SellAdd,  m_BtnAdd);
	DDX_Control(pDX, IDC_Spin,     m_Spin);
	DDX_Control(pDX, IDC_SELLLIST, m_SellList);
	DDX_Text(pDX, IDC_GoodsID,     m_GoodsID);
	DDX_Text(pDX, IDC_VIPNo,       m_VIPNo);
	DDX_Text(pDX, IDC_SellNumber,  m_SellNumber);
	DDX_Text(pDX, IDC_Discount,    m_SellDiscount);
	DDX_Text(pDX, IDC_Salesman,    m_Salesman);
	DDX_Text(pDX, IDC_Price, m_SellPrice);
	DDV_MinMaxFloat(pDX, m_SellPrice, 0.f, 99999.f);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgSell, CDialog)
	//{{AFX_MSG_MAP(CDlgSell)
	ON_WM_LBUTTONDOWN()
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_OK, OnOk)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgSell message handlers

BOOL CDlgSell::OnInitDialog() 
{
	CDialog::OnInitDialog();
	//初始化列表框
	m_SellList.SetTextColor(RGB (0, 0, 0));
	m_SellList.SetBkColor(RGB(255,255,255));
	m_SellList.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT);	

	m_SellList.InsertColumn(0,_T("货品ID"), LVCFMT_CENTER,70);
	m_SellList.InsertColumn(1,_T("售价"),   LVCFMT_CENTER,55);
	m_SellList.InsertColumn(2,_T("销售量"), LVCFMT_CENTER,65);
	m_SellList.InsertColumn(3,_T("折扣"),   LVCFMT_CENTER,50);
	m_SellList.InsertColumn(4,_T("VIP客户"),LVCFMT_CENTER,65);
	m_SellList.InsertColumn(5,_T("售货员"), LVCFMT_CENTER,60);
	m_SellList.InsertColumn(6,_T("时间"),   LVCFMT_CENTER,90);

	m_Spin.SetRange(0,1000);   //Spin控件设置
	m_Spin.SetPos(1);
	return TRUE;  
}

void CDlgSell::OnOk() 
{
	UpdateData(TRUE);
	m_SellDate = GetTime();         //获取当前时间
  
	CDlgLogin dlgLogin;
	try
	{   //连接数据源
		_bstr_t Conn = "DSN="+_bstr_t(dlgLogin.m_LoginDSN)+";";   
		pConn.CreateInstance(__uuidof(Connection));
		HRESULT hr=pConn->Open(Conn,_bstr_t(""),_bstr_t(""),adModeUnknown);  //
	}
	catch(_com_error& ex)
	{
		AfxMessageBox(ex.Description());
	}	

	_RecordsetPtr pRst,pRst1;   
	CString _sql, _sql1;          //拼写SQL字串
	_sql.Format("insert into TableSell values(\'%s\',\'%s\',\'%d\',\'%f\',\'%f\',\'%s\',\'%s\',\'%s\')",
		m_GoodsID,      "",        m_SellNumber,   m_SellPrice, 
		m_SellDiscount, m_VIPNo,   m_Salesman,     m_SellDate );

	_sql1.Format("SELECT Number FROM TableStorage WHERE GoodsID = \'%s\'",m_GoodsID);
	_bstr_t sql = _sql;           //用于向TableSell插入记录
	_bstr_t sql1 = _sql1;         //用于查询TableStorage表
	try
	{
		pRst1 = pConn->Execute(sql1,NULL, adCmdText);
		if(pRst1->End)
			AfxMessageBox("无此货品");
		else
		{
			_variant_t vNUM = pRst1->Fields->GetItem("Number")->Value; 
			int num = vNUM.iVal;
			if(num < m_SellNumber) //库存量不能小于销售量
			{
				AfxMessageBox("库存量不足!");
			}
			else
			{
				try	
				{
					pRst = pConn->Execute(sql,NULL,adCmdText); //向TableSell插入记录 
			        AddListItem();    //在列表框显示销售信息
				}  
				catch(_com_error& e)	{AfxMessageBox(e.Description()); }
			pRst.Release();
			pRst1.Release();
			pConn.Release();
			}	
		}

	}
	catch(_com_error& e)
	{
		AfxMessageBox(e.Description());
	}

}
//==添加列表项==============================
void CDlgSell::AddListItem()
{
	CString sNumber,sPrice,sDiscount;			
	sNumber.Format("%d",  m_SellNumber);
	sPrice.Format("%8.2f",m_SellPrice);
	sDiscount.Format("%d",m_SellDiscount);
	
	int i = m_SellList.GetItemCount();
	m_SellList.InsertItem(i,   m_GoodsID);         //列表显示
	m_SellList.SetItemText(i,1,sPrice);	
	m_SellList.SetItemText(i,2,sNumber);
	m_SellList.SetItemText(i,3,sDiscount);
	m_SellList.SetItemText(i,4,m_VIPNo);
	m_SellList.SetItemText(i,5,m_Salesman);
	m_SellList.SetItemText(i,6,m_SellDate);
	i++;
	m_GoodsID = m_Salesman = m_VIPNo ="";			 //清空
	m_SellNumber = m_SellDiscount = m_SellPrice =0;           
	UpdateData(false);
}


void CDlgSell::OnLButtonDown(UINT nFlags, CPoint point) 
{
	PostMessage(WM_NCLBUTTONDOWN,HTCAPTION,MAKELPARAM(point.x, point.y));
	CDialog::OnLButtonDown(nFlags, point);
}


void CDlgSell::OnCancel() 
{
	CDialog::OnCancel();
}




⌨️ 快捷键说明

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