private void btnDelete_Click(object sender, EventArgs e) { FormError confirmDialog = new FormError(); confirmDialog.changeLabel.Text = "Delete this Promotional Code?\n" + tblPromotionDataGridView.CurrentRow.Cells[0].Value + "." + tblPromotionDataGridView.CurrentRow.Cells[1].Value; confirmDialog.changeTitle = "Confirm Delete"; confirmDialog.changeButtonTwo.Text = "Cancel"; confirmDialog.ShowDialog(); if (FormError.getClickResult_FormError()) { int remove = (int)tblPromotionDataGridView.CurrentRow.Cells[0].Value; tblPromotion code = dbe.tblPromotions.First(p => p.ID == remove); dbe.tblPromotions.Remove(code); dbe.SaveChanges(); FormError sucessful = new FormError(); sucessful.changeTitle = "Confirmation."; sucessful.changeLabel.Text = "Deleted sucessfully!"; sucessful.changeButtonTwo.Hide(); sucessful.changeButtonTwo.Hide(); sucessful.ShowDialog(); //refresh data: display(); if (tblPromotionDataGridView.Rows.Count == 0) { cmbDiscount.Text = ""; } } txtBoxSearch.Text = ""; txtBoxDiscount.Text = ""; }
private void btnAdd_Click(object sender, EventArgs e) { if (txtBoxPromoCode.Text != "" && txtBoxDiscount.Text != "" && txtBoxPromoCode.Text.Length <= 10 && txtBoxPromoCode.Text.Length >= 5) { bool foundPromoCode = dbe.tblPromotions.Any(p => p.PromoCode == txtBoxPromoCode.Text); int discount = int.Parse(txtBoxDiscount.Text); bool matchDiscount = dbe.tblPromotions.Any(p => p.Discount == discount); if (!foundPromoCode || (foundPromoCode && matchDiscount)) { tblPromotion newPromoCode = new tblPromotion(); newPromoCode.PromoCode = txtBoxPromoCode.Text; newPromoCode.Discount = int.Parse(txtBoxDiscount.Text); dbe.tblPromotions.Add(newPromoCode); dbe.SaveChanges(); FormError successMessage = new FormError(); successMessage.changeButtonTwo.Hide(); successMessage.changeTitle = "Sucessful"; successMessage.changeLabel.Text = "Added sucessfully!"; successMessage.ShowDialog(); //refresh data display(); } else { FormError successMessage = new FormError(); successMessage.changeButtonTwo.Hide(); successMessage.changeTitle = "Error"; successMessage.changeLabel.Text = "The same codes have to \nhave the same discount percentage. \nTry again!"; successMessage.ShowDialog(); } } else { if (txtBoxPromoCode.Text.Length < 5 || txtBoxPromoCode.Text.Length > 10) { FormError successMessage = new FormError(); successMessage.changeButtonTwo.Hide(); successMessage.changeTitle = "Error"; successMessage.changeLabel.Text = "Invalid Promotional Code.\nCode need to be 5-10 characters.\nTry again!"; successMessage.ShowDialog(); } else { FormError successMessage = new FormError(); successMessage.changeButtonTwo.Hide(); successMessage.changeTitle = "Error"; successMessage.changeLabel.Text = "Missing Information.\nTry again!"; successMessage.ShowDialog(); } } //reset: txtBoxPromoCode.Clear(); txtBoxDiscount.Clear(); }