Esempio n. 1
0
        /// <summary>
        /// 保存实体数据.
        /// </summary>
        public void Save(ContactModel model, HttpFileCollectionBase Files)
        {
            model.ItemCode = Guid.NewGuid().ToString();
            model.CreatId  = LoginHelper.LoginUser.UserId;
            model.Creator  = LoginHelper.LoginUser.UserName;

            if (model.ContactId == 0)
            {
                DBProvider.ContactDAO.Add(model);
            }
            else
            {
                DBProvider.ContactDAO.Update(model);
            }

            BusinessAttachmentModel businessAttach = null;

            if (Files != null && Files.Count > 0 && Files[0].ContentLength > 0)
            {
                IList <BusinessAttachmentModel> businessAttachList = ServiceProvider.BusinessAttachmentService.GetByBusinessTypeAndId(Constants.AttachmentBusinessType.联络单.GetHashCode(), model.ContactId);
                //如果原来有附件,删除原来的
                if (businessAttachList.Count > 0 && businessAttachList.First() != null)
                {
                    businessAttach = businessAttachList.First();
                    Global.Business.ServiceProvider.AttachmentService.DeleteById(businessAttach.FileId);
                    ServiceProvider.BusinessAttachmentService.DeleteById(businessAttach.Id);
                }
                businessAttach = new BusinessAttachmentModel();
                businessAttach.BusinessType  = Constants.AttachmentBusinessType.联络单.GetHashCode();
                businessAttach.BusinessKeyId = model.ContactId;
                businessAttach.UserName      = LoginHelper.LoginUser.UserName;
                ServiceProvider.BusinessAttachmentService.UploadBusinessAttachment("", businessAttach, Files);
            }
        }
Esempio n. 2
0
 /// <summary>
 /// 保存实体数据.
 /// </summary>
 public void Save(BusinessAttachmentModel model)
 {
     if (model.Id == 0)
     {
         DBProvider.BusinessAttachmentDao.Add(model);
     }
     else
     {
         DBProvider.BusinessAttachmentDao.Update(model);
     }
 }
Esempio n. 3
0
        /// <summary>
        /// 删除记录.
        /// </summary>
        public void DeleteById(int Id)
        {
            //找出记录
            BusinessAttachmentModel model = GetById(Id);

            if (model != null)
            {
                Global.Business.ServiceProvider.AttachmentService.DeleteById(model.FileId);
            }
            DBProvider.BusinessAttachmentDao.DeleteById(Id);
        }
Esempio n. 4
0
 public ActionResult UpdateRemark(int id, string remark)
 {
     try
     {
         BusinessAttachmentModel model = new BusinessAttachmentModel();
         model.Id     = id;
         model.Remark = UtilsHelper.SpecialCharValidate(remark);
         ServiceProvider.BusinessAttachmentService.UpdateRemark(model);
     }
     catch (Exception ex)
     {
         log.Error(ex);
         return(Content(ex.Message));
     }
     return(Content("OK"));
 }
Esempio n. 5
0
        /// <summary>
        /// 上传业务附件-自动解压 Add by Raven 2014-12-31
        /// </summary>
        /// <param name="businessNumber"></param>
        /// <param name="model"></param>
        /// <param name="Files"></param>
        public void UploadBusinessAttachmentbyExtract(string businessNumber, BusinessAttachmentModel model, HttpFileCollectionBase Files)
        {
            string targetDir = GetByBusinessTypeAndId((Constants.AttachmentBusinessType)model.BusinessType, businessNumber);
            //获取后缀名
            string Extension = System.IO.Path.GetExtension(Files[0].FileName).ToLower();

            ToolsLib.FileService.FileCompress fc = new ToolsLib.FileService.FileCompress();
            //解压包的路径
            string newFile = ToolsLib.Utility.CommonUtils.GetPhysicsPath("/tempFile/" + Guid.NewGuid().ToString() + Extension);

            //保存
            Files[0].SaveAs(newFile);
            string ExtractDir = ToolsLib.Utility.CommonUtils.GetPhysicsPath("/tempFile/" + Guid.NewGuid().ToString());
            string ext        = fc.Extract(newFile, ExtractDir);

            //解压后删除临时文件
            File.Delete(newFile);
            //获取目录下的文件
            string[] fileList = Directory.GetFiles(ExtractDir, "*", SearchOption.AllDirectories);

            AttachmentModel         attachment = null;
            BusinessAttachmentModel newmodel   = null;

            foreach (var file in fileList)
            {
                attachment             = new AttachmentModel();
                newmodel               = new BusinessAttachmentModel();
                newmodel.BusinessKeyId = model.BusinessKeyId;
                newmodel.BusinessType  = model.BusinessType;
                newmodel.UserName      = LoginHelper.LoginUser.UserName;
                string fileName       = Guid.NewGuid().ToString();
                string targetFileName = string.Format(@"{0}{1}{2}", targetDir, fileName, Path.GetExtension(file));

                //原始记录上传操作
                attachment = UtilsHelper.FileUpload(file, targetFileName, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));
                //入库
                Global.Business.ServiceProvider.AttachmentService.Save(attachment);
                newmodel.FileId   = attachment.FileId;
                newmodel.FileName = attachment.FileName;
                Save(newmodel);
                //删除临时文件
                File.Delete(file);
            }
            //删除目录
            Directory.Delete(ExtractDir, true);
        }
Esempio n. 6
0
        public ActionResult UploadBusinessAttachment(int businessType, string businessKeyId, string businessNumber, FormCollection collection)
        {
            BusinessAttachmentModel model = new BusinessAttachmentModel();

            try
            {
                //是否需要自动解压缩
                bool isExtract = collection["isExtract"] == null ? false : true;

                model.BusinessType  = businessType;
                model.BusinessKeyId = UtilsHelper.Decrypt2Int(businessKeyId);
                model.UserName      = LoginHelper.LoginUser.UserName;
                //获取后缀名
                string Extension = System.IO.Path.GetExtension(Request.Files[0].FileName).ToLower();
                if (isExtract)
                {
                    switch (Extension)
                    {
                    case ".zip":
                    case ".bz":
                    case ".gz":
                        ServiceProvider.BusinessAttachmentService.UploadBusinessAttachmentbyExtract(businessNumber, model, Request.Files);
                        break;

                    default:
                        ServiceProvider.BusinessAttachmentService.UploadBusinessAttachment(businessNumber, model, Request.Files);
                        break;
                    }
                }
                else
                {
                    ServiceProvider.BusinessAttachmentService.UploadBusinessAttachment(businessNumber, model, Request.Files);
                }
            }
            catch (Exception ex)
            {
                log.Error(ex);
                return(Content(ex.Message + "_-1"));
            }
            return(Content("OK_" + model.FileId));
        }
Esempio n. 7
0
        /// <summary>
        /// 上传业务附件
        /// </summary>
        /// <param name="businessNumber"></param>
        /// <param name="model"></param>
        /// <param name="Files"></param>
        public void UploadBusinessAttachment(string businessNumber, BusinessAttachmentModel model, HttpFileCollectionBase Files)
        {
            AttachmentModel attachment = new AttachmentModel();
            string          targetDir  = GetByBusinessTypeAndId((Constants.AttachmentBusinessType)model.BusinessType, businessNumber);


            //默认随机名
            string fileName = Guid.NewGuid().ToString();

            string targetFile = string.Format(@"{0}{1}{2}", targetDir, fileName, System.IO.Path.GetExtension(Files[0].FileName));

            //原始记录上传操作
            attachment = UtilsHelper.FileUpload(Files[0].InputStream, Files[0].FileName, targetFile, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));

            //入库
            Global.Business.ServiceProvider.AttachmentService.Save(attachment);
            model.FileId   = attachment.FileId;
            model.FileName = attachment.FileName;

            Save(model);
        }
Esempio n. 8
0
 //保存仪器照片
 public void SaveInstrumentPic(HttpFileCollectionBase Files, int instrumentId)
 {
     if (Files["InstrumentPic"] != null)
     {
         //保存仪器图片
         string          targetPath = WebUtils.GetSettingsValue("InstrumentPicFilePath");
         string          targetFile = string.Format(@"{0}/{1}{2}", targetPath, StrUtils.GetUniqueFileName(null), Path.GetExtension(Files["InstrumentPic"].FileName));
         AttachmentModel attModel   = UtilsHelper.FileUpload(Files["InstrumentPic"], targetFile, (UtilConstants.ServerType)Convert.ToInt32(WebUtils.GetSettingsValue("WebFileType") == null ? "1" : WebUtils.GetSettingsValue("WebFileType")));
         attModel.FileType = (int)Instrument.Common.Constants.AttachmentBusinessType.仪器照片;
         attModel.UserId   = LoginHelper.LoginUser.UserId;
         attModel.UserName = LoginHelper.LoginUser.UserName;
         Global.Business.ServiceProvider.AttachmentService.Save(attModel);
         BusinessAttachmentModel businessAttachmentModel = new BusinessAttachmentModel();
         businessAttachmentModel.BusinessKeyId = instrumentId;
         businessAttachmentModel.BusinessType  = attModel.FileType;
         businessAttachmentModel.UserName      = LoginHelper.LoginUser.UserName;
         businessAttachmentModel.FileName      = attModel.FileName;
         businessAttachmentModel.FileId        = attModel.FileId;
         Instrument.Business.ServiceProvider.BusinessAttachmentService.Save(businessAttachmentModel);
     }
 }
Esempio n. 9
0
 /// <summary>
 /// 更新备注
 /// </summary>
 public void UpdateRemark(BusinessAttachmentModel model)
 {
     DBProvider.BusinessAttachmentDao.UpdateRemark(model);
 }
 /// <summary>
 /// 更新备注
 /// </summary>
 public void UpdateRemark(BusinessAttachmentModel model)
 {
     DBProvider.dbMapper.Update("Business_Attachment.UpdateRemark", model);
 }
 /// <summary>
 /// 增加一条数据.
 /// </summary>
 public void Add(BusinessAttachmentModel model)
 {
     DBProvider.dbMapper.Insert("Business_Attachment.Insert", model);
 }