StoreInEditDlg.cpp
资源名称:final.rar [点击查看]
上传用户:fangwenmm
上传日期:2014-06-18
资源大小:6955k
文件大小:7k
源码类别:
企业管理
开发平台:
Visual C++
- // StoreInEditDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Stock.h"
- #include "StoreInEditDlg.h"
- #include "StoreIn.h"
- #include "ProInStore.h"
- extern CUsers curUser;
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CStoreInEditDlg dialog
- CStoreInEditDlg::CStoreInEditDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CStoreInEditDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CStoreInEditDlg)
- m_MakeDate = 0;
- m_OptDate = _T("");
- m_Pnum = 0;
- m_Pprice = 0.0f;
- m_Price = _T("");
- m_User = _T("");
- //}}AFX_DATA_INIT
- }
- void CStoreInEditDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CStoreInEditDlg)
- DDX_Control(pDX, IDC_CLTTYPE_COMBO, m_CltType);
- DDX_Control(pDX, IDC_SITYPE_COMBO, m_SiType);
- DDX_Control(pDX, IDC_ADODC1, m_adodc1);
- DDX_Control(pDX, IDC_ADODC2, m_adodc2);
- DDX_Control(pDX, IDC_ADODC3, m_adodc3);
- DDX_Control(pDX, IDC_ADODC4, m_adodc4);
- DDX_DateTimeCtrl(pDX, IDC_MAKEDATE, m_MakeDate);
- DDX_Text(pDX, IDC_OPTDATE_STATIC, m_OptDate);
- DDX_Text(pDX, IDC_PNUM_EDIT, m_Pnum);
- DDX_Text(pDX, IDC_PPRICE_EDIT, m_Pprice);
- DDX_Text(pDX, IDC_PRICE_STATIC, m_Price);
- DDX_Control(pDX, IDC_PROTYPE1_DATACOMBO, m_ProType1);
- DDX_Control(pDX, IDC_PROTYPE2_DATACOMBO, m_ProType2);
- DDX_Text(pDX, IDC_USER_STATIC, m_User);
- DDX_Control(pDX, IDC_CLIENT_DATACOMBO, m_Client);
- DDX_Control(pDX, IDC_PNAME_DATACOMBO, m_Pname);
- DDX_Control(pDX, IDC_ADODC5, m_adodc5);
- DDX_Control(pDX, IDC_STOREHOUSE_DATACOMBO, m_Storehouse);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CStoreInEditDlg, CDialog)
- //{{AFX_MSG_MAP(CStoreInEditDlg)
- ON_CBN_SELCHANGE(IDC_CLTTYPE_COMBO, OnSelchangeClttypeCombo)
- ON_EN_CHANGE(IDC_PPRICE_EDIT, OnChangePpriceEdit)
- ON_EN_CHANGE(IDC_PNUM_EDIT, OnChangePnumEdit)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CStoreInEditDlg message handlers
- void CStoreInEditDlg::OnOK()
- {
- // TODO: Add extra validation here
- UpdateData(TRUE); //将输入数据读取到成员变量
- //判断输入数据是否有效
- if (m_Client.GetBoundText() == "")
- {
- MessageBox("请选择客户");
- return;
- }
- if (m_Pname.GetBoundText() == "")
- {
- MessageBox("请选择产品");
- return;
- }
- if (m_Storehouse.GetBoundText() == "")
- {
- MessageBox("请选择仓库");
- return;
- }
- if (m_Pnum == 0)
- {
- MessageBox("请输入入库产品数量");
- return;
- }
- CStoreIn si;
- int index;
- index = m_SiType.GetCurSel();
- CString cType;
- m_SiType.GetLBText(index, cType);
- si.SetSiType(cType); //入库类型
- si.SetPid(atoi(m_Pname.GetBoundText())); //产品编号
- si.SetMakeDate(m_MakeDate.Format("%Y-%m-%d")); //生产日期
- si.SetPprice(m_Pprice); //单价
- si.SetPnum(m_Pnum); //数量
- si.SetCid(atoi(m_Client.GetBoundText())); //客户编号
- si.SetSid(atoi(m_Storehouse.GetBoundText())); //仓库编号
- si.SetEmpName(m_User); //操作用户
- si.SetOptDate(m_OptDate); //操作日期
- //插入入库数量
- si.sql_insert();
- //@@@@@ 保存库存产品信息 @@@@@
- CProInStore pi;
- pi.SetPid(atoi(m_Pname.GetBoundText())); //产品编号
- pi.SetPprice(m_Pprice); //单价
- pi.SetPnum(m_Pnum); //数量
- pi.SetMakeDate(m_MakeDate.Format("%Y-%m-%d")); //生产日期
- pi.SetSid(atoi(m_Storehouse.GetBoundText())); //仓库编号
- //如果不存在当前库存产品,则插入新记录,否则更新库存数量
- CString cPid;
- cPid.Format("%d", pi.GetPid());
- CString cPrice;
- cPrice.Format("%f", m_Pprice);
- CString cSid;
- cSid.Format("%d", pi.GetSid());
- if (pi.HaveData(cPid, cPrice, pi.GetMakeDate(), cSid) == 1)
- pi.sql_updateDiff(cPid, cPrice, pi.GetMakeDate(), cSid);
- else
- pi.sql_insert();
- CDialog::OnOK();
- }
- BOOL CStoreInEditDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- m_CltType.SetCurSel(0); //设置客户类型
- m_SiType.SetCurSel(0); //设置入库类型
- CTime t = CTime::GetCurrentTime(); //读取当前系统日期
- m_MakeDate = t; //设置生产日期为当日
- m_User = curUser.GetUserName(); //自动设置操作人
- m_OptDate = t.Format("%Y-%m-%d"); //自动设置操作时间
- UpdateData(FALSE);
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CStoreInEditDlg::OnSelchangeClttypeCombo()
- {
- // TODO: Add your control notification handler code here
- //设置查询客户的SELECT语句
- CString cSource;
- cSource = "SELECT * FROM Client";
- //根据客户类别设置查询条件
- if (m_CltType.GetCurSel() == 0)
- cSource += " WHERE Ctype = 1";
- else
- cSource += " WHERE Ctype = 2";
- m_Client.SetText(""); //清除客户组合框的显示内容
- m_adodc1.SetRecordSource(cSource); //设置数据源,重新客户列表
- m_adodc1.Refresh();
- }
- BEGIN_EVENTSINK_MAP(CStoreInEditDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CStoreInEditDlg)
- ON_EVENT(CStoreInEditDlg, IDC_PROTYPE1_DATACOMBO, -600 /* Click */, OnClickProtype1Datacombo, VTS_I2)
- ON_EVENT(CStoreInEditDlg, IDC_PROTYPE2_DATACOMBO, -600 /* Click */, OnClickProtype2Datacombo, VTS_I2)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
- void CStoreInEditDlg::OnClickProtype1Datacombo(short Area)
- {
- // TODO: Add your control notification handler code here
- //读取一级产品类别编号
- CString cUpperId;
- cUpperId = m_ProType1.GetBoundText();
- if (cUpperId == "")
- cUpperId = "0";
- //设置查询二级产品类型的SELECT语句
- CString cSource;
- cSource = "SELECT * FROM ProType WHERE UpperId=" + cUpperId;
- m_ProType2.SetText("");
- //设置m_adodc3,从而刷新二级产品类别的列表
- m_adodc3.SetRecordSource(cSource);
- m_adodc3.Refresh();
- //设置产品列表框,因为没有选中二级产品类别,所以要清空产品列表框
- cSource = "SELECT * FROM Product WHERE TypeId=0";
- m_Pname.SetText("");
- //设置m_adodc3,从而刷新二级产品类别的列表
- m_adodc4.SetRecordSource(cSource);
- m_adodc4.Refresh();
- }
- void CStoreInEditDlg::OnClickProtype2Datacombo(short Area)
- {
- // TODO: Add your control notification handler code here
- //读取二级产品类别编号
- CString cTypeId;
- cTypeId = m_ProType2.GetBoundText();
- if (cTypeId == "")
- cTypeId = "0";
- //设置查询二级产品类型的SELECT语句
- CString cSource;
- cSource = "SELECT * FROM Product WHERE TypeId=" + cTypeId;
- m_Pname.SetText("");
- //设置m_adodc3,从而刷新二级产品类别的列表
- m_adodc4.SetRecordSource(cSource);
- m_adodc4.Refresh();
- }
- void CStoreInEditDlg::OnChangePpriceEdit()
- {
- UpdateData(TRUE); //读取输入数据到成员变量
- m_Price.Format("%.2f", m_Pprice * m_Pnum); //计算总价格
- UpdateData(FALSE); //显示成员变量值
- }
- void CStoreInEditDlg::OnChangePnumEdit()
- {
- UpdateData(TRUE); //读取输入数据到成员变量
- m_Price.Format("%.2f", m_Pprice * m_Pnum); //计算总价格
- UpdateData(FALSE); //显示成员变量值
- }