#region using System; using System.Data; using System.Windows.Forms; using CSFrameworkV5.Business; using CSFrameworkV5.Business.BLL_Permission; using CSFrameworkV5.Common; using CSFrameworkV5.Core; using CSFrameworkV5.Library.CommonClass; using CSFrameworkV5.Models; #endregion namespace CSFrameworkV5.Library.PermissionForms { public partial class frmRole : frmBaseDataForm { private bllRole _BLL; private bllPermission _Permission; //角色管理业务逻辑 private RoleActionsView _RoleActionsView; private DataTable tbBM; //条码表 public frmRole() { InitializeComponent(); } private void btnEmpty_Click(object sender, EventArgs e) { txt_RoleType.Text = ""; txt_Content.Text = ""; } private void btnQuery_Click(object sender, EventArgs e) { try { frmWaitingEx.ShowMe(this); var roleType = txt_RoleType.Text == "<全部>" ? "" : txt_RoleType.Text; var dt = _BLL.Query(roleType, txt_Content .Text); //调用业务逻辑类的GetSummaryData()方法获取数据 DoBindingSummaryGrid(dt); //绑定主表的Grid } finally { frmWaitingEx.HideMe(this); } } protected override void ButtonStateChanged(UpdateType currentState) { base.ButtonStateChanged(currentState); SetDetailEditorsAccessable(_DetailGroupControl, DataChanged); //仅新增状态可修改主键输入框 if (_KeyEditor != null) _KeyEditor.Enabled = UpdateType.Add == currentState; var editMode = currentState == UpdateType.Add || currentState == UpdateType.Modify; _RoleActionsView.OnViewMode = !editMode; //查看模式禁止操作树视图 txtRoleID.Enabled = currentState == UpdateType.Add; } public override void DoAdd(IButtonInfo sender) { _BLL.CreateDataBinder(null); InitTreeView(); //初始化树视图。 _RoleActionsView.CurrentRoleID = ""; //当前角号编号 _RoleActionsView.ShowRoleActions(); DoBindingSummaryEditor(_BLL.DataBinder); //绑定数据输入控件 SetEditorBindingValue(txtRoleType, "普通角色", true); base.DoAdd(sender); ShowDetailPage(true); } /// /// 绑定输入框 /// /// protected void DoBindingSummaryEditor(DataTable summary) { DataBinder.BindingEditorPanel(gcDetailEditor, summary); } public override void DoCancel(IButtonInfo sender) { if (Msg.AskQuestion("要取消修改吗?")) base.DoCancel(sender); } public override void DoDelete(IButtonInfo sender) { AssertFocusedRow(); //检查是否选择一条记录 //调用业务逻辑类删除记录 var summary = _SummaryView.GetDataRow(_SummaryView.FocusedRowHandle); var key = summary[tb_MyRole.RoleID].ToStringEx(); //主键值 var roleType = summary[tb_MyRole.RoleType].ToStringEx(); //主键值 if (roleType == "系统角色") throw new Exception("不可删除系统角色!"); if (!Msg.AskQuestion("确定要删除?")) return; var b = _BLL.Delete(key); AssertEqual(b, true, "删除记录时发生错误!"); base.DoDelete(sender); DeleteSummaryRow(_SummaryView.FocusedRowHandle); //删除Summary资料行 if (_SummaryView.FocusedRowHandle < 0) //删除了最後一条记录. 显示Summary页面. ShowSummaryPage(true); else DoViewContent(_buttons.GetButtonByName(ButtonNameList.btnView)); } public override void DoEdit(IButtonInfo sender) { AssertFocusedRow(); var roleType = ConvertEx.ToString( gvSummary.GetFocusedDataRow()[tb_MyRole.RoleType].ToStringEx()); if (roleType == "系统角色") throw new Exception("系统角色不可修改!"); { base.DoEdit(sender); DoViewContent(sender); ShowDetailPage(true); } } public override void DoSave(IButtonInfo sender) { UpdateLastControl(); //更新最后一个输入控件的数据 if (!ValidatingData()) return; //检查输入完整性 var changes = _RoleActionsView.GetChanges(); var roleUsers = gcRoleUsers.DataSource as DataTable; //调用业务逻辑层的Update方法提交数据 //bool ret = _BLL.Update(_UpdateType, _RoleActionsView.RoleActionData); var ret = _BLL.Update(_UpdateType, changes, roleUsers); if (ret) { UpdateSummaryRow(_BLL.DataBinder.Rows[0]); //刷新表格内的数据. base.DoSave(sender); Msg.ShowInformation("保存成功!"); } else { Msg.Warning("保存失败!"); } } public override void DoViewContent(IButtonInfo sender) { AssertFocusedRow(); //检查有无记录. var page = tcBusiness.SelectedTabPage; var roleID = ConvertEx.ToString(gvSummary.GetFocusedRowCellValue(colRoleID)); InitTreeView(); //初始化树视图。 _BLL.CreateDataBinder( _SummaryView.GetDataRow(_SummaryView.FocusedRowHandle)); _RoleActionsView.CurrentRoleID = roleID; //当前角号编号 _RoleActionsView.ShowRoleActions(); //显示角色的权限 base.DoViewContent(sender); DoBindingSummaryEditor(_BLL.DataBinder); //绑定数据输入控件 var ds = _BLL.GetRoleOwners(roleID); gcMyGroups.DataSource = ds.Tables[tb_MyGroup.__TableName]; gcMyUser.DataSource = ds.Tables[tb_MyUser.__TableName]; gcRoleUsers.DataSource = ds.Tables[tb_MyUserRoles.__TableName]; ShowDetailPage(false); //用户点击ViewContent按钮可以显示Summary页 xtraTabControl1.SelectedTabPageIndex = 0; } private void frmRole_Load(object sender, EventArgs e) { InitializeForm(); SetLanguage(); } protected override void InitializeForm() { try { base.InitializeForm(); _SummaryView = new DevGridView(gvSummary); var sqlstr = "SELECT BM002 部门编号,BM003 部门名称 FROM GS_BM "; _ActiveEditor = txtRoleID; _DetailGroupControl = gcDetailEditor; gvSummary.DoubleClick += OnGridViewDoubleClick; //主表DoubleClict frmGridCustomize.RegisterGrid(gvSummary); DevStyle.SetGridControlLayout(gcSummary, false); //表格设置 DevStyle.SetSummaryGridViewLayout(gvSummary); _BLL = new bllRole(); _Permission = new bllPermission(); _RoleActionsView = new RoleActionsView(tvRoleActions); tbBM = _BLL.GETDAT(sqlstr); txtRoleID.Properties.ValueMember = "部门名称"; txtRoleID.Properties.DisplayMember = "部门名称"; //txtRoleID.Properties.SH = false; txtRoleID.Properties.DataSource = tbBM; ShowSummary(); //下载显示数据. DataBinder.BindingLookupEditDataSource(lookUser, DataDictCache.Cache.User, tb_MyUser.UserName, tb_MyUser.Account); BindingSummaryNavigator(controlNavigatorSummary, gcSummary); //Summary导航条. ShowSummaryPage(true); //一切初始化完毕後显示SummaryPage } catch (Exception ex) { Msg.ShowException(ex); } } private void InitTreeView() { if (_RoleActionsView.IsCreatedTree == false) { //下载生成树相关的基础资料 _RoleActionsView.RoleData = _Permission.GetRoleData(); _RoleActionsView.ActionsData = _Permission.GetActionData(); _RoleActionsView.ActionCustomNameData = _Permission.GetFormTagCustomName(); //管理员取全部菜单数据 if (Loginer.CurrentUser.IsAdmin()) _RoleActionsView.MenuData = _Permission.GetMenuData(); else //取当前用户的菜单数据 _RoleActionsView.MenuData = _Permission.GetMenuByUser(Loginer.CurrentUser.Account, Loginer.CurrentUser.DBID); _RoleActionsView.InitTree(""); //创建树视图 } _RoleActionsView.OnViewMode = false; } private void menuCollase_Click(object sender, EventArgs e) { if (tvRoleActions.SelectedNode != null) tvRoleActions.SelectedNode.Collapse(); } private void menuExpand_Click(object sender, EventArgs e) { if (tvRoleActions.SelectedNode != null) tvRoleActions.SelectedNode.ExpandAll(); } private void ShowSummary() { try { _BLL.GetSummaryData( true); //调用业务逻辑类的GetSummaryData()方法获取数据 DoBindingSummaryGrid(_BLL.SummaryTable); //绑定主表的Grid ShowSummaryPage(true); //显示Summary页面. } catch (Exception ex) { Msg.ShowException(ex); } } private void tvRoleActions_MouseDown(object sender, MouseEventArgs e) { //在角色的权限树按下鼠标键,选择结点,设置高亮状态 var info = tvRoleActions.HitTest(e.Location); tvRoleActions.SelectedNode = info.Node; } private bool ValidatingData() { if (txtRoleID.Text == string.Empty) { Msg.Warning("编号不能为空!"); txtRoleID.Focus(); return false; } if (txtRoleName.Text == string.Empty) { Msg.Warning("名称不能为空!"); txtRoleName.Focus(); return false; } if (_UpdateType == UpdateType.Add) if (_BLL.IsExists(txtRoleID.Text)) { Msg.Warning("编号已存在!"); txtRoleID.Focus(); return false; } return true; } } }