private Guid LoadBudgetReceiptFile(string path, BungetType type) { var fs = new FileStream(path, FileMode.Open, FileAccess.Read); var modelId = Guid.NewGuid(); if (path.IndexOf(".xlsx", StringComparison.OrdinalIgnoreCase) > 0) // 2007版本 { this._workbook = new XSSFWorkbook(fs); } else if (path.IndexOf(".xls", StringComparison.OrdinalIgnoreCase) > 0) // 2003版本 { this._workbook = new HSSFWorkbook(fs); } else { throw new UserFriendlyException("上传文件格式不正确"); } var currentYear = this._sysDictionaryRepository.FirstOrDefault(r => r.Category == DictionaryCategory.Budget_Year && r.Value4 == true.ToString()); if (currentYear == null) { throw new UserFriendlyException("未设置预算年度"); } var list = new List <BudgetOutlay>(); for (var j = 0; j < this._workbook.NumberOfSheets; j++) { var sheet = this._workbook.GetSheetAt(j); //最后一列的标号 var rowCount = sheet.LastRowNum + 1; for (var i = 3; i < rowCount; i++) { var row = sheet.GetRow(i); if (!string.IsNullOrEmpty(row.GetCell(1).ToStr())) { var item = new BudgetOutlay { Type = type, SheetName = sheet.SheetName, Name = row.GetCell(0).ToStr(), Unit = row.GetCell(1).ToStr(), Amount = decimal.Parse(row.GetCell(2).ToStr()), Price = decimal.Parse(row.GetCell(3).ToStr()), Column1 = row.GetCell(6).ToStr().ToDecimal(), Column2 = row.GetCell(7).ToStr().ToDecimal(), Column3 = row.GetCell(8).ToStr().ToDecimal(), FileId = modelId, Year = currentYear.Value.ToInt() }; list.Add(item); } } } this._budgetOutlayRepository.Delete(r => r.Year.ToString() == currentYear.Value && r.Type == type); this._budgetOutlayRepository.InsertRange(list); return(modelId); }
private Guid LoadBudgetReceiptFile(string path, BungetType type) { var fs = new FileStream(path, FileMode.Open, FileAccess.Read); var modelId = Guid.NewGuid(); if (path.IndexOf(".xlsx", StringComparison.OrdinalIgnoreCase) > 0) // 2007版本 { this._workbook = new XSSFWorkbook(fs); } else if (path.IndexOf(".xls", StringComparison.OrdinalIgnoreCase) > 0) // 2003版本 { this._workbook = new HSSFWorkbook(fs); } else { throw new UserFriendlyException("上传文件格式不正确"); } var sheet = this._workbook.GetSheetAt(0); //最后一列的标号 int rowCount = sheet.LastRowNum + 1; var list = new List <BudgetReceipt>(); var currentYear = this._sysDictionaryRepository.FirstOrDefault(r => r.Category == DictionaryCategory.Budget_Year && r.Value4 == true.ToString()); if (currentYear == null) { throw new UserFriendlyException("未设置预算年度"); } for (var i = 2; i < rowCount; i++) { var row = sheet.GetRow(i); if (!string.IsNullOrEmpty(row.GetCell(0).ToStr())) { var item = new BudgetReceipt { Type = type, Code = row.GetCell(0).ToStr(), Column1 = row.GetCell(4).ToStr().ToDecimal(), Note1 = row.GetCell(5).ToStr(), Column21 = row.GetCell(6).ToStr().ToDecimal(), Note21 = row.GetCell(7).ToStr(), Column22 = row.GetCell(8).ToStr().ToDecimal(), Note22 = row.GetCell(9).ToStr(), Column31 = row.GetCell(11).ToStr().ToDecimal(), Note31 = row.GetCell(12).ToStr(), Column32 = row.GetCell(13).ToStr().ToDecimal(), Note32 = row.GetCell(14).ToStr(), Column33 = row.GetCell(15).ToStr().ToDecimal(), Note33 = row.GetCell(16).ToStr(), Column34 = row.GetCell(17).ToStr().ToDecimal(), Note34 = row.GetCell(18).ToStr(), Column35 = row.GetCell(19).ToStr().ToDecimal(), Note35 = row.GetCell(20).ToStr(), Column36 = row.GetCell(21).ToStr().ToDecimal(), Note36 = row.GetCell(22).ToStr(), Column37 = row.GetCell(23).ToStr().ToDecimal(), Note37 = row.GetCell(24).ToStr(), Column41 = row.GetCell(26).ToStr().ToDecimal(), Note41 = row.GetCell(27).ToStr(), Column42 = row.GetCell(28).ToStr().ToDecimal(), Note42 = row.GetCell(29).ToStr(), Column43 = row.GetCell(30).ToStr().ToDecimal(), Note43 = row.GetCell(31).ToStr(), Column44 = row.GetCell(32).ToStr().ToDecimal(), Note44 = row.GetCell(33).ToStr(), Column45 = row.GetCell(34).ToStr().ToDecimal(), Note45 = row.GetCell(35).ToStr(), Column46 = row.GetCell(36).ToStr().ToDecimal(), Note46 = row.GetCell(37).ToStr(), Column47 = row.GetCell(38).ToStr().ToDecimal(), Note47 = row.GetCell(39).ToStr(), Column5 = row.GetCell(40).ToStr().ToDecimal(), Note5 = row.GetCell(41).ToStr(), FileId = modelId, Year = currentYear.Value.ToInt() }; list.Add(item); } } this._budgetReceiptRepository.Delete(r => r.Year.ToString() == currentYear.Value && r.Type == type); this._budgetReceiptRepository.InsertRange(list); return(modelId); }