//UPDATE public static bool updateProducto(Producto producto) { try { using (var db = new MercatorEntities()) { db.Entry(producto).State = System.Data.Entity.EntityState.Modified; int changes = db.SaveChanges(); if (changes > 0) { return(true); } else { return(false); } } } catch (DbEntityValidationException dbEx) { foreach (DbEntityValidationResult entityErr in dbEx.EntityValidationErrors) { foreach (DbValidationError error in entityErr.ValidationErrors) { Console.WriteLine("Error Property Name {0} : Error Message: {1}", error.PropertyName, error.ErrorMessage); } } } return(false); }
//CREATE public static bool createCompra(Compra compra) { try { using (var db = new MercatorEntities()) { db.Compras.Add(compra); db.SaveChanges(); return(true); } } catch (DbEntityValidationException dbEx) { foreach (DbEntityValidationResult entityErr in dbEx.EntityValidationErrors) { foreach (DbValidationError error in entityErr.ValidationErrors) { Console.WriteLine("Error Property Name {0} : Error Message: {1}", error.PropertyName, error.ErrorMessage); } } } return(false); }
//DELETE public static bool deleteProveedor(int idproveedor) { try { using (var db = new MercatorEntities()) { var query = (from p in db.Proveedors where p.IdProveedor == idproveedor select p).Single(); db.Proveedors.Remove(query); db.SaveChanges(); return(true); } } catch (DbEntityValidationException dbEx) { foreach (DbEntityValidationResult entityErr in dbEx.EntityValidationErrors) { foreach (DbValidationError error in entityErr.ValidationErrors) { Console.WriteLine("Error Property Name {0} : Error Message: {1}", error.PropertyName, error.ErrorMessage); } } } return(false); }
//DELETE public static bool deleteProducto(int id) { try { using (var db = new MercatorEntities()) { // Realizamos la consulta var query = db.Productoes.Where(p => p.IdProducto == id).First(); // Eliminamos el cliente db.Productoes.Remove(query); // Para el Framework 4.0 o inferior // Guardamos los cambios int res = db.SaveChanges(); return(res > 0); } } catch (DbEntityValidationException dbEx) { foreach (DbEntityValidationResult entityErr in dbEx.EntityValidationErrors) { foreach (DbValidationError error in entityErr.ValidationErrors) { Console.WriteLine("Error Property Name {0} : Error Message: {1}", error.PropertyName, error.ErrorMessage); } } } return(false); }
//READ ALL public static List <DetalleCompra> getCompra() { using (var db = new MercatorEntities()) { var query = (from c in db.DetalleCompras select c).ToList(); return(query); } }
//READ ALL public static List <Producto> getProductos() { using (var db = new MercatorEntities()) { var query = (from p in db.Productoes select p).ToList(); return(query); } }
//READ ALL public static List <DetalleVenta> getVentas() { using (var db = new MercatorEntities()) { var query = (from v in db.DetalleVentas select v).ToList(); return(query); } }
//READ ALL public static List <Empleado> getEmpleados() { using (var db = new MercatorEntities()) { var query = (from p in db.Empleadoes select p).ToList(); return(query); } }
//READ BY SERIE public static Compra getCompraBySr(string serie) { using (var db = new MercatorEntities()) { var query = (from c in db.Compras where c.Serie == serie select c).Single(); return(query); } }
//READ BY ID public static Producto getProductoByDescription(int id) { using (var db = new MercatorEntities()) { var query = (from p in db.Productoes where p.IdProducto == id select p).Single(); return(query); } }
//READ BY NAME public static Proveedor getProveedorByName(int idproveedor) { using (var db = new MercatorEntities()) { var query = (from p in db.Proveedors where p.IdProveedor == idproveedor select p).Single(); return(query); } }
//READ BY SERIE public static Venta getVentasBySr(int serie) { using (var db = new MercatorEntities()) { var query = (from v in db.Ventas where v.Serie == serie select v).Single(); return(query); } }
//READ BY ID public static Empleado getEmpleadoByName(int id) { using (var db = new MercatorEntities()) { var query = (from e in db.Empleadoes where e.IdEmpleado == id select e).Single(); return(query); } }
public static DataTable mostrarCategoria() { //Creando el DataTable DataTable dtCategoria = new DataTable(); //Añadiendo las columnas que llevara el DataTable dtCategoria.Columns.Add("IdCategoria", typeof(int)); dtCategoria.Columns.Add("Descripcion", typeof(string)); //Añadir una fila o registro a el DataTable dtCategoria.Rows.Add("0", "--Seleccione--"); //Espacio de nombres de la cadena de conexion using (var dbCtx = new MercatorEntities()) { //Query que traera la informacion de la Base de Datos var query = (from c in dbCtx.Categorias select c).ToList(); //Ciclo FOR para crear las filas con la informacion //de la base de datos query.ToList().ForEach((c) => { //Creando una fila en el DataTable DataRow Row = dtCategoria.NewRow(); //Columnas que llevara la fila Row.SetField <int>("IdCategoria", c.IdCategoria); Row.SetField <string>("Descripcion", c.Descripcion); //Añadir la fila creada al DataTable dtCategoria.Rows.Add(Row); }); } return(dtCategoria); }