public void DeleteRole(RoleData role) { try { } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "DeleteRole.\r\n{0}", ex.ToString()); } }
public RoleTileControl( bool isNewRole,RoleData roleData,RoleData allPermissions, Action<bool,RoleData> RoleMangerFunction,Action<RoleData> DeleteRole) { InitializeComponent(); this._RoleData = roleData; this._AddNewRole = RoleMangerFunction; this._DeleteRole = DeleteRole; this._AllPermissions = allPermissions; this._isNewRole = isNewRole; if (isNewRole) { Edit_Click(null, null); this.Delete.Visibility = System.Windows.Visibility.Hidden; } else { this.RoleName.Text = roleData.RoleName; } }
public RoleGridData(RoleData role, bool isAllowAdd, bool isAllowDelete, bool isAllowEdit) { RoleId = role.RoleId; RoleName = role.RoleName; IsAllowAdd = isAllowAdd; IsAllowDelete = isAllowDelete; IsAllowEdit = isAllowEdit; }
public static List<UserData> GetUserData() { List<UserData> data = new List<UserData>(); using (SqlConnection sqlConnection = DataAccess.GetInstance().GetSqlConnection()) { SqlCommand command = sqlConnection.CreateCommand(); command.CommandText = "SELECT u.Id,u.[Name] FROM dbo.Users u SELECT uir.UserId,uir.RoleId,r.RoleName FROM dbo.UserInRole uir INNER JOIN dbo.Roles r ON r.Id = uir.RoleId"; command.CommandType = System.Data.CommandType.Text; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { UserData user = new UserData(); user.UserId = (Guid)reader["Id"]; user.UserName = reader["Name"].ToString(); data.Add(user); } reader.NextResult(); while (reader.Read()) { RoleData role = new RoleData(); role.RoleId = (int)reader["RoleId"]; role.RoleName = reader["RoleName"].ToString(); data.Find(u=>u.UserId==(Guid)reader["UserId"]).Roles.Add(role); } } return data; }
public static List<RoleData> GetRoles(string language) { List<RoleData> roles = new List<RoleData>(); string sql = "[dbo].[GetAllRoleData]"; DataAccess.GetInstance().ExecuteReader(sql, CommandType.StoredProcedure, delegate(SqlDataReader reader) { while (reader.Read()) { RoleData role = new RoleData(); role.RoleId = (int)reader.GetValue(0); role.RoleName = reader.GetValue(1).ToString(); roles.Add(role); } if (reader.NextResult()) { while (reader.Read()) { RoleFunctonPermission functionPermission = new RoleFunctonPermission(); functionPermission.FunctionId = (int)reader["FunctionId"]; functionPermission.Code = reader["Code"].ToString(); if (!(reader["ParentId"] is DBNull)) { functionPermission.ParentId = (int)reader["ParentId"]; } functionPermission.Level = (int)reader["Level"]; functionPermission.Description = reader["Description"].ToString(); functionPermission.IsAllow = (bool)reader["IsAllow"]; int id = (int)reader["RoleId"]; roles.SingleOrDefault(r => r.RoleId == id).FunctionPermissions.Add(functionPermission); } } if (reader.NextResult()) { while (reader.Read()) { RoleDataPermission dataPermission = new RoleDataPermission(); dataPermission.PermissionId = (int)reader["TargetId"]; dataPermission.Code = reader["Code"].ToString(); if (!(reader["ParentId"] is DBNull)) { dataPermission.ParentId = (int)reader["ParentId"]; } if (!(reader["DataObjectId"] is DBNull)) { dataPermission.DataObjectId = (Guid)reader["DataObjectId"]; } dataPermission.IsAllow = (bool)reader["IsAllow"]; dataPermission.ExchangeCode = reader["IExchangeCode"].ToString(); int id = (int)reader["RoleId"]; roles.SingleOrDefault(r => r.RoleId == id).DataPermissions.Add(dataPermission); } } }, new SqlParameter("@language", language)); return roles; }
public static bool EditRole(RoleData role) { bool isSuccess = false; DataTable permission = new DataTable(); permission.Columns.Add("Id", typeof(int)); permission.Columns.Add("ParentId", typeof(int)); permission.Columns.Add("Level", typeof(int)); permission.Columns.Add("Code", typeof(string)); permission.Columns.Add("ExchangeCode", typeof(string)); permission.Columns.Add("TargetType", typeof(int)); permission.Columns.Add("DataObjectType", typeof(string)); permission.Columns.Add("DataObjectId", typeof(Guid)); permission.Columns.Add("Status", typeof(bool)); foreach (RoleFunctonPermission item in role.FunctionPermissions) { DataRow row = permission.NewRow(); row["Id"] = item.FunctionId; row["ParentId"] = item.ParentId; row["Level"] = item.Level; row["Code"] = item.Code; row["TargetType"] = 1; row["Status"] = item.IsAllow; permission.Rows.Add(row); } foreach (RoleDataPermission item in role.DataPermissions) { DataRow row = permission.NewRow(); row["Id"] = item.PermissionId; row["ParentId"] = item.ParentId; row["Level"] = item.Level; row["Code"] = item.Code; row["DataObjectType"] = item.Type; row["ExchangeCode"] = item.ExchangeCode; row["TargetType"] = 2; row["DataObjectId"] = item.DataObjectId; row["Status"] = item.IsAllow; permission.Rows.Add(row); } using (SqlConnection con = DataAccess.GetInstance().GetSqlConnection()) { using (SqlTransaction transaction = con.BeginTransaction()) { using (SqlCommand command = con.CreateCommand()) { command.CommandText = "[dbo].[Roles_Update]"; command.Transaction = transaction; command.CommandType = CommandType.StoredProcedure; command.Parameters.Add(new SqlParameter("@roleId", role.RoleId)); command.Parameters.Add(new SqlParameter("@roleName", role.RoleName)); SqlParameter parameter = command.Parameters.AddWithValue("@permissionTarget", permission); parameter.SqlDbType = SqlDbType.Structured; parameter.TypeName = "dbo.PermissionTargetType"; command.Parameters.Add(new SqlParameter("@RETURN_VALUE", SqlDbType.Int) { Direction = ParameterDirection.ReturnValue }); command.ExecuteNonQuery(); int returnValue = (int)command.Parameters["@RETURN_VALUE"].Value; isSuccess = (returnValue == 0); if (isSuccess) { transaction.Commit(); } } } } return isSuccess; }
private void Submit_Click(object sender, RoutedEventArgs e) { try { RoleData newRole = new RoleData(); if (!this._FunctionGridDatas.CheckData()) { MessageBox.Show("有部分操作权限没有赋值,请检查后再提交"); return; } if (!this._DataPermissionGridDatas.CheckData()) { MessageBox.Show("有部分数据权限没有赋值,请检查后再提交"); return; } if (string.IsNullOrEmpty(this.RoleName.Text)) { MessageBox.Show("请输入角色名!"); return; } newRole.FunctionPermissions = this._FunctionGridDatas.CastGridDataToFunction(); newRole.DataPermissions = this._DataPermissionGridDatas.CastGridDataToDataPermission(); newRole.RoleId = this._SelectRole.RoleId; this._SelectRole.RoleName = this.RoleName.Text; newRole.RoleName = this._SelectRole.RoleName; this._isNew = false; if (this._roleDatas.SingleOrDefault(r=>r.RoleId==this._SelectRole.RoleId)==null) { this._isNew = true; } this._SelectRole = newRole; ConsoleClient.Instance.UpdateRole(newRole, this._isNew, EditResult); } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "Submit_Click.\r\n{0}", ex.ToString()); } }
private void RoleGrid_CellClicked(object sender, CellClickedEventArgs e) { try { string roleName = e.Cell.Value.ToString(); RoleData role = this._roleDatas.SingleOrDefault(r => r.RoleName == roleName); this._SelectRole = role; this.RoleName.Text = this._SelectRole.RoleName; this.RoleName.IsReadOnly = true; FunctionGridData functionGrid = new FunctionGridData(); functionGrid.CastFunctionToGridData(role.FunctionPermissions, this._AllFunctions); this._FunctionGridDatas = functionGrid; DataPermissionGridData dataPermissionGrid = new DataPermissionGridData(); dataPermissionGrid.CastDataPermissionToGridData(role.DataPermissions, this._AllData); this._DataPermissionGridDatas = dataPermissionGrid; this.FunctionPermission.ItemsSource = this._FunctionGridDatas.CategoryDatas; this.FunctionPermission.EditingSettings.AllowEditing = EditingType.None; this.DataPermission.ItemsSource = this._DataPermissionGridDatas.IExchangeCodes; this.DataPermission.EditingSettings.AllowEditing = EditingType.None; this.Submit.Visibility = System.Windows.Visibility.Hidden; this.Cancel.Visibility = System.Windows.Visibility.Hidden; } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "RoleManager/RoleGrid_CellClicked.\r\n{0}", ex.ToString()); } }
private void EditButton_Click(object sender, RoutedEventArgs e) { try { Button edit = sender as Button; int roleId = (int)edit.Tag; this._SelectRole = this._roleDatas.SingleOrDefault(r => r.RoleId == roleId); this.RoleName.Text = this._SelectRole.RoleName; this.RoleName.IsReadOnly = false; this.Submit.Visibility = System.Windows.Visibility.Visible; this.Cancel.Visibility = System.Windows.Visibility.Visible; this.FunctionPermission.EditingSettings.AllowEditing = EditingType.Hover; this.DataPermission.EditingSettings.AllowEditing = EditingType.Hover; } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "EditButton_Click.\r\n{0}", ex.ToString()); } }
private void DeleteButton_Click(object sender, RoutedEventArgs e) { try { Button btn = sender as Button; int roleId = (int)btn.Tag; if (roleId == 2) { MessageBox.Show(App.MainFrameWindow, "无法删除系统默认角色!", "", MessageBoxButton.OK, MessageBoxImage.Asterisk, MessageBoxResult.OK); return; } this._SelectRole = this._roleDatas.SingleOrDefault(r => r.RoleId == roleId); if (MessageBox.Show(App.MainFrameWindow,string.Format("确认删除{0}角色吗?", this._SelectRole.RoleName), "", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.No) == MessageBoxResult.Yes) { ConsoleClient.Instance.DeleteRole(roleId, DeleteResult); } } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "DeleteButton_Click.\r\n{0}", ex.ToString()); } }
private void AddRole_Click(object sender, RoutedEventArgs e) { try { this._SelectRole = new RoleData(); int id = 0; foreach (RoleData item in this._roleDatas) { if (item.RoleId >= id) { id = item.RoleId + 1; } } this._SelectRole.RoleId = id; this.Submit.Visibility = System.Windows.Visibility.Visible; this.Cancel.Visibility = System.Windows.Visibility.Hidden; this.RoleName.IsReadOnly = false; this.RoleName.Text = string.Empty; FunctionGridData allfunctionData = new FunctionGridData(); allfunctionData.CastFunctionToGridData(new List<RoleFunctonPermission>(), this._AllFunctions); this._FunctionGridDatas = allfunctionData; DataPermissionGridData allDataPermissions = new DataPermissionGridData(); allDataPermissions.CastDataPermissionToGridData(new List<RoleDataPermission>(), this._AllData); this._DataPermissionGridDatas = allDataPermissions; this.FunctionPermission.ItemsSource = this._FunctionGridDatas.CategoryDatas; this.DataPermission.ItemsSource = this._DataPermissionGridDatas.IExchangeCodes; this.FunctionPermission.EditingSettings.AllowEditing = EditingType.Hover; this.DataPermission.EditingSettings.AllowEditing = EditingType.Hover; } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "AddRole_Click.\r\n{0}", ex.ToString()); } }
private void AddNewRole(bool result,RoleData role) { try { } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "AddNewRole.\r\n{0}", ex.ToString()); } }
public static List<RoleData> GetRoles() { List<RoleData> roles = new List<RoleData>(); using (SqlConnection sqlConnection = DataAccess.GetSqlConnection()) { SqlCommand command = sqlConnection.CreateCommand(); command.CommandText = "SELECT r.Id,r.RoleName FROM dbo.Roles r"; command.CommandType = System.Data.CommandType.Text; SqlDataReader reader = command.ExecuteReader(); while (reader.Read()) { RoleData role = new RoleData(); role.RoleId = (int)reader.GetValue(0); role.RoleName = reader.GetValue(1).ToString(); roles.Add(role); } } return roles; }
public void UpdateRole(RoleData role, bool isNewRole, Action<bool> endUpdateRole) { this._ServiceProxy.BeginUpdateRole(role, isNewRole, delegate(IAsyncResult ar) { bool isSuccess = this._ServiceProxy.EndUpdateRole(ar); endUpdateRole(isSuccess); }, null); }
private void Submit_Click(object sender, RoutedEventArgs e) { try { if (this._EditType != 0) { RoleData newRole = new RoleData(); if (this._EditType > 1) { if (!this._isNewRole) { newRole.RoleId = this._RoleData.RoleId; } foreach (XamDataTreeNode category in this.AccessTree.Nodes) { CategoryNode categoryNode = (CategoryNode)category.Data; categoryNode.ModuleNodes.Clear(); foreach (XamDataTreeNode module in category.Nodes) { ModuleNode moduleNode = (ModuleNode)module.Data; moduleNode.OperationNodes.Clear(); foreach (XamDataTreeNode operation in module.Nodes) { if ((bool)operation.IsChecked) { AccessPermission access = new AccessPermission(); access.CategotyType = categoryNode.CategoryType; access.ModuleType = moduleNode.Type; OperationNode operationNode = (OperationNode)operation.Data; access.OperationId = operationNode.Id; access.OperationName = operationNode.OperationDescription; newRole.AccessPermissions.Add(access); } } } } foreach (XamDataTreeNode systemNode in this.DataTree.Nodes) { ExchangeSystemNode system = (ExchangeSystemNode)systemNode.Data; foreach (XamDataTreeNode typeNode in systemNode.Nodes) { DataObjectTypeNode dataType = (DataObjectTypeNode)typeNode.Data; foreach (XamDataTreeNode dataNode in typeNode.Nodes) { if ((bool)dataNode.IsChecked) { DataPermission dataPermission = new DataPermission(); dataPermission.ExchangeSystemCode = system.ExChangeCode; dataPermission.DataObjectType = dataType.Type; DataObjectNode data = (DataObjectNode)dataNode.Data; dataPermission.DataObjectId = data.DataObjectId; dataPermission.DataObjectDescription = data.Decription; newRole.DataPermissions.Add(dataPermission); } } } } } if (this._EditType % 2 == 1) { newRole.RoleName = this.RoleName.Text; } this._RoleData = newRole; if (CheckNewRole(newRole)) { ConsoleClient.Instance.UpdateRole(newRole, this._isNewRole, EditResult); } } } catch (Exception ex) { Logger.TraceEvent(System.Diagnostics.TraceEventType.Error, "Submit_Click.\r\n{0}", ex.ToString()); } //ConsoleClient.Instance.UpdateRolePermission(this._roleId, this._EditType, this.RoleName.Text, this._NewAccessTree, this._NewDataTree, EditResult); }
private bool CheckNewRole(RoleData role) { if (this._isNewRole) { if (string.IsNullOrEmpty(role.RoleName)) { return false; } if (role.AccessPermissions.Count == 0) { return false; } if (role.DataPermissions.Count == 0) { return false; } } return true; }