using MWS.Domain.Common.DataExporting.Excel.EpPlus;
using MWS.Model;
using MWS.Model.Dto;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MWS.Domain.Common.DataExporting
{
    public class WeightRecordReportExcelExporter : EpPlusExcelExporterBase
    {
        /// <summary>
        /// 
        /// </summary>
        /// <param name="filePath"></param>
        /// <param name="userListDtos"></param>
        public void ExportToFile(string filePath, List<RecordDto> weightRecordDtos)
        {
            CreateExcelPackage(
              filePath,
              excelPackage =>
              {
                  var sheet = excelPackage.Workbook.Worksheets.Add("OperatorRecords");
                  sheet.OutLineApplyStyle = true;
                  AddHeader(
                      sheet,
                     "设备",
                     "料口",
                     "班组",
                     "重量",
                     "时间"
                      );

                  AddObjects(
                      sheet, 2, weightRecordDtos,
                      _ => _.DeviceName,
                      _ => _.EntranceName,
                      _ => _.TeamName,
                      _ => _.NetWeight,
                      _ => _.Time
                      );


                  //var lastLoginTimeColumn = sheet.Column(3);
                  //lastLoginTimeColumn.Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";

                  var creationTimeColumn = sheet.Column(5);
                  creationTimeColumn.Style.Numberformat.Format = "yyyy-MM-dd HH:mm:ss";

                  for (var i = 1; i <= 5; i++)
                  {
                      sheet.Column(i).AutoFit();
                  }
              });
        }
    }
}
