private void ExportPDF(Sale[] sales = null)
        {
            string filePath = string.Empty;
            using (SaveFileDialog saveFile = new SaveFileDialog())
            {
                saveFile.Filter = "PDF (*.pdf)|*.pdf";
                if (saveFile.ShowDialog() == DialogResult.OK)
                {
                    filePath = saveFile.FileName;
                }
                else
                {
                    return;
                }
            }

            System.Threading.Tasks.Task.Run(() =>
            {
                var report = new PdfReport(filePath);
                report.Create(sales ?? this.sales);
                MessageBox.Show("Done!");
            });
        }
        private void ExportSelectionToPDF(object sender, EventArgs e)
        {
            if (this.sales.Length == 0)
            {
                MessageBox.Show("The sales table is empty.");
                return;
            }

            if (this.dataGridViewSales.SelectedRows.Count == 0)
            {
                MessageBox.Show("No selection.");
                return;
            }

            int selectedSalesCount = this.dataGridViewSales.SelectedRows.Count;
            var selectedSales = new Sale[selectedSalesCount];
            for (int i = 0; i < selectedSalesCount; i++)
            {
                int selectedRowIndex = this.dataGridViewSales.SelectedRows[i].Index;
                selectedSales[i] = this.sales[selectedRowIndex];
            }

            ExportPDF(selectedSales);
        }
        private Sale CreateSale(string productName, string shopName, string quantity, string price)
        {
            int productsQuantity;
            decimal productPrice;

            if (string.IsNullOrEmpty(productName))
            {
                throw new ArgumentNullException("Product name must not be null or empty.");
            }

            if (string.IsNullOrEmpty(shopName))
            {
                throw new ArgumentNullException("Shop name must not be null or empty.");
            }

            if (!int.TryParse(quantity, out productsQuantity))
            {
                throw new ArgumentException("Quanity is not an integer.");
            }

            if (!decimal.TryParse(price, out productPrice))
            {
                throw new ArgumentException("Product price is not a decimal.");
            }

            Product product = new Product() { Name = productName };
            Shop shop = new Shop() { Name = shopName };

            Sale sale = new Sale()
            {
                Product = product,
                Shop = shop,
                UnitPrice = productPrice,
                Quantity = productsQuantity,
            };

            return sale;
        }