📄 dware_edit.cpp
字号:
// DWare_Edit.cpp : implementation file
//
#include "stdafx.h"
#include "商品库存管理系统.h"
#include "DWare_Edit.h"
#include "DClime.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr cnn;
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDWare_Edit dialog
CDWare_Edit::CDWare_Edit(CWnd* pParent /*=NULL*/)
: CDialog(CDWare_Edit::IDD, pParent)
{
//{{AFX_DATA_INIT(CDWare_Edit)
//}}AFX_DATA_INIT
}
void CDWare_Edit::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDWare_Edit)
DDX_Control(pDX, IDC_COMTown, m_ComTown);
DDX_Control(pDX, IDC_EdtSpec, m_EdtSpec);
DDX_Control(pDX, IDC_EdtName2, m_EdtName);
DDX_Control(pDX, IDC_EDTLetterName, m_EdtLetterName);
DDX_Control(pDX, IDC_EdtID, m_EdtID);
DDX_Control(pDX, IDC_DATOutFactoryTime, m_DatOutFactoryTime);
DDX_Control(pDX, IDC_DATKeepTime, m_DatKeepTime);
DDX_Control(pDX, IDC_COMUnit, m_ComUnit);
DDX_Control(pDX, IDC_COMProvince, m_ComProvince);
DDX_Control(pDX, IDC_COMCity, m_ComCity);
DDX_Control(pDX, IDC_BUTUndo, m_ButUndo);
DDX_Control(pDX, IDC_BUTSave, m_ButSave);
DDX_Control(pDX, IDC_BUTExit, m_ButExit);
DDX_Control(pDX, IDC_BUTDele, m_ButDele);
DDX_Control(pDX, IDC_BUTChange, m_ButChange);
DDX_Control(pDX, IDC_BUTAdd, m_ButAdd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDWare_Edit, CDialog)
//{{AFX_MSG_MAP(CDWare_Edit)
ON_BN_CLICKED(IDC_BUTAdd, OnBUTAdd)
ON_EN_CHANGE(IDC_EdtName2, OnChangeEdtName)
ON_CBN_KILLFOCUS(IDC_COMProvince, OnKillfocusCOMProvince)
ON_CBN_KILLFOCUS(IDC_COMCity, OnKillfocusCOMCity)
ON_BN_CLICKED(IDC_BUTChange, OnBUTChange)
ON_BN_CLICKED(IDC_BUTDele, OnBUTDele)
ON_BN_CLICKED(IDC_BUTSave, OnBUTSave)
ON_BN_CLICKED(IDC_BUTUndo, OnBUTUndo)
ON_BN_CLICKED(IDC_BUTExit, OnBUTExit)
ON_NOTIFY(NM_KILLFOCUS, IDC_DATKeepTime, OnKillfocusDATKeepTime)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDWare_Edit message handlers
void CDWare_Edit::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
BOOL CDWare_Edit::OnInitDialog()
{
CString sSQL;
CDialog::OnInitDialog();
//设置图标
m_hIcon=::LoadIcon(::AfxGetResourceHandle(),MAKEINTRESOURCE(IDI_ICON1));
this->SetIcon(m_hIcon,true);
rst.CreateInstance(__uuidof(Recordset));
sSQL.Format("SELECT* From 地域信息表 WHERE 上级编号=0");
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->m_ComProvince.SetRecordset(rst,"名称");
rst->Close();
sSQL.Format("SELECT* From 地域信息表 WHERE 上级编号=1");
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->m_ComCity.SetRecordset(rst,"名称");
rst->Close();
sSQL.Format("SELECT* From 地域信息表 WHERE 上级编号=2");
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->m_ComTown.SetRecordset(rst,"名称");
rst->Close();
rst=cnn->Execute(L"计量单位表",NULL,adCmdTable);
this->m_ComUnit.SetRecordset(rst,"名称");
rst->Close();
this->Display(this->DisplayNumber);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDWare_Edit::Display(CString ID)
{
CString sID,sName,SLatterName,sSpec,sUnit,sProducing,sOutfactoryTime,sKeepTime;
CString sSQL;
sSQL.Format("Select * from 商品信息查询 Where 编号='%s'",ID);
try{
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
}
catch(...)
{
theApp.ADOError(rst);
return;
}
if(theApp.GetRecordCount(rst)>0)
{
rst->MoveFirst();
CTime OutfactoryTime,KeepTime;
sID=(char*)(_bstr_t)rst->GetCollect("编号");
sName=(char*)(_bstr_t)rst->GetCollect("名称");
SLatterName=(char*)(_bstr_t)rst->GetCollect("简称");
sSpec=(char*)(_bstr_t)rst->GetCollect("规格");
sUnit=(char*)(_bstr_t)rst->GetCollect("计量单位");
sProducing=(char*)(_bstr_t)rst->GetCollect("产地");
int pos=sProducing.Find("市",0);
CString sCD=sProducing.Mid(pos+2);
sProducing=sCD.Mid(0,sCD.GetLength()-2);
sOutfactoryTime=(char*)(_bstr_t)rst->GetCollect("出厂日期");
sKeepTime=(char*)(_bstr_t)rst->GetCollect("保质期");
m_EdtID.SetWindowText(sID);
this->m_EdtLetterName.SetWindowText(SLatterName);
this->m_EdtName.SetWindowText(sName);
this->m_EdtSpec.SetWindowText(sSpec);
this->m_ComUnit.SetWindowText(sUnit);
OutfactoryTime=theApp.CStringTOCTime(sOutfactoryTime);
KeepTime=theApp.CStringTOCTime(sKeepTime);
this->m_DatOutFactoryTime.SetTime(&OutfactoryTime);
this->m_DatKeepTime.SetTime(&KeepTime);
int nProducing=theApp.NumberTOName("地域信息表","名称",sProducing);
Clime(nProducing);
}
rst->Close();
}
int CDWare_Edit::Clime(int Number)
{
_RecordsetPtr ClimeRst;
ClimeRst.CreateInstance(__uuidof(Recordset));
CString sSQL,Style,Name,ParentID;
int ReturnNumber;
sSQL.Format("Select * from 地域信息表 Where 编号=%d",Number);
ClimeRst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(theApp.GetRecordCount(ClimeRst)>0)
{
ClimeRst->MoveFirst();
Style=(char*)(_bstr_t)ClimeRst->GetCollect("类型");
Name=(char*)(_bstr_t)ClimeRst->GetCollect("名称");
ParentID=(char*)(_bstr_t)ClimeRst->GetCollect("上级编号");
if(Style=="3")
this->m_ComTown.SetWindowText(Name);
if(Style=="2")
this->m_ComCity.SetWindowText(Name);
if(Style=="1")
this->m_ComProvince.SetWindowText(Name);
if(ParentID!="0")
{
ReturnNumber=atoi(ParentID);
this->Clime(ReturnNumber);
}
else
{
ReturnNumber=0;
}
}
return ReturnNumber;
}
void CDWare_Edit::Enabled(bool bEnabled)
{
m_ComTown.EnableWindow(bEnabled);
m_EdtSpec.EnableWindow(bEnabled);
m_EdtName.EnableWindow(bEnabled);
m_EdtLetterName.EnableWindow(bEnabled);
m_DatOutFactoryTime.EnableWindow(bEnabled);
m_DatKeepTime.EnableWindow(bEnabled);
m_ComUnit.EnableWindow(bEnabled);
m_ComProvince.EnableWindow(bEnabled);
m_ComCity.EnableWindow(bEnabled);
m_ButUndo.EnableWindow(bEnabled);
m_ButSave.EnableWindow(bEnabled);
m_ButExit.EnableWindow(!bEnabled);
m_ButDele.EnableWindow(!bEnabled);
m_ButChange.EnableWindow(!bEnabled);
m_ButAdd.EnableWindow(!bEnabled);
}
void CDWare_Edit::OnBUTAdd()
{
CString NewID;
Enabled(true);
ClearFrom();
NewID=theApp.AutoNumber("商品信息表","SP",1);
this->m_EdtID.SetWindowText(NewID);
m_EdtName.SetFocus();
AddOrChange=true;
}
void CDWare_Edit::ClearFrom()
{
CTime CurrentTime;
m_EdtID.SetWindowText("");
CurrentTime=CurrentTime.GetCurrentTime();
m_EdtName.SetWindowText("");
m_ComTown.SetWindowText("");
m_EdtSpec.SetWindowText("");
m_EdtName.SetWindowText("");
m_EdtLetterName.SetWindowText("");
m_DatOutFactoryTime.SetTime(&CurrentTime);
m_DatKeepTime.SetTime(&CurrentTime);
m_ComUnit.SetWindowText("");
m_ComProvince.SetWindowText("");
m_ComCity.SetWindowText("");
}
void CDWare_Edit::OnChangeEdtName()
{
CString sName,sLaterName;
m_EdtName.GetWindowText(sName);
sLaterName=theApp.CharToLetterCode(sName);
this->m_EdtLetterName.SetWindowText(sLaterName);
}
void CDWare_Edit::OnKillfocusCOMProvince()
{
int ID;
CString sClime,sSQL;
m_ComProvince.GetWindowText(sClime);
ID=theApp.NumberTOName("地域信息表","名称",sClime);
if(ID<=0)
{
int a=MessageBox("您输入的省份并没有登记!请先在地域管理模块中登记!进入地域管理模块吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
if(a==1)
{
CDClime dlg;
dlg.DoModal();
}
else
{
m_ComProvince.SetWindowText("");
m_ComProvince.SetFocus();
}
}
else
{
sSQL.Format("SELECT* From 地域信息表 WHERE 上级编号=%d",ID);
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->m_ComCity.ResetContent();
this->m_ComCity.SetRecordset(rst,"名称");
rst->Close();
}
}
void CDWare_Edit::OnKillfocusCOMCity()
{
int ID;
CString sClime,sSQL;
m_ComCity.GetWindowText(sClime);
ID=theApp.NumberTOName("地域信息表","名称",sClime);
if(ID<=0)
{
int a=MessageBox("您输入的城市并没有登记!请先在地域管理模块中登记!进入地域管理模块吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
if(a==1)
{
CDClime dlg;
dlg.DoModal();
}
else
{
m_ComCity.SetWindowText("");
m_ComCity.SetFocus();
}
}
else
{
sSQL.Format("SELECT* From 地域信息表 WHERE 上级编号=%d",ID);
rst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->m_ComTown.ResetContent();
this->m_ComTown.SetRecordset(rst,"名称");
rst->Close();
}
}
void CDWare_Edit::OnBUTChange()
{
Enabled(true);
m_EdtName.SetFocus();
AddOrChange=false;
}
void CDWare_Edit::OnBUTDele()
{
CString ID,sSQL;
this->m_EdtID.GetWindowText(ID);
if(ID.IsEmpty()==false)
{
int a=MessageBox("确定要删除此条记录吗?","系统提示",MB_OKCANCEL|MB_ICONQUESTION);
if (a==1)
{
CString sSQL;
sSQL.Format("DELETE FROM 商品信息表 WHERE 编号='%s'",ID);
try{
cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
}
catch(...)
{
MessageBox("记录删除失败!仓库中存在着此商品信息!","系统提示",MB_OK|MB_ICONSTOP);
return;
}
this->Enabled(false);
this->ClearFrom();
}
}
else
{
MessageBox("请选择一条记录!","系统提示",MB_OK|MB_ICONSTOP);
}
}
void CDWare_Edit::OnBUTSave()
{
int a=MessageBox("确定保存记录吗?","系统提示",MB_ICONQUESTION|MB_OKCANCEL);
if(a==1)
{
CTime time;
CString sID,sSQL,sName,sLetterName,sUnit,sSpec,sTown,sOutFauctryTime,sKeepTime;
int nUnit,nTown;
m_EdtID.GetWindowText(sID);
m_EdtLetterName.GetWindowText(sLetterName);
m_DatOutFactoryTime.GetTime(time);
sOutFauctryTime=theApp.CTimeToCString(time);
m_DatKeepTime.GetTime(time);
sKeepTime=theApp.CTimeToCString(time);
m_EdtName.GetWindowText(sName);
if(sName.IsEmpty())
{
MessageBox("请输入商品名称!","系统提示",MB_OK|MB_ICONSTOP);
m_EdtName.SetFocus();
return;
}
m_EdtSpec.GetWindowText(sSpec);
if(sSpec.IsEmpty())
{
MessageBox("请输入商品规格!","系统提示",MB_OK|MB_ICONSTOP);
m_EdtSpec.SetFocus();
return;
}
m_ComUnit.GetWindowText(sUnit);
nUnit=theApp.NumberTOName("计量单位表","名称",sUnit);
if(sUnit.IsEmpty())
{
MessageBox("请输入计量单位!","系统提示",MB_OK|MB_ICONSTOP);
m_ComUnit.SetFocus();
return;
}
m_ComTown.GetWindowText(sTown);
nTown=theApp.NumberTOName("地域信息表","名称",sTown);
if(sTown.IsEmpty())
{
MessageBox("请输入产地!","系统提示",MB_OK|MB_ICONSTOP);
m_ComTown.SetFocus();
return;
}
if(this->AddOrChange==true)// 如果执行添加操作
sSQL.Format("Insert Into 商品信息表 values ('%s','%s','%s','%s',%d,%d,#%s#,#%s#)",sID,sName,sLetterName,sSpec,nTown,nUnit,sOutFauctryTime,sKeepTime);
else
sSQL.Format("UPDATE 商品信息表 SET 名称='%s',简称='%s',规格='%s',产地=%d,计量单位=%d,出厂日期=#%s#,保质期=#%s# WHERE 编号='%s'",sName,sLetterName,sSpec,nTown,nUnit,sOutFauctryTime,sKeepTime,sID);
cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->Enabled(false);
}
}
void CDWare_Edit::OnBUTUndo()
{
this->Display(this->DisplayNumber);
this->Enabled(false);
}
void CDWare_Edit::OnBUTExit()
{
this->OnCancel();
}
void CDWare_Edit::OnKillfocusDATKeepTime(NMHDR* pNMHDR, LRESULT* pResult)
{
CTime KeepTime,OutFactoryTime;
this->m_DatKeepTime.GetTime(KeepTime);
this->m_DatOutFactoryTime.GetTime(OutFactoryTime);
if(OutFactoryTime>KeepTime)
{
MessageBox("您输入的保质期有误!","系统提示",MB_OK|MB_ICONSTOP);
this->m_DatKeepTime.SetFocus();
}
*pResult = 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -