/// <summary> /// 获取精品文字详情 /// </summary> /// <param name="articleID"></param> /// <returns></returns> public ShortArticleModel GetShortArticleDetail(Guid articleID) { string strSql = string.Format("SELECT *,(SELECT CustomerName FROM dbo.Customer c WHERE c.CustomerID=a.CustomerID) as CustomerName,(SELECT count(1) FROM [ArticleLike] l WHERE l.ArticleID=a.ArticleID) as LikeCount,(SELECT count(1) FROM [ArticleComment] c WHERE c.ArticleID=a.ArticleID) as CommentCount, (SELECT Sex FROM dbo.Customer c WHERE c.CustomerID=a.CustomerID) as CustomerSex FROM dbo.ShortArticle a where a.ArticleID='{0}' ORDER BY CreateDate DESC", articleID); SqlDataReader sqlDataReader = DBHelper.GetDataReader(strSql.ToString()); ShortArticleModel model = sqlDataReader.ReaderToModel <ShortArticleModel>(); sqlDataReader.Close(); return(model); }
protected void btnPost_Click(object sender, EventArgs e) { //从会话里面获取到用户详细信息 CustomerModel customer = Session["UserInfo"] as CustomerModel; ShortArticleModel model = new ShortArticleModel(); //创建文字对象 model.CustomerID = customer.CustomerID; //文字发布人设置为当前登录用户 model.ArticleContent = txtContent.Text; //将用户输入文本框的内容赋值给内容字段 bool bl = service.CreateShortArticle(model); //提交至数据库 if (bl) { Response.Write("<script>alert('发布成功');window.location='Index.aspx';</script>"); } else { Response.Write("<script>alert('发布不成功 请重试');window.location='Index.aspx';</script>"); } }
/// <summary> /// 发布精品文字 /// </summary> /// <param name="model"></param> /// <returns></returns> public bool CreateShortArticle(ShortArticleModel model) { StringBuilder strSql = new StringBuilder(); strSql.Append("insert into ShortArticle("); strSql.Append("ArticleID,ArticleContent,CustomerID,ArticleType,GetCount,DataState,CreateDate)"); strSql.Append(" values ("); strSql.Append("@ArticleID,@ArticleContent,@CustomerID,@ArticleType,@GetCount,@DataState,@CreateDate)"); SqlParameter[] parameters = { new SqlParameter("@ArticleID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@ArticleContent", SqlDbType.VarChar, -1), new SqlParameter("@CustomerID", SqlDbType.UniqueIdentifier, 16), new SqlParameter("@ArticleType", SqlDbType.Int, 4), new SqlParameter("@GetCount", SqlDbType.Int, 4), new SqlParameter("@DataState", SqlDbType.Int, 4), new SqlParameter("@CreateDate", SqlDbType.DateTime) }; parameters[0].Value = Guid.NewGuid(); parameters[1].Value = model.ArticleContent; parameters[2].Value = model.CustomerID; parameters[3].Value = 0; //文字类型默认0 parameters[4].Value = 0; //初始浏览次数0 parameters[5].Value = 0; //默认状态0 parameters[6].Value = DateTime.Now; int rows = DBHelper.ExecuteCommand(strSql.ToString(), parameters); if (rows > 0) { return(true); } else { return(false); } }