protected void btnAdd_Click(object sender, EventArgs e)
 {
     if (!lblCode.Text.Equals("Promotion code will appear here!"))
     {
         PromotionDTO dto = new PromotionDTO
         {
             Code   = lblCode.Text,
             Name   = txtName.Text.Trim(),
             Active = true
         };
         try
         {
             if (dao.AddPromotion(dto))
             {
                 SetMessageTextAndColor("Successfully Added", Color.Green);
             }
             else
             {
                 SetMessageTextAndColor("Failed to add", Color.Red);
             }
         }
         catch
         {
             SetMessageTextAndColor("Code has already been added please generate a different one.", Color.Red);
         }
     }
 }
示例#2
0
        private void confirmButton_Click(object sender, EventArgs e)
        {
            int discAmt = 0;

            try
            {
                discAmt = Int32.Parse(discountAmountTextBox.Text);

                if (mode == ADD_PROMOTION)
                {
                    Promotion promotion = new Promotion();
                    promotion.Make           = (Make)makeDropDownBox.SelectedItem;
                    promotion.discountAmount = discAmt;

                    if (promotion.Make != null && promotion.discountAmount != 0 && promotion.discountAmount > 0)
                    {
                        PromotionDAO.AddPromotion(promotion);
                        promotionsForm.ReloadPromotions();
                        this.Close();
                    }
                    else
                    {
                        //TODO: should show a different error message depending on what value is null
                        MessageBox.Show("Invalid input!", "Invalid Input", MessageBoxButtons.OK);
                    }
                }
                else if (mode == EDIT_PROMOTION)
                {
                    currentPromotion.Make           = (Make)makeDropDownBox.SelectedItem;
                    currentPromotion.discountAmount = discAmt;

                    if (currentPromotion.Make != null && currentPromotion.discountAmount != 0 && currentPromotion.discountAmount > 0)
                    {
                        PromotionDAO.EditPromotion(currentPromotion);
                        promotionsForm.ReloadPromotions();
                        this.Close();
                    }
                    else
                    {
                        //TODO: should show a different error message depending on what value is null
                        MessageBox.Show("Invalid input!", "Invalid Input", MessageBoxButtons.OK);
                    }
                }
            }
            catch
            {
                MessageBox.Show("Invalid input!", "Invalid Input", MessageBoxButtons.OK);
            }
        }