📄 stockinput.cpp
字号:
BrowseInfo.hwndOwner = GetSafeHwnd();
BrowseInfo.pidlRoot = NULL;
BrowseInfo.pszDisplayName = szDisplayName;
BrowseInfo.lpszTitle = "==== 选择存放导出文件的位置后单击[确定]按钮 ====";
BrowseInfo.ulFlags = BIF_USENEWUI;
BrowseInfo.lpfn = NULL;
BrowseInfo.lParam = 0;
LPITEMIDLIST lpItemIDList;
if ( ( lpItemIDList = ::SHBrowseForFolder( &BrowseInfo ) ) != NULL )
{
if ( ::SHGetPathFromIDList( lpItemIDList, szBuffer ) )
{
if ( szBuffer[0] == '\0' )
AfxMessageBox( "无效路径,重新选择!");
Directory = szBuffer;
}
else
AfxMessageBox( "无效路径,请重新选择!");
lpMalloc->Free( lpItemIDList );
lpMalloc->Release();
if(Directory.GetLength()>=1)
{
if(Directory.GetLength()>3)
Directory+="\\";
CTime t=CTime::GetCurrentTime();
CString filename,windowtext,bookname;
GetWindowText(windowtext);
if(windowtext==_T("药品退货"))
bookname=_T("退货表");
else
bookname=_T("总库存表");
filename=t.Format("%Y年%m月%d日")+bookname;
filename+=_T(".xls");
CString strPath=Directory+filename;
filename+=_T("\r\n\t工作表标签名:\r\n\t\t");
filename+=bookname;
CString message=_T("请在确认以下信息后单击[是]按钮开始导出数据!!!\r\n");
message+="\r\n\t导出Excel文件至:\r\n\t\t";
message+=Directory;
message+="\r\n\t导出Excel文件名:\r\n\t\t";
message+=filename;
if(AfxMessageBox(message,MB_YESNO|MB_ICONQUESTION)==IDYES)
{
if(theApp.MyGetDiskFreeSpace(Directory.Left(3))<3145728)
{
AfxMessageBox("目标磁盘空间太小,不能完成导出!");
return;
}
theApp.BeginWaitCursor();
CFileFind find,find1;
BOOL bFound = find.FindFile(strPath.Left(strPath.GetLength()-1)+_T("t"));
if(bFound)
::remove(strPath.Left(strPath.GetLength()-1)+_T("t"));
find.Close();
BOOL bFound1=find1.FindFile(strPath.Left(strPath.GetLength()-1)+_T("s"));
if(bFound1)
::remove(strPath.Left(strPath.GetLength()-1)+_T("s"));
find1.Close();
theApp.DbToFile(bookname+_T(".xlt"),strPath.Left(strPath.GetLength()-1)+_T("t1"));
LZARI Lzari;
Lzari.UnCompress(strPath.Left(strPath.GetLength()-1)+_T("t1"),strPath.Left(strPath.GetLength()-1)+_T("t"));
::remove(strPath.Left(strPath.GetLength()-1)+_T("t1"));
///
_Application ExcelApp;
Workbooks wbsMyBooks;
_Workbook wbMyBook;
Worksheets wssMysheets;
_Worksheet wsMysheet;
Range rgMyRge;
if (!ExcelApp.CreateDispatch("Excel.Application",NULL))
{
AfxMessageBox("创建Excel服务失败,要使用导出功能至少要求安装Microsoft Excel 2000!");
exit(1);
}
ExcelApp.SetVisible(false);
wbsMyBooks.AttachDispatch(ExcelApp.GetWorkbooks(),true);
wbMyBook.AttachDispatch(wbsMyBooks.Add(_variant_t(strPath.Left(strPath.GetLength()-4))));
//得到Worksheets
wssMysheets.AttachDispatch(wbMyBook.GetWorksheets(),true);
wsMysheet.AttachDispatch(wssMysheets.GetItem(_variant_t(bookname)),true);
//得到全部Cells,此时,rgMyRge是cells的集合
rgMyRge.AttachDispatch(wsMysheet.GetCells(),true);
int row=m_list.GetItemCount();
LPDISPATCH lpDisp;
lpDisp = wsMysheet.GetRange(_variant_t("A4"),_variant_t("A4"));
ASSERT(lpDisp);
rgMyRge.AttachDispatch(lpDisp);
lpDisp = rgMyRge.GetEntireRow();
rgMyRge.AttachDispatch(lpDisp);
for(int r=0;r<row-2;r++)
rgMyRge.Insert(_variant_t((long)1));
rgMyRge.AttachDispatch(wsMysheet.GetCells(),true);
//设置单元格的值
int rowcheck=0;
for(int r=0;r<row;r++)
{
for(int c=0;c<12;c++)
if(m_list.GetCheck(r))
rgMyRge.SetItem(_variant_t((long)rowcheck+3),_variant_t((long)c+1),_variant_t(m_list.GetItemText(r,c)));
if(m_list.GetCheck(r))
rowcheck++;
}
//将表格保存
wsMysheet.SaveAs(strPath.Left(strPath.GetLength()-4)+_T(".xls"),vtMissing,vtMissing,vtMissing,vtMissing,
vtMissing,vtMissing,vtMissing,vtMissing);
ExcelApp.SetVisible(true);
//wbMyBook.PrintPreview(_variant_t(false));
//释放对象
rgMyRge.ReleaseDispatch();
wsMysheet.ReleaseDispatch();
wssMysheets.ReleaseDispatch();
wbMyBook.ReleaseDispatch();
wbsMyBooks.ReleaseDispatch();
ExcelApp.ReleaseDispatch();
::remove(strPath.Left(strPath.GetLength()-1)+_T("t"));
///
theApp.EndWaitCursor();
AfxMessageBox("数据导出完毕!");
}
else
AfxMessageBox("用户取消了导出!");
}
}
else
AfxMessageBox("用户取消了选择或导出!");
}
}
void CStockInput::OnEnKillfocusStockmoney()//检验单价的合法性并转换
{
CString stri,strf;
GetDlgItemText(IDC_STOCKMONEY,stri);
//校验数据的有效性
if(!theApp.Examination(stri))
{
AfxMessageBox(_T("输入单价错误!"));
SetDlgItemText(IDC_STOCKMONEY,_T(""));
GotoDlgCtrl(GetDlgItem(IDC_STOCKMONEY));
return;
}
//校验结束
strf.Format("%f",atof(stri));
SetDlgItemText(IDC_STOCKMONEY,strf.Left(strf.Find('.',0)+1)+strf.Mid(strf.Find('.',0)+1,2));
theApp.SetInputMethod(FALSE);
}
void CStockInput::OnEnSetfocusStockmoney()
{
theApp.SetInputMethod(FALSE);
}
void CStockInput::OnEnSetfocusFindname()
{
theApp.SetInputMethod(TRUE);
}
void CStockInput::OnCbnSetfocusName()
{
theApp.SetInputMethod(TRUE);
}
void CStockInput::OnCbnSetfocusSpec()
{
theApp.SetInputMethod(FALSE);
}
void CStockInput::OnCbnSetfocusStockfactory()
{
theApp.SetInputMethod(FALSE);
}
void CStockInput::OnEnSetfocusBatchnumber()
{
theApp.SetInputMethod(FALSE);
}
BOOL CStockInput::PreTranslateMessage(MSG* pMsg)
{
m_tooltip.RelayEvent(pMsg);
return CDialog::PreTranslateMessage(pMsg);
}
void CStockInput::OnBnClickedAllselect()
{
int row=m_list.GetItemCount();
for(int x=0;x<row;x++)
m_list.SetCheck(x,1);
}
void CStockInput::OnBnClickedNoselect()
{
int row=m_list.GetItemCount();
for(int x=0;x<row;x++)
m_list.SetCheck(x,0);
}
void CStockInput::OnBnClickedAllorno()
{
int row=m_list.GetItemCount();
for(int x=0;x<row;x++)
if(m_list.GetCheck(x))
m_list.SetCheck(x,0);
else
m_list.SetCheck(x,1);
}
void CStockInput::OnCbnSetfocusType()
{
theApp.SetInputMethod(FALSE);
}
void CStockInput::OnCbnSetfocusForm()
{
theApp.SetInputMethod(FALSE);
}
void CStockInput::OnCbnSetfocusConclusion()
{
theApp.SetInputMethod(FALSE);
}
void CStockInput::OnCbnSetfocusCondition()
{
theApp.SetInputMethod(FALSE);
}
void CStockInput::OnEnSetfocusPer()//设置为中文输入法
{
theApp.SetInputMethod(TRUE);
}
void CStockInput::OnNMSetfocusAcce(NMHDR *pNMHDR, LRESULT *pResult)
{
theApp.SetInputMethod(FALSE);
*pResult = 0;
}
void CStockInput::OnEnSetfocusApprovalnumber()
{
theApp.SetInputMethod(TRUE);
}
void CStockInput::OnNMSetfocusMakedate(NMHDR *pNMHDR, LRESULT *pResult)
{
theApp.SetInputMethod(FALSE);
*pResult = 0;
}
void CStockInput::OnNMSetfocusValidate(NMHDR *pNMHDR, LRESULT *pResult)
{
theApp.SetInputMethod(FALSE);
*pResult = 0;
}
void CStockInput::OnCbnSetfocusNumber()
{
theApp.SetInputMethod(FALSE);
}
void CStockInput::OnCbnSetfocusUnit()
{
theApp.SetInputMethod(FALSE);
}
void CStockInput::OnNMDblclkStocklist1(NMHDR *pNMHDR, LRESULT *pResult)//双击右键修改
{
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
}
void CStockInput::OnNMRdblclkStocklist1(NMHDR *pNMHDR, LRESULT *pResult)//双击右键删除
{
// TODO: 在此添加控件通知处理程序代码
*pResult = 0;
}
void CStockInput::OnBnClickedStockenter()//从采购计划表中导入数据
{
CStockEnterData dlg;
if(dlg.DoModal()==IDCANCEL)
AfxMessageBox("当前操作被用户取消!");
else
{
CString vau=dlg.select;
int rang=0;
m_pRecordset.CreateInstance(_T("ADODB.Recordset"));
m_pRecordset1.CreateInstance(_T("ADODB.Recordset"));
m_pRecordset2.CreateInstance(_T("ADODB.Recordset"));
CString strSQL="SELECT * FROM entergoods";
m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
while(!(m_pRecordset->adoEOF))
{
rang++;
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
}
m_pRecordset->Close();
m_progress.SetRange(0,rang);
m_progress.SetStep(1);
strSQL="SELECT * FROM entergoods where g_id='";
strSQL+=vau;
strSQL+="'";//得到关键字日期以备查询用
m_pRecordset->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
strSQL="select * from productdetail";
m_pRecordset2->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
while(!(m_pRecordset->adoEOF))
{
vau=(LPTSTR)_bstr_t(m_pRecordset->GetCollect("name"));//得到要查找编号的药品名
CString vau1=(LPTSTR)_bstr_t(m_pRecordset->GetCollect("factory"));
strSQL="SELECT product_id,standard,permitcode,makearea,unit1_id,medtype FROM products where name='";
strSQL+=vau;
strSQL+="' and makearea='";
strSQL+=vau1;
strSQL+="'";//返回对应药品的唯一编号
m_pRecordset1->Open((LPTSTR)strSQL.GetBuffer(strSQL.GetLength()+1),
((CMedicineSaleManagesApp*)AfxGetApp())->m_pConn1.GetInterfacePtr(),
adOpenDynamic,adLockPessimistic,adCmdText);
m_pRecordset2->AddNew();
if(!(m_pRecordset1->adoEOF))//视查找情况写入编号
{
m_pRecordset2->PutCollect("p_id",m_pRecordset1->GetCollect("product_id"));
m_pRecordset2->PutCollect("specification",m_pRecordset1->GetCollect("standard"));
m_pRecordset2->PutCollect("approvaltextnumber",m_pRecordset1->GetCollect("permitcode"));
m_pRecordset2->PutCollect("factory",m_pRecordset1->GetCollect("makearea"));
m_pRecordset2->PutCollect("quantity",m_pRecordset->GetCollect("number"));
m_pRecordset2->PutCollect("unitid",m_pRecordset1->GetCollect("unit1_id"));
m_pRecordset2->PutCollect("price",m_pRecordset->GetCollect("readem"));//备注已改为单价
//合计
double q=0,pq=0;
CString p;
q=m_pRecordset->GetCollect("number");
p=(LPTSTR)_bstr_t(m_pRecordset->GetCollect("readem"));
pq=q*atof(p);
m_pRecordset2->PutCollect("total",_variant_t(pq));
//
m_pRecordset2->PutCollect("medtype",m_pRecordset1->GetCollect("medtype"));//剂型为剂型编号,需使用查询来更正
}
else
m_pRecordset2->PutCollect("p_id",_variant_t("0"));
//写入规格specification
//批准文号approvaltextnumber
//生产厂家factory
//数量quantity
//单位unitid
//单价price
//合计total
//药品剂型(待查询)medtype
m_pRecordset2->Update();
m_pRecordset->PutCollect("writed", _variant_t(1));
m_pRecordset->Update();
if(!(m_pRecordset->adoEOF))
m_pRecordset->MoveNext();
m_pRecordset1->Close();
m_progress.StepIt();
}
m_pRecordset2->Close();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -