//------------------------------------------------------------------------------------------------------------------ public static void UpdateProducto(Producto objProducto) { if (objProducto.ProductoId <= 0) { throw new ArgumentException("El producto no puede ser menor o igual a cero."); } try { ProductoTableAdapter localAdapter = new ProductoTableAdapter(); object resutl = localAdapter.UpdateProducto( string.IsNullOrEmpty(objProducto.Nombre) ? "" : objProducto.Nombre, string.IsNullOrEmpty(objProducto.Descripcion) ? "" : objProducto.Descripcion, string.IsNullOrEmpty(objProducto.UnidadMedidaId) ? "" : objProducto.UnidadMedidaId, objProducto.Precio, objProducto.Stock, objProducto.FamiliaId, objProducto.ProductoId); log.Debug("Se actualizo el producto " + objProducto.ProductoId); } catch (Exception q) { log.Error("Ocurrió un error al actualizar el producto", q); throw q; } }
public void CrearDataSetCompleto() { dsAlmacen = new DsAlmacen(); daCliente = new DsAlmacenTableAdapters.ClienteTableAdapter(); daCliente.Fill(dsAlmacen.Cliente); daPedido = new DsAlmacenTableAdapters.PedidoTableAdapter(); daPedido.Fill(dsAlmacen.Pedido); daEmpleado = new DsAlmacenTableAdapters.EmpleadoTableAdapter(); daEmpleado.Fill(dsAlmacen.Empleado); daProducto = new DsAlmacenTableAdapters.ProductoTableAdapter(); daProducto.Fill(dsAlmacen.Producto); daDetalles = new DsAlmacenTableAdapters.DetallesPedidoTableAdapter(); daDetalles.Fill(dsAlmacen.DetallesPedido); daCategoria = new DsAlmacenTableAdapters.CategoriaTableAdapter(); daCategoria.Fill(dsAlmacen.Categoria); daProveedor = new DsAlmacenTableAdapters.ProveedorTableAdapter(); daProveedor.Fill(dsAlmacen.Proveedor); }
public static Producto GetProductoById(int Idprocuto) { ProductoTableAdapter localAdapter = new ProductoTableAdapter(); if (Idprocuto <= 0) { return(null); } Producto theUser = null; try { ProductoDS.ProductoDataTable table = localAdapter.GetProductoById(Idprocuto); if (table != null && table.Rows.Count > 0) { ProductoDS.ProductoRow row = table[0]; theUser = FillProdutowithImagenRecord(row); } } catch (Exception q) { log.Error("Un error ocurrio mientras obtenia el modulo de la base de dato", q); return(null); } return(theUser); }
public static List <Producto> GetProductoListForSearch(string whereSql) { if (string.IsNullOrEmpty(whereSql)) { whereSql = "1 = 1"; } List <Producto> theList = new List <Producto>(); Producto theUser = null; ProductoTableAdapter theAdapter = new ProductoTableAdapter(); try { ProductoDS.ProductoDataTable table = theAdapter.GetProductoForSearch(whereSql); if (table != null && table.Rows.Count > 0) { foreach (ProductoDS.ProductoRow row in table.Rows) { theUser = FillProdutowithImagenRecord(row); theList.Add(theUser); } } } catch (Exception q) { log.Error("el error ocurrio mientras obtenia la lista de los productos de la base de datos", q); return(null); } return(theList); }
private void GenerarAlertas()//metodo para generar las alertas { try { ProductoTableAdapter adapterPro = new ProductoTableAdapter(); //instanciar objeto para utilizar los querys de la tblProducto ProductoDataTable dataPro = adapterPro.ProdAcabandose(); //instanciar objeto para almacenar la data de los productos, en este caso los productos acabandose foreach (ProductoRow item in dataPro) //recorre cada fila de productos que se estan acabando { dgvAlertas.Rows.Add($"[{item.NombreProducto}] quedan {item.NumExistencias}"); // agrega los productos de un determinado formato en el data grid view } FacturasCajTableAdapter adapterFac = new FacturasCajTableAdapter(); // objeto para utilizar los querys de tblFactura con el nombre del cliente ya traido FacturasCajDataTable dataFac = adapterFac.FacturaSinPagarConCaj(); //objeto para almacenar las facturas que tienen mas de un mes sin pagarse foreach (FacturasCajRow item in dataFac) //recorre cada fila de las facturas sin pagar { TimeSpan diasDebiendo = DateTime.Now - item.Fecha; // almacena la diferencia de dias que el cliente debe int diasDebe = diasDebiendo.Days + 1; //se le añade un día porque falta uno si no se añade dgvAlertas.Rows.Add($"[{item.NomCliente}] debe RD${item.TotalGeneral - item.Pago} desde hace {diasDebe} días de la factura #{item.IdFactura}"); //se agrega al datagridview el cliente, el pago que debe, los dias y el id de la factura } log.Info("Se generaron las alertas en el menú"); //se registra que se cargó las alertas } catch (Exception error) { log.Error($"Error: {error.Message}", error); MessageBox.Show($"Error: {error.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public void LlenarProducto(ComboBox CbProducto) { ProductoTableAdapter adapter = new ProductoTableAdapter(); CbProducto.DataSource = adapter.GetDataByCb(); CbProducto.DisplayMember = "Producto"; CbProducto.ValueMember = "IdProducto"; CbProducto.SelectedIndex = 0; }
public void TraerProducto(DataGridView DgvMostrar) { DgvMostrar.Rows.Clear(); ProductoTableAdapter adapter = new ProductoTableAdapter(); ProductoDataTable mitabla = adapter.GetData(); for (int i = 0; i < mitabla.Count; i++) { ProductoRow misRegistro = (ProductoRow)mitabla.Rows[i]; DgvMostrar.Rows.Add( null, misRegistro.IdProducto, misRegistro.Producto ); } }
public static void DeleteProducto(int productoId) { if (productoId <= 0) { throw new ArgumentException("El producto no puede ser menor o igual a cero."); } try { ProductoTableAdapter theAdapter = new ProductoTableAdapter(); theAdapter.DeleteProducto(productoId); } catch (Exception ex) { log.Error("Ocurrio un error al Eliminar el prooducto.", ex); throw; } }
public static void InserProducto(Producto objProducto) { try { ProductoTableAdapter localAdapter = new ProductoTableAdapter(); object resutl = localAdapter.InsertProducto( string.IsNullOrEmpty(objProducto.Nombre) ? "" : objProducto.Nombre, string.IsNullOrEmpty(objProducto.Descripcion) ? "" : objProducto.Descripcion, string.IsNullOrEmpty(objProducto.UnidadMedidaId) ? "" : objProducto.UnidadMedidaId, objProducto.Precio, objProducto.Stock, objProducto.FamiliaId); log.Debug("Se insertó el producto " + objProducto.Nombre); } catch (Exception q) { log.Error("Ocurrió un error al insertar el nombre", q); throw q; } }
//------------------------------------------paginacion----------------------------------------------------- public static int SearchProductoPaginacion(ref List <Producto> articulos, string where, int pageSize, int firstRow, string ordenar) { try { int?totalRows = 0; ProductoTableAdapter localAdapter = new ProductoTableAdapter(); ProductoDS.ProductoDataTable theTable = localAdapter.GetSearchForProducto(where, pageSize, firstRow, ref totalRows, ordenar); if (theTable != null && theTable.Rows.Count > 0) { foreach (ProductoDS.ProductoRow row in theTable.Rows) { articulos.Add(FillProdutowithImagenRecord(row)); } } return((int)totalRows); } catch (Exception ex) { throw ex; } }
private void btnAgregar_Click(object sender, EventArgs e)//evento que se dispara cuando das clic al boton agregar { try { if (txtCodigo.Text != "" && txtNombre.Text != "" && txtPrecioDetalle.Text != "" && txtPrecioMayor.Text != "" && txtNumExistencia.Text != "") //verifica que se introduzca la informacion necesaria { ProductoTableAdapter adapter = new ProductoTableAdapter(); //objeto para usar los querys de tblProducto ProductoDataTable data = adapter.BuscarProductoPorCodigo(txtCodigo.Text); //objeto para almacenar informacion de tblProducto, en este caso buscada por el codigo de barra ingresado if (data.Count == 0) //verifica que no haya ya un producto ingresado con ese codigo de barra { decimal descuento = Convert.ToDecimal(txtDescuento.Text); //convierte los numeros ingresados en el textbox descuento en decimal para ingresarlo posteriormente a la base de datos int idCategoria = Convert.ToInt32(cboCategoria.SelectedValue); //guarda la categoria que se seleccionó para el producto adapter.InsertarP(txtNombre.Text.Trim(), txtCodigo.Text.Trim(), Convert.ToDecimal(txtPrecioDetalle.Text), Convert.ToDecimal(txtPrecioMayor.Text), Convert.ToDecimal(txtNumExistencia.Text), idCategoria, descuento, cbxITBIS.Checked); //se inserta el producto en tblProducto log.Info($"Se agregó el producto con el código [{txtCodigo.Text}] al sistema por el usuario {usuario.Nombre} {usuario.Apellidos}"); //se registra que se ingresó el producto MessageBox.Show($"Se agregó al sistema el producto ingresado con el código: {txtCodigo.Text}", "Agregar producto", MessageBoxButtons.OK, MessageBoxIcon.Information); //notifica al usuario con un mensaje que se ingresó el producto Limpiar(); //se limpian todos los textbox } else //si ya hay un producto con este codigo de barra { if ((MessageBox.Show($"Ya hay un producto ingresado con este Código: {txtCodigo.Text}, ¿Desea limpiar todos los campos?", "Error", MessageBoxButtons.YesNo) == DialogResult.Yes)) //le pregunta al usuario si desea limpiar todos los campos. si responde si pasa lo siguiente { Limpiar(); //se limpian todos los textbox } else //si responde que no { txtCodigo.Focus(); //coloca al usuario en el textbox codigo para que lo modifique } log.Info($"Se intentó agregar el producto {txtCodigo.Text} al sistema por el usuario {usuario.Nombre} {usuario.Apellidos} pero ya existe uno con este mismo código"); //registra que se intentó agregar un producto para ya habia uno con este codigo } }//si falta alguna informacion else { string mensaje = "Falta(n) por llenar lo(s) siguiente(s) campo(s): "; //string para guardar que info hace falta if (txtCodigo.Text == "") //si no se ingresó el codigo de barra en su respectivo textbo { mensaje += "\nCódigo de Barras"; //notifica que falta el codigo de barras } if (txtNombre.Text == "") //si no se ingresó el nombre en su respectivo textbo { mensaje += "\nNombre"; //notifica que falta el nombre } if (txtPrecioDetalle.Text == "") //si no se ingresó el precio al detalle en su respectivo textbo { mensaje += "\nPrecio al Detalle"; //notifica que falta el precio al detalle } if (txtPrecioMayor.Text == "") //si no se ingresó el precio mayor en su respectivo textbo { mensaje += "\nPrecio al Mayor"; //notifica que falta el precio al por mayor } if (txtNumExistencia.Text == "") //si no se ingresó el numero de existencias en su respectivo textbo { mensaje += "\nNúmero de Existencia"; //notifica que falta el numero de existencia } MessageBox.Show(mensaje, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); //notifica al usuario el mensaje de lo que falta } } catch (Exception error) { log.Error($"Error: {error.Message}", error); MessageBox.Show($"Error: {error.Message}", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }