/// <summary> /// Método que recupera todas las entradas de la base de datos /// </summary> /// <returns>Devuele una lista con todos los productos</returns> public List <productes> LeerProdutos() { using (var context = new dbempresaEntities()) { return(context.productes.ToList()); } }
public List <factura_detall> LeerDetall() { using (var context = new dbempresaEntities()) { return(context.factura_detall.ToList()); } }
/// <summary> /// Devuelve una lista con los clientes</summary> /// <returns>Devuelve una lista de clientes</returns> /// public List <clients> LeerCliente() { using (var context = new dbempresaEntities()) { return(context.clients.ToList()); } }
public void CrearDetall(factura_detall f) { using (var context = new dbempresaEntities()) { context.factura_detall.Add(f); context.SaveChanges(); } }
/// <summary> /// Método que crea una factura /// </summary> /// <param name="f">objeto factura que se quiere crear</param> public void CrearFactura(factura f) { using (var context = new dbempresaEntities()) { context.factura.Add(f); context.SaveChanges(); } }
/// <summary> /// Método que devuelve una lista de facturas /// </summary> /// <returns>Devuelve una lista de facturas</returns> public List <factura> LeerFacturas() { using (var context = new dbempresaEntities()) { return(context.factura.ToList()); } }
/// <summary> /// carga los datos de la BD /// </summary> private void loadData() { this.context = new dbempresaEntities(); BindingSource bi = new BindingSource(); bi.DataSource = this.context.clients.ToList(); dataGridView1.DataSource = bi; }
/// <summary> /// Crea un nuevo usuario</summary> /// <returns> /// Devuelve una lista de clientes</returns> public void CrearCliente(clients c) { using (var context = new dbempresaEntities()) { context.clients.Add(c); context.SaveChanges(); } }
/// <summary> /// Crea un nuevo objeto producto /// </summary> /// <param name="p">objeto producto que se quiere guadar</param> public void CrearProducto(productes p) { //Querying with LINQ to Entities using (var context = new dbempresaEntities()) { context.productes.Add(p); context.SaveChanges(); } }
/// <summary> /// Método que recuperar una entrada de la base de datos /// </summary> /// <param name="id">id del objeto que queremos recuperar</param> /// <returns>devuelve un objeto productes</returns> public productes LeerProducto(int id) { //Querying with LINQ to Entities using (var context = new dbempresaEntities()) { return(context.productes .Where(s => s.id_produte == id) .FirstOrDefault()); } }
public factura_detall LeerDetall(int id) { //Querying with LINQ to Entities using (var context = new dbempresaEntities()) { return(context.factura_detall .Where(s => s.id_factura_detall == id) .FirstOrDefault()); } }
/// <summary> /// Devuelve una factura /// </summary> /// <param name="id">id de la factura que se quiere buscar</param> /// <returns></returns> public factura LeerFactura(int id) { //Querying with LINQ to Entities using (var context = new dbempresaEntities()) { return(context.factura .Where(s => s.n_factura == id) .FirstOrDefault()); } }
/// <summary> /// Devuelve un cliente /// </summary> /// <param name="id">id del cliente que queremos recuperar</param> /// <returns>Devuelve un objeto cliente</returns> public clients LeerCliente(int id) { //Querying with LINQ to Entities using (var context = new dbempresaEntities()) { return(context.clients .Where(s => s.id_client == id) .FirstOrDefault()); } }
/// <summary> /// Elimina un CLiente</summary> /// <param name="id"> Variable que representa la id del Cliente que queremos eliminar</param> public void BorrarCliente(int id) { using (var context = new dbempresaEntities()) { try { clients clt = context.clients.First(i => i.id_client == id); context.clients.Remove(clt); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.InnerException); } } }
public void BorrarDetall(int id) { using (var context = new dbempresaEntities()) { try { factura_detall fac = context.factura_detall.First(i => i.id_factura_detall == id); context.factura_detall.Remove(fac); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.InnerException); } } }
/// <summary> /// Método que elimina un registro de la base de datos /// </summary> /// <param name="id">id del producto que se quiere borrar</param> public void BorrarProducto(int id) { using (var context = new dbempresaEntities()) { try { productes prod = context.productes.First(i => i.id_produte == id); context.productes.Remove(prod); context.SaveChanges(); } catch (Exception ex) { Console.WriteLine(ex.InnerException); } } }
/// <summary> /// carga los datos de la BD a la tabla /// </summary> private void loadData() { this.context = new dbempresaEntities(); BindingSource bi = new BindingSource(); bi.DataSource = this.context.productes.ToList(); dataGridView1.DataSource = bi; this.Dock = DockStyle.Fill; this.chart1.Series.Clear(); Series series = this.chart1.Series.Add("Preus"); series.ChartType = SeriesChartType.Spline; foreach (productes p in this.context.productes.ToList()) { series.Points.AddXY(p.producte.ToString(), p.preu); } }
public void addData() //add list to context //problem the id autoincremental... T_T { this.context = new dbempresaEntities(); foreach (clients c in clientList) { int realId = c.id_client; new DAOFactory().getClienteDAO().CrearCliente(c); this.context.SaveChanges(); Debug.WriteLine(" Client ID is " + c.id_client); // modify all the fk foreach (factura f in facturaList) { if (f.id_client == realId) { f.id_client = c.id_client; } } } foreach (productes pt in producteList) { var realId = pt.id_produte; new DAOFactory().getProductoDAO().CrearProducto(pt); this.context.SaveChanges(); Debug.WriteLine("id productes: " + pt.id_produte + " " + realId); // modify all the fk foreach (factura_detall fd in factura_detallList) { Debug.WriteLine("real: " + realId); if (fd.id_producte == realId) { fd.id_producte = pt.id_produte; } Debug.WriteLine("id productes de factura detall: " + fd.id_producte); } } foreach (factura f in facturaList) { int realnFactura = f.n_factura; new DAOFactory().getFacturaDAO().CrearFactura(f); this.context.SaveChanges(); //el id incremental , hay que volverlo a setear, si no hace el autoincremental normal //factura fact = this.context.factura.First(i => i.id_client == f.id_client && i.data == f.data //&& i.descompte == f.descompte && i.iva == f.iva); //factura fact = this.context.factura.Last<factura>(); //int max = this.context.factura.Max(p => p.n_factura); //factura fact = this.context.factura.First(i => i.n_factura == max); //fact.n_factura = f.n_factura; // modify all the fk foreach (factura_detall fd in factura_detallList) { Debug.WriteLine("id nfactura: " + f.n_factura + " real " + realnFactura + "fd" + fd.n_factura); if (fd.n_factura == realnFactura) { fd.n_factura = f.n_factura; } } } foreach (factura_detall fd in factura_detallList) { new DAOFactory().getFacturaDetallDAO().CrearFacturaDetall(fd); this.context.SaveChanges(); //el id incremental , hay que volverlo a setear, si no hace el autoincremental normal //factura_detall factd = this.context.factura_detall.First(i => i.n_factura == fd.n_factura); //factura_detall factd = this.context.factura_detall.Last<factura_detall>(); //int max = this.context.factura_detall.Max(p => p.id_factura_detall); //factura_detall factd = this.context.factura_detall.First(i => i.id_factura_detall == max); //factd.id_factura_detall = fd.id_factura_detall; } }
private void login_Load(object sender, EventArgs e) { this.context = new dbempresaEntities(); this.admin = this.context.admin.FirstOrDefault(); }
private void XMLExporter_Load(object sender, EventArgs e) { this.context = new dbempresaEntities(); //Declaramos el documento y su definición XDocument document = new XDocument( new XDeclaration("1.0", "utf-8", null)); //Creamos el nodo raiz y lo añadimos al documento XElement nodoRaiz = new XElement("empresa"); document.Add(nodoRaiz); XElement nodoClients = new XElement("clients"); XElement nodoProductes = new XElement("productes"); XElement nodoFactures = new XElement("factura"); XElement nodoFacturesDetall = new XElement("factura_detall"); nodoRaiz.Add(nodoClients); nodoRaiz.Add(nodoProductes); nodoRaiz.Add(nodoFactures); nodoRaiz.Add(nodoFacturesDetall); foreach (clients c in this.context.clients) { XElement nodoClient = new XElement("client"); nodoClient.Add(new XElement("id_client", c.id_client)); nodoClient.Add(new XElement("nom", c.nom)); nodoClient.Add(new XElement("cognom1", c.cognom1)); nodoClient.Add(new XElement("cognom2", c.cognom2)); nodoClient.Add(new XElement("adreça", c.adreça)); nodoClient.Add(new XElement("codi_postal", c.codi_postal)); nodoClient.Add(new XElement("poblacio", c.poblacio)); nodoClient.Add(new XElement("provincia", c.provincia)); nodoClient.Add(new XElement("telefon", c.telefon)); nodoClient.Add(new XElement("fax", c.fax)); nodoClient.Add(new XElement("email", c.email)); nodoClients.Add(nodoClient); } foreach (productes p in this.context.productes) { XElement nodoProducte = new XElement("producte"); nodoProducte.Add(new XElement("id_produte", p.id_produte)); nodoProducte.Add(new XElement("producte", p.producte)); nodoProducte.Add(new XElement("preu", p.preu)); nodoProductes.Add(nodoProducte); } foreach (factura f in this.context.factura) { XElement nodoFactura = new XElement("factura"); nodoFactura.Add(new XElement("n_factura", f.n_factura)); nodoFactura.Add(new XElement("id_client", f.id_client)); nodoFactura.Add(new XElement("descompte", f.descompte)); nodoFactura.Add(new XElement("data", f.data)); nodoFactura.Add(new XElement("iva", f.iva)); nodoFactures.Add(nodoFactura); } foreach (factura_detall fd in this.context.factura_detall) { XElement nodoFacturaDetall = new XElement("factura_detall"); nodoFacturaDetall.Add(new XElement("id_factura_detall", fd.id_factura_detall)); nodoFacturaDetall.Add(new XElement("n_factura", fd.n_factura)); nodoFacturaDetall.Add(new XElement("id_producte", fd.id_producte)); nodoFacturaDetall.Add(new XElement("quantitat", fd.quantitat)); nodoFacturesDetall.Add(nodoFacturaDetall); } Debug.WriteLine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\export.xml"); document.Save(Environment.GetFolderPath(Environment.SpecialFolder.Desktop) + "\\export.xml"); }