/// <summary> /// 增加一条数据 /// </summary> public int Add(RentPersonEntity model) { try { return(RentPersonDb.Instance.Add(model)); } catch (Exception ex) { WriteLog.WriteError(ex); throw ex; } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(RentPersonEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update sns_rentPerson set "); strSql.Append("UserId=@UserId,"); strSql.Append("RId=@RId,"); strSql.Append("AddTime=@AddTime,"); strSql.Append("Address=@Address,"); strSql.Append("Examine=@Examine,"); strSql.Append("Status=@Status"); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@RId", SqlDbType.VarChar, 50), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@Address", SqlDbType.VarChar, 500), new SqlParameter("@Examine", SqlDbType.VarChar, 50), new SqlParameter("@Status", SqlDbType.Int, 4), new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = model.UserId; parameters[1].Value = model.RId; parameters[2].Value = model.AddTime; parameters[3].Value = model.Address; parameters[4].Value = model.Examine; parameters[5].Value = model.Status; parameters[6].Value = model.Id; int rows = SqlHelper.Instance.ExecSqlNonQuery(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 得到一个对象实体 /// </summary> private RentPersonEntity DataRowToModel(DataRow row) { RentPersonEntity model = new RentPersonEntity(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["UserId"] != null) { model.UserId = row["UserId"].ToString(); } if (row["RId"] != null) { model.RId = row["RId"].ToString(); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(row["AddTime"].ToString()); } if (row["Address"] != null) { model.Address = row["Address"].ToString(); } if (row["Examine"] != null) { model.Examine = row["Examine"].ToString(); } if (row["Status"] != null && row["Status"].ToString() != "") { model.Status = int.Parse(row["Status"].ToString()); } } return(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(RentPersonEntity model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into sns_rentPerson("); strSql.Append("UserId,RId,AddTime,Address,Examine,Status)"); strSql.Append(" values ("); strSql.Append("@UserId,@RId,@AddTime,@Address,@Examine,@Status)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@UserId", SqlDbType.VarChar, 50), new SqlParameter("@RId", SqlDbType.VarChar, 50), new SqlParameter("@AddTime", SqlDbType.DateTime), new SqlParameter("@Address", SqlDbType.VarChar, 500), new SqlParameter("@Examine", SqlDbType.VarChar, 50), new SqlParameter("@Status", SqlDbType.Int, 4) }; parameters[0].Value = model.UserId; parameters[1].Value = model.RId; parameters[2].Value = model.AddTime; parameters[3].Value = model.Address; parameters[4].Value = model.Examine; parameters[5].Value = model.Status; object obj = SqlHelper.Instance.ExecSqlScalar(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 得到一个对象实体 /// </summary> public RentPersonEntity GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,UserId,RId,AddTime,Address,Examine,Status from sns_rentPerson "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; RentPersonEntity model = new RentPersonEntity(); DataSet ds = SqlHelper.Instance.ExecSqlDataSet(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return(DataRowToModel(ds.Tables[0].Rows[0])); } else { return(null); } }
public void ProcessRequest(HttpContext context) { string userId = context.Request.Form["UserId"]; //报名人id string rId = context.Request.Form["RId"]; //出租的帖子id string address = context.Request.Form["AddressId"]; //收货地址id string s = "{\"status\":\"error\"}"; bool b = false; //获得帖子信息 RentEntity rentEntity = RentBll.Instance.GetModel(int.Parse(rId)); string official = rentEntity.Official; if (rentEntity.Examine == "1") //兑换中状态 { //取身家值 MemberEntity memberEntity = MemberBll.Instance.GetModel(int.Parse(userId)); if (memberEntity.Shenjia < decimal.Parse(official)) { s = "{\"status\":\"lacking\"}"; } else { //添加积分变更表 IntegralChangeEntity integralChangeEntity = new IntegralChangeEntity(); integralChangeEntity.UserId = userId; integralChangeEntity.source = "rent"; //出租 integralChangeEntity.ShenJia = -decimal.Parse(official); integralChangeEntity.Cnbi = "0"; integralChangeEntity.integral = 0; integralChangeEntity.ardent = 0; integralChangeEntity.Growth = 0; integralChangeEntity.Bean = "0"; integralChangeEntity.Status = 1; integralChangeEntity.AddTime = DateTime.Now; IntegralChangeBll.Instance.Add(integralChangeEntity); //更新会员表积分 MemberBll.Instance.UpdateIntegral(userId, "ShenJia", integralChangeEntity.ShenJia.ToString()); //添加兑换表 RentPersonEntity rentPersonEntity = new RentPersonEntity(); rentPersonEntity.UserId = userId; rentPersonEntity.RId = rId; rentPersonEntity.AddTime = DateTime.Now; rentPersonEntity.Address = address; rentPersonEntity.Examine = "1"; rentPersonEntity.Status = 1; b = RentPersonBll.Instance.Add(rentPersonEntity) > 0; if (b) { //更新出租表 rentEntity.RentPerson = userId; rentEntity.EnterTime = DateTime.Now; rentEntity.Examine = "0"; b = RentBll.Instance.Update(rentEntity); if (b) { s = "{\"status\":\"success\"}"; } } } } else { s = "{\"status\":\"other\"}"; } context.Response.ContentType = "text/plain"; context.Response.Charset = "utf-8"; context.Response.Write(s); }