Esempio n. 1
0
        public ActionResult NewUpload(HttpPostedFileBase fileData, string guid, string number)
        {
            try
            {
                var files = Request.Files;
                if (files != null && files.Count > 0)
                {
                    Stream fileStream     = Request.Files[0].InputStream;
                    byte[] fileDataStream = new byte[Request.Files[0].ContentLength];
                    fileStream.Read(fileDataStream, 0, Request.Files[0].ContentLength);
                    T_Attachment entity = new T_Attachment();
                    entity.A_GUID     = Guid.NewGuid().ToString();
                    entity.FileName   = Request.Files[0].FileName;
                    entity.FileType   = Request.Files[0].ContentType;
                    entity.FR_GUID    = guid;
                    entity.FlieData   = fileDataStream;
                    entity.Number     = number;
                    entity.FileRemark = "";

                    bool rResult = new AttachmentSvc().AddAttachment(entity);
                    return(Content(rResult.ToString()));
                }
                else
                {
                    return(Content("false"));
                }
            }
            catch (Exception ex)
            {
                return(Content("false"));
            }
        }
        private static T_Attachment CreateAttach(string name, string filePath, int size, string contentType)
        {
            if (!CheckFilePath(filePath))
            {
                throw new Exception("文件不存在!");
            }
            T_Attachment attachment = new T_Attachment {
                FileName      = Path.GetFileName(filePath),
                DisplayName   = name,
                FileSize      = new int?(size),
                FilePath      = filePath,
                ContentType   = contentType,
                FileExtension = Path.GetExtension(name),
                FileData      = GetFileData(filePath)
            };

            if (attachment.FileSize == -1)
            {
                attachment.FileSize = new int?(attachment.FileData.Length);
            }
            int?fileSize = attachment.FileSize;
            int length   = attachment.FileData.Length;

            if ((fileSize.GetValueOrDefault() != length) || !fileSize.HasValue)
            {
                throw new Exception("文件长度异常,文件可能已损坏!");
            }
            return(attachment);
        }
 public virtual int SaveAttachment(T_Attachment attach)
 {
     if (File.Exists(attach.FilePath))
     {
         File.Delete(attach.FilePath);
     }
     return(this.Save(attach));
 }
        private T_Attachment GetFileFromDB(int id)
        {
            T_Attachment attachment = this._context.FindById <T_Attachment>(new object[] { id });

            if (attachment != null)
            {
                return(attachment);
            }
            return(null);
        }
        public static int GetPercent(T_Attachment p)
        {
            int?nullable;

            if (!(p.FileSize.HasValue && !(((nullable = p.FileSize).GetValueOrDefault() == p.FileData.Length) && nullable.HasValue)))
            {
                return(100);
            }
            double a = (p.FileData.Length * 100.0) / ((double)p.FileSize.Value);

            return((int)Math.Ceiling(a));
        }
        private int Save(T_Attachment attachment)
        {
            int num;

            try
            {
                attachment.Attachment_ID = this._context.GetNextIdentity_Int(false);
                this._context.Insert(attachment);
                num = attachment.Attachment_ID;
            }
            catch (ApplicationException exception)
            {
                throw exception;
            }
            return(num);
        }
        /// <summary>
        /// 更新附件备注
        /// </summary>
        /// <param name="attachenmt"></param>
        /// <returns></returns>
        public string UpdAttachment(T_Attachment attachenmt)
        {
            string msg    = string.Empty;
            bool   result = new AttachmentSvc().UpdAttachment(attachenmt.A_GUID, attachenmt.FileName, attachenmt.FileRemark);

            if (result)
            {
                msg = General.Resource.Common.Success;
            }
            else
            {
                msg = General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
Esempio n. 8
0
        private void SaveAttachmentOwnerForAttachmentList(IEntitySchema es, object entity)
        {
            T_AttachmentList list = entity as T_AttachmentList;

            if ((list.Attachment_ID.HasValue && list.EntityId.HasValue) && list.ObjectID.HasValue)
            {
                string       entityNameById = this.GetEntityNameById(list.EntityId.Value);
                int          num            = list.ObjectID.Value;
                T_Attachment attach         = this._attachHandler.GetAttachment(list.Attachment_ID.Value);
                if (attach != null)
                {
                    attach.OwnerEntityType = entityNameById;
                    attach.OwnerObjectId   = new int?(num);
                    this._attachHandler.UpdateAttachment(attach, p => new { OwnerEntityType = p.OwnerEntityType, OwnerObjectId = p.OwnerObjectId });
                }
            }
        }
        /// <summary>
        /// 修改附件名称
        /// </summary>
        /// <param name=""></param>
        /// <returns></returns>
        /// <remarks>hdy   2017/03/09   create</remarks>
        public string UpdHaveFileUpload(T_Attachment form)
        {
            bool   result = false;
            string msg    = string.Empty;

            result = new AttachmentSvc().UpdHaveFileUpload(form);
            if (result)
            {
                msg = General.Resource.Common.Success;
            }
            else
            {
                msg = General.Resource.Common.Failed;
            }
            return(string.Format("{{\"Result\":{0},\"Msg\":\"{1}\"}}"
                                 , result.ToString().ToLower(), msg));
        }
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="frGuid"></param>
        /// <returns></returns>
        /// <remarks>liujf   2016/05/05   create</remarks>
        public ActionResult FileUpload(string frGuid, string TempFileNameFirst)
        {
            var        files = Request.Files;
            ExceResult res   = new ExceResult();
            //获取当前时间戳
            string CreateDate = GetDetailDate();

            if (files != null && files.Count > 0)
            {
                ControllerContext.HttpContext.Request.ContentEncoding  = Encoding.GetEncoding("UTF-8");
                ControllerContext.HttpContext.Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
                ControllerContext.HttpContext.Response.Charset         = "UTF-8";

                //写入数据流
                Stream fileStream     = files[0].InputStream;
                byte[] fileDataStream = new byte[files[0].ContentLength];
                fileStream.Read(fileDataStream, 0, files[0].ContentLength);



                //写入数据

                for (int iFile = 0; iFile < files.Count; iFile++)
                {
                    T_Attachment entity = new T_Attachment();
                    entity.A_GUID   = Guid.NewGuid().ToString();
                    entity.FileName = TempFileNameFirst + CreateDate;
                    entity.FileType = files[0].ContentType;
                    entity.FR_GUID  = frGuid;
                    entity.FlieData = fileDataStream;

                    bool rResult = new AttachmentSvc().AddAttachment(entity);
                    if (rResult)
                    {
                        res.success = true;
                    }
                    else
                    {
                        res.success = false;
                        res.msg     = "保存附件异常";
                    }
                }
            }

            return(Content(Newtonsoft.Json.JsonConvert.SerializeObject(res)));
        }
Esempio n. 11
0
 private void SaveAttachmentOwnerForCommonEntities(IEntitySchema es, object entity)
 {
     if (es.FilePropertys.Count > 0)
     {
         foreach (string str in es.FilePropertys)
         {
             int?nullable = Convert.ToString(entity.GetPropertyValue(str, null)).ToIntNullable();
             if (nullable.HasValue)
             {
                 T_Attachment attach = this._attachHandler.GetAttachment(nullable.Value);
                 if (attach != null)
                 {
                     attach.OwnerEntityType = es.EntityName;
                     attach.OwnerObjectId   = Convert.ToString(entity.GetPropertyValue(es.KeyName, null)).ToIntNullable();
                     this._attachHandler.UpdateAttachment(attach, p => new { OwnerEntityType = p.OwnerEntityType, OwnerObjectId = p.OwnerObjectId });
                 }
             }
         }
     }
 }
Esempio n. 12
0
        public void ToDownLoadFile()
        {
            T_Attachment atta = this.DataHelper.FindById <T_Attachment>(FileId);

            if (atta != null)
            {
                byte[] fileByte = atta.FileData;//二进制字段内容
                string fileName = atta.DisplayName;
                Response.Clear();
                Response.AppendHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8));//设置编码,解决下载文件名乱码
                Response.AppendHeader("Content-Length", fileByte.Length.ToString());
                Response.ContentType = "application/octet-stream";
                Response.OutputStream.Write(fileByte, 0, fileByte.Length);
                Response.End();
            }
            else
            {
                this.AjaxAlert("不存在");
            }
        }
Esempio n. 13
0
        /// 新增/编辑 图片
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public bool AddAttachment(T_Attachment entity)
        {
            DBHelper db = new DBHelper();

            db.strCmd = "SP_AddAttachment";
            db.AddPare("@A_GUID", SqlDbType.NVarChar, 50, entity.A_GUID);
            db.AddPare("@FileName", SqlDbType.NVarChar, 200, entity.FileName);
            db.AddPare("@FileType", SqlDbType.NVarChar, 50, entity.FileType);
            db.AddPare("@FR_GUID", SqlDbType.NVarChar, 50, entity.FR_GUID);
            db.AddPare("@FlieData", SqlDbType.VarBinary, 2147483647, entity.FlieData);
            db.AddPare("@FileRemark", SqlDbType.NVarChar, 200, entity.FileRemark = null);
            try
            {
                db.NonQuery();
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Esempio n. 14
0
        public bool UpdHaveFileUpload(T_Attachment form)
        {
            DBHelper dh = new DBHelper();

            dh.BeginTran();
            try
            {
                dh.strCmd = "SP_UpdAttachmentName";

                dh.AddPare("@A_GUID", SqlDbType.NVarChar, 40, form.A_GUID);
                dh.AddPare("@FileName", SqlDbType.NVarChar, 200, form.FileName);
                dh.NonQuery();
                dh.CleanPara();
                dh.CommitTran();
                return(true);
            }
            catch
            {
                dh.RollBackTran();
                return(false);
            }
        }
Esempio n. 15
0
        /// <summary>
        /// 上传图片
        /// </summary>
        /// <param name="fileData">上传文件</param>
        /// <param name="guid"></param>
        /// <param name="folder"></param>
        /// <returns></returns>
        //[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult Upload(HttpPostedFileBase fileData, string guid, string folder)
        {
            DelAttachment(guid);
            if (fileData != null)
            {
                try
                {
                    ControllerContext.HttpContext.Request.ContentEncoding  = Encoding.GetEncoding("UTF-8");
                    ControllerContext.HttpContext.Response.ContentEncoding = Encoding.GetEncoding("UTF-8");
                    ControllerContext.HttpContext.Response.Charset         = "UTF-8";

                    //写入数据流
                    Stream fileStream     = fileData.InputStream;
                    byte[] fileDataStream = new byte[fileData.ContentLength];
                    fileStream.Read(fileDataStream, 0, fileData.ContentLength);
                    //写入数据
                    T_Attachment entity = new T_Attachment();
                    entity.A_GUID     = Guid.NewGuid().ToString();
                    entity.FileName   = fileData.FileName;
                    entity.FileType   = fileData.ContentType;
                    entity.FR_GUID    = guid;
                    entity.FlieData   = fileDataStream;
                    entity.FileRemark = "";


                    bool rResult = new AttachmentSvc().AddAttachment(entity);
                    return(Content(rResult.ToString()));
                }
                catch (Exception ex)
                {
                    return(Content("false"));
                }
            }
            else
            {
                return(Content("false"));
            }
        }
 public virtual void UpdateAttachment(T_Attachment att)
 {
     this._context.Update(att);
 }
Esempio n. 17
0
        private async static Task SaveInfomationDetail(string pageSource, T_Information info, XmlNode infoNode, BizDataContext db, v_crawler crawler, string detailUrl)
        {
            var rootNode = CommonHelper.GetRootNode(pageSource);

            if (info != null)
            {
                var xmlRoot = infoNode.SelectSingleNode("DataDetail");

                var detailHost = new Regex(@"\S+/").Match(detailUrl).Value;

                //新闻解析应该包含多个子节点,每个子节点表示一个属性,这里进行循环赋值
                foreach (XmlNode property in xmlRoot.ChildNodes)
                {
                    info = CommonHelper.GetProperty(info, rootNode, property, detailHost);
                }


                var info_infotag = new T_InfoType_Information()
                {
                    InfoType_Information_Id = await db.GetNextIdentity_IntAsync(),
                    CreateTime    = DateTime.Now,
                    InformationId = info.Information_Id,
                    InfoTypeId    = crawler.infotype,
                };

                var informationcontent = new T_Information_Content()
                {
                    Information_Content_Id = await db.GetNextIdentity_IntAsync(),
                    Conent      = info.Content,
                    ContentType = (int)Information_Content_ContentTypeEnum.TextWords,

                    OrderIndex    = 0,
                    InformationId = info.Information_Id,
                    State         = 0,
                    CreateTime    = DateTime.Now,
                };

                info.ClassifyId  = (int)InfoSource.Crawler;
                info.PublishTime = info.CreateTime;
                info.IsTop       = false;



                if (!string.IsNullOrEmpty(informationcontent.Conent))
                {
                    var regex    = new Regex("<img.*?>");
                    var imgMtach = regex.Match(info.Content);
                    if (imgMtach.Success)
                    {
                        var img      = imgMtach.Value;
                        var srcMatch = new Regex("src=\".*?\"").Match(img);
                        if (srcMatch.Success)
                        {
                            var src = srcMatch.Value;

                            var att = new T_Attachment()
                            {
                                Attachment_ID = await db.GetNextIdentity_IntAsync(),
                                FilePath      = src,

                                State      = 0,
                                CreateTime = DateTime.Now,
                            };
                            await db.InsertAsync(att);
                        }
                    }

                    await db.InsertAsync(info);

                    await db.InsertAsync(info_infotag);

                    await db.InsertAsync(informationcontent);
                }
            }
        }
        public static string GetJsonFromAttachment(T_Attachment atm)
        {
            JavaScriptSerializer serializer = new JavaScriptSerializer();

            return(serializer.Serialize(new { id = Guid.NewGuid().ToString(), name = atm.DisplayName, size = atm.FileSize, loaded = atm.FileData.Length, percent = GetPercent(atm), status = 5 }));
        }
 public virtual void UpdateAttachment(T_Attachment att, Expression <Func <T_Attachment, object> > cols)
 {
     this._context.UpdatePartial <T_Attachment>(att, cols);
 }
 public virtual void DeleteAttachment(T_Attachment att)
 {
     this._context.Delete(att);
 }