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