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

📄 ustomertypedlg.cpp

📁 用于网络管理统计的
💻 CPP
字号:
// ustomerTypeDlg.cpp : implementation file
//

#include "stdafx.h"
#include "CustomerManage.h"
#include "ustomerTypeDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CustomerTypeDlg dialog


CustomerTypeDlg::CustomerTypeDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CustomerTypeDlg::IDD, pParent)
{
	bIsAdd = false;
	bIsModify = false;
	//{{AFX_DATA_INIT(CustomerTypeDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
}


void CustomerTypeDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CustomerTypeDlg)
	DDX_Control(pDX, IDC_BUTTON_CUSTOMER_TYPE_SAVE, m_save);
	DDX_Control(pDX, IDC_BUTTON_CUSTOMER_TYPE_MODIFY, m_modify);
	DDX_Control(pDX, IDC_BUTTON_CUSTOMER_TYPE_ADD, m_add);
	DDX_Control(pDX, IDCANCEL, m_cancel);
	DDX_Control(pDX, IDC_DELETE_TYPE, m_ok);
	DDX_Control(pDX, IDC_LIST_CUSTOMER_TYPE, m_list);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CustomerTypeDlg, CDialog)
	//{{AFX_MSG_MAP(CustomerTypeDlg)
	ON_NOTIFY(NM_CLICK, IDC_LIST_CUSTOMER_TYPE, OnClickListCustomerType)
	ON_BN_CLICKED(IDC_BUTTON_CUSTOMER_TYPE_ADD, OnButtonCustomerTypeAdd)
	ON_BN_CLICKED(IDC_BUTTON_CUSTOMER_TYPE_MODIFY, OnButtonCustomerTypeModify)
	ON_BN_CLICKED(IDC_BUTTON_CUSTOMER_TYPE_SAVE, OnButtonCustomerTypeSave)
	ON_WM_PAINT()
	ON_BN_CLICKED(IDC_DELETE_TYPE, OnDeleteType)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CustomerTypeDlg message handlers

BOOL CustomerTypeDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	InitialListView();
	InsertData();
	InitialCtrl();
	SetButtonBkColor();
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void CustomerTypeDlg::InitialListView()
{
    ListView_SetExtendedListViewStyle(m_list.m_hWnd,
             LVS_EX_FULLROWSELECT|LVS_EX_GRIDLINES|
             LVS_EX_FLATSB|LVS_EX_HEADERDRAGDROP);
	m_list.InsertColumn(0,"ID",LVCFMT_CENTER,0);
	CRect rect;
	m_list.GetClientRect(&rect);
	rect.NormalizeRect();
	m_list.InsertColumn(1,"客户类型",LVCFMT_LEFT,rect.Width());
}
void CustomerTypeDlg::InsertData()
{
	CString strSQL;
	int Index = 0;
	_RecordsetPtr m_pADOSet;
	try
	{
		m_pADOSet.CreateInstance(__uuidof(Recordset));
		strSQL = "select ID,客户类型 from CustomerType";
		m_pADOSet = theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
		while(!m_pADOSet->adoEOF)
		{
			Index = m_list.GetItemCount();
			m_list.InsertItem(Index,"");
			strSQL.Format("%d",m_pADOSet->GetCollect("ID").iVal);
			m_list.SetItemText(Index,0,strSQL);
			m_list.SetItemText(Index,1,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("客户类型"));
			m_pADOSet->MoveNext();
		}
		m_pADOSet->Close();
	}
	catch(_com_error e)
	{
		MessageBox(e.Description(),MB_OK);
		return;
	}
}

void CustomerTypeDlg::OnClickListCustomerType(NMHDR* pNMHDR, LRESULT* pResult) 
{
	// TODO: Add your control notification handler code here
	int Index = 0;
	Index = m_list.GetSelectionMark();
	if(GetDlgItem(IDC_EDIT_CUSTOMER_TYPE))
		GetDlgItem(IDC_EDIT_CUSTOMER_TYPE)->SetWindowText(m_list.GetItemText(Index,1));
	*pResult = 0;
}
void CustomerTypeDlg::InitialCtrl()
{
	if((!bIsAdd) && (!bIsModify))
	{
	    if(GetDlgItem(IDC_BUTTON_CUSTOMER_TYPE_SAVE))
		    GetDlgItem(IDC_BUTTON_CUSTOMER_TYPE_SAVE)->EnableWindow(false);
		if(GetDlgItem(IDC_EDIT_CUSTOMER_TYPE))
			GetDlgItem(IDC_EDIT_CUSTOMER_TYPE)->EnableWindow(false);
	}
	else
	{
	    if(GetDlgItem(IDC_BUTTON_CUSTOMER_TYPE_SAVE))
		    GetDlgItem(IDC_BUTTON_CUSTOMER_TYPE_SAVE)->EnableWindow(true);
		if(GetDlgItem(IDC_EDIT_CUSTOMER_TYPE))
			GetDlgItem(IDC_EDIT_CUSTOMER_TYPE)->EnableWindow(true);
	}
}

void CustomerTypeDlg::OnButtonCustomerTypeAdd() 
{
	// TODO: Add your control notification handler code here
	bIsAdd = true;
	bIsModify = false;
    InitialCtrl();
	GetDlgItem(IDC_EDIT_CUSTOMER_TYPE)->SetWindowText(_T(""));

}

void CustomerTypeDlg::OnButtonCustomerTypeModify() 
{
	// TODO: Add your control notification handler code here
	CString sValue;
	GetDlgItem(IDC_EDIT_CUSTOMER_TYPE)->GetWindowText(sValue);
	if(sValue == _T(""))
	{
		MessageBox("请你选择要修改的类型",MB_OK);
		return;
	}
	bIsModify = true;
	bIsAdd = false;
	InitialCtrl();
}

void CustomerTypeDlg::OnButtonCustomerTypeSave() 
{
	// TODO: Add your control notification handler code here
	CString sValue;
	CString strSQL;
	int Index = 0;
	CString sData;
	GetDlgItem(IDC_EDIT_CUSTOMER_TYPE)->GetWindowText(sValue);
	if(sValue == _T(""))
	{
		MessageBox("客户类型不能为空",MB_OK);
		return;
	}
	if(bIsModify)
	{
		bIsModify = false;
		Index = m_list.GetSelectionMark();
		sData = m_list.GetItemText(Index,0);
		strSQL.Format("Update CustomerType Set 客户类型='%s' where ID=%d",sValue,sData);
		try
		{
		    theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
		}
		catch(_com_error e)
		{
			MessageBox(e.Description(),MB_OK);
			m_save.EnableWindow(false);
			return;
		}
	}
	if(bIsAdd)
	{
		bIsAdd = false;
		strSQL.Format("Insert into CustomerType (客户类型) Values ('%s')",sValue);
		try
		{
		     theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
		     m_list.DeleteAllItems();
	       	 strSQL = "select * from CustomerType";
		     _RecordsetPtr m_pADOSet;
		     m_pADOSet = theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
			 while(!m_pADOSet->adoEOF)
			 {
			     Index = m_list.GetItemCount();
			     m_list.InsertItem(Index,"");
			     strSQL.Format("%d",m_pADOSet->GetCollect("ID").iVal);
			     m_list.SetItemText(Index,0,strSQL);
			     m_list.SetItemText(Index,1,(LPCSTR)(_bstr_t)m_pADOSet->GetCollect("客户类型"));
			     m_pADOSet->MoveNext();
			 }
			 m_pADOSet->Close();
		}
		catch(_com_error e)
		{
			MessageBox(e.Description(),MB_OK);
			m_save.EnableWindow(false);
			return;
		}
	}
	m_save.EnableWindow(false);
}
void CustomerTypeDlg::SetButtonBkColor()
{
	m_save.SetActiveBgColor (RGB(162,189,255));
	m_save.SetInactiveBgColor (RGB(162,189,255));
	m_ok.SetActiveBgColor (RGB(162,189,255));
	m_ok.SetInactiveBgColor (RGB(162,189,255));
	m_add.SetActiveBgColor (RGB(162,189,255));
	m_add.SetInactiveBgColor (RGB(162,189,255));
	m_cancel.SetActiveBgColor (RGB(162,189,255));
	m_cancel.SetInactiveBgColor (RGB(162,189,255));
	m_modify.SetActiveBgColor (RGB(162,189,255));
	m_modify.SetInactiveBgColor (RGB(162,189,255));
}

void CustomerTypeDlg::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	CRect rcClient;
	GetClientRect(&rcClient);
	bar.DrawLeft(&dc,CRect(0,0,10,rcClient.bottom));
	bar.DrawTop(&dc,CRect(0,0,rcClient.right,10));
	bar.DrawRight(&dc,CRect(rcClient.right-10,0,rcClient.right,rcClient.bottom));
	bar.DrawBottom(&dc,CRect(0,rcClient.bottom-10,rcClient.right,rcClient.bottom));		
	// Do not call CDialog::OnPaint() for painting messages
}

void CustomerTypeDlg::OnDeleteType() 
{
	// TODO: Add your control notification handler code here
	CString sTypeName = "";
	GetDlgItem(IDC_EDIT_CUSTOMER_TYPE)->GetWindowText(sTypeName);
	if(sTypeName == "")
	{
		MessageBox("请你选择要删除的记录",MB_OK);
		return;
	}
    int Index = 0;
	Index = m_list.GetSelectionMark();
	CString sID = m_list.GetItemText(Index,0);
	CString strSQL;
	strSQL.Format("delete from CustomerType where ID=%s",sID);
	if(MessageBox("删除客户类型会影响到客户信息的正常显示","提示",MB_ICONEXCLAMATION|MB_YESNO) == IDYES)
	{
		try
		{
			theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
		}
		catch(_com_error e)
		{
			MessageBox(e.Description(),MB_OK);
			return;
		}
		m_list.DeleteItem(Index);
		MessageBox("删除成功",MB_OK);
	}
}

⌨️ 快捷键说明

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