#include <wobject/xstring.hpp>
|
#include <wobject/xwin.hpp>
|
#include <wobject/xaserver.hpp>
|
#include <wobject/xaserverarg.hpp>
|
#include <xcontrol/xtreeview.hpp>
|
#include <xcontrol/xlayersheet.hpp>
|
#include <xcontrol/xdwgrid.hpp>
|
#include <xcontrol/xsedit.hpp>
|
#include <xcontrol/xcombobox.hpp>
|
#include "XDevEditPage.hpp"
|
|
using xml = KXMLDOMDocument;
|
class export XDevEditXQuery : public XDevEditPage
|
{
|
public:
|
XDevEditXQuery(void* implPtr, HWND hWnd) :XDevEditPage(implPtr, hWnd) {}
|
public:
|
static XDevEditXQuery* CreateInstance(void* implPtr, void* hWnd)
|
{
|
XDevEditXQuery* pWin = new XDevEditXQuery(implPtr, (HWND)hWnd);
|
return pWin;
|
}
|
private: //
|
xdwgrid dw_list;
|
|
xnode m_agentNode; //Agent Condition
|
xstring m_agentCond; //Agent Node
|
public:
|
int SetAgent()
|
{
|
/*
|
xstring xfNodeAgentArea = L"agentarea";
|
xnode anode = GetAgentNode(xfNodeAgentArea);
|
auto xframeElement = GetElement();
|
auto agent = xframeElement.selectSingleNode(L"agent/"+xfNodeAgentArea+L"[1]/*");
|
if(agent)
|
{
|
xstring s = agent.xml;
|
m_agentNode = SetAgentNodeContent (anode,s);
|
}
|
*/
|
return 1;
|
}
|
|
//½¹µã¼¤»î´¦Àíº¯Êý
|
int OnSetFocus(TEvent* evt,LPARAM param)
|
{
|
SetAgent();
|
|
//ÖØÖù¤¾ßÌõ
|
return 1;
|
}
|
|
int LoadData()
|
{
|
if (!GetWinParam()) return 1;
|
xstring content = GetData();
|
xsedit xs = GetControl(L"sqlcontent");
|
if (content != L"")
|
{
|
xml x;
|
x.loadXML(content);
|
KXMLDOMElement e = x.documentElement();
|
auto ele = e.selectSingleNode(L"datasource/sql");
|
if (ele)
|
xs.LoadContent(ele.text(), L".sql");
|
|
KXMLDOMElement e1 = e.selectSingleNode(L"datasource");
|
xcontrol xc = GetControl(L"datasource");
|
xstring v = e1.getAttribute(L"source");
|
xc.SetText(L"" + v);
|
xc = GetControl(L"linkname");
|
v = e1.getAttribute(L"link");
|
xc.SetText(L"" + v);
|
|
KXMLDOMElement e2 = e.selectSingleNode(L"paras");
|
xml y;
|
y.loadXML(e2.xml());
|
dw_list.Retrieve(y);
|
}
|
else
|
{
|
xs.LoadContent(L"import 'qx.object.xq'",L".sql");
|
}
|
|
return 1;
|
}
|
|
xstring ProcessDevCmdEx(xstring cmd)
|
{
|
int nlen = 0;
|
BYTE* pdata;
|
xaserver::ProcessCmd(GetServerUrl(),L"uri.hxsoft.com/xaserver/xquery:" + cmd,0,pdata,nlen);
|
if (nlen > 0)
|
{
|
xstring str = ((WCHAR*)pdata);;
|
return str.mid(0,99999999);
|
}
|
else
|
return L"";
|
}
|
|
//ÃüÁî·¢²¼º¯Êý
|
int OnCmdDispatch(xstring comdid)
|
{
|
HCURSOR hCursor = xutil::SetCursorWait();
|
if (comdid == L"xmFileSaveEx")
|
{
|
HCURSOR hCursor = xutil::SetCursorWait();
|
|
xstring content;
|
xsedit xs = GetControl(L"sqlcontent");
|
xs.GetContent(content);
|
|
xml x;
|
x.loadXML(L"<xquery/>");
|
auto root = x;
|
KXMLDOMElement e = root.createElement(L"datasource");
|
xcontrol xc = GetControl(L"datasource");
|
xstring v = xc.GetText();
|
e.setAttribute(L"source", L"" + v);
|
xc = GetControl(L"linkname");
|
v = xc.GetText();
|
e.setAttribute(L"link", L"" + v);
|
KXMLDOMElement e1 = root.createElement(L"sql");
|
e1.settext(content);
|
e.appendChild(e1);
|
root.documentElement().appendChild(e);
|
|
xml y;
|
dw_list.DwUpdateTo(y);
|
root.documentElement().appendChild(y.documentElement());
|
//trace(y.xml());
|
|
//trace(x.xml());
|
SaveContent(x.xml());
|
|
xutil::RestoreCursor(hCursor);
|
return 1;
|
}
|
else if (comdid == L"xmFilePreviewEx")
|
{
|
xstring content;
|
xsedit xs = GetControl(L"sqlcontent");
|
xs.GetContent(content);
|
|
xcombobox ddlb = GetControl(L"datasource");
|
xstring ddlbStr = ddlb.GetText();
|
if (ddlbStr == L"VSQLEx")
|
{
|
xml x ;
|
xaserverarg arg ;
|
arg.AddArg(L"sql", content);
|
xaserver::ExecXQuery(GetServerUrl(), L"[test1.xq]", arg.GetString(), x);
|
xstring data = x.xml();
|
//xsedit xc = GetControl(L"resultcontent");
|
//xc.LoadContent(L""+data,L".xml");
|
xsedit xc1 = GetControl(L"frame:vdata");
|
xc1.LoadContent(L"" + data,L".xml");
|
}
|
else
|
{
|
|
xwin w = GetFrameWindow();
|
xtreeview tv_folder = w.GetControl(L"DevExplorer");
|
HTREEITEM hItem = (HTREEITEM)GetWinParam();
|
KXMLDOMElement e = tv_folder.GetItemData(hItem);
|
xstring guid = e.getAttribute(L"guid");
|
|
xstring data;
|
if (ddlbStr == L"XQUERY")
|
{
|
data = ProcessDevCmdEx(L"" + guid);
|
}
|
else
|
{
|
data = ProcessDevCmdEx(L"" + guid);
|
xml x ;
|
xaserver::ExecXQuery(GetServerUrl(),guid,L"",x);
|
data = x.xml();
|
}
|
|
//xsedit xc = GetControl(L"resultcontent");
|
///*if(data != L"")*/ xc.LoadContent(L""+data,L".xml");
|
|
//xwin xw = GetFrameWindow();
|
xsedit xc1 = GetControl(L"frame:vdata");
|
trace(data.left(16384));
|
//if(data.length() > 16000)
|
/*if(data!=L"")
|
xc1.LoadContent(L""+data,L".xml");
|
else
|
xc1.LoadContent(L" ",L".xml");*/
|
xc1.SetText(data);
|
|
}
|
xutil::RestoreCursor(hCursor);
|
return 1;
|
}
|
else if (comdid == L"argaddEx")
|
{
|
dw_list.InsertRow(0);
|
xutil::RestoreCursor(hCursor);
|
return 1;
|
}
|
else if (comdid == L"argdeleteEx")
|
{
|
int row = dw_list.GetRow();
|
if (row < 1) return 0;
|
dw_list.DeleteRow(row);
|
xutil::RestoreCursor(hCursor);
|
return 1;
|
}
|
else if (comdid == L"xmEntitySel")
|
{
|
xaserverarg arg ;
|
OpenWindow(L"dev:xpage[XEntityColumnSelDlg.xpage]",arg);
|
xstring str = arg.GetArgString(L"select");
|
if (str != L"") trace(L"\r\n---------------------\r\n" + str);
|
xutil::RestoreCursor(hCursor);
|
return 1;
|
}
|
else if (comdid == L"xmEditFind")
|
{
|
xutil::RestoreCursor(hCursor);
|
xsedit xs = GetControl(L"sqlcontent");
|
xs.OnFindDlg();
|
return 1;
|
}
|
else if (comdid == L"xmEditReplace")
|
{
|
xutil::RestoreCursor(hCursor);
|
xsedit xs = GetControl(L"sqlcontent");
|
xs.OnReplaceDlg();
|
return 1;
|
}
|
|
xutil::RestoreCursor(hCursor);
|
return 0;
|
}
|
|
//ÃüÁî´¦Àíʼþ
|
int OnXCommand(TEvent* evt,LPARAM param)
|
{
|
return OnCmdDispatch(evt->xcommand.pStrID);
|
}
|
|
int OnAttachEvent()
|
{
|
//°ó¶¨¹¤¾ßÌõµã»÷ʼþ
|
AttachEvent(L"WM_XCOMMAND",(FEvent)&XDevEditXQuery::OnXCommand);
|
//»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ
|
AttachEvent(L"WM_SETFOCUS", (FEvent)&XDevEditXQuery::OnSetFocus);
|
|
return 1;
|
}
|
|
int OnInitial()
|
{
|
SetAgent();
|
|
OnAttachEvent();
|
|
return 1;
|
}
|
|
int onload()
|
{
|
dw_list = GetControl(L"parasgrid");
|
|
OnInitial();
|
LoadData();
|
|
return 1;
|
}
|
};
|