商店管理系統源代碼(十)

#if !defined(AFX_DLGINTEGRAL_H__B214685B_09EE_412A_8A55_5A1A425E836B__INCLUDED_)
#define AFX_DLGINTEGRAL_H__B214685B_09EE_412A_8A55_5A1A425E836B__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgIntegral.h : header file
//

/////////////////////////////////////////////////////////////////////////////
// CDlgIntegral dialog

class CDlgIntegral : public CDialog
{
// Construction
public:
	CDlgIntegral(CWnd* pParent = NULL);   // standard constructor
	CString strBarcode;
	
// Dialog Data
	//{{AFX_DATA(CDlgIntegral)
	enum { IDD = IDD_INTEGRAL };
	CListCtrl	m_ctrlListMain;
	CString	m_strCardCode;
	CString	m_strCommodityName;
	CString	m_strCode;
	int		m_iNum;
	//}}AFX_DATA


// Overrides
	// ClassWizard generated virtual function overrides
	//{{AFX_VIRTUAL(CDlgIntegral)
	protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	//}}AFX_VIRTUAL

// Implementation
protected:

	// Generated message map functions
	//{{AFX_MSG(CDlgIntegral)
	virtual BOOL OnInitDialog();
	afx_msg void OnFinduser();
	afx_msg void OnFind();
	afx_msg void OnAdd();
	afx_msg void OnUpdate();
	afx_msg void OnDel();
	//}}AFX_MSG
	DECLARE_MESSAGE_MAP()
};

//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.

#endif // !defined(AFX_DLGINTEGRAL_H__B214685B_09EE_412A_8A55_5A1A425E836B__INCLUDED_)





// DlgIntegral.cpp : implementation file
//

#include "stdafx.h"
#include "SalesManagementSystem.h"
#include "DlgIntegral.h"
#include "DlgAll.h"
#include "ADOConn.h"
#include "MyTime.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgIntegral dialog


CDlgIntegral::CDlgIntegral(CWnd* pParent /*=NULL*/)
	: CDialog(CDlgIntegral::IDD, pParent)
{
	//{{AFX_DATA_INIT(CDlgIntegral)
	m_strCardCode = _T("");
	m_strCommodityName = _T("");
	m_strCode = _T("");
	m_iNum = 0;
	//}}AFX_DATA_INIT
}


void CDlgIntegral::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CDlgIntegral)
	DDX_Control(pDX, IDC_LISTMAIN, m_ctrlListMain);
	DDX_Text(pDX, IDC_CARDCODE, m_strCardCode);
	DDX_Text(pDX, IDC_COMMODTIYNAME, m_strCommodityName);
	DDX_Text(pDX, IDC_CODE, m_strCode);
	DDX_Text(pDX, IDC_NUM, m_iNum);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CDlgIntegral, CDialog)
	//{{AFX_MSG_MAP(CDlgIntegral)
	ON_BN_CLICKED(IDC_FINDUSER, OnFinduser)
	ON_BN_CLICKED(IDC_FIND, OnFind)
	ON_BN_CLICKED(IDC_ADD, OnAdd)
	ON_BN_CLICKED(IDC_UPDATE, OnUpdate)
	ON_BN_CLICKED(IDC_DEL, OnDel)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDlgIntegral message handlers

BOOL CDlgIntegral::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	m_iNum = 1;
	m_ctrlListMain.InsertColumn(0, "卡號", LVCFMT_CENTER, 100);
	m_ctrlListMain.InsertColumn(1, "名字", LVCFMT_CENTER, 50);
	m_ctrlListMain.InsertColumn(2, "總共積分", LVCFMT_CENTER, 100);
	m_ctrlListMain.InsertColumn(3, "已用積分", LVCFMT_CENTER, 100);
	m_ctrlListMain.InsertColumn(4, "剩餘積分", LVCFMT_CENTER, 100);
	m_ctrlListMain.InsertColumn(5, "日期", LVCFMT_CENTER, 100);
	m_ctrlListMain.InsertColumn(6, "條形碼", LVCFMT_CENTER, 50);
	m_ctrlListMain.InsertColumn(7, "名稱", LVCFMT_CENTER, 70);
	m_ctrlListMain.InsertColumn(8, "價格", LVCFMT_CENTER, 50);
	m_ctrlListMain.InsertColumn(9, "數目", LVCFMT_CENTER, 50);
	m_ctrlListMain.SetExtendedStyle(LVS_EX_GRIDLINES | LVS_EX_FULLROWSELECT);
	UpdateData(FALSE);
	
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void CDlgIntegral::OnFinduser() 
{
	// TODO: Add your control notification handler code here
	CDlgAll dlgAll;
	CString strSQL;

	strSQL = "SELECT * FROM ClientInfo";
	dlgAll.strTitle = "客戶基本信息";
	dlgAll.strSQL = strSQL;
	dlgAll.intKey = 0;

	if (dlgAll.DoModal() == IDOK)
	{
		m_strCardCode = dlgAll.strKey;
		UpdateData(FALSE);
	}
}

void CDlgIntegral::OnFind() 
{
	// 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_strCode + "' OR CommodityInfo.commoditycode = '";
	strSQL = strSQL + m_strCode + "' OR CommodityInfo.spellcode = '";
	strSQL = strSQL + m_strCode + "'";
	dlgAll.strTitle = "商品基本信息";
	dlgAll.strSQL = strSQL;
	dlgAll.intKey = 0;

	if (dlgAll.DoModal() == IDOK)
	{
		strSQL = "SELECT CommodityInfo.barcode, CommodityInfo.name FROM CommodityInfo ";
		strSQL = strSQL + "WHERE CommodityInfo.barcode = '";
		strSQL = strSQL + dlgAll.strKey + "'";
		adoFind.Open(strSQL);
		strBarcode = dlgAll.strKey;
		m_strCommodityName = adoFind.GetItemString(1);
		adoFind.ExitConnect();
		UpdateData(FALSE);
	}
}

void CDlgIntegral::OnAdd() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CString strSQL, strTemp;
	CADOConn adoIntegral;
	CMyTime myTime;

	strSQL = "SELECT ClientInfo.cardcode, ClientInfo.username, Integral.totalintegral, Integral.usedintegral, ";
	strSQL = strSQL + "Integral.remainderintegral FROM ClientInfo INNER JOIN Integral ON ";
	strSQL = strSQL + "ClientInfo.cardcode = Integral.cardcode WHERE ClientInfo.cardcode = '";
	strSQL = strSQL + m_strCardCode + "'";
	adoIntegral.Open(strSQL);
	
	if (!adoIntegral.adoEOF())
	{
		m_ctrlListMain.InsertItem(0, adoIntegral.GetItemString(0));
		m_ctrlListMain.SetItemText(0, 1, adoIntegral.GetItemString(1));
		m_ctrlListMain.SetItemText(0, 2, adoIntegral.GetItemString(2));
		m_ctrlListMain.SetItemText(0, 3, adoIntegral.GetItemString(3));
		m_ctrlListMain.SetItemText(0, 4, adoIntegral.GetItemString(4));
		m_ctrlListMain.SetItemText(0, 5, myTime.GetDateString(FALSE));
		m_ctrlListMain.SetItemText(0, 6, strBarcode);
		strSQL = "SELECT CommodityInfo.barcode, CommodityInfo.name, StoreInfo.saleprice ";
		strSQL = strSQL + "FROM CommodityInfo INNER JOIN StoreInfo ON CommodityInfo.barcode = StoreInfo.barcode WHERE CommodityInfo.barcode = '";
		strSQL = strSQL + strBarcode + "'";
		adoIntegral.Open(strSQL);
		m_ctrlListMain.SetItemText(0, 7, adoIntegral.GetItemString(1));
		m_ctrlListMain.SetItemText(0, 8, adoIntegral.GetItemString(2));
		strTemp.Format(_T("%d"), m_iNum);
		m_ctrlListMain.SetItemText(0, 9, strTemp);
		adoIntegral.ExitConnect();
	}
}

void CDlgIntegral::OnUpdate() 
{
	// TODO: Add your control notification handler code here
	UpdateData(TRUE);
	CString strSQL, strTemp;
	CADOConn adoIntegral, adoIntegralCommodity;
	POSITION pos;
	int index;
	
	pos = m_ctrlListMain.GetFirstSelectedItemPosition();
	index = m_ctrlListMain.GetNextSelectedItem(pos);
	
	strSQL = "UPDATE Integral SET usedintegral = '";
	strTemp.Format(_T("%d"), atoi(m_ctrlListMain.GetItemText(index, 3)) + atoi(m_ctrlListMain.GetItemText(index, 8)) * m_iNum);
	strSQL = strSQL + strTemp + "', remainderintegral = '";
	strTemp.Format(_T("%d"), atoi(m_ctrlListMain.GetItemText(index, 4)) - atoi(m_ctrlListMain.GetItemText(index, 8)) * m_iNum);
	strSQL = strSQL + strTemp + "' WHERE cardcode = '";
	strSQL = strSQL + m_strCardCode + "'";
	adoIntegral.ExecuteSQL(strSQL);

	strSQL = "INSERT INTO IntegralCommodity VALUES ('";
	strSQL = strSQL + m_ctrlListMain.GetItemText(index, 0) + "', '";
	strSQL = strSQL + m_ctrlListMain.GetItemText(index, 5) + "', '";
	strSQL = strSQL + m_ctrlListMain.GetItemText(index, 6) + "', '";
	strSQL = strSQL + m_ctrlListMain.GetItemText(index, 7) + "', '";
	strSQL = strSQL + m_ctrlListMain.GetItemText(index, 8) + "', '";
	strSQL = strSQL + m_ctrlListMain.GetItemText(index, 9) + "')";
	adoIntegralCommodity.ExecuteSQL(strSQL);
}

void CDlgIntegral::OnDel() 
{
	// TODO: Add your control notification handler code here
	POSITION pos;
	int index;
	CString strSQL, strTemp;
	CADOConn adoIntegral;

	pos = m_ctrlListMain.GetFirstSelectedItemPosition();
	index = m_ctrlListMain.GetNextSelectedItem(pos);

	strSQL = "UPDATE Integral SET usedintegral = '";
	strTemp.Format(_T("%d"), atoi(m_ctrlListMain.GetItemText(index, 3)) - atoi(m_ctrlListMain.GetItemText(index, 8)) * atoi(m_ctrlListMain.GetItemText(index, 9)));
	strSQL = strSQL + strTemp + "', remainderintegral = '";
	strTemp.Format(_T("%d"), atoi(m_ctrlListMain.GetItemText(index, 4)) + atoi(m_ctrlListMain.GetItemText(index, 8)) * atoi(m_ctrlListMain.GetItemText(index, 9)));
	strSQL = strSQL + strTemp + "' WHERE cardcode = '";
	strSQL = strSQL + m_strCardCode + "'";
	adoIntegral.ExecuteSQL(strSQL);

	m_ctrlListMain.DeleteItem(index);
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章