Beispiel #1
0
        /// <summary>
        ///     Validate the user input. Save button is disabled in case of invalid input
        /// </summary>
        /// <returns>True if valid, false if invalid</returns>
        private bool ValidateInput()
        {
            bool valid = true;

            if (string.IsNullOrEmpty(txtName.Text))
            {
                valid = false;
                errorProvider.SetError(txtName,
                                       "Name cannot be empty");
            }
            else if (Tasker.Tasks.ContainsKey(txtName.Text) && (_taskToEdit == null || _taskToEdit.Name != txtName.Text))
            {
                valid = false;
                errorProvider.SetError(txtName,
                                       "Name is already in use for another task");
            }
            else
            {
                errorProvider.SetError(txtName, "");
            }

            if (_selectedTrigger != null)
            {
                errorProvider.SetError(cbTrigger, "");
                if (_selectedTrigger.ValidateInput(txtTriggerParam.Text))

                {
                    errorProvider.SetError(txtTriggerParam, "");
                }
                else
                {
                    valid = false;
                    errorProvider.SetError(txtTriggerParam,
                                           "Invalid parameter!" + Environment.NewLine + _selectedTrigger.ParameterDescription);
                }
            }
            else
            {
                errorProvider.SetError(cbTrigger,
                                       "No trigger selected!");
                valid = false;
            }

            // there's always at least the button
            if (gbAction.Controls.Count < 2)
            {
                errorProvider.SetError(btnNewAction,
                                       "No action selected!");
                valid = false;
            }
            else
            {
                errorProvider.SetError(btnNewAction, "");
            }

            btnSave.Enabled = valid;
            return(valid);
        }