📄 supplys.cpp
字号:
// Supply.cpp : implementation file
//
#include "stdafx.h"
#include "aoManage.h"
#include "SupplyS.h"
#include "MainFrm.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CSupplyS dialog
CSupplyS::CSupplyS(CWnd* pParent /*=NULL*/)
: CParentDlg(CSupplyS::IDD, pParent)
{
//{{AFX_DATA_INIT(CSupplyS)
m_strSName = _T("");
m_strCClass = _T("");
m_strCity = _T("");
m_strSCode = _T("");
m_strContact = _T("");
m_strTele = _T("");
m_strFax = _T("");
m_strDemo = _T("");
m_strAddress = _T("");
m_strPostcode = _T("");
m_strMobile = _T("");
//}}AFX_DATA_INIT
m_pSupply=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
m_pCClass=new CDaoRecordset(&((CMainFrame*)AfxGetMainWnd())->m_db);
}
void CSupplyS::DoDataExchange(CDataExchange* pDX)
{
CParentDlg::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSupplyS)
DDX_Control(pDX, IDC_COMBO1, m_ctlCbCClass);
DDX_Control(pDX, IDC_COMBO2, m_ctlCbCity);
DDX_Text(pDX, IDC_EDIT1, m_strSName);
DDX_CBString(pDX, IDC_COMBO1, m_strCClass);
DDX_CBString(pDX, IDC_COMBO2, m_strCity);
DDX_Text(pDX, IDC_EDIT2, m_strSCode);
DDX_Text(pDX, IDC_EDIT3, m_strContact);
DDX_Text(pDX, IDC_EDIT4, m_strTele);
DDX_Text(pDX, IDC_EDIT5, m_strFax);
DDX_Text(pDX, IDC_EDIT9, m_strDemo);
DDX_Text(pDX, IDC_EDIT6, m_strAddress);
DDX_Text(pDX, IDC_EDIT7, m_strPostcode);
DDX_Text(pDX, IDC_EDIT8, m_strMobile);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSupplyS, CParentDlg)
//{{AFX_MSG_MAP(CSupplyS)
ON_BN_CLICKED(IDC_BUTTON3, OnButton3)
ON_BN_CLICKED(IDC_BUTTON4, OnButton4)
ON_WM_CLOSE()
ON_CBN_KILLFOCUS(IDC_COMBO2, OnKillfocusCombo2)
ON_BN_CLICKED(IDC_BUTTON8, OnButton8)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSupplyS message handlers
BOOL CSupplyS::OnInitDialog()
{
CParentDlg::OnInitDialog();
m_pSupply->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from supply");
m_pCClass->Open(AFX_DAO_USE_DEFAULT_TYPE,"select * from cclass");
COleVariant vCode,vName;
CString strTemp;
while (!m_pCClass->IsEOF())
{
m_pCClass->GetFieldValue("code",vCode);
m_pCClass->GetFieldValue("name",vName);
strTemp=(LPCTSTR)vCode.bstrVal;
strTemp+=" ";
strTemp+=(LPCTSTR)vName.bstrVal;
m_ctlCbCClass.AddString(strTemp);
m_pCClass->MoveNext();
}
m_ctlCbCity.AddString("01 苏州");
m_ctlCbCity.AddString("02 江苏(除苏州)");
m_ctlCbCity.AddString("03 浙江");
m_ctlCbCity.AddString("04 其它");
m_pSupply->FindFirst("scode='"+m_strSCode+"'");
COleVariant vVal;
m_pSupply->GetFieldValue("sname",vVal);
m_strSName=(LPCTSTR)vVal.bstrVal;
m_pSupply->GetFieldValue("contact",vVal);
m_strContact=(LPCTSTR)vVal.bstrVal;
m_pSupply->GetFieldValue("tele",vVal);
m_strTele=(LPCTSTR)vVal.bstrVal;
m_pSupply->GetFieldValue("fax",vVal);
m_strFax=(LPCTSTR)vVal.bstrVal;
m_pSupply->GetFieldValue("postcode",vVal);
m_strPostcode=(LPCTSTR)vVal.bstrVal;
m_pSupply->GetFieldValue("demo",vVal);
m_strDemo=(LPCTSTR)vVal.bstrVal;
m_pSupply->GetFieldValue("address",vVal);
m_strAddress=(LPCTSTR)vVal.bstrVal;
m_pSupply->GetFieldValue("mobile",vVal);
m_strMobile=(LPCTSTR)vVal.bstrVal;
m_strCClass=m_strSCode.Left(4).Right(2);
m_strCity=m_strSCode.Left(2);
UpdateData(FALSE);
m_strCodeOld=m_strSCode;
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CSupplyS::OnButton3()
{
if (MessageBox("确实要修改吗?",NULL,MB_OKCANCEL)==IDCANCEL)
return;
UpdateData(TRUE);
if (!m_strSName.GetLength()||!m_strSCode.GetLength()||!m_strContact.GetLength())
{
MessageBox("厂名,厂代码或联系人不能为空,请重新输入");
return;
}
if (strcmp(m_strSCode,m_strCodeOld))
{
if (m_pSupply->FindFirst("scode='"+m_strSCode+"'"))
{
MessageBox("此厂家已存在,请重新输入");
return;
}
else
m_pSupply->FindFirst("scode='"+m_strCodeOld+"'");
}
m_pSupply->Edit();
m_pSupply->SetFieldValue("sname",(LPCTSTR)m_strSName);
m_pSupply->SetFieldValue("scode",(LPCTSTR)m_strSCode);
m_pSupply->SetFieldValue("contact",(LPCTSTR)m_strContact);
m_pSupply->SetFieldValue("tele",(LPCTSTR)m_strTele);
m_pSupply->SetFieldValue("fax",(LPCTSTR)m_strFax);
m_pSupply->SetFieldValue("mobile",(LPCTSTR)m_strMobile);
m_pSupply->SetFieldValue("address",(LPCTSTR)m_strAddress);
m_pSupply->SetFieldValue("postcode",(LPCTSTR)m_strPostcode);
m_pSupply->SetFieldValue("demo",(LPCTSTR)m_strDemo);
m_pSupply->Update();
MessageBox("记录已成功修改");
OnOK();
}
void CSupplyS::OnButton4()
{
OnCancel();
}
void CSupplyS::OnClose()
{
if (m_pSupply->IsOpen())
m_pSupply->Close();
if (m_pCClass->IsOpen())
m_pCClass->Close();
CParentDlg::OnClose();
}
void CSupplyS::OnKillfocusCombo2()
{
UpdateData(TRUE);
if (m_strCClass.GetLength()&&m_strCity.GetLength())
{
CString strFltr=m_strCity.Left(2)+m_strCClass.Left(2);
strFltr+="??\?";
strFltr="scode like '"+strFltr+"'";
if (m_pSupply->FindLast(strFltr))
{
COleVariant vVar;
m_pSupply->GetFieldValue("scode",vVar);
m_strSCode=(LPCTSTR)vVar.bstrVal;
m_strSCode.Format("%03d",atoi(m_strSCode.Right(3))+1);
}
else
m_strSCode="001";
m_strSCode=m_strCity.Left(2)+m_strCClass.Left(2)+m_strSCode;
}
else
m_strSCode="";
UpdateData(FALSE);
}
void CSupplyS::OnButton8()
{
if (MessageBox("确实要删除吗?",NULL,MB_OKCANCEL)==IDOK)
{
m_pSupply->Delete();
MessageBox("记录已成功删除");
OnOK();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -