📄 newbilldlg.cpp
字号:
// NewBillDlg.cpp : implementation file
//
#include "stdafx.h"
#include "myprinter.h"
#include "NewBillDlg.h"
#include "MyDlgName.h"
#include "Columns.h"
#include "Column.h"
#include "MyClass.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CNewBillDlg dialog
CNewBillDlg::CNewBillDlg(CWnd* pParent /*=NULL*/)
: CDialog(CNewBillDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CNewBillDlg)
//}}AFX_DATA_INIT
HRESULT hr;
//初始化连接指针
CoInitialize(NULL);
hr=p_MyConNewBill.CreateInstance(_uuidof(Connection));
if(FAILED(hr))
{
CWnd::MessageBox ("_ConnectionPtr初始化错误!");
}
//初始化recordset指针
hr=p_MyRstNewBill.CreateInstance(_uuidof(Recordset));
if(FAILED(hr))
{
CWnd::MessageBox ("_RecordsetPtr初始化错误!");
}
hr=p_MyRstDBNewBill.CreateInstance(_uuidof(Recordset));
if(FAILED(hr))
{
CWnd::MessageBox ("_RecordsetPtr初始化错误!");
}
}
void CNewBillDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CNewBillDlg)
DDX_Control(pDX, IDC_COMBO_SERIALNUM, m_Combo_SerialNum);
DDX_Control(pDX, IDC_EDIT_NOTE, m_Edit_Note);
DDX_Control(pDX, IDC_COMBO_WAREHOUSE, m_Combo_WareHouse);
DDX_Control(pDX, IDC_COMBO_NO, m_Combo_NO_);
DDX_Control(pDX, IDC_DATETIMEPICKER1, m_DateTimeCtrl_DateTime);
DDX_Control(pDX, IDC_EDIT_YEAR, m_Edit_Year);
DDX_Control(pDX, IDC_EDIT_PIHAO, m_Edit_PiHao);
DDX_Control(pDX, IDC_COMBO_PLANT, m_Combo_Plant);
DDX_Control(pDX, IDC_COMBO_NAME, m_Combo_Name);
DDX_Control(pDX, IDC_EDIT_TOTAL, m_Edit_Total);
DDX_Control(pDX, IDC_COMBO_PRICE, m_Combo_Price);
DDX_Control(pDX, IDC_EDIT_NUM, m_Edit_Num);
DDX_Control(pDX, IDC_COMBO_HOSPITAL, m_Combo_Hospital);
DDX_Control(pDX, IDC_COMBO_UNIT, m_Combo_Unit);
DDX_Control(pDX, IDC_EDIT_MAIN, m_Edit_Main);
DDX_Control(pDX, IDC_DATAGRID, m_DataGrid);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CNewBillDlg, CDialog)
//{{AFX_MSG_MAP(CNewBillDlg)
ON_CBN_SELCHANGE(IDC_COMBO_HOSPITAL, OnSelchangeComboHospital)
ON_NOTIFY(DTN_DATETIMECHANGE, IDC_DATETIMEPICKER1, OnDatetimechangeDatetimepicker1)
ON_CBN_EDITCHANGE(IDC_COMBO_HOSPITAL, OnEditchangeComboHospital)
ON_BN_CLICKED(IDC_BUTTON_NEW, OnButtonNew)
ON_CBN_EDITCHANGE(IDC_COMBO_PRICE, OnEditchangeComboPrice)
ON_EN_CHANGE(IDC_EDIT_NUM, OnChangeEditNum)
ON_BN_CLICKED(IDC_BUTTON_NAME, OnButtonName)
ON_CBN_EDITCHANGE(IDC_COMBO_NAME, OnEditchangeComboName)
ON_CBN_EDITCHANGE(IDC_COMBO_PLANT, OnEditchangeComboPlant)
ON_CBN_SELCHANGE(IDC_COMBO_NAME, OnSelchangeComboName)
ON_BN_CLICKED(IDC_BUTTON_PLANT, OnButtonPlant)
ON_BN_CLICKED(IDC_BUTTON_DEL, OnButtonDel)
ON_EN_CHANGE(IDC_EDIT_YEAR, OnChangeEditYear)
ON_CBN_EDITCHANGE(IDC_COMBO_SERIALNUM, OnEditchangeComboSerialNum)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CNewBillDlg message handlers
BOOL CNewBillDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// TODO: Add extra initialization here
//---------------------------------------------------------
this->InitUnit ();
this->InitHospital ();
this->m_Edit_Main .SetWindowText ("山东临沂药材采购供应站商品发货单");
this->GetDlgItem(IDC_COMBO_NO)->SetWindowText("000000003965");
this->GetDlgItem(IDC_COMBO_WAREHOUSE)->SetWindowText("总公司仓库(N)");
this->GetDlgItem(IDC_DATAGRID)->SetWindowText("");
(CButton *)GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(FALSE);
GetDlgItem(IDC_COMBO_NAME)->EnableWindow(FALSE);
GetDlgItem(IDC_COMBO_PLANT)->EnableWindow(FALSE);
GetDlgItem(IDC_COMBO_UNIT)->EnableWindow(FALSE);
GetDlgItem(IDC_COMBO_PRICE)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_NUM)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_TOTAL)->EnableWindow(FALSE);
GetDlgItem(IDC_COMBO_SERIALNUM)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_PIHAO)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_YEAR)->EnableWindow(FALSE);
GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(FALSE);
GetDlgItem(IDC_DATAGRID)->EnableWindow(FALSE);
//GetDlgItem(IDC_EDIT_TOTAL)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_YEAR)->SetWindowText("-");
this->InitDataGrid ();
//---------------------------------------------------------
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
int CNewBillDlg::InitUnit()
{
HRESULT hr;
CString str;
if(p_MyRstNewBill->GetState()==adStateOpen) p_MyRstNewBill->Close();
try
{
hr=p_MyRstNewBill->Open (_variant_t("药品单位"),
_variant_t((IDispatch *)p_MyConNewBill,true),
adOpenKeyset,
adLockOptimistic,
adCmdTable
);
if(FAILED(hr))
{
CWnd::MessageBox ("记录集打开失败");
}
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
return 4;
}
if(p_MyRstNewBill->BOF ==TRUE&&p_MyRstNewBill->adoEOF ==TRUE)
{
CWnd::MessageBox ("数据库中没有记录!");
return -1;
}
int i_RecordNum =p_MyRstNewBill->RecordCount ;
if(i_RecordNum>0)
{
p_MyRstNewBill->MoveFirst ();
}
while(p_MyRstNewBill->adoEOF==VARIANT_FALSE)
{
if(p_MyRstNewBill->Fields ->GetItem (_variant_t("单位"))->Value.vt!=VT_NULL)
{
str=(char *)(_bstr_t)(p_MyRstNewBill->Fields ->GetItem (_variant_t("单位"))->Value);
}
else
{
//p_MyRstNewBill->Fields ->GetItem (_variant_t("pwd"))->Value=_variant_t(str_ChangePwd);
}
this->m_Combo_Unit.AddString (str);
p_MyRstNewBill->MoveNext ();
}
//p_MyRstNewBill->Update ();
if(p_MyRstNewBill->GetState()==adStateOpen) p_MyRstNewBill->Close();
return 0;
}
void CNewBillDlg::InitHospital()
{
HRESULT hr;
CString str;
if(p_MyRstNewBill->GetState()==adStateOpen) p_MyRstNewBill->Close();
try
{
hr=p_MyRstNewBill->Open (_variant_t("购货单位"),
_variant_t((IDispatch *)p_MyConNewBill,true),
adOpenKeyset,
adLockOptimistic,
adCmdTable
);
if(FAILED(hr))
{
CWnd::MessageBox ("记录集打开失败");
}
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
}
if(p_MyRstNewBill->BOF ==TRUE&&p_MyRstNewBill->adoEOF ==TRUE)
{
CWnd::MessageBox ("数据库中没有记录!");
}
int i_RecordNum =p_MyRstNewBill->RecordCount ;
if(i_RecordNum>0)
{
p_MyRstNewBill->MoveFirst ();
}
while(p_MyRstNewBill->adoEOF==VARIANT_FALSE)
{
if(p_MyRstNewBill->Fields ->GetItem (_variant_t("购货单位"))->Value.vt!=VT_NULL)
{
str=(char *)(_bstr_t)(p_MyRstNewBill->Fields ->GetItem (_variant_t("购货单位"))->Value);
}
else
{
//p_MyRstNewBill->Fields ->GetItem (_variant_t("pwd"))->Value=_variant_t(str_ChangePwd);
}
this->m_Combo_Hospital .AddString (str);
p_MyRstNewBill->MoveNext ();
}
if(p_MyRstNewBill->GetState()==adStateOpen) p_MyRstNewBill->Close();
//p_MyRstNewBill->Update ();
}
void CNewBillDlg::OnSelchangeComboHospital()
{
// TODO: Add your control notification handler code here
this->LetEnable ();
this->InitDataGrid ();
//GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(TRUE);
}
void CNewBillDlg::OnDatetimechangeDatetimepicker1(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
//-------------------------
//this->MessageBox ("^_^");
this->LetEnable ();
this->InitDataGrid ();
*pResult = 0;
}
void CNewBillDlg::OnEditchangeComboHospital()
{
// TODO: Add your control notification handler code here
//this->MessageBox ("^_^^_^");
CString str;
this->m_Combo_Hospital.GetWindowText (str);
//if(str_Hospital.GetLength() >0)
//{
// CMyClass::s_HospitalName =str_Hospital;
// m_DateTimeCtrl_DateTime .GetWindowText(CMyClass::s_DateTime );
//}
if(str!="")
this->LetEnable ();
//GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(TRUE);
else
this->LetDisable ();
this->InitDataGrid ();
//GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(FALSE);
}
void CNewBillDlg::LetDisable()
{
(CButton *)GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(FALSE);
GetDlgItem(IDC_COMBO_NAME)->EnableWindow(FALSE);
GetDlgItem(IDC_COMBO_PLANT)->EnableWindow(FALSE);
GetDlgItem(IDC_COMBO_UNIT)->EnableWindow(FALSE);
GetDlgItem(IDC_COMBO_PRICE)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_NUM)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_TOTAL)->EnableWindow(FALSE);
GetDlgItem(IDC_COMBO_SERIALNUM)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_PIHAO)->EnableWindow(FALSE);
GetDlgItem(IDC_EDIT_YEAR)->EnableWindow(FALSE);
GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(FALSE);
GetDlgItem(IDC_DATAGRID)->EnableWindow(FALSE);
}
void CNewBillDlg::LetEnable()
{
(CButton *)GetDlgItem(IDC_BUTTON_NEW)->EnableWindow(TRUE);
GetDlgItem(IDC_COMBO_NAME)->EnableWindow(TRUE);
GetDlgItem(IDC_COMBO_PLANT)->EnableWindow(TRUE);
GetDlgItem(IDC_COMBO_UNIT)->EnableWindow(TRUE);
GetDlgItem(IDC_COMBO_PRICE)->EnableWindow(TRUE);
GetDlgItem(IDC_EDIT_NUM)->EnableWindow(TRUE);
GetDlgItem(IDC_EDIT_TOTAL)->EnableWindow(TRUE);
GetDlgItem(IDC_COMBO_SERIALNUM)->EnableWindow(TRUE);
GetDlgItem(IDC_EDIT_PIHAO)->EnableWindow(TRUE);
GetDlgItem(IDC_EDIT_YEAR)->EnableWindow(TRUE);
GetDlgItem(IDC_DATETIMEPICKER1)->EnableWindow(TRUE);
GetDlgItem(IDC_DATAGRID)->EnableWindow(TRUE);
}
void CNewBillDlg::OnButtonNew()
{
HRESULT hr;
// TODO: Add your control notification handler code here
//CString str_Name;//商品名称
//CString str_Plant;//生产厂家
//CString str_Unit;//单位-〉板,盒等
//CString str_Num;//数量
//CString str_Price;//金额单价
//CString str_TotalNum;//总金额
//CString str_SerialNum;//药品编号
//CString str_PiHao;//商品批号
//CString str_Year;//有效期
//CString str_Hospital;//医院名称
//CString str_DateTime;//开票日期
//CString str_NO_;//编号NO.=00000003956等
//CString str_WareHouse;//仓库
CString str_Temp;//临时变量
this->m_Combo_Name.GetWindowText (str_Name);//商品名称
this->m_Combo_Plant .GetWindowText (str_Plant);//生产厂家
this->m_Combo_Unit .GetWindowText (str_Unit);//单位-〉板,盒等
this->m_Edit_Num .GetWindowText (str_Num);//数量
this->m_Combo_Price .GetWindowText (str_Price);//金额单价
this->m_Edit_Total .GetWindowText (str_TotalNum);//总金额
this->m_Combo_SerialNum .GetWindowText (str_SerialNum);//药品编号
this->m_Edit_PiHao .GetWindowText (str_PiHao);//商品批号
this->m_Edit_Year .GetWindowText (str_Year);//有效期
this->m_Combo_Hospital .GetWindowText (str_Hospital);//医院名称
this->m_DateTimeCtrl_DateTime .GetWindowText (str_DateTime);//开票日期
this->m_Combo_NO_ .GetWindowText (str_NO_);//编号NO.=00000003956等
this->m_Combo_WareHouse .GetWindowText (str_WareHouse);//仓库
if(str_Name.GetLength ()==0)
{
this->MessageBox ("药品名称不能为空!");
return;
}
if(str_Plant.GetLength ()==0)
{
this->MessageBox ("生产厂商不能为空!");
return;
}
if(str_Unit.GetLength ()==0)
{
this->MessageBox ("药品单位不能为空!");
return;
}
if(str_Num.GetLength ()==0)
{
this->MessageBox ("药品数量不能为空!");
return;
}
if(str_Price.GetLength ()==0)
{
this->MessageBox ("单价不能为空!");
return;
}
if(str_TotalNum.GetLength ()==0)
{
this->MessageBox ("总金额不能为空!");
return;
}
if(str_SerialNum.GetLength ()==0)
{
this->MessageBox ("药品编号不能为空!");
return;
}
if(str_PiHao.GetLength ()==0)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -