protected void Page_Load(object sender, EventArgs e) { String id = Request.QueryString["id"]; if (!IsPostBack) { pId = id; Bindjiushu(id);//绑定 BindMessage(id); } else { if (Session["Userinfo"] == null) { Response.Redirect("/Users/Login.aspx"); } else { shaoqi.Model.User model = (shaoqi.Model.User)Session["Userinfo"]; shaoqi.Model.Comment messmodel = new shaoqi.Model.Comment(); shaoqi.BLL.Comment messBll = new shaoqi.BLL.Comment(); messmodel.ComContent = Request.Form["context"]; messmodel.UserId.Id = model.Id; messmodel.CartoonId.Id = Convert.ToInt32(Request.Form["Pid"]); messmodel.AddTime = DateTime.Now; messBll.Add(messmodel); BindMessage(messmodel.CartoonId.Id.ToString()); } } }
/// <summary> /// 得到一个对象实体 /// </summary> public shaoqi.Model.Comment DataRowToModel(DataRow row) { DAL.User userDal = new User(); DAL.CatroonInfo catrDal = new CatroonInfo(); shaoqi.Model.Comment model = new shaoqi.Model.Comment(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["CartoonId"] != null && row["CartoonId"].ToString() != "") { model.CartoonId = catrDal.GetModel(int.Parse(row["CartoonId"].ToString())); } if (row["ComContent"] != null) { model.ComContent = row["ComContent"].ToString(); } if (row["UserId"] != null && row["UserId"].ToString() != "") { model.UserId = userDal.GetModel(int.Parse(row["UserId"].ToString())); } if (row["AddTime"] != null && row["AddTime"].ToString() != "") { model.AddTime = DateTime.Parse(row["AddTime"].ToString()); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public shaoqi.Model.Comment GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,CartoonId,ComContent,UserId,AddTime from Comment "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) }; parameters[0].Value = Id; shaoqi.Model.Comment model = new shaoqi.Model.Comment(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }