Example #1
0
        /// <summary>
        /// Takes the user-inputed price and converts to a double if it is valid and positive
        /// </summary>
        /// <returns>true if price is valid and > 0</returns>
        private bool ReadAndValidatePrice(out double price)
        {
            string input = txtPrice.Text;

            if (InputUtility.GetPositiveDouble(input, out price))
            {
                return(true);
            }
            else
            {
                MessageBox.Show("Invalid price. Must be positive and consisting of at least one number, whole or decimal.", "Invalid price", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Validates that name is valid (not empty or only spaces)
        /// </summary>
        /// <returns>true if name is valid</returns>
        private bool ReadAndValidateName(out string name)
        {
            name = txtName.Text;

            if (!InputUtility.ValidateString(name))
            {
                MessageBox.Show("Invalid entry. Name cannot be empty," + Environment.NewLine + " and must have at least one character (cannot be a blankspace)", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                txtName.Focus();
                txtName.Text = " ";
                txtName.SelectAll();
                return(false);
            }
            else
            {
                return(true);
            }
        }