?? addstoredlg.cpp
字號:
// AddStoreDlg.cpp : implementation file
//
#include "stdafx.h"
#include "SuperMarket.h"
#include "AddStoreDlg.h"
#include "afxdb.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CAddStoreDlg dialog
CAddStoreDlg::CAddStoreDlg(CWnd* pParent /*=NULL*/)
: CDialog(CAddStoreDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CAddStoreDlg)
m_spaddress = _T("");
m_spname = _T("");
m_spnumber = _T("");
m_spprice = 0.0f;
m_spcount = 1;
//}}AFX_DATA_INIT
}
void CAddStoreDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CAddStoreDlg)
DDX_Text(pDX, IDC_SPADDRESS, m_spaddress);
DDX_Text(pDX, IDC_SPNAME, m_spname);
DDX_Text(pDX, IDC_SPNUMBER, m_spnumber);
DDX_Text(pDX, IDC_SPPRICE, m_spprice);
DDX_Text(pDX, IDC_SPCOUNT, m_spcount);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAddStoreDlg, CDialog)
//{{AFX_MSG_MAP(CAddStoreDlg)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CAddStoreDlg message handlers
void CAddStoreDlg::OnOK()
{
// TODO: Add extra validation here
CString str0,str1,str2;
int count;
CString strSQL;
CDatabase dbTemp;
UpdateData();
if(m_spnumber==""||m_spname=="")
{
MessageBox("請輸入商品編號!"); //初始化窗口
}
else
{
dbTemp.OpenEx("Driver={Microsoft Access Driver (*.mdb)};DBQ=超市管理數據庫.mdb;");
CRecordset rs( &dbTemp);
rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 商品信息表 where 商品編號='"+m_spnumber+"'");
if(!rs.IsEOF()) //如果是舊產品,更新庫存
{
rs.GetFieldValue((short)4,str2); //更新庫存量
count=atoi(str2);
count=count+m_spcount;
str2.Format("%d",count);
strSQL="update 商品信息表 set 庫存量='"+str2+"' where 商品編號='"+m_spnumber+"'";
dbTemp.ExecuteSQL(strSQL);
}
else //如果是新產品,添加商品信息
{
str0.Format("%d",m_spcount);
str1.Format("%f",m_spprice);
strSQL="insert into 商品信息表 values('"+m_spnumber+"','"+m_spname+"','"+str1+"','"+m_spaddress+"','"+str0+"')";
dbTemp.ExecuteSQL(strSQL);
}
MessageBox("添加成功!"); //初始化窗口
m_spnumber = _T("");
m_spname = _T("");
m_spprice = 0.0f;
m_spcount = 1;
m_spaddress = _T("");
UpdateData(false);
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -