using CCDCount.DLL.Tools;
using CCDCount.MODEL.SqlDataModel;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CCDCount.DLL.AuditTrail
{
    public class ErrorMessageRecordClass
    {
        private byte[] imageBytes = null;
        public void GetRecordLogo(byte[] LogoPath)
        {
            imageBytes = LogoPath;
        }
        public string ErrorMessageRecordToPDF(List<ErroeMesDataModelClass> ErrrorMes)
        {
            string SavePath = $"{AppDomain.CurrentDomain.BaseDirectory}PDF\\ErrorMessageRecord.pdf";
            PDFGenerateTools pDFGenerate = new PDFGenerateTools(SavePath);
            pDFGenerate.InsertText("异常记录", 20, 3);
            pDFGenerate.InsertNewLine();
            if (imageBytes != null)
            {
                pDFGenerate.InsertImage(imageBytes);
            }
            pDFGenerate.InsertNewLine();
            pDFGenerate.InsertTable(ErrrorMes.Select(o =>
            new { o.Category, o.MessageType, o.Message, o.DateTime, o.UserID }).ToList(), "异常记录");
            pDFGenerate.SavePDF();
            return SavePath;
        }


        public string ErrorMessageRecordToPDFReColspan(List<ErroeMesDataModelClass> ErrorMes, List<string> ColSpanNames)
        {
            string SavePath = $"{AppDomain.CurrentDomain.BaseDirectory}PDF\\ErrorMessageRecord.pdf";
            float[] ColSpanWidth = { 10f, 10f, 40f, 15f, 15f, 10f };
            PDFGenerateTools pDFGenerate = new PDFGenerateTools(SavePath);
            pDFGenerate.InsertText("异常记录", 20, 3);
            pDFGenerate.InsertNewLine();
            if (imageBytes != null)
            {
                pDFGenerate.InsertImage(imageBytes);
            }
            pDFGenerate.InsertNewLine();
            pDFGenerate.InsertTable(ErrorMes.Select(o =>
            new { o.Category, o.MessageType, o.Message, o.Path, o.DateTime, o.UserID }).ToList(),ColSpanNames,ColSpanWidth, "异常记录");
            pDFGenerate.SavePDF();
            return SavePath;
        }

        public string ErrorMessageRecordToPDF(List<ErroeMesDataModelClass> ErrorMes, string FileName)
        {
            string SavePath = $"{AppDomain.CurrentDomain.BaseDirectory}PDF\\{FileName}.pdf";
            PDFGenerateTools pDFGenerate = new PDFGenerateTools(SavePath);
            pDFGenerate.InsertText("异常记录", 20, 3);
            pDFGenerate.InsertNewLine();
            if (imageBytes != null)
            {
                pDFGenerate.InsertImage(imageBytes);
            }
            pDFGenerate.InsertNewLine();
            pDFGenerate.InsertTable(ErrorMes.Select(o =>
            new { o.Category, o.MessageType, o.Message, o.DateTime, o.UserID }).ToList(), "异常记录");
            pDFGenerate.SavePDF();
            return SavePath;
        }
    }
}
