| | |
| | | using DevExpress.XtraEditors; |
| | | using DevExpress.XtraGrid.Views.Base; |
| | | using DevExpress.XtraTreeList.Nodes; |
| | | using Gs.DevApp.Models; |
| | | using Gs.DevApp.ToolBox; |
| | | using Newtonsoft.Json; |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.ComponentModel; |
| | | using System.Data; |
| | | using System.Drawing; |
| | | using System.Linq; |
| | | using System.Text; |
| | | using System.Threading.Tasks; |
| | | using System.Windows.Forms; |
| | | |
| | | namespace Gs.DevApp.DevFrm.User |
| | | { |
| | | //https://blog.csdn.net/m0_54035969/article/details/140716675 |
| | | public partial class Role : DevExpress.XtraEditors.XtraForm |
| | | { |
| | | System.Text.StringBuilder sbRolist = new System.Text.StringBuilder(); |
| | | public Role() |
| | | { |
| | | InitializeComponent(); |
| | | this.toolBarMenu1.btnAddClick += ToolBarMenu1_btnAddClick; |
| | | GetPageList(1, 999999); |
| | | getTree(); |
| | | 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; |
| | | this.toolBarMenu1.btnRoleClick += ToolBarMenu1_btnRoleClick; |
| | | gcMain.MouseDoubleClick += GcMain_MouseDoubleClick; |
| | | gridView1.FocusedRowChanged += GridView1_FocusedRowChanged; |
| | | PageBar1.PagerEvent += PageBar1_PagerEvent; |
| | | GetPageList(1, UtilityHelper.GetPageSize()); |
| | | trv.AfterCheck += Trv_AfterCheck; |
| | | } |
| | | |
| | | |
| | | |
| | | private void GridView1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) |
| | | { |
| | | string rowGuid = ""; |
| | | DataRow myDataRow = gridView1.GetDataRow(e.FocusedRowHandle); |
| | | rowGuid = myDataRow["guid"].ToString(); |
| | | GetTree(rowGuid); |
| | | groupBox1.Text = "请勾选【" + myDataRow["roleName"].ToString() + "】的权限"; |
| | | } |
| | | /// <summary> |
| | | /// 双击事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void GcMain_MouseDoubleClick(object sender, MouseEventArgs e) |
| | | { |
| | | string rowGuid = ""; |
| | | ColumnView cv = (ColumnView)gcMain.FocusedView; |
| | | object rowIdObj = gridView1.GetRowCellValue(cv.FocusedRowHandle, "guid"); |
| | | DataRow myDataRow = gridView1.GetDataRow(gridView1.FocusedRowHandle); |
| | | rowGuid = myDataRow["guid"].ToString(); |
| | | GetModel(rowGuid, false, 999); |
| | | } |
| | | /// <summary> |
| | | /// 分页事件 |
| | | /// </summary> |
| | | /// <param name="curPage"></param> |
| | | /// <param name="pageSize"></param> |
| | | private void PageBar1_PagerEvent(int curPage, int pageSize) |
| | | { |
| | | GetPageList(curPage, pageSize); |
| | | } |
| | | /// <summary> |
| | | /// 取消事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void ToolBarMenu1_btnEscClick(object sender, EventArgs e) |
| | | { |
| | | UtilityHelper.ChangeTab(xtraTabControl1, 0); |
| | | } |
| | | /// <summary> |
| | | /// 删除事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void ToolBarMenu1_btnDelClick1(object sender, EventArgs e) |
| | | { |
| | | DataRow dr = gridView1.GetFocusedDataRow(); |
| | | if (dr == null || string.IsNullOrEmpty(dr["guid"].ToString())) |
| | | { |
| | | ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); |
| | | return; |
| | | } |
| | | if (!MsgHelper.AskQuestion("你选择了【" + dr["roleName"].ToString() + "】,确定删除吗?")) |
| | | return; |
| | | var _obj = new |
| | | { |
| | | guidList = dr["guid"].ToString(),//主建 |
| | | }; |
| | | string strJson = ""; |
| | | try |
| | | { |
| | | strJson = UtilityHelper.HttpPost("", "Role/DeleteModel", JsonConvert.SerializeObject(_obj)); |
| | | ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson); |
| | | if (_rtn.rtnCode > 0) |
| | | { |
| | | UtilityHelper.ChangeTab(xtraTabControl1, 0); |
| | | GetPageList(1, UtilityHelper.GetPageSize()); |
| | | } |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 刷新事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e) |
| | | { |
| | | UtilityHelper.ChangeTab(xtraTabControl1, 0); |
| | | GetPageList(1, UtilityHelper.GetPageSize()); |
| | | } |
| | | /// <summary> |
| | | /// 修改事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void ToolBarMenu1_btnEdtClick(object sender, EventArgs e) |
| | | { |
| | | DataRow dr = gridView1.GetFocusedDataRow(); |
| | | if (dr == null || string.IsNullOrEmpty(dr["guid"].ToString())) |
| | | { |
| | | ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); |
| | | return; |
| | | } |
| | | GetModel(dr["guid"].ToString(), true, 1); |
| | | |
| | | } |
| | | /// <summary> |
| | | /// 新增事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void ToolBarMenu1_btnAddClick(object sender, EventArgs e) |
| | | { |
| | | RoleAdd frm = new RoleAdd(""); |
| | | frm.ShowDialog(); |
| | | UtilityHelper.ChangeTab(xtraTabControl1, 1); |
| | | lbGuid.Text = ""; |
| | | UtilityHelper.CleanValue(this.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_roleName.Text.Trim())) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.Warning("角色名称不能为空!"); |
| | | txt_roleName.Focus(); |
| | | return; |
| | | } |
| | | if (string.IsNullOrEmpty(txt_rolRemark.Text.Trim())) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.Warning("角色备注不能为空!"); |
| | | txt_rolRemark.Focus(); |
| | | return; |
| | | } |
| | | if (string.IsNullOrEmpty(txt_status.Text.Trim())) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.Warning("角色状态不能为空!"); |
| | | txt_rolRemark.Focus(); |
| | | return; |
| | | } |
| | | var _obj = new |
| | | { |
| | | guid = lbGuid.Text.Trim(), |
| | | roleName = txt_roleName.Text.Trim(), |
| | | rolRemark = txt_rolRemark.Text.Trim(), |
| | | status = txt_status.SelectedIndex,//状态 |
| | | }; |
| | | string strJson = ""; |
| | | try |
| | | { |
| | | strJson = UtilityHelper.HttpPost("", "Role/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); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// 权限设置事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void ToolBarMenu1_btnRoleClick(object sender, EventArgs e) |
| | | { |
| | | DataRow dr = gridView1.GetFocusedDataRow(); |
| | | if (dr == null || string.IsNullOrEmpty(dr["guid"].ToString())) |
| | | { |
| | | ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); |
| | | return; |
| | | } |
| | | if (!MsgHelper.AskQuestion("你选择了【" + dr["roleName"].ToString() + "】,确定设置权限吗?")) |
| | | return; |
| | | sbRolist = new System.Text.StringBuilder(); |
| | | TraverseTreeViewNodes(trv.Nodes); |
| | | var _obj = new |
| | | { |
| | | roleGuid = dr["guid"].ToString(), |
| | | roleLst = sbRolist.ToString(), |
| | | }; |
| | | string strJson = ""; |
| | | try |
| | | { |
| | | strJson = UtilityHelper.HttpPost("", "MenuAction/SetRoleByRolueGuid", JsonConvert.SerializeObject(_obj)); |
| | | ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson); |
| | | if (_rtn.rtnCode > 0) |
| | | { |
| | | |
| | | } |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | /// <summary> |
| | | /// |
| | | /// </summary> |
| | |
| | | strReturn = UtilityHelper.HttpPost("", "Role/GetListPage", json); |
| | | ReturnModel<PageListModel> dd = UtilityHelper.GetTableByJson(strReturn); |
| | | DataTable dt = dd.rtnData.list; |
| | | gc_Main.BindingContext = new BindingContext(); |
| | | gc_Main.DataSource = dt; |
| | | gc_Main.ForceInitialize(); |
| | | gcMain.BindingContext = new BindingContext(); |
| | | gcMain.DataSource = dt; |
| | | gcMain.ForceInitialize(); |
| | | int dddd = dd.rtnData.pages;//总页 |
| | | PageBar1.TotalPages = dddd; |
| | | PageBar1.RecordCount = dd.rtnData.total;//记录总数 |
| | | PageBar1.CurrentPage = curPage;//当前页 |
| | | PageBar1.RowsCount = pageSize;//每页显示 |
| | | PageBar1.setTxt(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | |
| | | private void getTree() |
| | | 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("", "Role/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); |
| | | } |
| | | else |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | private void GetTree(string rolueGuid) |
| | | { |
| | | trv.Nodes.Clear(); |
| | | ImageList imageList = new ImageList(); |
| | |
| | | imageList.Images.Add("icon2", Properties.Resources.listmultilevel_16x16); |
| | | imageList.Images.Add("icon3", Properties.Resources.addcalculatedfield_16x16); |
| | | trv.ImageList = imageList; |
| | | Models.PageQueryModel pgq = new Models.PageQueryModel(1, 999999, "idx", "desc", "", ""); |
| | | string json = JsonConvert.SerializeObject(pgq); |
| | | var _obj = new |
| | | { |
| | | rolueGuid = rolueGuid,//主建 |
| | | }; |
| | | string strReturn = ""; |
| | | try |
| | | { |
| | | strReturn = UtilityHelper.HttpPost("", "MenuAction/GetListPageByOrg", json); |
| | | strReturn = UtilityHelper.HttpPost("", "MenuAction/GetListPageByOrg", JsonConvert.SerializeObject(_obj)); |
| | | ReturnModel<PageListModel> dd = UtilityHelper.GetTableByJson(strReturn); |
| | | DataTable dt = dd.rtnData.list; |
| | | DataRow[] drGrp = dt.Select("upGuid='' or upGuid is null"); |
| | | foreach (DataRow _dy in drGrp) |
| | | { |
| | | string _orgGuid = _dy["guid"].ToString() + "&"; |
| | | TreeNode node = new TreeNode();//定义结点 |
| | | node.Text = _dy["name"].ToString();//为结点赋值 |
| | | node.Name = _dy["guid"].ToString(); |
| | | node.ImageIndex = 0; |
| | | DataRow[] drItem = dt.Select("upGuid='" + _dy["guid"].ToString() + "' and orgGuid='"+ _dy["guid"].ToString() + "'"); |
| | | DataRow[] drItem = dt.Select("upGuid='" + _dy["guid"].ToString() + "' and orgGuid='" + _dy["guid"].ToString() + "'"); |
| | | foreach (DataRow _dy2 in drItem) |
| | | { |
| | | TreeNode node22 = new TreeNode();//定义结点 |
| | | node22.Text = _dy2["name"].ToString();//为结点赋值 |
| | | node22.Name = _dy2["guid"].ToString(); |
| | | node22.Name = _orgGuid + _dy2["guid"].ToString(); |
| | | node22.ImageIndex = 1; |
| | | DataRow[] drItem33 = dt.Select("upGuid='" + _dy2["guid"].ToString() + "' and orgGuid='"+ _dy["guid"].ToString() + "'"); |
| | | DataRow[] drItem33 = dt.Select("upGuid='" + _dy2["guid"].ToString() + "' and orgGuid='" + _dy["guid"].ToString() + "'"); |
| | | foreach (DataRow _dy3 in drItem33) |
| | | { |
| | | TreeNode node33 = new TreeNode();//定义结点 |
| | | node33.Text = _dy3["name"].ToString();//为结点赋值 |
| | | node33.Name = _dy3["guid"].ToString(); |
| | | node33.Name = _orgGuid + _dy3["guid"].ToString(); |
| | | node33.ImageIndex = 2; |
| | | DataRow[] drItem44 = dt.Select("upGuid='" + _dy3["guid"].ToString() + "' and orgGuid='" + _dy["guid"].ToString() + "'"); |
| | | foreach (DataRow _dy4 in drItem44) |
| | | { |
| | | TreeNode node44= new TreeNode();//定义结点 |
| | | TreeNode node44 = new TreeNode();//定义结点 |
| | | node44.Text = _dy4["name"].ToString();//为结点赋值 |
| | | node44.Name = _dy4["guid"].ToString(); |
| | | node44.Name = _orgGuid + _dy4["guid"].ToString(); |
| | | node44.ImageIndex = 3; |
| | | node33.Nodes.Add(node44); |
| | | } |
| | | node22.Nodes.Add(node33); |
| | | } |
| | | node22.Expand(); |
| | | node.Nodes.Add(node22); |
| | | } |
| | | node.ExpandAll(); |
| | | node.Expand(); |
| | | trv.Nodes.Add(node); |
| | | } |
| | | } |
| | |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | private void Trv_AfterCheck(object sender, TreeViewEventArgs e) |
| | | { |
| | | try |
| | | { |
| | | UtilityHelper.TreeViewCheck(e); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | MsgHelper.ShowError(ex.Message); |
| | | } |
| | | } |
| | | // 遍历TreeView中的所有节点 |
| | | private void TraverseTreeViewNodes(TreeNodeCollection nodes) |
| | | { |
| | | foreach (TreeNode node in nodes) |
| | | { |
| | | if (node.Checked) |
| | | sbRolist.Append(node.Name + "~"); |
| | | // 递归遍历子节点 |
| | | if (node.Nodes.Count > 0) |
| | | { |
| | | TraverseTreeViewNodes(node.Nodes); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | } |