📄 proeditdlg.cpp
字号:
// ProEditDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SuperMarket.h"
#include "ProEditDlg.h"
#include "Product.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CProEditDlg dialog
CProEditDlg::CProEditDlg(CWnd* pParent /*=NULL*/)
: CDialog(CProEditDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CProEditDlg)
m_Pname = _T("");
m_Alarm = 0;
m_Pprice = 0.0f;
m_Pstyle = _T("");
m_Ptype = _T("");
m_Punit = _T("");
m_Valid = 0;
m_Plow = 0;
m_Phigh = 0;
m_Pid = 0;
DoType=0;
m_Pstore = _T("");
//}}AFX_DATA_INIT
}
void CProEditDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CProEditDlg)
DDX_Text(pDX, IDC_PNAME_EDIT, m_Pname);
DDX_Text(pDX, IDC_ALARM_EDIT, m_Alarm);
DDX_Text(pDX, IDC_PPRICE_EDIT, m_Pprice);
DDX_Text(pDX, IDC_PSTYLE_EDIT, m_Pstyle);
DDX_Text(pDX, IDC_PTYPE_STATIC, m_Ptype);
DDX_Text(pDX, IDC_PUNIT_EDIT, m_Punit);
DDX_Text(pDX, IDC_VALID_EDIT, m_Valid);
DDX_Text(pDX, IDC_PLOW_EDIT, m_Plow);
DDX_Text(pDX, IDC_PHIGH_EDIT, m_Phigh);
DDX_Control(pDX, IDC_ADODC1, m_ado);
DDX_Text(pDX, IDC_PID_EDIT, m_Pid);
DDX_Text(pDX, IDC_PSTORE_EDIT, m_Pstore);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CProEditDlg, CDialog)
//{{AFX_MSG_MAP(CProEditDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CProEditDlg message handlers
void CProEditDlg::OnOK()
{
// TODO: Add extra validation here
UpdateData(true); //将数据读取到成员变量
/* if (m_Pname == "")
{
MessageBox("请输入产品名称");
return;
}
CProduct pr;
pr.SetPname(m_Pname); //产品名称
pr.SetTypeId(iTypeId); //产品类别
pr.SetPprice(m_Pprice); //参考价格
pr.SetPstyle(m_Pstyle); //产品规格
pr.SetPunit(m_Punit); //计量单位
pr.SetPlow(m_Plow); //数量下限
pr.SetPhigh(m_Phigh); //数量上限
pr.SetValid(m_Valid); //有效期
pr.SetAlarmDays(m_Alarm); //警告期
if (cPid == "") //表示插入记录
if (pr.HaveName(m_Pname) == 1)
{
MessageBox("当前产品名称已经存在,请重新输入");
return;
}
else
pr.sql_insert();
else
if (m_Pname != cPname && pr.HaveName(m_Pname) == 1)
{
MessageBox("当前产品名称已经存在,请重新输入");
return;
}
else
pr.sql_update(cPid);
*/
if(DoType==1)
{
m_pRecordset.CreateInstance(__uuidof(Recordset));
OpenProduct();
_variant_t var;
CString str;
try
{
m_pRecordset->AddNew();
var.iVal=m_Pid;
m_pRecordset->PutCollect("Pid",var.iVal);
m_pRecordset->PutCollect("Pname",_variant_t(m_Pname));
m_pRecordset->PutCollect("Pstyle",_variant_t(m_Pstyle));
m_pRecordset->PutCollect("Punit",_variant_t(m_Punit));
var.fltVal=m_Pprice;
m_pRecordset->PutCollect("Pprice",var.fltVal);
var.iVal=m_Phigh;
m_pRecordset->PutCollect("Phigh",var.iVal);
var.iVal=m_Plow;
m_pRecordset->PutCollect("Plow",var.iVal);
var.iVal=m_Alarm;
m_pRecordset->PutCollect("AlarmDays",var.iVal);
//var.iVal=m_Pstore;
// m_pRecordset->PutCollect("Pstore",_variant_t(m_Pstore));
var.iVal=iTypeId;
m_pRecordset->PutCollect("TypeID",var.iVal);
var.iVal=m_Valid;
m_pRecordset->PutCollect("Valid",var.iVal);
m_pRecordset->Update();
m_pRecordset->MoveLast();
AfxMessageBox("插入成功");
}
catch(_com_error*e)
{
AfxMessageBox(e->ErrorMessage());
}
}
CDialog::OnOK();
}
void CProEditDlg::OpenProduct()
{
try
{
//从SQL数据库中打开Users表
m_pRecordset->Open("SELECT*FROM Product",
theApp.m_pConnection.GetInterfacePtr(),
adOpenDynamic,
adLockOptimistic,
adCmdText);
}
catch(_com_error*e)
{
AfxMessageBox(e->ErrorMessage());
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -