SaleDlg.cpp
上传用户:tyjx315
上传日期:2015-01-18
资源大小:1685k
文件大小:4k
- // SaleDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "SuperMarket.h"
- #include "SaleDlg.h"
- #include "afxdb.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CSaleDlg dialog
- CSaleDlg::CSaleDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CSaleDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CSaleDlg)
- m_number = _T("");
- m_count = 1;
- m_time = 0;
- total = 0;
- add_time = 0;
- //}}AFX_DATA_INIT
- }
- void CSaleDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CSaleDlg)
- DDX_Control(pDX, IDC_LIST1, m_list);
- DDX_Text(pDX, IDC_EDIT1, m_number);
- DDX_Text(pDX, IDC_EDIT2, m_count);
- DDX_DateTimeCtrl(pDX, IDC_DATETIMEPICKER1, m_time);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CSaleDlg, CDialog)
- //{{AFX_MSG_MAP(CSaleDlg)
- ON_BN_CLICKED(IDC_ADD, OnAdd)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CSaleDlg message handlers
- void CSaleDlg::OnAdd()
- {
- // TODO: Add your control notification handler code here
-
- UpdateData();
- int count;
- CString str0,str1,str2,str3,str4,strSQL;
- CDatabase dbTemp;
-
- dbTemp.OpenEx("Driver={Microsoft Access Driver (*.mdb)};DBQ=超市管理数据库.mdb;");
- CRecordset rs( &dbTemp);
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 商品信息 where 商品编号='"+m_number+"'");
- rs.GetFieldValue((short)0,str0); //从商品信息表中读入商品信息
- rs.GetFieldValue((short)1,str1);
- rs.GetFieldValue((short)2,str2);
- rs.GetFieldValue((short)4,str4);
-
- count=atoi(str4); //更新库存量
- count=count-m_count;
- str4.Format("%d",count);
- strSQL="update 商品信息 set 库存量='"+str4+"' where 商品编号='"+m_number+"'";
- dbTemp.ExecuteSQL(strSQL);
- rs.Close();
-
- price = atof(str2);
- total=total+price*m_count;
- str3.Format("%d",m_count); //显示到窗口
- m_list.InsertItem (add_time,str0);//写第一列;
- m_list.SetItemText (add_time,1,str1);//第二列;
- m_list.SetItemText (add_time,2,str2);//第三列;
- m_list.SetItemText (add_time,3,str3);//第四列;
-
- add_time = add_time + 1;
- UpdateData(false);
- }
- void CSaleDlg::OnOK()
- {
- // TODO: Add extra validation here
- CString str0,strSQL,time,str1;
- int sale_number;
-
- str0.Format("%.2f",total); //窗口中显示总价
- MessageBox("总价:"+str0);
- CDatabase dbTemp;
-
- dbTemp.OpenEx("Driver={Microsoft Access Driver (*.mdb)};DBQ=超市管理数据库.mdb;");
- CRecordset rs( &dbTemp);
-
- rs.Open(AFX_DB_USE_DEFAULT_TYPE,"select * From 销售表");//把一次销售添加到销售表中
- time.Format("%d-%d-%d",m_time.GetYear(),m_time.GetMonth(),m_time.GetDay()); //获取当天时间
- sale_number=(int)rs.GetRecordCount();
- while(!rs.IsEOF())
- {
- sale_number++;
- rs.MoveNext();
- }
- str1.Format("%d",sale_number);
- strSQL="insert into 销售表 values('"+str1+"','"+str0+"','"+time+"')";
- dbTemp.ExecuteSQL(strSQL);
- rs.Close();
-
- total = 0;
- m_list.DeleteAllItems();
- m_number="";
- m_count =1;
- add_time = 0;
- UpdateData(false);
-
- // CDialog::OnOK();
- }
- BOOL CSaleDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
-
- // TODO: Add extra initialization here
- CTime temptime;
- m_time = temptime.GetCurrentTime();
- UpdateData(false);
-
- // Set the icon for this dialog. The framework does this automatically
- // when the application's main window is not a dialog
- // m_list.SetExtendedStyle(LVS_EX_GRIDLINES);
- m_list.SetExtendedStyle(LVS_EX_GRIDLINES|LVS_EX_FULLROWSELECT|LVS_EX_ONECLICKACTIVATE);
- m_list.InsertColumn(0,"编号",LVCFMT_LEFT,80);
- m_list.InsertColumn(1,"名称",LVCFMT_LEFT,145);
- m_list.InsertColumn(2,"价格",LVCFMT_LEFT,80);
- m_list.InsertColumn(3,"数量",LVCFMT_LEFT,100);
-
- UpdateData();
-
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }