xj qian
2024-12-11 6b556dfc6d549954add3a9da5d37df8a502491a3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
#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;
}
};