VC++6.0商品库存管理信息系统源代码
本论文站仅贴出部分代码,需要全部代码的请联系站长QQ,谢谢
// DUser.cpp : implementation file
//
#include "stdafx.h"
#include "商品库存管理系统.h"
#include "DUser.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern _ConnectionPtr cnn;
extern CMyApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CDUser dialog
CDUser::CDUser(CWnd* pParent /*=NULL*/)
: CDialog(CDUser::IDD, pParent)
{
//{{AFX_DATA_INIT(CDUser)
//}}AFX_DATA_INIT
}
void CDUser::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CDUser)
DDX_Control(pDX, IDC_LIST1, m_List);
DDX_Control(pDX, IDC_EDTPassward, m_EdtPassWard);
DDX_Control(pDX, IDC_EdtName2, m_EdtName);
DDX_Control(pDX, IDC_EdtID, m_EdtID);
DDX_Control(pDX, IDC_EDTAffirmPsd, m_EdtAffirmPsd);
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_BueDele);
DDX_Control(pDX, IDC_BUTChange, m_ButChange);
DDX_Control(pDX, IDC_BUTAdd, m_ButAdd);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CDUser, CDialog)
//{{AFX_MSG_MAP(CDUser)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList)
ON_BN_CLICKED(IDC_BUTAdd, OnBUTAdd)
ON_BN_CLICKED(IDC_BUTChange, OnBUTChange)
ON_BN_CLICKED(IDC_BUTDele, OnBUTDele)
ON_BN_CLICKED(IDC_BUTUndo, OnBUTUndo)
ON_BN_CLICKED(IDC_BUTSave, OnBUTSave)
ON_BN_CLICKED(IDC_BUTExit, OnBUTExit)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CDUser message handlers
void CDUser::OnOK()
{
// TODO: Add extra validation here
//CDialog::OnOK();
}
BOOL CDUser::OnInitDialog()
{
CDialog::OnInitDialog();
rst.CreateInstance((__uuidof(Recordset)));
rst=cnn->Execute(L"用户信息表",NULL,adCmdTable);
if(theApp.GetRecordCount(rst)>0)
{
m_List.SetRecordset(rst,"用户名");
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CDUser::Display(CString sFieldvalue)
{
if(sFieldvalue.IsEmpty())
return;
CString sSQL,sID,sPassWard;
_RecordsetPtr DispRst;
DispRst.CreateInstance(__uuidof(Recordset));
sSQL.Format("SELECT * FROM 用户信息表 WHERE 用户名='%s'",sFieldvalue);
DispRst=cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
if(theApp.GetRecordCount(DispRst)>0)
{
DispRst->MoveFirst();
sID=((char*)(_bstr_t)DispRst->GetCollect("编号"));
_variant_t psd=DispRst->GetCollect("密码");
if(psd.vt==VT_EMPTY)
sPassWard="";
else
sPassWard=(char*)(_bstr_t)psd;
}
m_EdtID.SetWindowText(sID);
m_EdtName.SetWindowText(sFieldvalue);
m_EdtPassWard.SetWindowText(sPassWard);
m_EdtAffirmPsd.SetWindowText(sPassWard);
}
void CDUser::OnSelchangeList()
{
CString sName;
m_List.GetText(m_List.GetCurSel(),sName);
this->Display(sName);
}
void CDUser::Enabled(bool bEnabled)
{
m_List.EnableWindow(!bEnabled);
m_EdtPassWard.EnableWindow(bEnabled);
m_EdtName.EnableWindow(bEnabled);
m_EdtAffirmPsd.EnableWindow(bEnabled);
m_ButUndo.EnableWindow(bEnabled);
m_ButSave.EnableWindow(bEnabled);
m_ButExit.EnableWindow(!bEnabled);
m_BueDele.EnableWindow(!bEnabled);
m_ButChange.EnableWindow(!bEnabled);
m_ButAdd.EnableWindow(!bEnabled);
}
void CDUser::ClearFrom()
{
m_EdtID.SetWindowText("");
m_EdtPassWard.SetWindowText("");
m_EdtName.SetWindowText("");
m_EdtAffirmPsd.SetWindowText("");
}
void CDUser::OnBUTAdd()
{
CString sNewID;
this->ClearFrom();
int nNewID=theApp.AutoNumber(0,"用户信息表");
sNewID.Format("%d",nNewID);
m_EdtID.SetWindowText(sNewID);
this->Enabled(true);
this->m_EdtName.SetFocus();
this->AddOrChange=true;
}
void CDUser::OnBUTChange()
{
this->Enabled(true);
this->m_EdtName.SetFocus();
this->AddOrChange=false;
}
void CDUser::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();
this->m_List.UpDating();
}
}
else
{
MessageBox("请选择一条记录!","系统提示",MB_OK|MB_ICONSTOP);
}
}
void CDUser::OnBUTUndo()
{
CString sName;
this->ClearFrom();
if(sName.IsEmpty())
goto end;
m_List.GetText(m_List.GetCurSel(),sName);
this->Display(sName);
end: this->Enabled(false);
}
void CDUser::OnBUTSave()
{
int a=MessageBox("确定保存记录吗?","系统提示",MB_ICONQUESTION|MB_OKCANCEL);
if(a==1)
{
CString sSQL,sID,sName,sPassWard,sAffirmPsd;
m_EdtID.GetWindowText(sID);
m_EdtName.GetWindowText(sName);
m_EdtPassWard.GetWindowText(sPassWard);
m_EdtAffirmPsd.GetWindowText(sAffirmPsd);
if(sPassWard!=sAffirmPsd)
{
MessageBox("两次输入的密码不一致!","系统提示",MB_OK|MB_ICONSTOP);
m_EdtAffirmPsd.SetWindowText("");
m_EdtAffirmPsd.SetFocus();
return;
}
if(sName.IsEmpty())
{
MessageBox("用户名不允许为空!","系统提示",MB_OK|MB_ICONSTOP);
m_EdtName.SetFocus();
return;
}
if(this->AddOrChange==true)// 如果执行添加操作
sSQL.Format("Insert Into 用户信息表 values (%s,'%s','%s')",sID,sName,sPassWard);
else
sSQL.Format("UPDATE 用户信息表 SET 用户名='%s',密码='%s'WHERE 编号=%s",sName,sPassWard,sID);
cnn->Execute((_bstr_t)sSQL,NULL,adCmdText);
this->Enabled(false);
this->m_List.UpDating();
this->OnCancel();
}
}
void CDUser::OnBUTExit()
{
this->OnCancel();
}