#if !defined(AFX_DLGCLIENT_H__C5CDA217_1770_4544_A53C_1BF029D8C452__INCLUDED_)
#define AFX_DLGCLIENT_H__C5CDA217_1770_4544_A53C_1BF029D8C452__INCLUDED_
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
// DlgClient.h : header file
//
/
// CDlgClient dialog
class CDlgClient : public CDialog
{
// Construction
public:
CDlgClient(CWnd* pParent = NULL); // standard constructor
// Dialog Data
//{{AFX_DATA(CDlgClient)
enum { IDD = IDD_CLIENTINFO };
CListCtrl m_ctrlListMain;
CString m_strClientCode;
CString m_strClientName;
CString m_strClientPhone;
CString m_strAddress;
//}}AFX_DATA
// Overrides
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CDlgClient)
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
// Generated message map functions
//{{AFX_MSG(CDlgClient)
virtual BOOL OnInitDialog();
afx_msg void OnAddclient();
afx_msg void OnUpdateclientinfo();
afx_msg void OnDeleteclient();
afx_msg void OnClickListmain(NMHDR* pNMHDR, LRESULT* pResult);
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
//{{AFX_INSERT_LOCATION}}
// Microsoft Visual C++ will insert additional declarations immediately before the previous line.
#endif // !defined(AFX_DLGCLIENT_H__C5CDA217_1770_4544_A53C_1BF029D8C452__INCLUDED_)
// DlgClient.cpp : implementation file
//
#include "stdafx.h"
#include "SalesManagementSystem.h"
#include "DlgClient.h"
#include "ADOConn.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/
// CDlgClient dialog
CDlgClient::CDlgClient(CWnd* pParent /*=NULL*/)
: CDialog(CDlgClient::IDD, pParent)
{
//{{AFX_DATA_INIT(CDlgClient)
m_strClientCode = _T("");
m_strClientName = _T("");
m_strClientPhone = _T("");
m_strAddress = _T("");
//}}AFX_DATA_INIT
}
void CDlgClient::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDlgClient)
DDX_Control(pDX, IDC_LISTMAIN, m_ctrlListMain);
DDX_Text(pDX, IDC_CLIENTCODE, m_strClientCode);
DDX_Text(pDX, IDC_CLIENTNAME, m_strClientName);
DDX_Text(pDX, IDC_CLIENTPHONE, m_strClientPhone);
DDX_Text(pDX, IDC_ADDRESS, m_strAddress);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDlgClient, CDialog)
//{{AFX_MSG_MAP(CDlgClient)
ON_BN_CLICKED(IDC_ADDCLIENT, OnAddclient)
ON_BN_CLICKED(IDC_UPDATECLIENTINFO, OnUpdateclientinfo)
ON_BN_CLICKED(IDC_DELETECLIENT, OnDeleteclient)
ON_NOTIFY(NM_CLICK, IDC_LISTMAIN, OnClickListmain)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/
// CDlgClient message handlers
BOOL CDlgClient::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
CADOConn adoClient;
CString strSQL;
strSQL = "SELECT * FROM ClientInfo";
adoClient.Open(strSQL);
adoClient.InitList(&m_ctrlListMain);
adoClient.FillList(&m_ctrlListMain);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDlgClient::OnAddclient()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
m_ctrlListMain.InsertItem(0, m_strClientCode);
m_ctrlListMain.SetItemText(0, 1, m_strClientName);
m_ctrlListMain.SetItemText(0, 2, m_strClientPhone);
m_ctrlListMain.SetItemText(0, 3, m_strAddress);
}
void CDlgClient::OnUpdateclientinfo()
{
// TODO: Add your control notification handler code here
POSITION pos;
int index;
CString strSQL;
CADOConn adoClient;
pos = m_ctrlListMain.GetFirstSelectedItemPosition();
index = m_ctrlListMain.GetNextSelectedItem(pos);
strSQL = "SELECT * FROM ClientInfo WHERE ClientInfo.cardcode = '";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 0) + "'";
adoClient.Open(strSQL);
if (adoClient.adoEOF())
{
strSQL = "INSERT INTO ClientInfo VALUES ('";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 0) + "', '";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 1) + "', '";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 2) + "', '";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 3) + "')";
adoClient.ExitConnect();
adoClient.ExecuteSQL(strSQL);
}
else
{
strSQL = "UPDATE ClientInfo SET cardcode = '";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 0) + "', username = '";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 1) + "', address = '";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 2) + "', telephone = '";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 3) + "' WHERE cardcode = '";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 0) + "'";
adoClient.ExitConnect();
adoClient.ExecuteSQL(strSQL);
}
}
void CDlgClient::OnDeleteclient()
{
// TODO: Add your control notification handler code here
POSITION pos;
int index;
CADOConn adoClient;
CString strSQL;
pos = m_ctrlListMain.GetFirstSelectedItemPosition();
index = m_ctrlListMain.GetNextSelectedItem(pos);
strSQL = "DELETE * FROM ClientInfo WHERE ClientInfo.cardcode ='";
strSQL = strSQL + m_ctrlListMain.GetItemText(index, 0) + "'";
adoClient.ExecuteSQL(strSQL);
m_ctrlListMain.DeleteItem(index);
}
void CDlgClient::OnClickListmain(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
POSITION pos;
int index;
pos = m_ctrlListMain.GetFirstSelectedItemPosition();
index = m_ctrlListMain.GetNextSelectedItem(pos);
m_strClientCode = m_ctrlListMain.GetItemText(index, 0);
m_strClientName = m_ctrlListMain.GetItemText(index, 1);
m_strClientPhone = m_ctrlListMain.GetItemText(index, 2);
m_strAddress = m_ctrlListMain.GetItemText(index, 3);
UpdateData(FALSE);
*pResult = 0;
}