📄 myprinterdlg.cpp
字号:
{
CWnd::MessageBox ("_RecordsetPtr初始化错误!");
return 3;
}
hr=p_MyRstTemp.CreateInstance(_uuidof(Recordset));
if(FAILED(hr))
{
CWnd::MessageBox ("_RecordsetPtr初始化错误!");
return 4;
}
//打开记录集
/* try
{
hr=p_MyRst->Open (_variant_t("打印单据"),
_variant_t((IDispatch *)p_MyCon,true),
adOpenKeyset,
adLockOptimistic,
adCmdTable
);
if(FAILED(hr))
{
CWnd::MessageBox ("记录集打开失败");
}
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
return 4;
}
//long l=this->GetRecorNum ();
if(p_MyRst->BOF ==TRUE&&p_MyRst->adoEOF ==TRUE)
{
CWnd::MessageBox ("数据库中没有记录!");
return -1;
}
*/
return 0;
}
void CMyPrinterDlg::OnMenuNew()
{
// TODO: Add your command handler code here
CNewBillDlg newbilldlg;
newbilldlg.p_MyConNewBill =this->p_MyCon ;
newbilldlg.DoModal ();
if(CMyClass::s_HospitalName .GetLength ()>0 && CMyClass::s_DateTime .GetLength ()>0)
{
this->m_Edit_Hospital.ShowWindow (TRUE);
this->m_Edit_Hospital.SetWindowText (CMyClass::s_HospitalName);
this->m_Edit_Hospital .EnableWindow (FALSE);
int i1,i2,i3;
CString str1,str2,str3;
str1=CMyClass::s_DateTime.Left(4);
i1=atoi(str1);
str2=CMyClass::s_DateTime.Mid(5,2);
if(str2.Right (1)=="-")
{
str2=str2.Left (1);
}
i2=atoi(str2);
str3=CMyClass::s_DateTime.Right (2);
if(str3.Left (1)=="-")
{
str3=str3.Right (1);
}
i3=atoi(str3);
CTime m_time(i1,i2,i3,0,0,0);
m_DateTime.SetTime(&m_time);
this->m_Combo_Hospital .EnableWindow (FALSE);
this->m_Combo_Hospital .ShowWindow(FALSE);
this->m_Combo_NO_ .EnableWindow (FALSE);
this->m_Combo_WareHouse .EnableWindow (FALSE);
this->m_DateTime .EnableWindow (FALSE);
(CButton *)GetDlgItem(IDC_BUTTON_SURE)->EnableWindow(FALSE);
(CButton *)GetDlgItem(IDC_BUTTON_REFRESH)->EnableWindow(FALSE);
this->InitDataGrid ();
this->m_Combo_NO_ .SetWindowText (CMyClass::s_NO_ );
this->m_Combo_WareHouse .SetWindowText (CMyClass::s_WareHouse );
}
//this->InitDataGrid ();
//this->MessageBox("mmm");
}
int CMyPrinterDlg::FindDB(CString &str)
{
CString str_DB;
char c_Path[MAX_PATH];
GetModuleFileName(NULL,c_Path,MAX_PATH);//str_DB.GetBufferSetLength (MAX_PATH+1)
str_DB=(CString)c_Path;
//GetCurrentDirectory(MAX_PATH,c_Path);
// strcpy(c_Path, __argv[0]);
// char buffer[_MAX_PATH];
// _getcwd( buffer, _MAX_PATH );
// GetModuleFileName(NULL, filename, MAX_PATH); // 获取应用程序路径
//LPCTSTR aa=AfxGetAppName();
str = CString(str_DB); //设定当前目录下的子目录PLUGINS
long lll=CString(AfxGetAppName()).GetLength();
lll=str_DB.GetLength();
str = str_DB.Left(str_DB.GetLength() - CString(AfxGetAppName()).GetLength()-4);//+ CString("PLUGINS");
//CString strFindFile = strPath + "\\*.dll";
//str=buffer;
return 0;
}
int CMyPrinterDlg::TrimDBPath(CString &str)
{
if(str=="")
{
CWnd::MessageBox ("目录出错");
return -1;
}
CString str_Temp,str_1;
int i_PathLength=0;
str_1=str;
str="";
i_PathLength=str_1.GetLength ();
for(int i=0;i<i_PathLength;i++)
{
str_Temp=str_1.Mid (i,1);
if(str_Temp[0]!=92)
{
str+=str_Temp;
}
else
{
str=str+str_Temp+str_Temp;
}
}
if(str.Right (1)!=92)
str=str+"\\" +"\\" +"database"+"\\" +"\\"+"db.mdb";
else
str=str+"database"+"\\"+"\\" +"db.mdb";
return 0;
}
void CMyPrinterDlg::InitDataGrid()
{
HRESULT hr;
CString str;
int i;
double double_Money=0.0;
try
{
if(this->p_MyRst ->GetState()==adStateOpen)
p_MyRst->Close();
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
}
if(m_Combo_Hospital.IsWindowVisible ())
{
i=m_Combo_Hospital .GetCurSel ();
if(i!=-1)
{
m_Combo_Hospital.GetLBText(i,CMyClass::s_HospitalName );
}
else
CMyClass::s_HospitalName="";
}
else
{
this->m_Edit_Hospital .GetWindowText (CMyClass::s_HospitalName);
}
m_DateTime.GetWindowText (CMyClass::s_DateTime );//前面不要加"this->"
if(CMyClass::s_HospitalName.GetLength ()==0)
str.Format ("select * from 打印单据 where 日期= '%s'",CMyClass::s_DateTime);
else
str.Format ("select * from 打印单据 where 购货单位= '%s' and 日期= '%s' and 打印='N'",CMyClass::s_HospitalName,CMyClass::s_DateTime);
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_Main .SetRefDataSource(p_MyRst);
i=p_MyRst->GetRecordCount ();
if(i)
{
m_DataGrid_Main.GetColumns().GetItem(_variant_t("购货单位")).SetWidth(60.0);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("日期")).SetWidth(60.0);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("NO")).SetWidth(40.0);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("仓库")).SetWidth(40.0);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("药品编号")).SetWidth(50.0);
m_DataGrid_Main.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);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("数量")).SetWidth(40.0);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("单价")).SetWidth(50.0);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("金额")).SetWidth(60.0);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("商品批号")).SetWidth(40.0);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("有效期")).SetWidth(30.0);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("备注")).SetWidth(0.0);
m_DataGrid_Main.GetColumns().GetItem(_variant_t("打印")).SetWidth(30.0);
// m_DataGrid.GetColumns().GetItem(_variant_t("")).SetWidth(30.0);
}
while(p_MyRst->adoEOF==VARIANT_FALSE)
{
if(p_MyRst->Fields ->GetItem (_variant_t("金额"))->Value.vt!=VT_NULL)
{
str=(char *)(_bstr_t)(p_MyRst->Fields ->GetItem (_variant_t("金额"))->Value);
double_Money+=atof(str);
}
p_MyRst->MoveNext ();
}
if(i<0) i=0;
str.Format ("共 %d 条记录,分为 %d 页, 总金额为 ¥%.2f 元",i,i%8==0?i/8:i/8+1,double_Money);
this->m_Static_Text .SetWindowText (str);
}
void CMyPrinterDlg::OnButtonRefresh()
{
// TODO: Add your control notification handler code here
this->m_Combo_Hospital .GetWindowText (CMyClass::s_HospitalName );
this->m_DateTime .GetWindowText(CMyClass::s_DateTime );
this->InitDataGrid ();
}
void CMyPrinterDlg::OnButtonSure()
{
// TODO: Add your control notification handler code here
}
void CMyPrinterDlg::InitHospital()
{
HRESULT hr;
CString str;
if(p_MyRstTemp->GetState()==adStateOpen) p_MyRstTemp->Close();
try
{
hr=p_MyRstTemp->Open (_variant_t("购货单位"),
_variant_t((IDispatch *)p_MyCon,true),
adOpenKeyset,
adLockOptimistic,
adCmdTable
);
if(FAILED(hr))
{
CWnd::MessageBox ("记录集打开失败");
}
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
}
if(p_MyRstTemp->BOF ==TRUE&&p_MyRstTemp->adoEOF ==TRUE)
{
CWnd::MessageBox ("数据库中没有记录!");
}
int i_RecordNum =p_MyRstTemp->RecordCount ;
if(i_RecordNum>0)
{
p_MyRstTemp->MoveFirst ();
}
while(p_MyRstTemp->adoEOF==VARIANT_FALSE)
{
if(p_MyRstTemp->Fields ->GetItem (_variant_t("购货单位"))->Value.vt!=VT_NULL)
{
str=(char *)(_bstr_t)(p_MyRstTemp->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_MyRstTemp->MoveNext ();
}
if(p_MyRstTemp->GetState()==adStateOpen) p_MyRstTemp->Close();
}
void CMyPrinterDlg::OnButtonDel()
{
// TODO: Add your control notification handler code here
try
{
if(p_MyRst->GetState()==adStateOpen &&p_MyRst->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_MyRst->GetState()==adStateOpen) //p_MyRstDBNewBill->Close();
p_MyRst->Delete(adAffectCurrent);
p_MyRst->Update ();
}
catch(_com_error &err)
{
CWnd::MessageBox (err.Description ());
}
this->InitDataGrid ();
//this->MessageBox ("OK ^_^");
}
void CMyPrinterDlg::OnMenuCancel()
{
// TODO: Add your command handler code here
//this->MessageBox ("OK ^_^");
this->m_Edit_Hospital .ShowWindow (FALSE);
this->m_Combo_Hospital .ShowWindow (TRUE);
this->m_Combo_Hospital .EnableWindow (TRUE);
this->m_Combo_Hospital .SetCurSel (-1);
CMyClass::s_HospitalName="";
this->m_Combo_NO_ .EnableWindow (TRUE);
this->m_Combo_WareHouse .EnableWindow (TRUE);
this->m_DateTime .EnableWindow (TRUE);
(CButton *)GetDlgItem(IDC_BUTTON_REFRESH)->EnableWindow(TRUE);//IDC_BUTTON_REFRESH
this->InitDataGrid ();
}
void CMyPrinterDlg::OnSelchangeComboHospital()
{
// TODO: Add your control notification handler code here
this->m_Combo_Hospital .GetWindowText (CMyClass::s_HospitalName );
this->m_DateTime .GetWindowText (CMyClass::s_DateTime );
this->InitDataGrid ();
}
void CMyPrinterDlg::OnCloseupDatetimepicker(NMHDR* pNMHDR, LRESULT* pResult)
{
// TODO: Add your control notification handler code here
this->m_Combo_Hospital .GetWindowText (CMyClass::s_HospitalName );
this->m_DateTime .GetWindowText (CMyClass::s_DateTime );
this->InitDataGrid ();
*pResult = 0;
}
void CMyPrinterDlg::OnMenuDel()
{
// TODO: Add your command handler code here
CMyAddDel dlg_AddDel;
dlg_AddDel.i_Type =11;
dlg_AddDel.p_connection =this->p_MyCon ;
dlg_AddDel.p_recordset =this->p_MyRst ;
dlg_AddDel.DoModal ();
//this->MessageBox ("^_^");
}
void CMyPrinterDlg::OnMenuAdd()
{
// TODO: Add your command handler code here
CMyAddDel dlg_AddDel;
dlg_AddDel.i_Type =1;
dlg_AddDel.p_connection =this->p_MyCon ;
dlg_AddDel.p_recordset =this->p_MyRst ;
dlg_AddDel.DoModal ();
//this->MessageBox ("^_^");
}
void CMyPrinterDlg::OnMenuSetup()
{
// TODO: Add your command handler code here
CMyDlgSetup dlg_setup;
dlg_setup.DoModal ();
}
void CMyPrinterDlg::OnMenuAddName()
{
// TODO: Add your command handler code here
CMyAddDel dlg_AddDel;
dlg_AddDel.i_Type =1;
dlg_AddDel.p_connection =this->p_MyCon ;
dlg_AddDel.p_recordset =this->p_MyRst ;
dlg_AddDel.DoModal ();
}
void CMyPrinterDlg::OnMenuAddPlant()
{
// TODO: Add your command handler code here
CMyAddDel dlg_AddDel;
dlg_AddDel.i_Type =2;
dlg_AddDel.p_connection =this->p_MyCon ;
dlg_AddDel.p_recordset =this->p_MyRst ;
dlg_AddDel.DoModal ();
}
void CMyPrinterDlg::OnMenuAddUnit()
{
// TODO: Add your command handler code here
CMyAddDel dlg_AddDel;
dlg_AddDel.i_Type =3;
dlg_AddDel.p_connection =this->p_MyCon ;
dlg_AddDel.p_recordset =this->p_MyRst ;
dlg_AddDel.DoModal ();
}
void CMyPrinterDlg::OnMenuHistory()
{
// TODO: Add your command handler code here
CMyDlgBrowse dlg_Browse;
dlg_Browse.b_Date =FALSE;
dlg_Browse.b_Hospital =FALSE;
dlg_Browse.b_ShowAll =TRUE;
dlg_Browse.p_connection =this->p_MyCon ;
dlg_Browse.DoModal ();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -