📄 ustomertractsetdlg.cpp
字号:
// ustomerTractSetDlg.cpp : implementation file
//
#include "stdafx.h"
#include "CustomerManage.h"
#include "ustomerTractSetDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CustomerTractSetDlg dialog
CustomerTractSetDlg::CustomerTractSetDlg(CWnd* pParent /*=NULL*/)
: CDialog(CustomerTractSetDlg::IDD, pParent)
{
bIsAdd = false;
bIsModify = false;
//{{AFX_DATA_INIT(CustomerTractSetDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CustomerTractSetDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CustomerTractSetDlg)
DDX_Control(pDX, IDC_DELETE_TRACT, m_ok);
DDX_Control(pDX, IDCANCEL, m_cancel);
DDX_Control(pDX, IDC_BUTTON_CUSTOMER_TRACT_SAVE, m_save);
DDX_Control(pDX, IDC_BUTTON_CUSTOMER_TRACT_MODIFY, m_modify);
DDX_Control(pDX, IDC_BUTTON_CUSTOMER_TRACT_ADD, m_add);
DDX_Control(pDX, IDC_LIST_CUSTOMER_TRACT, m_list);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CustomerTractSetDlg, CDialog)
//{{AFX_MSG_MAP(CustomerTractSetDlg)
ON_WM_PAINT()
ON_BN_CLICKED(IDC_BUTTON_CUSTOMER_TRACT_ADD, OnButtonCustomerTractAdd)
ON_BN_CLICKED(IDC_BUTTON_CUSTOMER_TRACT_MODIFY, OnButtonCustomerTractModify)
ON_BN_CLICKED(IDC_BUTTON_CUSTOMER_TRACT_SAVE, OnButtonCustomerTractSave)
ON_NOTIFY(NM_CLICK, IDC_LIST_CUSTOMER_TRACT, OnClickListCustomerTract)
ON_BN_CLICKED(IDC_DELETE_TRACT, OnDeleteTract)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CustomerTractSetDlg message handlers
BOOL CustomerTractSetDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
InitialListView();
InsertData();
SetButtonBkColor();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CustomerTractSetDlg::InsertData()
{
CString strSQL;
int Index = 0;
_RecordsetPtr m_pADOSet;
try
{
m_pADOSet.CreateInstance(__uuidof(Recordset));
strSQL = "select ID,所属地域 from CustomerTract";
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 CustomerTractSetDlg::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 CustomerTractSetDlg::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));
m_save.EnableWindow(false);
GetDlgItem(IDC_EDIT_CUSTOMER_TRACT)->EnableWindow(false);
}
void CustomerTractSetDlg::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 CustomerTractSetDlg::OnButtonCustomerTractAdd()
{
// TODO: Add your control notification handler code here
bIsAdd = true;
bIsModify = false;
GetDlgItem(IDC_EDIT_CUSTOMER_TRACT)->EnableWindow(true);
GetDlgItem(IDC_EDIT_CUSTOMER_TRACT)->SetWindowText("");
m_save.EnableWindow(true);
}
void CustomerTractSetDlg::OnButtonCustomerTractModify()
{
// TODO: Add your control notification handler code here
bIsAdd = false;
bIsModify = true;
GetDlgItem(IDC_EDIT_CUSTOMER_TRACT)->EnableWindow(true);
m_save.EnableWindow(true);
}
void CustomerTractSetDlg::OnButtonCustomerTractSave()
{
// TODO: Add your control notification handler code here
CString sValue;
CString strSQL;
int Index = 0;
CString sData;
GetDlgItem(IDC_EDIT_CUSTOMER_TRACT)->GetWindowText(sValue);
if(sValue == _T(""))
{
MessageBox("客户类型不能为空",MB_OK);
return;
}
if(bIsModify)
{
bIsModify = false;
GetDlgItem(IDC_EDIT_CUSTOMER_TRACT)->EnableWindow(false);
Index = m_list.GetSelectionMark();
sData = m_list.GetItemText(Index,0);
strSQL.Format("Update CustomerTract Set 所属地域='%s' where ID=%s",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 CustomerTract (所属地域) Values ('%s')",sValue);
try
{
theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
m_list.DeleteAllItems();
strSQL = "select * from CustomerTract";
_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 CustomerTractSetDlg::OnClickListCustomerTract(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
int Index = 0;
Index = m_list.GetSelectionMark();
if(GetDlgItem(IDC_EDIT_CUSTOMER_TRACT))
GetDlgItem(IDC_EDIT_CUSTOMER_TRACT)->SetWindowText(m_list.GetItemText(Index,1));
*pResult = 0;
}
void CustomerTractSetDlg::OnDeleteTract()
{
// TODO: Add your control notification handler code here
int Index = 0;
CString sID = "";
GetDlgItem(IDC_EDIT_CUSTOMER_TRACT)->GetWindowText(sID);
if(sID == "")
{
MessageBox("请你选择要删除的记录",MB_OK);
return;
}
Index = m_list.GetSelectionMark();
sID = m_list.GetItemText(Index,0);
CString strSQL;
strSQL.Format("delete from CustomerTract where ID=%s",sID);
if(MessageBox("你的确要删除吗?","提示",MB_YESNO|MB_ICONEXCLAMATION) == IDYES)
{
try
{
theApp.ADOConn->Execute(strSQL.AllocSysString(),NULL,adCmdText);
}
catch(_com_error e)
{
MessageBox(e.Description(),MB_OK);
return;
}
GetDlgItem(IDC_EDIT_CUSTOMER_TRACT)->SetWindowText("");
m_list.DeleteItem(Index);
MessageBox("删除成功",MB_OK);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -