public static bool CreateArticle(ArticleInfo article) { if (null == article) { return false; } Globals.EntityCoding(article, true); return CommentsProvider.Instance().AddArticle(article); }
private void btnAddArticle_Click(object sender, EventArgs e) { string str = string.Empty; if (this.fileUpload.HasFile) { try { str = SubsiteCommentsHelper.UploadArticleImage(this.fileUpload.PostedFile); } catch { this.ShowMsg("图片上传失败,您选择的不是图片类型的文件,或者网站的虚拟目录没有写入文件的权限", false); return; } } ArticleInfo target = new ArticleInfo(); if (this.dropArticleCategory.SelectedValue.HasValue) { target.CategoryId = this.dropArticleCategory.SelectedValue.Value; target.Title = this.txtArticleTitle.Text.Trim(); target.MetaDescription = this.txtMetaDescription.Text.Trim(); target.MetaKeywords = this.txtMetaKeywords.Text.Trim(); target.IconUrl = str; target.Description = this.txtShortDesc.Text.Trim(); target.Content = this.fcContent.Text; target.AddedDate = DateTime.Now; target.IsRelease = this.ckrrelease.Checked; ValidationResults results = Hishop.Components.Validation.Validation.Validate<ArticleInfo>(target, new string[] { "ValArticleInfo" }); string msg = string.Empty; if (!results.IsValid) { foreach (ValidationResult result in (IEnumerable<ValidationResult>) results) { msg = msg + Formatter.FormatErrorMessage(result.Message); } this.ShowMsg(msg, false); } else if (SubsiteCommentsHelper.CreateArticle(target)) { this.txtArticleTitle.Text = string.Empty; this.txtShortDesc.Text = string.Empty; this.fcContent.Text = string.Empty; this.ShowMsg("成功添加了一篇文章", true); } else { this.ShowMsg("添加文章错误", false); } } else { this.ShowMsg("请选择文章分类", false); } }
public override bool AddArticle(ArticleInfo article) { DbCommand sqlStringCommand = database.GetSqlStringCommand("INSERT INTO Hishop_Articles(CategoryId, Title, Meta_Description, Meta_Keywords, IconUrl, Description, Content, AddedDate,IsRelease) VALUES (@CategoryId, @Title, @Meta_Description, @Meta_Keywords, @IconUrl, @Description, @Content, @AddedDate,@IsRelease)"); database.AddInParameter(sqlStringCommand, "CategoryId", DbType.Int32, article.CategoryId); database.AddInParameter(sqlStringCommand, "Title", DbType.String, article.Title); database.AddInParameter(sqlStringCommand, "Meta_Description", DbType.String, article.MetaDescription); database.AddInParameter(sqlStringCommand, "Meta_Keywords", DbType.String, article.MetaKeywords); database.AddInParameter(sqlStringCommand, "IconUrl", DbType.String, article.IconUrl); database.AddInParameter(sqlStringCommand, "Description", DbType.String, article.Description); database.AddInParameter(sqlStringCommand, "Content", DbType.String, article.Content); database.AddInParameter(sqlStringCommand, "AddedDate", DbType.DateTime, article.AddedDate); database.AddInParameter(sqlStringCommand, "IsRelease", DbType.Boolean, article.IsRelease); return (database.ExecuteNonQuery(sqlStringCommand) == 1); }
public override bool UpdateArticle(ArticleInfo article) { DbCommand sqlStringCommand = database.GetSqlStringCommand("UPDATE Hishop_Articles SET CategoryId = @CategoryId,AddedDate = @AddedDate,Title = @Title, Meta_Description = @Meta_Description, Meta_Keywords = @Meta_Keywords, IconUrl=@IconUrl,Description = @Description,Content = @Content,IsRelease=@IsRelease WHERE ArticleId = @ArticleId"); database.AddInParameter(sqlStringCommand, "CategoryId", DbType.Int32, article.CategoryId); database.AddInParameter(sqlStringCommand, "Title", DbType.String, article.Title); database.AddInParameter(sqlStringCommand, "Meta_Description", DbType.String, article.MetaDescription); database.AddInParameter(sqlStringCommand, "Meta_Keywords", DbType.String, article.MetaKeywords); database.AddInParameter(sqlStringCommand, "IconUrl", DbType.String, article.IconUrl); database.AddInParameter(sqlStringCommand, "Description", DbType.String, article.Description); database.AddInParameter(sqlStringCommand, "Content", DbType.String, article.Content); database.AddInParameter(sqlStringCommand, "IsRelease", DbType.Boolean, article.IsRelease); database.AddInParameter(sqlStringCommand, "AddedDate", DbType.DateTime, article.AddedDate); database.AddInParameter(sqlStringCommand, "ArticleId", DbType.Int32, article.ArticleId); return (database.ExecuteNonQuery(sqlStringCommand) == 1); }
public static ArticleInfo PopulateArticle(IDataRecord reader) { if (null == reader) { return null; } ArticleInfo info = new ArticleInfo(); info.ArticleId = (int) reader["ArticleId"]; info.CategoryId = (int) reader["CategoryId"]; info.Title = (string) reader["Title"]; if (reader["Meta_Description"] != DBNull.Value) { info.MetaDescription = (string) reader["Meta_Description"]; } if (reader["Meta_Keywords"] != DBNull.Value) { info.MetaKeywords = (string) reader["Meta_Keywords"]; } if (reader["Description"] != DBNull.Value) { info.Description = (string) reader["Description"]; } if (reader["IconUrl"] != DBNull.Value) { info.IconUrl = (string) reader["IconUrl"]; } info.Content = (string) reader["Content"]; info.AddedDate = (DateTime) reader["AddedDate"]; info.IsRelease = (bool) reader["IsRelease"]; return info; }
public abstract bool AddArticle(ArticleInfo article);
public abstract bool UpdateArticle(ArticleInfo article);