ClientManDlg.cpp
资源名称:SQLVC.rar [点击查看]
上传用户:biney012
上传日期:2022-05-09
资源大小:4592k
文件大小:4k
源码类别:
数据库系统
开发平台:
Visual C++
- // ClientManDlg.cpp : implementation file
- //
- #include "stdafx.h"
- #include "Stock.h"
- #include "ClientManDlg.h"
- #include "COMDEF.H"
- #include "Columns.h"
- #include "Column.h"
- #include "ClientEditDlg.h"
- #include "_recordset.h"
- #include "Client.h"
- #include "StoreIn.h"
- #include "TakeOut.h"
- #include "ProInStore.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #undef THIS_FILE
- static char THIS_FILE[] = __FILE__;
- #endif
- /////////////////////////////////////////////////////////////////////////////
- // CClientManDlg dialog
- CClientManDlg::CClientManDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CClientManDlg::IDD, pParent)
- {
- //{{AFX_DATA_INIT(CClientManDlg)
- // NOTE: the ClassWizard will add member initialization here
- //}}AFX_DATA_INIT
- }
- void CClientManDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- //{{AFX_DATA_MAP(CClientManDlg)
- DDX_Control(pDX, IDC_CTYPE_COMBO, m_Ctype);
- DDX_Control(pDX, IDC_ADODC1, m_adodc);
- DDX_Control(pDX, IDC_DATAGRID1, m_datagrid);
- //}}AFX_DATA_MAP
- }
- BEGIN_MESSAGE_MAP(CClientManDlg, CDialog)
- //{{AFX_MSG_MAP(CClientManDlg)
- ON_BN_CLICKED(IDC_ADD_BUTTON, OnAddButton)
- ON_CBN_SELCHANGE(IDC_CTYPE_COMBO, OnSelchangeCtypeCombo)
- ON_BN_CLICKED(IDC_MODI_BUTTON, OnModiButton)
- ON_BN_CLICKED(IDC_DEL_BUTTON, OnDelButton)
- //}}AFX_MSG_MAP
- END_MESSAGE_MAP()
- /////////////////////////////////////////////////////////////////////////////
- // CClientManDlg message handlers
- void CClientManDlg::Refresh_Data()
- {
- UpdateData(TRUE); //将控件的值读取到成员变量中
- CString cSource;
- CString cCtype; //读取客户类型值
- cCtype.Format("%d", m_Ctype.GetCurSel() + 1);
- //设置SELECT语句,按客户单位排序
- cSource = "SELECT Cid, Cname AS 客户单位, Contact AS 联系人, Address AS 通信地址,";
- cSource += " Postcode AS 邮政编码, Phone AS 联系电话, Fax AS 传真电话, Memo AS 备注";
- cSource += " FROM Client WHERE Ctype=" + cCtype + " ORDER BY Cname";
- m_adodc.SetRecordSource(cSource);
- m_adodc.Refresh();
- //设置表格列宽度
- _variant_t vIndex;
- vIndex = long(0);
- m_datagrid.GetColumns().GetItem(vIndex).SetWidth(0);
- }
- BOOL CClientManDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // TODO: Add extra initialization here
- m_Ctype.SetCurSel(0); //设置客户类型
- Refresh_Data(); //刷新表格中的记录集
- return TRUE; // return TRUE unless you set the focus to a control
- // EXCEPTION: OCX Property Pages should return FALSE
- }
- void CClientManDlg::OnAddButton()
- {
- // TODO: Add your control notification handler code here
- UpdateData(TRUE);
- //打开编辑对话框
- CClientEditDlg dlg;
- dlg.cCid = "";
- dlg.iCtype = m_Ctype.GetCurSel() + 1;
- if (dlg.DoModal() == IDOK)
- Refresh_Data();
- }
- void CClientManDlg::OnSelchangeCtypeCombo()
- {
- // TODO: Add your control notification handler code here
- Refresh_Data();
- }
- void CClientManDlg::OnModiButton()
- {
- // TODO: Add your control notification handler code here
- if (m_adodc.GetRecordset().GetEof())
- {
- MessageBox("请选择要修改的记录");
- return;
- }
- UpdateData(TRUE);
- CClientEditDlg dlg;
- dlg.cCid = m_datagrid.GetItem(0); //记录编号
- dlg.iCtype = m_Ctype.GetCurSel() + 1; //客户类型
- dlg.m_Cname = m_datagrid.GetItem(1); //单位名称
- dlg.cCname = m_datagrid.GetItem(1);
- dlg.m_Contact = m_datagrid.GetItem(2); //联系人
- dlg.m_Address = m_datagrid.GetItem(3); //通信地址
- dlg.m_Postcode = m_datagrid.GetItem(4); //邮政编码
- dlg.m_Phone = m_datagrid.GetItem(5); //联系电话
- dlg.m_Fax = m_datagrid.GetItem(6); //传真
- dlg.m_Memo = m_datagrid.GetItem(7); //备注信息
- if (dlg.DoModal() == IDOK)
- Refresh_Data();
- }
- void CClientManDlg::OnDelButton()
- {
- // TODO: Add your control notification handler code here
- if (m_adodc.GetRecordset().GetEof())
- {
- MessageBox("请选择要删除的记录");
- return;
- }
- CString Cid;
- Cid = m_datagrid.GetItem(0);
- CStoreIn obj;
- if (obj.HaveClient(Cid) == 1)
- {
- MessageBox("客户出现在入库单中,不能删除");
- return;
- }
- CTakeOut obj1;
- if (obj1.HaveClient(Cid) == 1)
- {
- MessageBox("客户出现在出库单中,不能删除");
- return;
- }
- if (MessageBox("是否删除当前记录","请确定", MB_YESNO) == IDYES)
- {
- CClient clt;
- clt.sql_delete(m_datagrid.GetItem(0));
- Refresh_Data();
- }
- }