protected void egvAttachments_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            ArticleAttachment attachment = e.Row.DataItem as ArticleAttachment;
            Image             picture    = e.Row.FindControl("imgPicture") as Image;

            if (picture != null)
            {
                if (attachment.IsRemote)
                {
                    picture.ImageUrl = attachment.FileName;
                }
                else
                {
                    picture.ImageUrl = attachment.GetDefaultImageUrl((int)picture.Width.Value, (int)picture.Height.Value);
                }
            }

            HyperLink hyName = e.Row.FindControl("hlName") as HyperLink;
            if (hyName != null)
            {
                hyName.Text        = attachment.Name;
                hyName.NavigateUrl = "#";
            }
        }
    }
Example #2
0
        public override ArticleAttachment CreateUpdateArticleAttachment(ArticleAttachment info, HHOnline.Framework.DataProviderAction action, out HHOnline.Framework.DataActionStatus status)
        {
            ELParameter[] parms = new ELParameter[]
            {
                action == DataProviderAction.Create ?
                new ELParameter("@AttachmentID", DbType.Int32, 4, ParameterDirection.Output) :
                new ELParameter("@AttachmentID", DbType.Int32, info.ID),
                new ELParameter("@AttachmentName", DbType.String, info.Name),
                new ELParameter("@AttachmentFile", DbType.String, info.FileName),
                new ELParameter("@ContentType", DbType.String, info.ContentType),
                new ELParameter("@ContentSize", DbType.Int32, info.ContentSize),
                new ELParameter("@IsRemote", DbType.Int32, info.IsRemote ? 1 : 0),
                new ELParameter("@ImageWidth", DbType.Int32, info.ImageWidth == null ? (object)DBNull.Value : (object)info.ImageWidth),
                new ELParameter("@ImageHeight", DbType.Int32, info.ImageHeight == null ? (object)DBNull.Value : (object)info.ImageHeight),
                new ELParameter("@AttachmentDesc", DbType.String, info.Desc),
                new ELParameter("@AttachmentMemo", DbType.String, info.Memo),
                new ELParameter("@AttachmentStatus", DbType.Int32, info.Status),
                new ELParameter("@User", DbType.Int32, GlobalSettings.GetCurrentUser().UserID),
                new ELParameter("@Action", DbType.Int32, action),
            };

            status = (DataActionStatus)Convert.ToInt32(DataHelper.ExecuteScalar(CommandType.StoredProcedure, "sp_ArticleAttachment_CreateUpdate", parms));
            if (status == DataActionStatus.Success && action == DataProviderAction.Create)
            {
                info.ID = Convert.ToInt32(parms[0].Value);
            }

            return(info);
        }
        private void UploadWholeFile(HttpContext context, List <FilesStatus> statuses)
        {
            IUserBasic     user = context.User.Identity as IUserBasic;
            HttpPostedFile httpPostedFile;

            for (int i = 0; i < context.Request.Files.Count; i++)
            {
                httpPostedFile = context.Request.Files[i];

                ArticleAttachment articleAttachment = new ArticleAttachment(this.RequestContextData.ApplicationThemeInfo.ApplicationId, user);

                articleAttachment.Content     = ReadStream(httpPostedFile.InputStream, httpPostedFile.ContentLength);
                articleAttachment.ContentSize = httpPostedFile.ContentLength;
                articleAttachment.ContentType = httpPostedFile.ContentType;
                articleAttachment.FileName    = httpPostedFile.FileName;

                UrlHelper urlHelper = new UrlHelper(context.Request.RequestContext);
                string    action    = urlHelper.RouteUrl(MagicStrings.FormatRouteName(
                                                             this.RequestContextData.ApplicationThemeInfo.ApplicationGroup, "Articles_FileUploadHandler"));

                var report = InstanceContainer.ArticleAttachmentManager.CreateTemporaryFile(articleAttachment);
                if (report.Status != Workmate.Components.Contracts.DataRepositoryActionStatus.Success)
                {
                    // TODO (Roman): errorhandling
                    statuses.Add(new FilesStatus(articleAttachment, report.Message, action));
                }
                else
                {
                    statuses.Add(new FilesStatus(articleAttachment, action));
                }
            }
        }
        public ActionResult Create(ArticleAttachmentViewModel vm)
        {
            if (ModelState.IsValid)
            {
                var newAttachment = new ArticleAttachment
                {
                    ArticleId      = vm.ArticleId,
                    AttachmentType = vm.AttachmentType,
                    FileSize       = 0.0
                };

                if (vm.Document != null)
                {
                    var siteSettings      = _settingsService.GetSiteSettings();
                    var blobUploadService = new BlobUploadService(siteSettings.BlobSettings);
                    var blobPath          = blobUploadService.UploadArticleAttachment(vm.Document);
                    newAttachment.DocumentPath = blobPath;
                    newAttachment.FileName     = vm.Document.FileName;
                }

                _articleAttachmentRepository.Create(newAttachment);
                _unitOfWork.Commit();

                return(RedirectToAction("Edit", "Articles", new { id = vm.ArticleId }));
            }

            ViewBag.ArticleId = new SelectList(_articleRepository.GetAll(), "Id", "Title", vm.ArticleId);

            return(View(vm));
        }
Example #5
0
        /// <summary>
        /// 更新附件
        /// </summary>
        /// <param name="info"></param>
        /// <returns></returns>
        public static DataActionStatus UpdateArticleAttachment(ArticleAttachment info)
        {
            DataActionStatus result;

            ArticleAttachmentProvider.Instance.CreateUpdateArticleAttachment(info, DataProviderAction.Update, out result);

            return(result);
        }
        public FilesStatus(ArticleAttachment attachment, string error, string action)
        {
            this.attachmentId = attachment.ArticleAttachmentId;
            this.delete_type  = "DELETE";

            this.delete_url = action + "?f=" + attachment.ArticleAttachmentId; // TODO (Roman): implement proper path
            this.url        = action + "?f=" + attachment.ArticleAttachmentId; // TODO (Roman): implement proper path
            this.error      = error;
            this.name       = attachment.FileName;
            this.progress   = "1.0";
            this.size       = attachment.ContentSize;
            this.type       = attachment.ContentType;
        }
Example #7
0
 protected void dlArticle_ItemDataBound(object sender, DataListItemEventArgs e)
 {
     if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
     {
         Image image = e.Item.FindControl("imgArticle") as Image;
         if (image != null)
         {
             Article article = e.Item.DataItem as Article;
             //image.ImageUrl = GlobalSettings.RelativeWebRoot + article.GetDefaultImageUrl(100, 100);
             if (article != null)
             {
                 // 获取附件
                 ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image);
                 if (attachment != null)
                 {
                     if (attachment.IsRemote)
                     {
                         image.ImageUrl = attachment.FileName;
                     }
                     else
                     {
                         image.ImageUrl = attachment.GetDefaultImageUrl(100, 100);
                     }
                     image.Visible = true;
                 }
                 else
                 {
                     image.Visible = false;
                 }
             }
             else
             {
                 image.Visible = false;
             }
         }
         //Literal ltPrice = e.Item.FindControl("ltPrice") as Literal;
         //if (ltPrice != null)
         //{
         //    decimal? price = null;
         //    if (!User.Identity.IsAuthenticated)
         //    {
         //        price = ArticlePrices.GetPriceDefault(article.ID);
         //    }
         //    else
         //    {
         //        price = ArticlePrices.GetPriceDefault(article.ID);
         //    }
         //    ltPrice.Text = (price == null ? "需询价" : price.Value.ToString("c"));
         //}
     }
 }
Example #8
0
        public override List <ArticleAttachment> GetAllArticleAttachments()
        {
            using (IDataReader dr = DataHelper.ExecuteReader(CommandType.StoredProcedure, "sp_ArticleAttachment_GetAll"))
            {
                List <ArticleAttachment> result = new List <ArticleAttachment>();
                for (; dr.Read();)
                {
                    ArticleAttachment article = ArticleReaderConverter.ParseArticleAttachment(dr);
                    result.Add(article);
                }

                return(result);
            }
        }
        public async Task <IActionResult> PostArticleAttachment([FromBody] ArticleAttachment articleAttachment)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var article = _context
                          .Articles
                          .FirstOrDefault(x => x.Id == articleAttachment.ArticleId);

            if (article == null)
            {
                return(NotFound("Article with such id doesn't exists!"));
            }
            var role    = StaticHelper.GetCurrentRole(User);
            var current = _context.Users.FirstOrDefault(x => x.Email == User.Identity.Name);

            if (current == null)
            {
                return(BadRequest());
            }
            if (role != "admin" & article.UserId != current.Id)
            {
                return(BadRequest());
            }
            try
            {
                articleAttachment.Type = articleAttachment.Path.Substring(articleAttachment.Path.LastIndexOf('.') + 1);
                if (String.IsNullOrWhiteSpace(articleAttachment.Type))
                {
                    return(BadRequest("Unable to define file type."));
                }
            }
            catch
            {
                return(BadRequest("Unable to define file type."));
            }

            if (articleAttachment.Name == null)
            {
                articleAttachment.Name = "attachment";
            }
            _context.ArticleAttachments.Add(articleAttachment);
            await _context.SaveChangesAsync();

            return(CreatedAtAction("GetArticleAttachment", new { id = articleAttachment.Id }, articleAttachment));
        }
Example #10
0
        public override ArticleAttachment GetArticleAttachment(int id)
        {
            ELParameter idParam = new ELParameter("@AttachmentID", DbType.Int32);

            idParam.Value = id;

            using (IDataReader dr = DataHelper.ExecuteReader(CommandType.StoredProcedure, "sp_ArticleAttachment_Get", idParam))
            {
                ArticleAttachment result = null;
                if (dr.Read())
                {
                    result = ArticleReaderConverter.ParseArticleAttachment(dr);
                }

                return(result);
            }
        }
    private void BindDetail()
    {
        ArticleAttachment attachment = ArticleAttachments.GetAttachment(attachmentID);

        if (attachment != null)
        {
            txtTitle.Text = attachment.Name;
            txtMemo.Text  = attachment.Desc;
            cboAttachmentType.SelectedIndex = attachment.IsRemote ? 1 : 0;
            if (attachment.IsRemote)
            {
                txtUrl.Text = attachment.FileName;
            }
            csAttachment.SelectedValue = attachment.Status;

            ClientScript.RegisterClientScriptBlock(typeof(string), "CheckAttachmentType", "window.onload = function() {CheckAttachmentType();}", true);
        }
    }
Example #12
0
        /// <summary>
        /// 资源
        /// </summary>
        /// <param name="dr"></param>
        /// <returns></returns>
        public static ArticleAttachment ParseArticleAttachment(IDataReader dr)
        {
            ArticleAttachment result = new ArticleAttachment();

            result.ID          = DataRecordHelper.GetInt32(dr, "AttachmentID");
            result.FileName    = DataRecordHelper.GetString(dr, "AttachmentFile");
            result.Name        = DataRecordHelper.GetString(dr, "AttachmentName");
            result.ContentType = DataRecordHelper.GetString(dr, "ContentType");
            result.ContentSize = DataRecordHelper.GetInt32(dr, "ContentSize");
            result.IsRemote    = DataRecordHelper.GetInt32(dr, "IsRemote") > 0;
            result.ImageWidth  = DataRecordHelper.GetNullableInt32(dr, "ImageWidth");
            result.ImageHeight = DataRecordHelper.GetNullableInt32(dr, "ImageHeight");
            result.Desc        = DataRecordHelper.GetString(dr, "AttachmentDesc");
            result.Memo        = DataRecordHelper.GetString(dr, "AttachmentMemo");
            result.Status      = (ComponentStatus)DataRecordHelper.GetInt32(dr, "AttachmentStatus");
            result.CreateTime  = DataRecordHelper.GetDateTime(dr, "CreateTime");
            result.CreateUser  = DataRecordHelper.GetInt32(dr, "CreateUser");
            result.UpdateTime  = DataRecordHelper.GetDateTime(dr, "UpdateTime");
            result.UpdateUser  = DataRecordHelper.GetInt32(dr, "UpdateUser");

            return(result);
        }
Example #13
0
        internal static IArticleAttachmentModel AddAttachment(IDataStore dataStore, int applicationId, IArticleModel articleModel, IUserBasic userBasic, Random random)
        {
            ArticleAttachmentManager articleAttachmentManager = new ArticleAttachmentManager(dataStore);
            ArticleAttachment        attachment = new ArticleAttachment(applicationId, userBasic);
            ArticleManager           manager    = new ArticleManager(dataStore);

            attachment.Content          = Encoding.Unicode.GetBytes("HELLO");
            attachment.ContentSize      = attachment.Content.Length;
            attachment.ContentType      = "text";
            attachment.FileName         = "myfile " + random.Next(1000, 10000) + ".txt";
            attachment.FriendlyFileName = "My File " + random.Next(1000, 10000);

            Assert.AreEqual(DataRepositoryActionStatus.Success, articleAttachmentManager.CreateTemporaryFile(attachment).Status);

            articleModel = manager.GetArticleModel(articleModel.ArticleId);
            int totalAttachments = articleModel.Attachments.Count;

            int articleAttachmentId;

            Assert.IsTrue(articleAttachmentManager.MoveTemporaryFileToFiles(attachment.ArticleAttachmentId, articleModel.ArticleId
                                                                            , attachment.FileName, attachment.FriendlyFileName, out articleAttachmentId));
            Assert.Greater(articleAttachmentId, 0);

            articleModel = manager.GetArticleModel(articleModel.ArticleId);
            Assert.AreEqual(totalAttachments + 1, articleModel.Attachments.Count);

            IArticleAttachmentModel articleAttachmentModel = articleModel.Attachments.Find(c => c.AttachmentId == articleAttachmentId);

            Assert.IsNotNull(articleAttachmentModel);

            Assert.AreEqual(attachment.ContentSize, articleAttachmentModel.ContentSize);
            Assert.AreEqual(attachment.ContentType, articleAttachmentModel.ContentType);
            Assert.AreEqual(attachment.FileName, articleAttachmentModel.FileName);
            Assert.AreEqual(attachment.FriendlyFileName, articleAttachmentModel.FriendlyFileName);
            Assert.AreEqual(attachment.UserId, articleAttachmentModel.UserId);

            return(articleAttachmentModel);
        }
Example #14
0
    void WritePics()
    {
        AttachmentQuery          aq    = new AttachmentQuery();
        List <ArticleAttachment> items = ArticleAttachments.GetAttachments(aq).Records;

        if (items != null && items.Count > 0)
        {
            StringBuilder sb = new StringBuilder();
            foreach (ArticleAttachment a in items)
            {
                if (a.IsRemote)
                {
                    sb.Append("item" + a.ID.ToString() + ":'" + a.FileName + "',");
                }
                else
                {
                    sb.Append("item" + a.ID.ToString() + ":'" + a.GetDefaultImageUrl(40, 40) + "',");
                }
            }
            ArticleAttachment aa = items[0];
            imgTitleImg.ImageUrl = (aa.IsRemote ? aa.FileName : aa.GetDefaultImageUrl(40, 40));
            base.ExecuteJs("var titlePics = {" + sb.ToString().Remove(sb.ToString().Length - 1) + "};", true);
        }
    }
 protected void repArticles_ItemDataBound(object sender, RepeaterItemEventArgs e)
 {
     if (e.Item.Controls.Count > 1)
     {
         Image image = e.Item.Controls[1] as Image;
         if (image != null)
         {
             Article article = e.Item.DataItem as Article;
             if (article != null)
             {
                 // 获取附件
                 ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image);
                 if (attachment != null)
                 {
                     if (attachment.IsRemote)
                     {
                         image.ImageUrl = attachment.FileName;
                     }
                     else
                     {
                         image.ImageUrl = attachment.GetDefaultImageUrl(100, 100);
                     }
                     image.Visible = true;
                 }
                 else
                 {
                     image.Visible = false;
                 }
             }
             else
             {
                 image.Visible = false;
             }
         }
     }
 }
    protected void egvArticles_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Article article = e.Row.DataItem as Article;

            if (article != null)
            {
                Image image = e.Row.FindControl("imgPicture") as Image;

                if (image != null)
                {
                    //image.ImageUrl = article.GetDefaultImageUrl((int)image.Width.Value, (int)image.Height.Value);
                    // 获取附件
                    ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image);
                    if (attachment != null)
                    {
                        string imgPath = "../FileStore/" + ArticleAttachments.FileStoreKey + "/" + attachment.FileName;
                        image.ImageUrl = imgPath;
                        image.Visible  = true;
                    }
                    else
                    {
                        image.Visible = false;
                    }
                }

                HyperLink hyName = e.Row.FindControl("hlName") as HyperLink;
                if (hyName != null)
                {
                    hyName.Text        = article.Title;
                    hyName.NavigateUrl = "#";
                }
            }
        }
    }
Example #17
0
    private void BindData()
    {
        string articleIDStr = Request.QueryString["id"];

        if (!string.IsNullOrEmpty(articleIDStr))
        {
            int articleID;
            if (int.TryParse(HHOnline.Framework.GlobalSettings.Decrypt(articleIDStr), out articleID))
            {
                // 增加点击率
                //ArticleManager.IncreaseHitTimes(articleID);
                BaseViews views = ViewsFactory.GetViews(typeof(ArticleViews));
                views.AddViewCount(articleID);

                Article article = ArticleManager.GetArticle(articleID);
                if (article != null)
                {
                    lblAbstract.InnerHtml = article.Abstract;
                    lblAuthor.Text        = string.IsNullOrEmpty(article.Author) ? "匿名" : article.Author;
                    lblDate.Text          = article.Date.HasValue ? article.Date.Value.ToString() : DateTime.Now.ToString();
                    lblHitTimes.Text      = article.HitTimes.ToString();
                    lblTitle.Text         = article.Title;
                    lblSubTitle.Text      = article.SubTitle;
                    lblKeywords.Text      = string.IsNullOrEmpty(article.Keywords) ? "无" : article.Keywords;

                    // 获取所有产品
                    ProductQuery pq = new ProductQuery();
                    pq.HasPublished = true;
                    List <Product>         products = Products.GetProductList(pq);
                    List <ReplaceKeyValue> rkvs     = new List <ReplaceKeyValue>();

                    foreach (Product item in products)
                    {
                        ReplaceKeyValue rkv = new ReplaceKeyValue();
                        rkv.Key   = item.ProductName;
                        rkv.Value = "<a style='color: blue; text-decoration:underline;' href=\"view.aspx?product-product&ID=" + HHOnline.Framework.GlobalSettings.Encrypt(item.ProductID.ToString()) + "\">" + item.ProductName + "</a>";
                        rkvs.Add(rkv);
                    }

                    FastReplace fr = new FastReplace(rkvs.ToArray());
                    lblContent.InnerHtml = fr.ReplaceAll(article.Content);

                    // 查找分类
                    ArticleCategory ac = ArticleManager.GetArticleCategory(article.Category);
                    if (ac != null)
                    {
                        btnCategory.Text          = ac.Name;
                        btnCategory.OnClientClick = "window.location.href='view.aspx?news-newslist&cate=" + HHOnline.Framework.GlobalSettings.Encrypt(ac.ID.ToString()) + "';return false;";
                    }

                    if (!string.IsNullOrEmpty(article.CopyFrom))
                    {
                        lblCopyForm.Text    = "文章来源: " + article.CopyFrom;
                        lblCopyForm.Visible = true;
                    }
                    else
                    {
                        lblCopyForm.Visible = false;
                    }

                    // 获取附件
                    ArticleAttachment attachment = ArticleAttachments.GetAttachment(article.Image);
                    if (attachment != null)
                    {
                        if (attachment.IsRemote)
                        {
                            imgAttachment.ImageUrl = attachment.FileName;
                        }
                        else
                        {
                            imgAttachment.ImageUrl = attachment.GetDefaultImageUrl(100, 100);
                        }
                        imgAttachment.Visible = true;
                    }
                    else
                    {
                        imgAttachment.Visible = false;
                    }

                    this.ShortTitle = article.Title;
                }
                else
                {
                    imgAttachment.Visible = false;
                }
            }
            this.SetTitle();
        }
    }
        //private bool IsImage(string ext)
        //{
        //  return ext == ".gif" || ext == ".jpg" || ext == ".png";
        //}

        //private string EncodeFile(string fileName)
        //{
        //  return Convert.ToBase64String(System.IO.File.ReadAllBytes(fileName));
        //}

        //static double ConvertBytesToMegabytes(long bytes)
        //{
        //  return (bytes / 1024f) / 1024f;
        //}
        #endregion

        //private void SetValues(string fileName, int fileLength)
        //{
        //  name = fileName;
        //  type = "image/png";
        //  size = fileLength;
        //  progress = "1.0";
        //  url = "/wm/Handlers/Articles/FileUploadHandler.ashx?f=" + fileName; // TODO (Roman): implement proper path
        //  delete_url = "/wm/Handlers/Articles/FileUploadHandler.ashx?f=" + fileName;// TODO (Roman): implement proper path
        //  delete_type = "DELETE";

        //  // TODO (Roman): remove path stuff
        //  var ext = ".txt"; // Path.GetExtension(fullPath);
        //  thumbnail_url = "na.img";
        //  //var fileSize = ConvertBytesToMegabytes(new FileInfo(fullPath).Length);
        //  //if (fileSize > 3 || !IsImage(ext))
        //  //  thumbnail_url = "/Content/img/generalFile.png";
        //  //else
        //  //  thumbnail_url = @"data:image/png;base64," + EncodeFile(fullPath);
        //}

        public FilesStatus(ArticleAttachment attachment, string action) : this(attachment, null, action)
        {
        }
Example #19
0
        public static ArticleAttachment GetAttachment(int id)
        {
            ArticleAttachment result = ArticleAttachmentProvider.Instance.GetArticleAttachment(id);

            return(result);
        }
    protected void btnPost_Click(object sender, EventArgs e)
    {
        if (action == OperateType.Edit)
        {
            int id = int.Parse(Request.QueryString["ID"]);
            ArticleAttachment attachment = ArticleAttachments.GetAttachment(id);

            attachment.Name     = txtTitle.Text;
            attachment.Desc     = txtMemo.Text;
            attachment.IsRemote = cboAttachmentType.SelectedIndex == 1;
            attachment.Memo     = txtMemo.Text;
            attachment.Status   = csAttachment.SelectedValue;

            // 判断是远程则直接更新URL,否则先删除本地文件
            if (cboAttachmentType.SelectedIndex == 1)
            {
                // 远程
                attachment.IsRemote = true;

                // TODO: 删除文件
                string filePath = attachmentLocalPath + attachment.FileName;
                File.Delete(filePath);

                // 更新字段
                attachment.FileName = txtUrl.Text;
            }
            else
            {
                // 本地上传
                attachment.IsRemote = false;

                // TODO: 本地上传
                // 获取扩展名
                string ext = Path.GetExtension(fuLocal.FileName);

                attachment.FileName = Guid.NewGuid().ToString() + ext;
                string filePath = attachmentLocalPath + attachment.FileName;

                fuLocal.SaveAs(filePath);
            }

            attachment.ContentType = MimeTypeManager.GetMimeType(attachment.FileName);
            attachment.UpdateTime  = DateTime.Now;
            attachment.UpdateUser  = Profile.AccountInfo.UserID;

            DataActionStatus status = ArticleAttachments.UpdateArticleAttachment(attachment);

            if (status == DataActionStatus.DuplicateName)
            {
                mbMsg.ShowMsg("修改附件失败,存在同名附件!");
            }
            else if (status == DataActionStatus.UnknownFailure)
            {
                throw new HHException(ExceptionType.Failed, "更新附件信息失败,请联系管理员!");
            }
            else if (status == DataActionStatus.Success)
            {
                throw new HHException(ExceptionType.Success, "操作成功,已成功更新附件!");
            }
        }
        else
        {
            ArticleAttachment attachment = new ArticleAttachment();

            attachment.Name     = txtTitle.Text;
            attachment.Desc     = txtMemo.Text;
            attachment.IsRemote = cboAttachmentType.SelectedIndex == 1;
            attachment.Memo     = txtMemo.Text;
            attachment.Status   = csAttachment.SelectedValue;

            // 判断是远程则直接更新URL
            if (cboAttachmentType.SelectedIndex == 1)
            {
                // 远程
                attachment.IsRemote = true;

                // url字段
                attachment.FileName = txtUrl.Text;
            }
            else
            {
                // 本地上传
                attachment.IsRemote = false;

                // TODO: 本地上传
                string ext = Path.GetExtension(fuLocal.FileName);

                attachment.FileName = Guid.NewGuid().ToString() + ext;

                string filePath = attachmentLocalPath + attachment.FileName;

                fuLocal.SaveAs(filePath);
            }

            attachment.ContentType = MimeTypeManager.GetMimeType(attachment.FileName);
            attachment.CreateTime  = DateTime.Now;
            attachment.CreateUser  = Profile.AccountInfo.UserID;
            attachment.UpdateTime  = DateTime.Now;
            attachment.UpdateUser  = Profile.AccountInfo.UserID;

            DataActionStatus status;
            ArticleAttachments.AddArticleAttachment(attachment, out status);

            if (status == DataActionStatus.DuplicateName)
            {
                throw new HHException(ExceptionType.Failed, "新增附件失败,存在同名附件!");
            }
            else if (status == DataActionStatus.UnknownFailure)
            {
                throw new HHException(ExceptionType.Failed, "新增附件失败,请联系管理员!");
            }
            else if (status == DataActionStatus.Success)
            {
                throw new HHException(ExceptionType.Success, "操作成功,已成功增加一个新的附件!");
            }
        }
    }
Example #21
0
        /// <summary>
        /// 添加附件
        /// </summary>
        /// <param name="info"></param>
        /// <param name="?"></param>
        /// <returns></returns>
        public static ArticleAttachment AddArticleAttachment(ArticleAttachment info, out DataActionStatus status)
        {
            ArticleAttachment result = ArticleAttachmentProvider.Instance.CreateUpdateArticleAttachment(info, DataProviderAction.Create, out status);

            return(result);
        }
 public abstract ArticleAttachment CreateUpdateArticleAttachment(ArticleAttachment info, DataProviderAction action, out DataActionStatus status);
Example #23
0
 public BusinessObjectActionReport <DataRepositoryActionStatus> CreateTemporaryFile(ArticleAttachment articleAttachment)
 {
     return(_CMSFileManager.CreateTemporaryFile(articleAttachment.CMSFile));
 }