LiFan
2024-07-15 1b1a2e68cfd02074fc3300a0cc0fa40888a92f10
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
use "win.vl"
use "treeview.vm"
use "dev:vm[xdwgrid.vm]"
use "dev:vm[xdwtable.vm]"
use "pref.vl"
use "dev:vm[xml.vm]"
use "dev:vm[xaserverarg.vm]"
use "dev:vm[xaserver.vm]"
use "dev:vm[xutil.vm]"
use "list.vl"
unit vbusiness.xpage
[
    HrOrgMaint is extend list;
    about HrOrgMaint
        [
            control:
 
        method:
            [
                xdwtable__    dw_detail;
                string        m_operate;
                string        m_sguid;
                string        m_tvOrgID;
                string        m_tvOrgName;
                string        m_tvRootOrgID;
                string        m_tvRootOrgName;
 
                xnode__    m_agentNode;    //Agent Condition
                string    m_agentCond;    //Agent Node    
                int SetAgent()
                {
                    string xfNodeAgentArea = "agentarea";
                    xnode__ anode = new xnode__;
                    anode.setNativePointer(GetAgentNode(xfNodeAgentArea));
                    var xframeElement = GetElement();
                    var agent = xframeElement.selectSingleNode("agent/" + xfNodeAgentArea + "[1]/*");
                    if (agent)
                    {
                        string s = agent.xml;
                        SetAgentNodeContent(anode, s);
                    }
                    return 1;
                }
 
                //½¹µã¼¤»î´¦Àíº¯Êý
                int OnSetFocus(ref TEvent evt, int p)
                {
                    SetAgent();
 
                    //ÖØÖù¤¾ßÌõ
                    return 1;
                }
 
                int  OnRetrieve()
                {
                    xml__ x = new xml__;
                    x.setNativePointer(x.CreateInstance());
                    xaserverarg__ arg = new xaserverarg__;
                    arg.setNativePointer(arg.CreateInstance());
                    arg.AddArg("guid", m_sguid);
                    if (url::get("OrganizationStruct/detail.HrOrg", arg.GetString(), x) != 1)
                    {
                        trace(x.GetXmlDoc().text);
                        return -1;
                    }
                    else
                    {
                        trace(x.GetXml());
                        dw_detail.Retrieve(x);
                        dw_detail.Redraw();
                    }
                    return 1;
                }
 
                int OnSave()
                {
                    int hIcon = xutil__::SetCursorWait();
                    //dw_detail.AcceptText();                    
                    string val;
                    xml__ x = new xml__;
                    x.setNativePointer(x.CreateInstance());
                    var xdoc = x.GetXmlDoc();
                    dw_detail.DwUpdateAllTo(xdoc);
                    val = xdoc.xml;
                    //trace(val);
                    //return 1;
                    xaserverarg__ args = new xaserverarg__;
                    args.setNativePointer(args.CreateInstance());
                    args.AddArg("content", val);
                    //trace(val);
                    xml__ x1 = new xml__;
                    x1.setNativePointer(x1.CreateInstance());
                    if (url::post("OrganizationStruct/update.HrOrg", args.GetString(), x1) != 1)
                    {
                        string error = x1.GetXmlDoc().text;
                        trace(error);
                    }
                    else
                    {
                        win__::MessageBox(GetHWND(), "±£´æ³É¹¦£¡", "Ìáʾ", 0);
                    }
                    dw_detail.ResetUpdateStatus();
                    xutil__::RestoreCursor(hIcon);
                    return 1;
                }
 
                int OnNew()
                {
                    dw_detail.openUrl("×éÖ¯¼Ü¹¹.vface/template/HrOrg/detail");
                    if (m_operate == "new0")
                    {
                        dw_detail.SetItemString(1, "ParentOrgID", m_tvOrgID);
                        dw_detail.SetItemDisplayString(1, "ParentOrgID", m_tvOrgName);
                    }
                    dw_detail.SetItemString(1, "Status", "Y");
                    //dw_detail.SetItemDisplayString(1,"Status","ÓÐЧ");
                    return 1;
                }
 
                //ÃüÁî·¢²¼º¯Êý
                int OnCmdDispatch(string comdid)
                {
                    if (comdid == "New") OnNew();
                    if (comdid == "Save") OnSave();
                    if (comdid == "xmOk") OnSave();
                    if (comdid == "xmCancel") CloseWindow();
                    return 0;
                }
 
                //ÃüÁî´¦Àíʼþ
                int OnXCommand(ref TXCommandEvent evt, int p)
                {
                    return OnCmdDispatch(evt.pStrID);
                }
 
                int OnChildContent(ref TNotifyEvent evt, int p)
                {
                    ref DWNMHDR dwhdr = evt.pnmh;
                    string col = dwhdr.colname;
                    if (col != "") {
                        xml__ x = new xml__;
                        x.setNativePointer(x.CreateInstance());
                        xaserverarg__ arg = new xaserverarg__;
                        arg.setNativePointer(arg.CreateInstance());
                        string query;
                        query = "[IResourceMSSql.xq]";
                        if (col == "OrgTypeID") {
                            arg.AddArg("ResourceType", "HrOrgType");//×éÖ¯ÀàÐÍ    
                        }
                        else if (col == "OrgAddress000") {
                            arg.AddArg("ResourceType", "HR_Address");//×éÖ¯µØÖ·    
                        }
                        else if (col == "CompanyID") {
                            arg.AddArg("ResourceType", "CompanyInfo");//ËùÊô·¨ÈË    
                        }
                        else if (col == "OrgProLine") {
                            arg.AddArg("ResourceType", "OrgProLine");//²úÆ·Ïß
                        }
                        if (xaserver__::ExecXQuery(GetServerUrl(), query, arg.GetString(), x) == 1)
                            dwhdr.data = x.GetXml();
                        //trace(x.GetXml());
                    }
                    return 1;
                }
                int OnClicked(ref TNotifyEvent evt, int p)
                {
                    ref DWNMHDR  hdr = evt.pnmh;
 
                    xaserverarg__ arg = new xaserverarg__;
                    arg.setNativePointer(arg.CreateInstance());
 
                    string colname = hdr.colname;
                    if (colname == "ParentOrgID")
                    {
                        openUrl("×éÖ¯¼Ü¹¹.vface/xpage/HrOrg/Chart", arg);
                        //trace(arg.GetString());
                        string comdid = arg.GetArgString("comdid");
                        if (comdid == "xmOk")
                        {
                            string OrgName = arg.GetArgString("OrgName");
                            string OrgID = arg.GetArgString("OrgId");
                            dw_detail.SetItemDisplayString(1, "ParentOrgID", OrgName);
                            dw_detail.SetItemString(1, "ParentOrgID", OrgID);
                            dw_detail.Redraw();
                        }
                    }
                    if (colname == "LeaderID")
                    {
                        openUrl("×éÖ¯¼Ü¹¹.vface/xpage/hremployee/select", arg);
                        comdid = arg.GetArgString("comdid");
                        if (comdid == "xmOk")
                        {
                            string sPersonID = arg.GetArgString("sPersonID");
                            //trace(sPersonID);
                            string sPersonName = arg.GetArgString("sPersonName");
                            dw_detail.SetItemDisplayString(1, colname, sPersonName);
                            dw_detail.SetItemString(1, colname, sPersonID);
                            dw_detail.Redraw();
                        }
                    }
                    return 1;
                }
 
                int OnAttachEvent()
                {
                    //°ó¶¨¹¤¾ßÌõµã»÷ʼþ
                    AttachEvent("WM_XCOMMAND", OnXCommand);
                    //»ñÈ¡½¹µãʼþ£¬ÓÃÓÚÖØÖù¤¾ßÌõ
                    AttachEvent("WM_SETFOCUS", OnSetFocus);
                    //ÏÂÀ­¿ò  ÌṩÄÚÈÝ
                    AttachEvent("dw_detail", "DWV_CHILDCONTENT", OnChildContent);
                    AttachEvent("dw_detail", "DWV_ITEMFOCUSCHANGED", OnClicked);
                }
 
 
                int OnInitial()
                {
                    SetAgent();
                    OnAttachEvent();
                    return 1;
                }
 
                int onload()
                {
                    dw_detail = new xdwtable__;
                    dw_detail.setNativePointer(this.GetControl("dw_detail"));
                    dw_detail.openUrl("×éÖ¯¼Ü¹¹.vface/template/HrOrg/detail");
                    OnInitial();
 
                    xaserverarg__ arg = new xaserverarg__;
                    arg.setNativePointer(arg.CreateInstance());
                    arg = this.GetParam();
                    if (arg)
                    {
                        m_operate = arg.GetArgString("operate");
                        m_sguid = arg.GetArgString("guid");
                        m_tvOrgID = arg.GetArgString("tvOrgID");//×éÖ¯Ê÷µÄID
                        m_tvOrgName = arg.GetArgString("tvOrgName");//×éÖ¯Ê÷µÄName
                        m_tvRootOrgID = arg.GetArgString("tvRootOrgID");//×éÖ¯Ê÷µÄID
                        m_tvRootOrgName = arg.GetArgString("tvRootOrgName");//×éÖ¯Ê÷µÄName
                        //alert(m_tvRootOrgName);
                    }
                    /*if ( m_sguid == "" || m_sguid == nil)
                    {
                        m_sguid = win__::GetGuid();//´íÎó
                        trace(m_sguid);
                    }*/
                    if (m_sguid != "") {
                        OnRetrieve();
                    };
                    if (m_operate == "new0")
                    {
                        //trace(m_tvOrgID);
                        dw_detail.SetItemString(1, "ParentOrgID", m_tvOrgID);
                        dw_detail.SetItemDisplayString(1, "ParentOrgID", m_tvOrgName);
                        dw_detail.SetItemString(1, "CompanyID", m_tvRootOrgID);
                        dw_detail.SetItemDisplayString(1, "CompanyID", m_tvRootOrgName);
                        dw_detail.SetItemString(1, "Status", "Y");
                        //dw_detail.SetItemDisplayString(1,"Status","ÓÐЧ");
                    }
                    return 1;
                }
            ]
 
        ]
]