ProManDlg.cpp
资源名称:SQLVC.rar [点击查看]
上传用户:biney012
上传日期:2022-05-09
资源大小:4592k
文件大小:5k
源码类别:
数据库系统
开发平台:
Visual C++
- // ProManDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Stock.h"
- #include "ProManDlg.h"
- #include "ProEditdlg.h"
- #include "COMDEF.H"
- #include "Columns.h"
- #include "Column.h"
- #include "StoreIn.h"
- #include "TakeOut.h"
- #include "ProInStore.h"
- #include "_recordset.h"
- #include "Product.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CProManDlg dialog
- CProManDlg::CProManDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CProManDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CProManDlg)
- //}}AFX_DATA_INIT
- }
- void CProManDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CProManDlg)
- 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_DATACOMBO1, m_datacombo1);
- DDX_Control(pDX, IDC_DATACOMBO2, m_datacombo2);
- DDX_Control(pDX, IDC_DATAGRID1, m_datagrid);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CProManDlg, CDialog)
- //{{AFX_MSG_MAP(CProManDlg)
- ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
- ON_BN_CLICKED(IDC_MODI_BUTTON, OnModiButton)
- ON_BN_CLICKED(IDC_DEL_BUTTON, OnDelButton)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CProManDlg message handlers
- void CProManDlg::Refresh_Data()
- {
- CString cTypeId;
- cTypeId = m_datacombo2.GetBoundText(); //读取选择的类别编号
- if (cTypeId == "")
- cTypeId = "0";
- //设置查询产品信息的SELECT语句
- CString cSource;
- cSource = "SELECT Pid, Pname AS 产品名称, Pstyle AS 产品规格, Punit AS 计量单位,";
- cSource += " Pprice AS 参考价格, Plow AS 数量下限, Phigh AS 数量上限, Valid As 有效期,";
- cSource += " AlarmDays As 警告期 FROM Product WHERE TypeId = " + cTypeId;
- //设置记录源
- m_adodc3.SetRecordSource(cSource);
- m_adodc3.Refresh();
- //设置表格列宽度
- _variant_t vIndex;
- vIndex = long(0);
- m_datagrid.GetColumns().GetItem(vIndex).SetWidth(0);
- }
- BEGIN_EVENTSINK_MAP(CProManDlg, CDialog)
- //{{AFX_EVENTSINK_MAP(CProManDlg)
- ON_EVENT(CProManDlg, IDC_DATACOMBO1, -600 /* Click */, OnClickDatacombo1, VTS_I2)
- ON_EVENT(CProManDlg, IDC_DATACOMBO2, -600 /* Click */, OnClickDatacombo2, VTS_I2)
- //}}AFX_EVENTSINK_MAP
- END_EVENTSINK_MAP()
- void CProManDlg::OnClickDatacombo1(short Area)
- {
- // TODO: Add your control notification handler code here
- CString cUpper;
- cUpper = m_datacombo1.GetBoundText(); //读取选择类别的编号
- if (cUpper == "")
- cUpper = "0";
- //设置二级类别的记录源
- m_adodc2.SetRecordSource("SELECT * FROM ProType WHERE UpperId=" + cUpper);
- m_adodc2.Refresh();
- }
- void CProManDlg::OnClickDatacombo2(short Area)
- {
- // TODO: Add your control notification handler code here
- Refresh_Data();
- }
- void CProManDlg::OnAddButton()
- {
- // TODO: Add your control notification handler code here
- if (m_datacombo2.GetBoundText() == "")
- {
- MessageBox("请选择产品类型");
- return;
- }
- CProEditDlg dlg;
- dlg.iTypeId = atoi(m_datacombo2.GetBoundText()); //设置产品类别为当前选择的类别
- dlg.cPid = ""; //表示插入记录
- dlg.cPname = ""; //设置产品名称为空
- dlg.m_Ptype = m_datacombo1.GetText() + " - " + m_datacombo2.GetText();
- if (dlg.DoModal() == IDOK)
- Refresh_Data();
- }
- void CProManDlg::OnModiButton()
- {
- // TODO: Add your control notification handler code here
- if (m_adodc3.GetRecordset().GetEof())
- {
- MessageBox("请选择要修改的记录");
- return;
- }
- UpdateData(TRUE);
- CProEditDlg dlg;
- dlg.cPid = m_datagrid.GetItem(0); //记录编号
- dlg.iTypeId = atoi(m_datacombo2.GetBoundText()); //产品类型
- dlg.cPname = m_datagrid.GetItem(1); //产品名称
- dlg.m_Pname = m_datagrid.GetItem(1);
- dlg.m_Ptype = m_datacombo1.GetText() + " - " + m_datacombo2.GetText();
- dlg.m_Pstyle = m_datagrid.GetItem(2); //产品规格
- dlg.m_Punit = m_datagrid.GetItem(3); //计量单位
- dlg.m_Pprice = atof(m_datagrid.GetItem(4)); //参考价格
- dlg.m_Plow = atoi(m_datagrid.GetItem(5)); //数量下限
- dlg.m_Phigh = atoi(m_datagrid.GetItem(6)); //数量上限
- dlg.m_Valid = atoi(m_datagrid.GetItem(7)); //有效期
- dlg.m_Alarm = atoi(m_datagrid.GetItem(8)); //警告期
- if (dlg.DoModal() == IDOK)
- Refresh_Data();
- }
- void CProManDlg::OnDelButton()
- {
- // TODO: Add your control notification handler code here
- if (m_adodc3.GetRecordset().GetEof())
- {
- MessageBox("请选择要删除的记录");
- return;
- }
- CString Pid;
- Pid = m_datagrid.GetItem(0);
- CStoreIn obj;
- if (obj.HaveProduct(Pid) == 1)
- {
- MessageBox("产品出现在入库单中,不能删除");
- return;
- }
- CTakeOut obj1;
- if (obj1.HaveProduct(Pid) == 1)
- {
- MessageBox("产品出现在出库单中,不能删除");
- return;
- }
- CProInStore obj2;
- if (obj2.HaveProduct(Pid) == 1)
- {
- MessageBox("产品出现在库存产品信息中,不能删除");
- return;
- }
- if (MessageBox("是否删除当前记录","请确定", MB_YESNO) == IDYES)
- {
- CProduct pr;
- pr.sql_delete(Pid);
- Refresh_Data();
- }
- }
- BOOL CProManDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- Refresh_Data();
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }