protected string mailLogLocation(string path) { try { string projectFile = Server.MapPath("~/mailTxt"); //預設txt位置 FileRelated.createFile(projectFile); string folderPath = Path.Combine(projectFile, path); //合併路徑&檔名 return(folderPath); } catch { return(string.Empty); } }
protected string txtLocation(string path) { try { string projectFile = Server.MapPath("~/" + SetFile.FileUploads); //預設txt位置 string configTxtLocation = ConfigurationManager.AppSettings["txtLogLocation"]; if (!string.IsNullOrWhiteSpace(configTxtLocation)) { projectFile = configTxtLocation; //有設定webConfig且不為空就取代 } FileRelated.createFile(projectFile); string folderPath = Path.Combine(projectFile, path); //合併路徑&檔名 return(folderPath); } catch { return(string.Empty); } }
public JsonResult Upload(ValidateFiles FileModel) { MSGReturnModel result = new MSGReturnModel(); try { #region 前端無傳送檔案進來 if (FileModel.File == null) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.upload_Not_Find.GetDescription(); return(Json(result)); } #endregion 前端無傳送檔案進來 #region 前端檔案大小不服或不為Excel檔案(驗證) if (!ModelState.IsValid) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.excel_Validate.GetDescription(); return(Json(result)); } #endregion 前端檔案大小不服或不為Excel檔案(驗證) #region 傳檔案 string pathType = Path.GetExtension(FileModel.File.FileName) .Substring(1); //上傳的檔案類型 var fileName = string.Format("{0}.{1}", Excel_UploadName.A71.GetDescription(), pathType); //固定轉成此名稱 Cache.Invalidate(CacheList.A71ExcelName); //清除 Cache Cache.Set(CacheList.A71ExcelName, fileName, 15); //把資料存到 Cache #region 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 string projectFile = Server.MapPath("~/" + SetFile.FileUploads); //專案資料夾 string path = Path.Combine(projectFile, fileName); FileRelated.createFile(projectFile); //檢查是否有FileUploads資料夾,如果沒有就新增 //呼叫上傳檔案 function result = FileRelated.FileUpLoadinPath(path, FileModel.File); if (!result.RETURN_FLAG) { return(Json(result)); } #endregion 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 #region 讀取Excel資料 使用ExcelDataReader 並且組成 json var stream = FileModel.File.InputStream; List <Exhibit29Model> dataModel = A7Repository.getExcel(pathType, stream); if (dataModel.Count > 0) { result.RETURN_FLAG = true; result.Datas = Json(dataModel); //給JqGrid 顯示 } else { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.data_Not_Compare.GetDescription(); } #endregion 讀取Excel資料 使用ExcelDataReader 並且組成 json #endregion 傳檔案 } catch (Exception ex) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.upload_Fail .GetDescription(FileModel.File.FileName, ex.Message); } return(Json(result)); }
public JsonResult UploadA42() { MSGReturnModel result = new MSGReturnModel(); //## 如果有任何檔案類型才做 if (Request.Files.AllKeys.Any()) { var FileModel = Request.Files["UploadedFile"]; string processingDate = Request.Form["processingDate"]; string reportDate = Request.Form["reportDate"]; try { #region 前端無傳送檔案進來 if (FileModel == null) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.upload_Not_Find.GetDescription(); return(Json(result)); } #endregion 前端無傳送檔案進來 #region 前端檔案大小不符或不為Excel檔案(驗證) //ModelState if (!ModelState.IsValid) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.excel_Validate.GetDescription(); return(Json(result)); } else { string ExtensionName = Path.GetExtension(FileModel.FileName).ToLower(); if (ExtensionName != ".xls" && ExtensionName != ".xlsx") { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.excel_Validate.GetDescription(); return(Json(result)); } } #endregion 前端檔案大小不符或不為Excel檔案(驗證) #region 傳檔案 string pathType = Path.GetExtension(FileModel.FileName) .Substring(1); //上傳的檔案類型 var fileName = string.Format("{0}.{1}", Excel_UploadName.A42.GetDescription(), pathType); //固定轉成此名稱 Cache.Invalidate(CacheList.A42ExcelName); //清除 Cache Cache.Set(CacheList.A42ExcelName, fileName, 15); //把資料存到 Cache #region 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 string projectFile = Server.MapPath("~/" + SetFile.FileUploads); //專案資料夾 string path = Path.Combine(projectFile, fileName); FileRelated.createFile(projectFile); //檢查是否有FileUploads資料夾,如果沒有就新增 //呼叫上傳檔案 function result = FileRelated.FileUpLoadinPath(path, FileModel); if (!result.RETURN_FLAG) { return(Json(result)); } #endregion 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 #region 讀取Excel資料 使用ExcelDataReader 並且組成 json var stream = FileModel.InputStream; List <A42ViewModel> dataModel = A4Repository.getA42Excel(pathType, stream, processingDate, reportDate); if (dataModel.Count > 0) { result.RETURN_FLAG = true; result.Datas = Json(dataModel); //給JqGrid 顯示 } else { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.data_Not_Compare.GetDescription(); } #endregion 讀取Excel資料 使用ExcelDataReader 並且組成 json #endregion 傳檔案 } catch (Exception ex) { result.RETURN_FLAG = false; result.DESCRIPTION = ex.Message; } } else { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.upload_Not_Find.GetDescription(); return(Json(result)); } return(Json(result)); }
public JsonResult File_Upload() { MSGReturnModel <string> result = new MSGReturnModel <string>(); try { ExcelName excelType = ExcelName.Marginp; #region 前端無傳送檔案進來 if (!Request.Files.AllKeys.Any()) { result.RETURN_FLAG = false; result.DESCRIPTION = MessageType.upload_Not_Find.GetDescription(); return(Json(result)); } var FileModel = Request.Files["UploadedFile"]; string type = Request.Form["type"]; excelType = EnumUtil.GetValues <ExcelName>().First(y => y.ToString() == type); #endregion 前端無傳送檔案進來 #region 前端檔案大小不符或不為Excel檔案(驗證) //ModelState if (!ModelState.IsValid) { result.RETURN_FLAG = false; result.DESCRIPTION = MessageType.excel_Validate.GetDescription(); return(Json(result)); } #endregion 前端檔案大小不符或不為Excel檔案(驗證) #region 傳檔案 string pathType = Path.GetExtension(FileModel.FileName) .Substring(1); //上傳的檔案類型 var fileName = string.Format("{0}.{1}", excelType.GetDescription(), pathType); //固定轉成此名稱 //Cache.Invalidate(CacheList.A59ExcelName); //清除 Cache //Cache.Set(CacheList.A59ExcelName, fileName); //把資料存到 Cache #region 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 string projectFile = Server.MapPath("~/" + SetFile.FileUploads); //專案資料夾 string path = Path.Combine(projectFile, fileName); FileRelated.createFile(projectFile); //檢查是否有FileUploads資料夾,如果沒有就新增 //呼叫上傳檔案 function result = FileRelated.FileUpLoadinPath <string>(path, FileModel); if (!result.RETURN_FLAG) { return(Json(result)); } #endregion 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 #region 讀取Excel資料 使用ExcelDataReader 並且組成 json var stream = FileModel.InputStream; IEnumerable <IFileModel> dataModel = null; var Excelresult = FileService.getExcel(pathType, path, excelType); if (Excelresult.Item1.IsNullOrWhiteSpace()) { switch (excelType) { case ExcelName.Marginp: dataModel = Excelresult.Item2.Cast <FileMarginpModel>().ToList(); break; case ExcelName.Marging: dataModel = Excelresult.Item2.Cast <FileMargingModel>().ToList(); break; case ExcelName.Stock: dataModel = Excelresult.Item2.Cast <FileStockModel>().ToList(); break; case ExcelName.Itemimp: dataModel = Excelresult.Item2.Cast <FileItemImpModel>().ToList(); break; } } else { result.RETURN_FLAG = false; result.DESCRIPTION = Excelresult.Item1; return(Json(result)); } if (dataModel.Any()) { result.RETURN_FLAG = true; Cache.Invalidate(CacheList.ExcelfileData); //清除 Cache Cache.Set(CacheList.ExcelfileData, dataModel); //把資料存到 Cache } else { result.RETURN_FLAG = false; result.DESCRIPTION = MessageType.data_Not_Compare.GetDescription(); } #endregion 讀取Excel資料 使用ExcelDataReader 並且組成 json #endregion 傳檔案 } catch (Exception ex) { result.RETURN_FLAG = false; result.DESCRIPTION = ex.Message; } return(Json(result)); }
public JsonResult UploadC10() { MSGReturnModel result = new MSGReturnModel(); try { #region 前端無傳送檔案進來 if (!Request.Files.AllKeys.Any()) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.upload_Not_Find.GetDescription(); return(Json(result)); } #endregion 前端無傳送檔案進來 #region 前端檔案大小不符或不為Excel檔案(驗證) var FileModel = Request.Files["UploadedFile"]; string reportDate = Request.Form["reportDate"]; DateTime dt = DateTime.MinValue; DateTime.TryParse(reportDate, out dt); string pathType = Path.GetExtension(FileModel.FileName) .Substring(1); //上傳的檔案類型 List <string> pathTypes = new List <string>() { "xlsx", "xls" }; if (!pathTypes.Contains(pathType.ToLower())) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.excel_Validate.GetDescription(); return(Json(result)); } #endregion 前端檔案大小不符或不為Excel檔案(驗證) #region 傳檔案 var fileName = string.Format("{0}.{1}", Excel_UploadName.C10.GetDescription(), pathType); //固定轉成此名稱 Cache.Invalidate(CacheList.C10ExcelName); //清除 Cache Cache.Set(CacheList.C10ExcelName, fileName); //把Excel_name存到 Cache #region 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 string projectFile = Server.MapPath("~/" + SetFile.FileUploads); //專案資料夾 string path = Path.Combine(projectFile, fileName); FileRelated.createFile(projectFile); //檢查是否有FileUploads資料夾,如果沒有就新增 //呼叫上傳檔案 function result = FileRelated.FileUpLoadinPath(path, FileModel); if (!result.RETURN_FLAG) { return(Json(result)); } #endregion 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 #region 讀取Excel資料 使用ExcelDataReader 並且組成 json var stream = FileModel.InputStream; var data = C0Repository.getExcel(pathType, stream, dt); if (!data.Item1.IsNullOrWhiteSpace()) { result.RETURN_FLAG = false; result.DESCRIPTION = data.Item1; return(Json(result)); } List <C10ViewModel> dataModel = data.Item2; if (dataModel.Count > 0) { result.RETURN_FLAG = true; Cache.Invalidate(CacheList.C10ExcelfileData); //清除 Cache Cache.Set(CacheList.C10ExcelfileData, dataModel); //把資料存到 Cache new BondsCheckRepository <C10ViewModel>(dataModel, Check_Table_Type.Bonds_C10_UpLoad_Check); } else { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.data_Not_Compare.GetDescription(); } #endregion 讀取Excel資料 使用ExcelDataReader 並且組成 json #endregion 傳檔案 } catch (Exception ex) { result.RETURN_FLAG = false; result.DESCRIPTION = ex.exceptionMessage(); } return(Json(result)); }
public JsonResult UploadC01() { MSGReturnModel result = new MSGReturnModel(); //## 如果有任何檔案類型才做 if (Request.Files.AllKeys.Any()) { var FileModel = Request.Files["UploadedFile"]; string version = Request.Form["Version"]; try { #region 前端無傳送檔案進來 if (FileModel == null) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.upload_Not_Find.GetDescription(); return(Json(result)); } #endregion 前端無傳送檔案進來 #region 前端檔案大小不符或不為Excel檔案(驗證) //ModelState if (!ModelState.IsValid) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.excel_Validate.GetDescription(); return(Json(result)); } else { string ExtensionName = Path.GetExtension(FileModel.FileName).ToLower(); if (ExtensionName != ".xls" && ExtensionName != ".xlsx") { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.excel_Validate.GetDescription(); return(Json(result)); } } #endregion 前端檔案大小不符或不為Excel檔案(驗證) #region 傳檔案 string pathType = Path.GetExtension(FileModel.FileName) .Substring(1); //上傳的檔案類型 var fileName = string.Format("{0}.{1}", Excel_UploadName.C01.GetDescription(), pathType); //固定轉成此名稱 Cache.Invalidate(CacheList.C01ExcelName); //清除 Cache Cache.Set(CacheList.C01ExcelName, fileName); //把資料存到 Cache #region 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 string projectFile = Server.MapPath("~/" + SetFile.FileUploads); //專案資料夾 string path = Path.Combine(projectFile, fileName); FileRelated.createFile(projectFile); //檢查是否有FileUploads資料夾,如果沒有就新增 //呼叫上傳檔案 function result = FileRelated.FileUpLoadinPath(path, FileModel); if (!result.RETURN_FLAG) { return(Json(result)); } #endregion 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 #region 讀取Excel資料 使用ExcelDataReader 並且組成 json List <C01ViewModel> dataModel = C0Repository.getC01Excel(pathType, path, version); if (dataModel.Count > 0) { result.RETURN_FLAG = true; Cache.Invalidate(CacheList.C01ExcelfileData); //清除 Cache Cache.Set(CacheList.C01ExcelfileData, dataModel); //把資料存到 Cache new BondsCheckRepository <C01ViewModel>(dataModel, Check_Table_Type.Bonds_C01_HK_VN_UpLoad); } else { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.data_Not_Compare.GetDescription(); } #endregion 讀取Excel資料 使用ExcelDataReader 並且組成 json #endregion 傳檔案 } catch (Exception ex) { result.RETURN_FLAG = false; result.DESCRIPTION = ex.Message; } } else { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.upload_Not_Find.GetDescription(); } return(Json(result)); }
public JsonResult Estate_Upload() { MSGReturnModel <JsonResult> result = new MSGReturnModel <JsonResult>(); try { #region 前端無傳送檔案進來 if (!Request.Files.AllKeys.Any()) { result.RETURN_FLAG = false; result.DESCRIPTION = Ref.MessageType.upload_Not_Find.GetDescription(); return(Json(result)); } var FileModel = Request.Files["UploadedFile"]; //string type = Request.Form["type"]; #endregion 前端無傳送檔案進來 #region 前端檔案大小不符或不為Excel檔案(驗證) //ModelState if (!ModelState.IsValid) { result.RETURN_FLAG = false; result.DESCRIPTION = Ref.MessageType.excel_Validate.GetDescription(); return(Json(result)); } #endregion 前端檔案大小不符或不為Excel檔案(驗證) #region 傳檔案 string pathType = Path.GetExtension(FileModel.FileName) .Substring(1); //上傳的檔案類型 var fileName = string.Format("{0}.{1}", Ref.ExcelName.Estate.GetDescription(), pathType); //固定轉成此名稱 //Cache.Invalidate(CacheList.A59ExcelName); //清除 Cache //Cache.Set(CacheList.A59ExcelName, fileName); //把資料存到 Cache #region 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 string projectFile = Server.MapPath("~/" + SetFile.FileUploads); //專案資料夾 string path = Path.Combine(projectFile, fileName); FileRelated.createFile(projectFile); //檢查是否有FileUploads資料夾,如果沒有就新增 //呼叫上傳檔案 function result = FileRelated.FileUpLoadinPath <JsonResult>(path, FileModel); if (!result.RETURN_FLAG) { return(Json(result)); } #endregion 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 #region 讀取Excel資料 使用ExcelDataReader 並且組成 json var stream = FileModel.InputStream; List <FileEstateModel> dataModel = new List <FileEstateModel>(); var Estateresult = new FileService().getExcel(pathType, path, Ref.ExcelName.Estate); if (Estateresult.Item1.IsNullOrWhiteSpace()) { dataModel = Estateresult.Item2.Cast <FileEstateModel>().ToList(); } else { result.RETURN_FLAG = false; result.DESCRIPTION = Estateresult.Item1; return(Json(result)); } if (dataModel.Count > 0) { if (Cache.IsSet(CacheList.ESTATEData)) { var tempData = (List <EstateDetailViewModel>)Cache.Get(CacheList.ESTATEData); dataModel.ForEach(x => { tempData.Add(new EstateDetailViewModel() { vItemId = Guid.NewGuid().ToString(), vEstate_From_No = x.ESTATE_FORM_NO, vEstate_Date = TypeTransfer.dateTimeNToString(TypeTransfer.stringToADDateTimeN(x.ESTATE_DATE)), vEstate_Seq = x.ESTATE_SEQ, vHouse_No = x.HOUSE_NO, vLand_Building_No = x.LAND_BUILDING_NO, vMemo = x.MEMO, vOwnership_Cert_No = x.OWNERSHIP_CERT_NO, vStatus = Ref.AccessInventoryType._3.GetDescription() }); }); Cache.Invalidate(CacheList.ESTATEData); Cache.Set(CacheList.ESTATEData, tempData); List <string> sames = new List <string>(); tempData.ForEach(y => { var tempData2 = tempData.Where(x => x.vItemId != y.vItemId).ToList(); bool sameFlag = //位(字號;地/建號;門牌號;流水號/編號等欄位)建置相同值時,系統提醒建相同資料的訊息(但不影響資料的建置) ((!y.vOwnership_Cert_No.IsNullOrWhiteSpace()) && tempData2.Where(x => x.vOwnership_Cert_No != null).Where(x => x.vOwnership_Cert_No?.Trim() == y.vOwnership_Cert_No?.Trim()).Any()) || ((!y.vLand_Building_No.IsNullOrWhiteSpace()) && tempData2.Where(x => x.vLand_Building_No != null).Where(x => x.vLand_Building_No?.Trim() == y.vLand_Building_No?.Trim()).Any()) || ((!y.vHouse_No.IsNullOrWhiteSpace()) && tempData2.Where(x => x.vHouse_No != null).Where(x => x.vHouse_No?.Trim() == y.vHouse_No?.Trim()).Any()) || ((!y.vEstate_Seq.IsNullOrWhiteSpace()) && tempData2.Where(x => x.vEstate_Seq != null).Where(x => x.vEstate_Seq?.Trim() == y.vEstate_Seq?.Trim()).Any()); if (sameFlag) { sames.Add($@"字號:{y.vOwnership_Cert_No},地/建號:{y.vLand_Building_No},門牌號:{y.vHouse_No},流水號/編號:{y.vEstate_Seq}"); } }); result.RETURN_FLAG = true; result.DESCRIPTION = Ref.MessageType.upload_Success.GetDescription(); if (sames.Any()) { result.DESCRIPTION = Ref.MessageType.upload_Success.GetDescription(null, "<br/>以下資料欄位驗證有重複<br/>" + string.Join("<br/>", sames)); } } } else { result.RETURN_FLAG = false; result.DESCRIPTION = Ref.MessageType.data_Not_Compare.GetDescription(); } #endregion 讀取Excel資料 使用ExcelDataReader 並且組成 json #endregion 傳檔案 } catch (Exception ex) { result.RETURN_FLAG = false; result.DESCRIPTION = ex.Message; } return(Json(result)); }
public ActionResult Logon(string userId, string pwd) { bool flag = false; var now = DateTime.Now; if (!ModelState.IsValid) { TempData["User"] = userId; TempData["Login"] = Message_Type.login_Captcha_Fail.GetDescription(); return(RedirectToAction("Login", "Account")); } else { MvcCaptcha.ResetCaptcha("ExampleCaptcha"); FileRelated.createFile(@"D:\IFRS9Log"); try { // set up domain context //PrincipalContext ctx = new PrincipalContext(ContextType.Domain); // find the current user //UserPrincipal aduser = UserPrincipal.Current; //驗證AD帳號 flag = LdapAuthentication.isAuthenticatrd(userId, pwd); } catch { } var user = new IFRS9_User(); using (IFRS9DBEntities db = new IFRS9DBEntities()) { if (flag) //AD帳號 { user = db.IFRS9_User.AsNoTracking().FirstOrDefault(x => x.User_Account == userId); } else //非AD帳號 { user = db.IFRS9_User .Where(x => userId.Equals(x.User_Account)) .AsEnumerable() .FirstOrDefault(x => pwd.stringToSHA512().Equals(x.User_Password)); } if (user != null) { if (user.Effective) { this.LoginProcess(user.User_Account, false, now); flag = true; user.LoginFlag = true; string IP = System.Web.HttpContext.Current.Request .ServerVariables["HTTP_X_FORWARDED_FOR"]; if (string.IsNullOrEmpty(IP)) { IP = System.Web.HttpContext.Current.Request .ServerVariables["REMOTE_ADDR"]; } db.IFRS9_User_Log.Add( new IFRS9_User_Log() { User_Account = user.User_Account, Login_Time = now, Login_IP = IP, Login_Date = now.Date }); try { db.SaveChanges(); } catch { } } else { TempData["Login"] = Message_Type.login_Effective_Fail .GetDescription(); ModelState.AddModelError("", Message_Type.login_Effective_Fail .GetDescription()); flag = false; } } else { TempData["Login"] = Message_Type.login_Fail.GetDescription(); ModelState.AddModelError("", Message_Type.login_Fail.GetDescription()); flag = false; } } if (flag) { TempData["Login"] = string.Empty; return(RedirectToAction("Index", "Home")); } else { TempData["User"] = userId; return(RedirectToAction("Login", "Account")); } } }
public JsonResult UploadA96(ValidateFiles FileModel) { MSGReturnModel result = new MSGReturnModel(); try { #region 前端無傳送檔案進來 if (FileModel.File == null) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.upload_Not_Find.GetDescription(); return(Json(result)); } #endregion 前端無傳送檔案進來 #region 前端檔案大小不符或不為Excel檔案(驗證) //ModelState if (!ModelState.IsValid) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.excel_Validate.GetDescription(); return(Json(result)); } #endregion 前端檔案大小不符或不為Excel檔案(驗證) #region 傳檔案 string pathType = Path.GetExtension(FileModel.File.FileName) .Substring(1); //上傳的檔案類型 var fileName = string.Format("{0}.{1}", Excel_UploadName.A96.GetDescription(), pathType); //固定轉成此名稱 Cache.Invalidate(CacheList.A96ExcelName); //清除 Cache Cache.Set(CacheList.A96ExcelName, fileName); //把資料存到 Cache #region 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 string projectFile = Server.MapPath("~/" + SetFile.FileUploads); //專案資料夾 string path = Path.Combine(projectFile, fileName); FileRelated.createFile(projectFile); //檢查是否有FileUploads資料夾,如果沒有就新增 //呼叫上傳檔案 function result = FileRelated.FileUpLoadinPath(path, FileModel.File); if (!result.RETURN_FLAG) { return(Json(result)); } #endregion 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 #region 讀取Excel資料 var data = A9Repository.getA96Excel(pathType, FileModel.File.InputStream); if (data.Item1.IsNullOrWhiteSpace()) { result.RETURN_FLAG = true; Cache.Invalidate(CacheList.A96ExcelfileData); //清除 Cache Cache.Set(CacheList.A96ExcelfileData, data.Item2); //把資料存到 Cache } else { result.RETURN_FLAG = false; result.DESCRIPTION = data.Item1; } #endregion 讀取Excel資料 #endregion 傳檔案 } catch (Exception ex) { result.RETURN_FLAG = false; result.DESCRIPTION = ex.Message; } return(Json(result)); }
public JsonResult UploadA59(ValidateFiles FileModel) { MSGReturnModel result = new MSGReturnModel(); try { #region 前端無傳送檔案進來 if (FileModel.File == null) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.upload_Not_Find.GetDescription(); return(Json(result)); } #endregion 前端無傳送檔案進來 #region 前端檔案大小不符或不為Excel檔案(驗證) //ModelState if (!ModelState.IsValid) { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.excel_Validate.GetDescription(); return(Json(result)); } #endregion 前端檔案大小不符或不為Excel檔案(驗證) #region 傳檔案 string pathType = Path.GetExtension(FileModel.File.FileName) .Substring(1); //上傳的檔案類型 var fileName = string.Format("{0}.{1}", Excel_UploadName.A59.GetDescription(), pathType); //固定轉成此名稱 Cache.Invalidate(CacheList.A59ExcelName); //清除 Cache Cache.Set(CacheList.A59ExcelName, fileName); //把資料存到 Cache #region 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 string projectFile = Server.MapPath("~/" + SetFile.FileUploads); //專案資料夾 string path = Path.Combine(projectFile, fileName); FileRelated.createFile(projectFile); //檢查是否有FileUploads資料夾,如果沒有就新增 //呼叫上傳檔案 function result = FileRelated.FileUpLoadinPath(path, FileModel.File); if (!result.RETURN_FLAG) { return(Json(result)); } #endregion 檢查是否有FileUploads資料夾,如果沒有就新增 並加入 excel 檔案 #region 讀取Excel資料 使用ExcelDataReader 並且組成 json var stream = FileModel.File.InputStream; List <A59ViewModel> dataModel = new List <A59ViewModel>(); var A59result = A5Repository.getA59Excel(pathType, path, "upload"); if (A59result.Item1.IsNullOrWhiteSpace()) { dataModel = A59result.Item2; } else { result.RETURN_FLAG = false; result.DESCRIPTION = A59result.Item1; return(Json(result)); } if (dataModel.Count > 0) { result.RETURN_FLAG = true; var A59 = new A59ViewModel(); var jqgridParams = A59.TojqGridData(); result.Datas = Json(jqgridParams); Cache.Invalidate(CacheList.A59ExcelfileData); //清除 Cache Cache.Set(CacheList.A59ExcelfileData, dataModel); //把資料存到 Cache } else { result.RETURN_FLAG = false; result.DESCRIPTION = Message_Type.data_Not_Compare.GetDescription(); } #endregion 讀取Excel資料 使用ExcelDataReader 並且組成 json #endregion 傳檔案 } catch (Exception ex) { result.RETURN_FLAG = false; result.DESCRIPTION = ex.Message; } return(Json(result)); }
public JsonResult autoTransfer(string datepicker, string version) { string sType = "原始投資信評"; string portfolio = "All"; string search = "Miss"; string from = ""; string to = ""; string bondNumber = ""; MSGReturnModel result_searchA58 = new MSGReturnModel(); MSGReturnModel result_getA59 = new MSGReturnModel(); MSGReturnModel result_saveA59Excel = new MSGReturnModel(); MSGReturnModel result_autoTransfer = new MSGReturnModel(); result_searchA58.RETURN_FLAG = false; result_getA59.RETURN_FLAG = false; result_autoTransfer.RETURN_FLAG = false; #region 找A58缺漏 var A58Data = A5Repository.GetA58(datepicker, sType, from, to, bondNumber, version, search, portfolio); result_searchA58.RETURN_FLAG = A58Data.Item1; #endregion #region 轉入寶碩信評資料 if (!A58Data.Item1) { result_searchA58.DESCRIPTION = Message_Type.not_Find_Any.GetDescription(); return(Json(result_searchA58)); } var A59Data = A5Repository.getA59(A58Data.Item2, datepicker); if (!A59Data.Item1) { result_getA59.DESCRIPTION = Message_Type.not_Find_CounterPartyCreditRating.GetDescription(); GetCheckDataToCache(); return(Json(result_getA59)); } #region 產excel出來 var A59Filled = Excel_DownloadName.A59Filled.ToString(); var fileName = string.Format("{0}.{1}", Excel_DownloadName.A59Filled.GetDescription(), "xlsx"); //固定轉成此名稱 //檢查資料夾是否存在 string projectFile = Server.MapPath("~/" + SetFile.FileUploads); //專案資料夾 string path = Path.Combine(projectFile, fileName); FileRelated.createFile(projectFile); //檢查是否有FileUploads資料夾,如果沒有就新增 result_saveA59Excel = A5Repository.SaveA59Excel(A59Filled, path, A59Data.Item2); //儲存excel失敗不用中止,只要記錄就好 DateTime startTime = DateTime.Now; DateTime reportdate = DateTime.MinValue; DateTime.TryParse(datepicker, out reportdate); bool A59Log = CommonFunction.saveLog(Table_Type.A59, fileName, SetFile.ProgramName, result_saveA59Excel.RETURN_FLAG, Debt_Type.B.ToString(), startTime, DateTime.Now, AccountController.CurrentUserInfo.Name, Convert.ToInt32(version), reportdate); //寫sql Log #endregion 測試產excel出來看 #endregion #region 更新A57、A58 #region txtlog 檔案名稱 string txtpath = SetFile.A59TransferTxtLog; //預設txt名稱 #endregion txtlog 檔案名稱 #region save A59(A59=>A57=>A58) DateTime st_saveA59 = DateTime.Now; result_autoTransfer = A5Repository.saveA59(A59Data.Item2); A5Repository.SaveA59TransLog(result_autoTransfer, datepicker, st_saveA59, Convert.ToInt32(version)); TxtLog.txtLog(Table_Type.A59Trans, result_autoTransfer.RETURN_FLAG, st_saveA59, txtLocation(txtpath)); //寫txt Log #endregion save A59(A59=>A57=>A58) #endregion 更新A57、A58 #region 執行檢核 A5Repository.GetA58TransferCheck(reportdate, Convert.ToInt32(version)); GetCheckDataToCache(); #endregion 執行檢核 return(Json(result_autoTransfer)); }