lu
2025-04-14 ecb7a60de1639f520712ce95f99414b0dd2c9713
DevApp/Gs.DevApp/DevFrm/User/Role.cs
@@ -1,15 +1,14 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DevExpress.XtraGrid.Views.Base;
using DevExpress.XtraEditors;
using Gs.DevApp.Entity;
using Gs.DevApp.Properties;
using Gs.DevApp.ToolBox;
using Gs.DevApp.UserControl;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace Gs.DevApp.DevFrm.User
{
@@ -17,7 +16,6 @@
    {
        private StringBuilder _actionLst = new StringBuilder();
        private List<FilterEntity> _filterList = new List<FilterEntity>();
        public Role()
        {
            InitializeComponent();
@@ -27,56 +25,27 @@
            toolBarMenu1.btnLoadClick += ToolBarMenu1_btnLoadClick;
            toolBarMenu1.btnDelClick += ToolBarMenu1_btnDelClick1;
            toolBarMenu1.btnEscClick += ToolBarMenu1_btnEscClick;
            toolBarMenu1.btnRoleClick += ToolBarMenu1_btnRoleClick;
            toolBarMenu1.btnQueryClick += ToolBarMenu1_btnQueryClick;
            gcMain.MouseDoubleClick += GcMain_MouseDoubleClick;
            gridView1.FocusedRowChanged += GridView1_FocusedRowChanged;
            getPageList(1, UtilityHelper.GetPageSize());
            this.toolBarMenu1.getXmlConfig();
            Gs.DevApp.ToolBox.UtilityHelper.SetGridViewParameter(gridView1, null, null, "", "", (value) =>
            {
                Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 0);
            }, tips);
            Gs.DevApp.ToolBox.UtilityHelper.SetTabParameter(gridView1, xtraTabControl1, pageBar1, (value) =>
            {
                getModel(value);
            }, (value) =>
            {
                getPageList(this.pageBar1.CurrentPage);
            }, lbGuid);
            getPageList(1);
            pageBar1.PagerEvent += PageBar1_PagerEvent;
            trv.AfterCheck += Trv_AfterCheck;
            gridView1.IndicatorWidth = 50;
            gridView1.CustomDrawRowIndicator += (s, e) =>
            {
                if (e.Info.IsRowIndicator && e.RowHandle >= 0)
                    e.Info.DisplayText = (e.RowHandle + 1).ToString();
            };
            gridView1.CustomDrawEmptyForeground += (s, e) =>
            {
                var str = "暂未查找到匹配的数据!";
                var f = new Font("微软雅黑", 16);
                var r = new Rectangle(gridView1.GridControl.Width / 2 - 100,
                    e.Bounds.Top + 45, e.Bounds.Right - 5, e.Bounds.Height - 5);
                e.Graphics.DrawString(str, f, Brushes.Gray, r);
            };
        }
        /// <summary>
        ///     换切换事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GridView1_FocusedRowChanged(object sender,
            FocusedRowChangedEventArgs e)
        private void GridView1_ColumnFilterChanged(object sender, EventArgs e)
        {
            var rowGuid = "";
            var myDataRow = gridView1.GetDataRow(e.FocusedRowHandle);
            if (myDataRow == null) return;
            rowGuid = myDataRow["guid"].ToString();
            getTree(rowGuid);
            groupBox1.Text = "请勾选【" + myDataRow["roleName"] + "】的权限";
        }
        /// <summary>
        ///     双击事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            var rowGuid =
                UtilityHelper.GetCurrentDoubleRow(gridView1, e, "guid");
            if (!string.IsNullOrEmpty(rowGuid))
                getModel(rowGuid, false, 999);
            _filterList = Gs.DevApp.ToolBox.UtilityHelper.GetDilter(gridView1.Columns, gridView1);
            Task.Delay(100);
            getPageList(1);
        }
        /// <summary>
@@ -86,7 +55,7 @@
        /// <param name="pageSize"></param>
        private void PageBar1_PagerEvent(int curPage, int pageSize)
        {
            getPageList(curPage, pageSize);
            getPageList(curPage);
        }
        /// <summary>
@@ -96,7 +65,10 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnQueryClick(object sender, EventArgs e)
        {
            var frm = new ShowFilter(gridView1.Columns, _filterList);
            gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
            gridView1.ActiveFilter.Clear();
            gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
            var frm = new ShowFilter(gridView1.Columns, _filterList, this.GetType().FullName);
            frm.UpdateParent += Frm_UpdateParent;
            frm.ShowDialog();
        }
@@ -109,7 +81,7 @@
        private void Frm_UpdateParent(object sender, UpdateParentEventArgs e)
        {
            _filterList = e.FilterList;
            getPageList(1, pageBar1.RowsCount);
            getPageList(1);
        }
        /// <summary>
@@ -119,7 +91,7 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEscClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
            Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 1);
        }
        /// <summary>
@@ -131,15 +103,13 @@
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_roleName, gridView1, 2);
                lbGuid, txt_roleName, gridView1, "roleName");
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            if (!MsgHelper.AskQuestion("你选择了【" + rowName +
                                       "】,确定删除吗?\n该操作将会清空相应的用户权限"))
            if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定删除吗?\n该操作将会清空相应的用户权限"))
                return;
            var lst = new List<string>();
            lst.Add(rowGuid);
@@ -151,10 +121,12 @@
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                if (_rtn.rtnCode > 0)
                {
                    UtilityHelper.JumpToTab(xtraTabControl1, 0);
                    getPageList(1, UtilityHelper.GetPageSize());
                    if (xtraTabControl1.SelectedTabPageIndex == 0)
                    { }
                    else
                        Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 2);
                    getPageList(this.pageBar1.CurrentPage);
                }
                MsgHelper.Warning("提示:" + _rtn.rtnMsg);
            }
            catch (Exception ex)
@@ -170,8 +142,20 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 0);
            getPageList(1, UtilityHelper.GetPageSize());
            if (xtraTabControl1.SelectedTabPageIndex == 1)
                getModel(lbGuid.Text.Trim());
            else
            {
                //_filterList.Clear();
                //if (gridView1.ActiveFilter.Count > 0)
                //{
                //    gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
                //    gridView1.ActiveFilter.Clear();
                //    gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
                //}
                //getPageList(1);
                getPageList(this.pageBar1.CurrentPage);
            }
        }
        /// <summary>
@@ -181,16 +165,22 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e)
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_roleName, gridView1);
            string rowGuid = "", rowName = "";
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1, lbGuid, txt_roleName, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                ToolBox.MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            getModel(rowGuid, true, 1);
            Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 3);
            if (xtraTabControl1.SelectedTabPageIndex == 1)
            {
                getModel(rowGuid);
            }
            else
            {
                UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, true);
            }
        }
        /// <summary>
@@ -200,9 +190,9 @@
        /// <param name="e"></param>
        private void ToolBarMenu1_btnAddClick(object sender, EventArgs e)
        {
            UtilityHelper.JumpToTab(xtraTabControl1, 1);
            lbGuid.Text = "";
            UtilityHelper.CleanValueByControl(panel1.Controls, true);
            Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 4);
            UtilityHelper.CleanValueByControl(this.layoutMx1.Controls, true);
        }
        /// <summary>
@@ -226,7 +216,6 @@
                txt_roleRemark.Focus();
                return;
            }
            var _obj = new
            {
                guid = UtilityHelper.ToGuid(lbGuid.Text.Trim()),
@@ -244,47 +233,10 @@
                {
                    lbGuid.Text = _rtn.rtnData;
                    toolBarMenu1.isSetBtn = true;
                    UtilityHelper.ChangeEnableByControl(panel1.Controls, false);
                    UtilityHelper.ChangeEnableByControl(this.layoutMx1.Controls, false);
                    toolBarMenu1.currentAction = "";
                    Gs.DevApp.ToolBox.UtilityHelper.JumpTab(xtraTabControl1, 6);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        /// <summary>
        ///     权限设置事件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ToolBarMenu1_btnRoleClick(object sender, EventArgs e)
        {
            string rowGuid, rowName;
            (rowGuid, rowName) = UtilityHelper.GetCurrentRow(xtraTabControl1,
                lbGuid, txt_roleName, gridView1);
            if (string.IsNullOrEmpty(rowGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            if (!MsgHelper.AskQuestion("你选择了【" + rowName + "】,确定设置权限吗?"))
                return;
            _actionLst = new StringBuilder();
            TraverseTreeViewNodes(trv.Nodes);
            var _obj = new
            {
                roleGuid = rowGuid,
                actionLst = _actionLst.ToString()
            };
            try
            {
                var strJson = UtilityHelper.HttpPost("",
                    "Role/SetRoleMenuAction",
                    JsonConvert.SerializeObject(_obj));
                var _rtn = UtilityHelper.ReturnToDynamic(strJson);
                MsgHelper.Warning("提示:" + _rtn.rtnData.outMsg);
            }
            catch (Exception ex)
            {
@@ -296,30 +248,38 @@
        /// </summary>
        /// <param name="curPage">第几页</param>
        /// <param name="pageSize">每页几条</param>
        private void getPageList(int curPage, int pageSize)
        private void getPageList(int curPage)
        {
            var _sbSqlWhere = new StringBuilder();
            foreach (var itm in _filterList)
                _sbSqlWhere.Append(" and " + itm.fileId + itm.fileOper + "'" +
                                   itm.fileValue + "'");
            var pgq = new PageQueryModel(curPage, pageSize, "CREATE_TIME",
                "desc", "", _sbSqlWhere.ToString());
            var _sbSqlWhere = UtilityHelper.GetSearchWhere(_filterList);
            var pgq = new PageQueryModel(curPage, this.pageBar1.RowsCount, "ROLE_NAME asc,CREATE_TIME ", "desc", "", _sbSqlWhere.ToString());
            var json = JsonConvert.SerializeObject(pgq);
            try
            {
                var strReturn =
                    UtilityHelper.HttpPost("", "Role/GetListPage", json);
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                var dt = dd.rtnData.list;
                gcMain.BindingContext = new BindingContext();
                gcMain.DataSource = dt;
                gcMain.ForceInitialize();
                var dddd = dd.rtnData.pages; //总页
                pageBar1.TotalPages = dddd;
                pageBar1.RecordCount = dd.rtnData.total; //记录总数
                pageBar1.CurrentPage = curPage; //当前页
                pageBar1.RowsCount = pageSize; //每页显示
                pageBar1.setTxt();
                if (dd.rtnCode > 0)
                {
                    DataTable dt = dd.rtnData.list;
                    gcMain1.BindingContext = new BindingContext();
                    gridView1.ColumnFilterChanged -= GridView1_ColumnFilterChanged;
                    if (dt.Rows.Count > 0)
                    {
                        gcMain1.DataSource = dt;
                        gcMain1.ForceInitialize();
                        gridView1.BestFitColumns(); Gs.DevApp.ToolBox.UtilityHelper.SetGridLayout(gridView1);
                    }
                    else
                        UtilityHelper.SetDefaultTable(gcMain1, gridView1);
                    gridView1.ColumnFilterChanged += GridView1_ColumnFilterChanged;
                    pageBar1.TotalPages = dd.rtnData.pages;//总页
                    pageBar1.CurrentPage = curPage;//当前页
                    pageBar1.RecordCount = dd.rtnData.total;//总记录数
                }
                else
                {
                    ToolBox.MsgHelper.ShowError("提示:" + dd.rtnMsg);
                }
            }
            catch (Exception ex)
            {
@@ -327,15 +287,16 @@
            }
        }
        private void getModel(string strGuid, bool isEdit, int tabIdx)
        private void getModel(string strGuid)
        {
            bool isEdit = false;
            if (toolBarMenu1.currentAction == "add") return;
            if (toolBarMenu1.currentAction == "edit") isEdit = true;
            if (string.IsNullOrEmpty(strGuid))
            {
                MsgHelper.Warning("请先选择你要操作的行!");
                return;
            }
            UtilityHelper.JumpToTab(xtraTabControl1, tabIdx);
            var _obj = new
            {
                guid = strGuid //主建
@@ -350,7 +311,7 @@
                {
                    var dy = _rtn.rtnData;
                    lbGuid.Text = strGuid;
                    UtilityHelper.SetValueByObj(panel1.Controls, dy, isEdit);
                    UtilityHelper.SetValueByObj(this.layoutMx1.Controls, dy, isEdit);
                }
                else
                {
@@ -362,104 +323,6 @@
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        private void getTree(string roleGuid)
        {
            trv.Nodes.Clear();
            var imageList = new ImageList();
            imageList.Images.Add("icon0", Resources.publicfix_32x32);
            imageList.Images.Add("icon1", Resources.addfooter_32x32);
            imageList.Images.Add("icon2", Resources.listmultilevel_16x16);
            imageList.Images.Add("icon3", Resources.addcalculatedfield_16x16);
            trv.ImageList = imageList;
            var _obj = new
            {
                roleGuid //主建
            };
            try
            {
                var strReturn = UtilityHelper.HttpPost("", "Role/GetListByRole",
                    JsonConvert.SerializeObject(_obj));
                var dd = UtilityHelper.ReturnToTablePage(strReturn);
                var dt = dd.rtnData.list;
                var drGrp = dt.Select("upGuid='' or upGuid is null");
                foreach (var _dy in drGrp)
                {
                    var _orgGuid = _dy["guid"] + "&";
                    var node = new TreeNode(); //定义结点
                    node.Text = _dy["name"].ToString(); //为结点赋值
                    node.Name = _dy["guid"].ToString();
                    node.ImageIndex = 0;
                    node.Checked = _dy["isCk"].ToString() == "1" ? true : false;
                    var drItem = dt.Select("upGuid='" + _dy["guid"] +
                                           "' and orgGuid='" + _dy["guid"] +
                                           "'");
                    foreach (var _dy2 in drItem)
                    {
                        var node22 = new TreeNode(); //定义结点
                        node22.Text = _dy2["name"].ToString(); //为结点赋值
                        node22.Name = _orgGuid + _dy2["guid"];
                        node22.ImageIndex = 1;
                        node22.Checked = _dy2["isCk"].ToString() == "1"
                            ? true
                            : false;
                        var drItem33 = dt.Select("upGuid='" + _dy2["guid"] +
                                                 "' and orgGuid='" +
                                                 _dy["guid"] + "'");
                        foreach (var _dy3 in drItem33)
                        {
                            var node33 = new TreeNode(); //定义结点
                            node33.Text = _dy3["name"].ToString(); //为结点赋值
                            node33.Name = _orgGuid + _dy3["guid"];
                            node33.ImageIndex = 2;
                            node33.Checked = _dy3["isCk"].ToString() == "1"
                                ? true
                                : false;
                            var drItem44 = dt.Select("upGuid='" + _dy3["guid"] +
                                "' and orgGuid='" + _dy["guid"] + "'");
                            foreach (var _dy4 in drItem44)
                            {
                                var node44 = new TreeNode(); //定义结点
                                node44.Text = _dy4["name"].ToString(); //为结点赋值
                                node44.Name = _orgGuid + _dy4["guid"];
                                node44.ImageIndex = 3;
                                node44.Checked = _dy4["isCk"].ToString() == "1"
                                    ? true
                                    : false;
                                node33.Nodes.Add(node44);
                            }
                            node22.Nodes.Add(node33);
                        }
                        node22.Expand();
                        node.Nodes.Add(node22);
                    }
                    node.Expand();
                    trv.Nodes.Add(node);
                }
            }
            catch (Exception ex)
            {
                MsgHelper.Warning("提示:" + ex.Message);
            }
        }
        private void Trv_AfterCheck(object sender, TreeViewEventArgs e)
        {
            try
            {
                trv.AfterCheck -= Trv_AfterCheck;
                UtilityHelper.TreeViewCheck(e);
                trv.AfterCheck += Trv_AfterCheck;
            }
            catch (Exception ex)
            {
                MsgHelper.ShowError(ex.Message);
            }
        }
        // 遍历TreeView中的所有节点
        private void TraverseTreeViewNodes(TreeNodeCollection nodes)
        {
@@ -471,5 +334,16 @@
                if (node.Nodes.Count > 0) TraverseTreeViewNodes(node.Nodes);
            }
        }
        private void repositoryItemButtonEdit1_ButtonClick(object sender, DevExpress.XtraEditors.Controls.ButtonPressedEventArgs e)
        {
            if (e.Button.Index == 0)
            {
                var rowhandle = gridView1.FocusedRowHandle;
                var dr = gridView1.GetDataRow(rowhandle);
                var roleGuid = dr["guid"].ToString();
                var frm = new RoleSelectAction(roleGuid);
                frm.ShowDialog();
            }
        }
    }
}