Esempio n. 1
0
        private void reloadButton_pictureBox_Click(object sender, EventArgs e)
        {
            TimeSpan usingTime;
            TimeSpan remainingTime;
            double   usingTimeI;
            double   remainingTimeI;

            for (int i = 0; i < storage.GetStorage.Count; i++)
            {
                foreach (Goods item in storage.GetStorage)
                {
                    if (item is Groceries)
                    {
                        Groceries tmp = item as Groceries;
                        if (tmp.dateExpiration < DateTime.Now)
                        {
                            storage.DeleteItem(item);
                            break;
                        }
                        else if (item.isChanged == false)
                        {
                            usingTime      = tmp.dateExpiration - tmp.dateCreation;
                            remainingTime  = tmp.dateExpiration - DateTime.Now;
                            usingTimeI     = usingTime.TotalSeconds;
                            remainingTimeI = remainingTime.TotalSeconds;
                            if ((usingTimeI * 0.2) <= remainingTimeI)
                            {
                                item.price    /= 2;
                                item.isChanged = true;
                            }
                        }
                    }
                }
            }
            Update();
        }
Esempio n. 2
0
        private void addButton_pictureBox_Click(object sender, EventArgs e)
        {
            AddForm add = new AddForm();

            add.ShowDialog();
            bool check = false;

            if (add.isGrocerie == 1)
            {
                foreach (Goods item in storage.GetStorage)
                {
                    if (item is Groceries)
                    {
                        Groceries tmp = item as Groceries;
                        if (tmp == add.groceries)
                        {
                            item.quantity += add.groceries.quantity;
                            check          = true;
                            foreach (ListViewItem i in items_listView.Items)
                            {
                                if (i.Tag is Groceries)
                                {
                                    Groceries grocerie = i.Tag as Groceries;
                                    if (grocerie == add.groceries)
                                    {
                                        i.SubItems[4].Text = item.quantity.ToString();
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                if (check == false)
                {
                    storage.AddItem(add.groceries);
                    if (add.groceries.isChanged == true)
                    {
                        MessageBox.Show("Price was reduced", "Price", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    ListViewItem listViewItem = new ListViewItem(add.groceries.name, 0);
                    listViewItem.Tag = add.groceries;
                    listViewItem.SubItems.Add("Grocerie");
                    listViewItem.SubItems.Add(add.groceries.producer);
                    listViewItem.SubItems.Add(add.groceries.price.ToString());
                    listViewItem.SubItems.Add(add.groceries.quantity.ToString());
                    items_listView.Items.Add(listViewItem);
                }
            }
            else if (add.isGrocerie == 2)
            {
                foreach (Goods item in storage.GetStorage)
                {
                    if (item is NonGroceries)
                    {
                        NonGroceries tmp = item as NonGroceries;
                        if (tmp == add.nonGroceries)
                        {
                            item.quantity += add.nonGroceries.quantity;
                            check          = true;
                            foreach (ListViewItem i in items_listView.Items)
                            {
                                if (i.Tag is NonGroceries)
                                {
                                    NonGroceries nonGrocerie = i.Tag as NonGroceries;
                                    if (nonGrocerie == add.nonGroceries)
                                    {
                                        i.SubItems[4].Text = item.quantity.ToString();
                                        break;
                                    }
                                }
                            }
                            break;
                        }
                    }
                }
                if (check == false)
                {
                    storage.AddItem(add.nonGroceries);
                    if (storage.GetStorage[storage.GetStorage.Count - 1].isChanged)
                    {
                        MessageBox.Show("Price was increased", "Price", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                    ListViewItem listViewItem = new ListViewItem(add.nonGroceries.name, 1);
                    listViewItem.Tag = add.nonGroceries;
                    listViewItem.SubItems.Add("NonGrocerie");
                    listViewItem.SubItems.Add(add.nonGroceries.producer);
                    listViewItem.SubItems.Add(add.nonGroceries.price.ToString());
                    listViewItem.SubItems.Add(add.nonGroceries.quantity.ToString());
                    items_listView.Items.Add(listViewItem);
                }
            }
        }
Esempio n. 3
0
        private void items_listView_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (items_listView.SelectedIndices.Count == 0)
            {
                weightOrGroup_label.Visible            = false;
                value1_label.Visible                   = false;
                dimensionsOrDateCreation_label.Visible = false;
                value2_label.Visible                   = false;
                dateExpiration_label.Visible           = false;
                value3_label.Visible                   = false;
                piece_label.Text = "0 pieces";
                index            = -1;
            }
            else
            {
                index = items_listView.SelectedIndices.Count - 1;
                var item = items_listView.SelectedItems[items_listView.SelectedIndices.Count - 1].Tag;
                if (item is Groceries)
                {
                    Groceries tmp = item as Groceries;
                    weightOrGroup_label.Visible            = true;
                    weightOrGroup_label.Text               = "Weight:";
                    value1_label.Visible                   = true;
                    value1_label.Text                      = tmp.weight.ToString();
                    dimensionsOrDateCreation_label.Visible = true;
                    dimensionsOrDateCreation_label.Text    = "Creation date:";
                    value2_label.Visible                   = true;
                    value2_label.Text                      = tmp.dateCreation.ToShortDateString().ToString();
                    dateExpiration_label.Visible           = true;
                    value3_label.Visible                   = true;
                    value3_label.Text                      = tmp.dateExpiration.ToShortDateString().ToString();
                    piece_label.Text = Counter(tmp.name).ToString() + " pieces";
                }
                else
                {
                    value3_label.Visible         = false;
                    dateExpiration_label.Visible = false;
                    NonGroceries tmp = item as NonGroceries;
                    weightOrGroup_label.Visible = true;
                    weightOrGroup_label.Text    = "Group:";
                    value1_label.Visible        = true;
                    switch (tmp.group)
                    {
                    case DestinationGroup.Nothing:
                        value1_label.Text = "Nothing";
                        break;

                    case DestinationGroup.Clothes:
                        value1_label.Text = "Clothes";
                        break;

                    case DestinationGroup.Machinery:
                        value1_label.Text = "Machinery";
                        break;

                    case DestinationGroup.Furniture:
                        value1_label.Text = "Furniture";
                        break;

                    case DestinationGroup.Dishes:
                        value1_label.Text = "Dishes";
                        break;

                    case DestinationGroup.Jewelry:
                        value1_label.Text = "Jewelry";
                        break;

                    default:
                        break;
                    }
                    dimensionsOrDateCreation_label.Visible = true;
                    dimensionsOrDateCreation_label.Text    = "Dimensions:";
                    value2_label.Visible = true;
                    value2_label.Text    = tmp.dimensions.height.ToString() + "x" + tmp.dimensions.length.ToString() + "x" + tmp.dimensions.width.ToString();
                    piece_label.Text     = Counter(tmp.name).ToString() + " pieces";
                }
            }
        }
Esempio n. 4
0
        private void openFileButton_pictureBox_Click(object sender, EventArgs e)
        {
            try
            {
                OpenFileDialog openFile = new OpenFileDialog();
                openFile.Title  = "Open from file";
                openFile.Filter = "Text files (*.txt)|*.txt";
                if (openFile.ShowDialog() == DialogResult.OK && openFile.FileName.Length > 0)
                {
                    using (System.IO.StreamReader of = new System.IO.StreamReader(openFile.FileName))
                    {
                        while (!of.EndOfStream)
                        {
                            bool   check = false;
                            string type  = of.ReadLine();
                            if (type == "Grocerie")
                            {
                                string name = of.ReadLine();
                                if (name == "")
                                {
                                    name = "No_name";
                                }
                                string producer = of.ReadLine();
                                if (producer == "")
                                {
                                    producer = "No_producer";
                                }
                                string strPrice = of.ReadLine();
                                int    price;
                                if (int.TryParse(strPrice, out price) == false)
                                {
                                    price = 0;
                                }
                                string strQuantity = of.ReadLine();
                                int    quantity;
                                if (int.TryParse(strQuantity, out quantity) == false)
                                {
                                    quantity = 0;
                                }
                                string strWeight = of.ReadLine();
                                int    weight;
                                if (int.TryParse(strWeight, out weight) == false)
                                {
                                    weight = 0;
                                }
                                string   strDate = of.ReadLine();
                                DateTime dateCreation;
                                if (DateTime.TryParse(strDate, out dateCreation) == false)
                                {
                                    dateCreation = DateTime.Now;
                                }
                                strDate = of.ReadLine();
                                DateTime dateExpiration;
                                if (DateTime.TryParse(strDate, out dateExpiration) == false)
                                {
                                    dateExpiration = DateTime.Now;
                                }
                                Groceries grocerie = new Groceries(name, producer, price, quantity, weight, dateCreation, dateExpiration);
                                foreach (Goods item in storage.GetStorage)
                                {
                                    if (item is Groceries)
                                    {
                                        Groceries tmp = item as Groceries;
                                        if (tmp == grocerie)
                                        {
                                            check          = true;
                                            item.quantity += grocerie.quantity;
                                            for (int i = 0; i < items_listView.Items.Count; i++)
                                            {
                                                if (items_listView.Items[i].Tag == item)
                                                {
                                                    items_listView.Items[i].SubItems[4].Text = item.quantity.ToString();
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                                if (check)
                                {
                                    continue;
                                }
                                storage.AddItem(grocerie);
                                ListViewItem listViewItem = new ListViewItem(grocerie.name, 0);
                                listViewItem.Tag = grocerie;
                                listViewItem.SubItems.Add("Grocerie");
                                listViewItem.SubItems.Add(grocerie.producer);
                                listViewItem.SubItems.Add(grocerie.price.ToString());
                                listViewItem.SubItems.Add(grocerie.quantity.ToString());
                                items_listView.Items.Add(listViewItem);
                            }
                            else if (type == "Non-Grocerie")
                            {
                                string name = of.ReadLine();
                                if (name == "")
                                {
                                    name = "No_name";
                                }
                                string producer = of.ReadLine();
                                if (producer == "")
                                {
                                    producer = "No_producer";
                                }
                                string strPrice = of.ReadLine();
                                int    price;
                                if (int.TryParse(strPrice, out price) == false)
                                {
                                    price = 0;
                                }
                                string strQuantity = of.ReadLine();
                                int    quantity;
                                if (int.TryParse(strQuantity, out quantity) == false)
                                {
                                    quantity = 0;
                                }
                                Dimensions dimensions = new Dimensions();
                                string     dimension  = of.ReadLine();
                                if (int.TryParse(dimension, out dimensions.height) == false)
                                {
                                    dimensions.height = 0;
                                }
                                dimension = of.ReadLine();
                                if (int.TryParse(dimension, out dimensions.length))
                                {
                                    dimensions.length = 0;
                                }
                                dimension = of.ReadLine();
                                if (int.TryParse(dimension, out dimensions.width) == false)
                                {
                                    dimensions.width = 0;
                                }
                                string strGroup = of.ReadLine();
                                int    group;
                                if (int.TryParse(strGroup, out group) == false)
                                {
                                    group = 0;
                                }
                                DestinationGroup destinationGroup = new DestinationGroup();
                                switch (group)
                                {
                                case 2:
                                    destinationGroup = DestinationGroup.Clothes;
                                    break;

                                case 3:
                                    destinationGroup = DestinationGroup.Machinery;
                                    break;

                                case 4:
                                    destinationGroup = DestinationGroup.Furniture;
                                    break;

                                case 5:
                                    destinationGroup = DestinationGroup.Dishes;
                                    break;

                                case 6:
                                    destinationGroup = DestinationGroup.Jewelry;
                                    break;

                                default:
                                    destinationGroup = DestinationGroup.Nothing;
                                    break;
                                }
                                NonGroceries nonGroceries = new NonGroceries(name, producer, price, quantity, dimensions, destinationGroup);
                                foreach (Goods item in storage.GetStorage)
                                {
                                    if (item is NonGroceries)
                                    {
                                        NonGroceries tmp = item as NonGroceries;
                                        if (tmp == nonGroceries)
                                        {
                                            check          = true;
                                            item.quantity += nonGroceries.quantity;
                                            item.quantity += nonGroceries.quantity;
                                            for (int i = 0; i < items_listView.Items.Count; i++)
                                            {
                                                if (items_listView.Items[i].Tag == item)
                                                {
                                                    items_listView.Items[i].SubItems[4].Text = item.quantity.ToString();
                                                }
                                            }
                                            break;
                                        }
                                    }
                                }
                                if (check)
                                {
                                    continue;
                                }
                                storage.AddItem(nonGroceries);
                                ListViewItem listViewItem = new ListViewItem(nonGroceries.name, 1);
                                listViewItem.Tag = nonGroceries;
                                listViewItem.SubItems.Add("NonGrocerie");
                                listViewItem.SubItems.Add(nonGroceries.producer);
                                listViewItem.SubItems.Add(nonGroceries.price.ToString());
                                listViewItem.SubItems.Add(nonGroceries.quantity.ToString());
                                items_listView.Items.Add(listViewItem);
                            }
                            else if (type == "")
                            {
                                return;
                            }
                            else
                            {
                                Exception exception = new Exception("File have mistakes");
                                throw exception;
                            }
                        }
                    }
                }
            }
            catch (Exception exp)
            {
                MessageBox.Show(exp.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Esempio n. 5
0
        private void saveFileButton_pictureBox_Click(object sender, EventArgs e)
        {
            if (storage.GetStorage.Count == 0)
            {
                MessageBox.Show("The storage is empty!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            SaveFileDialog saveFile = new SaveFileDialog();

            saveFile.Title  = "Save file";
            saveFile.Filter = "Text files (*.txt)|*.txt|All files (*.*)|*.*";
            if (saveFile.ShowDialog() == DialogResult.OK && saveFile.FileName.Length > 0)
            {
                using (System.IO.StreamWriter sf = new System.IO.StreamWriter(saveFile.FileName))
                {
                    foreach (Goods item in storage.GetStorage)
                    {
                        if (item is Groceries)
                        {
                            Groceries tmp = item as Groceries;
                            sf.WriteLine("Grocerie");
                            sf.WriteLine(tmp.name);
                            sf.WriteLine(tmp.producer);
                            sf.WriteLine(tmp.price);
                            sf.WriteLine(tmp.quantity);
                            sf.WriteLine(tmp.weight);
                            sf.WriteLine(tmp.dateCreation);
                            sf.WriteLine(tmp.dateExpiration);
                        }
                        else
                        {
                            NonGroceries tmp = item as NonGroceries;
                            sf.WriteLine("Non-Grocerie");
                            sf.WriteLine(tmp.name);
                            sf.WriteLine(tmp.producer);
                            sf.WriteLine(tmp.price);
                            sf.WriteLine(tmp.quantity);
                            sf.WriteLine(tmp.dimensions.height);
                            sf.WriteLine(tmp.dimensions.length);
                            sf.WriteLine(tmp.dimensions.width);
                            switch (tmp.group)
                            {
                            case DestinationGroup.Nothing:
                                sf.WriteLine(1);
                                break;

                            case DestinationGroup.Clothes:
                                sf.WriteLine(2);
                                break;

                            case DestinationGroup.Machinery:
                                sf.WriteLine(3);
                                break;

                            case DestinationGroup.Furniture:
                                sf.WriteLine(4);
                                break;

                            case DestinationGroup.Dishes:
                                sf.WriteLine(5);
                                break;

                            case DestinationGroup.Jewelry:
                                sf.WriteLine(6);
                                break;
                            }
                        }
                    }
                    sf.Close();
                }
            }
            MessageBox.Show("File saved", "Saved", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
Esempio n. 6
0
        private void uniqGoodsButton_pictureBox_Click(object sender, EventArgs e)
        {
            bool check = false;

            if (name_textBox.Text == String.Empty || producer_textBox.Text == String.Empty || outPrice_textBox.Text == String.Empty || outQuantity_textBox.Text == String.Empty)
            {
                check = true;
            }
            List <Goods> uniqGoods;

            if (grocerie_radioButton.Checked)
            {
                if (outWeight_textBox.Text == String.Empty)
                {
                    check = true;
                }
                if (!cDEnabled_checkBox.Checked || !eDEnabled_checkBox.Checked)
                {
                    check = true;
                }
                if (!check)
                {
                    items_listView.Items.Clear();
                    toPrice_textBox.Text    = outPrice_textBox.Text;
                    toQuantity_textBox.Text = outQuantity_textBox.Text;
                    toWeight_textBox.Text   = outWeight_textBox.Text;
                    Groceries uniq = new Groceries(name_textBox.Text, producer_textBox.Text, int.Parse(outPrice_textBox.Text), int.Parse(outQuantity_textBox.Text), int.Parse(outWeight_textBox.Text), outDateCreation_dateTimePicker.Value, outDateExpiration_dateTimePicker.Value);
                    uniqGoods = filterStorage.FindUniqGoods(uniq);
                    foreach (Goods item in uniqGoods)
                    {
                        ListViewItem listViewItem = new ListViewItem(item.name);
                        listViewItem.SubItems.Add("Grocerie");
                        listViewItem.SubItems.Add(item.producer);
                        listViewItem.SubItems.Add(item.price.ToString());
                        listViewItem.SubItems.Add(item.quantity.ToString());
                        items_listView.Items.Add(listViewItem);
                    }
                }
                else
                {
                    MessageBox.Show("You need to fill all of the fields!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
            else
            {
                if (outWidth_textBox.Text == String.Empty || outHeight_textBox.Text == String.Empty || outLength_textBox.Text == String.Empty || group_comboBox.SelectedIndex == -1)
                {
                    check = true;
                }
                if (!check)
                {
                    toWidth_textBox.Text  = outWidth_textBox.Text;
                    toHeight_textBox.Text = outHeight_textBox.Text;
                    toLength_textBox.Text = outLength_textBox.Text;
                    Dimensions dimensions = new Dimensions();
                    dimensions.height = int.Parse(outHeight_textBox.Text);
                    dimensions.length = int.Parse(outLength_textBox.Text);
                    dimensions.width  = int.Parse(outWidth_textBox.Text);
                    DestinationGroup group;
                    switch (group_comboBox.SelectedIndex)
                    {
                    case 0:
                        group = DestinationGroup.Clothes;
                        break;

                    case 1:
                        group = DestinationGroup.Machinery;
                        break;

                    case 2:
                        group = DestinationGroup.Furniture;
                        break;

                    case 3:
                        group = DestinationGroup.Dishes;
                        break;

                    case 4:
                        group = DestinationGroup.Jewelry;
                        break;

                    default:
                        group = DestinationGroup.Nothing;
                        break;
                    }
                    NonGroceries uniq = new NonGroceries(name_textBox.Text, producer_textBox.Text, int.Parse(outPrice_textBox.Text), int.Parse(outQuantity_textBox.Text), dimensions, group);
                    uniqGoods = filterStorage.FindUniqGoods(uniq);
                    foreach (Goods item in uniqGoods)
                    {
                        ListViewItem listViewItem = new ListViewItem(item.name);
                        listViewItem.SubItems.Add("NonGrocerie");
                        listViewItem.SubItems.Add(item.producer);
                        listViewItem.SubItems.Add(item.price.ToString());
                        listViewItem.SubItems.Add(item.quantity.ToString());
                        items_listView.Items.Add(listViewItem);
                    }
                }
                else
                {
                    MessageBox.Show("You need to fill all of the fields!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    return;
                }
            }
        }
Esempio n. 7
0
        private void acceptButton_pictureBox_Click(object sender, EventArgs e)
        {
            items_listView.Items.Clear();
            List <Goods> filterGoods = new List <Goods>();
            bool         check       = false;

            if (name_textBox.Text != String.Empty)
            {
                check = true;
                foreach (Goods item in filterStorage.GetStorage)
                {
                    if (item.name == name_textBox.Text)
                    {
                        filterGoods.Add(item);
                    }
                }
            }
            if (producer_textBox.Text != String.Empty)
            {
                if (check)
                {
                    for (int i = filterGoods.Count; i >= 0; i--)
                    {
                        foreach (Goods item in filterGoods)
                        {
                            if (item.producer != producer_textBox.Text)
                            {
                                filterGoods.Remove(item);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    check = true;
                    foreach (Goods item in filterStorage.GetStorage)
                    {
                        if (item.producer == producer_textBox.Text)
                        {
                            filterGoods.Add(item);
                        }
                    }
                }
            }
            if (outPrice_textBox.Text != String.Empty && toPrice_textBox.Text != String.Empty)
            {
                if (check)
                {
                    for (int i = filterGoods.Count; i >= 0; i--)
                    {
                        foreach (Goods item in filterGoods)
                        {
                            if (item.price < int.Parse(outPrice_textBox.Text) || item.price > int.Parse(toPrice_textBox.Text))
                            {
                                filterGoods.Remove(item);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    check = true;
                    foreach (Goods item in filterStorage.GetStorage)
                    {
                        if (item.price >= int.Parse(outPrice_textBox.Text) && item.price <= int.Parse(toPrice_textBox.Text))
                        {
                            filterGoods.Add(item);
                        }
                    }
                }
            }
            if (outQuantity_textBox.Text != String.Empty && toQuantity_textBox.Text != String.Empty)
            {
                if (check)
                {
                    for (int i = filterGoods.Count; i >= 0; i--)
                    {
                        foreach (Goods item in filterGoods)
                        {
                            if (item.quantity < int.Parse(outQuantity_textBox.Text) || item.quantity > int.Parse(toQuantity_textBox.Text))
                            {
                                filterGoods.Remove(item);
                                break;
                            }
                        }
                    }
                }
                else
                {
                    check = true;
                    foreach (Goods item in filterStorage.GetStorage)
                    {
                        if (item.quantity >= int.Parse(outQuantity_textBox.Text) && item.quantity <= int.Parse(toQuantity_textBox.Text))
                        {
                            filterGoods.Add(item);
                        }
                    }
                }
            }
            if (grocerie_radioButton.Checked)
            {
                if (outWeight_textBox.Text != String.Empty && toWeight_textBox.Text != String.Empty)
                {
                    if (check)
                    {
                        for (int i = filterGoods.Count; i >= 0; i--)
                        {
                            foreach (Goods item in filterGoods)
                            {
                                if (item is Groceries)
                                {
                                    Groceries tmp = item as Groceries;
                                    if (tmp.weight < int.Parse(outWeight_textBox.Text) || tmp.weight > int.Parse(toWeight_textBox.Text))
                                    {
                                        filterGoods.Remove(item);
                                        break;
                                    }
                                }
                                else
                                {
                                    filterGoods.Remove(item);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        check = true;
                        foreach (Goods item in filterStorage.GetStorage)
                        {
                            if (item is Groceries)
                            {
                                Groceries tmp = item as Groceries;
                                if (tmp.weight >= int.Parse(outWeight_textBox.Text) && tmp.weight <= int.Parse(toWeight_textBox.Text))
                                {
                                    filterGoods.Add(item);
                                }
                            }
                        }
                    }
                }
                if (cDEnabled_checkBox.Checked)
                {
                    if (check)
                    {
                        for (int i = filterGoods.Count; i >= 0; i--)
                        {
                            foreach (Goods item in filterGoods)
                            {
                                if (item is Groceries)
                                {
                                    Groceries tmp = item as Groceries;
                                    if (tmp.dateCreation < outDateCreation_dateTimePicker.Value || tmp.dateCreation > toDateCreation_dateTimePicker.Value)
                                    {
                                        filterGoods.Remove(item);
                                        break;
                                    }
                                }
                                else
                                {
                                    filterGoods.Remove(item);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        check = true;
                        foreach (Goods item in filterStorage.GetStorage)
                        {
                            if (item is Groceries)
                            {
                                Groceries tmp = item as Groceries;
                                if (tmp.dateCreation >= outDateCreation_dateTimePicker.Value && tmp.dateCreation <= toDateCreation_dateTimePicker.Value)
                                {
                                    filterGoods.Add(item);
                                }
                            }
                        }
                    }
                }
                if (eDEnabled_checkBox.Checked)
                {
                    if (check)
                    {
                        for (int i = filterGoods.Count; i >= 0; i--)
                        {
                            foreach (Goods item in filterGoods)
                            {
                                if (item is Groceries)
                                {
                                    Groceries tmp = item as Groceries;
                                    if (tmp.dateExpiration < outDateExpiration_dateTimePicker.Value || tmp.dateExpiration > toDateExpiration_dateTimePicker.Value)
                                    {
                                        filterGoods.Remove(item);
                                        break;
                                    }
                                }
                                else
                                {
                                    filterGoods.Remove(item);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        check = true;
                        foreach (Goods item in filterStorage.GetStorage)
                        {
                            if (item is Groceries)
                            {
                                Groceries tmp = item as Groceries;
                                if (tmp.dateExpiration >= outDateExpiration_dateTimePicker.Value && tmp.dateExpiration <= toDateExpiration_dateTimePicker.Value)
                                {
                                    filterGoods.Add(item);
                                }
                            }
                        }
                    }
                }
            }
            else
            {
                if (outWidth_textBox.Text != String.Empty && toWidth_textBox.Text != String.Empty)
                {
                    if (check)
                    {
                        for (int i = filterGoods.Count; i >= 0; i--)
                        {
                            foreach (Goods item in filterGoods)
                            {
                                if (item is NonGroceries)
                                {
                                    NonGroceries tmp = item as NonGroceries;
                                    if (tmp.dimensions.width < int.Parse(outWidth_textBox.Text) || tmp.dimensions.width > int.Parse(toWidth_textBox.Text))
                                    {
                                        filterGoods.Remove(item);
                                        break;
                                    }
                                }
                                else
                                {
                                    filterGoods.Remove(item);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        check = true;
                        foreach (Goods item in filterStorage.GetStorage)
                        {
                            if (item is NonGroceries)
                            {
                                NonGroceries tmp = item as NonGroceries;
                                if (tmp.dimensions.width >= int.Parse(outWidth_textBox.Text) && tmp.dimensions.width <= int.Parse(toWidth_textBox.Text))
                                {
                                    filterGoods.Add(item);
                                }
                            }
                        }
                    }
                }
                if (outHeight_textBox.Text != String.Empty && toHeight_textBox.Text != String.Empty)
                {
                    if (check)
                    {
                        for (int i = filterGoods.Count; i >= 0; i--)
                        {
                            foreach (Goods item in filterGoods)
                            {
                                if (item is NonGroceries)
                                {
                                    NonGroceries tmp = item as NonGroceries;
                                    if (tmp.dimensions.height < int.Parse(outHeight_textBox.Text) || tmp.dimensions.height > int.Parse(toHeight_textBox.Text))
                                    {
                                        filterGoods.Remove(item);
                                        break;
                                    }
                                }
                                else
                                {
                                    filterGoods.Remove(item);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        check = true;
                        foreach (Goods item in filterStorage.GetStorage)
                        {
                            if (item is NonGroceries)
                            {
                                NonGroceries tmp = item as NonGroceries;
                                if (tmp.dimensions.height >= int.Parse(outHeight_textBox.Text) && tmp.dimensions.height <= int.Parse(toHeight_textBox.Text))
                                {
                                    filterGoods.Add(item);
                                }
                            }
                        }
                    }
                }
                if (outLength_textBox.Text != String.Empty && toLength_textBox.Text != String.Empty)
                {
                    if (check)
                    {
                        for (int i = filterGoods.Count; i >= 0; i--)
                        {
                            foreach (Goods item in filterGoods)
                            {
                                if (item is NonGroceries)
                                {
                                    NonGroceries tmp = item as NonGroceries;
                                    if (tmp.dimensions.length < int.Parse(outLength_textBox.Text) || tmp.dimensions.length > int.Parse(toLength_textBox.Text))
                                    {
                                        filterGoods.Remove(item);
                                        break;
                                    }
                                }
                                else
                                {
                                    filterGoods.Remove(item);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        check = true;
                        foreach (Goods item in filterStorage.GetStorage)
                        {
                            if (item is NonGroceries)
                            {
                                NonGroceries tmp = item as NonGroceries;
                                if (tmp.dimensions.length >= int.Parse(outLength_textBox.Text) && tmp.dimensions.length <= int.Parse(toLength_textBox.Text))
                                {
                                    filterGoods.Add(item);
                                }
                            }
                        }
                    }
                }
                if (group_comboBox.SelectedIndex != -1)
                {
                    DestinationGroup group;
                    switch (group_comboBox.SelectedIndex)
                    {
                    case 0:
                        group = DestinationGroup.Clothes;
                        break;

                    case 1:
                        group = DestinationGroup.Machinery;
                        break;

                    case 2:
                        group = DestinationGroup.Furniture;
                        break;

                    case 3:
                        group = DestinationGroup.Dishes;
                        break;

                    case 4:
                        group = DestinationGroup.Jewelry;
                        break;

                    default:
                        group = DestinationGroup.Nothing;
                        break;
                    }
                    if (check)
                    {
                        for (int i = filterGoods.Count; i >= 0; i--)
                        {
                            foreach (Goods item in filterGoods)
                            {
                                if (item is NonGroceries)
                                {
                                    NonGroceries tmp = item as NonGroceries;
                                    if (tmp.group != group)
                                    {
                                        filterGoods.Remove(item);
                                        break;
                                    }
                                }
                                else
                                {
                                    filterGoods.Remove(item);
                                    break;
                                }
                            }
                        }
                    }
                    else
                    {
                        check = true;
                        foreach (Goods item in filterStorage.GetStorage)
                        {
                            if (item is NonGroceries)
                            {
                                NonGroceries tmp = item as NonGroceries;
                                if (tmp.group == group)
                                {
                                    filterGoods.Add(item);
                                }
                            }
                        }
                    }
                }
            }
            if (check)
            {
                foreach (Goods item in filterGoods)
                {
                    ListViewItem listViewItem = new ListViewItem(item.name);
                    if (item is Groceries)
                    {
                        listViewItem.SubItems.Add("Grocerie");
                    }
                    else
                    {
                        listViewItem.SubItems.Add("NonGrocerie");
                    }
                    listViewItem.SubItems.Add(item.producer);
                    listViewItem.SubItems.Add(item.price.ToString());
                    listViewItem.SubItems.Add(item.quantity.ToString());
                    items_listView.Items.Add(listViewItem);
                }
            }
            else
            {
                foreach (Goods item in filterStorage.GetStorage)
                {
                    if (grocerie_radioButton.Checked)
                    {
                        if (item is Groceries)
                        {
                            ListViewItem listViewItem = new ListViewItem(item.name);
                            listViewItem.SubItems.Add("Grocerie");
                            listViewItem.SubItems.Add(item.price.ToString());
                            listViewItem.SubItems.Add(item.quantity.ToString());
                            items_listView.Items.Add(listViewItem);
                        }
                    }
                    else
                    {
                        if (item is NonGroceries)
                        {
                            ListViewItem listViewItem = new ListViewItem(item.name);
                            listViewItem.SubItems.Add("NonGrocerie");
                            listViewItem.SubItems.Add(item.price.ToString());
                            listViewItem.SubItems.Add(item.quantity.ToString());
                            items_listView.Items.Add(listViewItem);
                        }
                    }
                }
            }
        }
Esempio n. 8
0
        private void acceptButton_pictureBox_Click(object sender, EventArgs e)
        {
            try
            {
                if (name_textBox.Text == "")
                {
                    Exception exception = new Exception("name");
                    throw exception;
                }
                if (producer_textBox.Text == "")
                {
                    Exception exception = new Exception("producer");
                    throw exception;
                }
                if (Convert.ToUInt64(price_textBox.Text) == 0)
                {
                    Exception exception = new Exception("price");
                    throw exception;
                }
                if (Convert.ToUInt16(quantity_numericUpDown.Value) == 0)
                {
                    Exception exception = new Exception("quantity");
                    throw exception;
                }
                if (type_comboBox.SelectedItem.ToString() == "Grocerie")
                {
                    if (int.Parse(weightOrHeight_textBox.Text) == 0)
                    {
                        Exception exception = new Exception("weight");
                        throw exception;
                    }
                }
                if (type_comboBox.SelectedItem.ToString() == "Non-grocerie")
                {
                    if (weightOrHeight_textBox.Text == "Height" || Convert.ToUInt64(weightOrHeight_textBox.Text) == 0 || length_textBox.Text == "Length" || Convert.ToUInt64(length_textBox.Text) == 0 || width_textBox.Text == "Width" || Convert.ToUInt64(width_textBox.Text) == 0)
                    {
                        Exception exception = new Exception("dimensions");
                        throw exception;
                    }
                    if (destinationGroup_comboBox.SelectedIndex == -1)
                    {
                        Exception exception = new Exception("destination group");
                        throw exception;
                    }
                }
                string name     = name_textBox.Text;
                int    price    = Convert.ToInt32(price_textBox.Text);
                int    quantity = Convert.ToInt32(quantity_numericUpDown.Value);
                string producer = producer_textBox.Text;
                if (type_comboBox.SelectedItem.ToString() == "Grocerie")
                {
                    check      = true;
                    isGrocerie = 1;
                    int      weight         = Convert.ToInt32(weightOrHeight_textBox.Text);
                    DateTime dateCreation   = dateCreation_dateTimePicker.Value;
                    DateTime expirationDate = dateExpiration_dateTimePicker.Value;
                    TimeSpan usingTime;
                    TimeSpan remainingTime;
                    double   usingTimeI;
                    double   remainingTimeI;
                    usingTime      = expirationDate - dateCreation;
                    remainingTime  = expirationDate - DateTime.Now;
                    usingTimeI     = usingTime.TotalSeconds;
                    remainingTimeI = remainingTime.TotalSeconds;
                    bool isChanged;
                    if ((usingTimeI * 0.2) > remainingTimeI)
                    {
                        price    /= 2;
                        isChanged = true;
                    }
                    else
                    {
                        isChanged = false;
                    }
                    groceries           = new Groceries(name, producer, price, quantity, weight, dateCreation, expirationDate);
                    groceries.isChanged = isChanged;
                    this.Close();
                }
                else
                {
                    check      = true;
                    isGrocerie = 2;
                    Dimensions dimensions = new Dimensions();
                    dimensions.height = Convert.ToInt32(weightOrHeight_textBox.Text);
                    dimensions.length = Convert.ToInt32(length_textBox.Text);
                    dimensions.width  = Convert.ToInt32(width_textBox.Text);
                    DestinationGroup destinationGroup = new DestinationGroup();
                    switch (destinationGroup_comboBox.SelectedIndex)
                    {
                    case 0:
                        destinationGroup = DestinationGroup.Clothes;
                        break;

                    case 1:
                        destinationGroup = DestinationGroup.Machinery;
                        break;

                    case 2:
                        destinationGroup = DestinationGroup.Furniture;
                        break;

                    case 3:
                        destinationGroup = DestinationGroup.Dishes;
                        break;

                    case 4:
                        destinationGroup = DestinationGroup.Jewelry;
                        break;

                    default:
                        destinationGroup = DestinationGroup.Nothing;
                        break;
                    }
                    bool isChanged;
                    if ((dimensions.height + dimensions.length + dimensions.width) > 600)
                    {
                        price    *= 120;
                        price    /= 100;
                        isChanged = true;
                    }
                    else
                    {
                        isChanged = false;
                    }
                    nonGroceries           = new NonGroceries(name, producer, price, quantity, dimensions, destinationGroup);
                    nonGroceries.isChanged = isChanged;
                    this.Close();
                }
            }
            catch (Exception text)
            {
                string message = "You made wrong input in ";
                message += text.Message;
                MessageBox.Show(message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }