📄 mydlgaddother.cpp
字号:
// MyDlgAddOther.cpp : implementation file
//
#include "stdafx.h"
#include "myprinter.h"
#include "MyDlgAddOther.h"
#include "column.h"
#include "columns.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMyDlgAddOther property page
IMPLEMENT_DYNCREATE(CMyDlgAddOther, CPropertyPage)
CMyDlgAddOther::CMyDlgAddOther() : CPropertyPage(CMyDlgAddOther::IDD)
{
EnableAutomation();
//{{AFX_DATA_INIT(CMyDlgAddOther)
// NOTE: the ClassWizard will add member initialization here
//}}AFX_DATA_INIT
HRESULT hr;
//初始化连接指针
CoInitialize(NULL);
hr=p_connection.CreateInstance(_uuidof(Connection));
if(FAILED(hr))
{
CWnd::MessageBox ("_ConnectionPtr初始化错误!");
}
//初始化recordset指针
hr=p_Rst_Hospital.CreateInstance(_uuidof(Recordset));
if(FAILED(hr))
{
CWnd::MessageBox ("_RecordsetPtr初始化错误!");
}
//初始化recordset指针
hr=p_Rst_Unit.CreateInstance(_uuidof(Recordset));
if(FAILED(hr))
{
CWnd::MessageBox ("_RecordsetPtr初始化错误!");
}
}
CMyDlgAddOther::~CMyDlgAddOther()
{
}
void CMyDlgAddOther::OnFinalRelease()
{
// When the last reference for an automation object is released
// OnFinalRelease is called. The base class will automatically
// deletes the object. Add additional cleanup required for your
// object before calling the base class.
CPropertyPage::OnFinalRelease();
}
void CMyDlgAddOther::DoDataExchange(CDataExchange* pDX)
{
CPropertyPage::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlgAddOther)
DDX_Control(pDX, IDC_STATIC_TEXT2, m_Static_Text2);
DDX_Control(pDX, IDC_STATIC_TEXT1, m_Static_Text1);
DDX_Control(pDX, IDC_EDIT_UNIT, m_Edit_Unit);
DDX_Control(pDX, IDC_EDIT_HOSPITAL, m_Edit_Hospital);
DDX_Control(pDX, IDC_DATAGRID_HOSPITAL, m_DataGrid_Hospital);
DDX_Control(pDX, IDC_DATAGRID_UNIT, m_DataGrid_Unit);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlgAddOther, CPropertyPage)
//{{AFX_MSG_MAP(CMyDlgAddOther)
ON_BN_CLICKED(IDC_BUTTON_ADDUNIT, OnButtonAddUnit)
ON_BN_CLICKED(IDC_BUTTON_ADDHOSPITAL, OnButtonAddHospital)
ON_BN_CLICKED(IDC_BUTTON_DELUNIT, OnButtonDelUnit)
ON_BN_CLICKED(IDC_BUTTON_DELHOSPITAL, OnButtonDelHospital)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_DISPATCH_MAP(CMyDlgAddOther, CPropertyPage)
//{{AFX_DISPATCH_MAP(CMyDlgAddOther)
// NOTE - the ClassWizard will add and remove mapping macros here.
//}}AFX_DISPATCH_MAP
END_DISPATCH_MAP()
// Note: we add support for IID_IMyDlgAddOther to support typesafe binding
// from VBA. This IID must match the GUID that is attached to the
// dispinterface in the .ODL file.
// {7C535A41-4EDA-4FBE-8FB9-B4C65F69F3E1}
static const IID IID_IMyDlgAddOther =
{ 0x7c535a41, 0x4eda, 0x4fbe, { 0x8f, 0xb9, 0xb4, 0xc6, 0x5f, 0x69, 0xf3, 0xe1 } };
BEGIN_INTERFACE_MAP(CMyDlgAddOther, CPropertyPage)
INTERFACE_PART(CMyDlgAddOther, IID_IMyDlgAddOther, Dispatch)
END_INTERFACE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlgAddOther message handlers
//DEL void CMyDlgAddOther::InitDataGrid()
//DEL {
//DEL
//DEL }
BOOL CMyDlgAddOther::OnInitDialog()
{
CPropertyPage::OnInitDialog();
// TODO: Add extra initialization here
this->InitDataGridHospital ();
this->InitDataGridUnit ();
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
void CMyDlgAddOther::InitDataGridHospital()
{
HRESULT hr;
CString str;
int i;
try
{
if(this->p_Rst_Hospital ->GetState()==adStateOpen)
p_Rst_Hospital->Close();
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
return;
}
//str.Format ("select * from 药品名称 ORDER BY 拼音 DESC");
try
{
hr=p_Rst_Hospital->Open (_variant_t("购货单位"),
_variant_t((IDispatch *)p_connection,true),
adOpenKeyset,
adLockOptimistic,
adCmdTable
);
if(FAILED(hr))
{
CWnd::MessageBox ("记录集打开失败");
return;
}
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
return;
}
//this->MessageBox ("OK ^_^");
//更新表格
this->m_DataGrid_Hospital.SetRefDataSource(p_Rst_Hospital);
i=p_Rst_Hospital->GetRecordCount ();
if(i)
{
m_DataGrid_Hospital.GetColumns().GetItem(_variant_t("拼音")).SetWidth(0.0);
m_DataGrid_Hospital.GetColumns().GetItem(_variant_t("购货单位")).SetWidth(120.0);
////m_DataGrid.GetColumns().GetItem(_variant_t("药品编号")).SetWidth(40.0);
//m_DataGrid.GetColumns().GetItem(_variant_t("规格")).SetWidth(20.0);
//m_DataGrid.GetColumns().GetItem(_variant_t("药品单位")).SetWidth(20.0);
//m_DataGrid.GetColumns().GetItem(_variant_t("生产厂家")).SetWidth(100.0);
//m_DataGrid_Main.GetColumns().GetItem(_variant_t("生产厂家")).SetWidth(70.0);
//m_DataGrid_Main.GetColumns().GetItem(_variant_t("单位")).SetWidth(30.0);
}
if(i<0) i=0;
str.Format ("数据库中共有 %d 条记录",i);
this->m_Static_Text2 .SetWindowText (str);
}
void CMyDlgAddOther::InitDataGridUnit()
{
HRESULT hr;
CString str;
int i;
try
{
if(this->p_Rst_Unit ->GetState()==adStateOpen)
p_Rst_Unit->Close();
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
return;
}
//str.Format ("select * from 药品名称 ORDER BY 拼音 DESC");
try
{
hr=p_Rst_Unit->Open (_variant_t("药品单位"),
_variant_t((IDispatch *)p_connection,true),
adOpenKeyset,
adLockOptimistic,
adCmdTable
);
if(FAILED(hr))
{
CWnd::MessageBox ("记录集打开失败");
return;
}
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
return;
}
//this->MessageBox ("OK ^_^");
//更新表格
this->m_DataGrid_Unit.SetRefDataSource(p_Rst_Unit);
i=p_Rst_Unit->GetRecordCount ();
if(i)
{
m_DataGrid_Unit.GetColumns().GetItem(_variant_t("拼音")).SetWidth(0.0);
m_DataGrid_Unit.GetColumns().GetItem(_variant_t("单位")).SetWidth(100.0);
////m_DataGrid.GetColumns().GetItem(_variant_t("药品编号")).SetWidth(40.0);
//m_DataGrid.GetColumns().GetItem(_variant_t("规格")).SetWidth(20.0);
//m_DataGrid.GetColumns().GetItem(_variant_t("药品单位")).SetWidth(20.0);
//m_DataGrid.GetColumns().GetItem(_variant_t("生产厂家")).SetWidth(100.0);
//m_DataGrid_Main.GetColumns().GetItem(_variant_t("生产厂家")).SetWidth(70.0);
//m_DataGrid_Main.GetColumns().GetItem(_variant_t("单位")).SetWidth(30.0);
}
if(i<0) i=0;
str.Format ("数据库中共有 %d 条记录",i);
this->m_Static_Text1 .SetWindowText (str);
}
void CMyDlgAddOther::OnButtonAddUnit()
{
// TODO: Add your control notification handler code here
CString str_con;
HRESULT hr;
this->m_Edit_Unit .GetWindowText (str_Unit);
//m_Edit_PinYin.GetWindowText (str_PinYin);
if(str_Unit.GetLength ()==0)
{
this->MessageBox ("【药品单位】不能为空!");
return;
}
str_con.Format ("select * from 药品单位 where 单位='%s'",str_Unit);
try
{
if(this->p_Rst_Unit ->GetState()==adStateOpen)
p_Rst_Unit->Close();
hr=p_Rst_Unit->Open (_variant_t(str_con),
_variant_t((IDispatch *)p_connection,true),
adOpenKeyset,
adLockOptimistic,
adCmdText
);
if(FAILED(hr))
{
CWnd::MessageBox ("记录集打开失败");
return;
}
if(p_Rst_Unit->GetRecordCount ()>0)
{
this->MessageBox ("【药品单位】重复,请重新选择或重新输入!\n\n");
return;
}
else
{
this->p_Rst_Unit ->AddNew ();
p_Rst_Unit->PutCollect (_variant_t("单位"),_variant_t(str_Unit));
//p_recordset->PutCollect (_variant_t("拼音"),_variant_t(str_PinYin));
p_Rst_Unit->Update ();
}
}//end try
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ()+"\n你填写的信息有错误!(wklh12-1023)");
return;
}
this->m_Edit_Unit .SetWindowText ("");
this->InitDataGridUnit ();
}
void CMyDlgAddOther::OnButtonAddHospital()
{
// TODO: Add your control notification handler code here
CString str_con;
HRESULT hr;
this->m_Edit_Hospital .GetWindowText (str_Hospital);
//m_Edit_PinYin.GetWindowText (str_PinYin);
if(str_Hospital.GetLength ()==0)
{
this->MessageBox ("【购货单位】不能为空!");
return;
}
str_con.Format ("select * from 购货单位 where 购货单位='%s'",str_Hospital);
try
{
if(this->p_Rst_Hospital ->GetState()==adStateOpen)
p_Rst_Hospital->Close();
hr=p_Rst_Hospital->Open (_variant_t(str_con),
_variant_t((IDispatch *)p_connection,true),
adOpenKeyset,
adLockOptimistic,
adCmdText
);
if(FAILED(hr))
{
CWnd::MessageBox ("记录集打开失败");
return;
}
if(p_Rst_Hospital->GetRecordCount ()>0)
{
this->MessageBox ("【购货单位】重复,请重新选择或重新输入!\n\n");
}
else
{
this->p_Rst_Hospital ->AddNew ();
p_Rst_Hospital->PutCollect (_variant_t("购货单位"),_variant_t(str_Hospital));
//p_recordset->PutCollect (_variant_t("拼音"),_variant_t(str_PinYin));
p_Rst_Hospital->Update ();
}
}//end try
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ()+"\n你填写的信息有错误!(wklh12-1021)");
return;
}
this->m_Edit_Hospital .SetWindowText ("");
this->InitDataGridHospital ();
}
void CMyDlgAddOther::OnButtonDelUnit()
{
// TODO: Add your control notification handler code here
try
{
if(p_Rst_Unit->GetState()==adStateOpen &&p_Rst_Unit->GetRecordCount ()>0) //p_MyRstDBNewBill->Close();
{
if(this->MessageBox ("您确定要删除这一条信息吗?\t删除后将不能恢复!","警告!",MB_YESNO)==7)//按确定等于6,按取消等于7
{
//this->MessageBox ("取消");
return;
}
}
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
return;
}
try
{
if(p_Rst_Unit->GetState()==adStateOpen) //p_MyRstDBNewBill->Close();
p_Rst_Unit->Delete(adAffectCurrent);
p_Rst_Unit->Update ();
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
return;
}
this->InitDataGridUnit ();
}
void CMyDlgAddOther::OnButtonDelHospital()
{
// TODO: Add your control notification handler code here
try
{
if(p_Rst_Hospital->GetState()==adStateOpen &&p_Rst_Hospital->GetRecordCount ()>0) //p_MyRstDBNewBill->Close();
{
if(this->MessageBox ("您确定要删除这一条信息吗?\t删除后将不能恢复!","警告!",MB_YESNO)==7)//按确定等于6,按取消等于7
{
//this->MessageBox ("取消");
return;
}
}
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
return;
}
try
{
if(p_Rst_Hospital->GetState()==adStateOpen) //p_MyRstDBNewBill->Close();
p_Rst_Hospital->Delete(adAffectCurrent);
p_Rst_Hospital->Update ();
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
return;
}
this->InitDataGridHospital ();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -