Esempio n. 1
0
        private void btnAddArticle_Click(object sender, System.EventArgs e)
        {
            string iconUrl = string.Empty;

            if (this.fileUpload.HasFile)
            {
                try
                {
                    iconUrl = SubsiteCommentsHelper.UploadArticleImage(this.fileUpload.PostedFile);
                }
                catch
                {
                    this.ShowMsg("图片上传失败,您选择的不是图片类型的文件,或者网站的虚拟目录没有写入文件的权限", false);
                    return;
                }
            }
            ArticleInfo articleInfo = new ArticleInfo();

            if (!this.dropArticleCategory.SelectedValue.HasValue)
            {
                this.ShowMsg("请选择文章分类", false);
            }
            else
            {
                articleInfo.CategoryId      = this.dropArticleCategory.SelectedValue.Value;
                articleInfo.Title           = this.txtArticleTitle.Text.Trim();
                articleInfo.MetaDescription = this.txtMetaDescription.Text.Trim();
                articleInfo.MetaKeywords    = this.txtMetaKeywords.Text.Trim();
                articleInfo.IconUrl         = iconUrl;
                articleInfo.Description     = this.txtShortDesc.Text.Trim();
                articleInfo.Content         = this.fcContent.Text;
                articleInfo.AddedDate       = System.DateTime.Now;
                articleInfo.IsRelease       = this.ckrrelease.Checked;
                ValidationResults validationResults = Validation.Validate <ArticleInfo>(articleInfo, new string[]
                {
                    "ValArticleInfo"
                });
                string text = string.Empty;
                if (!validationResults.IsValid)
                {
                    foreach (ValidationResult current in (System.Collections.Generic.IEnumerable <ValidationResult>)validationResults)
                    {
                        text += Formatter.FormatErrorMessage(current.Message);
                    }
                    this.ShowMsg(text, false);
                    return;
                }
                if (SubsiteCommentsHelper.CreateArticle(articleInfo))
                {
                    this.txtArticleTitle.Text = string.Empty;
                    this.txtShortDesc.Text    = string.Empty;
                    this.fcContent.Text       = string.Empty;
                    this.ShowMsg("成功添加了一篇文章", true);
                    return;
                }
                this.ShowMsg("添加文章错误", false);
                return;
            }
        }
Esempio n. 2
0
        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);
            }
        }