Exemple #1
0
 private void Tipo_pago_KeyPress(object sender, KeyPressEventArgs e)
 {
     //Validacion de la tecla Enter en el tipo de pago
     if ((int)e.KeyChar == (int)Keys.Enter)
     {
         if (Tipo_pago.Text == "1")
         {
             Nombre_pago.Text = "Efectivo";
             Monto.Enabled    = true;
             Monto.Text       = Saldo.Text;
             //Funcion para aplicar tabulador al presionar enter
             SendKeys.Send("{TAB}");
             Monto.SelectAll();
         }
         else
         {
             MessageBox.Show("No existe forma de pago.", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Error);
             //Seleccionar texto al recibir mensaje de error
             Tipo_pago.SelectionStart  = 0;
             Tipo_pago.SelectionLength = Tipo_pago.Text.Length;
             //metodo para limpiar textbox
             limpiar();
         }
     }
     //Validacion para solo aceptar numeros
     if (Char.IsDigit(e.KeyChar))
     {
         e.Handled = false;
     }
     else if (Char.IsControl(e.KeyChar))
     {
         e.Handled = false;
     }
     else
     {
         e.Handled = true;
     }
 }
Exemple #2
0
        private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
        {
            //Funcion Enter
            if ((int)e.KeyChar == (int)Keys.Enter)
            {
                //Obtener valores de los textbox
                if (Monto.Text == "")
                {
                    MessageBox.Show("Debes ingresar dinero.", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    //Seleccionar si marca error la comparacion
                    Monto.SelectAll();
                }
                else
                {
                    Monto_R = Double.Parse(Monto.Text.Replace(".", ","));
                    Total_C = Double.Parse(Saldo.Text.Replace(".", ","));

                    //Comparar
                    if (Monto_R < Total_C)
                    {
                        MessageBox.Show("Esta recibiendo un pago menor.", "Atención", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        //Seleccionar si marca error la comparacion
                        Monto.SelectAll();
                    }
                    else
                    {
                        double dinero;
                        double dinero_tota;
                        cmd = new SqlCommand("select * from dinero ", new Conexion().con);
                        SqlDataReader consu = cmd.ExecuteReader();
                        if (consu.Read() == true)
                        {
                            dinero_total = consu["dinero"].ToString();
                            dinero_total = dinero_total.Replace(".", ",");
                            dinero       = Convert.ToDouble(dinero_total);
                            dinero_tota  = Convert.ToDouble(Saldo.Text.Replace(".", ","));
                            dinero       = dinero + dinero_tota;
                            dinero_total = Convert.ToString(dinero);
                            dinero_total = dinero_total.Replace(",", ".");
                        }
                        consu.Close();

                        cmd = new SqlCommand("execute actualizardinero '" + dinero_total + "'", new Conexion().con);
                        cmd.ExecuteNonQuery();


                        Form2 id = Application.OpenForms.OfType <Form2>().SingleOrDefault();
                        id.cobrar();

                        total_cambio = Monto_R - Total_C;
                        cambio       = Convert.ToString(total_cambio);
                        cambio       = cambio.Replace(",", ".");
                        MessageBox.Show("Su cambio total es de : " + cambio, "Atención", MessageBoxButtons.OK);
                        imprimir();
                        id.limpiarventa();
                        this.Close();
                    }
                }
            }

            //Validacion para puros numeros
            if (e.KeyChar == 8)
            {
                e.Handled = false;
                return;
            }


            bool IsDec  = false;
            int  nroDec = 0;

            for (int i = 0; i < Monto.Text.Length; i++)
            {
                if (Monto.Text[i] == '.')
                {
                    IsDec = true;
                }

                if (IsDec && nroDec++ >= 2)
                {
                    e.Handled = true;
                    return;
                }
            }

            if (e.KeyChar >= 48 && e.KeyChar <= 57)
            {
                e.Handled = false;
            }
            else if (e.KeyChar == 46)
            {
                e.Handled = (IsDec) ? true : false;
            }
            else
            {
                e.Handled = true;
            }
        }