Esempio n. 1
0
        public static bool ValidateForm(this XtraForm frm)
        {
            dXErrorProvider.ClearErrors();
            var ctrls = frm.Controls.Cast <Control>().OrderBy(x => x.TabIndex).ToList();

            foreach (Control c in ctrls)
            {
                foreach (var ctrl in GetControls(c))
                {
                    if (ctrl is BaseEdit control)
                    {
                        if (!string.IsNullOrEmpty(control.Tag?.ToString()))
                        {
                            if (control.EditValue == null)
                            {
                                dXErrorProvider.SetError(control, control.Tag?.ToString());
                                dXErrorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleRight);
                                control.Focus();
                                return(false);
                            }
                        }
                    }
                }
            }

            return(true);
        }
Esempio n. 2
0
 /// <summary>
 ///  设定控件的警告信息
 /// </summary>
 /// <param name="ErrorInfo">异常信息对象提供者</param>
 /// <param name="ctl">控件对象</param>
 /// <param name="messageId">出错信息,可以用ID,可以用字符串</param>
 public static void ShowErrorInfo(DXErrorProvider ErrorInfo,  Control ctl, string messageId)
 {
   
     ErrorInfo.SetError (ctl,messageId);
     ErrorInfo.SetIconAlignment(ctl, ErrorIconAlignment.MiddleRight);
    
     //设定窗体控件的焦点
     Common.SetContorlFocus(ctl);
 }
 public static void Event_ErrorProvider(DXErrorProvider dxErrorProvider, Control x, bool isCheck, string errorText, bool CheckTrung = false, string errorTrung = "")
 {
     if (!isCheck || string.IsNullOrEmpty(x.Text) || CheckTrung)
     {
         x.Focus();
         dxErrorProvider.SetIconAlignment(x, ErrorIconAlignment.BottomRight);
         if (CheckTrung)
         {
             dxErrorProvider.SetError(x, errorTrung);
         }
         else
         {
             dxErrorProvider.SetError(x, errorText);
         }
     }
     else
     {
         dxErrorProvider.SetError(x, null);
     }
 }
Esempio n. 4
0
        public static bool ValidateFieldsNotEmpty(Control controlContenedor, DXErrorProvider errorProvider)
        {
            bool estado = true;
            int  nError = 0;

            foreach (Control control in controlContenedor.Controls)
            {
                var textEdit = control as TextEdit;
                if (textEdit != null && textEdit.Tag != null)
                {
                    if (textEdit.EditorTypeName == "TextEdit" && textEdit.Name.Substring(0, 1) == "i")
                    {
                        if (string.IsNullOrEmpty(textEdit.Text.Trim()))
                        {
                            errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
                            errorProvider.SetError(control, textEdit.Tag.ToString());
                            nError = nError + 1;
                        }
                        else
                        {
                            errorProvider.SetError(control, string.Empty);
                        }
                    }

                    if (textEdit.EditorTypeName == "TextEdit" && textEdit.Name.Substring(0, 1) == "n")
                    {
                        if ((decimal)textEdit.EditValue == 0.00m)
                        {
                            errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
                            errorProvider.SetError(control, textEdit.Tag.ToString());
                            nError = nError + 1;
                        }
                        else
                        {
                            errorProvider.SetError(control, string.Empty);
                        }
                    }

                    if (textEdit.EditorTypeName == "TextEdit" && textEdit.Name.Substring(0, 1) == "e")
                    {
                        if ((int)textEdit.EditValue == 0)
                        {
                            errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
                            errorProvider.SetError(control, textEdit.Tag.ToString());
                            nError = nError + 1;
                        }
                        else
                        {
                            errorProvider.SetError(control, string.Empty);
                        }
                    }
                }

                var lookUpEdit = control as LookUpEdit;
                if (lookUpEdit != null)
                {
                    if (lookUpEdit.EditorTypeName == "LookUpEdit")
                    {
                        if (lookUpEdit.Tag != null)
                        {
                            if (lookUpEdit.EditValue == null)
                            {
                                errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
                                errorProvider.SetError(control, lookUpEdit.Tag.ToString());
                                nError = nError + 1;
                            }
                            else
                            {
                                errorProvider.SetError(control, string.Empty);
                            }
                        }
                    }
                }

                var comboBoxEdit = control as ComboBoxEdit;
                if (comboBoxEdit != null)
                {
                    if (comboBoxEdit.EditorTypeName == "ComboBoxEdit")
                    {
                        if (comboBoxEdit.Tag != null)
                        {
                            if (comboBoxEdit.Text.Length == 0)
                            {
                                errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
                                errorProvider.SetError(control, comboBoxEdit.Tag.ToString());
                                nError = nError + 1;
                            }
                            else
                            {
                                errorProvider.SetError(control, string.Empty);
                            }
                        }
                    }
                }

                var memoEdit = control as MemoEdit;
                if (memoEdit != null)
                {
                    if (memoEdit.EditorTypeName == "MemoEdit")
                    {
                        if (memoEdit.Tag != null)
                        {
                            if (memoEdit.EditValue == null)
                            {
                                errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
                                errorProvider.SetError(control, memoEdit.Tag.ToString());
                                nError = nError + 1;
                            }
                            else
                            {
                                errorProvider.SetError(control, string.Empty);
                            }
                        }
                    }
                }

                var dateEdit = control as DateEdit;
                if (dateEdit != null)
                {
                    if (dateEdit.EditorTypeName == "DateEdit")
                    {
                        if (dateEdit.Tag != null)
                        {
                            if (dateEdit.EditValue == null)
                            {
                                errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
                                errorProvider.SetError(control, dateEdit.Tag.ToString());
                                nError = nError + 1;
                            }
                            else
                            {
                                errorProvider.SetError(control, string.Empty);
                            }
                        }
                    }
                }

                var searchLookUpEdit = control as SearchLookUpEdit;
                if (searchLookUpEdit != null)
                {
                    if (searchLookUpEdit.EditorTypeName == "SearchLookUpEdit")
                    {
                        if (searchLookUpEdit.Tag != null)
                        {
                            if (searchLookUpEdit.EditValue == null || Convert.ToInt32(searchLookUpEdit.EditValue) == 0)
                            {
                                errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
                                errorProvider.SetError(control, searchLookUpEdit.Tag.ToString());
                                nError = nError + 1;
                            }
                            else
                            {
                                errorProvider.SetError(control, string.Empty);
                            }
                        }
                    }
                }

                var buttonEdit = control as ButtonEdit;
                if (buttonEdit != null)
                {
                    if (buttonEdit.EditorTypeName == "ButtonEdit")
                    {
                        if (buttonEdit.Tag != null)
                        {
                            //if (buttonEdit.EditValue == null || string.IsNullOrEmpty((string)buttonEdit.EditValue))
                            if (buttonEdit.Text.Trim().Length == 0)
                            {
                                errorProvider.SetIconAlignment(control, ErrorIconAlignment.MiddleLeft);
                                errorProvider.SetError(control, buttonEdit.Tag.ToString());
                                nError = nError + 1;
                            }
                            else
                            {
                                errorProvider.SetError(control, string.Empty);
                            }
                        }
                    }
                }
            }

            if (nError > 0)
            {
                estado = false;
            }

            return(estado);
        }