using Microsoft.Identity.Client;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics.Metrics;
using System.Drawing;
using System.Drawing.Printing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using static System.Windows.Forms.AxHost;
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
using static System.Windows.Forms.VisualStyles.VisualStyleElement.ListView;

namespace WMS_project
{
    public partial class QuoteInvoiceForms : Form
    {


        public QuoteInvoiceForms(string companyName, string customerName, string customerAddress,
        string country, string city, string state, string zip,
        string phoneOne, string phoneTwo, string email,
        string companyNameB, string custNameB, string customerAddressB,
        string countryB, string cityB, string stateB, string zipB,
        string phoneOneB, string phoneTwoB)
        {
            InitializeComponent();
            PopulateInvoiceData(
             companyName, customerName, customerAddress,
            country, city, state, zip, phoneOne, phoneTwo, email,
            companyNameB, custNameB, customerAddressB,
            countryB, cityB, stateB, zipB, phoneOneB, phoneTwoB);
        }

        public void PopulateInvoiceData(string companyName, string customerName, string customerAddress,
        string country, string city, string state, string zip,
        string phoneOne, string phoneTwo, string email,
        string companyNameB, string custNameB, string customerAddressB,
        string countryB, string cityB, string stateB, string zipB,
        string phoneOneB, string phoneTwoB)
        {
            this.companyNameLabel.Text = companyName;
            this.customerNameLabel.Text = customerName;
            this.billingAddressLabel.Text = customerAddressB;
            this.companyLocationLabel.Text = country + ", " + city + ", " + state + ", " + zip;
            this.companyPhoneLabel.Text = "Primary: " + phoneOne + " || Secondary: " + phoneTwo;
            this.billingEmailLabel.Text = email;
            this.billingNameLabel.Text = companyNameB;
            this.billingCustomerLabel.Text = custNameB;
            this.companyAddressLabel.Text = customerAddress;
            this.billingLocationLabel.Text = countryB + ", " + cityB + ", " + stateB + ", " + zipB;
            this.billingPhoneLabel.Text = "Primary: " + phoneOneB + " || Secondary: " + phoneTwoB;
        }
        private void PrintDocument1_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            Graphics g = e.Graphics;

            // Create a bitmap to hold the form's image
            Bitmap bmp = new Bitmap(this.Width, this.Height);

            // Draw the form onto the bitmap
            this.DrawToBitmap(bmp, new Rectangle(0, 0, this.Width, this.Height));

            // Draw the bitmap on the print page
            g.DrawImage(bmp, e.PageBounds);
        }

        private void PrintButton_Click(object sender, EventArgs e)
        {
            PrintDocument pd = new PrintDocument();
            pd.PrintPage += new PrintPageEventHandler(PrintDocument1_PrintPage);

            PrintDialog printDialog = new PrintDialog();
            printDialog.Document = pd;

            if (printDialog.ShowDialog() == DialogResult.OK)
            {
                PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();
                printPreviewDialog.Document = pd;
                printPreviewDialog.ShowDialog();
            }
        }

        public void previewButton_Click(object sender, EventArgs e)
        {
            using (PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog())
            {
                printPreviewDialog.Document = printDocument1;
                printPreviewDialog.ShowDialog();
            }
        }
        public void UpdateListView(string itemNumber, string orderQuantity, string shipQuantity, string description)
        {
            bool found = false;

            // Check if a row with the given itemNumber already exists
            foreach (ListViewItem item in listView1.Items)
            {
                if (item.SubItems[0].Text == itemNumber) // Assuming itemNumber is in the first column
                {
                    // Update the existing row
                    item.SubItems[1].Text = description;
                    item.SubItems[2].Text = orderQuantity;
                    item.SubItems[3].Text = shipQuantity;
                    found = true;
                    break;
                }
            }

            if (!found)
            {
                // If the itemNumber doesn't exist, add a new row
                ListViewItem listViewItem = new ListViewItem(itemNumber);
                listViewItem.SubItems.Add(description);
                listViewItem.SubItems.Add(orderQuantity);
                listViewItem.SubItems.Add(shipQuantity);

                listView1.Items.Add(listViewItem);
            }
        }
        private void quoteinvoiceForms_Load(object sender, EventArgs e)
        {

        }

        private void addItem_Click(object sender, EventArgs e)
        {
            inputDialog inputForm = new inputDialog(this);
            inputForm.ShowDialog();
        }

    }
}

