using System;
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;
using FastReport.Export.OoXML;
using FastReport.Export.Pdf;
using Microsoft.AspNetCore.Mvc;
using rmutr_report.Models;
using Swashbuckle.AspNetCore.Annotations;

namespace rmutr_report.Controllers
{
    [SwaggerTag("สำหรับรายงาน ง.4")]
    public class BuildingFour : Controller
    {
        readonly Setting _setting;

        public BuildingFour(Setting setting)
        {
            this._setting = setting;
        }

        [HttpPost, Route("reports/building_four/{type}")]
        [ApiExplorerSettings(GroupName = "reports")]
        public IActionResult GetHrReport([FromRoute] string type,
            [FromBody] building_four building_fours)
        {
            foreach (var a in building_fours.building_type)
            {
                if (a.usage_per_target != null)
                {
                    var a1 = a.usage_per_target.Where(d => d.used_year == d.used_year)
                        .Sum(o => o.used_year);
                    building_fours.sum_year1 = a1;   
                    var a2 = a.usage_per_target.Where(d => d.year1 == d.year1)
                        .Sum(o => o.year1);
                    building_fours.sum_year2 = a2;  
                    var a3 = a.usage_per_target.Where(d => d.year2 == d.year2)
                        .Sum(o => o.year2);
                    building_fours.sum_year3 = a3;  
                    var a4 = a.usage_per_target.Where(d => d.year3 == d.year3)
                        .Sum(o => o.year3);
                    building_fours.sum_year4 = a4;  
                    var a5 = a.usage_per_target.Where(d => d.year4 == d.year4)
                        .Sum(o => o.year4);
                    building_fours.sum_year5 = a5;  
                    var a6 = a.usage_per_target.Where(d => d.year5 == d.year5)
                        .Sum(o => o.year5);
                    building_fours.sum_year6 = a6;    
                }
               
            }

            // foreach (var bb in building_fours.material_construction_labor1)
            // {
            //     if (bb != null)
            //     {
            //         bb.total_amount = bb.material_cost + bb.labor_unit;
            //         var f = building_fours.material_construction_labor1.Where(d => d.total_amount == d.total_amount)
            //             .Sum(o => o.total_amount);
            //         building_fours.material_total_amount1 = f;
            //     }
            // }
            // foreach (var bb in building_fours.material_construction_labor2)
            // {
            //     if (bb != null)
            //     {
            //         bb.total_amount = bb.material_cost + bb.labor_unit;
            //         var f = building_fours.material_construction_labor2.Where(d => d.total_amount == d.total_amount)
            //             .Sum(o => o.total_amount);
            //         building_fours.material_total_amount2 = f;
            //     }
            // }
            // foreach (var bb in building_fours.material_construction_labor3)
            // {
            //     if (bb != null)
            //     {
            //         bb.total_amount = bb.material_cost + bb.labor_unit;
            //         var f = building_fours.material_construction_labor3.Where(d => d.total_amount == d.total_amount)
            //             .Sum(o => o.total_amount);
            //         building_fours.material_total_amount3 = f;
            //     }
            // }
            foreach (var cc in building_fours.budget_limit)
                {
                    if (cc != null)
                    {
                      var a = building_fours.budget_limit.Where(d => d.amount == d.amount)
                            .Sum(o => o.amount);
                        building_fours.amount = a;
                        if (cc.outside_amount != null)
                        {
                            var b = building_fours.budget_limit.Where(d => d.outside_amount == d.outside_amount)
                                .Sum(o => o.outside_amount);
                            building_fours.outside_amount = b;   
                        }
                        if (cc.outside_amount == null)
                        {
                         
                            building_fours.outside_amount = null;   
                        }

                        if (cc.amount != null && cc.outside_amount != null)
                        {
                            cc.total_amount = cc.amount + cc.outside_amount;
                        }
                        var c = building_fours.budget_limit.Where(d => d.total_amount == d.total_amount)
                            .Sum(o => o.total_amount);
                        building_fours.total_amount = c; 
                    }
                }

            foreach (var boqPrice in building_fours.basic_information)
            {
                string str = boqPrice.list;
                if (str.Length == 4)
                {
                    for (int i = 1; i <= str.Length - 1; i += 4)
                    {
                        boqPrice.list = str.Insert(i, ",");
                    }
                }
                else if (str.Length == 5)
                {
                    for (int i = 2; i <= str.Length - 1; i += 5)
                    {
                        boqPrice.list = str.Insert(i, ",");
                    }
                }
                else if (str.Length == 6)
                {
                    for (int i = 3; i <= str.Length - 1; i += 6)
                    {
                        boqPrice.list = str.Insert(i, ",");
                    }
                }
                else if (str.Length == 7)
                {
                    for (int i = 4; i <= str.Length - 1; i += 7)
                    {
                        boqPrice.list = str.Insert(i, ",");
                    }
                }
                else if (str.Length == 8)
                {
                    for (int i = 5; i <= str.Length - 1; i += 8)
                    {
                        boqPrice.list = str.Insert(i, ",");
                    }

                    for (int i = 3; i <= str.Length - 1; i += 8)
                    {
                        boqPrice.list = str.Insert(i, ",");
                    }
                }
            }

            foreach (var boqPrice in building_fours.boq)
            {
                if (boqPrice.is_data == "1")
                {
                    string str = boqPrice.have;
                    if (str.Length == 4)
                    {
                        for (int i = 1; i <= str.Length - 1; i += 4)
                        {
                            boqPrice.have = str.Insert(i, ",");
                        }
                    }
                    else if (str.Length == 5)
                    {
                        for (int i = 2; i <= str.Length - 1; i += 5)
                        {
                            boqPrice.have = str.Insert(i, ",");
                        }
                    }
                    else if (str.Length == 6)
                    {
                        for (int i = 3; i <= str.Length - 1; i += 6)
                        {
                            boqPrice.have = str.Insert(i, ",");
                        }
                    }
                    else if (str.Length == 7)
                    {
                        for (int i = 4; i <= str.Length - 1; i += 7)
                        {
                            boqPrice.have = str.Insert(i, ",");
                        }
                    }
                    else if (str.Length == 8)
                    {
                        for (int i = 5; i <= str.Length - 1; i += 8)
                        {
                            boqPrice.have = str.Insert(i, ",");
                        }
                        for (int i = 3; i <= str.Length - 1; i += 8)
                        {
                            boqPrice.have = str.Insert(i, ",");
                        }
                    }
                    boqPrice.text1 = "- มี วงเงิน "+ boqPrice.have + " บาท";
                    boqPrice.text2 = "- ดำเนินการจัดทำ BOQ เดือน "+ boqPrice.pending_boq_month;
                    boqPrice.text3 = "- BOQ แล้วเสร็จเดือน "+ boqPrice.done_boq_month;
                    boqPrice.text4 = "- ขออนุมัติ BOQ เดือน "+ boqPrice.approval_month;
                    boqPrice.text5 = "- ทำสัญญาก่อสร้าง  เดือน "+ boqPrice.construction_contract_month;
                }
                if (boqPrice.is_data == "2")
                {
                    boqPrice.text1 = "- ไม่มี";
                    boqPrice.text2 = "- กรณีไม่มีคาดว่าจะแล้วเสร็จ เดือน "+ boqPrice.months + " ปี "+
                                     boqPrice.years;
                    boqPrice.text3 = "- ขณะนี้อยูในขั้นตอน "+ boqPrice.step;
                    
                }
               
            }
                
               
            var _building_fours = new List<building_four>() {building_fours};

            Report report = new Report();
            report.Load(_setting.report_path + "building_fours.frx");
            report.RegisterData(_building_fours, "building_four");
            report.Prepare();

            MemoryStream stream = new MemoryStream();
            switch (type)
            {
                case "view":
                    return File(stream, "application/pdf");
                case "pdf":
                    PDFExport pdf = new PDFExport();
                    report.Export(pdf, stream);
                    stream.Seek(0, SeekOrigin.Begin);
                    return File(stream, "application/pdf");

                case "xls":
                case "xlsx":
                    Excel2007Export excel = new Excel2007Export();
                    report.Export(excel, stream);
                    stream.Seek(0, SeekOrigin.Begin);
                    return File(stream, "application/vnd.ms-excel");
                    break;
                case "mht":
                    MHTExport mht = new MHTExport();
                    report.Export(mht, stream);
                    stream.Seek(0, SeekOrigin.Begin);
                    return File(stream, "multipart/related");
                    break;
                case "csv":
                    CSVExport csv = new CSVExport();
                    report.Export(csv, stream);
                    stream.Seek(0, SeekOrigin.Begin);
                    return File(stream, "text/csv");
                    break;
                case "doc" : case "docx":
                    Word2007Export word = new Word2007Export();
                    report.Export(word, stream);
                    stream.Seek(0, SeekOrigin.Begin);
                    return File(stream, "appllication/vnd.ms-word");
                    break;
            }

            return Ok();
        }
        //  [HttpPost, Route("reports/materials_construction_labor/{type}")]
        // [ApiExplorerSettings(GroupName = "reports")]
        // public IActionResult GetConstructionReport([FromRoute] string type,
        //     [FromBody] building_four building_fours) {
        //     {
        //         var workbook = new XLWorkbook();
        //         var ws = workbook.Worksheets.Add("Page1");
        //         ws.Range("A1:J1").Merge().Value = "13. บัญชีแสดงปริมาณวัสดุและแรงงานค่าก่อสร้าง";
        //         ws.Range("A1:J1").Style.Alignment.WrapText = true;
        //         ws.Range("A1:J1").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Left;
        //         ws.Range("A1:J1").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Cell("A1").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("A1").Style.Font.FontSize = 16;
        //         ws.Range("A1:D1").Style.Font.Bold = true;
        //         ws.Range("A2:A3").Merge().Value = "ลำดับที่";
        //         ws.Range("A2:A3").Style.Border.OutsideBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Range("A2:A3").Style.Alignment.WrapText = true;
        //         ws.Range("A2:A3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Range("A2:A3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Cell("A2").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("A2").Style.Font.FontSize = 14;
        //         ws.Range("A2:D2").Style.Font.Bold = true;
        //         ws.Range("B2:B3").Merge().Value = "กิจกรรมการดำเนินงาน";
        //         ws.Range("B2:B3").Style.Border.OutsideBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Cell("B2").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("B2").Style.Font.FontSize = 14;
        //         ws.Cell("B2").Style.Font.Bold = true;
        //         ws.Cell("B2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("B2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Range("C2:C3").Merge().Value = "ปริมาณ";
        //         ws.Cell("C2").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("C2").Style.Font.FontSize = 14;
        //         ws.Cell("C2").Style.Font.Bold = true;
        //         ws.Cell("C2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("C2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Range("D2:D3").Merge().Value = "หน่วย";
        //         ws.Range("D2:D3").Style.Border.OutsideBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Cell("D2").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("D2").Style.Font.FontSize = 14;
        //         ws.Cell("D2").Style.Font.Bold = true;
        //         ws.Cell("D2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("D2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Range("E2:F2").Merge().Value = "ค่าวัสดุ";
        //         ws.Range("E2:F2").Style.Border.OutsideBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Cell("E2").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("E2").Style.Font.FontSize = 14;
        //         ws.Cell("E2").Style.Font.Bold = true;
        //         ws.Cell("E2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("E2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Cell("E3").Value = "หน่วยละ";
        //         ws.Cell("E3").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("E3").Style.Font.FontSize = 14;
        //         ws.Cell("E3").Style.Font.Bold = true;
        //         ws.Cell("E3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("E3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Cell("E3").Style.Border.RightBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Cell("F3").Value = "รวมเงิน";
        //         ws.Cell("F3").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("F3").Style.Font.FontSize = 14;
        //         ws.Cell("F3").Style.Font.Bold = true;
        //         ws.Cell("F3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("F3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Cell("F3").Style.Border.RightBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Range("G2:H2").Merge().Value = "ค่าแรงงาน";
        //         ws.Range("G2:H2").Style.Border.OutsideBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Cell("G2").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("G2").Style.Font.FontSize = 14;
        //         ws.Cell("G2").Style.Font.Bold = true;
        //         ws.Cell("G2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("G2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Cell("G3").Value = "หน่วยละ";
        //         ws.Cell("G3").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("G3").Style.Font.FontSize = 14;
        //         ws.Cell("G3").Style.Font.Bold = true;
        //         ws.Cell("G3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("G3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Cell("G3").Style.Border.RightBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Cell("H3").Value = "รวมเงิน";
        //         ws.Cell("H3").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("H3").Style.Font.FontSize = 14;
        //         ws.Cell("H3").Style.Font.Bold = true;
        //         ws.Cell("H3").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("H3").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Cell("H3").Style.Border.RightBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Range("I2:I3").Merge().Value = "ราคารวม";
        //         ws.Cell("I2").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("I2").Style.Font.FontSize = 14;
        //         ws.Cell("I2").Style.Font.Bold = true;
        //         ws.Cell("I2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("I2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Range("J2:J3").Merge().Value = "หมายเหตุ";
        //         ws.Range("J2:J3").Style.Border.OutsideBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Cell("J2").Style.Font.FontName = "TH SarabunPSK";
        //         ws.Cell("J2").Style.Font.FontSize = 14;
        //         ws.Cell("J2").Style.Font.Bold = true;
        //         ws.Cell("J2").Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //         ws.Cell("J2").Style.Alignment.Vertical = XLAlignmentVerticalValues.Center;
        //         ws.Range("A2:J3").Style.Border.OutsideBorder =
        //             XLBorderStyleValues.Thin;
        //         ws.Row(1).Height = 20;
        //         ws.Column(1).Width = 10;
        //         ws.Column(2).Width = 30;
        //         ws.Column(3).Width = 10;
        //         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 = 30;
        //         int row = 4;
        //         int no = 1;
        //         ws.Range(ws.Cell(row, 5), ws.Cell(row, 9)).SetDataType(XLDataType.Number);
        //             if (building_fours.material_construction_labor != null)
        //             {
        //                 var sumall = building_fours.material_construction_labor.Where(d => d.total_amount == d.total_amount)
        //                     .Sum(o => o.total_amount);  
        //                 foreach (var fours in building_fours.material_construction_labor)
        //                 {
        //                 
        //                     if (fours.operational_activities != "รวมทั้งสิ้น")
        //                     {
        //
        //                         ws.Cell(row, 1).Value = no;
        //                         no++;
        //                         ws.Cell(row, 2).Value = fours.operational_activities;
        //                         ws.Cell(row, 3).Value = fours.amount;
        //                         ws.Cell(row, 4).Value = fours.unit;
        //                         ws.Cell(row, 5).Value = fours.material_cost;
        //                         ws.Cell(row, 6).Value = fours.material_cost;
        //                         ws.Cell(row, 7).Value = fours.labor_unit;
        //                         ws.Cell(row, 8).Value = fours.labor_cost;
        //                         ws.Cell(row, 9).Value = fours.total_amount;
        //                         ws.Cell(row, 10).Value = fours.note;
        //
        //                         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.FontSize = 14;
        //                         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.Alignment.Vertical =
        //                             XLAlignmentVerticalValues.Center;
        //                         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.Border.RightBorder =
        //                             XLBorderStyleValues.Thin;
        //                         ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //                         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.Left;
        //                         //ws.Range(ws.Cell(5, 1), ws.Cell(5, 4)).Style.Font.Bold = true;
        //                         //ws.Range(ws.Cell(6, 1), ws.Cell(6, 4)).Style.Border.BottomBorder = XLBorderStyleValues.Double;
        //                         //ws.Range(ws.Cell(6, 1), ws.Cell(6, 4)).Style.Font.Bold = true;
        //                         //ws.Cell(row, 3).Style.NumberFormat.NumberFormatId = 2;
        //                         //ws.Cell(row, 3).DataType = XLDataType.Number;
        //                         //ws.Cell(row,3).SetDataType(XLDataType.Number);
        //                         ws.Range(ws.Cell(row, 5), ws.Cell(row, 9)).Style.NumberFormat.SetFormat("#,#");
        //
        //                         row++;
        //                     }
        //                     if (fours.operational_activities == "รวมทั้งสิ้น")
        //                     {
        //
        //                         ws.Cell(row, 1).Value = null;
        //                         ws.Cell(row, 2).Value = fours.operational_activities;
        //                         ws.Cell(row, 3).Value = null;
        //                         ws.Cell(row, 4).Value = null;
        //                         ws.Cell(row, 5).Value = null;
        //                         ws.Cell(row, 6).Value = null;
        //                         ws.Cell(row, 7).Value = null;
        //                         ws.Cell(row, 8).Value = null;
        //                         ws.Cell(row, 9).Value = sumall;
        //                         ws.Cell(row, 10).Value = null;
        //
        //                         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.FontSize = 14;
        //                         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.Alignment.Vertical =
        //                             XLAlignmentVerticalValues.Center;
        //                         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.Border.RightBorder =
        //                             XLBorderStyleValues.Thin;
        //                         ws.Cell(row, 1).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //                         ws.Cell(row, 2).Style.Alignment.Horizontal = XLAlignmentHorizontalValues.Center;
        //                         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.Left;
        //                        ws.Cell(row, 2).Style.Font.Bold = true;
        //                        ws.Cell(row, 9).Style.Font.Bold = true;
        //                         //ws.Range(ws.Cell(6, 1), ws.Cell(6, 4)).Style.Border.BottomBorder = XLBorderStyleValues.Double;
        //                         //ws.Range(ws.Cell(6, 1), ws.Cell(6, 4)).Style.Font.Bold = true;
        //                         //ws.Cell(row, 3).Style.NumberFormat.NumberFormatId = 2;
        //                         //ws.Cell(row, 3).DataType = XLDataType.Number;
        //                         //ws.Cell(row,3).SetDataType(XLDataType.Number);
        //                         ws.Range(ws.Cell(row, 5), ws.Cell(row, 9)).Style.NumberFormat.SetFormat("#,#");
        //
        //                         row++;
        //                     }
        //                 }
        //             }
        //             using (var stream = new MemoryStream())
        //         {
        //             workbook.SaveAs(stream);
        //             var content = stream.ToArray();
        //             string date = DateTime.Now.ToString("yyyyMMddHHmmss");
        //             return File(
        //                 content,
        //                 "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
        //                 "materials_construction_" + date + ".xlsx");
        //         }
        //     }
        // }

    }
}