private void txtNombre_KeyPress(object sender, KeyPressEventArgs e) { e.KeyChar = char.ToUpper(e.KeyChar); if (e.KeyChar == (char)13) { MySqlConnection conexion = Conexion.MiConexion(); string query = "Select * from Productos where concat_ws(' ',Nombre,Descripcion) LIKE '%" + this.txtNombre.Text + "%';"; MySqlCommand comando = new MySqlCommand(query, conexion); MySqlDataReader leer = comando.ExecuteReader(); if (leer.Read() == true) { Codigo_Nombre = long.Parse(leer["Codigo"].ToString()); Nombre_Nombre = leer["Nombre"].ToString(); Descripcion_Nombre = leer["Descripcion"].ToString(); TipoUnidad_Nombre = leer["TipoUnidad"].ToString(); PrecioUnitario_Nombre = double.Parse(leer["Precio"].ToString()); Cantidad_Nombre = double.Parse(txtCantidad.Text); Importe_Nombre = double.Parse(PrecioUnitario.ToString()) * double.Parse(Cantidad.ToString()); } } }
private void btnAgregar_Carrito_Click(object sender, EventArgs e) { Pro_Productos Pro_Productos = new Pro_Productos(); //Validar si los campos codigo de producto y nombre de producto estan vacios if (txtProducto.Text.Length == 0 && txtNombre.Text.Length == 0) { MessageBox.Show("Error en campo codigo o nombre estan vacios", "Campo Obligatorio, verifique", MessageBoxButtons.OK, MessageBoxIcon.Error); txtProducto.Focus(); return; } //Validar si el campo codigo de producto es diferencte de vacio y si nombre de producto esta vacio else if (txtProducto.Text.Length != 0 && txtNombre.Text.Length == 0) { 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(); } else if (txtProducto.Text.Length == 0 && txtNombre.Text.Length != 0) { long Codigo; string Nombre, Descripcion, TipoUnidad; double PrecioUnitario, Importe; listView1.Items.Clear(); MySqlConnection conexion3 = Conexion.MiConexion(); string query2 = "Select * from Productos where concat_ws(' ',Nombre,Descripcion) LIKE '%" + this.txtNombre.Text + "%';"; MySqlCommand comando2 = new MySqlCommand(query2, conexion3); MySqlDataReader leer2 = comando2.ExecuteReader(); if (leer2.Read() == true) { Codigo_Nombre = long.Parse(leer2["Codigo"].ToString()); } if (!Venta.Existe(Convert.ToInt64(Codigo_Nombre)) == false) { //MessageBox.Show("Ya existe"); if (txtCantidad.Text == "1") { MySqlConnection conexion = Conexion.MiConexion(); string query = "SELECT * FROM Venta_Proceso WHERE Codigo ='" + Codigo_Nombre + "' "; 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 ='" + Codigo_Nombre + "' "; 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); } } } else { //MessageBox.Show("No existe, bla bla"); long Codigo2; string Nombre2, Descripcion2, TipoUnidad2; double PrecioUnitario2, Cantidad2, Importe2; listView1.Items.Clear(); MySqlConnection conexion = Conexion.MiConexion(); string query = "Select * from Productos where concat_ws(' ',Nombre,Descripcion) LIKE '%" + this.txtNombre.Text + "%';"; MySqlCommand comando = new MySqlCommand(query, conexion); MySqlDataReader leer = comando.ExecuteReader(); if (leer.Read() == true) { Codigo2 = long.Parse(leer["Codigo"].ToString()); Nombre2 = leer["Nombre"].ToString(); Descripcion2 = leer["Descripcion"].ToString(); TipoUnidad2 = leer["TipoUnidad"].ToString(); PrecioUnitario2 = double.Parse(leer["Precio"].ToString()); Cantidad2 = double.Parse(txtCantidad.Text); Importe2 = double.Parse(PrecioUnitario2.ToString()) * double.Parse(Cantidad2.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(Codigo2); Pro_Venta.Nombre = Nombre2; Pro_Venta.Descripcion = Descripcion2; Pro_Venta.TipoUnidad = TipoUnidad2; Pro_Venta.PrecioUnitario = Convert.ToDouble(PrecioUnitario2); Pro_Venta.Cantidad = Convert.ToDouble(Cantidad2); Pro_Venta.Importe = Convert.ToDouble(Importe2); Venta.AgregarVenta_Proceso(Pro_Venta); ////////////////////////////////////////////////////////////// } else { MessageBox.Show("Producto no encontrado"); } } //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(); } else { MessageBox.Show("Error en campo codigo y nombre no deben estar llenos en el mismo formulario", "Campo Obligatorio, verifique", MessageBoxButtons.OK, MessageBoxIcon.Error); txtProducto.Focus(); return; } }
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(); } }
public Libro SqlLibro2Libro() { string precioUnitario = PrecioUnitario.ToString(); return(new Libro(LibroID, EditorialID, NombreAutor, precioUnitario, Descricion, Genero)); }