📄 newbilldlg.cpp
字号:
try
{
if(p_MyRstNewBill->GetState()==adStateOpen) p_MyRstNewBill->Close();
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
}
str.Format ("select 拼音,生产厂家,药品编号 from 药品名称 where 药品名称='%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 ("数据库中没有记录!");
return;
}
int i_RecordNum =p_MyRstNewBill->RecordCount ;
if(i_RecordNum>0)
{
p_MyRstNewBill->MoveFirst ();
}
str="";
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);
this->m_Combo_Plant .AddString (str);
}
//else
//{
//p_MyRstNewBill->Fields ->GetItem (_variant_t("pwd"))->Value=_variant_t(str_ChangePwd);
//}
//将数据写入到药品编号下拉框中
str="";
if(p_MyRstNewBill->Fields ->GetItem (_variant_t("药品编号"))->Value.vt!=VT_NULL)
{
str=(char *)(_bstr_t)(p_MyRstNewBill->Fields ->GetItem (_variant_t("药品编号"))->Value);
this->m_Combo_SerialNum .AddString (str);
}
//else
//{
//p_MyRstNewBill->Fields ->GetItem (_variant_t("pwd"))->Value=_variant_t(str_ChangePwd);
//}
p_MyRstNewBill->MoveNext ();
}
if(p_MyRstNewBill->GetState()==adStateOpen)
p_MyRstNewBill->Close();
}
//DEL void CNewBillDlg::OnMenuNew()
//DEL {
//DEL // TODO: Add your command handler code here
//DEL
//DEL }
void CNewBillDlg::InitDataGrid()
{
HRESULT hr;
CString str;
int i;
double double_Money=0.0;
try
{
if(p_MyRstDBNewBill->GetState()==adStateOpen) p_MyRstDBNewBill->Close();
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
}
i=m_Combo_Hospital .GetCurSel ();
str_Hospital="";
if(i!=-1)
{
m_Combo_Hospital.GetLBText(i,str_Hospital);
}
m_DateTimeCtrl_DateTime.GetWindowText (str_DateTime);//前面不要加"this->"
if(str_Hospital.GetLength ()==0)
str.Format ("select * from 打印单据 where 日期= '%s'",str_DateTime);
else
str.Format ("select * from 打印单据 where 购货单位= '%s' and 日期= '%s' and 打印='N'",str_Hospital,str_DateTime);
try
{
hr=p_MyRstDBNewBill->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 ());
}
//this->MessageBox ("OK ^_^");
//更新表格
this->m_DataGrid .SetRefDataSource(p_MyRstDBNewBill);
i=p_MyRstDBNewBill->GetRecordCount ();//得到数据库中的记录条数
if(i)
{
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);
// m_DataGrid.GetColumns().GetItem(_variant_t("")).SetWidth(30.0);
}
while(p_MyRstDBNewBill->adoEOF==VARIANT_FALSE)
{
if(p_MyRstDBNewBill->Fields ->GetItem (_variant_t("金额"))->Value.vt!=VT_NULL)
{
str=(char *)(_bstr_t)(p_MyRstDBNewBill->Fields ->GetItem (_variant_t("金额"))->Value);
double_Money+=atof(str);
}
p_MyRstDBNewBill->MoveNext ();
}
if(i<0) i=0;
str.Format ("共 %d 条记录,分为 %d 页,总金额为 ¥%.2f 元",i,i%8==0?i/8:i/8+1,double_Money);
m_Edit_Note.SetWindowText (str);
//this->MessageBox ("OK ^_^");
}
void CNewBillDlg::OnButtonPlant()
{
// TODO: Add your control notification handler code here
CString str;
if(this->m_Combo_Plant .IsWindowEnabled())
{
CMyDlgName dlgname;
dlgname.p_MyCon =this->p_MyConNewBill;
dlgname.str_Name ="生产厂家";
dlgname.p_str =&str;
dlgname.DoModal ();
this->m_Combo_Plant .SetWindowText (str);
//this->SetName ();
}
else
m_Combo_Plant.SetWindowText ("");
}
void CNewBillDlg::OnButtonDel()
{
// TODO: Add your control notification handler code here
//this->MessageBox ("您确定要删除这一条信息吗?","警告!",MB_YESNO);
try
{
if(p_MyRstDBNewBill->GetState()==adStateOpen &&p_MyRstDBNewBill->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 ());
}
try
{
if(p_MyRstDBNewBill->GetState()==adStateOpen) //p_MyRstDBNewBill->Close();
p_MyRstDBNewBill->Delete(adAffectCurrent);
p_MyRstDBNewBill->Update ();
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
}
this->InitDataGrid ();
//this->MessageBox ("OK ^_^");
}
void CNewBillDlg::OnOK()
{
// TODO: Add extra validation here
//int iiii=this->m_DataGrid.GetCol ();
if(2==this->MessageBox ("你确定要退出? ","提示",MB_OKCANCEL|MB_ICONINFORMATION))
{//2-取消按钮,1-确定按钮
return;
}
this->m_Combo_Hospital.GetWindowText (str_Hospital );
CMyClass::s_HospitalName =str_Hospital;
try
{
//if(p_MyRstDBNewBill->GetState()==adStateOpen &&str_Hospital.GetLength()) //p_MyRstDBNewBill->Close();
if(p_MyRstDBNewBill->GetState()==adStateOpen && p_MyRstDBNewBill->GetRecordCount ()>0 && str_Hospital.GetLength()>0) //p_MyRstDBNewBill->Close();
{
//CMyClass::s_HospitalName =str_Hospital;
m_DateTimeCtrl_DateTime .GetWindowText(CMyClass::s_DateTime );
this->m_Combo_NO_ .GetWindowText (CMyClass::s_NO_ );
this->m_Combo_WareHouse .GetWindowText (CMyClass::s_WareHouse);
}
else
{
CMyClass::s_HospitalName ="";
CMyClass::s_DateTime="";
CMyClass::s_NO_ ="";
CMyClass::s_WareHouse ="";
}
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
}
CDialog::OnOK();
}
void CNewBillDlg::OnChangeEditYear()
{
// 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;
this->m_Edit_Year .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 ("^_^");
return;
}
else
{
//this->m_Edit_Year .GetWindowText (str);
//str=str.Left (str.GetLength()-1);
//m_Edit_Year.SetWindowText(str);
m_Edit_Year.Undo();
Beep(300,200);
}
}
void CNewBillDlg::OnEditchangeComboSerialNum()
{
// TODO: Add your control notification handler code here
//this->m_Combo_SerialNum.ResetContent ();
}
void CNewBillDlg::SetName()
{
HRESULT hr;
CString str,str_Name;
//this->UpdateData ();
// if(int i=this->m_Combo_Name .GetCurSel ()>=0)
//{
// this->m_Combo_Name .GetLBText (this->m_Combo_Name .GetCurSel (),str_Name);
//}
//else
//{
m_Combo_Name.GetWindowText (str_Name);
//}
this->m_Combo_Plant.ResetContent ();
this->m_Combo_SerialNum .ResetContent ();
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 药品名称='%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 ("数据库中没有记录!");
return;
}
int i_RecordNum =p_MyRstNewBill->RecordCount ;
if(i_RecordNum>0)
{
p_MyRstNewBill->MoveFirst ();
}
str="";
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);
this->m_Combo_Plant .AddString (str);
}
//else
//{
//p_MyRstNewBill->Fields ->GetItem (_variant_t("pwd"))->Value=_variant_t(str_ChangePwd);
//}
//将数据写入到药品编号下拉框中
str="";
if(p_MyRstNewBill->Fields ->GetItem (_variant_t("药品编号"))->Value.vt!=VT_NULL)
{
str=(char *)(_bstr_t)(p_MyRstNewBill->Fields ->GetItem (_variant_t("药品编号"))->Value);
this->m_Combo_SerialNum .AddString (str);
}
//else
//{
//p_MyRstNewBill->Fields ->GetItem (_variant_t("pwd"))->Value=_variant_t(str_ChangePwd);
//}
p_MyRstNewBill->MoveNext ();
}
if(p_MyRstNewBill->GetState()==adStateOpen)
p_MyRstNewBill->Close();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -