Ejemplo n.º 1
0
        public virtual bool ValidateBeforeSave()
        {
            CallValidatingEvent(this);

            string ErrorText = ErrorProvider.GetAllErrorText();

            if (!String.IsNullOrEmpty(ErrorText))
            {
                Alit.WinformControls.MessageBox.Show(this, "Can not save. Please fix following errors:\r\n\r\n" + ErrorText,
                                                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                if (ErrorProvider.ErrorList != null && ErrorProvider.ErrorList.Count > 0)
                {
                    Control FirstErrorControl = ErrorProvider.ErrorList.ElementAt(0).Key;
                    if (FirstErrorControl != null && FirstErrorControl.CanFocus)
                    {
                        FirstErrorControl.Focus();
                    }
                    else
                    {
                        panelContent.Focus();
                        SendKeys.SendWait("{Tab}");
                    }
                }
                return(false);
            }
            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Re-execute validation of all controls on form and show validation error message of all controls in one message, if any.
        /// </summary>
        /// <returns>false = has error, true = no error</returns>
        public bool ProcessValidationFormControls()
        {
            frmCRUDTemplate.CallValidatingEvent(this);

            string ErrorText = ErrorProvider.GetAllErrorText();

            if (!String.IsNullOrEmpty(ErrorText))
            {
                Alit.WinformControls.MessageBox.Show(this, "Can not save. Please fix following errors:\r\n\r\n" + ErrorText,
                                                     MessageBoxButtons.OK, MessageBoxIcon.Exclamation);

                if (ErrorProvider.ErrorList != null && ErrorProvider.ErrorList.Count > 0)
                {
                    SetFocusOnFirstControl();
                }
                return(false);
            }
            return(true);
        }