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

📄 mydlgname.cpp

📁 从列表进行打印的源码,请大家下载参考对照,从中发表意见,加深修改.
💻 CPP
字号:
// MyDlgName.cpp : implementation file
//

#include "stdafx.h"
#include "myprinter.h"
#include "MyDlgName.h"
#include "Columns.h"
#include "Column.h"


#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CMyDlgName dialog


CMyDlgName::CMyDlgName(CWnd* pParent /*=NULL*/)
	: CDialog(CMyDlgName::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMyDlgName)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT

	p_str=NULL;

	HRESULT hr;
	//初始化连接指针
	CoInitialize(NULL);
	hr=p_MyCon.CreateInstance(_uuidof(Connection));
	if(FAILED(hr))
	{
		CWnd::MessageBox ("_ConnectionPtr初始化错误!");
	
	}
	
   //初始化recordset指针
	hr=p_MyRst.CreateInstance(_uuidof(Recordset));
	if(FAILED(hr))
	{
		CWnd::MessageBox ("_RecordsetPtr初始化错误!");

	}
	

}


void CMyDlgName::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMyDlgName)
	DDX_Control(pDX, IDC_DATAGRID, m_DataGrid);
	//}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CMyDlgName, CDialog)
	//{{AFX_MSG_MAP(CMyDlgName)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMyDlgName message handlers

BOOL CMyDlgName::OnInitDialog() 
{
	CDialog::OnInitDialog();
	
	// TODO: Add extra initialization here
	
	HRESULT hr;
	CString str;


	try
	{
		if(p_MyRst->GetState()==adStateOpen) p_MyRst->Close();
	}
	catch(_com_error &err)
	{
		CWnd::MessageBox (err.Description ());
	}

	if(str_Name=="商品名称")
	{
		str.Format ("select 药品名称 from 药品名称");
	}
	else if(str_Name=="生产厂家")
	{
		str.Format ("select distinct 生产厂家 from 生产厂家");
	}
	else
	{
		this->MessageBox("程序出错!");
		return FALSE;
	}

	
	try
	{
		hr=p_MyRst->Open (_variant_t(str),
			_variant_t((IDispatch *)p_MyCon,true),
			adOpenKeyset,
			adLockOptimistic,
			adCmdText
			);
		if(FAILED(hr))
		{
			CWnd::MessageBox ("记录集打开失败");
		}
	}

	catch(_com_error &err)
	{
		CWnd::MessageBox (err.Description ());
	}

	//this->MessageBox ("OK    ^_^");

//更新表格
	this->m_DataGrid.SetCaption (str_Name);
	this->m_DataGrid .SetRefDataSource(p_MyRst);
	if(p_MyRst->GetRecordCount ())
	{
		if(str_Name=="商品名称")	
			m_DataGrid.GetColumns().GetItem(_variant_t("药品名称")).SetWidth(100.0);
		else if(str_Name=="生产厂家")
			m_DataGrid.GetColumns().GetItem(_variant_t("生产厂家")).SetWidth(100.0);
		
	}


	//this->MessageBox ("OK    ^_^");

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

BEGIN_EVENTSINK_MAP(CMyDlgName, CDialog)
    //{{AFX_EVENTSINK_MAP(CMyDlgName)
	ON_EVENT(CMyDlgName, IDC_DATAGRID, -601 /* DblClick */, OnDblClickDataDrid, VTS_NONE)
	//}}AFX_EVENTSINK_MAP
		//ON_EVENT(CMyDlgName, IDC_DATAGRID, -600 /* Click */, OnClickDataGrid, VTS_NONE)

END_EVENTSINK_MAP()

//DEL void CMyDlgName::OnClickDataGrid() 
//DEL {
//DEL 	// TODO: Add your control notification handler code here
//DEL 
//DEL }

void CMyDlgName::OnOK() 
{
	// TODO: Add extra validation here
	_variant_t var_Name;

	try
	{
		if(str_Name =="生产厂家")
		{
			var_Name=p_MyRst->GetCollect("生产厂家");
		}
		else if(str_Name =="商品名称")
		{
			var_Name=p_MyRst->GetCollect("药品名称");
		}
		else
			return;
	}
	catch(_com_error &err)
	{
		CWnd::MessageBox (err.Description ());
		return;
	}

		*p_str=(char*)_bstr_t(var_Name);

	//*m_pstrCstmCode=strCstmCode;
	//str_Name ="生产厂家";str_Name ="商品名称";

	CDialog::OnOK();
}

void CMyDlgName::OnDblClickDataDrid() 
{
	// TODO: Add your control notification handler code here
	_variant_t var_Name;

	try
	{
		if(str_Name =="生产厂家")
		{
			var_Name=p_MyRst->GetCollect("生产厂家");
		}
		else if(str_Name =="商品名称")
		{
			var_Name=p_MyRst->GetCollect("药品名称");
		}
		else
			return;
	}
	catch(_com_error &err)
	{
		CWnd::MessageBox (err.Description ());
		return;
	}

		*p_str=(char*)_bstr_t(var_Name);

		//*m_pstrCstmCode=strCstmCode;
		//str_Name ="生产厂家";str_Name ="商品名称";
		CDialog::OnOK();
}

⌨️ 快捷键说明

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