private void txtIDPROD_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { if (!ProductoValida.Valid(txtIDPROD.Text, Program.conexion)) { MessageBox.Show("no existe"); } else if (txtNombreCLiente.Text == "" || clienteValida.Valid(txtIdCliente.Text, Program.conexion) == null) { Program.retornarError("El cliente no existe, o debe ingresar uno correcto", "cliente invalida"); } else if (txtNombreEmpleado.Text == "" || empleadoValida.Valid(txtIdEmpleado.Text, Program.conexion) == null) { Program.retornarError("El empleado no existe, o debe ingresar uno correcto", "empleado invalido"); } else { try { IDbConnection conexion = new SqlConnection (Program.conexion); conexion.Open(); IDbCommand dbcmd = conexion.CreateCommand(); NpgsqlDataAdapter cons = new NpgsqlDataAdapter( "SELECT producto as IDproducto, producto.nombre, producto.detalle, cantidad, pedidodetalle.precio " + " FROM pedidodetalle INNER JOIN producto on producto.idproducto=pedidodetalle.producto " + " where folio=" + txtfolio.Text + "", Program.conexion) ; dbcmd.CommandText = "SELECT detalle, nombre, preciopub, existencia.cantidad FROM PRODUCTO" + " INNER JOIN existencia on producto.idproducto=existencia.producto AND existencia.sucursal='" + txtSucursal.Text + "'" + "WHERE idproducto ='" + txtIDPROD.Text + "';"; IDataReader reader = dbcmd.ExecuteReader(); if (reader.Read()) { txtDetalles.Text = reader.GetString(reader.GetOrdinal("detalle")); txtProducto.Text = reader.GetString(reader.GetOrdinal("nombre")); txtPrecio.Text = Convert.ToString(reader.GetDecimal(reader.GetOrdinal("preciopub"))); txtExistencia.Text = Convert.ToString(reader.GetInt32(reader.GetOrdinal("cantidad"))); conexion.Close(); } else { MessageBox.Show("El producto existe, pero no se han echo pedidos"); } } catch (Exception msg) { MessageBox.Show(msg.Message); } } } }
private void txtIDPROD_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { if (!ProductoValida.Valid(txtIDPROD.Text, Program.conexion)) { MessageBox.Show("no existe"); } else if (txtSucursal.Text == "" || SucursalValida.Valid(txtSucursal.Text, Program.conexion) == null) { Program.retornarError("La sucursal no existe o debe ingresar una correcta", "Sucursal invalida"); } else { try { IDataReader reader = builder.returnReader("PRODUCTO", "WHERE idproducto = '" + txtIDPROD.Text + "'; ", " * "); if (reader.Read()) { if (reader.GetString(reader.GetOrdinal("proveedor")) != txtProveedor.Text) { MessageBox.Show("Este producto no pertenece a el proveedor" + txtProveedor.Text); } else { txtDetalles.Text = reader.GetString(reader.GetOrdinal("detalle")); txtProducto.Text = reader.GetString(reader.GetOrdinal("nombre")); txtPrecio.Text = Convert.ToString(reader.GetDecimal(reader.GetOrdinal("preciolista"))); } } /* else * { * MessageBox.Show("El producto se a añadido, pero aún no hay pedidos del mismo, pida el producto a su proveedor para generar existencias"); * }*/ } catch (Exception msg) { MessageBox.Show(msg.Message); } } } }
private void btnAgregarprod_Click(object sender, EventArgs e) { if (!ProductoValida.Valid(txtIDPROD.Text, Program.conexion) || txtCantidad.Text == "" || txtPrecio.Text == "") { Program.retornarError("el producto no existe, o no introdujiste una cantidad valida", "ERROR"); } else if (MessageBox.Show("DESEAS AGREGAR EL ARTÍCULO A LA VENTA", "", MessageBoxButtons.YesNo) == DialogResult.Yes) { BuscarEnGrid(); if (band) { dtaGrid.Rows[cuenta].Cells[0].Value = txtIDPROD.Text; dtaGrid.Rows[cuenta].Cells[1].Value = txtProducto.Text; dtaGrid.Rows[cuenta].Cells[2].Value = txtDetalles.Text; dtaGrid.Rows[cuenta].Cells[3].Value = Convert.ToInt32(txtCantidad.Text) + Convert.ToInt32(dtaGrid.Rows[cuenta].Cells[3].Value); dtaGrid.Rows[cuenta].Cells[4].Value = txtPrecio.Text + "$"; dtaGrid.Rows[cuenta].Cells[5].Value = Convert.ToString(Convert.ToInt32(txtCantidad.Text) * Convert.ToDouble(txtPrecio.Text)) + "$"; } else { datos.Rows.Add(); dtaGrid.Rows[i].Cells[0].Value = txtIDPROD.Text; dtaGrid.Rows[i].Cells[1].Value = txtProducto.Text; dtaGrid.Rows[i].Cells[2].Value = txtDetalles.Text; dtaGrid.Rows[i].Cells[3].Value = txtCantidad.Text; dtaGrid.Rows[i].Cells[4].Value = txtPrecio.Text + "$"; dtaGrid.Rows[i].Cells[5].Value = Convert.ToString(Convert.ToInt32(txtCantidad.Text) * Convert.ToDouble(txtPrecio.Text)) + "$"; i++; dtaGrid.Rows[dtaGrid.RowCount - 1].ReadOnly = true; } calculaSubtotal(); } txtCantidad.Clear(); txtPrecio.Clear(); txtDetalles.Clear(); txtProducto.Clear(); }