public ActionResult AddFeeItem(int projectId,string feeTypeName, string paidItemName, decimal feeAmount) { var paiditem = new PaidFee() { FeeAmount = feeAmount, PaidItemName = paidItemName, FeeTypeName = feeTypeName, PaidDate = DateTime.Now.Date, ProjectId = projectId, PaidBy = CurrentUser.UserName }; _feeRepository.Add(paiditem); UnitOfWork.Commit(); return Json(new JsonResponse { Success = true, Message = "已录入一笔工程费用支出记录" }); }
public virtual ActionResult ImportFeeItem() { HttpPostedFileBase sourcefile = Request.Files[0]; var hssfworkbook = new HSSFWorkbook(sourcefile.InputStream); var sheet = hssfworkbook.GetSheetAt(0); var rows = sheet.GetRowEnumerator(); rows.MoveNext(); // rows.MoveNext(); while (rows.MoveNext()) { var row = (HSSFRow)rows.Current; var cell = row.GetCell(4); if (cell == null) continue; cell.SetCellType(CellType.STRING); var erpaccount = cell.StringCellValue.Trim(); if (string.IsNullOrEmpty(erpaccount)) continue;// 如果没有erp账号不导入 // cell = row.GetCell(3); var paidItemName = "工程费支出月度汇总"; // cell.StringCellValue.Trim(); double? feeAmount = null; cell = row.GetCell(8); if (cell != null && !string.IsNullOrEmpty(cell.ToString())) { cell.SetCellType(CellType.NUMERIC); feeAmount = cell.NumericCellValue; // 支付金额 } DateTime? paidDate = null; int year=0; int month=0; cell = row.GetCell(2); if (cell != null && !string.IsNullOrEmpty(cell.ToString())) year = Convert.ToInt32(cell.StringCellValue.Trim()); // 支付年度 cell = row.GetCell(3); if (cell != null && !string.IsNullOrEmpty(cell.ToString())) month = Convert.ToInt32(cell.StringCellValue.Trim()); // 支付月度 paidDate = new DateTime(year,month,1); var prj = _projectRepository.FindAll().SingleOrDefault(x => x.ErpCode == erpaccount); if (prj!=null) { var newitem = new PaidFee { ProjectId = prj.Id, FeeTypeName = "工程费用", PaidBy = CurrentUser.UserName, FeeAmount = Convert.ToDecimal(feeAmount), PaidDate = paidDate.Value, PaidItemName = paidItemName }; _feeRepository.Add(newitem); } } UnitOfWork.Commit(); return Content(Path.GetFileNameWithoutExtension(sourcefile.FileName) + "包含的现金流记录已经导入系统"); }