南骏 池
2024-09-01 fc1b563df6d0405a24e7898c997bd52472ae9154
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
using DevExpress.XtraEditors;
using Newtonsoft.Json;
using System;
using System.Data;
using Gs.DevApp.ToolBox;
using Gs.DevApp.Models;
using DevExpress.XtraTreeList.Nodes;
namespace Gs.DevApp.DevFrm.User
{
    public partial class SysMenuAdd : DevExpress.XtraEditors.XtraForm
    {
        public event EventHandler<UpdateParentEventArgs> UpdateParent;
 
        public SysMenuAdd(string guid)
        {
            InitializeComponent();
            btnSave.Click += BtnSave_Click;
            btnEsc.Click += BtnEsc_Click;
            txtMenuType.TextChanged += TxtMenuType_TextChanged;
            getTree();
            lbGuid.Text = guid;
            getModel();
        }
        private void TxtMenuType_TextChanged(object sender, EventArgs e)
        {
            if (txtMenuType.SelectedIndex == 1)
            {
                this.txtFormNamespace.Enabled = true;
                this.txtMenuIco.Enabled = true;
            }
            else
            {
                this.txtFormNamespace.Enabled = false;
                this.txtMenuIco.Enabled = false;
                this.txtFormNamespace.Text = "";
                this.txtMenuIco.Text = "";
            }
        }
 
        private void BtnEsc_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }
 
        private void BtnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(txtMenuType.Text.Trim()) || txtMenuType.SelectedIndex == 0)
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("菜单类型不能为空!");
                txtMenuType.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txtMenuName.Text.Trim()))
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("菜单名称不能为空!");
                txtMenuName.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txtStatus.Text.Trim()) || txtStatus.SelectedIndex == 0)
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("菜单状态不能为空!");
                txtStatus.Focus();
                return;
            }
            string _upGuid = "";
            TreeListNode focusedNode = txtParentMenuName.Properties.TreeList.FocusedNode;
            if (focusedNode != null)
            {
                _upGuid = focusedNode.GetValue("guid").ToString();
            }
            var _obj = new
            {
                guid = lbGuid.Text.Trim(),//主建
                upGuid = _upGuid,//上级的主建
                name = txtMenuName.Text.Trim(),//名称
                icon = txtMenuIco.Text,//菜单图标
                status = txtStatus.SelectedIndex,//状态
                formPath = txtFormNamespace.Text.Trim(),//窗体路径
                idx = int.Parse(txtIdx.Value.ToString()),//排序
                category = txtMenuType.SelectedIndex,//类型
            };
            string strJson = "";
            try
            {
                strJson = UtilityHelper.HttpPost("", "MenuAction/EditModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson);
                ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
                if (_rtn.rtnCode > 0)
                {
                    UpdateParent?.Invoke(this, new UpdateParentEventArgs { Data = "" });
                }
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void getTree()
        {
            Models.PageQueryModel pgq = new Models.PageQueryModel(1, 999999, "idx", "asc", "", " and category=1");
            string json = JsonConvert.SerializeObject(pgq);
            string strReturn = "";
            try
            {
                strReturn = UtilityHelper.HttpPost("", "MenuAction/GetListPage", json);
                ReturnModel<PageListModel> dd = UtilityHelper.GetTableByJson(strReturn);
                DataTable dt = dd.rtnData.list;
                txtParentMenuName.Properties.TreeList.KeyFieldName = "guid";
                txtParentMenuName.Properties.TreeList.ParentFieldName = "upGuid";
                //txtParentMenuName.Properties.ValueMember = "guid";
                txtParentMenuName.Properties.DisplayMember = "name";
                txtParentMenuName.Properties.DataSource = dt;
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void getModel()
        {
            if (lbGuid.Text.Length <= 0) return;
            var _obj = new
            {
                guid = lbGuid.Text.Trim(),//主建
            };
            string strJson = "";
            try
            {
                strJson = UtilityHelper.HttpPost("", "MenuAction/GetModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson);
                if (_rtn.rtnCode > 0)
                {
                    txtMenuName.Text = _rtn.rtnData.name;
                    txtMenuIco.Text = _rtn.rtnData.icon;
                    txtFormNamespace.Text = _rtn.rtnData.formPath;
                    txtStatus.SelectedIndex = _rtn.rtnData.status;
                    txtMenuType.SelectedIndex = _rtn.rtnData.category;
                    txtIdx.Value = _rtn.rtnData.idx;
                    //  txtParentMenuName.Text = "";
                }
                else
                    ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
 
        private void cleanTxt()
        {
            //guid = lbGuid.Text.Trim(),//主建
            //    upGuid = _upGuid,//上级的主建
            //    name = txtMenuName.Text.Trim(),//名称
            //    icon = txtMenuIco.Text,//菜单图标
            //    status = txtStatus.SelectedIndex,//状态
            //    formPath = txtFormNamespace.Text.Trim(),//窗体路径
            //    idx = int.Parse(txtIdx.Value.ToString()),//排序
            //    category = txtMenuType.SelectedIndex,//类型
 
            //if(lbGuid.Text)
        }
 
       
        
    }
}