using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Printing;
using Font = System.Drawing.Font;

namespace HSUCO_Cargo_Garage_Operation_Program
{


    internal class PrintFilingReceipt
    {
        private List<PrintFilingReceiptInformation> _printFilingReceiptInformation;
        private int _count;
        public PrintDocument printDocument;
        public PrintFilingReceipt(List<PrintFilingReceiptInformation> printFilingReceiptInformation)
        {
            _printFilingReceiptInformation = printFilingReceiptInformation;
            _count = 0;
            printDocument = new PrintDocument();
            printDocument.DocumentName = "접수증";
            printDocument.PrintPage += PrintPage;
            printDocument.DefaultPageSettings.Margins.Top = Convert.ToInt32(50); printDocument.DefaultPageSettings.Margins.Left = Convert.ToInt32(50);
            printDocument.DefaultPageSettings.Margins.Left = Convert.ToInt32(30);
            printDocument.DefaultPageSettings.Margins.Right = Convert.ToInt32(30);

        }
        public void PrintPage(object sender, PrintPageEventArgs e)
        {
            e.Graphics.DrawRectangle(new Pen(Brushes.Black, 3), e.MarginBounds.Left, e.MarginBounds.Top,
               e.MarginBounds.Width, e.MarginBounds.Height);

            e.Graphics.DrawLine(new Pen(Brushes.Black, 1), new Point(e.MarginBounds.Left, e.MarginBounds.Top + 290), new Point(e.MarginBounds.Right, e.MarginBounds.Top + 290));
            e.Graphics.DrawLine(new Pen(Brushes.Black, 1), new Point(e.MarginBounds.Left, e.MarginBounds.Top + 340), new Point(e.MarginBounds.Right, e.MarginBounds.Top + 340));
            e.Graphics.DrawLine(new Pen(Brushes.Black, 1), new Point(e.MarginBounds.Left, e.MarginBounds.Top + 390), new Point(e.MarginBounds.Right, e.MarginBounds.Top + 390));
            e.Graphics.DrawLine(new Pen(Brushes.Black, 1), new Point(e.MarginBounds.Left, e.MarginBounds.Top + 440), new Point(e.MarginBounds.Right, e.MarginBounds.Top + 440));
            e.Graphics.DrawLine(new Pen(Brushes.Black, 1), new Point(e.MarginBounds.Left, e.MarginBounds.Top + 490), new Point(e.MarginBounds.Right, e.MarginBounds.Top + 490));

            e.Graphics.DrawLine(new Pen(Brushes.Black, 1), new Point(e.MarginBounds.Left + 280, e.MarginBounds.Top + 290), new Point(e.MarginBounds.Left + 280, e.MarginBounds.Top + 490));
            e.Graphics.DrawLine(new Pen(Brushes.Black, 1), new Point(e.MarginBounds.Left + 520, e.MarginBounds.Top + 440), new Point(e.MarginBounds.Left + 520, e.MarginBounds.Top + 490));


            int totalWidth = (int)e.PageBounds.Width;
            int totalHeight = (int)e.PageBounds.Height;

            CenterTextWriter($"접 수 증", new Font("맑은 고딕", 30, FontStyle.Bold), e.Graphics, totalWidth, e.MarginBounds.Top + 100);


            e.Graphics.DrawString($"제 {_printFilingReceiptInformation[_count].No}호", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 100, e.MarginBounds.Top + 250);
            e.Graphics.DrawString($"접수일 : {_printFilingReceiptInformation[_count].DateReception.ToString("yyyy-MM-dd")}", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 500, e.MarginBounds.Top + 250);

            e.Graphics.DrawString($"① 신청인", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 50, e.MarginBounds.Top + 300);
            e.Graphics.DrawString($"{_printFilingReceiptInformation[_count].Name}", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 300, e.MarginBounds.Top + 300);
            e.Graphics.DrawString($"② 생년월일(법인등록번호)", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 50, e.MarginBounds.Top + 350);
            e.Graphics.DrawString($"{_printFilingReceiptInformation[_count].PersonalNumber}", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 300, e.MarginBounds.Top + 350);
            e.Graphics.DrawString($"③ 주소", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 50, e.MarginBounds.Top + 400);
            e.Graphics.DrawString($"{_printFilingReceiptInformation[_count].Address}", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 300, e.MarginBounds.Top + 400);
            e.Graphics.DrawString($"④ 차량번호", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 50, e.MarginBounds.Top + 450);
            e.Graphics.DrawString($"화물차량", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 289, e.MarginBounds.Top + 440);
            e.Graphics.DrawString($"{_printFilingReceiptInformation[_count].CargoVehicleNumber}", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 310, e.MarginBounds.Top + 460);
            e.Graphics.DrawString($"일반차량", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 528, e.MarginBounds.Top + 440);
            e.Graphics.DrawString($"{_printFilingReceiptInformation[_count].PassengerVehicleNumber}", new Font("맑은 고딕", 12), Brushes.Black, e.MarginBounds.Left + 550, e.MarginBounds.Top + 460);

            CenterTextWriter("화성도시공사 사장", new Font("맑은 고딕", 20, FontStyle.Bold), e.Graphics, totalWidth, e.MarginBounds.Top + 800);
            _count++;
            e.HasMorePages = _printFilingReceiptInformation.Count > _count;
        }

        private void CenterTextWriter(string text, Font font, Graphics g, int totalWidth, int posY)
        {
            SizeF textSize = g.MeasureString(text, font);
            float textPosX = (totalWidth - textSize.Width) / 2;
            g.DrawString(text, font, Brushes.Black, textPosX, posY);
        }

    }
}
