/// <summary> /// 新增角色。 /// </summary> /// <param name="dataset">包含角色数据的数据集对象。</param> /// <returns>包含执行结果的数据集对象。</returns> public DataSet AddRole(DataSet dsParams) { DataSet dsReturn = new DataSet(); string sql = ""; DbConnection dbconn = null; DbTransaction dbtran = null; try { dbconn = db.CreateConnection(); dbconn.Open(); //Create Transaction dbtran = dbconn.BeginTransaction(); RBAC_ROLE_FIELDS roleFields = new RBAC_ROLE_FIELDS(); if (null != dsParams && dsParams.Tables.Contains(RBAC_ROLE_FIELDS.DATABASE_TABLE_NAME)) { DataTable dataTable = dsParams.Tables[RBAC_ROLE_FIELDS.DATABASE_TABLE_NAME]; Hashtable hashData = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dataTable); string roleName = Convert.ToString(hashData[RBAC_ROLE_FIELDS.FIELD_ROLE_NAME]); sql = "SELECT COUNT(*) FROM RBAC_ROLE WHERE ROLE_NAME ='" + roleName.PreventSQLInjection() + "'"; int count = Convert.ToInt32(db.ExecuteScalar(CommandType.Text, sql)); if (count > 0) { FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:FanHai.Hemera.Modules.RBAC.RoleEngine.RollAlreadyExist}"); } else { hashData.Add(RBAC_ROLE_FIELDS.FIELD_CREATE_TIME, null); sql = DatabaseTable.BuildInsertSqlStatement(roleFields, hashData, null); db.ExecuteNonQuery(dbtran, CommandType.Text, sql); dbtran.Commit(); FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty); } } } catch (Exception ex) { dbtran.Rollback(); FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message); LogService.LogError("AddRole Error: " + ex.Message); } finally { if (dbtran != null) { dbtran = null; } //Close Connection if (dbconn != null) { dbconn.Close(); dbconn = null; } } return(dsReturn); }
/// <summary> /// 更新角色。 /// </summary> /// <param name="dsParams">包含角色数据的数据集对象。</param> /// <returns>包含执行结果的数据集对象。</returns> public DataSet UpdateRole(DataSet dsParams) { DataSet dsReturn = new DataSet(); DbConnection dbconn = null; DbTransaction dbtran = null; string sql = ""; try { dbconn = db.CreateConnection(); dbconn.Open(); //Create Transaction dbtran = dbconn.BeginTransaction(); RBAC_ROLE_FIELDS roleFields = new RBAC_ROLE_FIELDS(); if (null != dsParams && dsParams.Tables.Contains(RBAC_ROLE_FIELDS.DATABASE_TABLE_NAME)) { DataTable dataTable = dsParams.Tables[RBAC_ROLE_FIELDS.DATABASE_TABLE_NAME]; Hashtable hashData = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dataTable); hashData.Add(RBAC_ROLE_FIELDS.FIELD_EDIT_TIME, null); string roleKey = Convert.ToString(hashData[RBAC_ROLE_FIELDS.FIELD_ROLE_KEY]); WhereConditions wc = new WhereConditions(RBAC_ROLE_FIELDS.FIELD_ROLE_KEY, roleKey); hashData.Remove(RBAC_ROLE_FIELDS.FIELD_ROLE_KEY); sql = DatabaseTable.BuildUpdateSqlStatement(roleFields, hashData, wc); db.ExecuteNonQuery(dbtran, CommandType.Text, sql); dbtran.Commit(); } FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, string.Empty); } catch (Exception ex) { dbtran.Rollback(); FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, ex.Message); LogService.LogError("UpdateRole Error: " + ex.Message); } finally { if (dbtran != null) { dbtran = null; } //Close Connection if (dbconn != null) { dbconn.Close(); dbconn = null; } } return(dsReturn); }