| | |
| | | using DevExpress.XtraGrid.Views.Base; |
| | | using DevExpress.XtraTreeList.Nodes; |
| | | using DevExpress.XtraGrid.Views.Grid; |
| | | using DevExpress.XtraGrid.Views.Grid.ViewInfo; |
| | | using Gs.DevApp.Models; |
| | | using Gs.DevApp.ToolBox; |
| | | using Newtonsoft.Json; |
| | |
| | | |
| | | namespace Gs.DevApp.DevFrm.User |
| | | { |
| | | //https://www.cnblogs.com/mkmkbj/p/16771297.html |
| | | //https://blog.csdn.net/m0_54035969/article/details/140716675 |
| | | public partial class Role : DevExpress.XtraEditors.XtraForm |
| | | { |
| | | System.Text.StringBuilder sbRolist = new System.Text.StringBuilder(); |
| | | System.Text.StringBuilder actionLst = new System.Text.StringBuilder(); |
| | | public Role() |
| | | { |
| | | InitializeComponent(); |
| | |
| | | this.toolBarMenu1.btnRoleClick += ToolBarMenu1_btnRoleClick; |
| | | gcMain.MouseDoubleClick += GcMain_MouseDoubleClick; |
| | | gridView1.FocusedRowChanged += GridView1_FocusedRowChanged; |
| | | PageBar1.PagerEvent += PageBar1_PagerEvent; |
| | | GetPageList(1, UtilityHelper.GetPageSize()); |
| | | pageBar1.PagerEvent += PageBar1_PagerEvent; |
| | | getPageList(1, UtilityHelper.GetPageSize()); |
| | | trv.AfterCheck += Trv_AfterCheck; |
| | | } |
| | | |
| | | |
| | | |
| | | /// <summary> |
| | | /// 换切换事件 |
| | | /// </summary> |
| | | /// <param name="sender"></param> |
| | | /// <param name="e"></param> |
| | | private void GridView1_FocusedRowChanged(object sender, FocusedRowChangedEventArgs e) |
| | | { |
| | | string rowGuid = ""; |
| | | DataRow myDataRow = gridView1.GetDataRow(e.FocusedRowHandle); |
| | | rowGuid = myDataRow["guid"].ToString(); |
| | | GetTree(rowGuid); |
| | | getTree(rowGuid); |
| | | groupBox1.Text = "请勾选【" + myDataRow["roleName"].ToString() + "】的权限"; |
| | | } |
| | | /// <summary> |
| | |
| | | /// <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); |
| | | GridHitInfo info = gridView1.CalcHitInfo(e.Location); |
| | | if (info.InRow) |
| | | { |
| | | GridView view = info.View as GridView; |
| | | if (view != null) |
| | | { |
| | | DataRow row = view.GetDataRow(info.RowHandle); |
| | | if (row != null) |
| | | { |
| | | string rowGuid = (row["guid"].ToString()); |
| | | getModel(rowGuid, false, 999); |
| | | } |
| | | } |
| | | } |
| | | } |
| | | /// <summary> |
| | | /// 分页事件 |
| | |
| | | /// <param name="pageSize"></param> |
| | | private void PageBar1_PagerEvent(int curPage, int pageSize) |
| | | { |
| | | GetPageList(curPage, pageSize); |
| | | getPageList(curPage, pageSize); |
| | | } |
| | | /// <summary> |
| | | /// 取消事件 |
| | |
| | | ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); |
| | | return; |
| | | } |
| | | if (!MsgHelper.AskQuestion("你选择了【" + dr["roleName"].ToString() + "】,确定删除吗?")) |
| | | if (!MsgHelper.AskQuestion("你选择了【" + dr["roleName"].ToString() + "】,确定删除吗?\n该操作将会清空相应的用户权限")) |
| | | return; |
| | | var _obj = new |
| | | { |
| | | guidList = dr["guid"].ToString(),//主建 |
| | | guid = dr["guid"].ToString(),//主建 |
| | | }; |
| | | string strJson = ""; |
| | | try |
| | |
| | | if (_rtn.rtnCode > 0) |
| | | { |
| | | UtilityHelper.ChangeTab(xtraTabControl1, 0); |
| | | GetPageList(1, UtilityHelper.GetPageSize()); |
| | | getPageList(1, UtilityHelper.GetPageSize()); |
| | | } |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | } |
| | |
| | | private void ToolBarMenu1_btnLoadClick(object sender, EventArgs e) |
| | | { |
| | | UtilityHelper.ChangeTab(xtraTabControl1, 0); |
| | | GetPageList(1, UtilityHelper.GetPageSize()); |
| | | getPageList(1, UtilityHelper.GetPageSize()); |
| | | } |
| | | /// <summary> |
| | | /// 修改事件 |
| | |
| | | ToolBox.MsgHelper.Warning("请先选择你要操作的行!"); |
| | | return; |
| | | } |
| | | GetModel(dr["guid"].ToString(), true, 1); |
| | | getModel(dr["guid"].ToString(), true, 1); |
| | | |
| | | } |
| | | /// <summary> |
| | |
| | | txt_rolRemark.Focus(); |
| | | return; |
| | | } |
| | | if (string.IsNullOrEmpty(txt_status.Text.Trim())) |
| | | if (txt_status.SelectedIndex <= 0) |
| | | { |
| | | Gs.DevApp.ToolBox.MsgHelper.Warning("角色状态不能为空!"); |
| | | txt_rolRemark.Focus(); |
| | | txt_status.Focus(); |
| | | return; |
| | | } |
| | | var _obj = new |
| | |
| | | rolRemark = txt_rolRemark.Text.Trim(), |
| | | status = txt_status.SelectedIndex,//状态 |
| | | }; |
| | | string strJson = ""; |
| | | try |
| | | { |
| | | strJson = UtilityHelper.HttpPost("", "Role/EditModel", JsonConvert.SerializeObject(_obj)); |
| | | string strJson = UtilityHelper.HttpPost("", "Role/EditModel", JsonConvert.SerializeObject(_obj)); |
| | | ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson); |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | if (_rtn.rtnCode > 0) |
| | |
| | | } |
| | | if (!MsgHelper.AskQuestion("你选择了【" + dr["roleName"].ToString() + "】,确定设置权限吗?")) |
| | | return; |
| | | sbRolist = new System.Text.StringBuilder(); |
| | | actionLst = new System.Text.StringBuilder(); |
| | | TraverseTreeViewNodes(trv.Nodes); |
| | | var _obj = new |
| | | { |
| | | roleGuid = dr["guid"].ToString(), |
| | | roleLst = sbRolist.ToString(), |
| | | actionLst = actionLst.ToString(), |
| | | }; |
| | | string strJson = ""; |
| | | try |
| | | { |
| | | strJson = UtilityHelper.HttpPost("", "MenuAction/SetRoleByRolueGuid", JsonConvert.SerializeObject(_obj)); |
| | | string strJson = UtilityHelper.HttpPost("", "MenuAction/SetMenuActionByRole", JsonConvert.SerializeObject(_obj)); |
| | | ReturnModel<dynamic> _rtn = ToolBox.UtilityHelper.GetDataByJson(strJson); |
| | | if (_rtn.rtnCode > 0) |
| | | { |
| | | |
| | | } |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnMsg); |
| | | ToolBox.MsgHelper.Warning("提示:" + _rtn.rtnData.outMsg); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | |
| | | /// </summary> |
| | | /// <param name="curPage">第几页</param> |
| | | /// <param name="pageSize">每页几条</param> |
| | | private void GetPageList(int curPage, int pageSize) |
| | | private void getPageList(int curPage, int pageSize) |
| | | { |
| | | Models.PageQueryModel pgq = new Models.PageQueryModel(curPage, pageSize, "createDate", "asc", "", ""); |
| | | string json = JsonConvert.SerializeObject(pgq); |
| | | string strReturn = ""; |
| | | try |
| | | { |
| | | strReturn = UtilityHelper.HttpPost("", "Role/GetListPage", json); |
| | | string strReturn = UtilityHelper.HttpPost("", "Role/GetListPage", json); |
| | | ReturnModel<PageListModel> dd = UtilityHelper.GetTableByJson(strReturn); |
| | | DataTable dt = dd.rtnData.list; |
| | | 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(); |
| | | 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 GetModel(string strGuid, bool isEdit, int tabIdx) |
| | | private void getModel(string strGuid, bool isEdit, int tabIdx) |
| | | { |
| | | if (string.IsNullOrEmpty(strGuid)) |
| | | { |
| | |
| | | ToolBox.MsgHelper.Warning("提示:" + ex.Message); |
| | | } |
| | | } |
| | | private void GetTree(string rolueGuid) |
| | | private void getTree(string roleGuid) |
| | | { |
| | | trv.Nodes.Clear(); |
| | | ImageList imageList = new ImageList(); |
| | |
| | | trv.ImageList = imageList; |
| | | var _obj = new |
| | | { |
| | | rolueGuid = rolueGuid,//主建 |
| | | roleGuid = roleGuid,//主建 |
| | | }; |
| | | string strReturn = ""; |
| | | try |
| | | { |
| | | strReturn = UtilityHelper.HttpPost("", "MenuAction/GetListPageByOrg", JsonConvert.SerializeObject(_obj)); |
| | | strReturn = UtilityHelper.HttpPost("", "MenuAction/GetListByRole", JsonConvert.SerializeObject(_obj)); |
| | | ReturnModel<PageListModel> dd = UtilityHelper.GetTableByJson(strReturn); |
| | | DataTable dt = dd.rtnData.list; |
| | | DataRow[] drGrp = dt.Select("upGuid='' or upGuid is null"); |
| | |
| | | node.Text = _dy["name"].ToString();//为结点赋值 |
| | | node.Name = _dy["guid"].ToString(); |
| | | node.ImageIndex = 0; |
| | | node.Checked = (_dy["isCk"].ToString() == "1" ? true : false); |
| | | DataRow[] drItem = dt.Select("upGuid='" + _dy["guid"].ToString() + "' and orgGuid='" + _dy["guid"].ToString() + "'"); |
| | | foreach (DataRow _dy2 in drItem) |
| | | { |
| | |
| | | node22.Text = _dy2["name"].ToString();//为结点赋值 |
| | | node22.Name = _orgGuid + _dy2["guid"].ToString(); |
| | | node22.ImageIndex = 1; |
| | | node22.Checked = (_dy2["isCk"].ToString() == "1" ? true : false); |
| | | DataRow[] drItem33 = dt.Select("upGuid='" + _dy2["guid"].ToString() + "' and orgGuid='" + _dy["guid"].ToString() + "'"); |
| | | foreach (DataRow _dy3 in drItem33) |
| | | { |
| | |
| | | node33.Text = _dy3["name"].ToString();//为结点赋值 |
| | | node33.Name = _orgGuid + _dy3["guid"].ToString(); |
| | | node33.ImageIndex = 2; |
| | | node33.Checked = (_dy3["isCk"].ToString() == "1" ? true : false); |
| | | DataRow[] drItem44 = dt.Select("upGuid='" + _dy3["guid"].ToString() + "' and orgGuid='" + _dy["guid"].ToString() + "'"); |
| | | foreach (DataRow _dy4 in drItem44) |
| | | { |
| | |
| | | node44.Text = _dy4["name"].ToString();//为结点赋值 |
| | | node44.Name = _orgGuid + _dy4["guid"].ToString(); |
| | | node44.ImageIndex = 3; |
| | | node44.Checked = (_dy4["isCk"].ToString() == "1" ? true : false); |
| | | node33.Nodes.Add(node44); |
| | | } |
| | | node22.Nodes.Add(node33); |
| | |
| | | foreach (TreeNode node in nodes) |
| | | { |
| | | if (node.Checked) |
| | | sbRolist.Append(node.Name + "~"); |
| | | actionLst.Append(node.Name + "~"); |
| | | // 递归遍历子节点 |
| | | if (node.Nodes.Count > 0) |
| | | { |