示例#1
0
 private void txtCantidad_KeyPress(object sender, KeyPressEventArgs e)
 {
     Validaciones.Numeros(e);
 }
示例#2
0
        private void txtProducto_KeyPress(object sender, KeyPressEventArgs e)
        {
            Validaciones.Numeros(e);
            if (e.KeyChar == (char)13)
            {
                long   Codigo;
                string Nombre, Descripcion, TipoUnidad;
                double PrecioUnitario, Cantidad, Importe;
                listView1.Items.Clear();

                if (txtProducto.Text.Length != 0)
                {
                    if (!Venta.Existe(Convert.ToInt64(txtProducto.Text)) == true)
                    {
                        MySqlConnection conexion = Conexion.MiConexion();
                        string          query    = "SELECT * FROM Productos WHERE Codigo ='" + this.txtProducto.Text + "' ";
                        MySqlCommand    comando  = new MySqlCommand(query, conexion);
                        MySqlDataReader leer     = comando.ExecuteReader();

                        if (leer.Read() == true)
                        {
                            Codigo         = long.Parse(leer["Codigo"].ToString());
                            Nombre         = leer["Nombre"].ToString();
                            Descripcion    = leer["Descripcion"].ToString();
                            TipoUnidad     = leer["TipoUnidad"].ToString();
                            PrecioUnitario = double.Parse(leer["Precio"].ToString());
                            Cantidad       = double.Parse(txtCantidad.Text);
                            Importe        = double.Parse(PrecioUnitario.ToString()) * double.Parse(Cantidad.ToString());

                            //Provisional

                            /*
                             * txtCodigo1.Text = Convert.ToString(Codigo);
                             * txtNombre1.Text = Nombre;
                             * txtDescripcion1.Text = Descripcion;
                             * txtTipoUnidad1.Text = TipoUnidad;
                             * txtPrecio1.Text = Convert.ToString(PrecioUnitario);
                             * txtCantidad1.Text = Convert.ToString(Cantidad);
                             * txtImporte1.Text = Convert.ToString(Importe);
                             */
                            ///////////////////////////////////////////////////////////////

                            //Guardar productos en tabla temporal
                            Pro_Venta Pro_Venta = new Pro_Venta();
                            Pro_Venta.Codigo         = Convert.ToInt64(Codigo);
                            Pro_Venta.Nombre         = Nombre;
                            Pro_Venta.Descripcion    = Descripcion;
                            Pro_Venta.TipoUnidad     = TipoUnidad;
                            Pro_Venta.PrecioUnitario = Convert.ToDouble(PrecioUnitario);
                            Pro_Venta.Cantidad       = Convert.ToDouble(Cantidad);
                            Pro_Venta.Importe        = Convert.ToDouble(Importe);
                            Venta.AgregarVenta_Proceso(Pro_Venta);
                            //////////////////////////////////////////////////////////////
                        }
                        else
                        {
                            MessageBox.Show("Producto no encontrado");
                        }
                    }
                    else
                    {
                        //MessageBox.Show("Error, datos repetidos");
                        if (txtCantidad.Text == "1")
                        {
                            MySqlConnection conexion = Conexion.MiConexion();
                            string          query    = "SELECT * FROM Venta_Proceso WHERE Codigo ='" + this.txtProducto.Text + "' ";
                            MySqlCommand    comando  = new MySqlCommand(query, conexion);
                            MySqlDataReader leer     = comando.ExecuteReader();
                            if (leer.Read() == true)
                            {
                                Codigo         = long.Parse(leer["Codigo"].ToString());
                                Nombre         = leer["Nombre"].ToString();
                                Descripcion    = leer["Descripcion"].ToString();
                                TipoUnidad     = leer["TipoUnidad"].ToString();
                                PrecioUnitario = double.Parse(leer["PrecioUnitario"].ToString());
                                double Cant     = double.Parse(leer["Cantidad"].ToString());
                                double quantity = Cant = Cant + 1;
                                Importe = double.Parse(PrecioUnitario.ToString()) * double.Parse(quantity.ToString());
                                ///////////////////////////////////////////////////////////////////////////
                                //Guardar productos en tabla temporal
                                Pro_Venta Pro_Venta = new Pro_Venta();
                                Pro_Venta.Codigo         = Convert.ToInt64(Codigo);
                                Pro_Venta.Nombre         = Nombre;
                                Pro_Venta.Descripcion    = Descripcion;
                                Pro_Venta.TipoUnidad     = TipoUnidad;
                                Pro_Venta.PrecioUnitario = Convert.ToDouble(PrecioUnitario);
                                Pro_Venta.Cantidad       = Convert.ToDouble(quantity);
                                Pro_Venta.Importe        = Convert.ToDouble(Importe);
                                Venta.Modificar_Venta(Pro_Venta);
                            }
                        }
                        else
                        {
                            //MessageBox.Show("txtCantidad es mayor que 1");
                            MySqlConnection conexion = Conexion.MiConexion();
                            string          query    = "SELECT * FROM Venta_Proceso WHERE Codigo ='" + this.txtProducto.Text + "' ";
                            MySqlCommand    comando  = new MySqlCommand(query, conexion);
                            MySqlDataReader leer     = comando.ExecuteReader();
                            if (leer.Read() == true)
                            {
                                Codigo         = long.Parse(leer["Codigo"].ToString());
                                Nombre         = leer["Nombre"].ToString();
                                Descripcion    = leer["Descripcion"].ToString();
                                TipoUnidad     = leer["TipoUnidad"].ToString();
                                PrecioUnitario = double.Parse(leer["PrecioUnitario"].ToString());
                                double Cant     = double.Parse(leer["Cantidad"].ToString());
                                double quantity = Cant + double.Parse(txtCantidad.Text);
                                Importe = double.Parse(PrecioUnitario.ToString()) * double.Parse(quantity.ToString());
                                ///////////////////////////////////////////////////////////////////////////
                                //Guardar productos en tabla temporal
                                Pro_Venta Pro_Venta = new Pro_Venta();
                                Pro_Venta.Codigo         = Convert.ToInt64(Codigo);
                                Pro_Venta.Nombre         = Nombre;
                                Pro_Venta.Descripcion    = Descripcion;
                                Pro_Venta.TipoUnidad     = TipoUnidad;
                                Pro_Venta.PrecioUnitario = Convert.ToDouble(PrecioUnitario);
                                Pro_Venta.Cantidad       = Convert.ToDouble(quantity);
                                Pro_Venta.Importe        = Convert.ToDouble(Importe);
                                Venta.Modificar_Venta(Pro_Venta);
                            }
                        }
                    }
                }
                //Cargar productos de tabla de venta temporal
                MySqlConnection  conexion2 = Conexion.MiConexion();
                MySqlDataAdapter Consulta  = new MySqlDataAdapter("Select * from Venta_Proceso", conexion2);
                DataTable        dt        = new DataTable();
                Consulta.Fill(dt);
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    ListViewItem List;
                    List = listView1.Items.Add(dt.Rows[i][0].ToString());
                    List.SubItems.Add(dt.Rows[i][1].ToString());
                    List.SubItems.Add(dt.Rows[i][2].ToString());
                    List.SubItems.Add(dt.Rows[i][3].ToString());
                    List.SubItems.Add(dt.Rows[i][4].ToString());
                    List.SubItems.Add(dt.Rows[i][5].ToString());
                    List.SubItems.Add(dt.Rows[i][6].ToString());
                }

                double Total = 0;
                foreach (ListViewItem I in listView1.Items)
                {
                    Total += double.Parse(listView1.Items[I.Index].SubItems[6].Text);
                }
                txtTotal.Text = Total.ToString();
                txtProducto.Clear();
                txtNombre.Text   = "";
                txtCantidad.Text = "1";
                txtProducto.Focus();
            }
        }