private void llenarComboBox() { cmbProductos.ValueMember = "id"; cmbProductos.DisplayMember = "nombreMarcaPeso"; ProductoLogica logica = new ProductoLogica(); foreach (Producto item in logica.SeleccionarTodos()) { cmbProductos.Items.Add(item); } AutoCompleteStringCollection coleccion = new AutoCompleteStringCollection(); foreach (Producto item in logica.SeleccionarTodos()) { coleccion.Add(item.nombreMarcaPeso); } cmbProductos.AutoCompleteCustomSource = coleccion; cmbProductos.AutoCompleteMode = AutoCompleteMode.SuggestAppend; cmbProductos.AutoCompleteSource = AutoCompleteSource.CustomSource; }
private void btnBorrar_Click(object sender, EventArgs e) { try { if (dgvProductos.SelectedRows.Count > 0) { ProductoLogica logica = new ProductoLogica(); bool estado = MessageBox.Show("Esta seguro que desea borrar este producto?.", "Esta seguro?", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1) == DialogResult.Yes; if (estado) { int id = Convert.ToInt32(dgvProductos.CurrentRow.Cells[0].Value); logica.Borrar(id); } dgvProductos.DataSource = logica.SeleccionarTodos(); lblSuccess.Text = "*Se eliminó satisfactoriamente."; lblSuccess.Visible = true; MessageTimer.Start(); } else { MessageBox.Show("Debe seleccionar un producto de la tabla.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } catch (Exception ex) { lblError.Text = "*" + ex.Message; lblError.Visible = true; MessageTimer.Start(); } }
private void frmAgregarProductos_Load(object sender, EventArgs e) { ProductoLogica logica = new ProductoLogica(); //configuración del DataGridView Productos dgvProductos.AutoGenerateColumns = false; dgvProductos.DefaultCellStyle.Font = new Font("Tahoma", 13); dgvProductos.ColumnHeadersDefaultCellStyle.Font = new Font("Tahoma", 13); dgvProductos.DataSource = logica.SeleccionarTodos(); //Reseteo de controles del frame cmbArea.SelectedIndex = 0; cmbMedida.SelectedIndex = 0; llenarComboBox(); txtId.Text = "0"; txtPeso.Text = "0"; }
public void LLenarGridProductos() { ProductoLogica logica = new ProductoLogica(); List <Producto> productos = logica.SeleccionarTodos(); DataTable table = new DataTable(); table.Columns.Add("Id", typeof(int)); table.Columns.Add("Nombre", typeof(string)); foreach (Producto pro in productos) { DataRow row = table.NewRow(); row["Id"] = pro.IdProducto; row["Nombre"] = pro.Nombre; table.Rows.Add(row); } gridProductos.DataSource = table; gridProductos.DataBind(); gridProductos.SelectedIndex = -1; }
private void btnGuardar_Click(object sender, EventArgs e) { try { CategoriaLogica logicaCategoria = new CategoriaLogica(); ProductoLogica logicaProducto = new ProductoLogica(); Producto producto = new Producto(); producto.nombre = txtNombre.Text; producto.marca = txtMarca.Text; string unidad = cmbMedida.SelectedIndex == 0 ? "Kg" : cmbMedida.SelectedIndex == 1 ? "g" : cmbMedida.SelectedIndex == 2 ? "mL" : cmbMedida.SelectedIndex == 3 ? "L" : cmbMedida.SelectedIndex == 4 ? "oz" : "Kg"; int cantidad = 0; int minCantidad = 0; decimal precio = 0m; decimal peso = 0m; if (!int.TryParse(txtMinCantidad.Text, out minCantidad) || !int.TryParse(txtCantidad.Text, out cantidad) || !decimal.TryParse(txtPrecio.Text, out precio) || !decimal.TryParse(txtPeso.Text, out peso)) { lblError.Text = "*Debe ser un valor numérico."; lblError.Visible = true; } producto.peso = peso; producto.unidad = unidad; producto.cantidad = cantidad; producto.minCantidad = minCantidad; producto.precio = precio; producto.categoria = logicaCategoria.SeleccionarPorId(cmbArea.SelectedIndex); Producto p = logicaProducto.SeleccionarPorId(Convert.ToInt32(txtId.Text)); if (p != null) { producto.id = Convert.ToInt32(txtId.Text); logicaProducto.Actualizar(producto); } else { logicaProducto.Crear(producto); } dgvProductos.DataSource = logicaProducto.SeleccionarTodos(); dgvProductos.CurrentRow.Selected = false; MessageTimer.Start(); lblSuccess.Text = "*Guardado con éxito."; lblSuccess.Visible = true; btnLimpiar_Click(this, null); } catch (Exception ex) { lblError.Text = "*" + ex.Message; lblError.Visible = true; MessageTimer.Start(); } }