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