Пример #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            ConteinerRepository conteinerRepository = new ConteinerRepository();
            ProductRepository   productRepository   = new ProductRepository();

            try
            {
                foreach (var elem in productCount)
                {
                    conteinerRepository.Remove(elem.Key.Id, date, 2, elem.Value);
                }

                MessageBox.Show(@"Продукти успішно списані.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information);

                this.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                invoiceFile.Workbooks.Close();
                invoiceFile.Quit();
                updateInformation();
            }
        }
Пример #2
0
        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (textBox3.Text.Contains("№"))
                {
                    int cantainerId = Int32.Parse(textBox3.Text.Split('?')[1].Split('№')[0]);
                    ConteinerRepository conteinerRepository = new ConteinerRepository();
                    ProductRepository   productRepository   = new ProductRepository();

                    Conteiner currConteiner = conteinerRepository.GetDataSource().First(n => n.Id == cantainerId);
                    Product   currProduct   = productRepository.GetDataSource().First(n => n.Id == currConteiner.ProductId);
                    string    productName   = currProduct.Name;
                    double    productWidth  = currConteiner.Weight;
                    int       productCount  = 1;
                    double    price         = Double.Parse(textBox1.Text);
                    AddProductContainer(productName, productWidth, productCount, price);

                    textBox3.Text = "";
                }
            } catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #3
0
 private void ComboBox1_SelectedIndexChanged(object sender, EventArgs e)
 {
     if (radioButton1.Checked)
     {
         if (comboBox1.SelectedItem == null)
         {
             return;
         }
         var productRepository   = new ProductRepository();
         var conteinerRepository = new ConteinerRepository();
         var productConteiner    = productRepository.GetProductConteinerDataSource().
                                   First(element => $"{element.Name} {element.Weight}" == comboBox1.SelectedItem.ToString());
         var product   = productRepository.GetDataSource().First(element => element.Name == productConteiner.Name);
         var conteiner = conteinerRepository.GetDataSource().First(elem => elem.ProductId == product.Id & elem.Weight == productConteiner.Weight);
         numericUpDown1.Maximum = conteiner.Amount;
     }
 }
Пример #4
0
        private void RemoveProductsForRemaking()
        {
            ProductRepository productRepository = new ProductRepository();

            ConteinerRepository conteinerRepository = new ConteinerRepository();

            foreach (var elementOfRemaking in productsForRemaking)
            {

                var product = productRepository.GetDataSource()
                    .First(element => element.Name == elementOfRemaking.Name);

                var conteiner = conteinerRepository.GetDataSource()
                    .First(elem => elem.ProductId == product.Id & elem.Weight == elementOfRemaking.Weight);

                conteinerRepository.Remove(conteiner.Id, dateTimePicker1.Value, 3, elementOfRemaking.Amount);
            }
        }
Пример #5
0
        private void Button2_Click(object sender, EventArgs e)
        {
            if (patch != null)
            {
                var repository = new ConteinerRepository();
                try
                {
                    repository.BackupData(patch);

                    MessageBox.Show($"Локальна копія створена.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information);

                    this.Close();
                }
                catch (Exception exception)
                {
                    MessageBox.Show(exception.Message, "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
        }
Пример #6
0
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (radioButton1.Checked)
                {
                    var productRepository   = new ProductRepository();
                    var conteinerRepository = new ConteinerRepository();
                    var productConteiner    = productRepository.GetProductConteinerDataSource().
                                              First(element => $"{element.Name} {element.Weight}" == comboBox1.SelectedItem.ToString());
                    var product   = productRepository.GetDataSource().First(element => element.Name == productConteiner.Name);
                    var conteiner = conteinerRepository.GetDataSource().First(elem => elem.ProductId == product.Id & elem.Weight == productConteiner.Weight);
                    conteinerRepository.Remove(conteiner.Id, dateTimePicker1.Value, 1, Decimal.ToInt32(numericUpDown1.Value));
                }
                else if (radioButton2.Checked)
                {
                    var ingredientRepository = new IngredientRepository();
                    var packageRepository    = new PackageRepository();
                    var ingredientPackage    = ingredientRepository.GetIngredientPackageDataSource().
                                               First(element => $"{element.Name} {element.Weight}" == comboBox1.SelectedItem.ToString());
                    var ingredient = ingredientRepository.GetDataSource().First(element => element.Name == ingredientPackage.Name);
                    var conteiner  = packageRepository.GetDataSource().First(elem => elem.IngredientId == ingredient.Id & elem.Weight == ingredientPackage.Weight);
                    packageRepository.Remove(conteiner.Id, dateTimePicker1.Value, Double.Parse(maskedTextBox1.Text));
                }
                else
                {
                    TareRepository tareRepository  = new TareRepository();
                    Tare           tareForRemoving = tareRepository.GetDataSource().
                                                     First(elem => $"{elem.Name}   {elem.Amount}" == comboBox1.SelectedItem.ToString());
                    tareForRemoving.Amount = Decimal.ToInt32(numericUpDown1.Value);

                    tareRepository.Remove(tareForRemoving);
                }
                RadioButton1_CheckedChanged(null, null);

                MessageBox.Show(@"Об'єкт успішно списано.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
                updateInformation();
            }  catch (Exception)
            {
                MessageBox.Show(@"Помилка списання", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #7
0
        private void comboBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            try
            {
                if (radioButton1.Checked && comboBox1.Text.Contains("№"))
                {
                    int cantainerId = Int32.Parse(comboBox1.Text.Split('?')[1].Split('№')[0]);
                    ConteinerRepository conteinerRepository = new ConteinerRepository();

                    Conteiner currConteiner = conteinerRepository.GetDataSource().First(n => n.Id == cantainerId);
                    conteinerRepository.Remove(currConteiner.Id, dateTimePicker1.Value, 1, 1);

                    //MessageBox.Show(@"Об'єкт успішно списано.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    updateInformation();

                    comboBox1.Text = "";
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Пример #8
0
        private void Button1_Click(object sender, EventArgs e)
        {
            try
            {
                if (radioButton1.Checked)
                {

                    ConteinerRepository conteinerRepository = new ConteinerRepository();
                    IngredientsForProductRepository receiptRepository = new IngredientsForProductRepository();
                    IngredientRepository ingredientRepository = new IngredientRepository();

                    double weight = Double.Parse(maskedTextBox2.Text);
                    double amount = Double.Parse(maskedTextBox3.Text);
                    double weightIngredientKeyBatch = weight * amount;
                    double weightAllProducts = entryProductsContainerCollection.Sum(n => n.Amount * n.Weight);
                    double weightForRemaking = 0;


                    var ingredients = ingredientRepository.GetDataSource();
                    var detailReceipt = receipt.Join(
                        ingredients,
                        elem => elem.IngredientId,
                        ingr => ingr.Id,
                        (elem, ingr) => new
                        {
                            ingr.Name,
                            elem.Weight
                        }).ToList();

                    double weightIngredientKeyOnOneKilo = detailReceipt.First(n => n.Name == comboBox3.SelectedItem.ToString()).Weight;

                    double weightBatch = weightIngredientKeyBatch / weightIngredientKeyOnOneKilo;


                    if (weight <= 0)
                    {
                        MessageBox.Show(@"Некоректна вага інгредієнту-ключа на 1 заміс", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (amount <= 0)
                    {
                        MessageBox.Show(@"Некоректна кількість замісів", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (checkBox1.Checked)
                    {
                        weightForRemaking = productsForRemaking.Sum(n => n.Amount * n.Weight);
                    }

                    if (weightAllProducts > weightBatch + weightForRemaking || weightAllProducts == 0)
                    {

                        MessageBox.Show($"Некоректна вага всіх продуктів.\nВидаліть зайві продукти, збільшіть кількість замісів,\nабо додайте переробку.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    conteinerRepository.AddCollectionContainers(entryProductsContainerCollection, dateTimePicker1.Value, weightBatch);
                    RemoveProductsForRemaking();
                }
                else
                {
                    ConteinerRepository conteinerRepository = new ConteinerRepository();

                    double weightAllProducts = entryProductsContainerCollection.Sum(n => n.Amount * n.Weight);
                    double weightForRemaking = 0;

                    if (checkBox1.Checked)
                    {
                        weightForRemaking = productsForRemaking.Sum(n => n.Amount * n.Weight);
                    }

                    if (weightAllProducts > weightForRemaking || weightAllProducts == 0)
                    {
                        MessageBox.Show($"Некоректна вага всіх продуктів.\nВидаліть зайві продукти, збільшіть кількість замісів,\nабо додайте переробку.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    conteinerRepository.AddCollectionContainers(entryProductsContainerCollection, dateTimePicker1.Value, 0);
                    RemoveProductsForRemaking();
                    productsForRemaking.Clear();
                }

                UpdateListBoxProduct();

                // Друк штрих-кодів
                if (checkBox2.Checked)
                {
                    addedConteiners = new List<Conteiner>();
                    ConteinerRepository conteinerRepository = new ConteinerRepository();
                    var data = conteinerRepository.GetDataSource();
                    foreach (var item in entryProductsContainerCollection)
                    {
                        var oneProduct = data.First(n => n.ProductId == item.ProductId && n.Weight == item.Weight);
                        oneProduct.Amount = item.Amount;
                        addedConteiners.Add(oneProduct);
                    }


                    ProductRepository productRepository = new ProductRepository();
                    PrintBarcode printBarcode = new PrintBarcode();
                    foreach (var item in addedConteiners)
                    {
                        for (int i = 0; i < item.Amount; i++)
                        {
                            string productName = productRepository.GetDataSource().First(n => n.Id == item.ProductId).Name + " " + item.Weight + " кг.";
                            printBarcode.Print(item, productName);
                        }
                    }
                }

                checkBox1.Checked = false;

                MessageBox.Show($"Операція успішно виконана.", "Sucsess", MessageBoxButtons.OK, MessageBoxIcon.Information);

            }

            catch (NullReferenceException)
            {
                MessageBox.Show($"Не вибрано інгредієнт-ключ.\nБудь ласка виберіть інгредієнт-ключ", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                updateInformation();
            }
        }
Пример #9
0
        private void BtnOpen_Click(object sender, EventArgs e)
        {
            try
            {
                string nameProduct;
                int    count;
                double weight;

                productCount.Clear();
                textBox1.Text = "";

                ConteinerRepository conteinerRepository = new ConteinerRepository();
                ProductRepository   productRepository   = new ProductRepository();

                OpenFileDialog OPF = new OpenFileDialog();
                OPF.Filter = "MS Excel files|*.xlsx";
                OPF.Title  = "Excel invoice";
                if (OPF.ShowDialog() == DialogResult.OK)
                {
                    string fileInvoice = OPF.FileName;
                    // Відкриття файлу накладної.
                    invoiceFile.Workbooks.Open(fileInvoice.ToString());
                }

                sheet = invoiceFile.Sheets[2];

                string dateString = sheet.Range["E1"].Value;
                var    massDate   = dateString.Split('.');

                date = new DateTime(Int32.Parse(massDate[2]), Int32.Parse(massDate[1]), Int32.Parse(massDate[0]));
                int i = 1;
                while ((string)(sheet.Range["A" + i].Value) != null)
                {
                    nameProduct    = sheet.Range["A" + i].Value;
                    count          = (int)sheet.Range["B" + i].Value;
                    weight         = sheet.Range["C" + i].Value;
                    textBox1.Text += nameProduct + "   " + count + " шт. по " + String.Format("{0:f2}", weight) + " кг.\r\n";
                    var product = productRepository.GetDataSource().FirstOrDefault(n => n.Name == nameProduct);
                    if (product == null)
                    {
                        throw new ArgumentException();
                    }
                    var conteiner = conteinerRepository.GetDataSource().FirstOrDefault(n => (n.ProductId == product.Id & n.Weight == weight));
                    if (conteiner == null)
                    {
                        throw new ArgumentNullException("");
                    }
                    productCount.Add(conteiner, count);
                    i++;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                invoiceFile.Workbooks.Close();
                invoiceFile.Quit();
            }
        }