Example #1
0
 /// <summary>
 /// 新增UserGroup对象
 /// </summary>
 /// <param name="UserGroup">需要新增的对象</param>
 /// <returns>新插入数据的GroupID</returns>
 public Int32 AddUserGroup(UserGroup obj)
 {
     if(obj != null)
     {
         return Convert.ToInt32(_dal.InsertReturnID(obj));
     }
     return -1;
 }
Example #2
0
        /// <summary>
        /// 插入一条数据并返回GroupID
        /// </summary>
        /// <param name="UserGroup">需要插入的对象</param>
        /// <returns>新插入数据的GroupID</returns>
        public Object InsertReturnID(UserGroup obj)
        {
            //声明参数数组并赋值
            SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@GroupName",obj.GroupName),
                new SqlParameter("@ParentID",obj.ParentID),
                new SqlParameter("@Sort",obj.Sort),
                new SqlParameter("@AddTime",obj.AddTime),
                new SqlParameter("@Status",obj.Status)
            };

            return SqlHelper.ExecuteScalar(SqlHelper.connectionString, _SQL_INSERT_RETURNID, CommandType.Text, param);
        }
Example #3
0
        /// <summary>
        /// 插入一条数据
        /// </summary>
        /// <param name="UserGroup">需要插入的对象</param>
        /// <returns>影响行数</returns>
        public Int32 Insert(UserGroup obj)
        {
            //声明参数数组并赋值
            SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@GroupName",obj.GroupName),
                new SqlParameter("@ParentID",obj.ParentID),
                new SqlParameter("@Sort",obj.Sort),
                new SqlParameter("@AddTime",obj.AddTime),
                new SqlParameter("@Status",obj.Status)
            };

            return SqlHelper.ExecuteNonQuery(SqlHelper.connectionString, _SQL_INSERT, CommandType.Text, param);
        }
Example #4
0
        /// <summary>
        /// 将SqlDataReader对象转换成UserGroup对象
        /// </summary>
        /// <param name="dr">SqlDataReader对象</param>
        /// <returns></returns>
        private UserGroup ToObject(SqlDataReader dr)
        {
            using (dr)
            {
                if (dr.HasRows)
                {
                    while (dr.Read())
                    {
                        UserGroup model = new UserGroup();
                        model.GroupID = Convert.ToInt32(dr["GroupID"]);
                        model.GroupName = dr["GroupName"].ToString();
                        model.ParentID = Convert.ToInt32(dr["ParentID"]);
                        model.Sort = Convert.ToByte(dr["Sort"]);
                        model.AddTime = Convert.ToDateTime(dr["AddTime"]);
                        model.Status = Convert.ToByte(dr["Status"]);

                        return model;
                    }
                }
            }
            return null;
        }
Example #5
0
        /// <summary>
        /// 将SqlDataReader对象转换成UserGroup对象集合
        /// </summary>
        /// <param name="dr">SqlDataReader对象</param>
        /// <returns></returns>
        private List<UserGroup> ToList(SqlDataReader dr)
        {
            List<UserGroup> list = null;
            using (dr)
            {
                if (dr.HasRows)
                {
                    list = new List<UserGroup>();
                    while (dr.Read())
                    {
                        UserGroup model = new UserGroup();
                        model.GroupID = Convert.ToInt32(dr["GroupID"]);
                        model.GroupName = dr["GroupName"].ToString();
                        model.ParentID = Convert.ToInt32(dr["ParentID"]);
                        model.Sort = Convert.ToByte(dr["Sort"]);
                        model.AddTime = Convert.ToDateTime(dr["AddTime"]);
                        model.Status = Convert.ToByte(dr["Status"]);

                        list.Add(model);
                    }
                }
            }
            return list;
        }
Example #6
0
        /// <summary>
        /// 更新一条新数据。
        /// </summary>
        /// <param name="UserGroup">需要更新的对象</param>
        /// <returns>影响行数</returns>
        public Int32 Update(UserGroup obj)
        {
            //将WHERE条件组合进SQL语句
            String sqlStr = String.Format(_SQL_UPDATE, "WHERE [GroupID] = @GroupID");
            //声明参数数组并赋值
            SqlParameter[] param = new SqlParameter[]{
                new SqlParameter("@GroupID",obj.GroupID),
                new SqlParameter("@GroupName",obj.GroupName),
                new SqlParameter("@ParentID",obj.ParentID),
                new SqlParameter("@Sort",obj.Sort),
                new SqlParameter("@AddTime",obj.AddTime),
                new SqlParameter("@Status",obj.Status)
            };

            return SqlHelper.ExecuteNonQuery(SqlHelper.connectionString, sqlStr, CommandType.Text, param);
        }
Example #7
0
 /// <summary>
 /// 修改UserGroup对象
 /// </summary>
 /// <param name="UserGroup">需要修改的对象</param>
 /// <returns>影响行数</returns>
 public Int32 SetUserGroup(UserGroup obj)
 {
     if(obj != null)
     {
         return _dal.Update(obj);
     }
     return -1;
 }