Exemplo n.º 1
0
        private void btnLoadFile_Click(object sender, EventArgs e)
        {
            FileHandler txtload = new FileHandler();

            SequenceID.setProd_id(1); // Initialize the Sequence Id
            product_list.ReturnList().Clear();
            product_list = txtload.readFile();

            // Clean the List Box
            listBoxProducts.Items.Clear();

            foreach (Product emp in product_list.ReturnList())
            {
                listBoxProducts.Items.Add(product_list.ShowListInBox(emp));
            }
        }
Exemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            Product prod     = null;
            int     temp_seq = 0;

            if (!product_list.isUnique(txtSN.Text))
            {
                MessageBox.Show("There is another product with this SN...",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }

            if (cmbTypeProd.Text == "Book")
            {
                if (!DataValidator.verifyData(txtBPages.Text, new Regex(DataValidator.patternNumber)))
                {
                    MessageBox.Show("Pages has to be a numeric value", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                prod = new Book(Convert.ToInt16(txtBPages.Text),
                                (EnumBookGenre)cmbBGenre.SelectedItem);
                temp_seq = prod.Item; //Store last sequence
            }
            else if (cmbTypeProd.Text == "Software")
            {
                if (!DataValidator.verifyData(txtSCapacity.Text, new Regex(DataValidator.patternNumber)))
                {
                    MessageBox.Show("Software Capacity has to be a numeric value", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                prod     = new Software(txtSCapacity.Text, (EnumSoftType)cmbSoftType.SelectedItem);
                temp_seq = prod.Item; //Store last sequence
            }
            else
            {
                MessageBox.Show("Must be select a Type of Product...", "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            try
            {
                prod.SerialNumber = txtSN.Text;
                prod.Type         = (EnumProdType)cmbTypeProd.SelectedItem;
                prod.Titname      = txtTitle.Text;
                prod.Author       = txtAuthor.Text;

                // Validating Price
                if (!DataValidator.verifyData(txtPrice.Text, new Regex(DataValidator.patternMoney)))
                {
                    MessageBox.Show("Price has to be a numeric value", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                prod.Price = Convert.ToDouble(txtPrice.Text);

                //Validating Date
                if (!DataValidator.verifyData(txtHDay.Text, new Regex(DataValidator.patternDay)))
                {
                    MessageBox.Show("Wrong day...Must be between 1 and 31", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SequenceID.setProd_id(temp_seq); // Decrease the sequence
                    return;
                }
                if (!DataValidator.verifyData(txtHMonth.Text, new Regex(DataValidator.patternMonth)))
                {
                    MessageBox.Show("Wrong month...Must be between 1 and 12", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SequenceID.setProd_id(temp_seq); // Decrease the sequence
                    return;
                }
                if (!DataValidator.verifyData(txtHYear.Text, new Regex(DataValidator.patternYear)))
                {
                    MessageBox.Show("Wrong year...Must be between 1900 and 2099", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    SequenceID.setProd_id(temp_seq); // Decrease the sequence
                    return;
                }
                prod.Ed_pubDate = new Date(txtHDay.Text, txtHMonth.Text, txtHYear.Text);

                // Validating Stock
                if (!DataValidator.verifyData(txtStock.Text, new Regex(DataValidator.patternNumber)))
                {
                    MessageBox.Show("Stock has to be a numeric value", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
                prod.Stock = Convert.ToInt16(txtStock.Text);

                // Adding to list
                product_list.add(prod);

                this.listBoxProducts.Items.Add(product_list.ShowListInBox(prod));
                btnReset.PerformClick();

                MessageBox.Show("Product Added", "Confirmation",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                save_flag = true;
            }
            catch
            {
                MessageBox.Show("Missing or incorrects values to enter...Check and Try again",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Exemplo n.º 3
0
        private void btnModify_Click(object sender, EventArgs e)
        {
            Product prod     = null;
            int     temp_seq = 0;

            try
            {
                if (cmbTypeProd.Text == "Book")
                {
                    if (!DataValidator.verifyData(txtBPages.Text, new Regex(DataValidator.patternNumber)))
                    {
                        MessageBox.Show("Pages must be a numeric value", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    prod = new Book(Convert.ToInt16(txtBPages.Text),
                                    (EnumBookGenre)cmbBGenre.SelectedItem);
                    temp_seq = prod.Item; //Store last sequence
                }
                else if (cmbTypeProd.Text == "Software")
                {
                    if (!DataValidator.verifyData(txtSCapacity.Text, new Regex(DataValidator.patternNumber)))
                    {
                        MessageBox.Show("Software Capacity has to be a numeric value", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    prod     = new Software(txtSCapacity.Text, (EnumSoftType)cmbSoftType.SelectedItem);
                    temp_seq = prod.Item; //Store last sequence
                }
                else
                {
                    MessageBox.Show("Must be selected an Employee's Category...", "Error",
                                    MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                try
                {
                    prod.SerialNumber = txtSN.Text;
                    prod.Type         = (EnumProdType)cmbTypeProd.SelectedItem;
                    prod.Titname      = txtTitle.Text;
                    prod.Author       = txtAuthor.Text;

                    // Validating Price
                    if (!DataValidator.verifyData(txtPrice.Text, new Regex(DataValidator.patternMoney)))
                    {
                        MessageBox.Show("Price has to be a numeric value", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    prod.Price = Convert.ToDouble(txtPrice.Text);

                    //Validating Date
                    if (!DataValidator.verifyData(txtHDay.Text, new Regex(DataValidator.patternDay)))
                    {
                        MessageBox.Show("Wrong day...Must be between 1 and 31", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SequenceID.setProd_id(temp_seq); // Decrease the sequence
                        return;
                    }
                    if (!DataValidator.verifyData(txtHMonth.Text, new Regex(DataValidator.patternMonth)))
                    {
                        MessageBox.Show("Wrong month...Must be between 1 and 12", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SequenceID.setProd_id(temp_seq); // Decrease the sequence
                        return;
                    }
                    if (!DataValidator.verifyData(txtHYear.Text, new Regex(DataValidator.patternYear)))
                    {
                        MessageBox.Show("Wrong year...Must be between 1900 and 2099", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        SequenceID.setProd_id(temp_seq); // Decrease the sequence
                        return;
                    }
                    prod.Ed_pubDate = new Date(txtHDay.Text, txtHMonth.Text, txtHYear.Text);

                    // Validating Stock
                    if (!DataValidator.verifyData(txtStock.Text, new Regex(DataValidator.patternNumber)))
                    {
                        MessageBox.Show("Stock has to be a numeric value", "Error",
                                        MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                    prod.Stock = Convert.ToInt16(txtStock.Text);

                    prod.SerialNumber = tempsn; //Assign last displayed SN

                    prod.Item = temp_id;

                    if (txtSN.Text != prod.SerialNumber)
                    {
                        MessageBox.Show("Can't to modify the SN in the Modify option.  It should use Add button",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }

                    if (update_index > -1)
                    {
                        // Update list Box and list of Products
                        product_list.modify(prod, prod.SerialNumber);
                        listBoxProducts.Items.Clear();
                        foreach (Product temp in product_list.ReturnList())
                        {
                            this.listBoxProducts.Items.Add(product_list.ShowListInBox(temp));
                        }

                        btnReset.PerformClick();

                        update_index = -1;

                        save_flag = true;

                        MessageBox.Show("Product Mofified", "Confirmation",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Information);
                    }
                    else
                    {
                        MessageBox.Show("It must to select an item and display it.  Use Display Option",
                                        "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
                catch
                {
                    MessageBox.Show("Missing or incorrects values to enter...Check and Try again",
                                    "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            catch
            {
                MessageBox.Show("Missing or incorrects values to enter...Check and Try again",
                                "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }