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

📄 newbilldlg.cpp

📁 从列表进行打印的源码,请大家下载参考对照,从中发表意见,加深修改.
💻 CPP
📖 第 1 页 / 共 3 页
字号:
		this->MessageBox ("商品批号不能为空!");
		return;
	}
	if(str_Year.GetLength ()==0)
	{
		this->MessageBox ("有效期不能为空!");
		return;
	}
	if(str_Hospital.GetLength ()==0)
	{
		this->MessageBox ("医院名称不能为空!");
		return;
	}

	if(str_DateTime.GetLength ()==0)
	{
		this->MessageBox ("开票日期不能为空!");
		return;
	}
	if(str_NO_.GetLength ()==0)
	{
		this->MessageBox ("单据的编号不能为空!");
		return;
	}
	if(str_WareHouse.GetLength ()==0)
	{
		this->MessageBox ("仓库不能为空!");
		return;
	}

	//操作数据库
	try
	{
		if(p_MyRstNewBill->GetState()==adStateOpen) p_MyRstNewBill->Close();
	}
	catch(_com_error &err)
	{
		CWnd::MessageBox (err.Description ());
	}
	
	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 ());
	}

	//this->MessageBox ("OK    ^_^");
	try
	{
		this->p_MyRstNewBill ->AddNew ();
		p_MyRstNewBill->PutCollect (_variant_t("购货单位"),_variant_t(str_Hospital));
		p_MyRstNewBill->PutCollect (_variant_t("日期"),_variant_t(str_DateTime));
		p_MyRstNewBill->PutCollect (_variant_t("NO"),_variant_t(str_NO_));
		p_MyRstNewBill->PutCollect (_variant_t("仓库"),_variant_t(str_WareHouse));
		p_MyRstNewBill->PutCollect (_variant_t("药品编号"),_variant_t(str_SerialNum));
		p_MyRstNewBill->PutCollect (_variant_t("商品名称"),_variant_t(str_Name));
		p_MyRstNewBill->PutCollect (_variant_t("生产厂家"),_variant_t(str_Plant));
		p_MyRstNewBill->PutCollect (_variant_t("单位"),_variant_t(str_Unit));
		p_MyRstNewBill->PutCollect (_variant_t("数量"),_variant_t(str_Num));
		p_MyRstNewBill->PutCollect (_variant_t("单价"),_variant_t(str_Price));
		p_MyRstNewBill->PutCollect (_variant_t("金额"),_variant_t(str_TotalNum));
		p_MyRstNewBill->PutCollect (_variant_t("商品批号"),_variant_t(str_PiHao));
		p_MyRstNewBill->PutCollect (_variant_t("有效期"),_variant_t(str_Year));
		p_MyRstNewBill->PutCollect (_variant_t("打印"),_variant_t("N"));
		//p_MyRstNewBill->PutCollect (_variant_t(""),_variant_t(str_));
		
		p_MyRstNewBill->Update();

		
	}//end try
	catch(_com_error &err)
	{
		CWnd::MessageBox (err.Description ()+"\n你填写的信息有错误!(wklh12-1012)");
	}

	try
	{
		if(p_MyRstNewBill->GetState()==adStateOpen) p_MyRstNewBill->Close();
	}
	catch(_com_error &err)
	{
		CWnd::MessageBox (err.Description ());
		return;
	}
//更新表格
	this->InitDataGrid ();
	this->m_Combo_Name.SetWindowText("");//商品名称
	this->m_Combo_Plant .SetWindowText("");//生产厂家
	this->m_Combo_Unit .SetWindowText ("");//单位-〉板,盒等
	this->m_Edit_Num .SetWindowText ("");//数量
	this->m_Combo_Price .SetWindowText ("");//金额单价
	this->m_Edit_Total .SetWindowText ("");//总金额
	this->m_Combo_SerialNum .SetWindowText ("");//药品编号
	this->m_Edit_PiHao .SetWindowText ("");//商品批号
/*	m_DataGrid .SetRefDataSource(p_MyRstNewBill);
	m_DataGrid.GetColumns().GetItem(_variant_t("购货单位")).SetWidth(60.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("日期")).SetWidth(60.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("NO")).SetWidth(40.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("仓库")).SetWidth(40.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("药品编号")).SetWidth(50.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("商品名称")).SetWidth(100.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("生产厂家")).SetWidth(70.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("单位")).SetWidth(30.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("数量")).SetWidth(40.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("单价")).SetWidth(50.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("金额")).SetWidth(60.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("商品批号")).SetWidth(40.0);
	m_DataGrid.GetColumns().GetItem(_variant_t("有效期")).SetWidth(30.0);
	
	m_DataGrid.GetColumns().GetItem(_variant_t("备注")).SetWidth(0.0);
//	m_DataGrid.GetColumns().GetItem(_variant_t("")).SetWidth(30.0);
*/
	//this->MessageBox ("OK    ^_^");

}

void CNewBillDlg::OnEditchangeComboPrice() 
{
	// TODO: Add your control notification handler code here
	CString str_Price,str_Num,str;
	int i_Num=0;
	double d_Price=0.0,d_TotalNum=0.0;

	this->m_Combo_Price .GetWindowText (str);
	str=str.Right (1);
	
	if(str=="."||str=="-"||str=="0"||str=="1"||str=="2"||str=="3"||str=="4"||str=="5"||str=="6"||str=="7"||str=="8"||str=="9")
	{
		//this->MessageBox ("^_^");
		//continue;
		//return;
	}
	else
	{
		this->m_Combo_Price .GetWindowText (str);
		str=str.Left (str.GetLength()-1);
		m_Combo_Price.SetWindowText(str);
		//m_Combo_Price.
		Beep(300,200);
	}

	
	this->m_Combo_Price.GetWindowText (str_Price); 
	this->m_Edit_Num .GetWindowText (str_Num);
	//str_Price.Format ("%d",i_Num);
	//str_Num.Format ("%f",d_Price);
	i_Num=atoi(str_Num);
	d_Price=atof(str_Price);
	d_TotalNum=i_Num*d_Price;
	str.Format("%.2f",d_TotalNum);
	this->m_Edit_Total .SetWindowText (str);
}

void CNewBillDlg::OnChangeEditNum() 
{
	// TODO: If this is a RICHEDIT control, the control will not
	// send this notification unless you override the CDialog::OnInitDialog()
	// function and call CRichEditCtrl().SetEventMask()
	// with the ENM_CHANGE flag ORed into the mask.
	
	// TODO: Add your control notification handler code here
	CString str_Price,str_Num,str;
	int i_Num=0;
	double d_Price=0.0,d_TotalNum=0.0;
	this->m_Combo_Price.GetWindowText (str_Price); 
	this->m_Edit_Num .GetWindowText (str_Num);
	//str_Price.Format ("%d",i_Num);
	//str_Num.Format ("%f",d_Price);
	i_Num=atoi(str_Num);
	d_Price=atof(str_Price);
	d_TotalNum=i_Num*d_Price;
	str.Format("%.2f",d_TotalNum);
	this->m_Edit_Total .SetWindowText (str);
}

void CNewBillDlg::OnButtonName() 
{
	// TODO: Add your control notification handler code here
	CString str;
	
	if(this->m_Combo_Name .IsWindowEnabled ())
	{
		CMyDlgName dlgname;
		dlgname.p_MyCon =this->p_MyConNewBill;
		dlgname.str_Name ="商品名称";
		dlgname.p_str =&str;
		dlgname.DoModal ();
		this->m_Combo_Name .SetWindowText (str);
		this->SetName ();
	}
	else
		this->m_Combo_Name .SetWindowText ("");
}

void CNewBillDlg::OnEditchangeComboName() 
{
	// TODO: Add your control notification handler code here
	//this->MessageBox ("wklh12-2");
	//this->m_Combo_Name.ResetContent ();
	CString str_Name;
	this->m_Combo_Name .GetWindowText (str_Name);
	this->m_Combo_Name.ResetContent ();
	this->m_Combo_Name .SetWindowText (str_Name);
	this->InitName (str_Name);
	
	this->m_Combo_Name.ShowDropDown ();
	Sleep(50);
	//this->m_Combo_Name .GetActiveWindow ();
	this->m_Combo_Name.SetFocus ();
	
		

}

void CNewBillDlg::InitName(CString str_Name)
{
	HRESULT hr;
	CString str;
	if(str_Name.GetLength ()==0)
	{
		str_Name="a";
	}

	try
	{
		if(p_MyRstNewBill->GetState()==adStateOpen) 
			p_MyRstNewBill->Close();
	}
	catch(_com_error &err)
	{
		CWnd::MessageBox (err.Description ());
	}
	
	str.Format ("select 拼音,药品名称 from 药品名称 where 拼音 like '%s%%'  ORDER BY 拼音 DESC",str_Name);
//	str.Format ("select 拼音 from 药品名称 ORDER BY 拼音 DESC");
	
	try
	{
		hr=p_MyRstNewBill->Open (_variant_t(str),
			_variant_t((IDispatch *)p_MyConNewBill,true),
			adOpenKeyset,
			adLockOptimistic,
			adCmdText
			);
		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_Name .AddString (str);
		p_MyRstNewBill->MoveNext ();
	}
	
	if(p_MyRstNewBill->GetState()==adStateOpen) p_MyRstNewBill->Close();
	
		//p_MyRstNewBill->Update ();


}

void CNewBillDlg::OnEditchangeComboPlant() 
{
	// TODO: Add your control notification handler code here
	CString str_Plant;
	this->m_Combo_Plant .GetWindowText (str_Plant);
	this->m_Combo_Plant.ResetContent ();
	this->m_Combo_Plant .SetWindowText (str_Plant);
	this->InitPlant (str_Plant);

	this->m_Combo_Plant.ShowDropDown ();
	Sleep(50);
	this->m_Combo_Plant .SetFocus ();

}

void CNewBillDlg::InitPlant(CString str_Plant)
{
	HRESULT hr;
	CString str;
	if(str_Plant.GetLength ()==0)
	{
		str_Plant="a";
	}

	try
	{
		if(p_MyRstNewBill->GetState()==adStateOpen) p_MyRstNewBill->Close();
	}
	catch(_com_error &err)
	{
		CWnd::MessageBox (err.Description ());
	}
	
	str.Format ("select 拼音,生产厂家 from 生产厂家 where 拼音 like '%s%%'  ORDER BY 拼音 DESC",str_Plant);
//	str.Format ("select 拼音 from 药品名称 ORDER BY 拼音 DESC");
	
	try
	{
		hr=p_MyRstNewBill->Open (_variant_t(str),
			_variant_t((IDispatch *)p_MyConNewBill,true),
			adOpenKeyset,
			adLockOptimistic,
			adCmdText
			);
		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_Plant .AddString (str);
		p_MyRstNewBill->MoveNext ();
	}
	
	if(p_MyRstNewBill->GetState()==adStateOpen) p_MyRstNewBill->Close();
	
		//p_MyRstNewBill->Update ();

}

void CNewBillDlg::OnSelchangeComboName() 
{
	// TODO: Add your control notification handler code here
	//this->MessageBox ("wklh12-3");
	HRESULT hr;
	CString str,str_Name;
	this->UpdateData ();
	this->m_Combo_Name .GetLBText (this->m_Combo_Name .GetCurSel (),str_Name);
	this->m_Combo_Plant.ResetContent ();
	this->m_Combo_SerialNum .ResetContent ();

	if(str_Name.GetLength ()==0)
		str_Name="a";

⌨️ 快捷键说明

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