示例#1
0
        public static UserState AddUserState(UserState userState)
        {
            string sql =
                "INSERT UserStates (Name)" +
                "VALUES (@Name)";

            sql += " ; SELECT @@IDENTITY";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@Name", userState.Name)
                };

                int newId = DBHelper.GetScalar(sql, para);
                return GetUserStateById(newId);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
        }
示例#2
0
 public static void ModifyUserState(UserState userState)
 {
     UserStateService.ModifyUserState(userState);
 }
示例#3
0
 public static void DeleteUserState(UserState userState)
 {
     UserStateService.DeleteUserState(userState);
 }
示例#4
0
 public static UserState AddUserState(UserState userState)
 {
     return UserStateService.AddUserState(userState);
 }
示例#5
0
        public static UserState GetUserStateById(int id)
        {
            string sql = "SELECT * FROM UserStates WHERE Id = @Id";

            try
            {
                SqlDataReader reader = DBHelper.GetReader(sql, new SqlParameter("@Id", id));
                if (reader.Read())
                {
                    UserState userState = new UserState();

                    userState.Id = (int)reader["Id"];
                    userState.Name = (string)reader["Name"];

                    reader.Close();

                    return userState;
                }
                else
                {
                    reader.Close();
                    return null;
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
        }
示例#6
0
 public static void DeleteUserState(UserState userState)
 {
     DeleteUserStateById(userState.Id);
 }
示例#7
0
        private static IList<UserState> GetUserStatesBySql(string sql, params SqlParameter[] values)
        {
            List<UserState> list = new List<UserState>();

            try
            {
                DataTable table = DBHelper.GetDataSet(sql, values);

                foreach (DataRow row in table.Rows)
                {
                    UserState userState = new UserState();

                    userState.Id = (int)row["Id"];
                    userState.Name = (string)row["Name"];

                    list.Add(userState);
                }

                return list;
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                return null;
            }
        }
示例#8
0
        public static void ModifyUserState(UserState userState)
        {
            string sql =
                "UPDATE UserStates " +
                "SET " +
                    "Name = @Name " +
                "WHERE Id = @Id";

            try
            {
                SqlParameter[] para = new SqlParameter[]
                {
                    new SqlParameter("@Id", userState.Id),
                    new SqlParameter("@Name", userState.Name)
                };

                DBHelper.ExecuteCommand(sql, para);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
                throw e;
            }
        }