From 44124665cb3af1d54f454fda4b6c009602bb00b9 Mon Sep 17 00:00:00 2001 From: kamonwan taengsuk Date: Thu, 16 Mar 2023 16:14:26 +0700 Subject: [PATCH] bug fixed --- Controllers/TeachingFeeExtra.Controller.cs | 220 ++++++++++++--------- 1 file changed, 122 insertions(+), 98 deletions(-) diff --git a/Controllers/TeachingFeeExtra.Controller.cs b/Controllers/TeachingFeeExtra.Controller.cs index 2525fb1..648802b 100644 --- a/Controllers/TeachingFeeExtra.Controller.cs +++ b/Controllers/TeachingFeeExtra.Controller.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using ClosedXML.Excel; using Microsoft.AspNetCore.Mvc; using rmutr_report.Models; @@ -47,7 +48,9 @@ namespace rmutr_report.Controllers ws.Column(11).Width = 30; int row = 8; int col = 11; - int x = 2; + int x = 1; + int y = 2; + int z = 3; //ws.Cell(row, 3).SetDataType(XLDataType.Number); if (_teaching_fee_extra != null) { @@ -190,107 +193,96 @@ namespace rmutr_report.Controllers ws.Cell("K4").Style.Font.FontSize = 16; ws.Cell("K4").Style.Fill.BackgroundColor = XLColor.Bisque; ws.Range("K4:K7").Merge().Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + foreach (var teaching in _teaching_fee_extra.data) { - ws.Cell(row, 2).Value = teaching.course; - ws.Cell(row, 3).Value = null; - ws.Cell(row, 4).Value = teaching.number_of_hours1; - ws.Cell(row, 5).Value = teaching.number_of_weeks1; - ws.Cell(row, 6).Value = teaching.amount1; - ws.Cell(row, 7).Value = teaching.number_of_hours2; - ws.Cell(row, 8).Value = teaching.number_of_weeks2; - ws.Cell(row, 9).Value = teaching.amount2; - ws.Cell(row, 10).Value = teaching.total_amount; - //ws.Range(ws.Cell(row, 11), ws.Cell(row, 11)).Merge(); - ws.Range(ws.Cell(row, col), ws.Cell(row+x, col)).Merge().Value = teaching.major; - - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.FontName = - "TH SarabunPSK"; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.FontSize = 16; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Alignment.WrapText = true; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Alignment.Vertical = - XLAlignmentVerticalValues.Center; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.Bold = true; - ws.Cell(row, 2).Style.Fill.BackgroundColor = XLColor.Gainsboro; - ws.Cell(row, 3).Style.Fill.BackgroundColor = XLColor.Gainsboro; - ws.Cell(row, 4).Style.Fill.BackgroundColor = XLColor.Gainsboro; - ws.Cell(row, 5).Style.Fill.BackgroundColor = XLColor.Gainsboro; - ws.Cell(row, 6).Style.Fill.BackgroundColor = XLColor.Gainsboro; - ws.Cell(row, 7).Style.Fill.BackgroundColor = XLColor.Gainsboro; - ws.Cell(row, 8).Style.Fill.BackgroundColor = XLColor.Gainsboro; - ws.Cell(row, 9).Style.Fill.BackgroundColor = XLColor.Gainsboro; - ws.Cell(row, 10).Style.Fill.BackgroundColor = XLColor.Gainsboro; - ws.Cell(row, 11).Style.Fill.BackgroundColor = XLColor.White; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Border.OutsideBorder = - XLBorderStyleValues.Thin; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 10)).Style.Border.RightBorder = - XLBorderStyleValues.Thin; - ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; - ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; - ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 7).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 8).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 9).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 10).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 11).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Range(ws.Cell(row, 4), ws.Cell(row, 10)).Style.NumberFormat.SetFormat("#,#"); - row++; - foreach (var datadetail in teaching.datadetail) + var countrow = teaching.datadetail.Count; + if (teaching.course != "รวมทั้งสิ้น") { - if (datadetail.teacher != "รวมทั้งสิ้น") + ws.Cell(row, 2).Value = teaching.course; + ws.Cell(row, 3).Value = null; + ws.Cell(row, 4).Value = teaching.number_of_hours1; + ws.Cell(row, 5).Value = teaching.number_of_weeks1; + ws.Cell(row, 6).Value = teaching.amount1; + ws.Cell(row, 7).Value = teaching.number_of_hours2; + ws.Cell(row, 8).Value = teaching.number_of_weeks2; + ws.Cell(row, 9).Value = teaching.amount2; + ws.Cell(row, 10).Value = teaching.total_amount; + //ws.Range(ws.Cell(row, col), ws.Cell(row+x+1, col)).Merge().Value = teaching.major; + if (countrow == 1) { - ws.Cell(row, 2).Value = datadetail.teacher; - ws.Cell(row, 3).Value = datadetail.teaching_rate; - ws.Cell(row, 4).Value = datadetail.number_of_hours1; - ws.Cell(row, 5).Value = datadetail.number_of_weeks1; - ws.Cell(row, 6).Value = datadetail.amount1; - ws.Cell(row, 7).Value = datadetail.number_of_hours2; - ws.Cell(row, 8).Value = datadetail.number_of_weeks2; - ws.Cell(row, 9).Value = datadetail.amount2; - ws.Cell(row, 10).Value = datadetail.total_amount; - ws.Cell(row, 11).Value = null; - //ws.Range(ws.Cell(row, col), ws.Cell(row, col)).Merge(); - ws.Range(ws.Cell(row, col), ws.Cell(row, col )).Merge(); - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.FontName = - "TH SarabunPSK"; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.FontSize = 16; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Alignment.WrapText = true; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Alignment.Vertical = - XLAlignmentVerticalValues.Center; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Border.OutsideBorder = - XLBorderStyleValues.Thin; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 10)).Style.Border.RightBorder = - XLBorderStyleValues.Thin; - ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; - ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 7).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 8).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 9).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 10).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Cell(row, 11).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; - ws.Range(ws.Cell(row, 4), ws.Cell(row, 10)).Style.NumberFormat.SetFormat("#,#"); - row++; - + ws.Range(ws.Cell(row, col), ws.Cell(row + x, col)).Merge().Value = teaching.major; + } - //row++; - if (datadetail.teacher == "รวมทั้งสิ้น") + + if (countrow == 2) + { + ws.Range(ws.Cell(row, col), ws.Cell(row + y, col)).Merge().Value = teaching.major; + + } + + if (countrow == 3) + { + ws.Range(ws.Cell(row, col), ws.Cell(row + z, col)).Merge().Value = teaching.major; + + } + if (countrow == 4) + { + ws.Range(ws.Cell(row, col), ws.Cell(row + 4, col)).Merge().Value = teaching.major; + + } + if (countrow == 5) + { + ws.Range(ws.Cell(row, col), ws.Cell(row + 5, col)).Merge().Value = teaching.major; + + } + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.FontName = + "TH SarabunPSK"; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.FontSize = 16; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.Bold = true; + ws.Cell(row, 2).Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Cell(row, 3).Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Cell(row, 4).Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Cell(row, 5).Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Cell(row, 6).Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Cell(row, 7).Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Cell(row, 8).Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Cell(row, 9).Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Cell(row, 10).Style.Fill.BackgroundColor = XLColor.Gainsboro; + ws.Cell(row, 11).Style.Fill.BackgroundColor = XLColor.White; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 10)).Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 7).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 8).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 9).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 10).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 11).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range(ws.Cell(row, 4), ws.Cell(row, 10)).Style.NumberFormat.SetFormat("#,#"); + row++; + } + + if (teaching.course == "รวมทั้งสิ้น") { //ws.Cell(row2, 2).Value = datadetail.teacher; - ws.Range(ws.Cell(row, 2), ws.Cell(row, 3)).Merge().Value = datadetail.teacher; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 3)).Merge().Value = teaching.course; ws.Range(ws.Cell(row, 2), ws.Cell(row, 3)).Merge(); - //ws.Cell(row2, 3).Value = datadetail.teaching_rate; - ws.Cell(row, 4).Value = datadetail.number_of_hours1; - ws.Cell(row, 5).Value = datadetail.number_of_weeks1; - ws.Cell(row, 6).Value = datadetail.amount1; - ws.Cell(row, 7).Value = datadetail.number_of_hours2; - ws.Cell(row, 8).Value = datadetail.number_of_weeks2; - ws.Cell(row, 9).Value = datadetail.amount2; - ws.Cell(row, 10).Value = datadetail.total_amount; + ws.Cell(row, 4).Value = teaching.number_of_hours1; + ws.Cell(row, 5).Value = teaching.number_of_weeks1; + ws.Cell(row, 6).Value = teaching.amount1; + ws.Cell(row, 7).Value = teaching.number_of_hours2; + ws.Cell(row, 8).Value = teaching.number_of_weeks2; + ws.Cell(row, 9).Value = teaching.amount2; + ws.Cell(row, 10).Value = teaching.total_amount; ws.Cell(row, 11).Value = null; ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.FontName = "TH SarabunPSK"; @@ -317,11 +309,43 @@ namespace rmutr_report.Controllers ws.Range(ws.Cell(row, 4), ws.Cell(row, 10)).Style.NumberFormat.SetFormat("#,#"); row++; } - //row++; - //row2++; + foreach (var datadetail in teaching.datadetail) + { + + ws.Cell(row, 2).Value = datadetail.teacher; + ws.Cell(row, 3).Value = datadetail.teaching_rate; + ws.Cell(row, 4).Value = datadetail.number_of_hours1; + ws.Cell(row, 5).Value = datadetail.number_of_weeks1; + ws.Cell(row, 6).Value = datadetail.amount1; + ws.Cell(row, 7).Value = datadetail.number_of_hours2; + ws.Cell(row, 8).Value = datadetail.number_of_weeks2; + ws.Cell(row, 9).Value = datadetail.amount2; + ws.Cell(row, 10).Value = datadetail.total_amount; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.FontName = + "TH SarabunPSK"; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Font.FontSize = 16; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 11)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 2), ws.Cell(row, 10)).Style.Border.RightBorder = + XLBorderStyleValues.Thin; + ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Cell(row, 3).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 4).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 5).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 7).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 8).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 9).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 10).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 11).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range(ws.Cell(row, 4), ws.Cell(row, 10)).Style.NumberFormat.SetFormat("#,#"); + row++; + } - //row++; - //row2++; + } // foreach (var teaching in _teaching_fee_extra.data) // {