打印

字符串的解析

[复制链接]
715|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
caoruiyao123|  楼主 | 2015-12-19 15:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
公司给出了以下四个函数,实现一串字符流传过来时  自己解析建表  从表格中选中一行数据时提示框弹出一次,选中多个时(比如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;
}

相关帖子

沙发
caoruiyao123|  楼主 | 2015-12-19 19:06 | 只看该作者
为什么还是没有人

使用特权

评论回复
板凳
sepmoon| | 2015-12-19 19:10 | 只看该作者
表示看的很晕,这种甩出一堆代码找人分析但又提不出什么关键问题的估计很少有人会耐着性子看完……

使用特权

评论回复
地板
dirtwillfly| | 2015-12-19 19:24 | 只看该作者
楼上正解

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

主题

2

帖子

0

粉丝