📄 dstore.cpp
字号:
// DStore.cpp : implementation file
//
#include "stdafx.h"
#include "商品库存管理系统.h"
#include "DStore.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr cnn;
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDStore dialog
CDStore::CDStore(CWnd* pParent /*=NULL*/)
: CDialog(CDStore::IDD, pParent)
{
//{{AFX_DATA_INIT(CDStore)
//}}AFX_DATA_INIT
m_Record=1;
}
void CDStore::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDStore)
DDX_Control(pDX, IDC_BUT_UNDO, m_ButUndo);
DDX_Control(pDX, IDC_EDTSNAME, m_EdtSName);
DDX_Control(pDX, IDC_EDTName, m_EdtName);
DDX_Control(pDX, IDC_EdtID, m_EdtID);
DDX_Control(pDX, IDC_BUT_SAVE, m_ButSave);
DDX_Control(pDX, IDC_BUT_PIV, m_ButPiv);
DDX_Control(pDX, IDC_BUT_NEXT, m_ButNext);
DDX_Control(pDX, IDC_BUT_EXIT, m_ButExit);
DDX_Control(pDX, IDC_BUT_DELE, m_ButDele);
DDX_Control(pDX, IDC_BUT_CHANGE, m_ButChange);
DDX_Control(pDX, IDC_BUT_ADD, m_ButAdd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDStore, CDialog)
//{{AFX_MSG_MAP(CDStore)
ON_BN_CLICKED(IDC_BUT_PIV, OnButPiv)
ON_BN_CLICKED(IDC_BUT_NEXT, OnButNext)
ON_BN_CLICKED(IDC_BUT_EXIT, OnButExit)
ON_BN_CLICKED(IDC_BUT_ADD, OnButAdd)
ON_EN_CHANGE(IDC_EDTName, OnChangeEDTName)
ON_BN_CLICKED(IDC_BUT_CHANGE, OnButChange)
ON_BN_CLICKED(IDC_BUT_DELE, OnButDele)
ON_BN_CLICKED(IDC_BUT_SAVE, OnButSave)
ON_BN_CLICKED(IDC_BUT_UNDO, OnButUndo)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDStore message handlers
void CDStore::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
void CDStore::Clear()
{
m_EdtSName.SetWindowText("");
m_EdtName.SetWindowText("");
m_EdtID.SetWindowText("");
}
void CDStore::Display(int nID)
{
CString sID;
sID.Format("%d",nID);
_RecordsetPtr drst;
drst.CreateInstance(__uuidof(Recordset));
if(sID.IsEmpty())
return;
CString sSQL,sName,sSName;
_variant_t _name,_sname;
sSQL.Format("SELECT * FROM 仓库信息表 WHERE 编号=%s",sID);
drst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(drst->_EOF)
{
m_Record=0;
return;
}
_name=drst->GetCollect("名称");
if(_name.vt==VT_EMPTY||_name.vt==VT_NULL)
sName="";
else
sName=(char*)(_bstr_t)_name;
_sname=drst->GetCollect("简称");
if(_sname.vt==VT_EMPTY||_sname.vt==VT_NULL)
sSName="";
else
sSName=(char*)(_bstr_t)_sname;
this->m_EdtID.SetWindowText(sID);
this->m_EdtName.SetWindowText(sName);
this->m_EdtSName.SetWindowText(sSName);
}
void CDStore::Enabled(bool bEnabled)
{
m_EdtSName.EnableWindow(bEnabled);
m_EdtName.EnableWindow(bEnabled);
m_ButSave.EnableWindow(bEnabled);
m_ButPiv.EnableWindow(!bEnabled);
m_ButNext.EnableWindow(!bEnabled);
m_ButExit.EnableWindow(!bEnabled);
m_ButDele.EnableWindow(!bEnabled);
m_ButChange.EnableWindow(!bEnabled);
m_ButAdd.EnableWindow(!bEnabled);
m_ButUndo.EnableWindow(bEnabled);
}
BOOL CDStore::OnInitDialog()
{
CDialog::OnInitDialog();
Display(m_Record);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDStore::OnButPiv()
{
if(m_Record-1>0)
m_Record=m_Record-1;
Display(m_Record);
}
void CDStore::OnButNext()
{
m_Record=m_Record+1;
Display(m_Record);
}
void CDStore::OnButExit()
{
this->OnCancel();
}
void CDStore::OnButAdd()
{
int nNewID=theApp.AutoNumber(0,"仓库信息表");
CString sNewID;
sNewID.Format("%d",nNewID);
AddOrChange=1;
this->Enabled(true);
this->Clear();
m_EdtID.SetWindowText(sNewID);
m_EdtName.SetFocus();
}
void CDStore::OnChangeEDTName()
{
CString sName,sSName;
m_EdtName.GetWindowText(sName);
sSName=theApp.CharToLetterCode(sName);
m_EdtSName.SetWindowText(sSName);
}
void CDStore::OnButChange()
{
AddOrChange=2;
this->Enabled(true);
m_EdtName.SetFocus();
}
void CDStore::OnButDele()
{
if(MessageBox("确定要删除此条记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
return;
CString sSQL,sID;
this->m_EdtID.GetWindowText(sID);
sSQL.Format("DELETE FROM 仓库信息表 WHERE 编号=%s",sID);
cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->Display(1);
}
void CDStore::OnButSave()
{
if(MessageBox("确定要保存记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
return;
CString sSQL,sID,sName,sSName;
m_EdtID.GetWindowText(sID);
m_EdtName.GetWindowText(sName);
m_EdtSName.GetWindowText(sSName);
if(sName.IsEmpty() || sSName.IsEmpty())
{
MessageBox("您输入的数据不完整!","系统提示",MB_OK|MB_ICONSTOP);
return;
}
if(AddOrChange==1)
sSQL.Format("INSERT INTO 仓库信息表 VALUES(%s,'%s','%s')",sID,sName,sSName);
else
sSQL.Format("UPDATE 仓库信息表 SET 名称='%s' , 简称='%s' WHERE 编号=%s",sName,sSName,sID);
cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->Enabled(false);
m_ButAdd.SetFocus();
}
void CDStore::OnButUndo()
{
if(MessageBox("确定要撤消操作吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION)!=1)
return;
Clear();
Display(1);
this->Enabled(false);
m_ButAdd.SetFocus();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -