public bool validateSpecificItemAttributes(out object[] elements) { bool valid = true; uiSpecificItemAttributesErrorProvider.Clear(); elements = new object[2]; int nutritionQuantity = -1; Nutrition.nutritionType?nutritionType = null; if (string.IsNullOrWhiteSpace(uiNutritionQuantityUpDown.Text) || !(int.TryParse(uiNutritionQuantityUpDown.Text, out nutritionQuantity)) || nutritionQuantity <= 0) { uiSpecificItemAttributesErrorProvider.SetError(uiNutritionQuantityUpDown, "Please enter valid nutrition quantity"); uiSpecificItemAttributesErrorProvider.SetIconPadding(uiNutritionQuantityUpDown, 10); valid = false; } if (uiNutritionTypeComboBox.SelectedIndex < 0) { uiSpecificItemAttributesErrorProvider.SetError(uiNutritionTypeComboBox, "Please select nutrition type"); uiSpecificItemAttributesErrorProvider.SetIconPadding(uiNutritionTypeComboBox, 10); valid = false; } else { nutritionType = (Nutrition.nutritionType)uiNutritionTypeComboBox.SelectedItem; } elements[0] = nutritionQuantity; elements[1] = nutritionType; return(valid); }
protected override void addItem() { if (validateSpecificItemAttributes(out object[] elements) && base.validateGeneralItemAttributes()) { this.nutritionQuantity = (int)elements[0]; this.nutritionType = (Nutrition.nutritionType)elements[1]; this.DialogResult = DialogResult.OK; this.Close(); } }