📄 buyentrydlg.cpp
字号:
// BuyEntryDlg.cpp : implementation file
//
#include "stdafx.h"
#include "heavenmis.h"
#include "BuyEntryDlg.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
/////////////////////////////////////////////////////////////////////////////
// CBuyEntryDlg dialog
CBuyEntryDlg::CBuyEntryDlg(CWnd* pParent /*=NULL*/)
: CDialog(CBuyEntryDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CBuyEntryDlg)
m_buytime = COleDateTime::GetCurrentTime();
m_famount = 0.0f;
m_lQuantity = 0;
//}}AFX_DATA_INIT
}
void CBuyEntryDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CBuyEntryDlg)
DDX_Control(pDX, IDC_COMBO_PRODUCT, m_comboProd);
DDX_Control(pDX, IDC_COMBO_EMPLOYEE, m_comboEmp);
DDX_Control(pDX, IDC_COMBO_SUPPLIER, m_comboSupp);
DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER_BUY, m_buytime);
DDX_Text(pDX, IDC_EDIT_AMOUNT, m_famount);
DDX_Text(pDX, IDC_EDIT_QUANTITY, m_lQuantity);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CBuyEntryDlg, CDialog)
//{{AFX_MSG_MAP(CBuyEntryDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CBuyEntryDlg message handlers
BOOL CBuyEntryDlg::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;
}
void CBuyEntryDlg::OnOK()
{
UpdateData(TRUE);
CString productName,empName,suppName;
m_comboProd.GetWindowText(productName);
CProduct product;
int quantity;
//获得该商品的当前数量
quantity=product.GetAmountByName(productName);
//获得商品、供应商、员工的ID
long productID=product.GetKeyByName(productName);
m_comboSupp.GetWindowText(suppName);
CSupplier supplier;
long suppID=supplier.GetKeyByName(suppName);
m_comboEmp.GetWindowText(empName);
CEmployee employee;
int empID=employee.GetKeyByName(empName);
//添加销售记录到tbBuy
CADORecordset* pRs=new CADORecordset(((CHeavenMISApp*)AfxGetApp())->pDB);
pRs->Open("select * from tbBuy",CADORecordset.openQuery);
pRs->AddNew();
pRs->SetFieldValue("BuyDate",m_buytime);
pRs->SetFieldValue("ProductID",productID);
pRs->SetFieldValue("Quantity",m_lQuantity);
pRs->SetFieldValue("Amount",m_famount);
pRs->SetFieldValue("SupplierID",suppID);
pRs->SetFieldValue("EmployeeID",empID);
pRs->Update();
//修改销售商品的当前数量
product.SetCurAmount(quantity+m_lQuantity);
product.SetAmountByName(productName);
CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -