private Boolean EvaluaRangos(string ValorFuturo)
        {
            if (!ZMX_IsEnabled)
            {
                return(false);
            }

            Decimal valor = Convert.ToDecimal(ValorFuturo);

            Window win = Window.GetWindow(this);


            if (valor < ZMX_ValorMinimo)
            {
                UtileriasControles.MuestraToolTipSobreControl(win, txtValor, "Valor mínimo: " + ZMX_ValorMinimo, 1500, UtileriasControles.Posicion.Arriba);
                return(true);
            }
            else if (ZMX_ValorMaximo != 0 && valor > ZMX_ValorMaximo)
            {
                UtileriasControles.MuestraToolTipSobreControl(win, txtValor, "Valor máximo: " + ZMX_ValorMaximo, 1500, UtileriasControles.Posicion.Arriba);
                return(true);
            }

            return(false);
        }
Example #2
0
 private void TxtCodigo_PreviewTextInput(object sender, TextCompositionEventArgs e)
 {
     if (e.Text.Equals("&"))
     {
         ZMX_EsExpresionContable = true;
         txtDescripcion.Text     = "Expresión contable";
         if (ZMX_EsRequerido)
         {
             ZMX_MarcarRequerido = false;
         }
     }
     if (ZMX_EsExpresionContable && (((TextBox)sender).Text.Length + e.Text.Length) > 29)
     {
         UtileriasControles.MuestraToolTipSobreControl(Window.GetWindow((Control)sender), (Control)sender, "Longitud máxima: 29", UtileriasControles.Posicion.Derecha);
         e.Handled = true;
         return;
     }
 }
Example #3
0
 private void txt_KeyDown(object sender, KeyEventArgs e)
 {
     if (e.Key == Key.Enter)
     {
         if (ultimoTextBox.Text.Trim().Equals(""))
         {
             UtileriasControles.MuestraToolTipSobreControl(Window.GetWindow(this), ultimoTextBox, "Es necesario escribir un criterio para la busqueda.", UtileriasControles.Posicion.Derecha);
             return;
         }
         if ((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl)))
         {
             ultimoTextBox = (TextBox)sender;
             //aqui lanzar la busqueda
             if (ZMX_BuscarLocalidadesPorMunicipio != null)
             {
                 List <Object> lista = ZMX_BuscarLocalidadesPorMunicipio(this, ultimoTextBox.Text);
                 DibujarLocalidades(lista);
             }
         }
         else
         {
             ultimoTextBox = (TextBox)sender;
             //aqui lanzar la busqueda
             if (ZMX_BuscarLocalidades != null)
             {
                 List <Object> lista = ZMX_BuscarLocalidades(this, ultimoTextBox.Text);
                 DibujarLocalidades(lista);
             }
         }
     }
     else if (e.Key == Key.Escape)
     {
         LimpiarPanel();
         resultadosBusqueda.ZMX_Limpiar();
     }
 }
        private void TxtValor_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            valorAnterior = txtValor.Text;

            if (e.Text.Equals(""))
            {
                e.Handled = true;
                return;
            }
            //validando que no venga un simbolo negativo, si el valor minimo es 0
            if (e.Text.Equals("-") && ZMX_ValorMinimo == 0 && txtValor.SelectionStart == 0)
            {
                Window win = Window.GetWindow(this);
                UtileriasControles.MuestraToolTipSobreControl(win, txtValor, "Valor mínimo: " + ZMX_ValorMinimo, 1500, UtileriasControles.Posicion.Arriba);
                e.Handled = true;
                return;
            }
            //validando q no se tecleen caracteres especiales no permitidos
            if (!e.Text.Equals("-") && !char.IsDigit(e.Text, e.Text.Length - 1) && !e.Text.Equals("."))
            {
                e.Handled = true;
                return;
            }
            //validando q no venga un simbolo negativo despues de un numero
            if (e.Text.Equals("-") && txtValor.SelectionStart > 0)
            {
                e.Handled = true;
                return;
            }
            //validando que no venga un simbolo negativo antes q otro simbolo negativo
            if (e.Text.Equals("-") && txtValor.SelectionStart == 0 && txtValor.Text.StartsWith("-") && txtValor.SelectionLength == 0)
            {
                e.Handled = true;
                return;
            }


            if (txtValor.SelectionStart == 0 && txtValor.SelectionLength == txtValor.Text.Length)
            {
                txtValor.Text           = "" + e.Text;
                e.Handled               = true;
                txtValor.SelectionStart = 1;
                return;
            }
            if (txtValor.SelectionStart >= 0 && txtValor.SelectionLength > 0)
            {
                //replace de lo seleccionado si trae punto
                if (txtValor.Text.Substring(txtValor.SelectionStart, txtValor.SelectionLength).Contains("."))
                {
                    int    indicePunto = txtValor.Text.IndexOf(".");
                    String valorSel1   = txtValor.Text.Substring(0, txtValor.SelectionStart);
                    String valorSel2   = "";
                    try
                    {
                        valorSel2 = txtValor.Text.Substring(txtValor.SelectionStart + txtValor.SelectionLength, txtValor.Text.Length - (txtValor.SelectionStart + txtValor.SelectionLength));
                    }
                    catch { }
                    valorSel1 += e.Text + valorSel2;
                }
            }
            //replace de lo seleccionado si no trae punto
            if (txtValor.SelectionStart >= 0 && txtValor.SelectionLength > 0)
            {
                String valorSel1 = txtValor.Text.Substring(0, txtValor.SelectionStart);
                String valorSel2 = "";
                try
                {
                    valorSel2 = txtValor.Text.Substring(txtValor.SelectionStart + txtValor.SelectionLength, txtValor.Text.Length - (txtValor.SelectionStart + txtValor.SelectionLength));
                }
                catch { }
                valorSel1 += e.Text + valorSel2;
                //se evalua que al cambiar el texto seleccionado por el valor a introducir, conserve el formato.
                EvaluarNumero(e, valorSel1);
                e.Handled = EvaluarEstructuraNumero(valorSel1, e.Text);
                if (e.Handled)
                {
                    return;
                }

                int n = txtValor.SelectionStart;
                txtValor.Text            = valorSel1;
                txtValor.SelectionStart  = n + 1;
                txtValor.SelectionLength = 0;
                e.Handled = true;
                return;
            }

            if (!char.IsDigit(e.Text, e.Text.Length - 1) && !e.Text.Equals(".") && !e.Text.Equals("-"))
            {
                e.Handled = true;
            }

            if (e.Text.Equals(".") && txtValor.Text.Contains("."))
            {
                e.Handled = true;
                return;
            }

            if (e.Text.Equals(".") && ZMX_Decimales == 0)
            {
                e.Handled = true;
                return;
            }

            String valorTemp1 = txtValor.Text.Substring(0, txtValor.SelectionStart);

            if (e.Text.Equals("-") && valorTemp1.Contains("-"))
            {
                e.Handled = true;
                return;
            }



            String valorTemp2 = "";

            try
            {
                valorTemp2 = txtValor.Text.Substring(txtValor.SelectionStart, txtValor.Text.Length - txtValor.SelectionStart);
            }
            catch { }
            valorTemp1 += e.Text + valorTemp2;

            //Evaluando el caso "-."
            if (valorTemp1.StartsWith("-."))
            {
                int indice = txtValor.SelectionStart;

                valorTemp1              = valorTemp1.Replace("-.", "0");
                txtValor.Text           = txtValor.Text.Replace("-", "0.");
                e.Handled               = true;
                txtValor.SelectionStart = 2;
                return;
            }
            //validando si empieza con .
            if (valorTemp1.StartsWith("."))
            {
                txtValor.Text           = txtValor.Text.Replace(".", "0") + valorTemp1;
                e.Handled               = true;
                txtValor.SelectionStart = 3;
                return;
            }


            EvaluarNumero(e, valorTemp1);

            e.Handled = EvaluarEstructuraNumero(valorTemp1, e.Text);

            //Validamos que el numero que va a quedar este dentro del rango configurado y que haya pasado las validaciones de estructura
            if (!e.Handled)
            {
                e.Handled = EvaluaRangos(valorTemp1);
            }
        }