104 lines
3.5 KiB
C#
104 lines
3.5 KiB
C#
using CarParkValidationAPI.Datas;
|
|
using CarParkValidationAPI.Models;
|
|
using Microsoft.Extensions.Options;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using SpreadsheetLight;
|
|
using CarParkValidationAPI.Entities;
|
|
using System.IO;
|
|
|
|
namespace CarParkValidationAPI.Repository
|
|
{
|
|
public class ConcessionValidationReportRepository
|
|
{
|
|
private readonly DataContext _context;
|
|
private readonly IOptions<AppSettings> _appSettings;
|
|
const string DateFormat = "dd-MM-yyyy";
|
|
public ConcessionValidationReportRepository(
|
|
DataContext context, IOptions<AppSettings> appSettings)
|
|
{
|
|
_context = context;
|
|
_appSettings = appSettings;
|
|
}
|
|
|
|
public async Task<ResultModel<FileContent>> GetConcessionValidationReport(DateTime fromDate, DateTime toDate)
|
|
{
|
|
//excel SLDocument sl = new SLDocument();
|
|
int statusCode = 1;
|
|
ConcessionValidationExtDto item;
|
|
int col = 1;
|
|
int row = 1;
|
|
SLDocument sl = new SLDocument();
|
|
|
|
|
|
// add the title first
|
|
sl.SetCellValue(row, col++, "Date");
|
|
sl.SetCellValue(row, col++, "Concession Card");
|
|
sl.SetCellValue(row, col++, "Concession Holder");
|
|
sl.SetCellValue(row, col++, "ConcessionExpiry");
|
|
sl.SetCellValue(row, col++, "ConcessionType");
|
|
sl.SetCellValue(row, col++, "ValidationPiont");
|
|
sl.SetCellValue(row, col++, "StaffLink No");
|
|
|
|
//format date
|
|
|
|
SLStyle style = sl.CreateStyle();
|
|
style.FormatCode = "dd/mm/yyyy hh:mm:ss";
|
|
sl.SetColumnStyle(1, style);
|
|
style = sl.CreateStyle();
|
|
style.Font.Bold = true;
|
|
sl.SetRowStyle(1, style);
|
|
|
|
var list = await _context.SelectConcessionValidationByDate(true, fromDate.ToLocalTime(), toDate.ToLocalTime());
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
col = 1;
|
|
item = list[i];
|
|
row = i + 2;
|
|
sl.SetCellValue(row, col++, item.ValidateDate);
|
|
sl.SetCellValue(row, col++, item.ConcessionCard);
|
|
sl.SetCellValue(row, col++, item.ConcessionHolder);
|
|
sl.SetCellValue(row, col++, item.ConcessionExpiry);
|
|
sl.SetCellValue(row, col++, item.ConcessionType);
|
|
sl.SetCellValue(row, col++, item.ValidationPiont);
|
|
sl.SetCellValue(row, col++, item.StafflinkNo);
|
|
}
|
|
byte[] array;
|
|
// sl.SaveAs("C:\\Temp\\Report\\ConcessionValidationDate" + DateTime.Now.ToString("yyyyMMddHHmm") + ".xlsx");
|
|
using (MemoryStream ws = new MemoryStream())
|
|
{
|
|
sl.SaveAs(ws);
|
|
array = ws.ToArray();
|
|
/*
|
|
using (FileStream fs = new FileStream("c:\\temp\\Report\\conReport.xlsx",FileMode.Create,FileAccess.Write))
|
|
{
|
|
ws.WriteTo(fs);
|
|
fs.Close();
|
|
}
|
|
*/
|
|
ws.Close();
|
|
|
|
}
|
|
|
|
|
|
var result = new FileContent
|
|
{
|
|
Content = array,
|
|
FileName = "Report" +DateTime.Now.ToString("yyyy_MM_dd_HH_mm")+ ".xlsx",
|
|
|
|
};
|
|
|
|
|
|
|
|
return new ResultModel<FileContent>
|
|
{
|
|
Data = result,
|
|
StatusCode = statusCode
|
|
};
|
|
|
|
}
|
|
}
|
|
}
|