public bool Update(Producto o)
        {
            try
            {
                using (var db = new DymContext())
                {
                    db.Entry(o).State = EntityState.Modified;

                    foreach (var item in db.ProductoSustancia.Where(x => x.ProductoId == o.ProductoId).ToList())
                    {
                        db.Remove(item);
                    }

                    db.SaveChanges();

                    foreach (var sustancia in o.ProductoSustancia)
                    {
                        db.Add(sustancia);
                    }

                    db.SaveChanges();

                    return(true);
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
            }
            return(false);
        }
        public bool HardReset()
        {
            try
            {
                using (var db = new DymContext())
                {
                    var puntos = db.Punto.Where(x => x.ResetedBy == null).ToList();

                    foreach (var p in puntos)
                    {
                        p.ResetedBy = Ambiente.LoggedUser.UsuarioId;
                        p.UpdatedBy = Ambiente.LoggedUser.UsuarioId;
                        p.IsDeleted = true;
                    }
                    db.UpdateRange(puntos);
                    db.SaveChanges();
                    return(true);
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
            }
            return(false);
        }
        private void CalculaTotales()
        {
            //controladores

            partidas = ventapController.SelectPartidas(venta.VentaId);

            if (venta == null || partidas == null)
            {
                return;
            }

            else
            {
                venta.Unidades = 0;
                venta.SubTotal = 0;
                venta.Impuesto = 0;
                venta.Total    = 0;

                foreach (var partida in partidas)
                {
                    partida.SubTotal         = partida.Cantidad * partida.Precio;
                    partida.ImporteImpuesto1 = partida.SubTotal * partida.Impuesto1;
                    partida.ImporteImpuesto2 = partida.SubTotal * partida.Impuesto2;
                    partida.Total            = partida.SubTotal + partida.ImporteImpuesto1 + partida.ImporteImpuesto2;

                    //sumar el total por partida a los totales de la venta
                    venta.Unidades += partida.Cantidad;
                    venta.SubTotal += partida.SubTotal;
                    venta.Impuesto += partida.ImporteImpuesto1 + partida.ImporteImpuesto2;
                    venta.Total    += partida.SubTotal + partida.ImporteImpuesto1 + partida.ImporteImpuesto2;
                }

                venta.EstadoDocId   = "CON";
                venta.TotalConLetra = moneda.Convertir(venta.Total.ToString(), true);
                venta.Pago1         = venta.Total;

                using (var db = new DymContext())
                {
                    db.Update(venta);
                    db.SaveChanges();
                    db.UpdateRange(partidas);
                    db.SaveChanges();
                }
            }
        }
 public bool Update(CMetodopago o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Entry(o).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
             return(db.SaveChanges() > 0 ? true : false);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje("Algo salio mal con: " + MethodBase.GetCurrentMethod().Name + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool Delete(CMetodopago o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Remove(o);
             return(db.SaveChanges() > 0 ? true : false);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje("Algo salio mal con: " + MethodBase.GetCurrentMethod().Name + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
Beispiel #6
0
 public bool InsertOne(CierreInventario o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Add(o);
             return(db.SaveChanges() > 0 ? true : false);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje("Algo salio mal con: " + MethodBase.GetCurrentMethod().Name + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool InsertRange(List <CMetodopago> lista)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.AddRange(lista);
             return(db.SaveChanges() > 0 ? true : false);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje("Algo salio mal con: " + MethodBase.GetCurrentMethod().Name + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool InsertRange(List <Actualizacion> lista)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.AddRange(lista);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show("Algo salio mal @ " + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool InsertOne(Cxp o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Add(o);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool Update(CambiosPrecio o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Entry(o).State = EntityState.Modified;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool Delete(Actualizacion o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Remove(o);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show("Algo salio mal @ " + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool UpdateRange(List <Lote> lotes)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.UpdateRange(lotes);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
Beispiel #13
0
 public bool InsertOne(DymError o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Add(o);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show("Algo salio mal @ " + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool InsertaPartidas(ICollection <Cxpp> partidas)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.AddRange(partidas);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
Beispiel #15
0
 public bool Update(InformeCategoria o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Entry(o).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
Beispiel #16
0
 public bool Delete(InformeCategoria o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Remove(o);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool Update(Actualizacion o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Entry(o).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show("Algo salio mal @ " + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
Beispiel #18
0
 public bool InsertRange(List <InformeCategoria> lista)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.AddRange(lista);
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool Delete(Impuesto o)
 {
     try
     {
         using (var db = new DymContext())
         {
             o.IsDeleted       = true;
             db.Entry(o).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
             db.SaveChanges();
             return(true);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Algo salio mal @" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
        public string InsertRange(List <ProductoSustancia> lista)
        {
            List <ProductoSustancia> listaCorrectos = new List <ProductoSustancia>();
            List <string>            errores        = new List <string>();
            string correctos = string.Empty;

            try
            {
                using (var db = new DymContext())
                {
                    foreach (var item in lista)
                    {
                        var producto  = db.Producto.FirstOrDefault(x => x.ProductoId == item.ProductoId);
                        var sustancia = db.Sustancia.FirstOrDefault(x => x.SustanciaId == item.SustanciaId);
                        if (producto != null && sustancia != null)
                        {
                            var prodsus = new ProductoSustancia();
                            prodsus.ProductoId  = producto.ProductoId;
                            prodsus.SustanciaId = sustancia.SustanciaId;
                            prodsus.Contenido   = item.Contenido;

                            listaCorrectos.Add(prodsus);
                        }
                        else
                        {
                            errores.Add(item.SustanciaId + ", NO EXISTE EN LAS SUSTANCIAS o, " + item.ProductoId + ", NO EXISTE EN LOS PRODUCTOS");
                        }
                    }
                    db.ProductoSustancia.AddRange(listaCorrectos);
                    db.SaveChanges();
                    correctos += "SE GUARDARON " + listaCorrectos.Count + " REGISTOS\n\n";
                    correctos += "SE OMITIERON " + errores.Count + " REGISTOS\n\n";
                    correctos += "COPIE Y PEGUE LOS DETALLES\n\n ";
                    var result = String.Join(" \n ", errores.ToArray());
                    correctos += result;
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + this.GetType().Name + "\n" + ex.ToString());
            }

            return(correctos);
        }
Beispiel #21
0
        public string InsertRange(List <ProductoImpuesto> lista)
        {
            var           listaCorrectos = new List <ProductoImpuesto>();
            List <string> errores        = new List <string>();
            string        correctos      = string.Empty;

            try
            {
                using (var db = new DymContext())
                {
                    foreach (var item in lista)
                    {
                        var producto = db.Producto.FirstOrDefault(x => x.ProductoId == item.ProductoId);
                        var impuesto = db.Impuesto.FirstOrDefault(x => x.ImpuestoId == item.ImpuestoId);
                        if (producto != null && impuesto != null)
                        {
                            var prodImp = new ProductoImpuesto();
                            prodImp.ProductoId = producto.ProductoId;
                            prodImp.ImpuestoId = impuesto.ImpuestoId;
                            listaCorrectos.Add(prodImp);
                        }
                        else
                        {
                            errores.Add(item.ImpuestoId + ", NO EXISTE EN LOS IMPUESTOS o, " + item.ProductoId + ", NO EXISTE EN LOS PRODUCTOS");
                        }
                    }
                    db.AddRange(listaCorrectos);
                    db.SaveChanges();
                    correctos += "SE GUARDARON " + listaCorrectos.Count + " REGISTOS\n\n";
                    correctos += "SE OMITIERON " + errores.Count + " REGISTOS\n\n";
                    correctos += "COPIE Y PEGUE LOS DETALLES\n\n ";
                    var result = String.Join(" \n ", errores.ToArray());
                    correctos += result;
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
            }

            return(correctos);
        }
 public bool Delete(string Id)
 {
     try
     {
         using (var db = new DymContext())
         {
             var temp = db.CMetodopago.FirstOrDefault(x => x.MetodoPagoId == Id);
             if (temp != null)
             {
                 db.Remove(temp);
                 return(db.SaveChanges() > 0 ? true : false);
             }
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje("Algo salio mal con: " + MethodBase.GetCurrentMethod().Name + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 internal bool DeletePartidas(Devolucion devolucion)
 {
     try
     {
         using (var db = new DymContext())
         {
             var partidas = db.Devolucionp.Where(x => x.DevolucionId == devolucion.DevolucionId).ToList();
             if (partidas != null)
             {
                 db.RemoveRange(partidas);
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool DeleteOne(int Id)
 {
     try
     {
         using (var db = new DymContext())
         {
             var temp = db.Cxp.FirstOrDefault(x => x.CxpId == Id);
             if (temp != null)
             {
                 db.Remove(temp);
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool DeletePartidas(Compra compra)
 {
     try
     {
         using (var db = new DymContext())
         {
             var partidas = db.Comprap.Where(x => x.CompraId == compra.CompraId).ToList();
             if (partidas != null)
             {
                 db.RemoveRange(partidas);
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool Delete(string Id)
 {
     try
     {
         using (var db = new DymContext())
         {
             var temp = db.Impuesto.FirstOrDefault(x => x.ImpuestoId == Id.Trim());
             if (temp != null)
             {
                 temp.IsDeleted = true;
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show("Algo salio mal @" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool Delete(int Id)
 {
     try
     {
         using (var db = new DymContext())
         {
             var temp = db.Actualizacion.FirstOrDefault(x => x.ActualizacionId == Id);
             if (temp != null)
             {
                 db.Remove(temp);
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         System.Windows.Forms.MessageBox.Show("Algo salio mal @ " + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool Delete(string Id)
 {
     try
     {
         using (var db = new DymContext())
         {
             var temp = db.Proveedor.FirstOrDefault(x => x.ProveedorId == Id.Trim());
             if (temp != null)
             {
                 temp.IsDeleted = true;
                 db.SaveChanges();
                 return(true);
             }
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool DeleteOne(Venta o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Remove(o);
             if (db.SaveChanges() > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
Beispiel #30
0
        public bool AfectaInventario(string productoId, decimal cantidad)
        {
            //creamos nuestro contexto
            using (var db = new DymContext())
            {
                //creamos el ámbito de la transacción
                using (var transaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        var producto = db.Producto.FirstOrDefault(x => x.ProductoId == productoId.Trim());
                        if (producto != null)
                        {
                            producto.Stock += cantidad;

                            if (db.SaveChanges() > 0)
                            {
                                transaction.Commit();
                                return(true);
                            }
                            else
                            {
                                transaction.Rollback();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        //hacemos rollback si hay excepción
                        ex.ToString();
                        transaction.Rollback();
                    }
                }
            }
            return(false);
        }