diff --git a/Controllers/RoFive.Controller.cs b/Controllers/RoFive.Controller.cs index 3e9571a..caac32b 100644 --- a/Controllers/RoFive.Controller.cs +++ b/Controllers/RoFive.Controller.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Globalization; using System.IO; using System.Linq; +using ClosedXML.Excel; using FastReport; using FastReport.Export.Csv; using FastReport.Export.Mht; @@ -434,38 +435,37 @@ namespace rmutr_report.Controllers return Ok(); } - [HttpPost, Route("reports/ro_ten/{type}")] + + [HttpPost, Route("reports/ro_ten/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetTenReport([FromRoute] string type, [FromBody] ro_ten ten) { var t_ten = ten.data.ToArray(); - if (t_ten != null) - { - // var t1 = ten.data.Sum(g => g.amount_1); - // var t2 = ten.data.Sum(g => g.amount_2); - // var t3 = ten.data.Sum(g => g.amount_3); - // var t2 = t_ten.Sum(g => g.amount_2); - // var t3 = t_ten.Sum(g => g.amount_3); - - - foreach (var detail in t_ten) + if (t_ten != null) { - var s1 = detail.data_detail.Sum(g => g.amount_1); - var s2 = detail.data_detail.Sum(g => g.amount_2); - var s3 = detail.data_detail.Sum(g => g.amount_3); - // var s4 = t_ten.Sum(g => g.amount_1); - // var s5 = t_ten.Sum(g => g.amount_2); - // var s6 = t_ten.Sum(g => g.amount_3); - detail.amount_1 = s1; - detail.amount_2 = s2; - detail.amount_3 = s3; - + // var t1 = ten.data.Sum(g => g.amount_1); + // var t2 = ten.data.Sum(g => g.amount_2); + // var t3 = ten.data.Sum(g => g.amount_3); + // var t2 = t_ten.Sum(g => g.amount_2); + // var t3 = t_ten.Sum(g => g.amount_3); + + + foreach (var detail in t_ten) + { + var s1 = detail.data_detail.Sum(g => g.amount_1); + var s2 = detail.data_detail.Sum(g => g.amount_2); + var s3 = detail.data_detail.Sum(g => g.amount_3); + // var s4 = t_ten.Sum(g => g.amount_1); + // var s5 = t_ten.Sum(g => g.amount_2); + // var s6 = t_ten.Sum(g => g.amount_3); + detail.amount_1 = s1; + detail.amount_2 = s2; + detail.amount_3 = s3; + } } - - } - - var _budget_summary_report = new List() { ten }; - + + var _budget_summary_report = new List() { ten }; + Report report = new Report(); report.Load(_setting.report_path + "ro_ten.frx"); report.RegisterData(_budget_summary_report, "ro_ten"); @@ -492,11 +492,11 @@ namespace rmutr_report.Controllers "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", date + ".xlsx"); break; - } return Ok(); } + [HttpPost, Route("reports/ro_eleven/{type}")] [ApiExplorerSettings(GroupName = "reports")] public IActionResult GetEleReport([FromRoute] string type, [FromBody] ro_eleven eleven) @@ -510,12 +510,10 @@ namespace rmutr_report.Controllers eleven.total_amount_1 = t1; eleven.total_amount_2 = t2; eleven.total_amount_3 = t3; - - } - + var ele = new List() { eleven }; - + Report report = new Report(); report.Load(_setting.report_path + "ro_eleven.frx"); report.RegisterData(ele, "ro_eleven"); @@ -542,14 +540,15 @@ namespace rmutr_report.Controllers "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", date + ".xlsx"); break; - } return Ok(); } + [HttpPost, Route("reports/revenue_estimate_income_summary/{type}")] [ApiExplorerSettings(GroupName = "reports")] - public IActionResult GetEstimateIncomeReport([FromRoute] string type, [FromBody] revenue_estimate_income_summary estimate) + public IActionResult GetEstimateIncomeReport([FromRoute] string type, + [FromBody] revenue_estimate_income_summary estimate) { var s1 = estimate.data.Sum(d => d.science_1); var s2 = estimate.data.Sum(d => d.social_1); @@ -578,8 +577,8 @@ namespace rmutr_report.Controllers estimate.sum_11 = s11; estimate.sum_12 = s12; estimate.sum_13 = s13; - var estimateEducation = new List() { estimate }; - + var estimateEducation = new List() { estimate }; + Report report = new Report(); report.Load(_setting.report_path + "revenue_estimate_income_summary.frx"); report.RegisterData(estimateEducation, "revenue_estimate_income_summary"); @@ -599,23 +598,23 @@ namespace rmutr_report.Controllers Excel2007Export excel = new Excel2007Export(); report.Export(excel, stream); stream.Seek(0, SeekOrigin.Begin); - + return File( stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "estimateincome_" + ".xlsx"); - } return Ok(); } + [HttpPost, Route("reports/revenue_estimate_education_fee/{type}")] [ApiExplorerSettings(GroupName = "reports")] - public IActionResult GetEstimateReport([FromRoute] string type, [FromBody] revenue_estimate_education_fee estimate) + public IActionResult GetEstimateReport([FromRoute] string type, + [FromBody] revenue_estimate_education_fee estimate) { - var estimateEducation = new List() { estimate }; - + Report report = new Report(); report.Load(_setting.report_path + "revenue_estimate_education_fee.frx"); report.RegisterData(estimateEducation, "revenue_estimate_education_fee"); @@ -635,15 +634,433 @@ namespace rmutr_report.Controllers Excel2007Export excel = new Excel2007Export(); report.Export(excel, stream); stream.Seek(0, SeekOrigin.Begin); - + return File( stream, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "estimateEducation" + ".xlsx"); - } return Ok(); } + + [HttpPost, Route("reports/revenue_estimate_register_credits/{type}")] + [ApiExplorerSettings(GroupName = "reports")] + public IActionResult GetDetailKpiReport([FromRoute] string type, + [FromBody] revenue_estimate_register_credits revenueEstimate) + { + var workbook = new XLWorkbook(); + var ws = workbook.Worksheets.Add("detailkpi"); + ws.Range("A1:R1").Merge().Value = + "งบประมาณรายจ่ายจากเงินรายได้ ประจำปีงบประมาณ พ.ศ. " + revenueEstimate.budget_year; + ws.Range("A1:R1").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("A1:R1").Style.Font.SetBold().Font.FontSize = 22; + ws.Range("A1:R1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A2:R2").Merge().Value = + "ประมาณการรายรับภาคปกติ ของคณะศิลปศาสตร์ จาก ค่าหน่วยกิตที่ลงทะเบียน ( พื้นที่ " + + revenueEstimate.area + " ) " + "จากการจัดการศึกษาให้แก่" + revenueEstimate.faculty + " ภาคเรียนที่ " + + revenueEstimate.semester + "/" + revenueEstimate.year; + ws.Range("A2:R2").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("A2:R2").Style.Font.SetBold().Font.FontSize = 22; + ws.Range("A2:R2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A3:C3").Merge().Value = "ประมาณการรายรับจากการจัดการศึกษาด้าน "; + ws.Range("A3:C3").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("A3:C3").Style.Font.SetBold().Font.FontSize = 22; + ws.Range("A3:C3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("D3").Value = "þ"; + ws.Cell("D3").Style.Font.Bold = true; + ws.Cell("D3").Style.Font.FontName = "Wingdings"; + ws.Cell("D3").Style.Font.SetBold().Font.FontSize = 22; + ws.Cell("D3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell("D3").Style.Fill.BackgroundColor = XLColor.FromArgb(198, 224, 180); + ws.Range("E3:M3").Merge().Value = revenueEstimate.budget_project_name_th; + ws.Range("E3:M3").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("E3:M3").Style.Font.SetBold().Font.FontSize = 22; + ws.Range("E3:M3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left; + ws.Range("E3:M3").Style.Fill.BackgroundColor = XLColor.FromArgb(198, 224, 180); + + ws.Range("A4:A6").Merge().Value = "ลำดับที่"; + ws.Range("A4:A6").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("A4:A6").Style.Font.SetBold().Font.FontSize = 16; + ws.Range("A4:A6").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("A4:A6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Range("B4:B6").Merge().Value = "รหัสวิชา"; + ws.Range("B4:B6").Style.Font.SetBold().Font.FontSize = 16; + ws.Range("B4:B6").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("B4:B6").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("B4:B6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Range("C4:C6").Merge().Value = "ชื่อรายวิชา"; + ws.Range("C4:C6").Style.Font.SetBold().Font.FontSize = 16; + ws.Range("C4:C6").Style.Font.FontName = "TH SarabunPSK"; + ws.Range("C4:C6").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Range("C4:C6").Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + + ws.Column(1).Width = 10; + ws.Column(2).Width = 15; + ws.Column(3).Width = 30; + ws.Column(4).Width = 10; + ws.Column(5).Width = 10; + ws.Column(6).Width = 10; + ws.Column(7).Width = 10; + ws.Column(8).Width = 10; + ws.Column(9).Width = 10; + ws.Column(10).Width = 10; + ws.Column(11).Width = 10; + ws.Column(12).Width = 10; + ws.Column(13).Width = 10; + ws.Column(15).Width = 10; + ws.Column(16).Width = 10; + ws.Column(17).Width = 10; + ws.Column(18).Width = 10; + ws.Column(19).Width = 10; + ws.Column(20).Width = 10; + ws.Column(21).Width = 10; + ws.Column(22).Width = 10; + ws.Column(23).Width = 10; + + int col = 4; + int rowhead = 5; + int row = 7; + + if (revenueEstimate != null) + { + + foreach (var i in revenueEstimate.majors) + { + + //ws.Cell(rowhead, col).Value = i.major_name; + ws.Range(ws.Cell(rowhead, col), ws.Cell(rowhead+1, col)).Merge().Value = i.major_name; + ws.Cell(rowhead, col).Style.Alignment.SetTextRotation(90); + ws.Cell(rowhead, col).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(rowhead, col).Style.Alignment.Vertical = XLAlignmentVerticalValues.Center; + ws.Cell(rowhead, col).Style.Border.RightBorder = XLBorderStyleValues.Thin; + ws.Cell(rowhead, col).Style.Font.FontName = "TH SarabunPSK"; + ws.Cell(rowhead, col).Style.Font.FontSize = 16; + ws.Range(ws.Cell(rowhead, col), ws.Cell(rowhead+1, col)).Style.Alignment.WrapText = true; + col++; + var a = revenueEstimate.majors.Count; + + if (a == 1) + { + ws.Range("D4:E4").Merge().Value = "จำนวนนักศึกษาที่ลงทะเบียน"; + + ws.Cell("E5").Value = "รวม"; + ws.Cell("E6").Value = "( 1 )"; + ws.Cell("F5").Value = "จำนวนหน่วยกิตบรรยาย"; + ws.Cell("F6").Value = "( 2 )"; + ws.Cell("G5").Value = "จำนวนหน่วยกิตปฏิบัติ"; + ws.Cell("G6").Value = "( 3 )"; + ws.Cell("H5").Value = "รวมค่าหน่วยกิตบรรยาย"; + ws.Cell("H6").Value = "(4)=(1)x(2)x150"; + ws.Cell("I5").Value = "รวมค่าหน่วยกิตปฏิบัติ"; + ws.Cell("I6").Value = "(5)=(1)x(3)x200"; + ws.Cell("J5").Value = "รวมเงินค่าลงทะเบียนเรียน"; + ws.Cell("J6").Value = "( 6 )=( 4 )+( 5 )"; + ws.Cell("F5").Style.Alignment.SetTextRotation(90); + ws.Cell("G5").Style.Alignment.SetTextRotation(90); + ws.Range("F4:J4").Merge().Merge().Value = + "ค่าลงทะเบียนเรียนภาคเรียน " + revenueEstimate.semester + " / " + revenueEstimate.year; + ws.Range(ws.Cell(4, 4), ws.Cell(8, 10)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(4, 4), ws.Cell(8, 10)).Style.Alignment.Horizontal = + XLAlignmentHorizontalValues.Center; + ws.Range(ws.Cell(4, 4), ws.Cell(8, 10)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(4, 4), ws.Cell(8, 10)).Style.Font.SetBold().Font.FontSize = 16; + ws.Range(ws.Cell(4, 5), ws.Cell(8, 10)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(5, 5), ws.Cell(6, 10)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range("D4:E4").Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range("F4:J4").Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(4, 4), ws.Cell(4, 10)).Style.Fill.BackgroundColor = + XLColor.FromArgb(198, 224, 180); + + ws.Range(ws.Cell(5, 5), ws.Cell(6, 10)).Style.Border.RightBorder = XLBorderStyleValues.Thin; + // ws.Cell("D4").Style.Border.RightBorder = XLBorderStyleValues.Thin; + // ws.Cell("D4").Style.Border.TopBorder = XLBorderStyleValues.Thin; + } + + if (a == 2) + { + ws.Range("D4:F4").Merge().Value = "จำนวนนักศึกษาที่ลงทะเบียน"; + + ws.Cell("F5").Value = "รวม"; + ws.Cell("F6").Value = "( 1 )"; + ws.Cell("G5").Value = "จำนวนหน่วยกิตบรรยาย"; + ws.Cell("G6").Value = "( 2 )"; + ws.Cell("H5").Value = "จำนวนหน่วยกิตปฏิบัติ"; + ws.Cell("H6").Value = "( 3 )"; + ws.Cell("I5").Value = "รวมค่าหน่วยกิตบรรยาย"; + ws.Cell("I6").Value = "(4)=(1)x(2)x150"; + ws.Cell("J5").Value = "รวมค่าหน่วยกิตปฏิบัติ"; + ws.Cell("J6").Value = "(5)=(1)x(3)x200"; + ws.Cell("K5").Value = "รวมเงินค่าลงทะเบียนเรียน"; + ws.Cell("K6").Value = "( 6 )=( 4 )+( 5 )"; + ws.Cell("G5").Style.Alignment.SetTextRotation(90); + ws.Cell("H5").Style.Alignment.SetTextRotation(90); + ws.Range("G4:K4").Merge().Merge().Value = + "ค่าลงทะเบียนเรียนภาคเรียน " + revenueEstimate.semester + " / " + revenueEstimate.year; + ws.Range(ws.Cell(4, 4), ws.Cell(8, 11)).Style.Alignment.Vertical = + XLAlignmentVerticalValues.Center; + ws.Range(ws.Cell(4, 4), ws.Cell(8, 11)).Style.Alignment.Horizontal = + XLAlignmentHorizontalValues.Center; + ws.Range(ws.Cell(4, 4), ws.Cell(8, 11)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(4, 4), ws.Cell(8, 11)).Style.Font.SetBold().Font.FontSize = 16; + ws.Range(ws.Cell(4, 5), ws.Cell(8, 11)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(5, 5), ws.Cell(6, 11)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range("D4:F4").Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range("G4:K4").Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(4, 4), ws.Cell(4, 11)).Style.Fill.BackgroundColor = + XLColor.FromArgb(198, 224, 180); + + ws.Range(ws.Cell(5, 5), ws.Cell(6, 11)).Style.Border.RightBorder = XLBorderStyleValues.Thin; + } + } + } + + // int col2 = 6; + foreach (var header in revenueEstimate.data) + { + var a = revenueEstimate.majors.Count; + int rowhead2 = 4; + int no = 1; + if (a == 1) + { + if (header.topic_type == 1) + { + ws.Range(ws.Cell(row, 3), ws.Cell(row, 10)).Merge().Value = header.education_level; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.SetBold().Font.FontSize = 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Fill.BackgroundColor = + XLColor.FromArgb(198, 224, 180); + + row++; + } + + if (header.topic_type == 2) + { + ws.Range(ws.Cell(row, 1), ws.Cell(row, 2)).Merge().Value = header.year_class; + ws.Cell(row, 3).Value = "นักศึกษา รหัส" + header.code; + ws.Cell(row, rowhead2 + 1).Value = header.total_credits; + ws.Cell(row, rowhead2 + 2).Value = header.lecture_credits; + ws.Cell(row, rowhead2 + 3).Value = header.practical_credits; + ws.Cell(row, rowhead2 + 4).Value = header.total_lecture_credits; + ws.Cell(row, rowhead2 + 5).Value = header.total_practical_credits; + ws.Cell(row, rowhead2 + 6).Value = header.total_register_amount; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 6)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 6)).Style.Font.SetBold().Font.FontSize = + 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 6)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 6)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 6)).Style.Fill.BackgroundColor = + XLColor.FromArgb(255, 255, 153); + ws.Range(ws.Cell(row, 1), ws.Cell(row, 3)).Style.Alignment.Horizontal = + XLAlignmentHorizontalValues.Center; + ws.Cell(row, rowhead2 + 6).Style.Alignment.Horizontal = + XLAlignmentHorizontalValues.Right; + ws.Range(ws.Cell(row, 4), ws.Cell(row, rowhead2 + 6)).Style.NumberFormat.SetFormat("#,#"); + ws.Range(ws.Cell(row, 1), ws.Cell(row, 2)).Style.Alignment.Horizontal = + XLAlignmentHorizontalValues.Center; + row++; + } + + if (header.topic_type==3) + { + ws.Cell(row, 1).Value = no; + no++; + ws.Cell(row, 2).Value = header.topic_code; + ws.Cell(row, 3).Value = header.topic; + foreach (var i in header.majors) + { + ws.Cell(row, rowhead2).Value = i.credits; + ws.Cell(row, rowhead2).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell(row, rowhead2).Style.Border.RightBorder = XLBorderStyleValues.Thin; + ws.Cell(row, rowhead2).Style.Font.FontName = "TH SarabunPSK"; + ws.Cell(row, rowhead2).Style.Font.FontSize = 16; + ws.Cell(row, rowhead2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + //rowhead2++; + } + ws.Cell(row, rowhead2 + 1).Value = header.total_credits; + ws.Cell(row, rowhead2 + 2).Value = header.lecture_credits; + ws.Cell(row, rowhead2 + 3).Value = header.practical_credits; + ws.Cell(row, rowhead2 + 4).Value = header.total_lecture_credits; + ws.Cell(row, rowhead2 + 5).Value = header.total_practical_credits; + ws.Cell(row, rowhead2 + 6).Value = header.total_register_amount; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 6)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 6)).Style.Font.SetBold().Font.FontSize = + 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 6)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 6)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 4), ws.Cell(row, rowhead2 + 6)).Style.NumberFormat.SetFormat("#,#"); + + + row++; + } + if (header.topic_type == 4) //รวมระดับชั้น + { + ws.Range(ws.Cell(row, 1), ws.Cell(row, 3)).Merge().Value = "รวม "+header.education_level; + ws.Cell(row, rowhead2 + 6).Value = header.total_register_amount; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.SetBold().Font.FontSize = 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Fill.BackgroundColor = + XLColor.FromArgb(198, 224, 180); + ws.Cell(row, rowhead2 + 6).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, rowhead2 + 6).Style.NumberFormat.SetFormat("#,#"); + + row++; + } + if (header.topic_type == 5) //รวมรายรับ + { + ws.Range(ws.Cell(row, 1), ws.Cell(row, 9)).Merge().Value = "รวมรายรับจากการจัดการศึกษาให้กับ "+revenueEstimate.faculty+ " " + + " ภาคเรียน "+ revenueEstimate.semester+" / "+revenueEstimate.year+ " "+ revenueEstimate.budget_project_name_th; + ws.Cell(row, 10).Value = revenueEstimate.total_income; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Font.SetBold().Font.FontSize = 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Cell(row, 10).Style.Fill.BackgroundColor = + XLColor.FromArgb(189, 215, 238); + ws.Range(ws.Cell(row, 1), ws.Cell(row, 9)).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 10).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 10).Style.NumberFormat.SetFormat("#,#"); + + } + + } + + if (a == 2) + { + if (header.topic_type == 1) + { + ws.Range(ws.Cell(row, 3), ws.Cell(row, 11)).Merge().Value = header.education_level; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Font.SetBold().Font.FontSize = 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Fill.BackgroundColor = + XLColor.FromArgb(198, 224, 180); + + row++; + } + + if (header.topic_type == 2) + { + ws.Range(ws.Cell(row, 1), ws.Cell(row, 2)).Merge().Value = header.year_class; + ws.Cell(row, 3).Value = "นักศึกษา รหัส" + header.code; + ws.Cell(row, rowhead2 + 2).Value = header.total_credits; + ws.Cell(row, rowhead2 + 3).Value = header.lecture_credits; + ws.Cell(row, rowhead2 + 4).Value = header.practical_credits; + ws.Cell(row, rowhead2 + 5).Value = header.total_lecture_credits; + ws.Cell(row, rowhead2 + 6).Value = header.total_practical_credits; + ws.Cell(row, rowhead2 + 7).Value = header.total_register_amount; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 7)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 7)).Style.Font.SetBold().Font.FontSize = + 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 7)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 7)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, rowhead2 + 7)).Style.Fill.BackgroundColor = + XLColor.FromArgb(255, 255, 153); + ws.Range(ws.Cell(row, 4), ws.Cell(row, rowhead2 + 7)).Style.NumberFormat.SetFormat("#,#"); + ws.Range(ws.Cell(row, 1), ws.Cell(row, 2)).Style.Alignment.Horizontal = + XLAlignmentHorizontalValues.Center; + row++; + } + if (header.topic_type==3) + { + ws.Cell(row, 1).Value = no; + no++; + ws.Cell(row, 2).Value = header.topic_code; + ws.Cell(row, 3).Value = header.topic; + foreach (var i in header.majors) + { + ws.Cell(row, rowhead2).Value = i.credits; + ws.Cell(row, rowhead2).Style.Border.OutsideBorder = XLBorderStyleValues.Thin; + ws.Cell(row, rowhead2).Style.Border.RightBorder = XLBorderStyleValues.Thin; + ws.Cell(row, rowhead2).Style.Font.FontName = "TH SarabunPSK"; + ws.Cell(row, rowhead2).Style.Font.FontSize = 16; + ws.Cell(row, rowhead2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + rowhead2++; + } + ws.Cell(row, 6).Value = header.total_credits; + ws.Cell(row, 7).Value = header.lecture_credits; + ws.Cell(row, 8).Value = header.practical_credits; + ws.Cell(row, 9).Value = header.total_lecture_credits; + ws.Cell(row, 10).Value = header.total_practical_credits; + ws.Cell(row, 11).Value = header.total_register_amount; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Font.SetBold().Font.FontSize = 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 4), ws.Cell(row, 11)).Style.NumberFormat.SetFormat("#,#"); + + row++; + } + if (header.topic_type == 4) //รวมระดับชั้น + { + ws.Range(ws.Cell(row, 1), ws.Cell(row, 3)).Merge().Value = "รวม "+header.education_level; + ws.Cell(row, rowhead2 + 7).Value = header.total_register_amount; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 3)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 3)).Style.Font.SetBold().Font.FontSize = 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 3)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Fill.BackgroundColor = + XLColor.FromArgb(198, 224, 180); + ws.Range(ws.Cell(row, 4), ws.Cell(row, 11)).Style.NumberFormat.SetFormat("#,#"); + ws.Cell(row, rowhead2 + 7).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + row++; + } + if (header.topic_type == 5) //รวมรายรับ + { + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Merge().Value = "รวมรายรับจากการจัดการศึกษาให้กับ "+revenueEstimate.faculty+ " " + + " ภาคเรียน "+ revenueEstimate.semester+" / "+revenueEstimate.year+ " "+ revenueEstimate.budget_project_name_th; + ws.Cell(row, 11).Value = revenueEstimate.total_income; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Font.FontName = "TH SarabunPSK"; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Font.SetBold().Font.FontSize = 16; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Alignment.WrapText = true; + ws.Range(ws.Cell(row, 1), ws.Cell(row, 11)).Style.Border.OutsideBorder = + XLBorderStyleValues.Thin; + ws.Cell(row, 10).Style.Fill.BackgroundColor = + XLColor.FromArgb(189, 215, 238); + ws.Range(ws.Cell(row, 1), ws.Cell(row, 10)).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center; + ws.Cell(row, 11).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Right; + ws.Cell(row, 11).Style.NumberFormat.SetFormat("#,#"); + + } + + + } + + // row++; + // col++; + } + //} + + using (var stream = new MemoryStream()) + { + workbook.SaveAs(stream); + var content = stream.ToArray(); + return File( + content, + "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", + "revenueEstimate_register" + ".xlsx"); + } + } } } \ No newline at end of file diff --git a/Models/RoReport/revenue_estimate_register_credits.cs b/Models/RoReport/revenue_estimate_register_credits.cs index dba5898..4d28bee 100644 --- a/Models/RoReport/revenue_estimate_register_credits.cs +++ b/Models/RoReport/revenue_estimate_register_credits.cs @@ -1,7 +1,46 @@ -namespace rmutr_report.Models.RoThree +using System.Collections.Generic; + +namespace rmutr_report.Models.RoThree { public class revenue_estimate_register_credits { - + public string budget_year { get; set; } + public string area { get; set; } + public string faculty { get; set; } + public string semester { get; set; } + public string year { get; set; } + public string budget_project_name_th { get; set; } + public decimal? total_income { get; set; } + + public List data { get; set; } + public List majors { get; set; } + } + + public class revenue_estimate_register_credit + { + public int? topic_type { get; set; } + public string education_level { get; set; } + public string year_class { get; set; } + public string code { get; set; } + public string topic_code { get; set; } + public string topic { get; set; } + public decimal? total_credits { get; set; } + public decimal? lecture_credits { get; set; } + public decimal? practical_credits { get; set; } + public decimal? total_lecture_credits { get; set; } + public decimal? total_practical_credits { get; set; } + public decimal? total_register_amount { get; set; } + public List majors { get; set; } + } + + public class major_data + { + public string major_name { get; set; } + } + + public class major + { + public string major_name { get; set; } + public decimal? credits { get; set; } } } \ No newline at end of file diff --git a/bin/Debug/netcoreapp3.1/rmutr_report.dll b/bin/Debug/netcoreapp3.1/rmutr_report.dll index bb28814..c854f87 100644 Binary files a/bin/Debug/netcoreapp3.1/rmutr_report.dll and b/bin/Debug/netcoreapp3.1/rmutr_report.dll differ diff --git a/bin/Debug/netcoreapp3.1/rmutr_report.pdb b/bin/Debug/netcoreapp3.1/rmutr_report.pdb index a87cec6..58589af 100644 Binary files a/bin/Debug/netcoreapp3.1/rmutr_report.pdb and b/bin/Debug/netcoreapp3.1/rmutr_report.pdb differ diff --git a/obj/Debug/netcoreapp3.1/rmutr_report.dll b/obj/Debug/netcoreapp3.1/rmutr_report.dll index bb28814..c854f87 100644 Binary files a/obj/Debug/netcoreapp3.1/rmutr_report.dll and b/obj/Debug/netcoreapp3.1/rmutr_report.dll differ diff --git a/obj/Debug/netcoreapp3.1/rmutr_report.pdb b/obj/Debug/netcoreapp3.1/rmutr_report.pdb index a87cec6..58589af 100644 Binary files a/obj/Debug/netcoreapp3.1/rmutr_report.pdb and b/obj/Debug/netcoreapp3.1/rmutr_report.pdb differ