Exemplo n.º 1
0
        static public Boolean ValidaSingle(object sender, EventArgs e)
        {
            float x;

            if (!String.IsNullOrEmpty(((TextBox)sender).Text) && !Single.TryParse(((TextBox)sender).Text, out x))
            {
                Mensajes.msgValorInvalidoNumero();
                ((TextBox)sender).Text = null;
                ((Control)sender).Focus();
                return(false);
            }
            return(true);
        }
Exemplo n.º 2
0
        public static Boolean ValidaSingle(object sender, EventArgs e, int intLength, int fracLength)
        {
            float x = 0;

            if (!String.IsNullOrEmpty(((TextBox)sender).Text) && !Single.TryParse(((TextBox)sender).Text, out x))
            {
                Mensajes.msgValorInvalidoNumero();
                ((TextBox)sender).Text = null;
                ((Control)sender).Focus();
                return(false);
            }

            decimal mWhole    = Math.Truncate(Convert.ToDecimal(x));
            decimal mFraction = Convert.ToDecimal(x) - mWhole;

            if (((TextBox)sender).Text.Split(',').Length == 2)
            {
                if (((TextBox)sender).Text.Split(',')[1] == string.Empty)
                {
                    Mensajes.msgValorInvalidoNumero();
                    ((TextBox)sender).Text = null;
                    ((Control)sender).Focus();
                    return(false);
                }
            }

            if (mFraction != 0)
            {
                if (mFraction.ToString().Split(',')[1].Length > fracLength)
                {
                    Mensajes.msgValorInvalidoCantidadDecimal();
                    ((TextBox)sender).Text = null;
                    ((Control)sender).Focus();
                    return(false);
                }
            }

            if (mWhole.ToString(CultureInfo.InvariantCulture).Length > intLength)
            {
                Mensajes.msgValorInvalidoCantidadEnteros();
                ((TextBox)sender).Text = null;
                ((Control)sender).Focus();
                return(false);
            }

            return(true);
        }