コード例 #1
0
        private void CheckBox1_CheckedChanged(object sender, EventArgs e)
        {
            groupBox2.Visible = groupBox2.Enabled = checkBox1.Checked;
            maskedTextBox1.Text = "";
            numericUpDown1.Value = 1;
            productsForRemaking.Clear();


            elementForRemaking = null;
            if (checkBox1.Checked)
            {
                Height = heightProductsWithRemake;
                panel1.Location = panel1PositionProductWithRemake;
                comboBox2.Enabled = checkBox1.Checked;
                bsConteinersForRemakingCollection = new BindingSource();
                comboBox2.IntegralHeight = false;
                numericUpDown2.Value = 1;
                listBox1.Items.Clear();

                ProductRepository repos = new ProductRepository();

                try
                {
                    // Оскільки деякі продукти, 
                    // які мають спільний головний інгредієнт 
                    // можна переробити, то ми витягуємо список 
                    // всіх продуктів які мають спільний головний інгредієнт.

                    ////////var name = comboBox1.SelectedItem.ToString().Substring(comboBox1.SelectedItem.ToString().IndexOf("\""));
                    ////////var data = repos.GetProductConteinerDataSource().
                    ////////Where(elem => elem.Name.Contains(name) & elem.Amount != 0 & elem.Weight <= 6).
                    ////////Select(element => $"{element.Name} {element.Weight}").ToList();

                    conteinersForRemakingCollection = repos.GetProductConteinerDataSource().Where(elem => elem.Amount != 0 & elem.Weight <= 6).Select(n => n.ToString()).ToList();
                    if (conteinersForRemakingCollection.Count == 0)
                    {
                        checkBox1.Checked = false;
                        MessageBox.Show(@"Продукту для переробки не існує", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        bsConteinersForRemakingCollection.DataSource = conteinersForRemakingCollection;
                        comboBox2.DataSource = bsConteinersForRemakingCollection;
                    }
                }
                catch (Exception)
                {
                    comboBox2.DataSource = null;
                }
            }
            else
            {
                this.Height = heightProductsWithoutRemake;
                panel1.Location = panel1PositionProductWithoutRemake;
            }
            groupBox2.Visible = groupBox2.Enabled = checkBox1.Checked;
            maskedTextBox1.Text = "";
            numericUpDown1.Value = 1;
        }
コード例 #2
0
        private void Button2_Click(object sender, EventArgs e)
        {
            try
            {
                if (!comboBox2.SelectedItem.Equals(null))
                {
                    elementForRemaking = new ProductConteiner(
                        defProductForRemaking.Name,
                        defProductForRemaking.Weight,
                        Decimal.ToInt32(numericUpDown2.Value)
                    );

                    bool wasNotFound = true;
                    listBox1.Items.Clear();

                    for (int index = 0; index < productsForRemaking.Count(); index++)
                    {
                        if (productsForRemaking[index].Name == elementForRemaking.Name & productsForRemaking[index].Weight == elementForRemaking.Weight)
                        {
                            if ((productsForRemaking[index].Amount + elementForRemaking.Amount) > Int32.Parse(label7.Text))
                            {
                                MessageBox.Show(@"Кіликість продукту занадто велика.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            }
                            else
                                productsForRemaking[index].Amount += elementForRemaking.Amount;
                            wasNotFound = false;
                        }
                        listBox1.Items.Add(productsForRemaking[index].ToString());
                    }
                    if (wasNotFound)
                    {
                        productsForRemaking.Add(elementForRemaking);
                        listBox1.Items.Add(elementForRemaking.ToString());
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
コード例 #3
0
        private void ComboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                if (comboBox2.SelectedItem == null)
                    return;
                var productRepository = new ProductRepository();
                defProductForRemaking = productRepository.GetProductConteinerDataSource().
                    First(element => element.ToString() == comboBox2.SelectedItem.ToString());
                label7.Text = defProductForRemaking.Amount.ToString();
                numericUpDown2.Minimum = 1;
                numericUpDown2.Maximum = Int32.Parse(label7.Text);

            }
            catch (NullReferenceException)
            {
                label7.Text = @"0";
                numericUpDown2.Minimum = 0;
                numericUpDown2.Maximum = 0;
            }
        }