📄 stockdlg.cpp
字号:
// StockDLG.cpp : implementation file
//
#include "stdafx.h"
#include "trade_mis.h"
#include "StockDLG.h"
#include "Trade_MISView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CStockDLG dialog
CStockDLG::CStockDLG(CWnd* pParent /*=NULL*/)
: CDialog(CStockDLG::IDD, pParent)
{
//{{AFX_DATA_INIT(CStockDLG)
m_sMemo = _T("");
m_tOrderDate = COleDateTime::GetCurrentTime();
m_sPrice = _T("");
m_sProductName = _T("");
m_sProductSpec = _T("");
m_sProductUnit = _T("");
m_sProviderName = _T("");
m_sProviderPerson = _T("");
m_sProviderPhone = _T("");
m_sQuantity = _T("");
//}}AFX_DATA_INIT
}
void CStockDLG::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CStockDLG)
DDX_Text(pDX, IDC_STOCK_MEMO, m_sMemo);
DDX_DateTimeCtrl(pDX, IDC_STOCK_ORDERDATE, m_tOrderDate);
DDX_Text(pDX, IDC_STOCK_PRICE, m_sPrice);
DDX_CBString(pDX, IDC_STOCK_PRODUCTNAME, m_sProductName);
DDX_Text(pDX, IDC_STOCK_PRODUCTSPEC, m_sProductSpec);
DDX_Text(pDX, IDC_STOCK_PRODUCTUNIT, m_sProductUnit);
DDX_CBString(pDX, IDC_STOCK_PROVIDERNAME, m_sProviderName);
DDX_Text(pDX, IDC_STOCK_PROVIDERPERSON, m_sProviderPerson);
DDX_Text(pDX, IDC_STOCK_PROVIDERPHONE, m_sProviderPhone);
DDX_Text(pDX, IDC_STOCK_QUANTITY, m_sQuantity);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CStockDLG, CDialog)
//{{AFX_MSG_MAP(CStockDLG)
ON_CBN_SELCHANGE(IDC_STOCK_PROVIDERNAME, OnStockProviderNameSelChange)
ON_CBN_SELCHANGE(IDC_STOCK_PRODUCTNAME, OnStockProductNameSelChange)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CStockDLG message handlers
BOOL CStockDLG::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
m_sOldProviderName = m_sProviderName;
m_sOldProductName = m_sProductName;
if (m_bAppend)
{
// Update Dialog Caption
SetWindowText(_T("添加进货信息"));
// Init Provider Combobox
_variant_t strQuery, Holder;
strQuery = "select * from suppliers";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
int iCount = theApp.m_pADOSet->GetRecordCount();
theApp.m_pADOSet->MoveFirst();
for (int i=0; i<iCount; i++)
{
Holder = theApp.m_pADOSet->GetCollect("CompanyName");
((CComboBox*)GetDlgItem(IDC_STOCK_PROVIDERNAME))->InsertString(i, Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
// Get other onfo to display
if ( 0==i )
{
// Get Person
Holder = theApp.m_pADOSet->GetCollect("ContactName");
m_sProviderPerson = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
// Get Phone
Holder = theApp.m_pADOSet->GetCollect("Phone");
m_sProviderPhone = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
}
theApp.m_pADOSet->MoveNext();
}
((CComboBox*)GetDlgItem(IDC_STOCK_PROVIDERNAME))->SetCurSel(0);
// Init Product Combobox
strQuery = "select * from products";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
iCount = theApp.m_pADOSet->GetRecordCount();
theApp.m_pADOSet->MoveFirst();
for (i=0; i<iCount; i++)
{
Holder = theApp.m_pADOSet->GetCollect("ProductName");
((CComboBox*)GetDlgItem(IDC_STOCK_PRODUCTNAME))->InsertString(i, Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder);
// Get other onfo to display
if ( 0==i )
{
// Get Spec
Holder = theApp.m_pADOSet->GetCollect("Spec");
m_sProductSpec = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
// Get Phone
Holder = theApp.m_pADOSet->GetCollect("Unit");
m_sProductUnit = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
}
theApp.m_pADOSet->MoveNext();
}
((CComboBox*)GetDlgItem(IDC_STOCK_PRODUCTNAME))->SetCurSel(0);
}
else
{
// Update Dialog Caption
SetWindowText(_T("修改进货信息"));
// Init Provider Combobox
_variant_t strQuery, Holder;
CString str;
int iSel = 0;
strQuery = "select * from suppliers";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
int iCount = theApp.m_pADOSet->GetRecordCount();
theApp.m_pADOSet->MoveFirst();
for (int i=0; i<iCount; i++)
{
Holder = theApp.m_pADOSet->GetCollect("CompanyName");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
((CComboBox*)GetDlgItem(IDC_STOCK_PROVIDERNAME))->InsertString(i, str);
// Get other onfo to display
if ( str==m_sProviderName )
{
// Get Person
Holder = theApp.m_pADOSet->GetCollect("ContactName");
m_sProviderPerson = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
// Get Phone
Holder = theApp.m_pADOSet->GetCollect("Phone");
m_sProviderPhone = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
iSel = i;
}
theApp.m_pADOSet->MoveNext();
}
((CComboBox*)GetDlgItem(IDC_STOCK_PROVIDERNAME))->SetCurSel(iSel);
// Init Product Combobox
strQuery = "select * from products";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
iCount = theApp.m_pADOSet->GetRecordCount();
theApp.m_pADOSet->MoveFirst();
for (i=0; i<iCount; i++)
{
Holder = theApp.m_pADOSet->GetCollect("ProductName");
str = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
((CComboBox*)GetDlgItem(IDC_STOCK_PRODUCTNAME))->InsertString(i, str);
if ( str==m_sProductName ) iSel = i;
theApp.m_pADOSet->MoveNext();
}
((CComboBox*)GetDlgItem(IDC_STOCK_PRODUCTNAME))->SetCurSel(iSel);
}
UpdateData(false);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CStockDLG::OnStockProviderNameSelChange()
{
// TODO: Add your control notification handler code here
UpdateData(true);
_variant_t strQuery, Holder;
strQuery = "select * from suppliers where CompanyName='"+m_sProviderName+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
// Get person
Holder = theApp.m_pADOSet->GetCollect("ContactName");
m_sProviderPerson = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
// Get Phone
Holder = theApp.m_pADOSet->GetCollect("Phone");
m_sProviderPhone = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
UpdateData(false);
}
void CStockDLG::OnStockProductNameSelChange()
{
// TODO: Add your control notification handler code here
UpdateData(true);
_variant_t strQuery, Holder;
strQuery = "select * from products where ProductName='"+m_sProductName+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
// Get Spec
Holder = theApp.m_pADOSet->GetCollect("Spec");
m_sProductSpec = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
// Get Unit
Holder = theApp.m_pADOSet->GetCollect("Unit");
m_sProductUnit = Holder.vt==VT_NULL?"":(char*)(_bstr_t)Holder;
UpdateData(false);
}
void CStockDLG::OnOK()
{
// TODO: Add extra validation here
UpdateData(true);
m_sQuantity.TrimRight(" ");
m_sPrice.TrimRight(" ");
// Make sure all needed info is available
CString sWarning="";
if ( ""==m_sQuantity ) sWarning=_T("数量");
else if ( ""==m_sPrice ) sWarning=_T("单价");
if ( ""!=sWarning )
{
sWarning += _T("不能为空");
AfxMessageBox(sWarning, MB_ICONEXCLAMATION);
return;
}
float fPrice=atof(m_sPrice);
if ( 0==fPrice )
{
AfxMessageBox(_T("单价:请输入非零数字"), MB_ICONEXCLAMATION);
return;
}
m_sPrice.Format("%.2f", fPrice);
_variant_t strQuery;
if ( m_bAppend || m_sOldProviderName!=m_sProviderName || m_sOldProductName!=m_sProductName )
{
// Judge Stock is unique
strQuery = "select * from sstock where ProviderName='"+m_sProviderName+"' and ProductName='"+m_sProductName+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
int iCount = theApp.m_pADOSet->GetRecordCount();
if ( 0!=iCount )
{
AfxMessageBox(_T("已经存在此进货记录!"), MB_ICONEXCLAMATION);
return;
}
}
if ( !m_bAppend ) // Not Append, delete old record first
{
strQuery = "delete from sstock where ProviderName='"+m_sOldProviderName+"' and ProductName='"+m_sOldProductName+"'";
theApp.ADOExecute(theApp.m_pADOSet, strQuery);
}
// Insert Record
// Get OrderDate
CString sOrderDate = m_tOrderDate.Format("%Y-%m-%d");
strQuery = "insert sstock (ProviderName, ProductName, Spec, Unit, Quantity, UnitPrice, OrderDate, Ordermemo) \
values ('"+m_sProviderName+"', '"+m_sProductName+"', '"+m_sProductSpec+"', '"+m_sProductUnit+"', "+m_sQuantity+", "+m_sPrice+", '"+sOrderDate+"', '"+m_sMemo+"')";
if ( theApp.ADOExecute(theApp.m_pADOSet, strQuery) )
{
if (m_bAppend)
{
AfxMessageBox(_T("添加进货信息成功!"), MB_ICONINFORMATION);
// Clear all input
m_sQuantity=m_sPrice=m_sMemo="";
UpdateData(false);
}
else AfxMessageBox(_T("修改进货信息成功!"), MB_ICONINFORMATION);
}
else
{
if (m_bAppend) AfxMessageBox(_T("添加进货信息失败!"), MB_ICONEXCLAMATION);
else AfxMessageBox(_T("修改进货信息失败!"), MB_ICONEXCLAMATION);
}
strQuery = "select * from sstock";
CTrade_MISView* p = (CTrade_MISView*)(((CMainFrame*)AfxGetMainWnd())->GetActiveView());
p->RefreshStock(strQuery);
if (!m_bAppend) CDialog::OnOK();
//CDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -