private void textBox2_KeyPress(object sender, KeyPressEventArgs e) { if (txtBucarProducto.Text.Equals("")) { if (e.KeyChar == 13) { btnBuscar.PerformClick(); e.Handled = true; } } else { if (e.KeyChar == 13) { ClsDProductos prod = new ClsDProductos(); var busqueda = prod.BuscarProducto(Convert.ToInt32(txtBucarProducto.Text)); if (busqueda.Count < 1) { MessageBox.Show("El codigo no existe"); txtBucarProducto.Text = ""; } foreach (var iteracion in busqueda) { txtId.Text = iteracion.idProducto.ToString(); txtNombreProducto.Text = iteracion.nombreProducto; txtPrecio.Text = iteracion.precioProducto.ToString(); txtCantidad.Text = "1"; txtCantidad.Focus(); txtBucarProducto.Text = ""; } } } }
private void txtCantidad_KeyPress(object sender, KeyPressEventArgs e) { if (e.KeyChar == 13) { e.Handled = true; btnAgregar.PerformClick(); txtBucarProducto.Focus(); } else { e.Handled = true; ClsDProductos cls = new ClsDProductos(); var busqueda = cls.BuscarProducto(Convert.ToInt32(txtBucarProducto.Text)); foreach (var iteracion in busqueda) { txtId.Text = iteracion.idProducto.ToString(); txtNombreProducto.Text = iteracion.nombreProducto; txtPrecio.Text = iteracion.precioProducto.ToString(); } } }