//导出入库记录 public IActionResult ExportIncomeList(string searchText, DateTime dt0, DateTime dt1) { var finds = _pharSvr.QueryIncomeList(searchText, dt0, dt1, UserSelf.DrugStoreStationId); var file = new CHIS.Code.Utility.FileUtils().ExportExcel(finds); var fs = System.IO.File.OpenRead(file); return(File(fs, "application/text", $"{DateTime.Now.ToString("我的药房入库记录yyMMddHHmmss")}.xlsx")); }
//导出监控的库存Excel数据 public IActionResult ExportStockMonitorList(string searchText, int drugStockTypeId = 0, int stockNumStatus = 0, string stockPriceStatus = "") { var finds = _pharSvr.QueryExportStockMonitorList(searchText, drugStockTypeId, stockNumStatus, stockPriceStatus, UserSelf.DrugStoreStationId); var file = new CHIS.Code.Utility.FileUtils().ExportExcel(finds); var fs = System.IO.File.OpenRead(file); return(File(fs, "application/text", $"{DateTime.Now.ToString("我的药房库存yyMMddHHmmss")}.xlsx")); }
/// <summary> /// 批量导入文件 /// </summary> /// <param name="file"></param> /// <returns></returns> public IEnumerable <Models.DataModel.ExcelIncomeImportModel> ImportIncomeExcel(IFormFile file) { string sWebRootFolder = Global.ConfigSettings.ImportFilePath; string sFileName = $"{Guid.NewGuid()}.xlsx"; FileInfo f = new FileInfo(Path.Combine(sWebRootFolder, sFileName)); string fn = f.ToString(); try { using (FileStream fs = new FileStream(fn, FileMode.Create)) { file.CopyTo((Stream)fs); fs.Flush(); } var items = new CHIS.Code.Utility.FileUtils().ImportExcel <Models.DataModel.ExcelIncomeImportModel>(fn); //合法性检查与数据重新整理 foreach (var item in items) { item.IncomeUnitId = Global.UnitName2Id(item.IncomeUnitName); item.CheckData(); } //重新整理数据 var drugsids = items.Select(m => m.DrugId); var drugs = _db.vwCHIS_Code_Drug_Main.Where(m => drugsids.Contains(m.DrugId)); foreach (var item in items) { var drug = drugs.FirstOrDefault(m => m.DrugId == item.DrugId); item.DrugName = drug.DrugName; item.DrugModel = drug.DrugModel; item.ManufacturerOrigin = drug.ManufacturerOrigin; item.DrugOrigPlace = drug.OriginPlace; item.DrugAlias = drug.Alias; item.outUnitBigId = drug.UnitBigId; item.outUnitBigName = drug.OutUnitBigName; item.outUnitSmallId = drug.UnitSmallId; item.outUnitSmallName = drug.OutUnitSmallName; item.UnitConvertRate = drug.OutpatientConvertRate; } return(items); } catch (Exception ex) { if (f.Exists) { System.IO.File.Delete(fn); } throw ex; } }
public async Task <IActionResult> JKImportDrugs(IFormFile importExcel) { try { DateTime dt = DateTime.Now; string sWebRootFolder = Global.ConfigSettings.ImportFilePath; string sFileName = $"{Guid.NewGuid()}.xlsx"; FileInfo f = new FileInfo(Path.Combine(sWebRootFolder, sFileName)); string fn = f.ToString(); using (FileStream fs = new FileStream(fn, FileMode.Create)) { importExcel.CopyTo((Stream)fs); fs.Flush(); } var items = new CHIS.Code.Utility.FileUtils().ImportExcel <Models.TEMP_Excel_JKImport>(fn); //合法性检查与数据重新整理 foreach (var item in items) { item.UnitId = Global.UnitName2Id(item.UnitName); item.CheckData(); } await _db.Database.ExecuteSqlCommandAsync("truncate table TEMP_Excel_JKImport"); //重置表格 await _db.AddRangeAsync(items); //一次写入大量表格数据 _db.SaveChanges(); //运行处理后的存储过程 await _db.Database.ExecuteSqlCommandAsync("exec sp_TEMP_Excel_JKImport"); base._setDebugText(dt); return(View("Success")); } catch (Exception ex) { return(View("Error", ex)); } }