Ejemplo n.º 1
0
        /// <summary>
        /// 更新用户。
        /// </summary>
        /// <param name="dsParams">包含用户信息的数据集对象。</param>
        /// <returns>包含执行结果的数据集对象。</returns>
        public DataSet UpdateUser(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();
                if (dsParams.Tables.Contains(RBAC_USER_FIELDS.DATABASE_TABLE_NAME))
                {
                    RBAC_USER_FIELDS userFields = new RBAC_USER_FIELDS();
                    DataTable        dataTable  = dsParams.Tables[RBAC_USER_FIELDS.DATABASE_TABLE_NAME];
                    Hashtable        hashData   = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dataTable);
                    hashData.Add(RBAC_USER_FIELDS.FIELD_EDIT_TIME, null);
                    WhereConditions wc = new WhereConditions(RBAC_USER_FIELDS.FIELD_USER_KEY, hashData[RBAC_USER_FIELDS.FIELD_USER_KEY].ToString());
                    hashData.Remove(RBAC_USER_FIELDS.FIELD_USER_KEY);
                    sql = DatabaseTable.BuildUpdateSqlStatement(userFields, 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("UpdateUser Error: " + ex.Message);
            }
            finally
            {
                //Close Connection
                dbconn.Close();
                dbtran = null;
                dbconn = null;
            }
            return(dsReturn);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="dsParams">包含用户信息的数据集对象。</param>
        /// <returns>包含执行结果的数据集对象。</returns>
        public DataSet AddUser(DataSet dsParams)
        {
            DataSet       dsReturn = new DataSet();
            string        sql      = string.Empty;
            DbConnection  dbconn   = null;
            DbTransaction dbtran   = null;

            try
            {
                dbconn = db.CreateConnection();
                dbconn.Open();
                //Create Transaction
                dbtran = dbconn.BeginTransaction();
                RBAC_USER_FIELDS userFields = new RBAC_USER_FIELDS();
                if (dsParams.Tables.Contains(RBAC_USER_FIELDS.DATABASE_TABLE_NAME))
                {
                    DataTable dataTable = dsParams.Tables[RBAC_USER_FIELDS.DATABASE_TABLE_NAME];
                    Hashtable hashData  = FanHai.Hemera.Share.Common.CommonUtils.ConvertToHashtable(dataTable);
                    string    userName  = hashData[RBAC_USER_FIELDS.FIELD_BADGE].ToString();
                    sql = "SELECT * FROM RBAC_USER WHERE BADGE='" + userName.PreventSQLInjection() + "'";
                    IDataReader read = db.ExecuteReader(CommandType.Text, sql);
                    try
                    {
                        if (read.Read())
                        {
                            FanHai.Hemera.Share.Common.ReturnMessageUtils.AddServerReturnMessage(dsReturn, "${res:FanHai.Hemera.Modules.RBAC.UserEngine.UserAlreadyExist}");
                            return(dsReturn);
                        }
                    }
                    finally
                    {
                        read.Close();
                        read.Dispose();
                        read = null;
                    }

                    hashData.Add(RBAC_USER_FIELDS.FIELD_CREATE_TIME, null);
                    hashData.Add(RBAC_USER_FIELDS.FIELD_IS_ACTIVE, "1");
                    hashData.Add(RBAC_USER_FIELDS.FIELD_IS_APPROVED, "0");
                    hashData.Add(RBAC_USER_FIELDS.FIELD_IS_LOCKED_OUT, "0");
                    hashData.Add(RBAC_USER_FIELDS.FIELD_EDITOR, hashData[RBAC_USER_FIELDS.FIELD_CREATOR].ToString());
                    hashData.Add(RBAC_USER_FIELDS.FIELD_EDIT_TIME, null);
                    sql = DatabaseTable.BuildInsertSqlStatement(userFields, 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("AddUser Error: " + ex.Message);
            }
            finally
            {
                //Close Connection
                dbconn.Close();
                dbtran = null;
                dbconn = null;
            }
            return(dsReturn);
        }