公司给出了以下四个函数,实现一串字符流传过来时 自己解析建表 从表格中选中一行数据时提示框弹出一次,选中多个时(比如3个)他会弹出3次 现在让我对其进行优化 选中多个时提示框(MessageBox(strInfo, "打印", MB_YESNO))也只弹出一次
BSTR DllPrintBook(LPCTSTR szInData)
{
int nRet=0;
vector<string> vstr;
nRet=CResolveParameter::Resolve("DllPrintBook",szInData,vstr);
if (nRet==0)
{
CFixedFormReport* pFixedFormReport=new CFixedFormReport;
nRet=pFixedFormReport->PrintBook(vstr[0].c_str(),vstr[1].c_str(),vstr[2].c_str());
SAFE_DELETE(pFixedFormReport);
}
theApp.m_strReturn.Format("%d",nRet);
return theApp.m_strReturn.AllocSysString();
}
int CResolveParameter::Resolve(string funName,string strInData,vector<string>& vstr) //解析字符串
{
string strItem;
string::size_type nBeginIndex=0;
string::size_type nEndIndex=0;
nEndIndex=strInData.find("<print>",nBeginIndex);
while(nEndIndex!=string::npos)
{
strItem=strInData.substr(nBeginIndex,nEndIndex-nBeginIndex);
vstr.push_back(strItem);
strItem.erase();
nBeginIndex=nEndIndex;
nBeginIndex+=strlen("<print>");
nEndIndex=strInData.find("<print>",nBeginIndex);
}
if (Check(vstr,funName)<0)
{
return -1;
}
return 0;
}
int CFixedFormReport::PrintBook(CString pTitle, CString strInData, CString strColName)
{
int nRet=0;
DebugLog("-------------------------CFixedFormReport::PrintBook:begin---------------------------");
DebugLog(pTitle);
nRet=PrintInit(pTitle,strInData,strColName,"Fixed");
if (nRet>=0)
{
nRet=CreateTmpFileForReport(pTitle);
if (nRet>=0)
{
CreateReport(pTitle);
}
}
ZeroData();
DebugLog("-------------------------CFixedFormReport::PrintBook:end---------------------------");
return nRet;
}
int CFixedFormReport::CreateReport(CString pTitle)
{
int nRet;
CString strInfo;
CString strFilename=pTitle+".txt";
CString strTxtTmp=m_strPrintPath+pTitle+".tmp";
CString strPathTxt=m_strPrintPath+strFilename;
nRet = g_DllPrintReport.DllCreateReport(TRUE, ".\\非工作流组件\\PrnFrm", strTxtTmp, pTitle, strPathTxt);
if(m_flag==0)
{
if(nRet >= 0)
{
strInfo.Format("[%s]已生成,是否打印?", strFilename);
if(MessageBox(strInfo, "打印", MB_YESNO) == IDYES)
{
nRet=g_DllPrintReport.DllPrintFile(strPathTxt, nRet);
if(nRet>=0)
{
}
else
{
MessageBox("打印失败,确认是否连接打印机");
return nRet;
}
}
else
{
int nResult = (int)ShellExecute(NULL, "open", strPathTxt, NULL, NULL, SW_NORMAL);
if(nResult <= 32)
{
CString strErr;
strErr.Format("打开[%s]失败:%d", strFilename, nResult);
MessageBox(strErr);
return -1;
}
}
}
else
{
strInfo.Format("生成报表[%s]失败!", strFilename);
MessageBox(strInfo);
return nRet;
}
}
// ::DeleteFile(strTxtTmp);
return 0;
} |