xj qian
2024-06-26 da2dab05bfc057f9a31599710cf52fc523092055
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
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
#pragma once
 
#include <wobject/xwin.hpp>
#include <wobject/xurl.hpp>
#include <wobject/xapp.hpp>
class xframe : public xwin
{
public:
    xframe(void* implPtr, HWND hWnd) :xwin(implPtr, hWnd) {
        this->SetArg(this->GetWinParam());
    }
 
    static int getUrl(string url1, string para, KXMLDOMDocument x)
    {
        return xurl::get(xapp::GetServerUrl(), url1, para, x);
    }
 
    static int getUrl(string serverUrl,string url1, string para, KXMLDOMDocument x)
    {
        return xurl::get(serverUrl,url1, para, x);
    }
    int getSql( string para, KXMLDOMDocument x)
    {
        return xurl::getSql(GetServerUrl(), para, x);
    }
 
    int getSql( xaserverarg para, KXMLDOMDocument x)
    {
        return xurl::getSql(GetServerUrl(), para.GetString(), x);
    }
 
    virtual string GetBillStatusName(xstring billstatus)
    {
        if (billstatus == L"1") return L"н¨";
        else if (billstatus == L"2") return L"´ýÅú";
        else if (billstatus ==L"3") return L"ÒÑÅú×¼";
        else if (billstatus ==L"4") return L"ÉêÇëÈ¡Ïû";
        else if (billstatus ==L"5") return L"ÐÞ¸Ä";
        else if (billstatus ==L"6") return L"ÒÑÉóºË";
        else if (billstatus ==L"9") return L"ºÏ²¢";
        else if (billstatus ==L"10") return L"¹éµµ";
        else if (billstatus ==L"11") return L"×÷·Ï";
 
        return L"#Error";
    }
 
    virtual int ProcessUsedArg(xaserverarg& arg)
    {
        return 1;
    }
 
    virtual xstring GetEntityName(LPARAM pr)
    {
        //alert("frame£ºget entity name!");
        return L"";
    }
 
    virtual xstring GetEntityIDName(LPARAM pr)
    {
        return L"";
    }
 
    virtual xstring GetEntityID(LPARAM pr)
    {
        return L"";
    }
 
    virtual xstring GetEntityData(LPARAM pr)
    {
        return L"";
    }
 
    virtual xstring GetEntityRowData(LPARAM pr)
    {
        return L"";
    }
 
    virtual xstring GetEntityTitle(LPARAM pr)
    {
        return L"";
    }
 
    virtual xstring GetEntityNo(LPARAM pr)
    {
        return L"";
    }
 
    virtual xstring GetEntityItemValue(LPARAM pr, xstring obj, xstring item)
    {
        return L"";
    }
 
    virtual int ViewUpdate(LPARAM pr, xstring updateItem, xaserverarg  arg)
    {
        return 1;
    }
 
    virtual xstring GetEntityWorkNode(LPARAM pr, xstring what)
    {
        return L"";
    }
 
    virtual int CheckEntityValidity(LPARAM pr)
    {
        return 1;
    }
    virtual int ShowAll()
    {
        return 1;
    }
    virtual int GridSearchnew()
    {
        return 1;
    }
    virtual int CustomerModify()
    {
        return 1;
    }
        
    virtual xstring GetReason(LPARAM pr)
    {
        xaserverarg arg;
        //openUrl("/sale/view/view.dlg/xpage/memo/edit", arg);
        arg.AddArg(L"EntityID", GetEntityID(2));
        openUrl(L"/sale/view/workflow.view/xpage/chkdlg_vd", &arg);        
        xstring comdid = arg.GetArgString(L"comdid");
        if (comdid ==L"xmOK")
        {
            string value = arg.GetArgString(L"content");
            return value;
        }
        return L"";
    }
 
    virtual xstring GetParamValue(xstring name)
    {
        return L"";
    }
 
    virtual xstring GetSheetContent()
    {
        return L"";
    }
 
    int OnModifyRows()
    {
        xstring SheetStr = GetSheetContent();
        if (SheetStr ==L"") return -1;
        xaserverarg arg;
        arg.AddArg(L"sheet", SheetStr);
        openUrl(L"/sale/view/view.dlg/xpage/grid/column/editex", &arg);
        return 1;
    }
 
    int ProcessFlowAction(xstring comdid, LPARAM pr1)
    {
        if (comdid ==L"__ModifyRows")
        {
            OnModifyRows();
            return 1;
        }
 
        LPARAM pr = pr1;
        xstring action = comdid.mid(comdid.find(L"action:", 0) + 7, 9999);
        if (action ==L"bill.delete" || action ==L"bill.deleteEx")
        {
            if (MessageBoxW(GetHWND(),L"ÊÇ·ñÈ·¶¨É¾³ý¼Ç¼!",L"Ìáʾ", 1) == 2)
                return 1;
        }
 
        xaserverarg& arg = *(new xaserverarg);
        arg.AddArg(L"Action", action);
        KXMLDOMDocument x;
 
        xstring aurl =L"/workflow/query/actioninfo/" + action;
 
        if (xurl::get(GetServerUrl(),aurl,L"", x) != 1)
            return -1;
 
        int nlen;
        int i = 0;
        xstring name;
        xstring worknode;
        xstring how;
        xstring state =L"";
        xstring billstatus =L"";
        KXMLDOMElement e;
 
        arg.AddArg(L"EntityName", GetEntityName(pr));
        //²ÎÊýÒªÇó
        KXMLDOMNodeList nlist = x.selectNodes(L"//params/param");
        nlen = nlist.length();
 
        for (i = 0; i < nlen; i++)
        {
            e = nlist.item(i);
            name = e.selectSingleNode(L"@name").text();
            how = e.selectSingleNode(L"@how").text();
 
            xstring content =L"";
            if (how ==L"Entity" || how ==L"EntityData")
            {
                content = GetEntityData(pr);
            }
            if (e.selectSingleNode(L"@valid"))
            {
                if (content.find(L"update.modify", 0) > 0 || content.find(L"update.delete", 0) > 0) {}
                else return 0;
                if (CheckEntityValidity(pr) < 0) return -1;
            }
            if (how ==L"EntityID")
                arg.AddArg(name, GetEntityID(pr),L"xs:string");
            else if (how ==L"Entity" || how ==L"EntityData")
                arg.AddArg(name, content,L"xs:string");
            else if (how ==L"EntityRowData")
                arg.AddArg(name, GetEntityRowData(pr),L"xs:string");
            else if (how ==L"Reason")
            {
                arg.AddArg(name, GetReason(1),L"xs:string");
            }
            else if (how ==L"EntityNo")
                arg.AddArg(name, GetEntityNo(pr),L"xs:string");
            else if (how ==L"EntityTitle")
                arg.AddArg(name, GetEntityTitle(pr),L"xs:string");
            else if (how ==L"GetParam")
                arg.AddArg(name, GetParamValue(name),L"xs:string");
            else if (how ==L"UserID")
                arg.AddArg(name, xaserver::GetUID(),L"xs:string");
            if (how ==L"Reason" && arg.GetArgString(name) ==L"") return -1;
            //if(how=="EntityData" && arg.GetArgString(name)=="") return -1;
            if (e.selectSingleNode(L"@check"))
            {
 
                xstring doCheck = e.selectSingleNode(L"@check").text();
                if (doCheck ==L"Y")
                {
                    xstring value = arg.GetArgString(name);
                    if (value ==L"")
                    {
                        alert(xstring(name) +L" ²ÎÊýÖµ²»ÄÜΪ¿Õ£¬Ê¼þÖÕÖ¹!");
                        return -1;
                    }
                }
            }
        }
 
        arg.AddArg(L"action.entity", GetEntityName(pr),L"xs:string");
        ProcessUsedArg(arg);
        //¶¯×÷
        KXMLDOMNode n = x.selectSingleNode(L"//view.action[1]");
 
        bool execResult = true; //´¦Àí½á¹û
        if (n)
        {
            name = n.selectSingleNode(L"@name").text();
            if (n.selectSingleNode(L"@worknode"))
                worknode = n.selectSingleNode(L"@worknode").text();
            else
                worknode = GetEntityWorkNode(pr, name);
            arg.AddArg(L"do", name,L"xs:string");
            if (worknode !=L"")
            {
                if (worknode.find(L"dev:xpage") == 0)
                    OpenWindow(worknode, (LPARAM) & arg);
                else
                    openUrl(worknode, &arg); 
            }
            else
            {
                alert(L"Warn: Please configure worknode for actionL" + xstring(name) +L".");
                return -1;
            }
        }
        else
        {
            //url::post(GetEntityName(pr)+"/workflow/action",arg.GetString(),x);
            KXMLDOMDocument x1;
            xstring EntityNo = GetEntityName(pr);
            int retxx = xurl::post(GetServerUrl(), (xstring)(L"/workflow/action/") + EntityNo + L"/" + action, arg.GetString(), x1);
 
            //alert("/workflow/action/"+GetEntityName(pr)+"/"+action+"\r\n"+arg.GetString()+"\r\n"+x1.GetXml());
 
            if (retxx != 1) execResult = false;
            if (x1.selectSingleNode(L"//process"))
            {
                KXMLDOMElement e1 = x1.selectSingleNode(L"//process");
                string valid = e1.getAttribute(L"valid");
                string finished = e1.getAttribute(L"finished");
                xstring errInfo =L"";
                if (valid ==L"0")
                {
                    errInfo = e1.getAttribute(L"errInfo");
                    alert(errInfo);
                    execResult = false;
                }
                else if (finished ==L"0")
                {
                    errInfo = e1.getAttribute(L"errInfo");
                    errInfo =L"´¦Àíʧ°Ü!\r\n" + errInfo;
                    alert(errInfo);
                    execResult = false;
                }
            }
            else if (x1.selectSingleNode(L"//process-check-list"))
            {
                KXMLDOMElement e2 = x1.selectSingleNode(L"//process-check-list");
                string val = e2.getAttribute(L"process");
                if (val ==L"ok")
                {
                    alert("´¦Àí³É¹¦");
                    PostMessageW(GetHWND(), 0x401,(WPARAM)L"action:bill.refresh", 0);
                }
                else if (val ==L"part")
                {
                    alert("Óв¿·ÖÊý¾Ý´¦Àíδ³É¹¦£¬Ìá½»³É¹¦µÄÒÑ´¦Àí¡£");
                    PostMessage(GetHWND(), 0x401, (WPARAM)L"action:bill.refresh", 0);
                }
                else
                    alert((xstring)L"Êý¾Ý´¦Àí²»³É¹¦\r\n" + x1.xml());
                return 1;
            }
            else if (x1.selectSingleNode(L"//msg"))
            {
                xstring aStr =x1.selectSingleNode(L"//msg[1]").text();
                //if(aStr.find("Àí³É¹¦",0) < 0)
                //    alert(aStr);
                if (aStr.find(L"ʧ°Ü", 0) >= 0)
                    execResult = false;
                alert(aStr);
            }
            if (x1.selectSingleNode(L"//msg/@state"))
            {
                state = x1.selectSingleNode(L"//msg[1]/@state").text();
                arg.AddArg(L"state", state,L"xs:string");
                billstatus = x1.selectSingleNode(L"//msg[1]/@billstatus").text();
                arg.AddArg(L"billstatus", billstatus,L"xs:string");
            }
        }
        //¸üÐÂÒªÇó
        if (execResult & 0xf)
        {
            nlist = x.selectNodes(L"//view/update");
            nlen = nlist.length();
            for (i = 0; i < nlen; i++)
            {
                e = nlist.item(i);
                how = e.selectSingleNode(L"@do").text();
                if (how ==L"setstate")
                {
                    if (state !=L"")
                    {
                        arg.AddArg(L"state", state,L"xs:string");
                        arg.AddArg(L"billstatus", billstatus,L"xs:string");
                        ViewUpdate(pr, how, arg);
 
                    }
                }
                else
                    ViewUpdate(pr, how, arg);
            }
        }
 
 
        return 1;
    }
 
    int OnItemError(TNotifyEvent* evt, int p)
    {
        DWNMHDR&  hdr = *(DWNMHDR *)evt->notify.pnmh;
        xstring value = hdr.data;
        int e = hdr.idFrom;
        if (e == -1000)
            MessageBoxW(0,L"¡¾" + value +L"¡¿²»ÊÇÓÐЧµÄÊý×Ö!",L"OnItemError", 0);
        if (e == -1001)
            MessageBoxW(0,L"¡¾" + value +L"¡¿²»ÊÇÓÐЧµÄÊý×Ö!", L"OnItemError", 0);
        if (e == -1002)
            MessageBoxW(0,L"¡¾" + value +L"¡¿²»ÊÇÓÐЧµÄÈÕÆÚ!", L"OnItemError", 0);
        hdr.idFrom = 0;
        return 1;
    }
 
    virtual int SetObjectInfo(KXMLDOMElement e)
    {
        return 1;
    }
 
    virtual string GetTaskID()
    {
        return L"";
    }
 
    virtual int SetAgent(xstring scene, xstring EntityID)
    {
        xstring xfNodeAgentArea =L"agentarea";
        xnode anode = GetAgentNode(xfNodeAgentArea);
        KXMLDOMElement xframeElement = GetElement();
        KXMLDOMNode agent = xframeElement.selectSingleNode(L"agent/" + xfNodeAgentArea +L"[1]/*");
 
        KXMLDOMDocument x;
        xaserverarg arg;
        arg.AddArg(L"scene", scene,L"xs:string");
        arg.AddArg(L"EntityID", EntityID,L"xs:string");
        arg.AddArg(L"TaskID", GetTaskID(),L"xs:string");
        arg.AddArg(L"EntityName", GetEntityName(1),L"xs:string");
        xurl::get(GetServerUrl(),(xstring)L"/workflow/query/datarole/" + GetEntityName(1), arg.GetString(), x);
        //if(x.GetXmlDoc().selectSingleNode("datarole/rightes/right"))
        SetObjectInfo(x.documentElement());
        xstring sNodes;
        sNodes =(xstring)L"datarole/actions/action[contains(@scene,'" + scene +L"')]";
        KXMLDOMNodeList nlist = x.selectNodes(sNodes);
        int  index;
        int  nlen = nlist.length();
        KXMLDOMElement ele;
 
        xstring tools =L"<vbox class=''>";
        if (scene ==L"list") tools +=L"<xspace height='12'/>";
 
        for (index = 0; index < nlen; index++)
        {
            ele = nlist.item(index);
            xstring name = ele.selectSingleNode(L"@id").text();//.getAttribute("id");
            xstring label = ele.selectSingleNode(L"@caption").text();//ele.getAttribute("caption");
            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();
 
            xstring tool;
 
            if (src !=L"")
                tool =(xstring)L"<xtoolbutton src='" + src +L"'  caption='" + label +L"' name='action:" + name +L"' height='23' style='background-color:none #ceecce  none #ffffff'/>";
            else
                tool =(xstring)L"<xtoolbutton image='" + image +L"'  caption='" + label +L"' name='action:" + name +L"' height='23'  style='background-color:none #ceecce none #ffffff'/>";
            tools += tool;
        }
        if (agent)
        {
            nlist = agent.selectNodes(L".//xtoolbutton");
            nlen = nlist.length();
            for (index = 0; index < nlen; index++)
            {
                ele = nlist.item(index);
                xstring tmp = ele.xml();
                tools += tmp;
            }
        }
        tools +=L"</vbox>";
        SetAgentNode(anode, tools);
 
        return 1;
    }
 
    virtual int SetAgent(xstring scene)
    {
        return SetAgent(scene,L"*");
    }
 
    virtual int SetAgent()
    {
        return SetAgent(L"list");
    }
 
    virtual int DoUpdate(bool showSuccess)
    {
        return 0;
    }
 
    virtual bool NeedNotifyUpdate()
    {
        return false;
        return true;
    }
 
    virtual int BeforeCloseWindow()
    {
        if (!NeedNotifyUpdate()) return 1;
        xstring content = GetEntityData(1);
        if (content ==L"") return 1;
        if (content.find(L"update.modify", 0) > 0 || content.find(L"update.delete", 0) > 0)
        {
            int MB_YESNOCANCEL = 3;
            int IDYES = 6;
            int IDNO = 7;
            int IDCANCEL = 2;
            int re = MessageBoxW(GetHWND(),L"Êý¾ÝÒѾ­Ð޸ģ¬ÊÇ·ñ±£´æ?",L"Ìáʾ:", MB_YESNOCANCEL);
            if (re == IDCANCEL) return -1;
            if (re == IDNO) return 1;
            if (DoUpdate(false) == 1) return 1;
            return -1;
        }
        return 1;
    }
 
    int OnCloseOwnerWindow(TEvent* evt, LPARAM p)
    {
        if (BeforeCloseWindow() < 0)     return 1;
        return 0;
    }
 
    int OnCloseFrameSheet(TEvent* evt, LPARAM p)
    {
        LYSNMHDR* nmtv = (LYSNMHDR*)evt->notify.pnmh;
        HWND h = (HWND)nmtv->idFrom;
        int canCLose = 1;
        if (h == GetHWND())
            canCLose = BeforeCloseWindow();
 
        if (canCLose < 0)
            nmtv->nSheet = canCLose;
        return 1;
    }
 
    int AttachCloseWindow()
    {
        xstring typ = GetElement().getAttribute(L"type");
        if (typ ==L"sheet")
        {
            AttachEvent(L"frame:mdilayer",L"LYSN_CLOSESHEET", (FEvent)&xframe::OnCloseFrameSheet);
        }
        else
        {
            AttachEvent(L"WM_CLOSE", (FEvent)&xframe::OnCloseOwnerWindow);
        }
        return 1;
    }
 
    int OnCloseWindow()
    {
        //AttachEvent("frame:mdilayer",L"LYSN_CLOSESHEET",BeforeCloseWindow);    
        return 1;
    }
 
    /*
    int AppendItem(xml x,msxml::IXMLDOMElement r,string name,string value)
    {
        msxml::IXMLDOMElement e = x.GetXmlDoc().createElement(name);
        e.text =L""+value;
        e.setAttribute("update.modify","1");
        r.appendChild(e);
        return 1;
    }
 
    int OnSaveTemplate(xdwgrid dw_list, string aurl)
    {
        //alert("먦·Å...");
        if(aurl ==L"") return -1;
        int i;
        int s = dw_list.GetColumnCount();
        xaserverarg arg = new xaserverarg;
        arg.setNativePointer(arg.CreateInstance());
        for(i=1; i<=s; i++)
        {
            string name = dw_list.GetColumnName(i);
            if(name ==L"guid") continue;
            string titlename = dw_list.GetTitleName(i - 1);
            int width = dw_list.GetColumnWidth(name);
            arg.AddArg(name, width.toString(), titlename);
        }
 
        xml x=new xml;
        x.setNativePointer(xml::CreateInstance());
        x.LoadXml("<root><SysGridCols update.new='1' update.modify='1'/></root>");
        msxml::IXMLDOMElement doc = x.GetXmlDoc().documentElement;
        msxml::IXMLDOMElement e = doc.selectSingleNode("*");
 
        //string guid1 = publiccode::GetGuid();
        //string gid = publiccode::GetCurrentDate();
 
        //AppendItem(x, e,L"ID", publiccode::GetGuid());
        AppendItem(x, e,L"TplType", aurl);
        AppendItem(x, e,L"Cols", arg.GetString());
        AppendItem(x, e,L"Recorder", xaserver::GetUserId());
        doc.appendChild(e);
        xaserverarg arg0 = new xaserverarg;
        arg0.setNativePointer(arg0.CreateInstance());
        arg0.AddArg("content", doc.xml);
        if(url::get("/workflow/action/SysGridCols/bill.update",arg0.GetString(),x)!=1)
        {
            trace("error:"+x.GetXml());
            alert("³ö´í!");
        }
        return 1;
    }        */
};