Exemplo n.º 1
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     try
     {
         if (UsefulAlgorithms.ValidateEmptyString(txtVitaminName.Text))
         {
             if (controller.AddVitamin(new Vitamin()
             {
                 Name = txtVitaminName.Text
             }))
             {
                 PopulateGrid();
                 MessageBox.Show(Resources.VitaminAddedWithSuccess, TitleFactory.GetTitle(this.GetType()), MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
         else
         {
             throw new Exception(Resources.ErrorNeedToFillVitaminName);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, TitleFactory.GetTitle(this.GetType()), MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Exemplo n.º 2
0
 private bool ValidateControl()
 {
     if (UsefulAlgorithms.ValidateEmptyString(txtFoodName.Text) &&
         ValidateNumbersAndEmptyString(txtAmount.Text) &&
         ValidateNumbersAndEmptyString(txtCalories.Text) &&
         ValidateNumbersAndEmptyString(txtCarbs.Text) &&
         ValidateNumbersAndEmptyString(txtFat.Text) &&
         ValidateNumbersAndEmptyString(txtProtein.Text))
     {
         return(true);
     }
     else
     {
         throw new Exception(Resources.ErrorNecessaryToFillAllFieldsCorrectly);
     }
 }
Exemplo n.º 3
0
 private bool ValidateNumbersAndEmptyString(string value)
 {
     return(UsefulAlgorithms.ValidateEmptyString(value) && UsefulAlgorithms.ValidateNumber(value));
 }