lu
2024-12-08 0895fb9962db16ca30e2913275396211d6094e13
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
using System;
using System.Collections.Generic;
using System.Data;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using Gs.DevApp.Entity;
using Gs.DevApp.Properties;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
 
namespace Gs.DevApp.DevFrm.User
{
    public partial class Organization : XtraForm
    {
        List<FilterEntity> _filterList = new List<FilterEntity>();
        public Organization()
        {
          
            InitializeComponent();
            //toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick;
            //toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick;
            //toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick;
            //toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            //toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
            //toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
            //toolBarMenu1.btnChkClick += ToolBarMenu1_btnChkClick;
            //toolBarMenu1.btnFChkClick += ToolBarMenu1_btnFChkClick;
            this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            this.toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
            tlMenu.DoubleClick += TlMenu_DoubleClick;
            getTree();
        }
        /// <summary>
        /// 查询事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e)
        {
            Gs.DevApp.ToolBox.MsgHelper.ShowInformation("该窗体不支持查询,若想更新页面,请点击 刷新");
        }
        /// <summary>
        /// 查询回调
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Frm_UpdateParent(object sender, UpdateParentEventArgs e)
        {
            _filterList = e.FilterList;
            getTree();
        }
 
        /// <summary>
        /// 刷新事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            if (xtraTabControl1.SelectedTabPageIndex == 1)
                getModel(lbGuid.Text.Trim(), false, 999);
            else
                getTree();
        }
        private void TlMenu_DoubleClick(object sender, EventArgs e)
        {
            var clickedNode = tlMenu.SelectedNode;
            if (clickedNode == null) return;
            if (clickedNode.FirstNode == null)
            {
                var rowGuid = clickedNode.Name;
                getModel(rowGuid, false, 999);
            }
        }
 
        /// <summary>
        ///     反审核
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        /// <exception cref="NotImplementedException"></exception>
        private void ToolBarMenu1_btnFChkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_name, tlMenu);
            toolBarMenu1.guidKey = rowGuid;
        }
 
        /// <summary>
        ///     审核事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnChkClick(object sender, EventArgs e)
        {
            toolBarMenu1.guidKey = "";
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_name, tlMenu);
            toolBarMenu1.guidKey = rowGuid;
        }
 
        /// <summary>
        ///     取消事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
        }
 
        /// <summary>
        ///     删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_name, tlMenu);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要删除的行!");
                return;
            }
 
            if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?")) return;
            var lst = new List<string>();
            lst.Add(rowGuid);
            var _obj = lst;
            try
            {
                var strJson = UtilityHelper.HttpPost("",
                    "Organization/DeleteModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    UtilityHelper.JumpToTab(xtraTabControl1, 0);
                    getTree();
                }
 
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
      
 
        /// <summary>
        ///     修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_name, tlMenu);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
 
            getModel(rowGuid, true, 1);
        }
 
        /// <summary>
        ///     新增事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 1);
            lbGuid.Text = "";
            UtilityHelper.CleanValueByControl(panel1.Controls, true);
        }
 
        /// <summary>
        ///     保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
        {
            toolBarMenu1.isSetBtn = false;
            if (string.IsNullOrEmpty(txt_fNumber.Text.Trim()))
            {
                MsgHelper.Warning("编号不能为空!");
                txt_fNumber.Focus();
                return;
            }
 
            if (string.IsNullOrEmpty(txt_name.Text.Trim()))
            {
                MsgHelper.Warning("名称不能为空!");
                txt_name.Focus();
                return;
            }
 
            if (string.IsNullOrEmpty(txt_conPeople.Text.Trim()))
            {
                MsgHelper.Warning("联系人不能为空!");
                txt_conPeople.Focus();
                return;
            }
 
            if (string.IsNullOrEmpty(txt_conTel.Text.Trim()))
            {
                MsgHelper.Warning("联系电话不能为空!");
                txt_conTel.Focus();
                return;
            }
 
            var _upGuid = txt_upGuid.Text.Trim().Length > 0
                ? txt_upGuid.SelectedValue.ToString()
                : "";
            var _obj = new
            {
                guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()), //主建
                upGuid = _upGuid, //上级的主建
                name = txt_name.Text.Trim(), //名称
                conPeople = txt_conPeople.Text, //联系人
                conTel = txt_conPeople.Text, //联系电话
                isStatus = txt_isStatus.Checked, //状态
                factory = txt_fNumber.Text //组织编号
            };
            try
            {
                var strJson = UtilityHelper.HttpPost("",
                    "Organization/EditModel",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                if (_rtn.rtnCode > 0)
                {
                    lbGuid.Text = _rtn.rtnData;
                    toolBarMenu1.isSetBtn = true;
                    UtilityHelper.ChangeEnableByControl(panel1.Controls, false);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void getTree()
        {
            tlMenu.Nodes.Clear();
            var imageList = new ImageList();
            imageList.Images.Add("icon1", Resources.publicfix_32x32);
            imageList.Images.Add("icon2", Resources.user_16x16);
            tlMenu.ImageList = imageList;
            var pgq = new PageQueryModel(1, 999999, "FID");
            var json = JsonConvert.SerializeObject(pgq);
            try
            {
                var strReturn = UtilityHelper.HttpPost("",
                    "Organization/GetListPage", json);
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                var dt = dd.rtnData.list;
                var drGrp = dt.Select("FID=1");
                var dtComList = new DataTable();
                dtComList.Columns.Add("guid", typeof(string));
                dtComList.Columns.Add("name", typeof(string));
                foreach (var _dy in drGrp)
                {
                    dtComList.Rows.Add(_dy["guid"].ToString(),
                        _dy["name"].ToString());
                    var node = new TreeNode(); //定义结点
                    node.Text =
                        "(" + _dy["FNumber"] + ")" + _dy["name"]; //为结点赋值
                    node.Name = _dy["guid"].ToString();
                    node.ImageIndex = 0;
                    var drItem = dt.Select("FParentlD='" + _dy["FID"] + "'");
                    foreach (var _dy2 in drItem)
                    {
                        var node22 = new TreeNode(); //定义结点
                        node22.Text =
                            "(" + _dy2["FNumber"] + ")" + _dy2["name"]; //为结点赋值
                        node22.Name = _dy2["guid"].ToString();
                        node22.ImageIndex = 1;
                        node.Nodes.Add(node22);
                    }
                    node.ExpandAll();
                    tlMenu.Nodes.Add(node);
                }
                txt_upGuid.DataSource = dtComList;
                txt_upGuid.DisplayMember = "name";
                txt_upGuid.ValueMember = "guid";
                getModel(dtComList.Rows[0]["guid"].ToString(),false,0);
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void getModel(string strGuid, bool isEdit, int tabIdx)
        {
            if (string.IsNullOrEmpty(strGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
 
            UtilityHelper.JumpToTab(xtraTabControl1, tabIdx);
            var _obj = new
            {
                guid = strGuid //主建
            };
            try
            {
                var strJson = UtilityHelper.HttpPost("",
                    "Organization/GetModel", JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    var dy = _rtn.rtnData;
                    lbGuid.Text = strGuid;
                    UtilityHelper.SetValueByObj(panel1.Controls, dy, isEdit);
                }
                else
                {
                    MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
       
    }
}