📄 basequery.cpp
字号:
// BaseQuery.cpp : implementation file
//
#include "stdafx.h"
#include "商品销售管理系统.h"
#include "BaseQuery.h"
#include "DCliect.h"
#include "DWare.h"
#include "DOP.h"
#include "DPerson.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBaseQuery dialog
CBaseQuery::CBaseQuery(CWnd* pParent /*=NULL*/)
: CDialog(CBaseQuery::IDD, pParent)
{
//{{AFX_DATA_INIT(CBaseQuery)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
}
void CBaseQuery::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBaseQuery)
DDX_Control(pDX, IDC_GRID, m_Grid);
DDX_Control(pDX, IDC_EDTCondition, m_EdtCondition);
DDX_Control(pDX, IDC_COMField, m_ComField);
DDX_Control(pDX, IDC_COMEmblem, m_ComEmblem);
DDX_Control(pDX, IDC_BUTQUERY, m_ButQuery);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBaseQuery, CDialog)
//{{AFX_MSG_MAP(CBaseQuery)
ON_BN_CLICKED(IDC_BUTQUERY, OnButquery)
ON_NOTIFY(NM_DBLCLK, IDC_GRID, OnDblclkGrid)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBaseQuery message handlers
void CBaseQuery::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CBaseQuery::SetCaption(CString sCaption)
{
m_Caption=sCaption;
}
void CBaseQuery::SetDataBase(CString sDataBaseName)
{
m_DataBaseName=sDataBaseName;
}
void CBaseQuery::OnButquery()
{
CString sField,sEmblem,sCondition,sSQL;
m_ComField.GetWindowText(sField);
m_ComEmblem.GetWindowText(sEmblem);
m_EdtCondition.GetWindowText(sCondition);
if(sEmblem!="LIKE")
sSQL.Format("SELECT * from %s WHERE %s %s '%s'",m_DataBaseName,sField,sEmblem,sCondition);
else
sSQL.Format("SELECT * from %s WHERE %s LIKE '%s%%'",m_DataBaseName,sField,sCondition);
rst.Open(sSQL,adCmdText);
m_Grid.AddCellValue(rst);
}
BOOL CBaseQuery::OnInitDialog()
{
CDialog::OnInitDialog();
this->SetWindowText(this->m_Caption);
if(m_Caption=="客户信息查询")
{
CString Fields[6]={"编号","名称", "简称", "地址", "电话", "联系人"};
for(int i=0;i<6;i++)
{
m_ComField.AddString(Fields[i]);
}
}
else
{
if(m_Caption=="商品信息查询")
{
CString Fields[5]={"编号","名称", "简称", "产地", "计量单位"};
for(int i=0;i<5;i++)
{
m_ComField.AddString(Fields[i]);
}
}
else
{
if(m_Caption=="操作员信息查询")
{
CString Fields[6]={"编号","名称", "简称", "员工姓名", "密码","头像"};
for(int i=0;i<5;i++)
{
m_ComField.AddString(Fields[i]);
}
}
else
{
CString Fields[6]={"编号","名称", "简称", "职务", "聘用日期","薪金"};
for(int i=0;i<5;i++)
{
m_ComField.AddString(Fields[i]);
}
}
}
}
m_Grid.ReadOnly(true);
m_Grid.SetDataBase(m_DataBaseName,adCmdTable);
this->m_ComEmblem.SetCurSel(0);
this->m_ComField.SetCurSel(0);
if(m_Grid.GetItemCount()<1)
{
if(m_Caption=="客户信息查询")
{
CDCliect cliectdlg;
cliectdlg.SetID("0");
cliectdlg.DoModal();
this->m_ComField.SetCurSel(0);
this->m_ComEmblem.SetCurSel(0);
this->m_EdtCondition.SetWindowText("");
this->OnButquery();
}
else
{
if(m_Caption=="商品信息查询")
{
CDWare waredlg;
waredlg.SetID("0");
waredlg.DoModal();
this->m_ComField.SetCurSel(0);
this->m_ComEmblem.SetCurSel(0);
this->m_EdtCondition.SetWindowText("");
this->OnButquery();
}
else
{
if(m_Caption=="操作员信息查询")
{
CDOP OPdlg;
OPdlg.SetID("0");
OPdlg.DoModal();
this->m_ComField.SetCurSel(0);
this->m_ComEmblem.SetCurSel(0);
this->m_EdtCondition.SetWindowText("");
this->OnButquery();
}
else
{
CDPerson Persondlg;
Persondlg.SetID("0");
Persondlg.DoModal();
this->m_ComField.SetCurSel(0);
this->m_ComEmblem.SetCurSel(0);
this->m_EdtCondition.SetWindowText("");
this->OnButquery();
}
}
}
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBaseQuery::OnDblclkGrid(NMHDR* pNMHDR, LRESULT* pResult)
{
CString sID;
if(m_Caption=="客户信息查询")
{
CDCliect cliectdlg;
if(m_Grid.GetHotItem()>=0)
{
sID=m_Grid.GetItemText(m_Grid.GetHotItem(),0);
cliectdlg.SetID(sID);
cliectdlg.DoModal();
this->m_ComField.SetCurSel(0);
this->m_ComEmblem.SetCurSel(0);
this->m_EdtCondition.SetWindowText("");
this->OnButquery();
}
}
else
{
if(m_Caption=="商品信息查询")
{
CDWare waredlg;
if(m_Grid.GetHotItem()>=0)
{
sID=m_Grid.GetItemText(m_Grid.GetHotItem(),0);
waredlg.SetID(sID);
waredlg.DoModal();
this->m_ComField.SetCurSel(0);
this->m_ComEmblem.SetCurSel(0);
this->m_EdtCondition.SetWindowText("");
this->OnButquery();
}
}
else
{
if(m_Caption=="操作员信息查询")
{
CDOP OPdlg;
if(m_Grid.GetHotItem()>=0)
{
sID=m_Grid.GetItemText(m_Grid.GetHotItem(),0);
OPdlg.SetID(sID);
OPdlg.DoModal();
this->m_ComField.SetCurSel(0);
this->m_ComEmblem.SetCurSel(0);
this->m_EdtCondition.SetWindowText("");
this->OnButquery();
}
}
else
{
CDPerson Persondlg;
if(m_Grid.GetHotItem()>=0)
{
sID=m_Grid.GetItemText(m_Grid.GetHotItem(),0);
Persondlg.SetID(sID);
Persondlg.DoModal();
this->m_ComField.SetCurSel(0);
this->m_ComEmblem.SetCurSel(0);
this->m_EdtCondition.SetWindowText("");
this->OnButquery();
}
}
}
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -