Esempio n. 1
0
        private void button5_Click(object sender, EventArgs e)
        {
            List <ProductInfo> ProductsInfo = new List <ProductInfo>();

            for (int i = 0; i < dataGrid.Rows.Count - 1; i++)
            {
                ProductInfo ProductInfo = new ProductInfo
                {
                    Product     = DbEditor.GetItemByName(dataGrid[0, i].Value.ToString()),
                    Count       = Convert.ToInt32(dataGrid[1, i].Value),
                    vatSumm     = Convert.ToDouble(dataGrid[6, i].Value),
                    summWithVat = Convert.ToDouble(dataGrid[5, i].Value)
                };
                ProductsInfo.Add(ProductInfo);
            }

            textBox1.Text += ProductsInfo[0].Product.Name + Environment.NewLine;
        }
Esempio n. 2
0
        private void button6_Click(object sender, EventArgs e)
        {
            int sellerId   = comboBox1.SelectedIndex + 1;
            int customerId = comboBox2.SelectedIndex + 1;
            int currencyId = comboBox3.SelectedIndex + 1;
            int unitId     = comboBox3.SelectedIndex + 1;

            if (sellerId <= 0 && customerId <= 0 && currencyId <= 0)
            {
                MessageBox.Show("Выберите продавца, покупателя и валюту из существующих или добавьте новые.", "Внимание",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
            else
            {
                string examplePath = Directory.CreateDirectory(Application.StartupPath + "/Example").FullName;
                string filePath;

                if (!File.Exists($"{examplePath}/Factura.xlsx"))
                {
                    File.WriteAllBytes($"{examplePath}/Factura.xlsx", Resource.Factura);
                }

                Seller             Seller       = DbEditor.GetSellerById(sellerId);
                Customer           Customer     = DbEditor.GetCustomerById(customerId);
                Currency           Currency     = DbEditor.GetCurrencyById(currencyId);
                List <ProductInfo> ProductsInfo = new List <ProductInfo>();

                for (int i = 0; i < dataGrid.Rows.Count - 1; i++)
                {
                    ProductInfo ProductInfo = new ProductInfo
                    {
                        Product        = DbEditor.GetItemByName(dataGrid[0, i].Value.ToString()),
                        Count          = Convert.ToInt32(dataGrid[1, i].Value),
                        vatSumm        = Convert.ToDouble(dataGrid[6, i].Value),
                        summWithVat    = Convert.ToDouble(dataGrid[5, i].Value),
                        summWithoutVat = Convert.ToDouble(dataGrid[7, i].Value)
                    };
                    ProductsInfo.Add(ProductInfo);
                }



                ExcelWorkbook WorkBook = new ExcelWorkbook($"{examplePath}/Factura.xlsx", Seller, Customer, ProductsInfo);


                WorkBook.facturaNumber     = numericUpDown1.Value.ToString();
                WorkBook.facturaDate       = dateTimePicker1.Value.ToString("dd MMMM yyyy");
                WorkBook.payDocumentNumber = numericUpDown2.Value.ToString();
                WorkBook.payDocumentDate   = dateTimePicker2.Value.ToString("dd MMMM yyyy");;
                WorkBook.currencyCode      = Currency.Code;
                WorkBook.Currency          = Currency.Name;



                // WorkBook.Products = Datas.ProductList;



                using (SaveFileDialog SaveFileDialog = new SaveFileDialog())
                {
                    SaveFileDialog.Filter = "Файлы Excel (*.xlsx) | *.xlsx";
                    if (SaveFileDialog.ShowDialog() == DialogResult.OK)
                    {
                        filePath = SaveFileDialog.FileName;
                        if (WorkBook.CreateFile(filePath) == null)
                        {
                            throw new Exception("Ошибка создания файла");
                        }
                    }
                }
            }
        }