private void btnBack_Click(object sender, EventArgs e) { frmManageProducts form = new frmManageProducts(); form.Show(); this.Hide(); }
private void btnAddProduct_Click(object sender, EventArgs e) { List <Product> products = Product.GetProducts(); bool productDescriptionExists = false; foreach (Product product in products) { if (product.Description == txtDescription.Text) { productDescriptionExists = true; } } if (productDescriptionExists) { MessageBox.Show("The product description already exists!", "ERROR!", MessageBoxButtons.OK, MessageBoxIcon.Error); } else { bool codeExists; string productCode = txtProductCode.Text; do { codeExists = false; foreach (Product product in products) { if (product.ProductCode == productCode) { codeExists = true; } } if (codeExists) { Regex r = new Regex("^[a-zA-Z0-9]*$"); do { if (productCode.Length != 5) { productCode = Interaction.InputBox("Enter a new product code:", "The product code must have a length of 5!", "AAAAA").ToUpper(); } else if (!r.IsMatch(productCode)) { productCode = Interaction.InputBox("Enter a new product code:", "Invalid product code!", "AAAAA").ToUpper(); } else if (codeExists) { productCode = Interaction.InputBox("Enter a new product code:", "The product code already exists!", "AAAAA").ToUpper(); } } while (productCode.Length != 5 || !r.IsMatch(productCode)); } } while (codeExists); txtProductCode.Text = productCode; string packageCode = Package.GetPackages(cbxPackageName.Text)[0].PackageCode; Product productToAdd = new Product(packageCode, txtProductCode.Text, txtDescription.Text, cbxManufacturer.Text); if (componentsChosen.Count > 0) { if (_ValidationMethods.isValid) { List <ClassLibrary.Component> components = new List <ClassLibrary.Component>(); foreach (ClassLibrary.Component component in componentsChosen) { components.Add(component); } productToAdd.Components = components; productToAdd.SaveProductToDB(); frmManageProducts form = new frmManageProducts(); form.Show(); this.Hide(); } } else { MessageBox.Show("No components were chosen!", "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }