📄 buydlg.cpp
字号:
// BuyDlg.cpp : implementation file
//
#include "stdafx.h"
#include "heavenmis.h"
#include "BuyDlg.h"
#include "product.h"
#include "supplier.h"
#include "employee.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CBuyDlg dialog
CBuyDlg::CBuyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBuyDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBuyDlg)
m_strEmployee = _T("");
m_strProduct = _T("");
m_strSupplier = _T("");
//}}AFX_DATA_INIT
}
void CBuyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBuyDlg)
DDX_Control(pDX, IDC_COMBO_SUPPLIER, m_comboSupp);
DDX_Control(pDX, IDC_COMBO_PRODUCT, m_comboProd);
DDX_Control(pDX, IDC_COMBO_EMPLOYEE, m_comboEmp);
DDX_Control(pDX, IDC_ADODC1, m_adodcBuy);
DDX_CBString(pDX, IDC_COMBO_EMPLOYEE, m_strEmployee);
DDX_CBString(pDX, IDC_COMBO_PRODUCT, m_strProduct);
DDX_CBString(pDX, IDC_COMBO_SUPPLIER, m_strSupplier);
DDX_Control(pDX, IDC_DATAGRID1, m_datagridBuy);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBuyDlg, CDialog)
//{{AFX_MSG_MAP(CBuyDlg)
ON_BN_CLICKED(IDC_BUTTON_QUERY, OnButtonQuery)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBuyDlg message handlers
BOOL CBuyDlg::OnInitDialog()
{
CDialog::OnInitDialog();
CADORecordset* pRs=new CADORecordset(((CHeavenMISApp*)AfxGetApp())->pDB);
//查询所有商品名初始化comboBox中
pRs->Open("select Name from tbProduct",CADORecordset.openQuery);
CString temp;
if(pRs->GetRecordCount()>0)
{
while(!pRs->IsEOF())
{
pRs->GetFieldValue("Name",temp);
m_comboProd.AddString(temp);
pRs->MoveNext();
}
}
pRs->Close();
//查询所有供应商名初始化comboBox
pRs->Open("select FactoryName from tbSupplier",CADORecordset.openQuery);
if(pRs->GetRecordCount()>0)
{
while(!pRs->IsEOF())
{
pRs->GetFieldValue("FactoryName",temp);
m_comboSupp.AddString(temp);
pRs->MoveNext();
}
}
pRs->Close();
//查询所有雇员名初始化comboBox控件
pRs->Open("select Name from tbEmployee",CADORecordset.openQuery);
if(pRs->GetRecordCount()>0)
{
while(!pRs->IsEOF())
{
pRs->GetFieldValue("Name",temp);
m_comboEmp.AddString(temp);
pRs->MoveNext();
}
}
pRs->Close();
delete pRs;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CBuyDlg::OnButtonQuery()
{
UpdateData(TRUE);
long suppID,prodID;
int empID;
CString strSQL,temp1,temp2,temp3;
strSQL="select * from tbBuy ";
//如果用户选择了该查询条件,构造where子句
if(!m_strSupplier.IsEmpty())
{
CSupplier supplier;
suppID=supplier.GetKeyByName(m_strSupplier);
temp1.Format("where SupplierID=%d ",suppID);
strSQL+=temp1;
}
if(!m_strProduct.IsEmpty())
{
CProduct product;
prodID=product.GetKeyByName(m_strProduct);
if(!m_strSupplier.IsEmpty())
temp2.Format("and ProductID=%d ",prodID);
else temp2.Format("where ProductID=%d ",prodID);
strSQL+=temp2;
}
if(!m_strEmployee.IsEmpty())
{
CEmployee employee;
empID=employee.GetKeyByName(m_strEmployee);
if(m_strSupplier.IsEmpty()&&m_strProduct.IsEmpty())
temp3.Format("where EmployeeID=%d",empID);
else temp3.Format("and EmployeeID=%d",empID);
strSQL+=temp3;
}
m_adodcBuy.SetRecordSource(strSQL);
m_adodcBuy.Refresh();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -