public string ReplyDocument_Upload(long customer, string customerName) { //新路径 string uploadFolderPath = Runbow.TWS.Common.Constants.UPLOAD_AMS_PATH; string targetPath = Path.Combine(uploadFolderPath, customerName, DateTime.Now.ToString("yyyy-MM")); DateTime createDate; string url = string.Empty, actualNameInServer = string.Empty, displayName = string.Empty, ext = string.Empty; IList <AMSUpload> amsUpload = new List <AMSUpload>(); if (string.IsNullOrEmpty(targetPath) || !Path.IsPathRooted(targetPath)) { return(new { msg = "程序出错!" }.ToJsonString()); } if (Request.Files.Count > 0) { HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase; if (hpf.ContentLength > 0) { if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } displayName = Path.GetFileName(hpf.FileName); ext = Path.GetExtension(hpf.FileName); if (!ext.ToLower().Equals(".zip")) { return(new { msg = "批量上传,请用zip格式压缩" }.ToJsonString()); } actualNameInServer = UserInfo.ProjectName + DateTime.Now.ToString("yyyyMMddHHmmss") + ext; url = Path.Combine(targetPath, actualNameInServer); hpf.SaveAs(url); hpf.InputStream.Close(); if (ext.ToLower().Equals(".zip")) { IList <string> unZipedFileName = new List <string>(); ZipHelper.UnZip(url, targetPath, unZipedFileName); MyFile.Delete(url); unZipedFileName.Each((k, fileName) => { actualNameInServer = Path.GetFileName(fileName); ext = Path.GetExtension(fileName); displayName = Path.GetFileNameWithoutExtension(Path.GetFileNameWithoutExtension(actualNameInServer)); createDate = DateTime.Now; amsUpload.Add(new AMSUpload() { FileName = displayName, FileType = ext, ServerName = actualNameInServer, FilePath = fileName, ProjectID = customer, ProjectName = customerName, OrderNo = "", Creator = UserInfo.Name, CreateTime = createDate, Updator = "", UpdateTime = createDate, Status = false }); }); } else { amsUpload.Add(new AMSUpload() { FileName = displayName, FileType = ext, ServerName = actualNameInServer, FilePath = url, ProjectID = UserInfo.ProjectID, ProjectName = UserInfo.ProjectName, OrderNo = "", Creator = UserInfo.Name, CreateTime = DateTime.Now, Updator = "", UpdateTime = DateTime.Now, Status = false }); } AMSUploadService service = new AMSUploadService(); //查询已存在的记录 Response <IEnumerable <AMSUpload> > resams = service.GetAMSUpload(new AddAMSUploadRequest() { amsUpload = amsUpload }); //执行新增修改操作 Response <IEnumerable <AMSUpload> > response = service.AddAMSUpload(new AddAMSUploadRequest() { amsUpload = amsUpload }); if (response.IsSuccess) { #region 除已存在记录的图片 if (resams.IsSuccess) { if (resams.Result != null) { foreach (AMSUpload a in resams.Result) { if (MyFile.Exists(a.FilePath)) { MyFile.Delete(a.FilePath); } } } } #endregion return(new { result = "批量上传文件成功!", IsSuccess = true }.ToJsonString()); } } return(new { result = "文件内容为空", IsSuccess = false }.ToJsonString()); } return(new { result = "请选择文件", IsSuccess = false }.ToJsonString()); }
public string ExcelCheck(string customer) { string uploadFolderPath = Runbow.TWS.Common.Constants.UPLOAD_FOLDER_PATH; string targetPath = Path.Combine(uploadFolderPath, "AMSTempFile"); string url = string.Empty, actualNameInServer = string.Empty, ext = string.Empty; DateTime amsDate = new DateTime(); if (string.IsNullOrEmpty(targetPath) || !Path.IsPathRooted(targetPath)) { return(new { msg = "程序出错!" }.ToJsonString()); } if (Request.Files.Count > 0) { HttpPostedFileBase hpf = Request.Files[0] as HttpPostedFileBase; if (hpf.ContentLength > 0) { if (!Directory.Exists(targetPath)) { Directory.CreateDirectory(targetPath); } ext = Path.GetExtension(hpf.FileName); if (!ext.ToLower().Equals(".xls") && !ext.ToLower().Equals(".xlsx")) { return(new { msg = "请选择Excel格式的文件" }.ToJsonString()); } actualNameInServer = DateTime.Now.ToString("yyyyMMddHHmmss") + ext; url = Path.Combine(targetPath, actualNameInServer); hpf.SaveAs(url); hpf.InputStream.Close(); Runbow.TWS.Common.ExcelHelper excelHelper = new Runbow.TWS.Common.ExcelHelper(url); DataSet ds = excelHelper.GetAllDataFromAllSheets(); excelHelper.Dispose(); MyFile.Delete(url); AMSUploadService service = new AMSUploadService(); Response <IEnumerable <AMSUpload> > response = service.GetAMSUpload(new AddAMSUploadRequest() { amsUpload = null }); if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0 && response.Result.Count() > 0) { StringBuilder results = new StringBuilder(); StringBuilder ids = new StringBuilder(); string projectName, fileName; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { DataRow row = ds.Tables[0].Rows[i]; projectName = row[0].ToString().Trim().ToUpper(); fileName = row[1].ToString().Trim().ToUpper(); if (projectName == "AMS_永兴东润") { amsDate = Convert.ToDateTime(row[2].ToString()); fileName = amsDate.ToString("yyyy-MM-") + fileName; } bool isExist = false; foreach (AMSUpload ams in response.Result) { if (projectName == ams.ProjectName.Trim().ToUpper() && fileName == ams.FileName.Trim().ToUpper()) { ids.Append("'" + ams.ID.ToString() + "',"); isExist = true; //if (projectName != "AMS_永兴东润") //AMS_永兴东润 //{ // break; //} } } if (!isExist) { results.Append("[" + row[0].ToString() + "]客户中[" + row[1].ToString() + "]运单号 未上传回单图片<br />"); } } if (ids.Length > 0) { service.UpdateAMSUploadStatus(new AddAMSUploadRequest() { Ids = ids.ToString() }); } if (results.Length <= 0) { results.Append("回单图片都已上传."); } return(new { result = results.ToString(), IsSuccess = true }.ToJsonString()); } } return(new { result = "文件内容为空", IsSuccess = false }.ToJsonString()); } return(new { result = "请选择文件", IsSuccess = false }.ToJsonString()); }