ÿþ#include <guiddef.h> #include <exdisp.h> // Defines of stuff like IWebBrowser2. This is an include file with Visual C 6 and above #include <mshtml.h> // Defines of stuff like IHTMLDocument2. This is an include file with Visual C 6 and above #include <mshtmhst.h> // Defines of stuff like IDocHostUIHandler. This is an include file with Visual C 6 and above #include <Shlwapi.h> #include <Windows.h> #include <comutil.h> #undef _XWIN #include <wobject/xstring.hpp> #include <xcontrol/xtreeview.hpp> #include <xcontrol/xdwgrid.hpp> #include <win32/xfile.hpp> #include <xcontrol/xexcel.hpp> #include "vbusiness/vframe/listwin.vframe.vbusiness.hpp" #include "viewobject/view.base.hpp" #include "vbusiness/vframe/frame.vframe.vbusiness.hpp" using xml = KXMLDOMDocument; class __declspec(dllexport) NewSample3 : public xframe { public: NewSample3(void* implPtr, HWND hWnd) :xframe(implPtr, hWnd) {} public: static NewSample3* CreateInstance(void* implPtr, void* hWnd) { return new NewSample3(implPtr, (HWND)hWnd); } public: xdwgrid dw_list; xdwtable dw_arg; xnode m_agentNode; //Agent Condition int SetAgent() { xstring xfNodeAgentArea = L"agentarea"; xnode anode = GetAgentNode(xfNodeAgentArea); if(m_agentNode) { SetAgentNode (anode,m_agentNode); } else { KXMLDOMElement xframeElement = GetElement(); KXMLDOMElement agent = xframeElement.selectSingleNode(L"agent/"+xfNodeAgentArea+L"[1]/*"); if(agent) { xstring s = agent.xml(); m_agentNode = SetAgentNode (anode,s); } } return 1; } //&q¹pÀo;mYtýQpe int OnSetFocus(TEvent* evt, LPARAM param) { //͑nå]wQag SetAgent(); return 1; } int OnLookImage(xstring skuid) { HCURSOR hCursor = xutil::SetCursorWait(); xaserverarg arg; arg.AddArg(L"guid",skuid); OpenWindow(L"dev:xpage[ViewPictures.vx]",arg); xutil::RestoreCursor(hCursor); return 1; } int OnPrint() { xaserverarg arg; arg.AddArg(L"EntityName",L"Quote",L""); arg.AddArg(L"EntityID",L"",L""); arg.AddArg(L"EntityNo",L"22JR0089",L""); openUrl(L"/sale/view/view.base/xpage/Template/PrintViewEx", arg); return 1; } xstring GetMySaveFileName(xstring initFileName, xstring filter, xstring ext) { wchar_t szFileName[255] = { 0 }; wchar_t szPath[255] = { 0 }; if (initFileName != L"") { int len = initFileName.length(); const wchar_t* tmp = initFileName; for (int i = 0; i < len + 1; i++) { //szFileName[i] = tmp[i]; szPath[i] = tmp[i]; } } int nFilterIndex = 1; OPENFILENAMEW ofn = { 0 }; //::ZeroMemory(&ofn,sizeof(OPENFILENAMEW)) //ofn.lStructSize = 88;//sizeof(ofn); ofn.lStructSize = sizeof(ofn); ofn.hwndOwner = GetHWND(); 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 = L"÷‹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 (xfile::GetSaveFileName(ofn)) { return szPath; } else { return L""; } } xstring GetModulePath() { wchar_t str[255]; GetModuleFileName(0, str, 255); PathRemoveFileSpec(str); return str; } xstring GetModuleTmpPath() { wchar_t str[255]; GetModuleFileName(0, str, 255); PathRemoveFileSpec(str); xstring tmp = (xstring)str + L"\\Temp"; xaserver::CreateDirectory(tmp); return tmp; } xstring getfilePath() { xstring path = GetModulePath() + L"\\resource\\image"; return path; } xstring replaceInnerElement(xstring html) { xstring str = html; if (str.find(L"[$element:") < 0) return str; int len = 0; int pos = 0; int pos1 = 0; xstring pre = L""; xstring left = L""; xstring right = L""; xstring tag = L""; len = ((xstring)L"[$element:").length(); while (true) { pos = str.find(L"[$element:"); if (pos < 0) break; left = str.left(pos); right = str.mid(pos + len, 999999); pos1 = right.find(L"]"); if (pos1 >= 0) { tag = right.left(pos1); if (tag.right(1) == L"$") tag = tag.left(tag.length() - 1); pre = pre + left + L"<" + tag + L">"; str = right.mid(pos1 + 1, 999999); } else { pre = pre + left + L"<"; str = right; } } str = pre + str; pre = L""; len = ((xstring)L"[/$element:").length(); while (true) { pos = str.find(L"[/$element:"); if (pos < 0) break; left = str.left(pos); right = str.mid(pos + len, 999999); pos1 = right.find(L"]"); if (pos1 >= 0) { tag = right.left(pos1); if (tag.right(1) == L"$") tag = tag.left(tag.length() - 1); pre = pre + left + L"</" + tag + L">"; str = right.mid(pos1 + 1, 999999); } else { pre = pre + left + L"</"; str = right; } } str = pre + str; return str; } xstring adjustXsl(xstring str, xstring localPath) { //if(str.find("%")>=0) str = str.replace("%",""); if (str.find(L"[$path]/rpttemplate") >= 0) str = str.replace(L"[$path]/rpttemplate", localPath); str = replaceInnerElement(str); return str; } xstring DownLoadSKUNoPic(xstring serverUrl, xstring SKUNo, xstring CustomerID = L"", xstring CustomerItemNo = L"") { xml x ; xaserverarg arg ; arg.AddArg(L"SKUNo", SKUNo); xstring src = L"/sale/data/ProductLibrary3/pref/picture/imagelistSKUNo"; if (CustomerID != L"") { arg.AddArg(L"CustomerID", CustomerID); arg.AddArg(L"CustomerItemNo", CustomerItemNo); src = L"/sale/data/ProductLibrary3/pref/picture/customer/imagelistSKUNo"; } //trace("SKUNo="+SKUNo);//‰ gU\:yþVGrågâ‹agöN…QÅ_š[‰skuno if (xurl::get(src, arg.GetString(), x) != 1) { trace(L"error for download skuno pic!"); return L""; } xstring spath = L""; xstring path = GetModuleTmpPath(); xstring ext = L"jpg"; if (x.selectSingleNode(L"//FileExt[1]")) { ext = x.selectSingleNode(L"//FileExt[1]").text(); } else if (CustomerID != L"") { src = L"/sale/data/ProductLibrary3/pref/picture/imagelistSKUNo"; if (xurl::get(src, arg.GetString(), x) != 1) { trace(L"error for download skuno pic!"); return L""; } if (x.selectSingleNode(L"//FileExt[1]")) ext = x.selectSingleNode(L"//FileExt[1]").text(); } xstring filename = SKUNo + L"." + ext; if (x.selectSingleNode(L"//PicPath[1]")) spath = x.selectSingleNode(L"//PicPath[1]").text(); if (spath != L"") { xaserver::DownLoadFile(serverUrl, spath, L"", path + L"/" + filename); } return L"file://" + path + L"/" + filename; } xstring DownLoadPaperPic(xstring guid, xstring serverUrl) { xstring path = GetModuleTmpPath(); xstring ext = L"jpg"; xstring filename = guid + L"." + ext; xstring str = guid.mid(0, 2); xstring spath = L"/business/products/chanpin/" + str + L"/" + guid + L".jpg"; xaserver::DownLoadFile(serverUrl, spath, L"", path + L"/" + filename); return L"file://" + path + L"/" + filename; } xstring GetHtml(xdwgrid dw_obj, xstring xslPath, xstring serverUrl) { HCURSOR hCursor = xutil::SetCursorWait(); xml m_dataset; dw_obj.DwUpdateAllTo(m_dataset); xstring argstr = L"<args><arg name='xsl' value='/business/" + xslPath + L"' type=''/></args>"; xml xsl; if (xurl::get(L"/sale/data/SysPrintTemplate/getxsl", argstr, xsl) != 1) { alert(L"penc!jg•ï‹!"); return L""; } xstring xslStr = xsl.xml(); xslStr = xslStr.replace(L"data/row", L"data"); xslStr = xslStr.replace(L"//ÁT T1/ĉ", sdate); xslStr = adjustXsl(xslStr, getfilePath()); trace(L"-----" + xslStr + L"-------"); xsl.loadXML(xslStr); xstring htmlStr = m_dataset.transformNode(xsl); xstring aspace = htmlStr.replace(L"[zz]", L"&nbsp;", 0); aspace = aspace.replace(L"[line]", L"<br/>", 0); xstring scontent = aspace.replace(L"<?xml version=\"1.0\"?>", L"", 0); xstring head = L""; xstring tail = scontent; int pos = tail.find(L"src=\"item-picture:"); while (pos > 0) { int spos = pos + ((xstring)L"src=\"item-picture:").length(); int pos1 = tail.find(L"\"", spos + 1); xstring skuno = tail.mid(spos, pos1 - spos).trim(); xstring CustomerID = L""; xstring CustomerItemNo = L""; if (skuno.find(L",") > 0) { CustomerID = skuno.left(skuno.find(L",")).trim(); skuno = skuno.mid(skuno.find(L",") + 1, 256).trim(); } if (skuno.find(L",") > 0) { CustomerItemNo = skuno.left(skuno.find(L",")).trim(); skuno = skuno.mid(skuno.find(L",") + 1, 256).trim(); } xstring src = DownLoadSKUNoPic(serverUrl, skuno, CustomerID, CustomerItemNo); head += tail.left(pos) + L"src=\"" + src; tail = tail.mid(pos1, 999999999); pos = tail.find(L"src=\"item-picture:"); } scontent = head + tail; head = L""; tail = scontent; int position = tail.find(L"src=\"paper-picture:"); while (position > 0) { int sposition = position + ((xstring)L"src=\"paper-picture:").length(); int position1 = tail.find(L"\"", sposition + 1); xstring guid = tail.mid(sposition, position1 - sposition).trim(); xstring src2 = DownLoadPaperPic(guid, serverUrl); head += tail.left(position) + L"src=\"" + src2; tail = tail.mid(position1, 999999999); position = tail.find(L"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; } int OnExport(HWND hWnd, xstring htmlStr) { xstring pre = L"eQ“^°eÁTß~¡‹hˆ"; xstring file = GetMySaveFileName(pre + L".xlsx", L"Excel‡eöN(*.xlsx)\0*.xlsx;*.xls\0Excel97‡eöN(*.xls)\0*.xls\0PDF‡eöN(*.pdf)\0*.pdf\0", L"xlsx"); if (file == L"") return 1; if (PathFileExists(file)) { int res = MessageBox(GetHWND(), L"‡eöNò]Ï~X[(W ÿ/f&T†‰Öv?", L"Ðc:y", 4); if (res != 6) return 1; } xutil::SaveToFile(file, htmlStr, L"", L"", (LPTSTR)L""); return 1; } int OntoExcel(xstring htmlStr) //l:NExcel { xexcel excel; xstring gid = publiccode::GetGuid(); xstring pre = L"eQ“^°eÁTß~¡‹hˆ"; xstring filename = pre + L".htm"; xstring filenameex = pre + L".xlsx"; xutil::SaveToFile(GetModuleTmpPath() + L"\\" + filename, htmlStr, L"", L"", (LPTSTR)L""); excel.OpenDocument(GetModuleTmpPath() + L"\\" + filename); //excel.put_Visible(true); //excel.TransShape(); if (PathFileExists(GetModuleTmpPath() + L"\\" + filenameex)) DeleteFile(GetModuleTmpPath() + L"\\" + filenameex); excel.SaveToFile(GetModuleTmpPath() + L"\\" + filenameex); excel.put_Visible(true); return 1; } //}TäNÑS^ýQpe int OnCmdDispatch(xstring comdid) { HCURSOR hCursor = 0; if (comdid == L"xmRefresh") { OnRetrieve(); } if(comdid==L"xmLookImage") { int row = dw_list.GetRow(); xstring skuid =dw_list.GetGuid(row); OnLookImage(skuid); return 1; } if(comdid==L"xmAnalysis") { hCursor = xutil::SetCursorWait(); xstring str = dw_list.DataAnalysis(L""); xaserverarg arg; arg.AddArg(L"html", str); OpenWindow(L"dev:xpage[data.vanalysis.vx]", arg); xutil::RestoreCursor(hCursor); return 1; } else if(comdid==L"xmExcel") { OntoExcel(GetHtml(dw_list,L"rpttemplate/Quote/A7510DD6-04BE-41E8-8CB1-A14DCA11D303.xsl",GetServerUrl())); return 1; } else if(comdid==L"xmSaveAs") { /*xstring file = exporter.GetSaveFileName(L"eQ“^°eÁTß~¡‹hˆ"+L".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(L""); xstring htmlStr = GetHtml(dw_list,L"rpttemplate/Quote/A7510DD6-04BE-41E8-8CB1-A14DCA11D303.xsl",GetServerUrl()); OnExport(GetHWND(), htmlStr); return 1; } else if(comdid==L"xmPrint") { OnPrint(); return 1; } return 0; } //æ‰ÑS Ÿh»y_Ttran‹NöN ÿÇåg~bÐg*NÂSpe—_0Rù[”^„vR int OnBaseItemChanged(TEvent* evt, int p) { DWNMHDR& hdr = *(DWNMHDR*)evt->notify.pnmh; xstring colname=hdr.colname; xstring value = hdr.data; xstring dwname = L"dw_list"; if(value != L"") { KXMLDOMNodeList nlist = GetElement().selectNodes(L"//*[@name='"+dwname+L"']/trans[@for='"+colname+L"']"); ViewObject::TransData(nlist, dw_list, hdr.row, colname, value); } return 1; } //}TäNYt‹NöN int OnXCommand(TEvent* evt, LPARAM param) { return OnCmdDispatch(evt->xcommand.pStrID); } int OnAttachEvent() { //Ñ~š[å]wQag¹pûQ‹NöN AttachEvent(L"WM_XCOMMAND", (FEvent)&NewSample3::OnXCommand); //·ƒÖS&q¹p‹NöN ÿ(uŽN͑nå]wQag AttachEvent(L"WM_SETFOCUS", (FEvent)&NewSample3::OnSetFocus); AttachEvent(L"dw_list",L"DWV_ITEMCHANGED", (FEvent)&NewSample3::OnBaseItemChanged); return 1; } xstring GetQueryArg() { dw_arg.AcceptText(); xml x ; dw_arg.DwUpdateAllTo(x); return x.xml(); } int OnRetrieve() { xml x ; xaserverarg arg ; arg.AddArg(L"QueryTxt",xcontrol(GetControl(L"search")).GetText()); arg.AddArg(L"QueryArg",GetQueryArg()); trace(GetQueryArg()); if (getUrl(L"/sale/data/Sample/entity/NewPageList",arg.GetString(),x)!=1) { alert(x.xml()); trace(x.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(L"dw_list"); dw_list.openUrl(L"/sale/view/Sample/template/Sample/7hÁTô•°eÁT"); dw_list.SetColumnState(L"SKUNo",false); dw_arg = GetControl(L"dw_arg"); dw_arg.openUrl(L"/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,L"DateType",L",gt^"); OnRetrieve(); OnAttachEvent(); return 1; } int onloaded() { SetAgent(); return 1; } };