ÿþuse "xcontrol.vframe.vbusiness.vd" use "xbase.vframe.vbusiness.vd" use "base.view.vd" use "publiccode.vutil.vbusiness.vd" unit trade [ namespace _excel for ole "Excel.Application,{00020813-0000-0000-C000-000000000046}"; 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 OPENFILENAMEW { 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 Exporter { cexcel excel; 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 OPENFILENAMEW)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 OPENFILENAMEW ofn = new OPENFILENAMEW; ofn.lStructSize = 88;//sizeof(ofn); ofn.hwndOwner = 0; ofn.hInstance = 0; ofn.lpstrFilter = filter; //"JPEG ‡eöN(*.jpg)\0*.jpg;*.jpeg;*.png;*.gif;*.bmp\0hQ萇eöN(*.*)\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 = "÷‹cš[‡eöN T"; 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 ""; } } string getfilePath() { string path=GetModulePath()+"\\resource\\image"; return path; } int OnExport(int hWnd,string htmlStr) { string pre ="eQ“^°eÁTß~¡‹hˆ"; string file = GetSaveFileName(pre+".xlsx", "Excel‡eöN(*.xlsx)\0*.xlsx;*.xls\0Excel97‡eöN(*.xls)\0*.xls\0PDF‡eöN(*.pdf)\0*.pdf\0", "xlsx"); if(file =="") return 1; if(win32::PathFileExists(file)) { int res = win32::MessageBox(hWnd, "‡eöNò]Ï~X[(W ÿ/f&T†‰Öv?","Ðc:y",4); if(res != 6) return 1; } xutil::SaveToFile(file, htmlStr,"","",""); return 1; trace("\r\n link excel"); excel = new cexcel; int hexcel = cexcel::CreateInstance(); excel.setNativePointer(hexcel); if(hexcel == 0) { win32::alert(" Ný€Þ¥cExcel"); return 1; } string gid = publiccode::GetGuid(); string filename= pre+"_.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(file.find(".xls")) { if(win32::PathFileExists(GetModuleTmpPath() + "\\"+ pre+"_.xls")) DeleteFile(GetModuleTmpPath() + "\\"+ pre+"_.xls"); excel.SaveToFile(GetModuleTmpPath() + "\\"+ pre+"_.xls"); //alert(GetModuleTmpPath() + "\\"+ pre+m_EntityNo+"_.xls"); } else { if(win32::PathFileExists(GetModuleTmpPath() + "\\"+ pre+"_.xlsx")) DeleteFile(GetModuleTmpPath() + "\\"+ pre+"_.xlsx"); excel.SaveToFile(GetModuleTmpPath() + "\\"+ pre+"_.xlsx"); } trace("\r\n save to excel file"); if(win32::PathFileExists(file)) //GetModuleTmpPath() + "\\"+ pre+m_EntityNo+"_.xlsx")) DeleteFile(file); excel.SaveToFile(file); excel.Quit(); excel.Release(excel.ptr_native_); return 1; } int OntoExcel(string htmlStr ) //l:NExcel { excel = new cexcel; excel.setNativePointer(cexcel::CreateInstance()); string gid = publiccode::GetGuid(); string pre = "eQ“^°eÁTß~¡‹hˆ"; string filename= pre+".htm"; string filenameex= pre+".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 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 serverUrl,string SKUNo,string CustomerID="",string CustomerItemNo="") { 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);//‰ gU\:yþVGrågâ‹agöN…QÅ_š[‰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(serverUrl,spath,"",path+"/"+filename); } return "file://"+ path+"/"+filename; } string DownLoadPaperPic(string guid,string serverUrl) { 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(serverUrl,spath,"",path+"/"+filename); return "file://"+ path+"/"+filename; } string GetHtml(xdwgrid dw_obj, string xslPath,string serverUrl) { int hCursor = xutil::SetCursorWait(); xml m_dataset = new xml; m_dataset .setNativePointer(xml::CreateInstance()); dw_obj.DwUpdateAllTo(m_dataset.GetXmlDoc()); string argstr = "<args><arg name='xsl' value='/business/"+xslPath+"' type=''/></args>"; xml xsl = new xml; xsl.setNativePointer(xml::CreateInstance()); if (url::get("/sale/data/SysPrintTemplate/getxsl",argstr ,xsl) != 1) { win32::alert("penc!jg•ï‹!"); return ""; } string xslStr = xsl.GetXml(); xslStr = xslStr.replace("data/row","data"); xslStr = xslStr.replace("//ÁT T1/ĉ",sdate); xslStr = adjustXsl(xslStr,getfilePath()); trace("-----"+xslStr+"-------"); xsl.LoadXml(xslStr); string htmlStr = m_dataset.GetXmlDoc().transformNode(xsl.GetXmlDoc()); string aspace = htmlStr.replace("[zz]","&nbsp;",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(serverUrl,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,serverUrl); head += tail.left(position) + "src=\"" + src2; tail = tail.mid(position1,999999999); position = tail.find("src=\"paper-picture:"); } scontent = head + tail; //scontent = adjustXsl(scontent,sPath); htmlStr = scontent; /* string xcontent = htmlStr.replace("[zz]"," ",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; }*/ return htmlStr; } }; ] unit trade [ class NewSample3 : public xframe { xdwgrid dw_list; xdwtable dw_arg; xnode m_agentNode; //Agent Condition int SetAgent() { string xfNodeAgentArea = "agentarea"; xnode anode = GetAgentNode(xfNodeAgentArea); if(m_agentNode) { SetAgentNodeContent (anode,m_agentNode); } else { msxml::IXMLDOMElement xframeElement = GetElement(); msxml::IXMLDOMElement agent = xframeElement.selectSingleNode("agent/"+xfNodeAgentArea+"[1]/*"); if(agent) { string s = agent.xml; m_agentNode = SetAgentNodeContent (anode,s); } } return 1; } //&q¹pÀo;mYtýQpe int OnSetFocus(ref TEvent evt,int param) { //͑nå]wQag SetAgent(); return 1; } int OnLookImage(string skuid) { int hCursor = xutil::SetCursorWait(); xaserverarg arg = ViewObject::MakeArg(); arg.AddArg("guid",skuid); OpenWindow("dev:xpage[ViewPictures.vx]",arg.getNativePointer()); xutil::RestoreCursor(hCursor); return 1; } int OnPrint() { xaserverarg arg=new xaserverarg; arg.setNativePointer(arg.CreateInstance()); arg.AddArg("EntityName","Quote",""); arg.AddArg("EntityID","",""); arg.AddArg("EntityNo","22JR0089",""); int p = arg.ptr_native_; openUrl("/sale/view/view.base/xpage/Template/PrintViewEx", p); return 1; } //}TäNÑS^ýQpe int OnCmdDispatch(string comdid) { int hCursor = 0; if (comdid == "xmRefresh") { OnRetrieve(); } if(comdid=="xmLookImage") { int row = dw_list.GetRow(); string skuid =dw_list.GetGuid(row); OnLookImage(skuid); return 1; } if(comdid=="xmAnalysis") { hCursor = xutil::SetCursorWait(); string str = dw_list.DataAnalysis(""); xaserverarg arg=new xaserverarg; arg.setNativePointer(arg.CreateInstance()); arg.AddArg("html", str); int obj = cast(dw_list as int); arg.AddArg("obj",obj.toString()); OpenWindow("dev:xpage[data.vanalysis.vx]", cast(arg as int)); xutil::RestoreCursor(hCursor); return 1; } else if(comdid=="xmExcel") { Exporter exporter1 = new Exporter; exporter1.OntoExcel(exporter1.GetHtml(dw_list,"rpttemplate/Quote/A7510DD6-04BE-41E8-8CB1-A14DCA11D303.xsl",GetServerUrl())); return 1; } else if(comdid=="xmSaveAs") { Exporter exporter = new Exporter; /*string file = exporter.GetSaveFileName("eQ“^°eÁTß~¡‹hˆ"+".xlsx", "Excel‡eöN(*.xlsx)\0*.xlsx;*.xls\0Excel97‡eöN(*.xls)\0*.xls\0PDF‡eöN(*.pdf)\0*.pdf\0", "xlsx"); */ //dw_list.SaveAs(""); string htmlStr = exporter.GetHtml(dw_list,"rpttemplate/Quote/A7510DD6-04BE-41E8-8CB1-A14DCA11D303.xsl",GetServerUrl()); exporter.OnExport(GetHWND(), htmlStr); return 1; } else if(comdid=="xmPrint") { OnPrint(); return 1; } return 0; } //æ‰ÑS Ÿh»y_Ttran‹NöN ÿÇåg~bÐg*NÂSpe—_0Rù[”^„vR int OnBaseItemChanged(ref TNotifyEvent evt,int p) { ref DWNMHDR hdr = trust(evt.pnmh as ref DWNMHDR); string colname=hdr.colname; string value = hdr.data; string dwname = "dw_list"; if(value != "") { msxml::IXMLDOMNodeList nlist = GetElement().selectNodes("//*[@name='"+dwname+"']/trans[@for='"+colname+"']"); ViewObject::TransData(nlist, dw_list, hdr.row, colname, value); } return 1; } //}TäNYt‹NöN int OnXCommand(ref TXCommandEvent evt,int param) { return OnCmdDispatch(evt.pStrID); } int OnAttachEvent() { //Ñ~š[å]wQag¹pûQ‹NöN AttachEvent("WM_XCOMMAND",OnXCommand); //·ƒÖS&q¹p‹NöN ÿ(uŽN͑nå]wQag AttachEvent("WM_SETFOCUS",OnSetFocus); AttachEvent("dw_list","DWV_ITEMCHANGED",OnBaseItemChanged); } string GetQueryArg() { dw_arg.AcceptText(); xml x = new xml; x.setNativePointer(xml::CreateInstance()); dw_arg.DwUpdateAllTo(x.GetXmlDoc()); return x.GetXml(); } int OnRetrieve() { xml x = new xml; x.setNativePointer(xml::CreateInstance()); xaserverarg arg = new xaserverarg; arg.setNativePointer(arg.CreateInstance()); arg.AddArg("QueryTxt",GetControl("search").GetText()); arg.AddArg("QueryArg",GetQueryArg()); trace(GetQueryArg()); if (getUrl("/sale/data/Sample/entity/NewPageList",arg.GetString(),x)!=1) { alert(x.GetXml()); trace(x.GetXmlDoc().text); return -1; }else { dw_list.Retrieve(x); dw_list.Redraw(); } dw_list.SetSelectionMode(1); dw_list.SetReadOnly(true); return 1; } int onload() { dw_list = GetControl("dw_list"); dw_list.openUrl("/sale/view/Sample/template/Sample/7hÁTô•°eÁT"); dw_list.SetColumnState("SKUNo",false); dw_arg = GetControl("dw_arg"); dw_arg.openUrl("/sale/view/AR/template/queryarg"); dw_arg.SetColHeaderHeight(0); dw_arg.SetRowSelectorWidth(0); dw_arg.SetHScrollState(false); dw_arg.SetVScrollState(false); dw_arg.SetItemString(1,"DateType",",gt^"); OnRetrieve(); OnAttachEvent(); return 1; } int onloaded() { SetAgent(); return 1; } }; ]