⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 promandlg.cpp

📁 h fghgklfgoh gfdklgh fd bfgh tfd h dfh gdflgh, fjghklg ldffdlgm dsfohglfj
💻 CPP
字号:
// ProManDlg.cpp : implementation file
//

#include "stdafx.h"
#include "SuperMarket.h"
#include "ProManDlg.h"
#include "ProEditDlg.h"
#include "_recordset.h"
#include "COMDEF.H"
#include "Columns.h"
#include "Column.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)
		// NOTE: the ClassWizard will add member initialization here
	//}}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::OnAddButton() 
{
	// TODO: Add your control notification handler code here
	if (m_datacombo2.GetBoundText() == "")
	{
		MessageBox("请选择产品类型");
		return;
	}
		
	CProEditDlg dlg;
	dlg.iTypeId = atoi(m_datacombo2.GetBoundText());  //设置产品类别为当前选择的类别
	dlg.DoType = 1;  
	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

	
	_variant_t RecordsAffected,var;
    CString str,source;

	UpdateData(TRUE);
	CProEditDlg dlg;

    UpdateData(true);

    str= m_datacombo2.GetText();

    dlg.m_Ptype = m_datacombo1.GetText() + " - " + m_datacombo2.GetText();
    
	m_pRecordset.CreateInstance(__uuidof(Recordset));

    dlg.DoType = 2;      

	if(str!="")
	{	
		source="SELECT Product.TypeId,Pid,Pname,Pstyle,Punit,Pprice,Plow,Phigh,Valid, AlarmDays,Pstore ";
		
		source+="FROM Product,ProType ";
		source+="WHERE Product.TypeId=ProType.TypeId and TypeName= '";
		

		source+=str;
		source+="'";
	}
	try
	{
	   
		
		m_pRecordset=theApp.m_pConnection->Execute(source.AllocSysString(),
			                                        &RecordsAffected,
			                                        adCmdText);
	  

	}
	catch(_com_error *e)
	{
		AfxMessageBox(e->ErrorMessage());
	}

	m_pRecordset->MoveFirst();

	while(!m_pRecordset->adoEOF)
	{
	    
		var=m_pRecordset->GetCollect("Pname");
	    str=(LPCSTR)_bstr_t(var);
        dlg.m_Pname = str;

		var=m_pRecordset->GetCollect("Pstyle");
	    str=(LPCSTR)_bstr_t(var);
        dlg.m_Pstyle = str;
        
		var=m_pRecordset->GetCollect("Punit");
	    str=(LPCSTR)_bstr_t(var);
        dlg.m_Punit = str;
        
		var=m_pRecordset->GetCollect("Pid");
	    dlg.m_Pid  = var.iVal;

		var=m_pRecordset->GetCollect("Plow");
	    dlg.m_Plow  = var.iVal;

	    var=m_pRecordset->GetCollect("Phigh");
	    dlg.m_Phigh   = var.iVal;
                
         

		var=m_pRecordset->GetCollect("Pprice");
	    dlg.m_Pprice  = var.iVal;

		var=m_pRecordset->GetCollect("Valid");
	    dlg.m_Valid  = var.iVal;
        

		var=m_pRecordset->GetCollect("AlarmDays");
	    dlg.m_Alarm = var.iVal;
        
        
	   // var=m_pRecordset->GetCollect("Pstore");
	    str=(LPCSTR)_bstr_t(var);
        dlg.m_Pstore  = str;

       
		//更新所有控件显示
		UpdateData(false);
	
		m_pRecordset->MoveNext();
	}

//	dlg.m_Ptype = m_datacombo1.GetText() + " - " + m_datacombo2.GetText();

	if (dlg.DoModal() == IDOK)
		Refresh_Data();		
}

void CProManDlg::OnDelButton() 
{
	// TODO: Add your control notification handler code here
/*
	if (MessageBox("是否删除当前记录","请确定", MB_YESNO) == IDYES)
	{
		CProduct pr;
		pr.sql_delete(Pid);
		Refresh_Data();
	}	*/	
}

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(); //读取选择类别的编号

	//MessageBox( cUpper);
		//设置二级类别的记录源
	CString source=" SELECT * FROM ProType WHERE UpperId= "+ cUpper;

//	MessageBox(" SELECT * FROM ProType WHERE UpperId= "+ cUpper);

	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::Refresh_Data()
{
    CString cTypeId;
	cTypeId = m_datacombo2.GetBoundText(); //读取选择的类别编号*****************************

	if (cTypeId == "")
		cTypeId = "0";

//	AfxMessageBox(cTypeId);
	//设置查询产品信息的SELECT语句
	CString cSource;

	cSource += " SELECT* FROM ProType WHERE TypeId = " + cTypeId;
	//设置记录源
	m_adodc3.SetRecordSource(cSource);
	m_adodc3.Refresh();
	//设置表格列宽度
	_variant_t vIndex;
	vIndex = long(0);
	m_datagrid.GetColumns().GetItem(vIndex).SetWidth(0);
}

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
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -