public ActionResult GenerateByUploadedExcel(DateTime paymentDate, string asOfDate) { return(ActionUtils.Json(() => { var path = DemoJianYuanUtils.GetExcelReportPath(); CommUtils.Assert(System.IO.File.Exists(path), "请先上传服务商报告文件(path={0})", path); Resource resource = null; using (FileStream fs = new FileStream(path, FileMode.Open)) { var ms = new MemoryStream(); var docFileInfo = new DocFileInfo { DisplayName = "信托受托机构报告.docx" }; var utils = new DemoJianYuanUtils(); utils.Generate(ms, fs, "服务商报告.xls", paymentDate, asOfDate); ms.Seek(0, SeekOrigin.Begin); var result = Tuple.Create(ms, docFileInfo); //生成报告 var userName = string.IsNullOrWhiteSpace(CurrentUserName) ? "anonymous" : CurrentUserName; resource = ResourcePool.RegisterMemoryStream(userName, result.Item2.DisplayName, result.Item1); } return ActionUtils.Success(resource.Guid.ToString()); })); }
private Tuple <MemoryStream, DocFileInfo> UploadDemoJianYuanReport(HttpPostedFileBase file, DateTime paymentDate, string asOfDate) { var ms = new MemoryStream(); var docFileInfo = new DocFileInfo { DisplayName = "信托受托机构报告.docx" }; var utils = new DemoJianYuanUtils(); utils.Generate(ms, file.InputStream, file.FileName, paymentDate, asOfDate); ms.Seek(0, SeekOrigin.Begin); return(Tuple.Create(ms, docFileInfo)); }
public ActionResult UploadExcelReport(HttpPostedFileBase file) { return(ActionUtils.Json(() => { CommUtils.AssertNotNull(file, "文件不能为空,请选择文件"); CommUtils.Assert(file.ContentLength > 0, "文件内容不能为空"); CommUtils.Assert(file.FileName.EndsWith(".xls", StringComparison.CurrentCultureIgnoreCase), "文件[{0}]格式错误,请选择.xls格式的文件", file.FileName); var path = DemoJianYuanUtils.GetExcelReportPath(); file.SaveAs(path); return ActionUtils.Success(1); })); }
public ActionResult GetKeyValue() { return(ActionUtils.Json(() => { var path = DemoJianYuanUtils.GetKeyValuePath(); string content = string.Empty; if (System.IO.File.Exists(path)) { using (StreamReader sr = new StreamReader(path)) { content = sr.ReadToEnd(); } } var dict = ParseKeyValue(content); return ActionUtils.Success(dict); })); }
public ActionResult UploadTemplateFile(HttpPostedFileBase file) { return(ActionUtils.Json(() => { CommUtils.AssertNotNull(file, "文件不能为空,请选择文件"); CommUtils.Assert(file.ContentLength > 0, "文件内容不能为空"); CommUtils.Assert(file.FileName.EndsWith(".docx", StringComparison.CurrentCultureIgnoreCase), "文件[{0}]格式错误,请选择.docx格式的文件", file.FileName); CommUtils.Assert(!CommUtils.IsWPS(file.InputStream), "不支持wps编辑过的.docx格式文件,仅支持office编辑的.docx文件"); var path = DemoJianYuanUtils.GetTemplateFilePath(); file.SaveAs(path); return ActionUtils.Success(1); })); }
public ActionResult DownloadModel(string asOfDate) { return(ActionUtils.Json(() => { CommUtils.AssertHasContent(asOfDate, "无效的参数:asOfDate"); var folder = DemoJianYuanUtils.GetModelFolder(); var ymlFilePath = Path.Combine(folder, "script.yml"); CommUtils.Assert(System.IO.File.Exists(ymlFilePath), "请先上传模型(找不到模型文件:{0})", ymlFilePath); var asOfDateFolder = Path.Combine(folder, asOfDate); CommUtils.Assert(System.IO.Directory.Exists(asOfDateFolder), "请先上传模型(找不到路径:{0})", asOfDateFolder); var fileNames = new List <string> { "script.yml", asOfDate + @"\AmortizationSchedule.csv", asOfDate + @"\Reinvestment.csv", asOfDate + @"\AnalyzerResults.csv", asOfDate + @"\AssetCashflowTable.csv", asOfDate + @"\CashflowTable.csv", asOfDate + @"\collateral.csv", asOfDate + @"\CurrentVariables.csv", asOfDate + @"\FutureVariables.csv", asOfDate + @"\PastVariables.csv" }; var ms = new MemoryStream(); ZipUtils.CompressFiles(folder, fileNames, ms); var fileFullName = "DataModel(" + asOfDate + ").zip"; var userName = string.IsNullOrWhiteSpace(CurrentUserName) ? "anonymous" : CurrentUserName; var resource = ResourcePool.RegisterMemoryStream(userName, fileFullName, ms); var guid = resource.Guid.ToString(); return ActionUtils.Success(guid); })); }
public ActionResult SetKeyValue(string keyValue) { return(ActionUtils.Json(() => { var dict = ParseKeyValue(keyValue); var path = DemoJianYuanUtils.GetKeyValuePath(); //CommUtils.Assert(System.IO.File.Exists(path), "请先上传服务商报告文件(path={0})", path); if (System.IO.File.Exists(path)) { System.IO.File.Delete(path); } using (StreamWriter sw = new StreamWriter(path)) { sw.Write(keyValue); } return ActionUtils.Success(dict); })); }
public ActionResult UploadModel(HttpPostedFileBase file, string asOfDate) { return(ActionUtils.Json(() => { CommUtils.Assert(DateUtils.IsDigitDate(asOfDate), "asOfDate格式错误(应为八位数字):{0}", asOfDate); CommUtils.AssertNotNull(file, "请选择文件"); CommUtils.Assert(file.FileName.EndsWith(".zip", StringComparison.CurrentCultureIgnoreCase), "请选择zip文件({0})", file.FileName); var fileNames = ZipUtils.GetZipFileNames(file.InputStream); file.InputStream.Seek(0, SeekOrigin.Begin); //检查上传模型文件结构 var modelFiles = CheckModelFile(asOfDate, fileNames); var modelFolder = DemoJianYuanUtils.GetModelFolder(); var fileDicts = modelFiles.GetFileDictionary(); ZipUtils.ExtractFiles(file.InputStream, fileDicts, modelFolder); return ActionUtils.Success(1); })); }
public ActionResult DownloadTemplateFile() { return(ActionUtils.Json(() => { var path = DemoJianYuanUtils.GetTemplateFilePath(); CommUtils.Assert(System.IO.File.Exists(path), "请先上传模板文件(path={0})", path); var guid = string.Empty; using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read)) { BinaryReader br = new BinaryReader(fs); var bytes = br.ReadBytes((int)br.BaseStream.Length); var ms = new MemoryStream(bytes); var fileName = Path.GetFileName(path); var userName = string.IsNullOrWhiteSpace(CurrentUserName) ? "anonymous" : CurrentUserName; var resource = ResourcePool.RegisterMemoryStream(userName, fileName, ms); guid = resource.Guid.ToString(); } return ActionUtils.Success(guid); })); }