TakeOutEditDlg.cpp
资源名称:SQLVC.rar [点击查看]
上传用户:biney012
上传日期:2022-05-09
资源大小:4592k
文件大小:8k
源码类别:
数据库系统
开发平台:
Visual C++
- // TakeOutEditDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Stock.h"
- #include "TakeOutEditDlg.h"
- #include "COMDEF.H"
- #include "Columns.h"
- #include "Column.h"
- #include "_recordset.h"
- #include "ProInStore.h"
- #include "TakeOut.h"
- extern CUsers curUser;
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CTakeOutEditDlg dialog
- CTakeOutEditDlg::CTakeOutEditDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CTakeOutEditDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CTakeOutEditDlg)
- m_OptDate = _T("");
- m_Pprice = _T("");
- m_User = _T("");
- m_Pnum1 = _T("");
- m_Pnum = 0;
- //}}AFX_DATA_INIT
- }
- void CTakeOutEditDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CTakeOutEditDlg)
- DDX_Control(pDX, IDC_TYPE_COMBO, m_Type);
- DDX_Control(pDX, IDC_CLTTYPE_COMBO, m_CltType);
- 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_Control(pDX, IDC_CLIENT_DATACOMBO, m_Client);
- DDX_Control(pDX, IDC_DATAGRID2, m_datagrid);
- DDX_Text(pDX, IDC_OPTDATE_STATIC, m_OptDate);
- DDX_Control(pDX, IDC_PNAME_DATACOMBO, m_Pname);
- DDX_Text(pDX, IDC_PPRICE_STATIC, m_Pprice);
- DDX_Control(pDX, IDC_PROTYPE1_DATACOMBO, m_ProType1);
- DDX_Control(pDX, IDC_PROTYPE2_DATACOMBO, m_ProType2);
- DDX_Control(pDX, IDC_STOREHOUSE_DATACOMBO, m_Storehouse);
- DDX_Text(pDX, IDC_USER_STATIC, m_User);
- DDX_Control(pDX, IDC_ADODC5, m_adodc5);
- DDX_Control(pDX, IDC_ADODC6, m_adodc6);
- DDX_Text(pDX, IDC_Pnum_STATIC, m_Pnum1);
- DDX_Text(pDX, IDC_PNUM_EDIT, m_Pnum);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CTakeOutEditDlg, CDialog)
- //{{AFX_MSG_MAP(CTakeOutEditDlg)
- ON_CBN_SELCHANGE(IDC_CLTTYPE_COMBO, OnSelchangeClttypeCombo)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CTakeOutEditDlg message handlers
- void CTakeOutEditDlg::Refresh_Data()
- {
- CString cPid; //保存当前选择的产品编号
- if (m_Pname.GetBoundText() == "")
- cPid = "0";
- else
- cPid = m_Pname.GetBoundText();
- CString cSid; //保存当前选择的仓库编号
- if (m_Storehouse.GetBoundText() == "")
- cSid = "0";
- else
- cSid = m_Storehouse.GetBoundText();
- //设置SELECT语句
- CString cSource;
- cSource = "SELECT SpId, Pprice As 产品入库单价, Pnum As 库存数量, MakeDate As 生产日期";
- cSource += " FROM ProInStore WHERE Pid=" + cPid + " AND Sid=" + cSid;
- //设置记录源
- m_adodc6.SetRecordSource(cSource);
- m_adodc6.Refresh();
- //设置表格列宽度
- _variant_t vIndex;
- vIndex = long(0);
- m_datagrid.GetColumns().GetItem(vIndex).SetWidth(0);
- vIndex = long(1);
- m_datagrid.GetColumns().GetItem(vIndex).SetWidth(130);
- vIndex = long(2);
- m_datagrid.GetColumns().GetItem(vIndex).SetWidth(130);
- vIndex = long(3);
- m_datagrid.GetColumns().GetItem(vIndex).SetWidth(130);
- }
- BOOL CTakeOutEditDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_CltType.SetCurSel(0); //设置客户类型
- m_Type.SetCurSel(0); //设置出库类型
- CTime t = CTime::GetCurrentTime(); //读取当前系统日期
- m_User = curUser.GetUserName(); //自动设置操作人
- m_OptDate = t.Format("%Y-%m-%d"); //自动设置操作时间
- UpdateData(FALSE);
- //刷新库存产品表格
- Refresh_Data();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CTakeOutEditDlg::OnSelchangeClttypeCombo()
- {
- //设置查询客户的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(CTakeOutEditDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CTakeOutEditDlg)
- ON_EVENT(CTakeOutEditDlg, IDC_PROTYPE1_DATACOMBO, -600 /* Click */, OnClickProtype1Datacombo, VTS_I2)
- ON_EVENT(CTakeOutEditDlg, IDC_PROTYPE2_DATACOMBO, -600 /* Click */, OnClickProtype2Datacombo, VTS_I2)
- ON_EVENT(CTakeOutEditDlg, IDC_PNAME_DATACOMBO, -600 /* Click */, OnClickPnameDatacombo, VTS_I2)
- ON_EVENT(CTakeOutEditDlg, IDC_STOREHOUSE_DATACOMBO, -600 /* Click */, OnClickStorehouseDatacombo, VTS_I2)
- ON_EVENT(CTakeOutEditDlg, IDC_DATAGRID2, -600 /* Click */, OnClickDatagrid2, VTS_NONE)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
- void CTakeOutEditDlg::OnClickProtype1Datacombo(short Area)
- {
- //读取一级产品类别编号
- 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();
- //刷新库存产品表格
- Refresh_Data();
- }
- void CTakeOutEditDlg::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();
- //刷新库存产品表格
- Refresh_Data();
- }
- void CTakeOutEditDlg::OnClickPnameDatacombo(short Area)
- {
- //刷新库存产品表格
- Refresh_Data();
- }
- void CTakeOutEditDlg::OnClickStorehouseDatacombo(short Area)
- {
- //刷新库存产品表格
- Refresh_Data();
- }
- void CTakeOutEditDlg::OnClickDatagrid2()
- {
- // TODO: Add your control notification handler code here
- if (m_adodc6.GetRecordset().GetEof())
- {
- m_Pprice = "0"; //产品价格设置为0
- m_Pnum1 = "0"; //产品数量设置为0
- }
- else
- {
- m_Pprice = m_datagrid.GetItem(1); //从表格中读取产品价格
- m_Pnum1 = m_datagrid.GetItem(2); //从表格中读取产品库存数量
- }
- UpdateData(FALSE);
- }
- void CTakeOutEditDlg::OnOK()
- {
- 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;
- }
- if (m_adodc6.GetRecordset().GetEof())
- {
- MessageBox("请选择要出库的库存产品记录");
- return;
- }
- // 从库存产品表中读取当前的产品数量
- // 因为此库存产品可能在其他客户端被出库,从而导致库存数量变量
- CProInStore pi;
- pi.GetData(m_datagrid.GetItem(0));
- if (m_Pnum > pi.GetPnum())
- {
- MessageBox("出库数量大于库存数量");
- m_Pnum1 = pi.GetPnum(); //显示新的库存数量
- UpdateData(FALSE);
- return;
- }
- //保存出库信息
- CTakeOut to;
- int index;
- index = m_Type.GetCurSel();
- CString cType;
- m_Type.GetLBText(index, cType);
- to.SetTtype(cType); //出库类型
- to.SetPid(atoi(m_Pname.GetBoundText())); //产品编号
- to.SetPprice(atof(m_Pprice)); //单价
- to.SetPnum(m_Pnum); //数量
- to.SetCid(atoi(m_Client.GetBoundText())); //客户编号
- to.SetSid(atoi(m_Storehouse.GetBoundText())); //仓库编号
- to.SetEmpName(m_User); //操作用户
- to.SetOptDate(m_OptDate); //操作日期
- //插入出库数量
- to.sql_insert();
- //@@@@@ 保存库存产品信息 @@@@@
- pi.SetPid(atoi(m_Pname.GetBoundText())); //产品编号
- pi.SetPprice(atof(m_Pprice)); //单价
- pi.SetPnum(m_Pnum * (-1)); //数量(因为要减去库存,所以乘以-1)
- CString cMakeDate;
- cMakeDate = m_datagrid.GetItem(3);
- pi.SetMakeDate(cMakeDate); //生产日期
- pi.SetSid(atoi(m_Storehouse.GetBoundText())); //仓库编号
- //如果不存在当前库存产品,则插入新记录,否则更新库存数量
- CString cPid;
- cPid.Format("%d", pi.GetPid());
- CString cSid;
- cSid.Format("%d", pi.GetSid());
- if (pi.HaveData(cPid, m_Pprice, pi.GetMakeDate(), cSid) == 1)
- pi.sql_updateDiff(cPid, m_Pprice, pi.GetMakeDate(), cSid);
- else
- pi.sql_insert();
- CDialog::OnOK();
- }