LiFan
10 天以前 63eebabbfee1bc84850b36967ecac5116a28b73f
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
#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 XDevEditXML : public XDevEditPage
{
    public:
    XDevEditXML(void* implPtr, HWND hWnd) :XDevEditPage(implPtr, hWnd) {}
public:
    static XDevEditXML* CreateInstance(void* implPtr, void* hWnd)
    {
        XDevEditXML* pWin = new XDevEditXML(implPtr, (HWND)hWnd);
        return pWin;
    }
private:    
    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();
        //trace(content);
        xsedit xs = GetControl(L"content");
        if (content != L"")
        {
            xs.LoadContent(content,L".xml");
        }
else
   xs.LoadContent(L"",L".xml");
return 1;
}
 
xstring OnGetType()
{
    xwin w = GetFrameWindow();
    xtreeview tv_folder = w.GetControl(L"DevExplorer");
    HTREEITEM hItem = (HTREEITEM)GetWinParam();
    KXMLDOMElement e = tv_folder.GetItemData(hItem);
    xstring str = e.getAttribute(L"type");
    return str;
}
 
//ÃüÁî·¢²¼º¯Êý
int OnCmdDispatch(xstring comdid)
{
    xstring content;
    xsedit xs = GetControl(L"content");
    xs.GetContent(content);
 
    HCURSOR hCursor = xutil::SetCursorWait();
    if (comdid == L"xmFileSave")
    {
        //save xml content
        SaveContent(content);
    }
    else if (comdid == L"xmRun")
    {
        xml x = new xml;
        x.loadXML(content);
        KXMLDOMElement e = x.documentElement();
        if (e.selectSingleNode(L"test[1]/@xpage"))
        {
            xstring xpage = e.selectSingleNode(L"test/@xpage").text();
            xaserverarg arg;
            arg.AddArg(L"configxml", content);
            //arg.AddArg(L"config", L"");
            if (e.selectSingleNode(L"test/@EntityID"))
                arg.AddArg(L"EntityID", e.selectSingleNode(L"test/@EntityID").text());
            OpenWindow(xpage + L"native=true", arg);
        }
    }
    else if (comdid == L"xmValid")
    {
        xml x;
        if (!x.loadXML(content))
        {
            KXMLDOMParseError pError = x.parseError();
            if (pError)
            {
                xstring str = pError.srcText();
                xstring sError = L"\r\nXML´íÎó: " + str.trim() + L"\r\n";
                int s = pError.errorCode();
                sError += L"   ´úÂë: " + xstring(s) + L"\r\n";
                s = pError.line();
                sError += L"   Î»ÖÃ: µÚ" + xstring(s) + L"ÐÐ,L";
                s = pError.linepos();
                sError += L"µÚ" + xstring(s) + L"ÁÐ" + L"\r\n";
                str = pError.reason();
                sError += L"   Ô­Òò: " + str;
                trace(sError);
            }
            else
            {
                trace(L"XML ´íÎó");
            }
            xutil::RestoreCursor(hCursor);
            return -1;
        }
        xstring sType = OnGetType();
        if (sType == L"xml.xsd")
        {
            BSTR sError;
            x.ValidSchema(content.c_str(), sError);
            trace(sError);
        }
    }
    else if (comdid == L"xmEditFind")
    {
        xutil::RestoreCursor(hCursor);
        xsedit xs = GetControl(L"content");
        xs.OnFindDlg();
        return 1;
    }
    else if (comdid == L"xmEditReplace")
    {
        xutil::RestoreCursor(hCursor);
        xsedit xs = GetControl(L"content");
        xs.OnReplaceDlg();
        return 1;
    }
    xutil::RestoreCursor(hCursor);
    return 0;
}
 
//ÃüÁî´¦Àíʼþ
int OnXCommand(TEvent* evt,LPARAM param)
{
    return OnCmdDispatch(evt->xcommand.pStrID);
}
 
int OnLButtonDown(TEvent* evt,LPARAM p)
{
    xsedit edit_1 = GetControl(L"content");
    int sPos = edit_1.GetSelectionStart();
    int ePos = edit_1.GetSelectionEnd();
    xstring content = edit_1.GetText();
    content = content.mid(sPos, ePos - sPos);
    //trace(content);
    if (content == L"") return -1;
    xwin w = GetFrameWindow();
    xtreeview tv_folder = w.GetControl(L"DevExplorer");
    HTREEITEM hItem = (HTREEITEM)GetWinParam();
    KXMLDOMElement e = tv_folder.GetItemData(hItem);
    //trace(e.xml);
    xstring str = e.getAttribute(L"type");
    xstring uri = e.getAttribute(L"uri");
    //trace(str);
    xml xl = new xml;
    xstring xtype = L"";
    if (str == L"iface")
        //xaserver::LoadUrl(GetServerUrl(),L"dev:xml[sale.data.url.xml]",L"",xl);
        xtype = L"data";
    else if (str == L"vface")
        //xaserver::LoadUrl(GetServerUrl(),L"dev:xml[sale.view.url.xml]",L"",xl);
        xtype = L"view";
    else
        return 0;
    xaserver::LoadUrl(GetServerUrl(),L"dev:xml[sale." + xtype + L".url.xml]",L"",xl);
    //trace(xl.xml());
    auto doc = xl;
    auto n = doc.selectSingleNode(L"//item[@src='dev:" + str + L"[" + uri + L"]']/@url");
    //trace(n.xml);
    xstring aurl = L"";
    if (n)
    {
        xstring tmp = n.text();
        aurl = L"/sale/" + xtype + L"/" + tmp + L"/" + content;
    }
    else
        return -1;
    trace(aurl);
    xml x = new xml;
    xaserverarg arg;
    arg.AddArg(L"url",aurl + L"?node");
    if (xaserver::ExecXQuery(GetServerUrl(),L"[service.url.xq]",arg.GetString(),x) != 1)
    {
        trace((xstring)L"error:" + x.xml());
        return 0;
    }
    trace(x.xml());
    xaserver::FetchXml(GetServerUrl(),L"dev:xpage[XDevEdit.xml]",L"",xl);
    //trace(xl.xml());
    auto n1 = xl.selectSingleNode(L"//editor[@filetype='" + str + L"']/@xpage");
    if (n1)
    {
        xstring xpage = n1.text();
        trace(xpage);
        OpenWindow(L"dev:xpage[" + xpage + L"]", 0);
    }
 
    return 1;
}
int OnAttachEvent()
{
    //°ó¶¨¹¤¾ßÌõµã»÷ʼþ
    AttachEvent(L"WM_XCOMMAND",(FEvent)&XDevEditXML::OnXCommand);
    //»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ
    AttachEvent(L"WM_SETFOCUS", (FEvent)&XDevEditXML::OnSetFocus);
    //AttachEvent(L"content",L"WM_LBUTTONDOWN", ,(FEvent)&XDevEditXML::OnLButtonDown);
 
    return 1;
}
 
int OnInitial()
{
    SetAgent();
 
    OnAttachEvent();
 
    return 1;
}
 
int onload()
{
    OnInitial();
    LoadData();
 
    return 1;
}
};