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

            if (this.fileUpload.HasFile)
            {
                try
                {
                    iconUrl = ArticleHelper.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 (ArticleHelper.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;
            }
        }
Exemplo n.º 2
0
        private void btnAddArticle_Click(object sender, EventArgs e)
        {
            string str = string.Empty;

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

            if (dropArticleCategory.SelectedValue.HasValue)
            {
                target.CategoryId      = dropArticleCategory.SelectedValue.Value;
                target.Title           = txtArticleTitle.Text.Trim();
                target.MetaDescription = txtMetaDescription.Text.Trim();
                target.MetaKeywords    = txtMetaKeywords.Text.Trim();
                target.IconUrl         = str;
                target.Description     = txtShortDesc.Text.Trim();
                target.Content         = fcContent.Text;
                target.AddedDate       = DateTime.Now;
                target.IsRelease       = 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);
                    }
                    ShowMsg(msg, false);
                }
                else if (ArticleHelper.CreateArticle(target))
                {
                    txtArticleTitle.Text = string.Empty;
                    txtShortDesc.Text    = string.Empty;
                    fcContent.Text       = string.Empty;
                    ShowMsg("成功添加了一篇文章", true);
                }
                else
                {
                    ShowMsg("添加文章错误", false);
                }
            }
            else
            {
                ShowMsg("请选择文章分类", false);
            }
        }
Exemplo n.º 3
0
        private void btnAddArticle_Click(object sender, EventArgs e)
        {
            string      text        = this.UploadImage();
            string      iconUrl     = text;
            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.Meta_Description = this.txtMetaDescription.Text.Trim();
                articleInfo.Meta_Keywords    = this.txtMetaKeywords.Text.Trim();
                articleInfo.IconUrl          = iconUrl;
                articleInfo.Description      = this.txtShortDesc.Text.Trim();
                articleInfo.Content          = this.fcContent.Text;
                articleInfo.AddedDate        = DateTime.Now;
                articleInfo.IsRelease        = this.ooRelease.SelectedValue;
                ValidationResults validationResults = Validation.Validate(articleInfo, "ValArticleInfo");
                string            text2             = string.Empty;
                if (!validationResults.IsValid)
                {
                    foreach (ValidationResult item in (IEnumerable <ValidationResult>)validationResults)
                    {
                        text2 += Formatter.FormatErrorMessage(item.Message);
                    }
                    this.ShowMsg(text2, false);
                }
                else if (ArticleHelper.CreateArticle(articleInfo))
                {
                    this.txtArticleTitle.Text = string.Empty;
                    this.txtShortDesc.Text    = string.Empty;
                    this.fcContent.Text       = string.Empty;
                    this.ShowMsg("成功添加了一篇文章", true);
                }
                else
                {
                    this.ShowMsg("添加文章错误", false);
                }
            }
        }