/// <summary> /// 得到一个对象实体 /// </summary> public Model.browse_goods GetModel(int id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select id, user_id, goods_id, img_url, goods_name, add_time, time "); strSql.Append(" from td_browse_goods "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4) }; parameters[0].Value = id; Model.browse_goods model = new Model.browse_goods(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { if (ds.Tables[0].Rows[0]["id"].ToString() != "") { model.id = int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if (ds.Tables[0].Rows[0]["user_id"].ToString() != "") { model.user_id = int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } if (ds.Tables[0].Rows[0]["goods_id"].ToString() != "") { model.goods_id = int.Parse(ds.Tables[0].Rows[0]["goods_id"].ToString()); } model.img_url = ds.Tables[0].Rows[0]["img_url"].ToString(); model.goods_name = ds.Tables[0].Rows[0]["goods_name"].ToString(); if (ds.Tables[0].Rows[0]["add_time"].ToString() != "") { model.add_time = DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } model.time = ds.Tables[0].Rows[0]["time"].ToString(); return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.browse_goods model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update td_browse_goods set "); strSql.Append(" user_id = @user_id , "); strSql.Append(" goods_id = @goods_id , "); strSql.Append(" img_url = @img_url , "); strSql.Append(" goods_name = @goods_name , "); strSql.Append(" add_time = @add_time , "); strSql.Append(" time = @time "); strSql.Append(" where id=@id "); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int, 4), new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@goods_id", SqlDbType.Int, 4), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@goods_name", SqlDbType.NVarChar, 100), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@time", SqlDbType.NVarChar, 100) }; parameters[0].Value = model.id; parameters[1].Value = model.user_id; parameters[2].Value = model.goods_id; parameters[3].Value = model.img_url; parameters[4].Value = model.goods_name; parameters[5].Value = model.add_time; parameters[6].Value = model.time; int rows = DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.browse_goods model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into td_browse_goods("); strSql.Append("user_id,goods_id,img_url,goods_name,add_time,time"); strSql.Append(") values ("); strSql.Append("@user_id,@goods_id,@img_url,@goods_name,@add_time,@time"); strSql.Append(") "); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@user_id", SqlDbType.Int, 4), new SqlParameter("@goods_id", SqlDbType.Int, 4), new SqlParameter("@img_url", SqlDbType.NVarChar, 255), new SqlParameter("@goods_name", SqlDbType.NVarChar, 100), new SqlParameter("@add_time", SqlDbType.DateTime), new SqlParameter("@time", SqlDbType.NVarChar, 100) }; parameters[0].Value = model.user_id; parameters[1].Value = model.goods_id; parameters[2].Value = model.img_url; parameters[3].Value = model.goods_name; parameters[4].Value = model.add_time; parameters[5].Value = model.time; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(0); } else { return(Convert.ToInt32(obj)); } }
/// <summary> /// 更新一条数据 /// </summary> public bool Update(Model.browse_goods model) { return(dal.Update(model)); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.browse_goods model) { return(dal.Add(model)); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.browse_goods GetModel(int id) { StringBuilder strSql=new StringBuilder(); strSql.Append("select id, user_id, goods_id, img_url, goods_name, add_time, time "); strSql.Append(" from td_browse_goods "); strSql.Append(" where id=@id"); SqlParameter[] parameters = { new SqlParameter("@id", SqlDbType.Int,4) }; parameters[0].Value = id; Model.browse_goods model=new Model.browse_goods(); DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters); if(ds.Tables[0].Rows.Count>0) { if(ds.Tables[0].Rows[0]["id"].ToString()!="") { model.id=int.Parse(ds.Tables[0].Rows[0]["id"].ToString()); } if(ds.Tables[0].Rows[0]["user_id"].ToString()!="") { model.user_id=int.Parse(ds.Tables[0].Rows[0]["user_id"].ToString()); } if(ds.Tables[0].Rows[0]["goods_id"].ToString()!="") { model.goods_id=int.Parse(ds.Tables[0].Rows[0]["goods_id"].ToString()); } model.img_url= ds.Tables[0].Rows[0]["img_url"].ToString(); model.goods_name= ds.Tables[0].Rows[0]["goods_name"].ToString(); if(ds.Tables[0].Rows[0]["add_time"].ToString()!="") { model.add_time=DateTime.Parse(ds.Tables[0].Rows[0]["add_time"].ToString()); } model.time= ds.Tables[0].Rows[0]["time"].ToString(); return model; } else { return null; } }
private void get_browse_goods(HttpContext context) { int id = DTRequest.GetQueryInt("id"); BLL.browse_goods bll = new BLL.browse_goods(); BLL.article abll = new BLL.article(); Model.article model = abll.GetModel(id); Model.browse_goods bmodel = new Model.browse_goods(); Model.users users = new BasePage().GetUserInfo(); if (users == null) { context.Response.Write("{\"status\":0, \"msg\":\"对不起,请登录!\"}"); return; } if (bll.Exists1(id)) { bll.UpdateField(id, "add_time=getdate()"); context.Response.Write("{\"status\":1, \"msg\":\"修改浏览信息成功!\"}"); return; } bmodel.user_id = users.id; bmodel.goods_id = model.id; bmodel.goods_name = model.title; bmodel.img_url = model.img_url; bmodel.add_time = DateTime.Now; bmodel.time = bmodel.add_time.ToString("yyyy-MM-dd"); if (bll.Add(bmodel) > 0) { context.Response.Write("{\"status\":1, \"msg\":\"添加浏览信息成功!\"}"); return; } else { context.Response.Write("{\"status\":0, \"msg\":\"添加浏览信息失败!\"}"); return; } }