Ejemplo n.º 1
0
 public object UpLoadFile()
 {
     try
     {
         //string filePath = Config.FilePath;
         string             webPath  = HttpContext.Current.Server.MapPath("~") + Config.GetSampleConfig().SampleFilePath;
         string             filePath = webPath + @"uploadfile\";
         HttpFileCollection files    = HttpContext.Current.Request.Files;
         string             filename = "";
         string             styleid  = SessionManage.CurrentSample.StyleId;
         foreach (string key in files.AllKeys)
         {
             HttpPostedFile file = files[key];//file.ContentLength文件长度
             if (string.IsNullOrEmpty(file.FileName) == false)
             {
                 //file.SaveAs(HttpContext.Current.Server.MapPath("~/App_Data/Image/") + file.FileName);
                 filename = SessionManage.CurrentSample.StyleId + file.FileName;
                 UploadHelper.FileUpload(file, filePath, filename);
                 //file.SaveAs(filePath + filename);
                 SessionManage.CurrentSample.AddFile(filename, "", file.FileName, FileType.File);
             }
         }
         return(Ok(new { name = filename }));
     }
     catch (Exception e)
     {
         return(BadRequest(e.Message));
     }
 }
Ejemplo n.º 2
0
        public IHttpActionResult UpLoadFile()
        {
            string             webPath  = HttpContext.Current.Server.MapPath("~") + Config.GetSampleConfig().ProofFilePath;
            string             filePath = webPath + @"tempfile\";
            HttpFileCollection files    = HttpContext.Current.Request.Files;
            string             proofId  = HttpContext.Current.Request.Form["ProofStyleId"];

            if (proofId != "")
            {
                string filename = "";
                foreach (string key in files.AllKeys)
                {
                    HttpPostedFile file = files[key];//file.ContentLength文件长度
                    if (string.IsNullOrEmpty(file.FileName) == false)
                    {
                        filename = proofId + "_" + DateTimeHelper.GetDataSecStr() + "_" + file.FileName;
                        UploadHelper.FileUpload(file, filePath, filename);
                    }
                }
                var re = new { name = filename, url = @"\src\proof\tempfile\" + filename };
                return(Ok(re));
            }
            else
            {
                return(BadRequest("申请单号不能为空!"));
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 导入Excell数据
        /// </summary>
        /// <returns></returns>
        public ActionResult ImportExel()
        {
            int       IsOk   = 1;               //导入状态
            DataTable Result = new DataTable(); //导入错误记录表

            try
            {
                string                 moduleId = Request["moduleId"];//表名
                StringBuilder          sb_table = new StringBuilder();
                HttpFileCollectionBase files    = Request.Files;
                HttpPostedFileBase     file     = files["filePath"];                               //获取上传的文件
                string                 fullname = file.FileName;
                string                 IsXls    = System.IO.Path.GetExtension(fullname).ToLower(); //System.IO.Path.GetExtension获得文件的扩展名
                if (IsXls != ".xls" && IsXls != ".xlsx")
                {
                    IsOk = 0;
                }
                else
                {
                    string filename = Guid.NewGuid().ToString() + ".xls";
                    if (fullname.IndexOf(".xlsx", StringComparison.Ordinal) > 0)
                    {
                        filename = Guid.NewGuid().ToString() + ".xlsx";
                    }
                    if (file.FileName != "")
                    {
                        string errMessage = string.Empty;
                        bool   flag       = UploadHelper.FileUpload(file, Server.MapPath("~/Resource/UploadFile/ImportExcel/"), filename, out errMessage);
                    }
                    DataTable dt = ImportExcel.ImportExcelFile(Server.MapPath("~/Resource/UploadFile/ImportExcel/") + filename);
                    IsOk = base_exceliportbll.ImportExcel(moduleId, dt, out Result);
                }
            }
            catch (Exception ex)
            {
                BaseSysLogBll.Instance.WriteLog("", OperationType.Add, "-1", "异常错误:" + ex.Message);
                IsOk = 0;
            }
            if (Result.Rows.Count > 0)
            {
                IsOk = 0;
            }
            var JsonData = new
            {
                Status     = IsOk > 0 ? "true" : "false",
                ResultData = Result
            };

            return(Content(JsonData.ToJson()));
        }
Ejemplo n.º 4
0
        public object UpLoadPic()
        {
            //try
            //{
            //string minPicPath = Config.MinPicPath;
            string             webPath    = HttpContext.Current.Server.MapPath("~") + Config.GetSampleConfig().SampleFilePath;
            string             picPath    = webPath + @"pic\";
            string             minPicPath = webPath + @"pic\MinPic\";
            HttpFileCollection files      = HttpContext.Current.Request.Files;
            string             filename   = "";
            string             styleid    = SessionManage.CurrentSample.StyleId;

            foreach (string key in files.AllKeys)
            {
                HttpPostedFile file = files[key];    //file.ContentLength文件长度
                if (string.IsNullOrEmpty(file.FileName) == false)
                {
                    string fname = DirFileHelper.GetFileName(file.FileName);
                    fname    = fname.Replace("(", string.Empty).Replace(")", string.Empty).Replace(" ", string.Empty);
                    filename = SessionManage.CurrentSample.StyleId + "_" + fname;
                    string filepath = picPath + fname;

                    UploadHelper.FileUpload(file, picPath, fname);
                    //原始文件压缩
                    ImageHelper.MakeSmallImg(filepath, picPath + filename, 1500, 1500);

                    //压缩文件再压缩
                    ImageHelper.MakeSmallImg(filepath, minPicPath + filename, 300, 300);
                    DirFileHelper.DeleteFile(filepath);

                    SessionManage.CurrentSample.AddFile(filename, "", fname, FileType.Pic);
                }
            }
            return(Ok(new { name = filename }));
            //}
            //catch (Exception e)
            //{
            //    return BadRequest(e.Message);
            //}
        }
Ejemplo n.º 5
0
 private void btnUpload_Click(object sender, EventArgs e)
 {
     if (this.Excel.Checked)
     {
         if (!this.fileUploader.HasFile)
         {
             this.ShowMsg("请浏览选择本地Excel文件!", false);
             return;
         }
         if (!UploadHelper.IsExcelFile(this.fileUploader.FileName))
         {
             this.ShowMsg("您选择的文件非Excel文件!", false);
             return;
         }
     }
     else
     {
         if (!this.fileUploader.HasFile)
         {
             this.ShowMsg("请浏览选择本地Csv文件!", false);
             return;
         }
         string extension = Path.GetExtension(this.fileUploader.FileName);
         if (".csv" != extension.ToLower())
         {
             this.ShowMsg("您选择的文件非csv文件!", false);
             return;
         }
     }
     try
     {
         string value = UploadHelper.FileUpload("~/Storage/master/ImportMember", this.fileUploader);
         this.hiddfullPath.Value = value;
     }
     catch (Exception ex)
     {
         this.ShowMsg("文件上传失败!请联系管理员.错误" + ex.Message, false);
     }
 }
Ejemplo n.º 6
0
        public ActionResult AttachmentUpload()
        {
            var result = new FileUploadResult()
            {
                IsSuccess = false
            };
            var files = new List <FileData>();

            foreach (string item in Request.Files)
            {
                HttpPostedFileBase file     = Request.Files[item];
                string             fileName = Path.GetFileName(file.FileName);
                int    filesize             = file.ContentLength;               //获取上传文件的大小单位为字节byte
                string fileEx     = Path.GetExtension(fileName);                //获取上传文件的扩展名
                string NoFileName = Path.GetFileNameWithoutExtension(fileName); //获取无扩展名的文件名
                int    maxByte    = 10;
                long   Maxsize    = maxByte * 1024 * 1024;                      //定义上传文件的最大空间大小为10M
                string FileType   = ".exe,.bat";                                //定义上传文件的类型字符串

                if (FileType.Contains(fileEx))
                {
                    result.Message = "can't upload .exe and .bat";
                    return(Content(JsonHelper.JsonSerializer(result)));
                }
                if (filesize >= Maxsize)
                {
                    result.Message = string.Format("file size can't big than {0} MB", maxByte);
                    return(Content(JsonHelper.JsonSerializer(result)));
                }
                files.Add(UploadHelper.FileUpload(file, Server.MapPath(@"\")));
            }
            result.data = files;
            if (files.Count > 0)
            {
                result.IsSuccess = true;
            }
            return(Content(JsonHelper.JsonSerializer(result)));
        }
Ejemplo n.º 7
0
        public IHttpActionResult UpLoadFile()
        {
            string             webPath     = HttpContext.Current.Server.MapPath("~") + Config.GetSampleConfig().ProofFilePath;
            string             filePath    = webPath + @"gyzb\";
            HttpFileCollection files       = HttpContext.Current.Request.Files;
            string             proofId     = HttpContext.Current.Request.Form["ProofOrderId"];
            string             TaskId      = HttpContext.Current.Request.Form["TaskId"];
            string             ProcessName = HttpContext.Current.Request.Form["ProcessName"];
            ProofFile          pf          = new ProofFile();

            if (proofId != "" && TaskId != "" && ProcessName != "")
            {
                string filename = "";
                string url      = "";
                foreach (string key in files.AllKeys)
                {
                    HttpPostedFile file = files[key];//file.ContentLength文件长度
                    if (string.IsNullOrEmpty(file.FileName) == false)
                    {
                        string DisplayName = file.FileName;
                        filename = proofId + "_" + ProcessName + "_" + DateTimeHelper.GetDataSecStr() + "_" + file.FileName;
                        UploadHelper.FileUpload(file, filePath, filename);
                        url = @"\src\proof\gyzb\" + filename;
                        ProofTaskOper pto = new ProofTaskOper(SessionManage.CurrentUser);
                        int           tid = int.Parse(TaskId);
                        pf = pto.AddProofFile(tid, proofId, filename, DisplayName, url, ProcessName);
                    }
                }

                return(Ok(pf));
            }
            else
            {
                return(BadRequest("上传文件参数错误!"));
            }
        }
Ejemplo n.º 8
0
        /// <summary>
        /// 商品导入
        /// </summary>
        /// <returns></returns>
        public ActionResult SubmitImportProduct()
        {
            bool   isSuccess = false;            //导入状态
            string errMessage;
            var    dataResult = new DataTable(); //导入错误记录表

            try
            {
                HttpFileCollectionBase files = Request.Files;
                HttpPostedFileBase     file  = files["filePath"];//获取上传的文件
                if (file != null && file.FileName != "")
                {
                    string fullname  = file.FileName;
                    var    extension = System.IO.Path.GetExtension(fullname);
                    if (extension != null)
                    {
                        string fileType = extension.ToLower();
                        if (fileType == ".xls" || fileType == ".xlsx")
                        {
                            string fileId   = Guid.NewGuid().ToString();
                            string filename = fileId + fileType;

                            bool flag = UploadHelper.FileUpload(file, Server.MapPath("~/UploadFile/ImportProduct/"),
                                                                filename, out errMessage);
                            if (flag)
                            {
                                ProductImportFileEntity importFile = new ProductImportFileEntity();
                                importFile.Create();
                                importFile.FileId   = fileId;
                                importFile.FileName = fullname;

                                DataTable dt = ImportExcel.ImportExcelFile(Server.MapPath("~/UploadFile/ImportProduct/") + filename);
                                flag = _productService.ImportProduct(importFile, dt, out dataResult, out errMessage);
                                if (flag)
                                {
                                    isSuccess = true;
                                }
                            }
                            else
                            {
                                throw new Exception("商品导入失败:" + errMessage);
                            }
                        }
                        else
                        {
                            throw new Exception("商品导入失败:文件格式不正确");
                        }
                    }
                    else
                    {
                        throw new Exception("商品导入失败:文件格式不正确");
                    }
                }
                else
                {
                    throw new Exception("请选择上传文件");
                }
            }
            catch (Exception ex)
            {
                BaseSysLogBll.Instance.WriteLog("", OperationType.Add, "-1", "异常错误:" + ex.Message);
                errMessage = ex.Message;
                isSuccess  = false;
            }

            if (dataResult.Rows.Count > 0)
            {
                isSuccess = false;
            }
            var data = new
            {
                status  = isSuccess ? "true" : "false",
                result  = dataResult,
                message = errMessage
            };

            return(Content(data.ToJson()));
        }
Ejemplo n.º 9
0
        public JsonResult AddFiles()
        {
            var typeId   = Request["typeId"].ToInt32();
            var departId = Request["depart"].ToInt32();

            if (typeId == 0 || departId == 0)
            {
                return(Json(new { msg = ErrorModel.InputError }));
            }

            // 将文件保存到本地
            var uploadRes    = UploadHelper.FileUpload();
            var filePathInfo = uploadRes as FilePathInfo;

            if (filePathInfo == null)
            {
                return(Json(new { msg = uploadRes }));
            }

            var fileBll = new TraficFilesBll();

            // 验证文件是否重名
            var condition = $"IsDelete=0 AND TypeId={typeId} AND FileName='{filePathInfo.OriginalFileName}'";

            if (fileBll.Exists(condition))
            {
                return(Json(ErrorModel.FileExists));
            }

            var loginUser = LoginStatus.GetLoginId();
            var fileModel = new TraficFiles
            {
                FileExtension  = filePathInfo.FileExtension,
                FileName       = filePathInfo.OriginalFileName,
                FilePath       = filePathInfo.FileRelativePath,
                OriginFilePath = filePathInfo.FileRelativePath,
                FileSize       = filePathInfo.FileSize,
                TypeId         = typeId,
                CreatorId      = loginUser,
                DepartmentId   = departId
            };

            var logBll = new OperateLogBll();
            var dirBll = new TraficFileTypeBll();
            var dir    = dirBll.QuerySingle(typeId);
            var log    = $"在目录[{dir.TypeName}]下添加了文件《{filePathInfo.OriginalFileName}》";

            // 执行插入操作、数据库更新日志插入操作以及后台操作日志插入操作
            var success = fileBll.ExecuteTransation(
                () => fileBll.Insert(fileModel).Id > 0,
                () => DataUpdateLog.SingleUpdate(nameof(TraficFiles), fileModel.Id, DataUpdateType.Insert),
                () => logBll.Add(nameof(TraficFiles), fileModel.Id, DataUpdateType.Insert, loginUser, log)
                );

            if (success)
            {
                // 开启新线程执行将 office 文件转换为 html 的任务
                // 以避免阻塞网络请求线程,造成用户长时间的等待
                Task.Factory.StartNew(() => FormatFile(fileModel));

                return(Json(new
                {
                    msg = ErrorModel.OperateSuccess,
                    data = uploadRes,
                    fileId = fileModel.Id,
                    fileModel
                }));
            }

            return(Json(new { msg = ErrorModel.OperateFailed }));
        }
Ejemplo n.º 10
0
        public JsonResult FileUpload()
        {
            var uploadRes = UploadHelper.FileUpload();

            return(Json(uploadRes));
        }
Ejemplo n.º 11
0
        /// <summary>
        /// 订单导入
        /// </summary>
        /// <returns></returns>
        public ActionResult SubmitImportOrder()
        {
            bool   isSuccess  = false;           //导入状态
            string errMessage = string.Empty;
            var    dataResult = new DataTable(); //导入错误记录表

            try
            {
                string WarehouseId = Request.Form["WarehouseId"];
                if (string.IsNullOrEmpty(WarehouseId))
                {
                    throw new Exception("上传文件失败:请选择默认出货仓库");
                }
                string MerchantId = HttpContext.Request.Form["MerchantId"];
                if (string.IsNullOrEmpty(MerchantId))
                {
                    throw new Exception("上传文件失败:请选择订单所属商户");
                }
                string MerchantMallId = HttpContext.Request.Form["MerchantMallId"];
                if (string.IsNullOrEmpty(MerchantMallId))
                {
                    throw new Exception("上传文件失败:请选择订单所属店铺");
                }

                HttpFileCollectionBase files = Request.Files;
                HttpPostedFileBase     file  = files["filePath"];//获取上传的文件
                if (file != null && file.FileName != "")
                {
                    string fullname  = file.FileName;
                    var    extension = System.IO.Path.GetExtension(fullname);
                    if (extension != null)
                    {
                        string fileType = extension.ToLower();
                        if (fileType == ".xls" || fileType == ".xlsx")
                        {
                            string fileId   = Guid.NewGuid().ToString();
                            string filename = fileId + fileType;

                            bool flag = UploadHelper.FileUpload(file, Server.MapPath("~/UploadFile/ImportOrder/"),
                                                                filename, out errMessage);
                            if (flag)
                            {
                                SaleOrderImportFileEntity importFile = new SaleOrderImportFileEntity();
                                importFile.Create();
                                importFile.FileId         = fileId;
                                importFile.WarehouseId    = WarehouseId;
                                importFile.MerchantId     = MerchantId;
                                importFile.MerchantMallId = MerchantMallId;
                                importFile.FileName       = fullname;

                                DataTable dt = ImportExcel.ImportExcelFile(Server.MapPath("~/UploadFile/ImportOrder/") + filename);
                                flag = _orderService.ImportOrder(importFile, dt, out dataResult, out errMessage);
                                if (flag)
                                {
                                    isSuccess = true;
                                }
                            }
                            else
                            {
                                throw new Exception("订单导入失败:" + errMessage);
                            }
                        }
                        else
                        {
                            throw new Exception("订单导入失败:文件格式不正确");
                        }
                    }
                    else
                    {
                        throw new Exception("订单导入失败:文件格式不正确");
                    }
                }
                else
                {
                    throw new Exception("请选择上传文件");
                }
            }
            catch (Exception ex)
            {
                BaseSysLogBll.Instance.WriteLog("", OperationType.Add, "-1", "异常错误:" + ex.Message);
                errMessage = ex.Message;
                isSuccess  = false;
            }

            if (dataResult.Rows.Count > 0)
            {
                isSuccess = false;
            }
            var data = new
            {
                status  = isSuccess ? "true" : "false",
                result  = dataResult,
                message = errMessage
            };

            return(Content(data.ToJson()));
        }
Ejemplo n.º 12
0
        public JsonResult FileUpload()
        {
            var pathInfo = UploadHelper.FileUpload();

            return(Json(pathInfo));
        }