zoukankan      html  css  js  c++  java
  • 商店管理系统源代码(三)

    #if !defined(AFX_SALESBILL_H__E95A758E_1C5A_442D_91F0_BA25EF86E146__INCLUDED_)
    #define AFX_SALESBILL_H__E95A758E_1C5A_442D_91F0_BA25EF86E146__INCLUDED_
    
    #if _MSC_VER > 1000
    #pragma once
    #endif // _MSC_VER > 1000
    // SalesBill.h : header file
    //
    
    /////////////////////////////////////////////////////////////////////////////
    // CSalesBill dialog
    #include "MyButton.h"
    
    class CSalesBill : public CDialog
    {
    private:
    	CBitmapButton bitmapButton;
    	
    // Construction
    public:
    	CSalesBill(CWnd* pParent = NULL);   // standard constructor
    
    // Dialog Data
    	//{{AFX_DATA(CSalesBill)
    	enum { IDD = IDD_SALESBILLDLG };
    	CMyButton	m_btnCommoditySearch;
    	CMyButton	m_btnCommodityResearch;
    	CListCtrl	m_ctrlListMain;
    	CString	m_strBillDate;
    	CString	m_strBiller;
    	CString	m_strNote;
    	CString	m_strSerchCode;
    	float	m_fltSalePrice;
    	int		m_iNum;
    	float	m_fltAmount;
    	CString	m_strClient;
    	CString	m_strBillCode;
    	//}}AFX_DATA
    
    
    // Overrides
    	// ClassWizard generated virtual function overrides
    	//{{AFX_VIRTUAL(CSalesBill)
    	protected:
    	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
    	//}}AFX_VIRTUAL
    
    // Implementation
    protected:
    
    	// Generated message map functions
    	//{{AFX_MSG(CSalesBill)
    	virtual BOOL OnInitDialog();
    	afx_msg void OnBill();
    	afx_msg void OnSave();
    	afx_msg void OnUpdate();
    	afx_msg void OnDelete();
    	afx_msg void OnAccount();
    	afx_msg void OnExit();
    	afx_msg void OnClientfind();
    	afx_msg void OnCommodityserch();
    	//}}AFX_MSG
    	DECLARE_MESSAGE_MAP()
    };
    
    //{{AFX_INSERT_LOCATION}}
    // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
    
    #endif // !defined(AFX_SALESBILL_H__E95A758E_1C5A_442D_91F0_BA25EF86E146__INCLUDED_)
    
    
    
    
    
    // SalesBill.cpp : implementation file
    //
    
    #include "stdafx.h"
    #include "SalesManagementSystem.h"
    #include "SalesManagementSystemDlg.h"
    #include "SalesBill.h"
    #include "ADOConn.h"
    #include "MyTime.h"
    #include "DiagLog.h"
    #include "DlgAll.h"
    
    #ifdef _DEBUG
    #define new DEBUG_NEW
    #undef THIS_FILE
    static char THIS_FILE[] = __FILE__;
    #endif
    
    /////////////////////////////////////////////////////////////////////////////
    // CSalesBill dialog
    
    
    CSalesBill::CSalesBill(CWnd* pParent /*=NULL*/)
    	: CDialog(CSalesBill::IDD, pParent)
    {
    	//{{AFX_DATA_INIT(CSalesBill)
    	m_strBillDate = _T("");
    	m_strBiller = _T("");
    	m_strNote = _T("");
    	m_strSerchCode = _T("");
    	m_fltSalePrice = 0.0f;
    	m_iNum = 0;
    	m_fltAmount = 0.0f;
    	m_strClient = _T("");
    	m_strBillCode = _T("");
    	//}}AFX_DATA_INIT
    }
    
    
    void CSalesBill::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CSalesBill)
    	DDX_Control(pDX, IDC_COMMODITYSERCH, m_btnCommoditySearch);
    	DDX_Control(pDX, IDC_LISTCOMMODITY, m_ctrlListMain);
    	DDX_Text(pDX, IDC_BILLDATE, m_strBillDate);
    	DDX_Text(pDX, IDC_BILLER, m_strBiller);
    	DDX_Text(pDX, IDC_NOTE, m_strNote);
    	DDX_Text(pDX, IDC_SERCHCODE, m_strSerchCode);
    	DDX_Text(pDX, IDC_SALEPRICE, m_fltSalePrice);
    	DDX_Text(pDX, IDC_NUM, m_iNum);
    	DDX_Text(pDX, IDC_AMOUNT, m_fltAmount);
    	DDX_Text(pDX, IDC_CLIENT, m_strClient);
    	DDX_Text(pDX, IDC_BILLCODE, m_strBillCode);
    	//}}AFX_DATA_MAP
    }
    
    
    BEGIN_MESSAGE_MAP(CSalesBill, CDialog)
    	//{{AFX_MSG_MAP(CSalesBill)
    	ON_BN_CLICKED(IDC_BILL, OnBill)
    	ON_BN_CLICKED(IDC_SAVE, OnSave)
    	ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
    	ON_BN_CLICKED(IDC_DELETE, OnDelete)
    	ON_BN_CLICKED(IDC_ACCOUNT, OnAccount)
    	ON_BN_CLICKED(IDC_CLIENTFIND, OnClientfind)
    	ON_BN_CLICKED(IDC_COMMODITYSERCH, OnCommodityserch)
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CSalesBill message handlers
    
    BOOL CSalesBill::OnInitDialog() 
    {
    	CDialog::OnInitDialog();
    	
    	// TODO: Add extra initialization here
    	m_btnCommoditySearch.SetXIcon(IDI_ICONSERCH);
    	//CBitmapButton bitmapButton;
    	//bitmapButton.LoadBitmaps(IDB_BITMAP1, IDB_BITMAP1);
    	bitmapButton.AutoLoad(IDC_BUTTON2, this);
    	bitmapButton.LoadBitmaps(IDI_ICONSERCH, IDB_BITMAP3);
    	//bitmapButton.SubclassDlgItem(IDC_COMMODITYSERCH, this);
    	bitmapButton.SizeToContent();
    	m_ctrlListMain.InsertColumn(0, "条形码", LVCFMT_CENTER, 100);
    	m_ctrlListMain.InsertColumn(1, "名称", LVCFMT_CENTER, 100);
    	m_ctrlListMain.InsertColumn(2, "标准", LVCFMT_CENTER, 100);
    	m_ctrlListMain.InsertColumn(3, "单位", LVCFMT_CENTER, 50);
    	m_ctrlListMain.InsertColumn(4, "价格", LVCFMT_CENTER, 50);
    	m_ctrlListMain.InsertColumn(5, "库存", LVCFMT_CENTER, 50);
    	m_ctrlListMain.InsertColumn(6, "数量", LVCFMT_CENTER, 50);
    	m_ctrlListMain.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
    	
    	return TRUE;  
    	// return TRUE unless you set the focus to a control
    	// EXCEPTION: OCX Property Pages should return FALSE
    }
    
    void CSalesBill::OnBill() 
    {
    	// TODO: Add your control notification handler code here
    	UpdateData(TRUE);
    	CMyTime myTime;
    
    	m_strBillCode = myTime.GetSimpleString();
    	m_strBillDate = myTime.GetDateString(FALSE);
    	m_strClient = "";
    	m_strNote = "";
    	m_fltSalePrice = 0;
    	m_iNum = 0;
    	m_fltAmount = 0;
    	UpdateData(FALSE);
    }
    
    void CSalesBill::OnSave() 
    {
    	// TODO: Add your control notification handler code here
    	UpdateData(TRUE);
    	POSITION pos;
    	int index;
    	CString strNum, strPrice;
    	
    	strNum.Format(_T("%d"), m_iNum);
    	strPrice.Format(_T("%f"), m_fltSalePrice);
    	pos = m_ctrlListMain.GetFirstSelectedItemPosition();
    	index = m_ctrlListMain.GetNextSelectedItem(pos);
    	m_fltAmount = m_fltAmount - atof(m_ctrlListMain.GetItemText(index, 4)) * atoi(m_ctrlListMain.GetItemText(index, 6));
    	m_ctrlListMain.SetItemText(index, 6, strNum);
    	m_ctrlListMain.SetItemText(index, 4, strPrice);
    	m_fltAmount = m_fltAmount + atof(m_ctrlListMain.GetItemText(index, 4)) * atoi(m_ctrlListMain.GetItemText(index, 6));
    	UpdateData(FALSE);
    }
    
    void CSalesBill::OnUpdate() 
    {
    	// TODO: Add your control notification handler code here
    	UpdateData(TRUE);
    	CString strSQL, strTemp;
    	CADOConn adoSaleBill, adoSaleCommodity, adoStoreInfo, adoIntegral;
    
    	strSQL = "INSERT INTO SaleBill VALUES ('";
    	strSQL = strSQL + m_strBillCode + "', '";
    	strSQL = strSQL + m_strBillDate + "', '";
    	strSQL = strSQL + m_strBiller + "', '";
    	strSQL = strSQL + m_strClient + "', '";
    	strSQL = strSQL + m_strNote + "')";
    	adoSaleBill.ExecuteSQL(strSQL);
    
    	for(int i = 0; i < m_ctrlListMain.GetItemCount(); i++)
    	{
    		strSQL = "INSERT INTO SaleCommodity VALUES ('";
    		strSQL = strSQL + m_strBillCode + "', '";
    		strSQL = strSQL + m_ctrlListMain.GetItemText(i, 0) + "', '";
    		strSQL = strSQL + m_ctrlListMain.GetItemText(i, 4) + "', '";
    		strSQL = strSQL + m_ctrlListMain.GetItemText(i, 6) + "')";
    		adoSaleCommodity.ExecuteSQL(strSQL);
    
    		int num = atoi(m_ctrlListMain.GetItemText(i, 5)) - atoi(m_ctrlListMain.GetItemText(i, 6));
    		strSQL = "UPDATE StoreInfo SET num = '";
    		strTemp.Format(_T("%d"), num);
    		strSQL = strSQL + strTemp + "' WHERE barcode = '";
    		strSQL = strSQL + m_ctrlListMain.GetItemText(i, 0) + "'";
    		adoStoreInfo.ExecuteSQL(strSQL);
    	}
    
    	strSQL = "SELECT * FROM Integral WHERE cardcode = '";
    	strSQL = strSQL + m_strClient + "'";
    	adoIntegral.Open(strSQL);
    	if (!adoIntegral.adoEOF())
    	{
    		strSQL = "UPDATE Integral SET totalintegral = '";
    		strTemp.Format(_T("%0.2f"), m_fltAmount + atoi(adoIntegral.GetItemString(1)));
    		strSQL = strSQL + strTemp + "', remainderintegral = '";
    		strTemp.Format(_T("%0.2f"), m_fltAmount + atoi(adoIntegral.GetItemString(3)));
    		strSQL = strSQL + strTemp + "' WHERE cardcode = '";
    		strSQL = strSQL + m_strClient + "'";
    		adoIntegral.ExecuteSQL(strSQL);
    	}
    	else
    	{
    		strSQL = "INSERT INTO Integral VALUES ('";
    		strSQL = strSQL + m_strClient + "', '";
    		strTemp.Format(_T("%d"), m_fltAmount);
    		strSQL = strSQL + strTemp + "', '0', '";
    		strSQL = strSQL + strTemp + "')";
    		adoIntegral.ExecuteSQL(strSQL);
    	}
    	
    }
    
    void CSalesBill::OnDelete() 
    {
    	// TODO: Add your control notification handler code here
    	POSITION pos;
    	int index;
    	CADOConn adoSaleBill;
    	CString strSQL;
    	
    	pos = m_ctrlListMain.GetFirstSelectedItemPosition();
    	index = m_ctrlListMain.GetNextSelectedItem(pos);
    	strSQL = "DELETE * FROM SaleBill WHERE SaleBill.salecode ='";
    	strSQL = strSQL + m_ctrlListMain.GetItemText(index, 0) + "'";
     	adoSaleBill.ExecuteSQL(strSQL);
    	m_fltAmount = m_fltAmount - atof(m_ctrlListMain.GetItemText(index, 4)) * atoi(m_ctrlListMain.GetItemText(index, 6));
    	m_ctrlListMain.DeleteItem(index);
    }
    
    void CSalesBill::OnAccount() 
    {
    	// TODO: Add your control notification handler code here
    	m_strBillCode = "";
    	m_strBillDate = "";
    	m_strClient = "";
    	m_strNote = "";
    	m_fltSalePrice = 0;
    	m_iNum = 0;
    	m_ctrlListMain.DeleteAllItems();
    	UpdateData(FALSE);
    }
    
    void CSalesBill::OnClientfind() 
    {
    	// TODO: Add your control notification handler code here
    	CADOConn adoFind;
    	CDlgAll dlgAll;
    	dlgAll.strTitle = "客户信息";
    	dlgAll.strSQL = "SELECT * FROM ClientInfo";
    	dlgAll.intKey = 0;
    
    	if (dlgAll.DoModal() == IDOK)
    	{
    		m_strClient = dlgAll.strKey;
    		UpdateData(FALSE);
    	}
    }
    
    void CSalesBill::OnCommodityserch() 
    {
    	// TODO: Add your control notification handler code here
    	UpdateData(TRUE);
    	CADOConn adoFind;
    	CDlgAll dlgAll;
    	CString strSQL;
    	
    	strSQL = "SELECT CommodityInfo.barcode, CommodityInfo.name, CommodityInfo.standard, ";
    	strSQL = strSQL + "CommodityInfo.unit, StoreInfo.saleprice, StoreInfo.num FROM CommodityInfo INNER JOIN StoreInfo ON ";
    	strSQL = strSQL + "CommodityInfo.barcode = StoreInfo.barcode WHERE CommodityInfo.barcode = '";
    	strSQL = strSQL + m_strSerchCode + "' OR CommodityInfo.commoditycode = '";
    	strSQL = strSQL + m_strSerchCode + "' OR CommodityInfo.spellcode = '";
    	strSQL = strSQL + m_strSerchCode + "'";
    	dlgAll.strTitle = "商品基本信息";
    	dlgAll.strSQL = strSQL;
    	dlgAll.intKey = 0;
    
    	if (dlgAll.DoModal() == IDOK)
    	{
    		strSQL = "SELECT CommodityInfo.barcode, CommodityInfo.name, CommodityInfo.standard, ";
    		strSQL = strSQL + "CommodityInfo.unit, StoreInfo.saleprice, StoreInfo.num FROM CommodityInfo INNER JOIN StoreInfo ON ";
    		strSQL = strSQL + "CommodityInfo.barcode = StoreInfo.barcode WHERE CommodityInfo.barcode = '";
    		strSQL = strSQL + dlgAll.strKey + "'";
    		adoFind.Open(strSQL);
    		//adoFind.InitList(&m_ctrlListMain);
    		adoFind.FillList(&m_ctrlListMain);
    		m_ctrlListMain.SetItemText(0, 6, "1");
    		m_fltSalePrice = atof(m_ctrlListMain.GetItemText(0, 4));
    		m_iNum = 1;
    		m_fltAmount = m_fltAmount + m_iNum * m_fltSalePrice;
    		UpdateData(FALSE);
    	}
    }
    


  • 相关阅读:
    算法的定义
    用标准的CSS定义你的表格样式
    Mysql存储过程中临时表的建立及游标遍历
    Ubuntu10.0下编译qt版webkit
    指针函数的一个范例,在单片机上运用它能让您的程序结构更明朗清晰,层次感强
    你若不自己爬上来,我就把你打死在水中——分享三个跟管理有关的小故事
    Windows 上使用 Github 手记
    IIS应用程序池由服务器引起常见错误号的原因分析及解决方法
    如何实施好基于MOSS的企业搜索项目(上)
    如何做好项目经理
  • 原文地址:https://www.cnblogs.com/jiangu66/p/3017484.html
Copyright © 2011-2022 走看看