Exemplo n.º 1
0
        //Event fired for button press in Supplies
        private void Btn_Supplies_Save_Click(object sender, EventArgs e)
        {
            Drink_Service sv = new Drink_Service();

            if (!Txt_Supplies_Price.Visible)
            {
                sv.UpdateDrink(Convert.ToInt32(Txt_Supplies_Id.Text), Txt_Supplies_NewName.Text, Convert.ToInt32(Txt_Supplies_NewStock.Text));
            }
            else
            {
                sv.AddDrink(Txt_Supplies_NewName.Text, Convert.ToInt32(Txt_Supplies_NewStock.Text), Convert.ToInt32(Txt_Supplies_Sold.Text), Convert.ToInt32(Txt_Supplies_Price.Text));
            }
            showPanel("DrinkSup");
        }
        public override void OnClickOK(object sender, EventArgs e)
        {
            Drink_Service drinkService = new Drink_Service();

            //Store the values of all of the inputs
            string name = CP_Popop_AddToDrinksMenu_txtName.Text;
            bool   alcoholic;

            bool priceParsed = double.TryParse(CP_Popop_AddToDrinksMenu_txtPrice.Text, out double price);
            bool stockParsed = int.TryParse(CP_Popup_AddToDrinksMenu_txtStock.Text, out int stock);

            if (!(priceParsed && stockParsed))
            {
                Close();
            }

            if (CP_Popup_AddToDrinksMenu_cboxAlcoholic.Checked)
            {
                alcoholic = true;
            }
            else
            {
                alcoholic = false;
            }

            //Add a new drink to the system
            try
            {
                drinkService.AddDrink(new Drink(name, alcoholic, price, stock));
            }
            catch (Exception ex)
            {
                ErrorHandler.Instance.HandleError("Drank kon niet toegevoegd worden!", "Drank niet toegevoegd", ex);

                //Tell the ControlPanel form that the action didn't succeed
                DialogResult = DialogResult.Cancel;
            }
        }
Exemplo n.º 3
0
        private void applyBtn_Click(object sender, EventArgs e)
        {
            int drinkType = 4;   //1 = alcoholic ; 0 = non-alcoholic

            //if it's true, there is an error, if it's false, there is no error
            bool error = false;


            //set drinkType based on the selected index
            if (typeCmb.SelectedIndex == 0)
            {
                drinkType = 0;
            }
            else if (typeCmb.SelectedIndex == 1)
            {
                drinkType = 1;
            }
            else
            {
                MessageBox.Show("You need to select a drink type!", "Select drink type", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                error = true;
            }
            if (!Regex.IsMatch(priceTxt.Text, @"[\d]{1,4}([.,][\d]{1,2})?"))
            {
                MessageBox.Show("Wrong price format", "Price error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                error = true;
            }
            //check if the name TextBox is empty or it has less than 4 characters
            if (nameTxt.Text == "" || nameTxt.Text.Length <= 3)
            {
                MessageBox.Show("Your drink name must NOT be empty and it has to have a minimum length of 3 characters!",
                                "Warning",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Warning);

                error = true;
            }
            if (!Regex.IsMatch(stockTxt.Text, "[0-9]"))
            {
                MessageBox.Show("The stock has to be a number!", "Stock error", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                error = true;
            }
            if (!error)
            {
                if (decimal.Parse(priceTxt.Text) < 0 || decimal.Parse(stockTxt.Text) < 0)
                {
                    MessageBox.Show("The stock and the price can't be less than 0!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                    error = true;
                }
            }

            if (!error) //if there are no errors, add a new drink
            {
                for (int i = 0; i < priceTxt.Text.Length; i++)
                {
                    //if there are commas in the price, replace them with a period
                    if (priceTxt.Text[i].ToString() == ",")
                    {
                        priceTxt.Text = priceTxt.Text.Replace(",", ".");
                    }
                }
                Drink_Service drinkService = new Drink_Service();
                drinkService.AddDrink(nameTxt.Text, int.Parse((stockTxt.Text)), decimal.Parse(priceTxt.Text), drinkType);
                MessageBox.Show("Drink added succesfully!", "Drink Added", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                this.Close();
            }
        }