⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 maskededitvalidator.cs

📁 AJAX 应用 实现页面的无刷新
💻 CS
📖 第 1 页 / 共 3 页
字号:
                    Culture = System.Globalization.CultureInfo.CurrentCulture.Name;
                }
                string CultureAMPMP = "";
                if (!string.IsNullOrEmpty(ControlCulture.DateTimeFormat.AMDesignator) && !string.IsNullOrEmpty(ControlCulture.DateTimeFormat.PMDesignator))
                {
                    CultureAMPMP = ControlCulture.DateTimeFormat.AMDesignator + ";" + ControlCulture.DateTimeFormat.PMDesignator;
                }
                switch (MaskExt.MaskType)
                {
                    case MaskedEditType.Number:
                        try
                        {
                            decimal numval = System.Decimal.Parse(Target.Text, ControlCulture);
                        }
                        catch
                        {
                            ok = false;
                        }
                        break;
                    case MaskedEditType.DateTime:
                    case MaskedEditType.Date:
                    case MaskedEditType.Time:
                        int tamtext = Target.Text.Length;
                        // gmorgan (25/06/2007) - Added check for AcceptAMPM in MaskedEditExtender to fix bug
                        // with validation in 24hr mode.
                        if (MaskExt.AcceptAMPM &&
                            !string.IsNullOrEmpty(CultureAMPMP) &&
                            (MaskExt.MaskType == MaskedEditType.Time || MaskExt.MaskType == MaskedEditType.DateTime))
                        {

                            char[] charSeparators = new char[] { ';' };
                            string[] ArrAMPM = CultureAMPMP.Split(charSeparators);
                            if (ArrAMPM[0].Length != 0)
                            {
                                tamtext -= (ArrAMPM[0].Length + 1);
                            }
                        }
                        if (MaskedEditCommon.GetValidMask(MaskExt.Mask).Length != tamtext)
                        {
                            ok = false;
                        }
                        if (ok)
                        {
                            try
                            {
                                DateTime dtval = System.DateTime.Parse(Target.Text, ControlCulture);
                            }
                            catch
                            {
                                ok = false;
                            }
                        }
                        break;
                }
                if (!ok)
                {
                    base.ErrorMessage = this.InvalidValueMessage;
                    if (string.IsNullOrEmpty(this.InvalidValueBlurredMessage))
                    {
                        base.Text = base.ErrorMessage;
                    }
                    else
                    {
                        base.Text = this.InvalidValueBlurredMessage;
                    }
                    cssError = MaskExt.OnInvalidCssClass;
                }
                if (ok && (!string.IsNullOrEmpty(this.MaximumValue) || !string.IsNullOrEmpty(this.MinimumValue)))
                {
                    switch (MaskExt.MaskType)
                    {
                        case MaskedEditType.None:
                            {
                                System.Int32 lenvalue;
                                if (!string.IsNullOrEmpty(this.MaximumValue))
                                {
                                    try
                                    {
                                        lenvalue = System.Int32.Parse(this.MaximumValue, ControlCulture);
                                        ok = (lenvalue >= Target.Text.Length);
                                    }
                                    catch
                                    {
                                        base.ErrorMessage = this.InvalidValueMessage;
                                        if (string.IsNullOrEmpty(this.InvalidValueBlurredMessage))
                                        {
                                            base.Text = base.ErrorMessage;
                                        }
                                        else
                                        {
                                            base.Text = this.InvalidValueBlurredMessage;
                                        }
                                        ok = false;
                                    }
                                    if (!ok)
                                    {
                                        base.ErrorMessage = this.MaximumValueMessage;
                                        if (string.IsNullOrEmpty(this.MaximumValueBlurredMessage))
                                        {
                                            base.Text = base.ErrorMessage;
                                        }
                                        else
                                        {
                                            base.Text = this.MaximumValueBlurredMessage;
                                        }
                                        cssError = MaskExt.OnInvalidCssClass;
                                    }
                                }
                                if (ok && !string.IsNullOrEmpty(this.MinimumValue))
                                {
                                    try
                                    {
                                        lenvalue = System.Int32.Parse(this.MinimumValue, ControlCulture);
                                        ok = (lenvalue <= Target.Text.Length);
                                    }
                                    catch
                                    {
                                        base.ErrorMessage = this.InvalidValueMessage;
                                        if (string.IsNullOrEmpty(this.InvalidValueBlurredMessage))
                                        {
                                            base.Text = base.ErrorMessage;
                                        }
                                        else
                                        {
                                            base.Text = this.InvalidValueBlurredMessage;
                                        }
                                        ok = false;
                                    }
                                    if (!ok)
                                    {
                                        base.ErrorMessage = this.MinimumValueMessage;
                                        if (string.IsNullOrEmpty(this.MinimumValueBlurredText))
                                        {
                                            base.Text = base.ErrorMessage;
                                        }
                                        else
                                        {
                                            base.Text = this.MinimumValueBlurredText;
                                        }
                                        cssError = MaskExt.OnInvalidCssClass;
                                    }
                                }
                                break;
                            }
                        case MaskedEditType.Number:
                            {
                                decimal numval = System.Decimal.Parse(Target.Text, ControlCulture);
                                decimal Compval;
                                if (!string.IsNullOrEmpty(this.MaximumValue))
                                {
                                    try
                                    {
                                        Compval = System.Decimal.Parse(this.MaximumValue, ControlCulture);
                                        ok = (Compval >= numval);
                                    }
                                    catch
                                    {
                                        ok = false;
                                    }
                                    if (!ok)
                                    {
                                        base.ErrorMessage = this.MaximumValueMessage;
                                        if (string.IsNullOrEmpty(this.MaximumValueBlurredMessage))
                                        {
                                            base.Text = base.ErrorMessage;
                                        }
                                        else
                                        {
                                            base.Text = this.MaximumValueBlurredMessage;
                                        }
                                        cssError = MaskExt.OnInvalidCssClass;
                                    }
                                }
                                if (ok && !string.IsNullOrEmpty(this.MinimumValue))
                                {
                                    try
                                    {
                                        Compval = System.Decimal.Parse(this.MinimumValue, ControlCulture);
                                        ok = (Compval <= numval);
                                    }
                                    catch
                                    {
                                        ok = false;
                                    }
                                    if (!ok)
                                    {
                                        base.ErrorMessage = this.MinimumValueMessage;
                                        if (string.IsNullOrEmpty(this.MinimumValueBlurredText))
                                        {
                                            base.Text = base.ErrorMessage;
                                        }
                                        else
                                        {
                                            base.Text = this.MinimumValueBlurredText;
                                        }
                                        cssError = MaskExt.OnInvalidCssClass;
                                    }
                                }
                                break;
                            }
                        case MaskedEditType.DateTime:
                        case MaskedEditType.Date:
                        case MaskedEditType.Time:
                            {
                                DateTime dtval = System.DateTime.Parse(Target.Text, ControlCulture);
                                DateTime dtCompval;
                                if (!string.IsNullOrEmpty(this.MaximumValue))
                                {
                                    try
                                    {
                                        dtCompval = System.DateTime.Parse(this.MaximumValue, ControlCulture);
                                        ok = (dtCompval >= dtval);
                                    }
                                    catch
                                    {
                                        ok = false;
                                    }
                                    if (!ok)
                                    {
                                        base.ErrorMessage = this.MaximumValueMessage;
                                        if (string.IsNullOrEmpty(this.MaximumValueBlurredMessage))
                                        {
                                            base.Text = base.ErrorMessage;
                                        }
                                        else
                                        {
                                            base.Text = this.MaximumValueBlurredMessage;
                                        }
                                        cssError = MaskExt.OnInvalidCssClass;
                                    }
                                }
                                if (ok && !string.IsNullOrEmpty(this.MinimumValue))
                                {
                                    try
                                    {
                                        dtCompval = System.DateTime.Parse(this.MinimumValue, ControlCulture);
                                        ok = (dtCompval <= dtval);
                                    }
                                    catch
                                    {
                                        ok = false;
                                    }
                                    if (!ok)
                                    {
                                        base.ErrorMessage = this.MinimumValueMessage;
                                        if (string.IsNullOrEmpty(this.MinimumValueBlurredText))
                                        {
                                            base.Text = base.ErrorMessage;
                                        }
                                        else
                                        {
                                            base.Text = this.MinimumValueBlurredText;
                                        }
                                        cssError = MaskExt.OnInvalidCssClass;
                                    }
                                }
                                break;
                            }
                    }
                }
            }
            if (ok && MaskedEditServerValidator != null)
            {
                ServerValidateEventArgs serverValidateEventArgs = new ServerValidateEventArgs(Target.Text, ok);
                MaskedEditServerValidator(Target, serverValidateEventArgs);
                ok = serverValidateEventArgs.IsValid;
                if (!ok)
                {
                    cssError = MaskExt.OnInvalidCssClass;
                    base.ErrorMessage = this.InvalidValueMessage;
                    if (string.IsNullOrEmpty(this.InvalidValueBlurredMessage))
                    {
                        base.Text = base.ErrorMessage;
                    }
                    else
                    {
                        base.Text = this.InvalidValueBlurredMessage;
                    }
                }
            }
            if (!ok)
            {
                // set CSS at server for browser with not implement client validator script (FF, others)   
                //MaskedEditSetCssClass(value,CSS)
                string Script = "MaskedEditSetCssClass(" + this.ClientID + ",'" + cssError + "');";
                ScriptManager.RegisterStartupScript(this, typeof(MaskedEditValidator), "MaskedEditServerValidator_" + this.ID, Script, true);
            }
            return ok;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -