AddNewMerchandiseDlg.cpp
上传用户:tyjx315
上传日期:2015-01-18
资源大小:1685k
文件大小:2k
源码类别:
百货/超市行业
开发平台:
Visual C++
- // AddNewMerchandiseDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "SuperMarket.h"
- #include "AddNewMerchandiseDlg.h"
- #include "afxdb.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CAddNewMerchandiseDlg dialog
- CAddNewMerchandiseDlg::CAddNewMerchandiseDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CAddNewMerchandiseDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CAddNewMerchandiseDlg)
- m_number = _T("");
- m_name = _T("");
- m_price = 0.0f;
- m_count = 1;
- m_producing_area = _T("");
- //}}AFX_DATA_INIT
- }
- void CAddNewMerchandiseDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CAddNewMerchandiseDlg)
- DDX_Text(pDX, IDC_EDIT1, m_number);
- DDX_Text(pDX, IDC_EDIT2, m_name);
- DDX_Text(pDX, IDC_EDIT3, m_price);
- DDX_Text(pDX, IDC_EDIT4, m_count);
- DDX_Text(pDX, IDC_EDIT5, m_producing_area);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CAddNewMerchandiseDlg, CDialog)
- //{{AFX_MSG_MAP(CAddNewMerchandiseDlg)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CAddNewMerchandiseDlg message handlers
- void CAddNewMerchandiseDlg::OnOK() //商品入库操作
- {
- // TODO: Add extra validation here
- // CDialog::OnOK();
- CString str0,str1,str2;
- int count;
- CString strSQL;
- CDatabase dbTemp;
- UpdateData();
- dbTemp.OpenEx("Driver={Microsoft Access Driver (*.mdb)};DBQ=超市管理数据库.mdb;");
- CRecordset rs( &dbTemp);
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 商品信息 where 商品编号='"+m_number+"'");
- if(!rs.IsEOF()) //如果是旧产品,更新库存
- {
- rs.GetFieldValue((short)4,str2); //更新库存量
- count=atoi(str2);
- count=count+m_count;
- str2.Format("%d",count);
- strSQL="update 商品信息 set 库存量='"+str2+"' where 商品编号='"+m_number+"'";
- dbTemp.ExecuteSQL(strSQL);
- }
- else //如果是新产品,添加商品信息
- {
- str0.Format("%d",m_count);
- str1.Format("%f",m_price);
- strSQL="insert into 商品信息 values('"+m_number+"','"+m_name+"','"+str1+"','"+m_producing_area+"','"+str0+"')";
- dbTemp.ExecuteSQL(strSQL);
- }
- MessageBox("录入成功!"); //初始化窗口
- m_number = _T("");
- m_name = _T("");
- m_price = 0.0f;
- m_count = 1;
- m_producing_area = _T("");
- UpdateData(false);
- }