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); } }
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); } }
private bool ValidateNumbersAndEmptyString(string value) { return(UsefulAlgorithms.ValidateEmptyString(value) && UsefulAlgorithms.ValidateNumber(value)); }