Beispiel #1
0
        private void btnBack_Click(object sender, EventArgs e)
        {
            frmAddProduct form = new frmAddProduct(componentsChosen);

            form.Show();

            this.Hide();
        }
Beispiel #2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            frmAddProduct form = new frmAddProduct();

            form.Show();

            this.Hide();
        }
Beispiel #3
0
        private void btnAddComponent_Click(object sender, EventArgs e)
        {
            decimal price;

            if (txtPrice.Text != null && txtPrice.Text != "")
            {
                price = decimal.Parse(txtPrice.Text);
            }
            else
            {
                price = 0;
            }

            List <ClassLibrary.Component> components = ClassLibrary.Component.GetComponents();

            bool descriptionExists = false;

            foreach (ClassLibrary.Component cmp in components)
            {
                if (cmp.Description == txtDescription.Text)
                {
                    descriptionExists = true;
                }
            }

            if (descriptionExists)
            {
                MessageBox.Show("The component description already exists!", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                bool   codeExists;
                string componentCode = txtComponentCode.Text;

                do
                {
                    codeExists = false;

                    foreach (ClassLibrary.Component cmp in components)
                    {
                        if (cmp.ComponentCode == componentCode)
                        {
                            codeExists = true;
                        }
                    }

                    if (!codeExists)
                    {
                        ClassLibrary.Component component = new ClassLibrary.Component(null, componentCode, txtDescription.Text, price, 0);

                        if (component.SaveComponentToDB())
                        {
                            frmAddProduct form = new frmAddProduct(componentsChosen);
                            form.Show();

                            this.Hide();
                        }
                    }
                    else
                    {
                        Regex r = new Regex("^[a-zA-Z0-9]*$");

                        do
                        {
                            if (componentCode.Length != 5)
                            {
                                componentCode = Interaction.InputBox("Enter a new component code:", "The component code must have a length of 5!", "AAAAA").ToUpper();
                            }
                            else if (!r.IsMatch(componentCode))
                            {
                                componentCode = Interaction.InputBox("Enter a new component code:", "Invalid component code!", "AAAAA").ToUpper();
                            }
                            else if (codeExists)
                            {
                                componentCode = Interaction.InputBox("Enter a new component code:", "The component code already exists!", "AAAAA").ToUpper();
                            }
                        } while (componentCode.Length != 5 || !r.IsMatch(componentCode));
                    }
                } while (codeExists);
            }
        }