📄 customerdlg.cpp
字号:
// CustomerDlg.cpp : implementation file
//
#include "stdafx.h"
#include "heavenmis.h"
#include "CustomerDlg.h"
#include "column.h"
#include "columns.h"
#include "addcusdlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CCustomerDlg dialog
CCustomerDlg::CCustomerDlg(CWnd* pParent /*=NULL*/)
: CDialog(CCustomerDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CCustomerDlg)
m_strCity = _T("");
m_strProvince = _T("");
//}}AFX_DATA_INIT
}
void CCustomerDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CCustomerDlg)
DDX_Control(pDX, IDC_ADODC1, m_adodcCus);
DDX_Control(pDX, IDC_DATAGRID1, m_datagridCus);
DDX_Text(pDX, IDC_EDIT_CITY, m_strCity);
DDX_Text(pDX, IDC_EDIT_PROVINCE, m_strProvince);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CCustomerDlg, CDialog)
//{{AFX_MSG_MAP(CCustomerDlg)
ON_BN_CLICKED(IDC_BUTTON_QUERY, OnButtonQuery)
ON_BN_CLICKED(IDC_BUTTON_ADD, OnButtonAdd)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CCustomerDlg message handlers
BOOL CCustomerDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
ResetCol();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CCustomerDlg::OnButtonQuery()
{
UpdateData(TRUE);
CString strQuery="select * from tbCustomer where ";
CString temp1="",temp2="";
//如果没有给定查询条件返回
if(m_strCity.IsEmpty()&&m_strProvince.IsEmpty())
return;
//用查询条件构造SQL语句
else if(!m_strProvince.IsEmpty())
{
temp1.Format("Province='%s'",m_strProvince);
strQuery+=temp1;
}
if(!m_strCity.IsEmpty())
{
if(temp1.IsEmpty())
temp2.Format("City='%s'",m_strCity);
else
temp2.Format("and City='%s'",m_strCity);
strQuery+=temp2;
}
//重新设置Recordsource,刷新数据
m_adodcCus.SetRecordSource(strQuery);
m_adodcCus.Refresh();
ResetCol();
}
void CCustomerDlg::OnButtonAdd()
{
CAddCusDlg addCusdlg;
if(addCusdlg.DoModal()==IDOK)
{
m_adodcCus.Refresh();
ResetCol();
}
}
void CCustomerDlg::ResetCol()
{
CColumns allCols;
CColumn onecol;
allCols=m_datagridCus.GetColumns();
//设置各列标题和宽度
onecol=allCols.GetItem(COleVariant(long(0)));
onecol.SetCaption("编号");
onecol.SetWidth(20);
onecol=allCols.GetItem(COleVariant(long(1)));
onecol.SetCaption("客户名称");
onecol.SetWidth(60);
onecol=allCols.GetItem(COleVariant(long(2)));
onecol.SetCaption("联系人");
onecol.SetWidth(60);
onecol=allCols.GetItem(COleVariant(long(3)));
onecol.SetCaption("联系电话");
onecol.SetWidth(80);
onecol=allCols.GetItem(COleVariant(long(4)));
onecol.SetCaption("地址");
onecol.SetWidth(140);
onecol=allCols.GetItem(COleVariant(long(5)));
onecol.SetCaption("省份");
onecol.SetWidth(100);
onecol=allCols.GetItem(COleVariant(long(6)));
onecol.SetCaption("城市");
onecol.SetWidth(100);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -