namespace _excel for ole "Excel.Application,{00020813-0000-0000-C000-000000000046}";
|
namespace _mshtml for ole "MSHtml,{3050F1C5-98B5-11CF-BB82-00AA00BDCE0B}";
|
|
class cexcel : public xnative native from "XControl.dll"
|
{
|
void Release(int t) alias "?Release@CExcelApplication@@QAEXPAV1@@Z";
|
static int CreateInstance() alias "?CreateInstance@CExcelApplication@@SAPAV1@XZ";
|
void put_Visible(bool t) alias "?put_Visible@CExcelApplication@@QAEXH@Z";
|
bool get_Visible() alias "?get_Visible@CExcelApplication@@QAEHXZ";
|
void OpenDocument(const string filename) alias "?OpenDocument@CExcelApplication@@QAEXQA_W@Z";
|
void TransShape() alias "?TransShape@CExcelApplication@@QAEXXZ";
|
void SaveToFile(string filename) alias "?SaveToFile@CExcelApplication@@QAEXQA_W@Z";
|
void Quit() alias "?Quit@CExcelApplication@@QAEXXZ";
|
};
|
|
struct MYOPENFILENAMEW
|
{
|
unsigned int lStructSize;
|
unsigned int hwndOwner;
|
unsigned int hInstance;
|
string lpstrFilter;
|
|
string lpstrCustomFilter;
|
unsigned int nMaxCustFilter;
|
unsigned int nFilterIndex;
|
string lpstrFile;
|
|
unsigned int nMaxFile;
|
string lpstrFileTitle;
|
unsigned int nMaxFileTitle;
|
string lpstrInitialDir;
|
|
string lpstrTitle;
|
unsigned int Flags;
|
unsigned short nFileOffset;
|
unsigned short nFileExtension;
|
string lpstrDefExt;
|
|
unsigned int lCustData;
|
unsigned int lpfnHook;
|
string lpTemplateName;
|
|
//_WIN32_WINNT >= 0x0500
|
unsigned int pvReserved;
|
unsigned int dwReserved;
|
unsigned int FlagsEx;
|
// (_WIN32_WINNT >= 0x0500)
|
};
|
|
class TemplatePrintViewEx : public frame
|
{
|
xole ole_print;
|
xcell cell;
|
string m_EntityName;
|
string m_EntityID;
|
string m_EntityNo;
|
string m_strHtml;
|
string m_spath;
|
bool updated;
|
|
string htmlStr;
|
cexcel excel;
|
bool editing;
|
|
string billName ;
|
string billID ;
|
string billPre;
|
|
string m_DocumentID;
|
xml m_dataset;
|
//bool showgrid;
|
bool PaperPrint;
|
|
static stdcall int GetModuleFileName(int hModule ,string lpFileName ,int nSize ) native from "kernel32.dll" alias "GetModuleFileNameW";
|
static stdcall int PathRemoveFileSpec(string lpFileName ) native from "shlwapi.dll" alias "PathRemoveFileSpecW";
|
static stdcall int DeleteFile(string lpFileName) native from "kernel32.dll" alias "DeleteFileW";
|
static stdcall bool GetSaveFileName(ref MYOPENFILENAMEW)native from "comdlg32.dll" alias "GetSaveFileNameW";
|
|
string GetModulePath()
|
{
|
string str ="";
|
str = str.space(255);
|
GetModuleFileName(0,str,250);
|
PathRemoveFileSpec(str);
|
return str;
|
}
|
string GetModuleTmpPath()
|
{
|
string str ="";
|
str = str.space(255);
|
GetModuleFileName(0,str,250);
|
PathRemoveFileSpec(str);
|
string tmp = str + "\\Temp";
|
xaserver::CreateDirectory(tmp);
|
return tmp;
|
}
|
|
string GetSaveFileName(string initFileName, string filter, string ext)
|
{
|
char[] szFileName = new char[255] ;
|
char[] szPath = new char[255];
|
szFileName[0] = 0;
|
szPath[0] = 0;
|
|
if(initFileName !="")
|
{
|
int len = initFileName.length();
|
char[] tmp = initFileName;
|
for(int i=0; i<len+1;i++)
|
{
|
//szFileName[i] = tmp[i];
|
szPath[i] = tmp[i];
|
}
|
}
|
|
int nFilterIndex = 1;
|
ref MYOPENFILENAMEW ofn = new MYOPENFILENAMEW;
|
|
ofn.lStructSize = 88;//sizeof(ofn);
|
ofn.hwndOwner = 0;
|
ofn.hInstance = 0;
|
ofn.lpstrFilter = filter;
|
//"JPEG Îļþ(*.jpg)\0*.jpg;*.jpeg;*.png;*.gif;*.bmp\0È«²¿Îļþ(*.*)\0*.*\0";
|
ofn.lpstrCustomFilter = 0;
|
ofn.nMaxCustFilter = 0;
|
ofn.nFilterIndex = nFilterIndex;
|
ofn.lpstrFile = szPath;
|
ofn.nMaxFile = 255;
|
ofn.lpstrFileTitle = szFileName;
|
ofn.nMaxFileTitle = 255;
|
ofn.lpstrTitle = "ÇëÖ¸¶¨ÎļþÃû";
|
ofn.lpstrDefExt = ext;
|
//"jpg";
|
ofn.lpstrInitialDir = 0;
|
ofn.Flags = 0x00000010/*OFN_SHOWHELP*/ | 0x00001000/*OFN_FILEMUSTEXIST*/;
|
ofn.lCustData = 0;
|
ofn.lpfnHook = 0;
|
ofn.lpTemplateName = 0;
|
|
//debugbreak();
|
if(GetSaveFileName(ofn))
|
{
|
delete ofn;
|
return szPath;
|
}
|
else
|
{
|
return "";
|
}
|
}
|
|
int OnExport()
|
{
|
string pre = billPre;
|
if(pre=="")
|
{
|
pre = m_EntityName;
|
if(m_EntityName=="SaleOrder") pre="PI";
|
if(m_EntityName=="GDN3")pre="INV";
|
}
|
string file1 = GetSaveFileName(pre+m_EntityNo+".xlsx",
|
"Excel1Îļþ(*.xlsx)\0*.xlsx;*.xls\0Excel97Îļþ(*.xls)\0*.xls\0PDFÎļþ(*.pdf)\0*.pdf\0",
|
"xlsx");
|
if(file1 =="") return 1;
|
|
if(win32::PathFileExists(file1))
|
{
|
int res = win32::MessageBox(this.GetHWND(), "ÎļþÒѾ´æÔÚ£¬ÊÇ·ñ¸²¸Ç?","Ìáʾ",4);
|
if(res != 6) return 1;
|
}
|
|
trace("\r\n link excel");
|
excel = new cexcel;
|
int hexcel = cexcel::CreateInstance();
|
excel.setNativePointer(hexcel);
|
if(hexcel == 0)
|
{
|
alert("²»ÄÜÁ¬½ÓExcel");
|
return 1;
|
}
|
|
string gid = publiccode::GetGuid();
|
string filename= pre+m_EntityNo+"_.htm";
|
xutil::SaveToFile(GetModuleTmpPath() + "\\"+ filename, htmlStr,"","","");
|
trace("\r\n excel to open");
|
excel .OpenDocument(GetModuleTmpPath() + "\\"+ filename);
|
trace("\r\n trans shape");
|
//excel .put_Visible(true);
|
excel.TransShape();
|
trace("\r\n save to tmp excel file");
|
if(file1.find(".xls"))
|
{
|
if(win32::PathFileExists(GetModuleTmpPath() + "\\"+ pre+m_EntityNo+"_.xls"))
|
DeleteFile(GetModuleTmpPath() + "\\"+ pre+m_EntityNo+"_.xls");
|
excel.SaveToFile(GetModuleTmpPath() + "\\"+ pre+m_EntityNo+"_.xls");
|
//alert(GetModuleTmpPath() + "\\"+ pre+m_EntityNo+"_.xls");
|
}
|
else
|
{
|
if(win32::PathFileExists(GetModuleTmpPath() + "\\"+ pre+m_EntityNo+"_.xlsx"))
|
DeleteFile(GetModuleTmpPath() + "\\"+ pre+m_EntityNo+"_.xlsx");
|
excel.SaveToFile(GetModuleTmpPath() + "\\"+ pre+m_EntityNo+"_.xlsx");
|
}
|
|
trace("\r\n save to excel file");
|
if(win32::PathFileExists(file1)) //GetModuleTmpPath() + "\\"+ pre+m_EntityNo+"_.xlsx"))
|
DeleteFile(file1);
|
excel.SaveToFile(file1);
|
|
excel.Quit();
|
excel.Release(excel.ptr_native_);
|
return 1;
|
}
|
|
int OntoExcel() //תΪExcel
|
{
|
excel = new cexcel;
|
excel.setNativePointer(cexcel::CreateInstance());
|
|
string gid = publiccode::GetGuid();
|
string pre = m_EntityName;
|
if(m_EntityName=="SaleOrder") pre="PI";
|
if(m_EntityName=="GDN3")pre="INV";
|
string filename= pre+m_EntityNo+".htm";
|
string filenameex= pre+m_EntityNo+".xlsx";
|
xutil::SaveToFile(GetModuleTmpPath() + "\\"+ filename, htmlStr,"","","");
|
excel .OpenDocument(GetModuleTmpPath() + "\\"+ filename);
|
//excel.put_Visible(true);
|
excel.TransShape();
|
if(win32::PathFileExists(GetModuleTmpPath() + "\\"+ filenameex))
|
DeleteFile(GetModuleTmpPath() + "\\"+ filenameex);
|
excel.SaveToFile(GetModuleTmpPath() + "\\"+ filenameex);
|
excel.put_Visible(true);
|
|
excel.Release(excel.ptr_native_);
|
return 1;
|
}
|
|
string getfilePath()
|
{
|
string path=GetModulePath()+"\\resource\\image";
|
string filename="contract.jpg";
|
filename="sign.png";
|
filename="jrj_maersk.png";
|
filename="HomeDecorSign.png";
|
xaserver::DownLoadFile(GetServerUrl(),"/business/rpttemplate/"+filename,"",path+"\\"+filename);
|
filename="HomeDecorLogo.jpg";
|
xaserver::DownLoadFile(GetServerUrl(),"/business/rpttemplate/"+filename,"",path+"\\"+filename);
|
return path;
|
}
|
|
string replaceInnerElement(string html)
|
{
|
string str = html;
|
if(str.find("[$element:")<0) return str;
|
|
int len = 0;
|
int pos = 0;
|
int pos1 = 0;
|
string pre="";
|
string left="";
|
string right="";
|
string tag="";
|
|
len = "[$element:".length();
|
while(true)
|
{
|
pos = str.find("[$element:");
|
if(pos < 0) break;
|
left = str.left(pos);
|
right = str.mid(pos+ len,999999);
|
|
pos1 = right.find("]");
|
if(pos1>=0)
|
{
|
tag = right.left(pos1);
|
if(tag.right(1)=="$") tag=tag.left(tag.length() - 1);
|
pre = pre + left + "<" + tag +">";
|
str = right.mid(pos1+ 1,999999);
|
}else
|
{
|
pre = pre + left+"<";
|
str = right;
|
}
|
}
|
|
str = pre + str;
|
pre = "";
|
len = "[/$element:".length();
|
while(true)
|
{
|
pos = str.find("[/$element:");
|
if(pos < 0) break;
|
left = str.left(pos);
|
right = str.mid(pos+ len,999999);
|
pos1 = right.find("]");
|
if(pos1>=0)
|
{
|
tag = right.left(pos1);
|
if(tag.right(1)=="$") tag=tag.left(tag.length() - 1);
|
pre = pre + left + "</" + tag +">";
|
str = right.mid(pos1+ 1,999999);
|
}else
|
{
|
pre = pre + left+"</";
|
str = right;
|
}
|
}
|
str = pre + str;
|
return str;
|
}
|
|
string adjustXsl(string str,string localPath)
|
{
|
//if(str.find("%")>=0) str = str.replace("%","");
|
if(str.find("[$path]/rpttemplate")>=0) str = str.replace("[$path]/rpttemplate",localPath);
|
str = replaceInnerElement(str);
|
return str;
|
}
|
|
string DownLoadSKUNoPic(string SKUNo,string CustomerID="",string CustomerItemNo="")
|
{
|
|
if(SKUNo.length()>20) return DownLoadPaperPic(SKUNo);
|
|
xml x = new xml;
|
x.setNativePointer(xml::CreateInstance());
|
xaserverarg arg = new xaserverarg;
|
arg.setNativePointer(arg.CreateInstance());
|
arg.AddArg("SKUNo",SKUNo);
|
|
string src ="/sale/data/ProductLibrary3/pref/picture/imagelistSKUNo";
|
if(CustomerID !="")
|
{
|
arg.AddArg("CustomerID",CustomerID);
|
arg.AddArg("CustomerItemNo",CustomerItemNo);
|
src ="/sale/data/ProductLibrary3/pref/picture/customer/imagelistSKUNo";
|
}
|
//trace("SKUNo="+SKUNo);//ÒªÓÐչʾͼƬ²éѯÌõ¼þÄڱض¨Òªskuno
|
if(url::get(src,arg.GetString(),x)!=1)
|
{
|
trace("error for download skuno pic!");
|
return "";
|
}
|
|
string spath = "";
|
string path =GetModuleTmpPath();
|
string ext = "jpg";
|
if(x.GetXmlDoc().selectSingleNode("//FileExt[1]"))
|
{
|
ext = x.GetXmlDoc().selectSingleNode("//FileExt[1]").text;
|
}else if(CustomerID !="")
|
{
|
src ="/sale/data/ProductLibrary3/pref/picture/imagelistSKUNo";
|
if(url::get(src,arg.GetString(),x)!=1)
|
{
|
trace("error for download skuno pic!");
|
return "";
|
}
|
if(x.GetXmlDoc().selectSingleNode("//FileExt[1]"))
|
ext = x.GetXmlDoc().selectSingleNode("//FileExt[1]").text;
|
}
|
|
string filename = SKUNo + "." + ext;
|
if(x.GetXmlDoc().selectSingleNode("//PicPath[1]"))
|
spath = x.GetXmlDoc().selectSingleNode("//PicPath[1]").text;
|
if(spath != "")
|
{
|
xaserver::DownLoadFile(GetServerUrl(),spath,"",path+"/"+filename);
|
}
|
return "file://"+ path+"/"+filename;
|
}
|
|
string DownLoadSKUNoPic(string SKUNo,string CustomerID="",string CustomerItemNo="")
|
{
|
|
if(SKUNo.length()>20) return DownLoadPaperPic(SKUNo);
|
|
xml x = new xml;
|
x.setNativePointer(xml::CreateInstance());
|
xaserverarg arg = new xaserverarg;
|
arg.setNativePointer(arg.CreateInstance());
|
arg.AddArg("SKUNo",SKUNo);
|
|
string src ="/sale/data/ProductLibrary3/pref/picture/imagelistSKUNo";
|
if(CustomerID !="")
|
{
|
arg.AddArg("CustomerID",CustomerID);
|
arg.AddArg("CustomerItemNo",CustomerItemNo);
|
src ="/sale/data/ProductLibrary3/pref/picture/customer/imagelistSKUNo";
|
}
|
//trace("SKUNo="+SKUNo);//ÒªÓÐչʾͼƬ²éѯÌõ¼þÄڱض¨Òªskuno
|
if(url::get(src,arg.GetString(),x)!=1)
|
{
|
trace("error for download skuno pic!");
|
return "";
|
}
|
|
string spath = "";
|
string path =GetModuleTmpPath();
|
string ext = "jpg";
|
if(x.GetXmlDoc().selectSingleNode("//FileExt[1]"))
|
{
|
ext = x.GetXmlDoc().selectSingleNode("//FileExt[1]").text;
|
}else if(CustomerID !="")
|
{
|
src ="/sale/data/ProductLibrary3/pref/picture/imagelistSKUNo";
|
if(url::get(src,arg.GetString(),x)!=1)
|
{
|
trace("error for download skuno pic!");
|
return "";
|
}
|
if(x.GetXmlDoc().selectSingleNode("//FileExt[1]"))
|
ext = x.GetXmlDoc().selectSingleNode("//FileExt[1]").text;
|
}
|
|
string filename = SKUNo + "." + ext;
|
if(x.GetXmlDoc().selectSingleNode("//PicPath[1]"))
|
spath = x.GetXmlDoc().selectSingleNode("//PicPath[1]").text;
|
if(spath != "")
|
{
|
xaserver::DownLoadFile(GetServerUrl(),spath,"",path+"/"+filename);
|
}
|
return "file://"+ path+"/"+filename;
|
}
|
|
string GetImageUrl(string id)
|
{
|
xml xp=new xml;
|
xp.setNativePointer(xml::CreateInstance());
|
xaserverarg arg_pic=new xaserverarg;
|
arg_pic.setNativePointer(arg_pic.CreateInstance());
|
arg_pic.AddArg("id",id);
|
|
string res = "/sale/data/productlibrary3/image/url";
|
if(url::get(res,arg_pic.GetString(),xp)!=1)
|
{
|
xp.GetXml();
|
return 1;
|
}else
|
{
|
string path = xp.GetXmlDoc().text;
|
if(path !="") return path;
|
}
|
|
return "/business/products/chanpin/"+id.left(2)+"/"+ id+".jpg";
|
}
|
|
string DownLoadPaperPic(string guid)
|
{
|
|
string path =GetModuleTmpPath();
|
string ext = "jpg";
|
string filename = guid + "." + ext;
|
string spath = GetImageUrl(guid);
|
//alert(spath);
|
xaserver::DownLoadFile(GetServerUrl(),spath,"",path+"/"+filename);
|
return "file://"+ path+"/"+filename;
|
}
|
|
string DownLoadPaperPic1(string guid)
|
{
|
string path =GetModuleTmpPath();
|
string ext = "jpg";
|
string filename = guid + "." + ext;
|
string str = guid.mid(0,2);
|
string spath = "/business/products/chanpin/"+str+"/"+guid+".jpg";
|
xaserver::DownLoadFile(GetServerUrl(),spath,"",path+"/"+filename);
|
return "file://"+ path+"/"+filename;
|
}
|
|
string DownLoadUrlPic(string src)
|
{
|
string guid = publiccode::GetGuid();
|
string path =GetModuleTmpPath();
|
string ext = "jpg";
|
string filename = guid + "." + ext;
|
string spath = src;
|
xaserver::DownLoadFile(GetServerUrl(),spath,"",path+"/"+filename);
|
return "file://"+ path+"/"+filename;
|
}
|
|
int OnHtml(xaserverarg arg)
|
{
|
int hCursor = xutil::SetCursorWait();
|
|
string sEntityName = arg.GetArgString("EntityName");
|
string sEntityID = arg.GetArgString("EntityID");
|
string dataUrl = arg.GetArgString("DataUrl");
|
if(dataUrl=="")
|
dataUrl = "/sale/data/"+sEntityName+"/print/dataset";
|
else if(dataUrl.left(1)!="/")
|
dataUrl = "/sale/data/"+sEntityName+ "/"+ dataUrl;
|
if(!m_dataset)
|
{
|
xml x0 = new xml;
|
x0.setNativePointer(xml::CreateInstance());
|
if (url::get(dataUrl,arg.GetString(),x0) != 1)
|
{
|
alert("Êý¾Ý¼¯³ö´íÁË!");
|
return 0;
|
}
|
trace(x0.GetXml());
|
m_dataset = x0;
|
}
|
|
string sPath;
|
sPath = getfilePath();
|
arg.AddArg("sPath",sPath);
|
m_spath = sPath;
|
|
xml xsl = new xml;
|
xsl.setNativePointer(xml::CreateInstance());
|
if (url::get("/sale/data/SysPrintTemplate/getxsl",arg.GetString(),xsl) != 1)
|
{
|
alert("Êý¾ÝÄ£°å´íÎó!");
|
return 0;
|
}
|
|
string xslStr = xsl.GetXml();
|
|
xslStr = adjustXsl(xslStr,sPath);
|
xsl.LoadXml(xslStr);
|
|
//trace(m_dataset.GetXml());
|
trace("\r\n--------\r\n"+xslStr);
|
|
m_strHtml = m_dataset.GetXmlDoc().transformNode(xsl.GetXmlDoc());
|
string aspace = m_strHtml.replace("[¿Õ]"," ",0);
|
aspace = aspace.replace("[line]","<br/>",0);
|
string scontent = aspace.replace("<?xml version=\"1.0\"?>","",0);
|
|
string head ="";
|
string tail = scontent;
|
|
int pos = tail.find("src=\"item-picture:");
|
while(pos > 0)
|
{
|
int spos = pos+"src=\"item-picture:".length();
|
int pos1 = tail.find("\"",spos+1);
|
string skuno = tail.mid(spos,pos1 - spos ).trim();
|
string CustomerID="";
|
string CustomerItemNo="";
|
if(skuno.find(",")>0)
|
{
|
CustomerID = skuno.left(skuno.find(",")).trim();
|
skuno = skuno.mid(skuno.find(",")+1,256).trim();
|
}
|
if(skuno.find(",")>0)
|
{
|
CustomerItemNo = skuno.left(skuno.find(",")).trim();
|
skuno = skuno.mid(skuno.find(",")+1,256).trim();
|
}
|
string src = DownLoadSKUNoPic(skuno,CustomerID,CustomerItemNo);
|
head += tail.left(pos) + "src=\"" + src;
|
tail = tail.mid(pos1,999999999);
|
pos = tail.find("src=\"item-picture:");
|
}
|
scontent = head + tail;
|
|
head ="";
|
tail = scontent;
|
int position = tail.find("src=\"paper-picture:");
|
while(position > 0)
|
{
|
int sposition = position+"src=\"paper-picture:".length();
|
int position1 = tail.find("\"",sposition+1);
|
string guid = tail.mid(sposition,position1 - sposition ).trim();
|
string src2 = DownLoadPaperPic(guid);
|
head += tail.left(position) + "src=\"" + src2;
|
tail = tail.mid(position1,999999999);
|
position = tail.find("src=\"paper-picture:");
|
}
|
scontent = head + tail;
|
|
head ="";
|
tail = scontent;
|
position = tail.find("src=\"src-picture:");
|
while(position > 0)
|
{
|
sposition = position+"src=\"src-picture:".length();
|
position1 = tail.find("\"",sposition+1);
|
guid = tail.mid(sposition,position1 - sposition ).trim();
|
src2 = DownLoadUrlPic(guid);
|
head += tail.left(position) + "src=\"" + src2;
|
tail = tail.mid(position1,999999999);
|
position = tail.find("src=\"src-picture:");
|
}
|
scontent = head + tail;
|
|
scontent = adjustXsl(scontent,sPath);
|
htmlStr = scontent;
|
ole_print.LoadHtml(scontent);
|
|
xml x1 = new xml;
|
x1.setNativePointer(xml ::CreateInstance());
|
//string xcontent = m_strHtml.replace(" ","[¿Õ]",0);
|
string xcontent = m_strHtml.replace("[¿Õ]"," ",0);
|
int pos0 = xcontent.find("<xml");
|
int pos2 = xcontent.find("</xml>");
|
if(pos0>=0)
|
{
|
string str = xcontent.left(pos0)+ xcontent.mid(pos2+6,9999999);
|
xcontent = str;
|
}
|
x1.LoadXml(xcontent);
|
if(x1.GetXmlDoc())
|
{
|
/*if(!showgrid)
|
{
|
SendCtrlCmd(cell,"xmFormatShowGrid");
|
showgrid = true;
|
}*/
|
cell.LoadTemplate(x1.GetXmlDoc());
|
cell.Redraw();
|
}
|
|
xutil::RestoreCursor(hCursor);
|
updateHtml();
|
return 1;
|
}
|
|
int updateHtml()
|
{
|
_mshtml::IHTMLDocument3 doc = ole_print.GetHtmlDocument();
|
_mshtml::IHTMLElementCollection rows = doc.getElementsByTagName("tr");
|
_mshtml::IHTMLElementCollection rows2 = doc.getElementsByTagName("td");
|
int len = rows.length;
|
int len2 = rows2.length;
|
for(int i=0; i < len - 1;i++)
|
{
|
_mshtml::IHTMLElement e = rows.item(i,i);
|
e.style.setAttribute("height",e.offsetHeight,0);
|
e.Release();
|
}
|
for( i=0; i < len2 - 1;i++)
|
{
|
_mshtml::IHTMLElement e2 = rows2.item(i,i);
|
e2.style.setAttribute("width",e.offsetWidth,0);
|
e2.Release();
|
}
|
rows.Release();
|
doc.release();
|
htmlStr = doc.documentElement.outerHtml;
|
return 1;
|
}
|
|
int OnOpenDocument()
|
{
|
if(GetParam())
|
{
|
xaserverarg arg = new xaserverarg;
|
arg.setNativePointer(GetParam());
|
int p = arg.ptr_native_;
|
arg.AddArg("action","open");
|
arg.AddArg("DocumentID","");
|
arg.AddArg("ok","");
|
openUrl("/sale/view/view.dlg/xpage/Template/PrintDialog", p);
|
string ret = arg.GetArgString("return");
|
string action = arg.GetArgString("action");
|
if (ret =="ok")
|
{
|
if(action =="open")
|
{
|
m_DocumentID = arg.GetArgString("DocumentID");
|
xml x = new xml;
|
x.setNativePointer(xml::CreateInstance());
|
string prestr = m_DocumentID.mid(0,2);
|
prestr = prestr.upper();
|
xaserver::LoadUrl(GetServerUrl(),"/business/data/bill/"+prestr+"/"+ m_DocumentID+".jpg","",x);
|
if(x.GetXml()!="")
|
{
|
if(x.GetXmlDoc())
|
{
|
/*if(!showgrid)
|
{
|
SendCtrlCmd(cell,"xmFormatShowGrid");
|
showgrid = true;
|
}*/
|
cell.LoadTemplate(x.GetXmlDoc());
|
cell.Redraw();
|
}
|
ole_print.LoadHtml(x.GetXml());
|
}else
|
{
|
ole_print.LoadHtml("<html><body>δÕÒµ½¶ÔÓ¦µÄÎĵµ</body></html>");
|
//cell.LoadHtml("<html><body>δÕÒµ½¶ÔÓ¦µÄÎĵµ</body></html>");
|
}
|
}
|
else
|
{
|
string templateName = arg.GetArgString("template-name");
|
win32::SetWindowText(GetHWND(),templateName);
|
billName = templateName;
|
billPre = arg.GetArgString("template-pre");
|
billID = arg.GetArgString("template-guid");
|
m_EntityID = arg.GetArgString("EntityID");
|
m_EntityNo = arg.GetArgString("EntityNo");
|
m_EntityName = arg.GetArgString("EntityName");
|
m_DocumentID = "";
|
|
OnHtml(arg);
|
|
}
|
}
|
}
|
return 1;
|
}
|
|
int OnPrintDialog()
|
{
|
if(GetParam())
|
{
|
xaserverarg arg = new xaserverarg;
|
arg.setNativePointer(GetParam());
|
int p = arg.ptr_native_;
|
arg.AddArg("ok","");
|
openUrl("/sale/view/view.dlg/xpage/Template/PrintDialog", p);
|
string ret = arg.GetArgString("return");
|
string action = arg.GetArgString("action");
|
if (ret =="ok")
|
{
|
updated = false;
|
if(action =="open")
|
{
|
m_DocumentID = arg.GetArgString("DocumentID");
|
xml x = new xml;
|
x.setNativePointer(xml::CreateInstance());
|
string prestr = m_DocumentID.mid(0,2);
|
prestr = prestr.upper();
|
xaserver::LoadUrl(GetServerUrl(),"/business/data/bill/"+prestr+"/"+ m_DocumentID+".jpg","",x);
|
if(x.GetXml()!="")
|
{
|
|
string content = "";
|
if(x.GetXmlDoc().documentElement.tagName=="Bill")
|
{
|
content = x.GetXmlDoc().documentElement.text;
|
content = content.replace("[¿Õ]"," ",0);
|
ole_print.LoadHtml(content);
|
}else
|
{
|
if(x.GetXmlDoc())
|
{
|
/*if(!showgrid)
|
{
|
SendCtrlCmd(cell,"xmFormatShowGrid");
|
showgrid = true;
|
}*/
|
xml x1 = new xml;
|
x1.setNativePointer(xml::CreateInstance());
|
string content1 = x.GetXml();
|
content1 = content1.replace("[¿Õ]"," ",0);
|
//trace(content1);
|
x1.LoadXml(content1);
|
cell.LoadTemplate(x1.GetXmlDoc());
|
cell.Redraw();
|
}
|
content = x.GetXml();
|
content = content.replace("[¿Õ]"," ",0);
|
ole_print.LoadHtml(content);
|
}
|
}else
|
{
|
ole_print.LoadHtml("<html><body>δÕÒµ½¶ÔÓ¦µÄÎĵµ</body></html>");
|
//cell.LoadHtml("<html><body>δÕÒµ½¶ÔÓ¦µÄÎĵµ</body></html>");
|
}
|
}
|
else
|
{
|
string templateName = arg.GetArgString("template-name");
|
win32::SetWindowText(GetHWND(),templateName);
|
billName = templateName;
|
billPre = arg.GetArgString("template-pre");
|
billID = arg.GetArgString("template-guid");
|
m_EntityID = arg.GetArgString("EntityID");
|
m_EntityNo = arg.GetArgString("EntityNo");
|
m_EntityName = arg.GetArgString("EntityName");
|
m_DocumentID = "";
|
OnHtml(arg);
|
}
|
}
|
}
|
return 1;
|
}
|
|
int SetAgent()
|
{
|
string xfNodeAgentArea = "agentarea";
|
xnode anode = GetAgentNode(xfNodeAgentArea);
|
msxml::IXMLDOMElement xframeElement = GetElement();
|
msxml::IXMLDOMNode agent = xframeElement.selectSingleNode("agent/"+xfNodeAgentArea+"[1]/*");
|
|
msxml::IXMLDOMNodeList nlist;
|
int index;
|
int nlen;
|
msxml::IXMLDOMElement ele;
|
string tools="<hbox class=''>";
|
if(agent)
|
{
|
nlist = agent.SelectNodes(".//xtoolbutton");
|
nlen = nlist.length;
|
for(index=0;index<nlen;index++)
|
{
|
ele = nlist.item(index);
|
string name = ele.selectSingleNode("@name").text;
|
string label = ele.selectSingleNode("@caption").text;
|
string image;
|
string src = "";
|
if(ele.selectSingleNode("@image"))
|
image = ele.selectSingleNode("@image").text;
|
else
|
image = "0 22";
|
|
if(ele.selectSingleNode("@src"))
|
src = ele.selectSingleNode("@src").text;
|
|
int strLen = label.length();
|
int width = 60 + (strLen - 2) * 10;
|
string tool;
|
if (src != "")
|
tool = "<xtoolbutton src='"+src+"' caption='"+label+"' name='"+name+"' height='28' class1='action'/>";
|
else
|
tool = "<xtoolbutton image='"+image+"' caption='"+label+"' name='"+name+"' height='28' class1='action'/>";
|
tools += tool;
|
}
|
}
|
tools +="</hbox>";
|
SetAgentNodeContent(anode, tools);
|
return 1;
|
}
|
|
//½¹µã¼¤»î´¦Àíº¯Êý
|
int OnSetFocus(ref TNotifyEvent evt,int p)
|
{
|
//ÖØÖù¤¾ßÌõ
|
SetAgent();
|
return 1;
|
}
|
|
int OnEdit()
|
{
|
editing = !editing;
|
if(editing)
|
{
|
SwitchLayer("cellview","viewclient");
|
}else
|
{
|
htmlStr = cell.GetHtml();
|
//string content = htmlStr;
|
htmlStr = htmlStr.replace("[¿Õ]"," ",0);
|
htmlStr = htmlStr.replace("[line]","<br/>",0);
|
ole_print.LoadHtml(htmlStr);
|
SwitchLayer("oleview","viewclient");
|
}
|
return 1;
|
}
|
|
int OnSaveAs() //Áí´æÎª...
|
{
|
ole_print.ExecWB(4,2);
|
return 1;
|
}
|
int OnPrint() //´òÓ¡
|
{
|
ole_print.ExecWB(6, 0);
|
return 1;
|
}
|
int PrintPaper() //´òÓ¡
|
{
|
//ole_print.GetHtmlDocument();
|
//return 1;
|
_mshtml::IHTMLDocument3 doc = ole_print.GetHtmlDocument();
|
_mshtml::IHTMLElementCollection rows = doc.getElementsByTagName("tr");
|
|
int len = rows.length;
|
for(int i=0; i < len - 1;i++)
|
{
|
//oleobject v = rows.item(i,i);
|
_mshtml::IHTMLElement e = rows.item(i,i);
|
_mshtml::IHTMLElement2 e1 = e;
|
//e.setAttribute("height",e1.clientHeight,0);
|
e.setAttribute("height",300,0);
|
e.Release();
|
e1.Release();
|
}
|
rows.Release();
|
doc.Release();
|
/*
|
if(PaperPrint == false)
|
{
|
ole_print.GetHtmlDocument().body.style.visibility="hidden";
|
PaperPrint = true;
|
}
|
else
|
{
|
ole_print.GetHtmlDocument().body.style.visibility="visible";
|
PaperPrint = false;
|
}
|
*/
|
return 1;
|
}
|
int OnPrintPreview() //´òÓ¡Ô¤ÀÀ
|
{
|
ole_print.ExecWB(7, 0);
|
return 1;
|
}
|
int OnPageSetup() //Ò³ÃæÉèÖÃ
|
{
|
ole_print.ExecWB(8, 0);
|
return 1;
|
}
|
int OnPortrait() //×ÝÏò
|
{
|
alert("Portrait");
|
return 1;
|
}
|
int OnLandscape() //ºáÏò
|
{
|
return 1;
|
}
|
int OnPageProperty() //²é¿´Ò³ÃæÊôÐÔ
|
{
|
ole_print.ExecWB(10, 1);
|
return 1;
|
}
|
int OnCustom() //×Ô¶¨Òå:? 25-400%
|
{
|
return 1;
|
}
|
|
int OnAddToDocument()
|
{
|
string content = htmlStr;
|
if(editing)content = cell.GetHtml();
|
string guid = publiccode::GetGuid();
|
|
string prestr = guid.mid(0,2);
|
prestr = prestr.upper();
|
|
|
content = content.replace("gb2312","utf-16",0);
|
content = content.replace(" ","[¿Õ]",0);
|
content = content.replace("&","",0);
|
|
xml x0 = new xml;
|
x0.setNativePointer(xml::CreateInstance());
|
x0.LoadXml("<Bill/>");
|
x0.GetXmlDoc().documentElement.text = content;
|
content = x0.GetXml();
|
|
int ret= xaserver::UploadData("bill"+prestr, guid+".jpg", content);
|
if(ret < 0) trace("error upload");
|
|
string ls_xml ="<DocumentList guid='"+guid+"' update.modify='1' update.new='1'>";
|
ls_xml += "<EntityName>"+ m_EntityName + "</EntityName>";
|
ls_xml += "<EntityID>"+ m_EntityID + "</EntityID>";
|
ls_xml += "<EntityNo>"+ m_EntityNo + "</EntityNo>";
|
ls_xml += "<BillID>"+ billID + "</BillID>";
|
ls_xml += "<BillName>"+ billName + "</BillName>";
|
ls_xml += "</DocumentList>";
|
|
xml x = new xml;
|
x.setNativePointer(xml::CreateInstance());
|
x.LoadXml(ls_xml);
|
xaserverarg arg = new xaserverarg;
|
arg.setNativePointer(xaserverarg::CreateInstance());
|
arg.AddArg("content",x.GetXml());
|
|
if(url::get("/sale/data/DocumentList3/bill/update", arg.GetString(),x)!=1)
|
{
|
string error = x.GetXmlDoc().text;
|
alert("err:"+error);
|
return 1;
|
}
|
string str = x.GetXmlDoc().documentElement.getAttribute("text");
|
if(str == "true")
|
{
|
alert("±£´æ³É¹¦!");
|
updated = false;
|
}else
|
{
|
alert("±£´æÊ§°Ü!");
|
}
|
|
return 1;
|
}
|
|
int SendCtrlCmd(xcontrol xc, string cmd)
|
{
|
win32::SendMessage(xc.GetId(),0x401,cmd,0);
|
return 1;
|
}
|
|
int OnRefreshData()
|
{
|
xaserverarg arg = new xaserverarg;
|
arg.setNativePointer(GetParam());
|
string templateName = arg.GetArgString("template-name");
|
win32::SetWindowText(GetHWND(),templateName);
|
OnHtml(arg);
|
billName = templateName;
|
billPre = arg.GetArgString("template-pre");
|
billID = arg.GetArgString("template-guid");
|
m_EntityID = arg.GetArgString("EntityID");
|
m_EntityNo = arg.GetArgString("EntityNo");
|
m_EntityName = arg.GetArgString("EntityName");
|
m_DocumentID = "";
|
return 1;
|
}
|
|
int OnCmdDispatch(string comdid)
|
{
|
if(comdid=="xmSort")
|
{
|
OpenWindow("dev:xpage[DataSort.dialog.vx]",cast(m_dataset as int));
|
return 1;
|
}
|
if(comdid=="print:PrintImmediate")
|
{
|
updated = true;
|
return OnPrint();
|
}
|
if(comdid=="print:PrintPaper") {
|
updated = true;
|
return PrintPaper();
|
}
|
if(comdid=="print:PrintPreview") {
|
updated = true;
|
return OnPrintPreview();
|
}
|
if(comdid=="print:Portrait") {
|
updated = true;
|
return OnPortrait();
|
}
|
if(comdid=="print:Landscape") {
|
updated = true;
|
return OnLandscape();
|
}
|
if(comdid=="print:PageSetup") {
|
updated = true;
|
return OnPageSetup();
|
}
|
if(comdid=="print:Custom") {
|
updated = true;
|
return OnCustom();
|
}
|
if(comdid=="print:PrintDialog")
|
{
|
if(updated)
|
{
|
int res = win32::MessageBox(this.GetHWND(), "µ¥¾ÝÒÑÖÆ×÷£¬ÊÇ·ñ±£´æ?","Ìáʾ",4);
|
if(res == 6)OnCmdDispatch("print:AddToDocumentList");
|
}
|
if(GetParam())
|
{
|
xaserverarg arg1 = new xaserverarg;
|
arg1.setNativePointer(GetParam());
|
arg1.AddArg("action","new");
|
OnPrintDialog();
|
arg1.AddArg("action","");
|
}
|
return 1;
|
}
|
if(comdid.find("print:toExcel",0)>=0) {
|
updated = true;
|
return OntoExcel();
|
}
|
if(comdid.find("print:Export",0)>=0) {
|
updated = true;
|
return OnExport();
|
}
|
if(comdid.find("print:SaveAs",0)>=0) return OnSaveAs();
|
if(comdid.find("print:Edit",0)>=0) {
|
updated = true;
|
return OnEdit();
|
}
|
if(comdid.find("action:Close",0)>=0) return CloseWindow();
|
if(comdid=="print:OpenDocument") return OnOpenDocument();
|
if(comdid=="print:AddToDocumentList") return OnAddToDocument();
|
if(comdid.find("action:",0)>=0) return ProcessFlowAction(comdid, 1);
|
|
if(comdid.left(3) == "xmSort")
|
{
|
//string str =
|
return 1;
|
}
|
|
if(comdid.left(3) == "IK_")
|
{
|
string cmd = comdid.mid(3, comdid.length());
|
SendCtrlCmd(cell,cmd);
|
return 1;
|
}
|
if(comdid=="print:MaintTemplate")
|
{
|
OpenWindow("dev:xpage[Maint.Template.Print.vx]");
|
return 1;
|
}
|
if(comdid == "print:RefreshData"){
|
return OnRefreshData();
|
}
|
|
if(comdid == "xxx")
|
{
|
ole_print.ExecWB(27,0);
|
return 1;
|
alert("xxx");
|
xml x1 = new xml;
|
x1.setNativePointer(xml::CreateInstance());
|
xaserver::ExecXQuery(GetServerUrl(), "[xsl.getdevobj.xq]","<args/>",x1);
|
}
|
|
if(comdid == "xxx")
|
{
|
xml x = new xml;
|
x.setNativePointer(xml::CreateInstance());
|
xaserverarg arg = new xaserverarg;
|
arg.setNativePointer(arg.CreateInstance());
|
arg.AddArg("strHtml",m_strHtml);
|
if (url::get("/sale/data/SysPrintTemplate/WebBrowser",arg.GetString(),x) != 1)
|
{
|
alert("Êý¾Ý¼¯³ö´íÁË!");
|
return 0;
|
}
|
string strHtml = x.GetXml();
|
ole_print.LoadHtml(strHtml);
|
}
|
return 0;
|
}
|
|
int OnXCommand(ref TXCommandEvent evt,int p)
|
{
|
return OnCmdDispatch(evt.pStrID);
|
}
|
|
int OnAttachEvent()
|
{
|
AttachEvent("WM_XCOMMAND",OnXCommand);
|
AttachEvent("WM_SETFOCUS",OnSetFocus);
|
//AttachEvent("WM_CLOSE",OnCloseOwnerWindow);
|
|
return 0;
|
}
|
|
int getURLParam()
|
{
|
return 1;
|
}
|
|
virtual int BeforeCloseWindow()
|
{
|
if(!updated) return 1;
|
|
int MB_YESNOCANCEL = 3;
|
int IDYES = 6;
|
int IDNO = 7;
|
int IDCANCEL = 2;
|
int re = win32::MessageBox(this.GetHWND(), "µ¥¾ÝÒÑÖÆ×÷£¬ÊÇ·ñ±£´æ?","Ìáʾ:",MB_YESNOCANCEL);
|
if(re==IDCANCEL) return -1;
|
if(re==IDNO) return 1;
|
OnCmdDispatch("print:AddToDocumentList");
|
return -1;
|
}
|
|
int onload()
|
{
|
OnAttachEvent();
|
AttachCloseWindow();
|
ole_print = GetControl("ole_print");
|
cell = GetControl("xcell");
|
|
//showgrid = false;
|
editing = false;
|
SetAgent();
|
|
m_dataset = 0;
|
billName = "";
|
billID = "";
|
billPre = "";
|
m_DocumentID = "";
|
PaperPrint = false;
|
|
return 1;
|
}
|
|
int onloaded()
|
{
|
updated = false;
|
if(GetParam())
|
{
|
xaserverarg arg = new xaserverarg;
|
arg.setNativePointer(GetParam());
|
string templateName = arg.GetArgString("template-name");
|
if(templateName =="")
|
{
|
OnPrintDialog();
|
}
|
|
else
|
{
|
win32::SetWindowText(GetHWND(),templateName);
|
OnHtml(arg);
|
billName = templateName;
|
billPre = arg.GetArgString("template-pre");
|
billID = arg.GetArgString("template-guid");
|
m_EntityID = arg.GetArgString("EntityID");
|
m_EntityNo = arg.GetArgString("EntityNo");
|
m_EntityName = arg.GetArgString("EntityName");
|
m_DocumentID = "";
|
}
|
}else
|
OnPrintDialog();
|
return 1;
|
}
|
|
};
|