Пример #1
0
        public static Boolean ValidateTextBox(Label lbl, TextBox tb, Boolean AllowEmpty, InputDataType dt)
        {
            String str = CLanguage.getValue("ERROR_TEXT_VALIDATE");
            String fmt = String.Format(str, lbl.Content);

            if (tb.IsEnabled)
            {
                if (AllowEmpty)
                {
                    return(true);
                }

                if (tb.Text.Trim().Equals(""))
                {
                    CMessageBox.Show(fmt, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                    tb.Focus();
                    return(false);
                }

                Regex regex = null;
                if (dt == InputDataType.InputTypeZeroPossitiveDecimal)
                {
                    regex = new Regex(@"^\d+(\.\d{1,2})?$");
                }
                else if (dt == InputDataType.InputTypeZeroPossitiveInt)
                {
                    regex = new Regex(@"^\d+$");
                }

                Boolean result = regex.IsMatch(tb.Text);
                if (!result)
                {
                    CMessageBox.Show(fmt, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                    tb.Focus();
                    return(false);
                }
            }

            return(true);
        }
Пример #2
0
        public static Boolean ValidatePasswordBox(Label lbl, PasswordBox tb, Boolean AllowEmpty)
        {
            String str = CLanguage.getValue("ERROR_TEXT_VALIDATE");
            String fmt = String.Format(str, lbl.Content);

            if (tb.IsEnabled)
            {
                if (AllowEmpty)
                {
                    return(true);
                }

                if (tb.Password.Trim().Equals(""))
                {
                    CMessageBox.Show(fmt, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                    tb.Focus();
                    return(false);
                }
            }

            return(true);
        }
Пример #3
0
        public static Boolean ValidateLookup(Label lbl, ULookupSearch2 ulk, Boolean AllowEmpty)
        {
            String str = CLanguage.getValue("ERROR_TEXT_VALIDATE");
            String fmt = String.Format(str, lbl.Content);

            if (ulk.IsEnabled)
            {
                if (AllowEmpty)
                {
                    return(true);
                }

                if (ulk.IsEmpty())
                {
                    CMessageBox.Show(fmt, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                    ulk.Focus();
                    return(false);
                }
            }

            return(true);
        }
Пример #4
0
        private static Boolean ValidateComboBox(String strMsg, Label lbl, ComboBox cb, Boolean AllowEmpty)
        {
            String lb = "";

            if (lbl != null)
            {
                lb = lbl.Content.ToString();
            }

            String str = CLanguage.getValue("ERROR_TEXT_VALIDATE");
            String fmt = "";

            if (!lb.Equals(""))
            {
                fmt = String.Format(str, lbl.Content);
            }
            else if (!strMsg.Equals(""))
            {
                fmt = String.Format(str, strMsg);
            }

            if (cb.IsEnabled)
            {
                if (AllowEmpty)
                {
                    return(true);
                }

                if (cb.Text.Trim().Equals(""))
                {
                    CMessageBox.Show(fmt, "ERROR", MessageBoxButton.OK, MessageBoxImage.Error);
                    cb.Focus();
                    return(false);
                }
            }

            return(true);
        }