📄 customermandlg.cpp
字号:
// CustomerManDlg.cpp : implementation file
//
#include "stdafx.h"
#include "QuoteManage.h"
#include "CustomerManDlg.h"
#include "CustomerEditDlg.h"
#include "CustomerInfo.h"
#include "COMDEF.H"
#include "Columns.h"
#include "Column.h"
#include "_Recordset.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCustomerManDlg dialog
CCustomerManDlg::CCustomerManDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCustomerManDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCustomerManDlg)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CCustomerManDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCustomerManDlg)
DDX_Control(pDX, IDC_ADODC1, m_Adodc);
DDX_Control(pDX, IDC_DATAGRID1, m_Datagrid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCustomerManDlg, CDialog)
//{{AFX_MSG_MAP(CCustomerManDlg)
ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
ON_BN_CLICKED(IDC_MODI_BUTTON, OnModiButton)
ON_BN_CLICKED(IDC_DEL_BUTTON, OnDelButton)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCustomerManDlg message handlers
BOOL CCustomerManDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
RefreshData();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
// 网格控件加载函数
void CCustomerManDlg::RefreshData()
{
UpdateData(TRUE);
// 设置Select语句
CString cSource;
cSource = "SELECT CustomerId, Name AS 姓名, Sex AS 性别,Company AS 所在单位,"
"Mobile AS 手机, Home AS 家庭电话,Memo AS 备注 FROM CustomerInfo";
//刷新ADO Data控件的记录源
m_Adodc.SetRecordSource(cSource);
m_Adodc.Refresh();
//设置列宽度
_variant_t vIndex;
vIndex = long(0);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(0);
vIndex = long(1);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(60);
vIndex = long(2);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(40);
vIndex = long(3);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(150);
vIndex = long(4);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(70);
vIndex = long(5);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(70);
vIndex = long(6);
m_Datagrid.GetColumns().GetItem(vIndex).SetWidth(150);
}
// 添加按钮
void CCustomerManDlg::OnAddButton()
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
// 初始化CustomerEditDlg对话框中的变量
CCustomerEditDlg dlg;
dlg.cId = "";
dlg.m_name = "";
dlg.cSex = "男";
dlg.m_company = "";
dlg.m_mobile = "";
dlg.m_home = "";
dlg.m_memo = "";
// 打开CustomerEditDlg对话框
if (dlg.DoModal() == IDOK)
RefreshData();
}
// 修改按钮
void CCustomerManDlg::OnModiButton()
{
// TODO: Add your control notification handler code here
if (m_Adodc.GetRecordset().GetEof())
{
MessageBox("请选择要修改的记录");
return;
}
// 设置CustomerEditDlg对话框中的变量
CCustomerEditDlg dlg;
dlg.cId = m_Datagrid.GetItem(0);
dlg.m_name = m_Datagrid.GetItem(1);
dlg.cSex = m_Datagrid.GetItem(2);
dlg.m_company = m_Datagrid.GetItem(3);
dlg.m_mobile = m_Datagrid.GetItem(4);
dlg.m_home = m_Datagrid.GetItem(5);
dlg.m_memo = m_Datagrid.GetItem(6);
// 打开CustomerEditDlg对话框
if (dlg.DoModal() == IDOK)
RefreshData();
}
// 删除按钮
void CCustomerManDlg::OnDelButton()
{
// TODO: Add your control notification handler code here
if (m_Adodc.GetRecordset().GetEof())
{
MessageBox("请选择要删除的记录!");
return;
}
if (MessageBox("是否删除当前记录?","请确认", MB_YESNO + MB_ICONQUESTION) == IDYES)
{
// 删除
CCustomerInfo cus;
cus.SqlDelete(m_Datagrid.GetItem(0));
RefreshData();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -