lg
2024-09-06 3d6533f1381e3e513ffb3d65bf34fb254f967088
DevApp/Gs.DevApp/DevFrm/User/SysMenu.cs
@@ -1,9 +1,9 @@
using Gs.DevApp.Models;
using DevExpress.XtraTreeList.Nodes;
using Gs.DevApp.Models;
using Gs.DevApp.ToolBox;
using Newtonsoft.Json;
using System;
using System.Data;
namespace Gs.DevApp.DevFrm.User
{
@@ -12,31 +12,40 @@
        public SysMenu()
        {
            InitializeComponent();
            getTree();
            this.toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick;
            this.toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick;
            this.toolBarMenu1.btnEdtClick += ToolBarMenu1_btnEdtClick;
            this.toolBarMenu1.btnSaveClick += ToolBarMenu1_btnSaveClick;
            this.toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            this.toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
            this.toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
            tlMenu.DoubleClick += TlMenu_DoubleClick;
            GetTree();
            GetDownList();
        }
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        private void TlMenu_DoubleClick(object sender, EventArgs e)
        {
            getTree();
        }
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            String rowGuid = Convert.ToString(tlMenu.FocusedNode.GetValue("guid"));
            if (string.IsNullOrEmpty(rowGuid))
            {
                ToolBox.MsgHelper.Warning("请先选择你要删除的行!");
                return;
            TreeListNode clickedNode = this.tlMenu.FocusedNode;
            if (clickedNode.FirstNode == null) {
                string rowGuid = clickedNode.GetValue("guid").ToString();
                GetModel(rowGuid, false, 999);
            }
            SysMenuAdd frm = new SysMenuAdd(rowGuid);
            frm.ShowDialog();
        }
        /// <summary>
        /// 取消事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
        {
            UtilityHelper.ChangeTab(xtraTabControl1, 0);
        }
        private void ToolBarMenu1_btnDelClick(object sender, EventArgs e)
        /// <summary>
        /// 删除事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e)
        {
            String rowGuid = Convert.ToString(tlMenu.FocusedNode.GetValue("guid"));
            if (string.IsNullOrEmpty(rowGuid))
@@ -57,7 +66,7 @@
            {
                strJson = UtilityHelper.HttpPost("", "MenuAction/DeleteModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson);
                if (_rtn.rtnCode > 0) { getTree(); }
                if (_rtn.rtnCode > 0) { GetTree(); }
                ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
@@ -66,17 +75,103 @@
            }
        }
        /// <summary>
        /// 刷新事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            UtilityHelper.ChangeTab(xtraTabControl1, 0);
            GetTree();
        }
        /// <summary>
        /// 修改事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            String rowGuid = Convert.ToString(tlMenu.FocusedNode.GetValue("guid"));
            if (string.IsNullOrEmpty(rowGuid))
            {
                ToolBox.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)
        {
            SysMenuAdd frm = new SysMenuAdd("");
            frm.UpdateParent += Frm_UpdateParent;
            frm.ShowDialog();
            UtilityHelper.ChangeTab(xtraTabControl1, 1);
            lbGuid.Text = "";
            UtilityHelper.CleanValue(this.panel1.Controls, true);
        }
        private void Frm_UpdateParent(object sender, UpdateParentEventArgs e)
        /// <summary>
        /// 保存事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnSaveClick(object sender, EventArgs e)
        {
            getTree();
            toolBarMenu1.isSetBtn = false;
            if (string.IsNullOrEmpty(txt_category.Text.Trim()) || txt_category.SelectedIndex == 0)
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("菜单类型不能为空!");
                txt_category.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txt_name.Text.Trim()))
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("菜单名称不能为空!");
                txt_name.Focus();
                return;
            }
            if (string.IsNullOrEmpty(txt_status.Text.Trim()) || txt_status.SelectedIndex == 0)
            {
                Gs.DevApp.ToolBox.MsgHelper.Warning("菜单状态不能为空!");
                txt_status.Focus();
                return;
            }
            string _upGuid = txt_upGuid.EditValue.ToString();
            var _obj = new
            {
                guid = lbGuid.Text.Trim(),//主建
                upGuid = _upGuid,//上级的主建
                name = txt_name.Text.Trim(),//名称
                icon = txt_icon.Text,//菜单图标
                status = txt_status.SelectedIndex,//状态
                formPath = txt_formPath.Text.Trim(),//窗体路径
                idx = int.Parse(txt_idx.Value.ToString()),//排序
                category = txt_category.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)
                {
                    lbGuid.Text = _rtn.rtnData;
                    toolBarMenu1.isSetBtn = true;
                    UtilityHelper.ChangeEnable(this.panel1.Controls, false);
                }
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        private void getTree()
        private void GetTree()
        {
            Models.PageQueryModel pgq = new Models.PageQueryModel(1, 999999, "idx", "asc", "", "");
            string json = JsonConvert.SerializeObject(pgq);
@@ -104,5 +199,59 @@
            }
        }
        private void GetModel(string strGuid, bool isEdit, int tabIdx)
        {
            if (string.IsNullOrEmpty(strGuid))
            {
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            UtilityHelper.ChangeTab(xtraTabControl1, tabIdx);
            var _obj = new
            {
                guid = strGuid,//主建
            };
            string strJson = "";
            try
            {
                strJson = UtilityHelper.HttpPost("", "MenuAction/GetModel", JsonConvert.SerializeObject(_obj));
                ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson);
                if (_rtn.rtnCode > 0)
                {
                    dynamic dy = _rtn.rtnData;
                    lbGuid.Text = strGuid;
                    UtilityHelper.SetValueByObj(this.panel1.Controls, dy, isEdit);
                    txt_upGuid.EditValue = dy.upGuid.ToString();
                }
                else
                    ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        private void GetDownList()
        {
            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;
                txt_upGuid.Properties.TreeList.KeyFieldName = "guid";
                txt_upGuid.Properties.TreeList.ParentFieldName = "upGuid";
                txt_upGuid.Properties.ValueMember = "guid";
                txt_upGuid.Properties.DisplayMember = "name";
                txt_upGuid.Properties.DataSource = dt;
            }
            catch (Exception ex)
            {
                ToolBox.MsgHelper.Warning("提示:" + ex.Message);
            }
        }
    }
}