/// <summary> /// 新增UserCookie对象 /// </summary> /// <param name="UserCookie">需要新增的对象</param> /// <returns>新插入数据的ID</returns> public Int64 AddUserCookie(UserCookie obj) { if(obj != null) { return Convert.ToInt32(_dal.InsertReturnID(obj)); } return -1; }
/// <summary> /// 插入一条数据并返回ID /// </summary> /// <param name="UserCookie">需要插入的对象</param> /// <returns>新插入数据的ID</returns> public Object InsertReturnID(UserCookie obj) { //声明参数数组并赋值 SqlParameter[] param = new SqlParameter[]{ new SqlParameter("@UserID",obj.UserID), new SqlParameter("@HostName",obj.HostName), new SqlParameter("@HostAddress",obj.HostAddress), new SqlParameter("@Password",obj.Password), new SqlParameter("@AddTime",obj.AddTime) }; return SqlHelper.ExecuteScalar(SqlHelper.connectionString, _SQL_INSERT_RETURNID, CommandType.Text, param); }
/// <summary> /// 插入一条数据 /// </summary> /// <param name="UserCookie">需要插入的对象</param> /// <returns>影响行数</returns> public Int32 Insert(UserCookie obj) { //声明参数数组并赋值 SqlParameter[] param = new SqlParameter[]{ new SqlParameter("@UserID",obj.UserID), new SqlParameter("@HostName",obj.HostName), new SqlParameter("@HostAddress",obj.HostAddress), new SqlParameter("@Password",obj.Password), new SqlParameter("@AddTime",obj.AddTime) }; return SqlHelper.ExecuteNonQuery(SqlHelper.connectionString, _SQL_INSERT, CommandType.Text, param); }
/// <summary> /// 将SqlDataReader对象转换成UserCookie对象 /// </summary> /// <param name="dr">SqlDataReader对象</param> /// <returns></returns> private UserCookie ToObject(SqlDataReader dr) { using (dr) { if (dr.HasRows) { while (dr.Read()) { UserCookie model = new UserCookie(); model.ID = Convert.ToInt64(dr["ID"]); model.UserID = Convert.ToInt32(dr["UserID"]); model.HostName = dr["HostName"].ToString(); model.HostAddress = dr["HostAddress"].ToString(); model.Password = dr["Password"].ToString(); model.AddTime = Convert.ToDateTime(dr["AddTime"]); return model; } } } return null; }
/// <summary> /// 将SqlDataReader对象转换成UserCookie对象集合 /// </summary> /// <param name="dr">SqlDataReader对象</param> /// <returns></returns> private List<UserCookie> ToList(SqlDataReader dr) { List<UserCookie> list = null; using (dr) { if (dr.HasRows) { list = new List<UserCookie>(); while (dr.Read()) { UserCookie model = new UserCookie(); model.ID = Convert.ToInt64(dr["ID"]); model.UserID = Convert.ToInt32(dr["UserID"]); model.HostName = dr["HostName"].ToString(); model.HostAddress = dr["HostAddress"].ToString(); model.Password = dr["Password"].ToString(); model.AddTime = Convert.ToDateTime(dr["AddTime"]); list.Add(model); } } } return list; }
/// <summary> /// 更新一条新数据。 /// </summary> /// <param name="UserCookie">需要更新的对象</param> /// <returns>影响行数</returns> public Int32 Update(UserCookie obj) { //将WHERE条件组合进SQL语句 String sqlStr = String.Format(_SQL_UPDATE, "WHERE [ID] = @ID"); //声明参数数组并赋值 SqlParameter[] param = new SqlParameter[]{ new SqlParameter("@ID",obj.ID), new SqlParameter("@UserID",obj.UserID), new SqlParameter("@HostName",obj.HostName), new SqlParameter("@HostAddress",obj.HostAddress), new SqlParameter("@Password",obj.Password), new SqlParameter("@AddTime",obj.AddTime) }; return SqlHelper.ExecuteNonQuery(SqlHelper.connectionString, sqlStr, CommandType.Text, param); }
/// <summary> /// 修改UserCookie对象 /// </summary> /// <param name="UserCookie">需要修改的对象</param> /// <returns>影响行数</returns> public Int32 SetUserCookie(UserCookie obj) { if(obj != null) { return _dal.Update(obj); } return -1; }