LiFan
2024-07-22 aecae8e9fa34b6307fb1b0e5478a69962d5ddd72
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
use "xcontrol.vframe.vbusiness.vd"
use "xbase.vframe.vbusiness.vd"
 
unit trade 
[
    class ViewEx1TotalWin :  public xwin
    {
        xdwgrid    dw_list;
        xoffice     dw_office;
        xcell        dw_cell;
        xnode    m_agentNode;    //Agent Condition
        msxml::IXMLDOMElement rptEle;
        string m_category;
        string argStr;
    
        int SetAgent()
        {
            string xfNodeAgentArea  = "agentarea";
            xnode anode = GetAgentNode(xfNodeAgentArea);
            if(m_agentNode)
            {
                SetAgentNodeContent (anode,m_agentNode);
            }
            else
            {
                msxml::IXMLDOMElement xframeElement =  GetElement();
                msxml::IXMLDOMElement agent = xframeElement.selectSingleNode("agent/"+xfNodeAgentArea+"[1]/*");
                if(agent)
                {
                    string s = agent.xml;
                    m_agentNode =  SetAgentNodeContent (anode,s);
                }
            }
            return 1;
        }
 
        //½¹µã¼¤»î´¦Àíº¯Êý
        int OnSetFocus(ref TEvent evt,int param)
        {
            //ÖØÖù¤¾ßÌõ
            SetAgent();
            return 1;
        }
 
        //ÃüÁî·¢²¼º¯Êý
        int OnCmdDispatch(string comdid)
        {
            int hCursor =  0;
             if(comdid=="xmAnalysis")
            {
                hCursor = xutil::SetCursorWait();
                string str = dw_list.DataAnalysis("");
                xaserverarg arg=new xaserverarg;
                arg.setNativePointer(arg.CreateInstance());                        
                arg.AddArg("html", str);
                int obj = cast(dw_list as int);
                arg.AddArg("obj",obj.toString());
                OpenWindow("dev:xpage[data.vanalysis.vx]", cast(arg as int));
                xutil::RestoreCursor(hCursor);
                return 1;
             }
             if(comdid=="xmTrans")
                 return OnTransData();
             if(comdid=="xmQuery")
            {
                if(rptEle)
                {
                    string argUrl = rptEle.getAttribute("arg");
                    if(argUrl !="")
                    {
                        xaserverarg ar = new xaserverarg;
                        ar.setNativePointer(ar.CreateInstance());
                        ar.AddArg("argurl",argUrl);
                        if(argStr !="") 
                            ar.AddArg("arg",argStr);
                        OpenWindow("dev:xpage[view.total.arg.vx]",cast(ar as int));
                        string arstr = ar.GetArgString("arg");
                        if(arstr != "" && ar.GetArgString("action")=="ok")
                        {
                            argStr = arstr;
                            hCursor = xutil::SetCursorWait();
                            OnRetrieve(rptEle.getAttribute("data"),argStr);
                            xutil::RestoreCursor(hCursor);
                        }
                    }
                    else
                    {
                        argStr="";
                        OnRetrieve(rptEle.getAttribute("data"),argStr);
                    }
                }
                return 1;
             }
            if(comdid=="xmSaveAs")
            {
                dw_list.SaveAs("");
                return 1;
            }
            return 0;
        }
        
        int SwitchReport(msxml::IXMLDOMElement e)
        {
            string dwname = e.getAttribute("template");
            string dataurl = e.getAttribute("data");
            string sheettype = e.getAttribute("reporttype");
            if(rptEle != e)
            {
                argStr = "";
                rptEle = e;
            }
            if(sheettype=="") sheettype="report";
            SwitchLayer("dw_"+sheettype,"report");
            if(sheettype=="report")dw_list.openUrl(dwname);
            
            SetAgent();
            return 1;
        }
        
        int OnCombboChanged(ref TCommandEvent evt,int lParam)
        {
            int h = xcombobox::GetCurSel(evt.hCtrl);
            if(h > -1) 
            {
                int hCursor = xutil::SetCursorWait();
                msxml::IXMLDOMElement e = xcombobox::GetItemData(evt.hCtrl, h);
                SwitchReport(e);
                win32::PostMessage(GetHWND(),0x401,"xmQuery",0);
                //OnCmdDispatch("xmQuery");
                xutil::RestoreCursor(hCursor);
            }
            return 1;
        }
 
        int OnTransData()
        {
            int ret =   win32::MessageBox(GetHWND(),"ÊÇ·ñ¸üÐÂÊý¾Ý?\n¸üйý³ÌÔ¤¼ÆÐèÒªËÄÊ®·ÖÖÓ£¬Èç¹ûÖм䵯³öµÈ´ýʱ¼ä¹ý³¤µÄÌáʾ£¬Çëµã»÷ÖмäÖØÊÔ°´Å¥£¬»òµÈ´ýµ½Ò»¶¨Ê±¼äÔÙµã»÷","Ìáʾ",0x4 /*yesno*/);
            if(ret != 6 /*IDYES */ ) return 1;
 
            xml x = new xml;
            x.setNativePointer(xml::CreateInstance());
            int hCursor = xutil::SetCursorWait();
            if (url::get("/sale/data/Total3/total/transdata","",x)!=1)
            {
                xutil::RestoreCursor(hCursor);
                return 1;
            }else    
            {
                xutil::RestoreCursor(hCursor);
                alert("Êý¾Ý´«ÊäÍê³É!");
                return 1;
            }
            
            return 1;
        }
            
        //ÃüÁî´¦Àíʼþ
        int OnXCommand(ref TXCommandEvent evt,int param)
        {
            return OnCmdDispatch(evt.pStrID);
        }
        
        int OnDWClick(ref TNotifyEvent evt,int p)
        {
            ref DWNMHDR  hdr = trust(evt.pnmh as ref DWNMHDR);
            string value = hdr.data;
            string colname = hdr.colname;
            int row = hdr.row;
            
            if(row < 1) return 1;
            
            xaserverarg arg;
            /*
            if(colname=="SONo")
            {
                string SONo = dw_list.GetItemString(row,colname);
                arg=new xaserverarg;
                arg.setNativePointer(arg.CreateInstance());                        
                arg.AddArg("EntityNo",SONo);
                arg.AddArg("ReadOnly","true");
                OpenWindow("dev:xpage[base.maint.so.vx]",arg.getNativePointer());
            }
            if(colname=="InvoiceNo")
            {
                string InvoiceNo= dw_list.GetItemString(row,colname);
                arg=new xaserverarg;
                arg.setNativePointer(arg.CreateInstance());                        
                arg.AddArg("EntityNo",InvoiceNo);
                arg.AddArg("ReadOnly","true");
                OpenWindow("dev:xpage[maint.GDN3.vx]",arg.getNativePointer());
            }
            if(colname=="InvoiceNoEx")
            {
                string InvoiceNoEx= dw_list.GetItemString(row,colname);
                arg=new xaserverarg;
                arg.setNativePointer(arg.CreateInstance());                        
                arg.AddArg("EntityNo",InvoiceNoEx);
                arg.AddArg("invoiceno",InvoiceNoEx);
                arg.AddArg("ReadOnly","true");
                OpenWindow("dev:xpage[maint.vatnotify.vx]",arg.getNativePointer());
            }
            */
            return 1;
        }
 
        int OnAttachEvent()
        {
            //°ó¶¨¹¤¾ßÌõµã»÷ʼþ
            AttachEvent("WM_XCOMMAND",OnXCommand);
            //»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ
            AttachEvent("WM_SETFOCUS",OnSetFocus);
            AttachEvent("cb_report","CBN_SELCHANGE",OnCombboChanged);
            AttachEvent("dw_report","DWV_CLICKED",OnDWClick);
        }
        
        int  OnRetrieve(string dataurl, string argstr)
        {
            if(!rptEle) return 0;
            
            dw_list.Reset();
            
            xml x = new xml;
            x.setNativePointer(xml::CreateInstance());
            xaserverarg arg = new xaserverarg;
            arg.setNativePointer(arg.CreateInstance());    
            arg.AddArg("arg",argstr);
            
            string sheettype = rptEle.getAttribute("reporttype");
            if(sheettype=="") sheettype="report";
            if (url::get(dataurl,arg.GetString(),x)!=1)
            {
                trace("\r\n--------"+x.GetXmlDoc().text);
                dw_list.Redraw();
                return -1;
            }else    
            {
                //xutil::SaveToFile("C:\\Temp\\Total3.xml",x.GetXml(),"","","");
                if(sheettype=="report")
                {
                    dw_list.Retrieve(x);
                    dw_list.Redraw();
                    dw_list.SetReadOnly(true);
                 }
                else if(sheettype=="cell")
                {
                }
                else if(sheettype=="office")
                {
                    dw_office.LoadTemplate(x);
                    for(int i=0; i<dw_office.GetSheetCount();i++)
                    {
                        xcell sheet = dw_office.GetSheet(i);
                        sheet.SetReadOnly(true);
                    }
                }
            }
            return 1;
        }
 
        xml getReportSet(string category)
        {
            xml x = new xml;
            x.setNativePointer(xml::CreateInstance());
            xaserverarg arg = new xaserverarg;
            arg.setNativePointer(arg.CreateInstance());    
            arg.AddArg("category",category);
            if (url::get("/sale/data/Total3/reportset",arg.GetString(),x)!=1)
            {
                return 0;
            }
            return x;
        }
        
        int onload()
        {
            dw_list = GetControl("dw_report");
            dw_office  = GetControl("dw_office");
            dw_cell = GetControl("dw_cell");
            dw_list.openUrl("/sale/view/Total3/template/sodetail");
            
            argStr ="";
            rptEle = 0;
            xcombobox xc = GetControl("cb_report");
            
            //m_category = "total/business";
            m_category = "total/sample";
            if(GetParam()) {
                xaserverarg arg = new xaserverarg;
                arg.setNativePointer(GetParam());    
                m_category = arg.GetArgString("category");
            }
            xml x = getReportSet(m_category);
            if(x)
            {
                msxml::IXMLDOMNodeList nlist =x.GetXmlDoc().selectNodes("//reports/report");
                int len = nlist.length;
                for(int i=0; i<len; i++)
                {
                    msxml::IXMLDOMElement rpt = nlist.item(i);
                    string name = rpt.getAttribute("name");
                    xcombobox::AddItem(xc.GetId(),name,trust(rpt as int));
                    if(i==0) xc.SetText(name);
                    if(i==0) rptEle = rpt;
                }
            }
            OnAttachEvent();    
            return 1;
        }
        
        int onloaded()
        {
            SetAgent();
            
            if(rptEle)
            {
                SwitchReport(rptEle);
                //OnCmdDispatch("xmQuery");
            }
            
            return 1;
        }        
    };
]