/// <summary> /// 获得数据列表 /// </summary> public List <Model.BookComment> DataTableToList(DataTable dt) { List <Model.BookComment> modelList = new List <Model.BookComment>(); int rowsCount = dt.Rows.Count; if (rowsCount > 0) { Model.BookComment model; for (int n = 0; n < rowsCount; n++) { model = new Model.BookComment(); if (dt.Rows[n]["Id"].ToString() != "") { model.Id = int.Parse(dt.Rows[n]["Id"].ToString()); } model.Msg = dt.Rows[n]["Msg"].ToString(); if (dt.Rows[n]["CreateDateTime"].ToString() != "") { model.CreateDateTime = DateTime.Parse(dt.Rows[n]["CreateDateTime"].ToString()); } if (dt.Rows[n]["BookId"].ToString() != "") { model.BookId = int.Parse(dt.Rows[n]["BookId"].ToString()); } modelList.Add(model); } } return(modelList); }
/// <summary> /// 添加评论 /// </summary> /// <param name="context"></param> /// <param name="msg"></param> /// <param name="isPass"></param> private void AddMsg(HttpContext context, string msg, int isPass) { Model.BookComment bookComment = new Model.BookComment(); bookComment.BookId = Convert.ToInt32(context.Request["bookId"]); bookComment.Msg = articelManager.CheckReplace(msg);//替换词 bookComment.CreateDateTime = DateTime.Now; //bookComment.IsPass=isPass //bookComment.UserId=userId. if (bll.Add(bookComment) > 0) { if (isPass == 1) { context.Response.Write("ok:评论成功"); } else { context.Response.Write("ok:评论成功含有审查词"); } } else { context.Response.Write("no:评论失败"); } }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.BookComment model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into BookComment("); strSql.Append("Msg,CreateDateTime,BookId)"); strSql.Append(" values ("); strSql.Append("@Msg,@CreateDateTime,@BookId)"); strSql.Append(";select @@IDENTITY"); SqlParameter[] parameters = { new SqlParameter("@Msg", SqlDbType.NVarChar), new SqlParameter("@CreateDateTime", SqlDbType.DateTime), new SqlParameter("@BookId", SqlDbType.Int, 4) }; parameters[0].Value = model.Msg; parameters[1].Value = model.CreateDateTime; parameters[2].Value = model.BookId; object obj = DbHelperSQL.GetSingle(strSql.ToString(), parameters); if (obj == null) { return(1); } else { return(Convert.ToInt32(obj)); } }
private void AddComment(HttpContext context) { Model.BookComment bookComment = new Model.BookComment(); bookComment.BookId = Convert.ToInt32(context.Request["bookId"]); bookComment.Msg = context.Request["msg"]; bookComment.CreateDateTime = DateTime.Now; BLL.BookCommentManager bookCommentManager = new BookCommentManager(); if (bookCommentManager.Add(bookComment) > 0) { context.Response.Write("OK"); } }
private void AddComment(HttpContext context) { Model.BookComment bookcomment = new Model.BookComment(); bookcomment.BookId = Convert.ToInt32(context.Request["bookId"]); bookcomment.Msg = context.Request["msg"]; bookcomment.CreatDateTime = DateTime.Now; if (bll.Add(bookcomment)) { context.Response.Write("ok"); } else { context.Response.Write("no"); } }
private void AddBookComment(HttpContext context, string msg) { Model.BookComment bookComment = new Model.BookComment(); bookComment.Msg = msg; bookComment.BookId = Convert.ToInt32(context.Request["bookId"]); bookComment.CreateDateTime = DateTime.Now; // bookComment.IsState=1 if (bookCommentManager.Add(bookComment) > 0) { context.Response.Write("ok:评论成功!!"); } else { context.Response.Write("no:评论失败!!"); } }
public void ProcessRequest(HttpContext context) { context.Response.ContentType = "text/plain"; string action = context.Request["action"]; if (action == "add") { Model.BookComment entity = new Model.BookComment(); entity.BookId = Convert.ToInt32(context.Request["bookId"]); entity.Msg = context.Request["msg"]; entity.CreateDateTime = DateTime.Now; BLL.BookComment bll = new BLL.BookComment(); if (bll.Add(entity) > 0) { context.Response.Write("ok"); } else { context.Response.Write("no"); } } else if (action == "load")//加载评论 { int bookId = Convert.ToInt32(context.Request["bookId"]); BLL.BookComment bll = new BLL.BookComment(); List <Model.BookComment> comments = bll.GetModelList(" bookId =" + bookId); //进行时间运算 List <CommentViewModel> viewList = new List <CommentViewModel>(); foreach (var entity in comments) { CommentViewModel view = new CommentViewModel(); view.Msg = entity.Msg; view.CreateDateTime = Common.WebCommon.GetTimeSpan(DateTime.Now - entity.CreateDateTime); viewList.Add(view); } System.Web.Script.Serialization.JavaScriptSerializer js = new System.Web.Script.Serialization.JavaScriptSerializer(); context.Response.Write(js.Serialize(viewList.ToArray())); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Model.BookComment model) { StringBuilder strSql = new StringBuilder(); strSql.Append("update BookComment set "); strSql.Append("Msg=@Msg,"); strSql.Append("CreateDateTime=@CreateDateTime,"); strSql.Append("BookId=@BookId"); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4), new SqlParameter("@Msg", SqlDbType.NVarChar), new SqlParameter("@CreateDateTime", SqlDbType.DateTime), new SqlParameter("@BookId", SqlDbType.Int, 4) }; parameters[0].Value = model.Id; parameters[1].Value = model.Msg; parameters[2].Value = model.CreateDateTime; parameters[3].Value = model.BookId; DbHelperSQL.ExecuteSql(strSql.ToString(), parameters); }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.BookComment GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Msg,CreateDateTime,BookId from BookComment "); strSql.Append(" where Id=@Id "); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int, 4) }; parameters[0].Value = Id; Model.BookComment model = new Model.BookComment(); 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()); } model.Msg = ds.Tables[0].Rows[0]["Msg"].ToString(); if (ds.Tables[0].Rows[0]["CreateDateTime"].ToString() != "") { model.CreateDateTime = DateTime.Parse(ds.Tables[0].Rows[0]["CreateDateTime"].ToString()); } if (ds.Tables[0].Rows[0]["BookId"].ToString() != "") { model.BookId = int.Parse(ds.Tables[0].Rows[0]["BookId"].ToString()); } return(model); } else { return(null); } }
/// <summary> /// 更新一条数据 /// </summary> public void Update(Model.BookComment model) { dal.Update(model); }
/// <summary> /// 增加一条数据 /// </summary> public int Add(Model.BookComment model) { return(dal.Add(model)); }
//添加评论 private bool AddComment(int bookId, string msg) { Model.BookComment bookComment = new Model.BookComment(); bookComment.CreateDateTime = System.DateTime.Now; bookComment.Msg = msg; bookComment.BookId = bookId; BLL.BookCommentBll bll = new BLL.BookCommentBll(); return bll.Add(bookComment) > 0; }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.BookComment DataRowToModel(DataRow row) { Model.BookComment model = new Model.BookComment(); if (row != null) { if (row["Id"] != null && row["Id"].ToString() != "") { model.Id = int.Parse(row["Id"].ToString()); } if (row["Msg"] != null) { model.Msg = row["Msg"].ToString(); } if (row["CreateDateTime"] != null && row["CreateDateTime"].ToString() != "") { model.CreateDateTime = DateTime.Parse(row["CreateDateTime"].ToString()); } if (row["BookId"] != null && row["BookId"].ToString() != "") { model.BookId = int.Parse(row["BookId"].ToString()); } if (row["parentId"] != null && row["parentId"].ToString() != "") { model.parentId = int.Parse(row["parentId"].ToString()); } if (row["floorIndexId"] != null && row["floorIndexId"].ToString() != "") { model.floorIndexId = int.Parse(row["floorIndexId"].ToString()); } } return model; }
/// <summary> /// 得到一个对象实体 /// </summary> public Model.BookComment GetModel(int Id) { StringBuilder strSql = new StringBuilder(); strSql.Append("select top 1 Id,Msg,CreateDateTime,BookId,parentId,floorIndexId from BookComment "); strSql.Append(" where Id=@Id"); SqlParameter[] parameters = { new SqlParameter("@Id", SqlDbType.Int,4) }; parameters[0].Value = Id; Model.BookComment model = new Model.BookComment(); DataSet ds = DbHelperSQL.Query(strSql.ToString(), parameters); if (ds.Tables[0].Rows.Count > 0) { return DataRowToModel(ds.Tables[0].Rows[0]); } else { return null; } }
public bool Add(Model.BookComment bookcomment)//添加数据 { return(dal.Add(bookcomment)); }