public bool UpdateOne(Venta o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.Entry(o).State = EntityState.Modified;
             if (db.SaveChanges() > 0)
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(false);
 }
 public bool UpdateRange(List <Venta> o)
 {
     try
     {
         using (var db = new DymContext())
         {
             db.UpdateRange(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);
 }
 public List <Lote> GetLotes(string productoId, int compraId)
 {
     try
     {
         using (var db = new DymContext())
         {
             var lotes = db.Lote.Where(x => x.ProductoId.Equals(productoId.Trim()) && x.CompraId == compraId).ToList();
             if (lotes.Count > 0)
             {
                 return(lotes);
             }
             else
             {
                 return(null);
             }
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(null);
 }
Пример #4
0
 public List <Venta> SelectFacturas(DateTime fini, DateTime ffin, bool solosintimbrar = false)
 {
     try
     {
         ffin = ffin.AddDays(1);
         using (var db = new DymContext())
         {
             if (solosintimbrar)
             {
                 return(db.Venta.Where(x => x.UuId == null && x.TipoDocId.Equals("FAC") && x.EstadoDocId.Equals("CON")).ToList());
             }
             else
             {
                 return(db.Venta.Where(x => x.CreatedAt >= fini && x.CreatedAt < ffin && x.TipoDocId.Equals("FAC") && x.EstadoDocId.Equals("CON")).ToList());
             }
         }
     }
     catch (Exception ex)
     {
         Ambiente.Mensaje(Ambiente.CatalgoMensajes[-1] + "@" + GetType().Name + "\n" + ex.ToString());
     }
     return(null);
 }
Пример #5
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);
        }
Пример #6
0
        public dynamic GetSelectedObject(string NodoName, DataGridView Grid1)
        {
            switch (NodoName)
            {
            case "NodoClientes":

                using (var db = new DymContext())
                {
                    return(db.Cliente.FirstOrDefault(x => x.ClienteId ==
                                                     Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }

            case "NodoProveedores":

                using (var db = new DymContext())
                {
                    return(db.Proveedor.FirstOrDefault(x => x.ProveedorId ==
                                                       Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }


            case "NodoProductos":

                using (var db = new DymContext())
                {
                    return(db.Producto.FirstOrDefault(x => x.ProductoId ==
                                                      Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }


            case "NodoCategorias":

                using (var db = new DymContext())
                {
                    return(db.Categoria.FirstOrDefault(x => x.CategoriaId ==
                                                       Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }


            case "NodoLaboratorios":

                using (var db = new DymContext())
                {
                    return(db.Laboratorio.FirstOrDefault(x => x.LaboratorioId ==
                                                         Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }


            case "NodoImpuestos":


                using (var db = new DymContext())
                {
                    return(db.Impuesto.FirstOrDefault(x => x.ImpuestoId ==
                                                      Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }

            case "NodoSustancias":


                using (var db = new DymContext())
                {
                    return(db.Sustancia.FirstOrDefault(x => x.SustanciaId ==
                                                       Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }



            case "NodoEstaciones":

                using (var db = new DymContext())
                {
                    return(db.Estacion.FirstOrDefault(x => x.EstacionId ==
                                                      Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }


            case "NodoClavesSat":
                using (var db = new DymContext())
                {
                    return(db.CClaveProdServ.FirstOrDefault(x => x.ClaveProdServId ==
                                                            Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }

            case "NodoPresentaciones":

                using (var db = new DymContext())
                {
                    return(db.Presentacion.FirstOrDefault(x => x.PresentacionId ==
                                                          Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }

            case "NodoUnidadesMedida":
                using (var db = new DymContext())
                {
                    return(db.UnidadMedida.FirstOrDefault(x => x.UnidadMedidaId ==
                                                          Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }

            case "NodoUsuarios":

                using (var db = new DymContext())
                {
                    return(db.Usuario.FirstOrDefault(x => x.UsuarioId ==
                                                     Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }

            //Conceptos
            case "NodoConEgre":
                using (var db = new DymContext())
                {
                    return(db.ConceptoEgreso.FirstOrDefault(x => x.ConceptoEgresoId ==
                                                            Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }

            case "NodoConIngre":
                using (var db = new DymContext())
                {
                    return(db.ConceptoIngreso.FirstOrDefault(x => x.ConceptoIngresoId ==
                                                             Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }

            case "NodoConMovsInv":
                using (var db = new DymContext())
                {
                    return(db.ConceptoMovInv.FirstOrDefault(x => x.ConceptoMovInvId ==
                                                            Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString()));
                }

            default:
                return(null);
            }
        }
Пример #7
0
        public static void Compras()
        {
            StiReport report = new StiReport();

            try
            {
                using (var form = new FrmParamData())
                {
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        using (var db = new DymContext())
                        {
                            if (form.TodasLasFechas)
                            {
                                var q = from compra in db.Compra
                                        join comprap in db.Comprap on compra.CompraId equals comprap.CompraId
                                        where compra.EstadoDocId.Equals("CON")
                                        select new
                                {
                                    compra.CompraId,
                                    comprap.ProductoId,
                                    comprap.Descripcion,
                                    comprap.Cantidad,
                                    comprap.ImporteImpuesto1,
                                    comprap.ImporteImpuesto2,
                                    comprap.PrecioCompra,
                                    comprap.Total,
                                    compra.CreatedAt,
                                    compra.CreatedBy
                                };
                                report.Load(Reports.FCompras);
                                report.Compile();
                                report["inicial"] = null;
                                //report["final"] = null;
                                report.Dictionary.DataSources.Clear();
                                report.RegBusinessObject("partidas", "partidas", q.ToList());
                                report.Dictionary.Synchronize();
                                //report.Design();
                                //report.Save(Reports.FCompras);
                                report.Show(true);
                            }
                            else
                            {
                                var q = from compra in db.Compra
                                        join comprap in db.Comprap on compra.CompraId equals comprap.CompraId
                                        where compra.EstadoDocId.Equals("CON") && compra.CreatedAt.Date >= FrmParamData.Inicial.Date && compra.CreatedAt.Date <= FrmParamData.Final.Date
                                        select new
                                {
                                    compra.CompraId,
                                    comprap.ProductoId,
                                    comprap.Descripcion,
                                    comprap.Cantidad,
                                    comprap.ImporteImpuesto1,
                                    comprap.ImporteImpuesto2,
                                    comprap.Total,
                                    comprap.PrecioCompra,
                                    compra.CreatedAt,
                                    compra.CreatedBy
                                };
                                report.Load(Reports.FCompras);
                                report.Compile();
                                report["inicial"] = FrmParamData.Inicial.Date;
                                report["final"]   = FrmParamData.Final.Date;
                                report.Dictionary.DataSources.Clear();
                                report.RegBusinessObject("partidas", "partidas", q.ToList());
                                report.Dictionary.Synchronize();
                                //report.Design();
                                //report.Save(Reports.FCompras);
                                report.Show(true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.Message);
            }
        }
Пример #8
0
        internal static void VentasAcosto(DateTime inicial, DateTime final, bool todasLasFechas)
        {
            report = new StiReport();


            List <Producto> productos;
            List <Ventap>   partidas;

            using (var db = new DymContext())
            {
                if (todasLasFechas)
                {
                    var q = from v in db.Venta
                            join vp in db.Ventap on v.VentaId equals vp.VentaId
                            where (v.Anulada == false && !v.EstadoDocId.Equals("PEN"))
                            select vp;
                    partidas  = q.ToList();
                    productos = db.Producto.ToList();
                }
                else
                {
                    var q = from v in db.Venta
                            join vp in db.Ventap on v.VentaId equals vp.VentaId
                            where (v.Anulada == false && !v.EstadoDocId.Equals("PEN") && v.CreatedAt.Date >= inicial.Date && v.CreatedAt.Date <= final.Date)
                            select vp;
                    partidas  = q.ToList();
                    productos = db.Producto.ToList();
                }
            }
            decimal subtotalvp = 0, impuestovp = 0, totalvp = 0;
            decimal subtotalcp = 0, impuestocp = 0, totalcp = 0;

            decimal subtotalvt = 0, impuestovt = 0, totalvt = 0;
            decimal subtotalct = 0, impuestoct = 0, totalct = 0;

            foreach (var p in partidas)
            {
                var prod = productoController.SelectOne(p.ProductoId.Trim());

                //Importe parcial venta
                subtotalvp = p.SubTotal;
                impuestovp = p.ImporteImpuesto1 + p.ImporteImpuesto2;
                totalvp    = subtotalvp + impuestovp;

                //Importe pacial costo
                impuestocp  = 0;
                subtotalcp  = p.Cantidad * prod.PrecioCompra;
                impuestocp  = subtotalcp * Ambiente.GetTasaImpuesto(prod.Impuesto1Id);
                impuestocp += subtotalcp * Ambiente.GetTasaImpuesto(prod.Impuesto2Id);
                totalcp     = subtotalcp + impuestocp;

                //Sumar totales

                subtotalvt += subtotalvp;
                impuestovt += impuestovp;
                totalvt    += totalvp;

                subtotalct += subtotalcp;
                impuestoct += impuestocp;
                totalct    += totalcp;
            }

            report.Load(@"C:\Dympos\Formatos\VentasAcosto.mrt");
            report.Compile();
            report["creador"]  = Ambiente.LoggedUser.UsuarioId;
            report["subv"]     = subtotalvt;
            report["impv"]     = impuestovt;
            report["totv"]     = totalvt;
            report["subc"]     = subtotalct;
            report["impc"]     = impuestoct;
            report["totc"]     = totalct;
            report["utilidad"] = totalvt - totalct;
            if (todasLasFechas)
            {
                report["inicial"] = null;
                //report["final"] = null;
            }
            else
            {
                report["inicial"] = inicial.ToString("dd-MM-yyyy");
                report["final"]   = final.ToString("dd-MM-yyyy");
            }

            report.Show();
        }
Пример #9
0
        internal static void Ventas()
        {
            StiReport report = new StiReport();

            try
            {
                using (var form = new FrmParamData())
                {
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        using (var db = new DymContext())
                        {
                            if (form.TodasLasFechas)
                            {
                                var q =
                                    from v in db.Venta
                                    join c in db.Cliente on v.ClienteId equals c.ClienteId
                                    where v.EstadoDocId.Equals("CON") && v.Anulada == false
                                    select new
                                {
                                    v.VentaId,
                                    c.RazonSocial,
                                    c.Negocio,
                                    v.CreatedAt,
                                    v.CreatedBy,
                                    v.SubTotal,
                                    v.Impuesto,
                                    v.Total,
                                    v.TipoDocId,
                                    v.NoRef
                                };
                                report.Load(FVentas);
                                report.Compile();
                                report["creador"] = Ambiente.LoggedUser.UsuarioId;
                                report["inicial"] = null;
                                // report["final"] = null;
                                report.Dictionary.DataSources.Clear();
                                report.RegBusinessObject("ventas", "ventas", q.ToList());
                                report.Dictionary.Synchronize();

                                //report.Design();
                                //report.Save(FVentas);
                                report.Show(true);
                            }
                            else
                            {
                                var q =
                                    from v in db.Venta
                                    join c in db.Cliente on v.ClienteId equals c.ClienteId
                                    where v.EstadoDocId.Equals("CON") && v.Anulada == false &&
                                    v.CreatedAt.Date >= FrmParamData.Inicial.Date && v.CreatedAt.Date <= FrmParamData.Final.Date
                                    select new
                                {
                                    v.VentaId,
                                    c.RazonSocial,
                                    c.Negocio,
                                    v.CreatedAt,
                                    v.CreatedBy,
                                    v.SubTotal,
                                    v.Impuesto,
                                    v.Total,
                                    v.TipoDocId,
                                    v.NoRef
                                };
                                report.Load(FVentas);
                                report.Compile();
                                report["creador"] = Ambiente.LoggedUser.UsuarioId;
                                report["inicial"] = FrmParamData.Inicial.Date;
                                report["final"]   = FrmParamData.Final.Date;
                                report.Dictionary.DataSources.Clear();
                                report.RegBusinessObject("ventas", "ventas", q.ToList());
                                report.Dictionary.Synchronize();

                                //report.Design();
                                //report.Save(FVentas);
                                report.Show(true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.Message);
            }
        }
Пример #10
0
        internal static void VentasDetallada()
        {
            StiReport report = new StiReport();

            try
            {
                using (var form = new FrmParamData())
                {
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        using (var db = new DymContext())
                        {
                            if (form.TodasLasFechas)
                            {
                                var q =
                                    from v in db.Venta
                                    join vp in db.Ventap on v.VentaId equals vp.VentaId
                                    join p in db.Producto on vp.ProductoId equals p.ProductoId
                                    where v.EstadoDocId.Equals("CON") && v.Anulada == false
                                    select new
                                {
                                    v.NoRef,
                                    vp.ProductoId,
                                    vp.Cantidad,
                                    vp.Descripcion,
                                    v.VentaId,
                                    v.CreatedAt,
                                    v.CreatedBy,
                                    vp.SubTotal,
                                    Impuesto = (vp.ImporteImpuesto1 + vp.ImporteImpuesto2),
                                    vp.Total
                                };
                                report.Load(FVentasDetallada);
                                report.Compile();
                                report["creador"] = Ambiente.LoggedUser.UsuarioId;

                                report.Dictionary.DataSources.Clear();
                                report.RegBusinessObject("ventas", "ventas", q.ToList());
                                report.Dictionary.Synchronize();

                                //report.Design();
                                //report.Save(FVentasDetallada);
                                report.Show(true);
                            }
                            else
                            {
                                var q =
                                    from v in db.Venta
                                    join vp in db.Ventap on v.VentaId equals vp.VentaId
                                    join p in db.Producto on vp.ProductoId equals p.ProductoId
                                    where v.EstadoDocId.Equals("CON") && v.Anulada == false
                                    select new
                                {
                                    v.NoRef,
                                    vp.ProductoId,
                                    vp.Cantidad,
                                    vp.Descripcion,
                                    v.VentaId,
                                    v.CreatedAt,
                                    v.CreatedBy,
                                    vp.SubTotal,
                                    Impuesto = (vp.ImporteImpuesto1 + vp.ImporteImpuesto2),
                                    vp.Total
                                };

                                report.Load(FVentasDetallada);
                                report.Compile();
                                report["creador"] = Ambiente.LoggedUser.UsuarioId;
                                report["inicial"] = FrmParamData.Inicial.Date;
                                report["final"]   = FrmParamData.Final.Date;
                                report.Dictionary.DataSources.Clear();
                                report.RegBusinessObject("ventas", "ventas", q.ToList());
                                report.Dictionary.Synchronize();

                                //report.Design();
                                //report.Save(FVentasDetallada);
                                report.Show(true);
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Ambiente.Mensaje(ex.Message);
            }
        }
Пример #11
0
        private void CargaGrid()
        {
            switch (Catalogo)
            {
            case (int)Ambiente.TipoBusqueda.Clientes:

                using (var db = new DymContext())
                {
                    if (SoloConLicencia)
                    {
                        Grid1.DataSource = db.Cliente.AsNoTracking().Where(x => x.RazonSocial.Contains(SearchText) || x.Negocio.Contains(SearchText) && (x.IsDeleted == false && x.TieneLicencia == true)).OrderBy(x => x.RazonSocial).
                                           Select(x => new { x.ClienteId, x.RazonSocial, x.Negocio, x.Rfc }).ToList();
                    }
                    else
                    {
                        Grid1.DataSource = db.Cliente.AsNoTracking().Where(x => x.RazonSocial.Contains(SearchText) || x.Negocio.Contains(SearchText) && x.IsDeleted == false).OrderBy(x => x.RazonSocial).
                                           Select(x => new { x.ClienteId, x.RazonSocial, x.Negocio, x.Rfc }).ToList();
                    }
                }


                break;

            case (int)Ambiente.TipoBusqueda.Proveedores:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Proveedor.AsNoTracking().Where(x => x.RazonSocial.Contains(SearchText) || x.Negocio.Contains(SearchText) && x.IsDeleted == false).OrderBy(x => x.RazonSocial).
                                       Select(x => new { x.ProveedorId, x.RazonSocial, x.Negocio }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Productos:

                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Producto.AsNoTracking().Where(
                        x => x.Descripcion.Contains(SearchText) && x.IsDeleted == false).Select(x => new
                    {
                        x.ProductoId,
                        x.Descripcion
                    }).OrderBy(x => x.Descripcion).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Categorias:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Categoria.AsNoTracking().Where(x => x.Nombre.Contains(SearchText) && x.IsDeleted == false).OrderBy(x => x.Nombre).
                                       Select(x => new { x.CategoriaId, x.Nombre }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Laboratorios:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Laboratorio.AsNoTracking().Where(x => x.Nombre.Contains(SearchText) && x.IsDeleted == false).OrderBy(x => x.Nombre).
                                       Select(x => new { x.LaboratorioId, x.Nombre }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Impuestos:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Impuesto.AsNoTracking().Where(x => x.ImpuestoId.Contains(SearchText) && x.IsDeleted == false).OrderBy(x => x.ImpuestoId).
                                       Select(x => new { x.ImpuestoId, x.Tasa }).ToList();
                }

                break;

            case (int)Ambiente.TipoBusqueda.Sustancias:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Sustancia.AsNoTracking().Where(x => x.Nombre.Contains(SearchText) && x.IsDeleted == false).
                                       Select(x => new { x.SustanciaId, x.Nombre }).OrderBy(x => x.Nombre).ToList();
                }

                break;



            case (int)Ambiente.TipoBusqueda.Estaciones:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Estacion.AsNoTracking().Where(x => x.Nombre.Contains(SearchText) && x.IsDeleted == false).OrderBy(x => x.Nombre).
                                       Select(x => new { x.EstacionId, x.Nombre }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.ClavesSat:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.CClaveProdServ.AsNoTracking().Where(x => x.Nombre.Contains(SearchText) && x.IsDeleted == false).OrderBy(x => x.Nombre).
                                       Select(x => new { x.ClaveProdServId, x.Nombre }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Presentaciones:

                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Presentacion.AsNoTracking().Where(x => x.Nombre.Contains(SearchText) && x.IsDeleted == false).OrderBy(x => x.Nombre).
                                       Select(x => new { x.PresentacionId, x.Nombre }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.UnidadesMedida:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.UnidadMedida.AsNoTracking().Where(x => x.Nombre.Contains(SearchText) && x.IsDeleted == false).OrderBy(x => x.Nombre).
                                       Select(x => new { x.UnidadMedidaId, x.Nombre }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Usuarios:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Usuario.AsNoTracking().Where(x => x.Nombre.Contains(SearchText) && x.IsDeleted == false).OrderBy(x => x.Nombre).
                                       Select(x => new { x.UsuarioId, x.Nombre }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.FormaPago:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.FormaPago.AsNoTracking().Where(x => x.Descripcion.Contains(SearchText)).OrderBy(x => x.Descripcion).
                                       Select(x => new { x.FormaPagoId, x.Descripcion }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.MetodoPago:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.CMetodopago.AsNoTracking().Where(x => x.Descripcion.Contains(SearchText)).OrderBy(x => x.Descripcion).
                                       Select(x => new { x.MetodoPagoId, x.Descripcion }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.UsoCDFI:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.CUsocfdi.AsNoTracking().Where(x => x.Descripcion.Contains(SearchText)).OrderBy(x => x.Descripcion).
                                       Select(x => new { x.UsoCfdiid, x.Descripcion }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Tickets:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Venta.AsNoTracking().Where(x => x.NoRef == int.Parse(SearchText) && x.EstadoDocId.Equals("CON")).
                                       Select(x => new { Ticket = x.NoRef, Status = x.EstadoDocId, x.DatosCliente }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Empresas:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Empresa.AsNoTracking().Where(x => x.Nombre.Contains(SearchText) && !(bool)x.IsDeleted).
                                       Select(x => new { ID = x.EmpresaId, x.Nombre }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.RegimenFiscal:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.CRegimenfiscal.AsNoTracking().Where(x => x.Descripcion.Contains(SearchText)).
                                       Select(x => new { ID = x.RegimenFiscalId, x.Descripcion }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Sucursal:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Sucursal.AsNoTracking().Where(x => x.Nombre.Contains(SearchText)).
                                       Select(x => new { ID = x.SucursalId, x.Nombre }).ToList();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Reportes:
                using (var db = new DymContext())
                {
                    Grid1.DataSource = db.Reporte.AsNoTracking().Where(x => x.Nombre.Contains(SearchText)).
                                       Select(x => new { ID = x.ReporteId, x.Nombre }).ToList();
                }
                break;

            default:
                MessageBox.Show("Error, no hay enumerador para catalogo");
                break;
            }
        }
Пример #12
0
        private void SeleccionaRegistro()
        {
            if (Grid1.Rows.Count <= 0)
            {
                DialogResult = DialogResult.Abort;
                Dispose();
                return;
            }


            switch (Catalogo)
            {
            case (int)Ambiente.TipoBusqueda.Clientes:

                using (var db = new DymContext())
                {
                    Cliente = db.Cliente.Where(x => x.ClienteId ==
                                               Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }

                break;

            case (int)Ambiente.TipoBusqueda.Proveedores:
                using (var db = new DymContext())
                {
                    Proveedor = db.Proveedor.Where(x => x.ProveedorId ==
                                                   Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Productos:
                using (var db = new DymContext())
                {
                    Producto = db.Producto.Where(x => x.ProductoId ==
                                                 Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Categorias:
                using (var db = new DymContext())
                {
                    Categoria = db.Categoria.Where(x => x.CategoriaId ==
                                                   Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Laboratorios:
                using (var db = new DymContext())
                {
                    Laboratorio = db.Laboratorio.Where(x => x.LaboratorioId ==
                                                       Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Impuestos:
                using (var db = new DymContext())
                {
                    Impuesto = db.Impuesto.Where(x => x.ImpuestoId ==
                                                 Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Sustancias:
                using (var db = new DymContext())
                {
                    Sustancia = db.Sustancia.Where(x => x.SustanciaId ==
                                                   Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }

                break;



            case (int)Ambiente.TipoBusqueda.Estaciones:
                using (var db = new DymContext())
                {
                    Estacion = db.Estacion.Where(x => x.EstacionId ==
                                                 Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.ClavesSat:
                using (var db = new DymContext())
                {
                    CClaveProdServ = db.CClaveProdServ.Where(x => x.ClaveProdServId ==
                                                             Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Presentaciones:

                using (var db = new DymContext())
                {
                    Presentacion = db.Presentacion.Where(x => x.PresentacionId ==
                                                         Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.UnidadesMedida:
                using (var db = new DymContext())
                {
                    UnidadMedida = db.UnidadMedida.Where(x => x.UnidadMedidaId ==
                                                         Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Usuarios:
                using (var db = new DymContext())
                {
                    Usuario = db.Usuario.Where(x => x.UsuarioId ==
                                               Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.MetodoPago:
                using (var db = new DymContext())
                {
                    MetodoPago = db.CMetodopago.Where(x => x.MetodoPagoId ==
                                                      Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.FormaPago:
                using (var db = new DymContext())
                {
                    FormaPago = db.FormaPago.Where(x => x.FormaPagoId ==
                                                   Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.UsoCDFI:
                using (var db = new DymContext())
                {
                    Usocfdi = db.CUsocfdi.Where(x => x.UsoCfdiid ==
                                                Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString().Trim()).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Tickets:
                using (var db = new DymContext())
                {
                    Venta = db.Venta.Where(x => x.NoRef ==
                                           (int)Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Empresas:
                using (var db = new DymContext())
                {
                    Empresa = db.Empresa.Where(x => x.EmpresaId ==
                                               (int)Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.RegimenFiscal:
                using (var db = new DymContext())
                {
                    Regimenfiscal = db.CRegimenfiscal.Where(x => x.RegimenFiscalId.Equals(
                                                                Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value.ToString())).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Sucursal:
                using (var db = new DymContext())
                {
                    Sucursal = db.Sucursal.Where(x => x.SucursalId == (int)Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value).FirstOrDefault();
                }
                break;

            case (int)Ambiente.TipoBusqueda.Reportes:
                using (var db = new DymContext())
                {
                    Reporte = db.Reporte.Where(x => x.ReporteId == (int)Grid1.Rows[Grid1.CurrentCell.RowIndex].Cells[0].Value).FirstOrDefault();
                }
                break;

            default:
                MessageBox.Show("Error, no hay enumerador para catalogo");
                break;
            }

            DialogResult = DialogResult.OK;
        }
Пример #13
0
        public static void ActualizaCierresInventario()
        {
            try
            {
                using (var db = new DymContext())
                {
                    var cpendientes1 = db.CierreInventario.Where(x => x.Etapa1Generada == false).ToList();

                    foreach (var c in cpendientes1)
                    {
                        if (c.FechaInicial.Month == DateTime.Now.Month)
                        {
                            if (!c.Etapa1Generada)
                            {
                                foreach (var p in db.Producto.ToList())
                                {
                                    var cierreInventariop = new CierreInventariop();
                                    cierreInventariop.CierreInventarioId = c.CierreInventarioId;
                                    cierreInventariop.ProductoId         = p.ProductoId;
                                    cierreInventariop.Descripcion        = p.Descripcion;
                                    cierreInventariop.InvInicial         = p.Stock;
                                    cierreInventariop.Entradas           = 0;
                                    cierreInventariop.Salidas            = 0;
                                    cierreInventariop.UltimoCosto        = p.UltimoCosto;
                                    cierreInventariop.PrevioVta          = p.Precio1;
                                    cierreInventariop.ValorCosto         = 0;
                                    cierreInventariop.ValorVenta         = 0;
                                    db.Add(cierreInventariop);
                                }
                                c.Etapa1Generada = true;
                                MessageBox.Show("INVENTARIO DE CIERRE GENERADO");
                                db.SaveChanges();
                            }
                        }
                    }

                    var cpendientes2 = db.CierreInventario.Where(x => x.Etapa1Generada == true && x.Etapa2Generada == false).ToList();
                    foreach (var c in cpendientes2)
                    {
                        if (c.FechaProgramacion.Date <= DateTime.Now.Date)
                        {
                            if (!c.Etapa2Generada)
                            {
                                MessageBox.Show("EL SISTEMA INICÍO EL MANTENIMIENTO MENSUAL \n" +
                                                " LE SUPLICAMOS NO CIERRE EL SISTEMA, " +
                                                " INCLUSO SI USTEN NO VE ACTIVIDAD SIMPLEMENTE ESPERE\n" +
                                                " ESTO TOMARÁ UN PAR DE MINUTOS"
                                                , "NO CERRAR EL SISTEMA",
                                                MessageBoxButtons.OK);


                                //****************Nuevo cierre inventario**********************
                                var ncierreInventario = new CierreInventario();
                                //var ini = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                                ncierreInventario.FechaInicial      = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                                ncierreInventario.FechaFinal        = ncierreInventario.FechaInicial.AddMonths(1).AddDays(-1);
                                ncierreInventario.FechaProgramacion = ncierreInventario.FechaFinal.AddDays(1);
                                ncierreInventario.Etapa1Generada    = true;
                                ncierreInventario.Etapa2Generada    = false;
                                ncierreInventario.CreatedAt         = DateTime.Now;
                                ncierreInventario.CreatedBy         = "SYS";
                                ncierreInventario.EstacionId        = "SYS";
                                db.Add(ncierreInventario);
                                // db.SaveChanges();

                                var productos = db.Producto.ToList();
                                foreach (var pr in productos)
                                {
                                    var cierreInventariop = new CierreInventariop();
                                    cierreInventariop.CierreInventarioId = ncierreInventario.CierreInventarioId;
                                    cierreInventariop.ProductoId         = pr.ProductoId;
                                    cierreInventariop.Descripcion        = pr.Descripcion;
                                    cierreInventariop.InvInicial         = pr.Stock;
                                    cierreInventariop.Entradas           = 0;
                                    cierreInventariop.Salidas            = 0;
                                    cierreInventariop.UltimoCosto        = pr.UltimoCosto;
                                    cierreInventariop.PrevioVta          = pr.Precio1;
                                    cierreInventariop.ValorCosto         = 0;
                                    cierreInventariop.ValorVenta         = 0;
                                    db.Add(cierreInventariop);
                                    // db.SaveChanges();
                                }

                                ////////////////////////////////////////////////////////////////


                                Producto p;
                                var      cierreinvp = db.CierreInventariop.Where(x => x.CierreInventarioId == c.CierreInventarioId).ToList();
                                var      mosvInv    = db.MovInv.Where(x => x.CreatedAt >= c.FechaInicial && x.CreatedAt <= c.FechaFinal.AddDays(1)).ToList();
                                foreach (var cp in cierreinvp)
                                {
                                    p = productos.FirstOrDefault(x => x.ProductoId.Equals(cp.ProductoId));
                                    if (p != null)
                                    {
                                        cp.Entradas    = mosvInv.Where(x => x.Es.Equals("E") && !x.ConceptoMovsInvId.Equals("IIN") && x.ProductoId.Equals(p.ProductoId) && x.CreatedAt >= c.FechaInicial && x.CreatedAt <= c.FechaFinal.AddDays(1)).Sum(x => x.Cantidad);
                                        cp.Salidas     = mosvInv.Where(x => x.Es.Equals("S") && x.ProductoId.Equals(p.ProductoId) && x.CreatedAt >= c.FechaInicial && x.CreatedAt <= c.FechaFinal.AddDays(1)).Sum(x => x.Cantidad);
                                        cp.InvFinal    = cp.InvInicial + cp.Entradas - cp.Salidas;
                                        cp.UltimoCosto = p.UltimoCosto;
                                        cp.PrevioVta   = p.Precio1; //ultimo precio venta
                                        cp.Stock       = p.Stock;
                                        cp.ValorCosto  = mosvInv.Where(x => x.Es.Equals("S") && x.ProductoId.Equals(p.ProductoId) && x.CreatedAt >= c.FechaInicial && x.CreatedAt <= c.FechaFinal.AddDays(1)).Sum(x => x.Valor);
                                        cp.ValorVenta  = mosvInv.Where(x => x.Es.Equals("S") && x.ProductoId.Equals(p.ProductoId) && x.CreatedAt >= c.FechaInicial && x.CreatedAt <= c.FechaFinal.AddDays(1)).Sum(x => x.Cantidad * x.PrecioVta);
                                        db.Update(cp);
                                    }
                                }
                                c.Etapa2Generada = true;
                                db.Update(c);
                                db.SaveChanges();


                                MessageBox.Show("INVENTARIO DE CIERRE GENERADO");
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error ActualizaCierresInventario : " + ex.ToString());
            }
        }
Пример #14
0
        public static void InicializaDatabaseDefaultsValues()
        {
            try
            {
                using (var db = new DymContext())
                {
                    var estacion = db.Estacion.FirstOrDefault(x => x.EstacionId == "SYS");
                    if (estacion == null)
                    {
                        estacion                   = new Estacion();
                        estacion.EstacionId        = "SYS";
                        estacion.Nombre            = "DEFAUTL";
                        estacion.CanjearPuntosAuto = false;
                        db.Add(estacion);
                    }

                    var sustancia = db.Sustancia.FirstOrDefault(x => x.SustanciaId == "SYS");
                    if (sustancia == null)
                    {
                        sustancia             = new Sustancia();
                        sustancia.SustanciaId = "SYS";
                        sustancia.Nombre      = "DEFAUTL";
                        db.Add(sustancia);
                    }

                    var categoria = db.Categoria.FirstOrDefault(x => x.CategoriaId == "SYS");
                    if (categoria == null)
                    {
                        categoria             = new Categoria();
                        categoria.CategoriaId = "SYS";
                        categoria.Nombre      = "DEFAUTL";
                        db.Add(categoria);
                    }


                    var presentacion = db.Presentacion.FirstOrDefault(x => x.PresentacionId == "SYS");
                    if (presentacion == null)
                    {
                        presentacion = new Presentacion();
                        presentacion.PresentacionId = "SYS";
                        presentacion.Nombre         = "DEFAUTL";
                        db.Add(presentacion);
                    }
                    var laboratorio = db.Laboratorio.FirstOrDefault(x => x.LaboratorioId == "SYS");
                    if (laboratorio == null)
                    {
                        laboratorio = new Laboratorio();
                        laboratorio.LaboratorioId = "SYS";
                        laboratorio.Nombre        = "DEFAUTL";
                        db.Add(laboratorio);
                    }
                    var impuesto = db.Impuesto.FirstOrDefault(x => x.ImpuestoId == "SYS");
                    if (impuesto == null)
                    {
                        impuesto            = new Impuesto();
                        impuesto.ImpuestoId = "SYS";
                        impuesto.Tasa       = 0;
                        impuesto.CImpuesto  = "002";
                        db.Add(impuesto);
                    }

                    var unidadMedida = db.UnidadMedida.FirstOrDefault(x => x.UnidadMedidaId == "SYS");
                    if (unidadMedida == null)
                    {
                        unidadMedida = new UnidadMedida();
                        unidadMedida.UnidadMedidaId = "SYS";
                        unidadMedida.Nombre         = "DEFAUTL";
                        unidadMedida.UnidadSat      = "H87";
                        db.Add(unidadMedida);
                    }

                    var edodocP = db.EstadoDoc.FirstOrDefault(x => x.EstadoDocId == "PEN");
                    if (edodocP == null)
                    {
                        edodocP             = new EstadoDoc();
                        edodocP.EstadoDocId = "PEN";
                        edodocP.Descripcion = "PENDIENTE";
                        db.Add(edodocP);
                    }
                    var edodocCa = db.EstadoDoc.FirstOrDefault(x => x.EstadoDocId == "CAN");
                    if (edodocCa == null)
                    {
                        edodocCa             = new EstadoDoc();
                        edodocCa.EstadoDocId = "CAN";
                        edodocCa.Descripcion = "CANCELADO";
                        db.Add(edodocCa);
                    }
                    var edodocCo = db.EstadoDoc.FirstOrDefault(x => x.EstadoDocId == "CON");
                    if (edodocCo == null)
                    {
                        edodocCo             = new EstadoDoc();
                        edodocCo.EstadoDocId = "CON";
                        edodocCo.Descripcion = "CONFIRMADO";
                        db.Add(edodocCo);
                    }



                    var clienteSYS = db.Cliente.FirstOrDefault(x => x.ClienteId == "SYS");
                    if (clienteSYS == null)
                    {
                        clienteSYS              = new Cliente();
                        clienteSYS.ClienteId    = "SYS";
                        clienteSYS.Rfc          = "XAXX010101000";
                        clienteSYS.Negocio      = "PUBLICO EN GENERAL";
                        clienteSYS.RazonSocial  = "PUBLICO EN GENERAL";
                        clienteSYS.MetodoPagoId = "PUE";
                        clienteSYS.FormaPagoId  = "01";
                        clienteSYS.UsoCfdiid    = "G01";
                        db.Add(clienteSYS);
                    }

                    var proveedorSYS = db.Proveedor.FirstOrDefault(x => x.ProveedorId == "SYS");
                    if (proveedorSYS == null)
                    {
                        proveedorSYS               = new Proveedor();
                        proveedorSYS.ProveedorId   = "SYS";
                        proveedorSYS.Negocio       = "PROVEEDOR GENERICO";
                        proveedorSYS.RazonSocial   = "PROVEEDOR GENERICO";
                        proveedorSYS.Rfc           = "XAXX010101000";
                        proveedorSYS.DiasCredito   = 0;
                        proveedorSYS.LimiteCredito = 0;
                        proveedorSYS.Saldo         = 0;
                        proveedorSYS.IsDeleted     = false;
                        db.Add(proveedorSYS);
                    }

                    var puntosConfig = db.PuntoConfig.FirstOrDefault();
                    if (puntosConfig == null)
                    {
                        puntosConfig               = new PuntoConfig();
                        puntosConfig.DiasReset     = 30;
                        puntosConfig.TasaDescuento = 0.01m;
                        puntosConfig.Vigente       = true;
                        puntosConfig.IsDeleted     = false;
                        db.Add(puntosConfig);
                    }
                    //01010101
                    var prodSys = db.Producto.FirstOrDefault(x => x.ProductoId.Equals("01010101"));

                    if (prodSys == null)
                    {
                        prodSys                 = new Producto();
                        prodSys.ProductoId      = "01010101";
                        prodSys.CategoriaId     = "SYS";
                        prodSys.PresentacionId  = "SYS";
                        prodSys.LaboratorioId   = "SYS";
                        prodSys.Stock           = 0;
                        prodSys.Descripcion     = "Concepto generico facturable";
                        prodSys.PrecioCompra    = 0;
                        prodSys.PrecioCaja      = 0;
                        prodSys.Precio1         = 0;
                        prodSys.Precio2         = 0;
                        prodSys.Precio3         = 0;
                        prodSys.Precio4         = 0;
                        prodSys.Utilidad1       = 0;
                        prodSys.Utilidad2       = 0;
                        prodSys.Utilidad3       = 0;
                        prodSys.Utilidad4       = 0;
                        prodSys.TieneLote       = false;
                        prodSys.IsDeleted       = false;
                        prodSys.CratedAt        = DateTime.Now;
                        prodSys.UnidadMedidaId  = "SYS";
                        prodSys.ClaveProdServId = "01010101";
                        prodSys.ClaveUnidadId   = "H87";
                        prodSys.ChkCaducidad    = false;
                        prodSys.CratedAt        = DateTime.Now;
                        prodSys.CratedBy        = "JMENDOZAJ";

                        db.Add(prodSys);
                    }



                    /**************ACTUALIZA CONEXION REPORTES**************/
                    var informes = db.Informe.ToList();

                    foreach (var informe in informes)
                    {
                        var stiReport = new StiReport();
                        stiReport.LoadPackedReportFromString(informe.Codigo);
                        stiReport.Dictionary.Databases.Clear();
                        stiReport.Dictionary.Databases.Add(new StiSqlDatabase("Dym", Ambiente.Conexion.StandardSecurityConnectionString()));
                        informe.Codigo = stiReport.SavePackedReportToString();
                        db.Update(informe);
                    }
                    /*******************************************************/


                    Ambiente.InformeTicket = db.Informe.FirstOrDefault(x => x.InformeId.Equals(
                                                                           db.InformeConfiguracion.Where(y => y.Ticket == true)
                                                                           .FirstOrDefault().InformeId));

                    Ambiente.InformeFactura = db.Informe.FirstOrDefault(x => x.InformeId.Equals(
                                                                            db.InformeConfiguracion.Where(y => y.Factura == true)
                                                                            .FirstOrDefault().InformeId));

                    Ambiente.InformeCompra = db.Informe.FirstOrDefault(x => x.InformeId.Equals(
                                                                           db.InformeConfiguracion.Where(y => y.Compra == true)
                                                                           .FirstOrDefault().InformeId));

                    Ambiente.InformeCorte = db.Informe.FirstOrDefault(x => x.InformeId.Equals(
                                                                          db.InformeConfiguracion.Where(y => y.Corte == true)
                                                                          .FirstOrDefault().InformeId));

                    Ambiente.InformeDevCom = db.Informe.FirstOrDefault(x => x.InformeId.Equals(
                                                                           db.InformeConfiguracion.Where(y => y.DevCom == true)
                                                                           .FirstOrDefault().InformeId));

                    Ambiente.InformeInvetarios = db.Informe.FirstOrDefault(x => x.InformeId.Equals(
                                                                               db.InformeConfiguracion.Where(y => y.Inventario == true)
                                                                               .FirstOrDefault().InformeId));

                    Ambiente.InformeCierresInv = db.Informe.FirstOrDefault(x => x.InformeId.Equals(
                                                                               db.InformeConfiguracion.Where(y => y.CierresInv == true)
                                                                               .FirstOrDefault().InformeId));


                    if (Ambiente.InformeTicket == null)
                    {
                        Ambiente.Mensaje("!Advertencia! El formato  o regla  de impresión de ticket no existe, esto causará problemas");
                    }

                    if (Ambiente.InformeFactura == null)
                    {
                        Ambiente.Mensaje("!Advertencia! El formato o regla  de impresión de factura no existe, esto causará problemas");
                    }

                    if (Ambiente.InformeCompra == null)
                    {
                        Ambiente.Mensaje("!Advertencia! El formato o regla  de impresión  de compra no existe, esto causará problemas");
                    }

                    if (Ambiente.InformeDevCom == null)
                    {
                        Ambiente.Mensaje("!Advertencia! El formato o regla  de impresión  de devcom no existe, esto causará problemas");
                    }

                    if (Ambiente.InformeCorte == null)
                    {
                        Ambiente.Mensaje("!Advertencia! El formato o regla  de impresión  de corte no existe, esto causará problemas");
                    }

                    if (Ambiente.InformeInvetarios == null)
                    {
                        Ambiente.Mensaje("!Advertencia! El formato o regla  de impresión  de inventarios no existe, esto causará problemas");
                    }

                    if (Ambiente.InformeCierresInv == null)
                    {
                        Ambiente.Mensaje("!Advertencia! El formato o regla  de impresión  de InformeCierresInv no existe, esto causará problemas");
                    }


                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error al inicializar db defautls: " + ex.ToString());
            }

            if (!Ambiente.ServerImgAccesible)
            {
                Ambiente.Mensaje("!Advertencia! Las rutas de red indicadas para llegar al servidor no  pasaron la prueba del 75%. Esto causará rendiento deficiente al acceder a recursos en el server.  valor real: " + Ambiente.ServerImgAccesible);
            }
        }
Пример #15
0
        public static void InicializaDatabaseDefaultsValues()
        {
            try
            {
                using (var db = new DymContext())
                {
                    var estacion = db.Estacion.FirstOrDefault(x => x.EstacionId == "SYS");
                    if (estacion == null)
                    {
                        estacion                   = new Estacion();
                        estacion.EstacionId        = "SYS";
                        estacion.Nombre            = "DEFAUTL";
                        estacion.CanjearPuntosAuto = false;
                        db.Add(estacion);
                    }

                    var sustancia = db.Sustancia.FirstOrDefault(x => x.SustanciaId == "SYS");
                    if (sustancia == null)
                    {
                        sustancia             = new Sustancia();
                        sustancia.SustanciaId = "SYS";
                        sustancia.Nombre      = "DEFAUTL";
                        db.Add(sustancia);
                    }

                    var categoria = db.Categoria.FirstOrDefault(x => x.CategoriaId == "SYS");
                    if (categoria == null)
                    {
                        categoria             = new Categoria();
                        categoria.CategoriaId = "SYS";
                        categoria.Nombre      = "DEFAUTL";
                        db.Add(categoria);
                    }


                    var presentacion = db.Presentacion.FirstOrDefault(x => x.PresentacionId == "SYS");
                    if (presentacion == null)
                    {
                        presentacion = new Presentacion();
                        presentacion.PresentacionId = "SYS";
                        presentacion.Nombre         = "DEFAUTL";
                        db.Add(presentacion);
                    }
                    var laboratorio = db.Laboratorio.FirstOrDefault(x => x.LaboratorioId == "SYS");
                    if (laboratorio == null)
                    {
                        laboratorio = new Laboratorio();
                        laboratorio.LaboratorioId = "SYS";
                        laboratorio.Nombre        = "DEFAUTL";
                        db.Add(laboratorio);
                    }
                    var impuesto = db.Impuesto.FirstOrDefault(x => x.ImpuestoId == "SYS");
                    if (impuesto == null)
                    {
                        impuesto            = new Impuesto();
                        impuesto.ImpuestoId = "SYS";
                        impuesto.Tasa       = 0;
                        impuesto.CImpuesto  = "002";
                        db.Add(impuesto);
                    }

                    var unidadMedida = db.UnidadMedida.FirstOrDefault(x => x.UnidadMedidaId == "SYS");
                    if (unidadMedida == null)
                    {
                        unidadMedida = new UnidadMedida();
                        unidadMedida.UnidadMedidaId = "SYS";
                        unidadMedida.Nombre         = "DEFAUTL";
                        unidadMedida.UnidadSat      = "H87";
                        db.Add(unidadMedida);
                    }

                    var edodocP = db.EstadoDoc.FirstOrDefault(x => x.EstadoDocId == "PEN");
                    if (edodocP == null)
                    {
                        edodocP             = new EstadoDoc();
                        edodocP.EstadoDocId = "PEN";
                        edodocP.Descripcion = "PENDIENTE";
                        db.Add(edodocP);
                    }
                    var edodocCa = db.EstadoDoc.FirstOrDefault(x => x.EstadoDocId == "CAN");
                    if (edodocCa == null)
                    {
                        edodocCa             = new EstadoDoc();
                        edodocCa.EstadoDocId = "CAN";
                        edodocCa.Descripcion = "CANCELADO";
                        db.Add(edodocCa);
                    }
                    var edodocCo = db.EstadoDoc.FirstOrDefault(x => x.EstadoDocId == "CON");
                    if (edodocCo == null)
                    {
                        edodocCo             = new EstadoDoc();
                        edodocCo.EstadoDocId = "CON";
                        edodocCo.Descripcion = "CONFIRMADO";
                        db.Add(edodocCo);
                    }

                    var tipoDocCom = db.TipoDoc.FirstOrDefault(x => x.TipoDocId == "COM");
                    if (tipoDocCom == null)
                    {
                        tipoDocCom             = new TipoDoc();
                        tipoDocCom.TipoDocId   = "COM";
                        tipoDocCom.Descripcion = "COMPRA";
                        db.Add(tipoDocCom);
                    }

                    var tipoDocDvc = db.TipoDoc.FirstOrDefault(x => x.TipoDocId == "DVC");
                    if (tipoDocDvc == null)
                    {
                        tipoDocDvc             = new TipoDoc();
                        tipoDocDvc.TipoDocId   = "DVC";
                        tipoDocDvc.Descripcion = "DEVOLUCIÓN SOBRE COMPRA";
                        db.Add(tipoDocDvc);
                    }

                    var tipoDocDev = db.TipoDoc.FirstOrDefault(x => x.TipoDocId == "DVV");
                    if (tipoDocDev == null)
                    {
                        tipoDocDev             = new TipoDoc();
                        tipoDocDev.TipoDocId   = "DVV";
                        tipoDocDev.Descripcion = "DEVOLUCIÓN SOBRE VENTA";
                        db.Add(tipoDocDev);
                    }

                    var tipoDocFac = db.TipoDoc.FirstOrDefault(x => x.TipoDocId == "FAC");
                    if (tipoDocFac == null)
                    {
                        tipoDocFac             = new TipoDoc();
                        tipoDocFac.TipoDocId   = "FAC";
                        tipoDocFac.Descripcion = "FACTURA";
                        db.Add(tipoDocFac);
                    }

                    var tipoDocRem = db.TipoDoc.FirstOrDefault(x => x.TipoDocId == "REM");
                    if (tipoDocRem == null)
                    {
                        tipoDocRem             = new TipoDoc();
                        tipoDocRem.TipoDocId   = "REM";
                        tipoDocRem.Descripcion = "REMISIÓN";
                        db.Add(tipoDocRem);
                    }

                    var tipoDocTic = db.TipoDoc.FirstOrDefault(x => x.TipoDocId == "TIC");
                    if (tipoDocTic == null)
                    {
                        tipoDocTic             = new TipoDoc();
                        tipoDocTic.TipoDocId   = "TIC";
                        tipoDocTic.Descripcion = "TICKET";
                        db.Add(tipoDocTic);
                    }

                    var tipoDocNc = db.TipoDoc.FirstOrDefault(x => x.TipoDocId == "NC");
                    if (tipoDocNc == null)
                    {
                        tipoDocNc             = new TipoDoc();
                        tipoDocNc.TipoDocId   = "NC";
                        tipoDocNc.Descripcion = "NOTA DE CRÉDITO";
                        db.Add(tipoDocNc);
                    }

                    var tipoDocCxp = db.TipoDoc.FirstOrDefault(x => x.TipoDocId == "CXP");
                    if (tipoDocCxp == null)
                    {
                        tipoDocCxp             = new TipoDoc();
                        tipoDocCxp.TipoDocId   = "CXP";
                        tipoDocCxp.Descripcion = "CUENTA POR PAGAR";
                        db.Add(tipoDocCxp);
                    }
                    var tipoDocTra = db.TipoDoc.FirstOrDefault(x => x.TipoDocId == "TRA");
                    if (tipoDocTra == null)
                    {
                        tipoDocTra             = new TipoDoc();
                        tipoDocTra.TipoDocId   = "TRA";
                        tipoDocTra.Descripcion = "TRASPASO DE MERCANCIAS";
                        db.Add(tipoDocTra);
                    }

                    var clienteSYS = db.Cliente.FirstOrDefault(x => x.ClienteId == "SYS");
                    if (clienteSYS == null)
                    {
                        clienteSYS              = new Cliente();
                        clienteSYS.ClienteId    = "SYS";
                        clienteSYS.Rfc          = "XAXX010101000";
                        clienteSYS.Negocio      = "PUBLICO EN GENERAL";
                        clienteSYS.RazonSocial  = "PUBLICO EN GENERAL";
                        clienteSYS.MetodoPagoId = "PUE";
                        clienteSYS.FormaPagoId  = "01";
                        clienteSYS.UsoCfdiid    = "G01";
                        db.Add(clienteSYS);
                    }
                    var proveedorSYS = db.Proveedor.FirstOrDefault(x => x.ProveedorId == "SYS");
                    if (proveedorSYS == null)
                    {
                        proveedorSYS               = new Proveedor();
                        proveedorSYS.ProveedorId   = "SYS";
                        proveedorSYS.Negocio       = "PROVEEDOR GENERICO";
                        proveedorSYS.RazonSocial   = "PROVEEDOR GENERICO";
                        proveedorSYS.Rfc           = "XAXX010101000";
                        proveedorSYS.DiasCredito   = 0;
                        proveedorSYS.LimiteCredito = 0;
                        proveedorSYS.Saldo         = 0;
                        proveedorSYS.IsDeleted     = false;
                        db.Add(proveedorSYS);
                    }

                    var puntosConfig = db.PuntoConfig.FirstOrDefault();
                    if (puntosConfig == null)
                    {
                        puntosConfig               = new PuntoConfig();
                        puntosConfig.DiasReset     = 30;
                        puntosConfig.TasaDescuento = 0.01m;
                        puntosConfig.Vigente       = true;
                        puntosConfig.IsDeleted     = false;
                        db.Add(puntosConfig);
                    }
                    //01010101
                    var prodSys = db.Producto.FirstOrDefault(x => x.ProductoId.Equals("01010101"));

                    if (prodSys == null)
                    {
                        prodSys                 = new Producto();
                        prodSys.ProductoId      = "01010101";
                        prodSys.CategoriaId     = "SYS";
                        prodSys.PresentacionId  = "SYS";
                        prodSys.LaboratorioId   = "SYS";
                        prodSys.Stock           = 0;
                        prodSys.Descripcion     = "Concepto generico facturable";
                        prodSys.PrecioCompra    = 0;
                        prodSys.PrecioCaja      = 0;
                        prodSys.Precio1         = 0;
                        prodSys.Precio2         = 0;
                        prodSys.Precio3         = 0;
                        prodSys.Precio4         = 0;
                        prodSys.Utilidad1       = 0;
                        prodSys.Utilidad2       = 0;
                        prodSys.Utilidad3       = 0;
                        prodSys.Utilidad4       = 0;
                        prodSys.TieneLote       = false;
                        prodSys.IsDeleted       = false;
                        prodSys.CratedAt        = DateTime.Now;
                        prodSys.UnidadMedidaId  = "SYS";
                        prodSys.ClaveProdServId = "01010101";
                        prodSys.ClaveUnidadId   = "SYS";
                        prodSys.ChkCaducidad    = false;

                        db.Add(prodSys);
                    }


                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Error al inicializar db defautls: " + ex.ToString());
            }
        }
        private void Bgw_DoWork(object sender, DoWorkEventArgs e)
        {
            if (Bgw.CancellationPending)
            {
                e.Cancel = true;
                return;
            }
            else
            {
                try
                {
                    using (var db = new DymContext())
                    {
                        ClavesSat      = db.CClaveProdServ.AsNoTracking().ToList();
                        Laboratorios   = db.Laboratorio.AsNoTracking().ToList();
                        UnidadMedidas  = db.UnidadMedida.AsNoTracking().ToList();
                        Presentaciones = db.Presentacion.AsNoTracking().ToList();
                        Categorias     = db.Categoria.AsNoTracking().ToList();
                    }

                    //Opening an existing Excel file
                    if (Ruta.Length == 0)
                    {
                        Ambiente.Mensaje("Archivo invalido. \nProceso abortado");
                        return;
                    }

                    fi = new FileInfo(Ruta);
                    using (ExcelPackage excelPackage = new ExcelPackage(fi))
                    {
                        //Get a WorkSheet by index. Note that EPPlus indexes are base 1, not base 0!
                        //Get a WorkSheet by name. If the worksheet doesn't exist, throw an exeption

                        workSheet = excelPackage.Workbook.Worksheets[1];

                        var start = workSheet.Dimension.Start;
                        var end   = workSheet.Dimension.End;



                        bool    succes    = false;
                        int     nIntValue = 0;
                        decimal nDecValue = 1m;

                        for (row = start.Row + 1; row <= end.Row; row++)
                        { // Row by row...
                            var producto = new Producto();

                            for (col = start.Column; col <= end.Column; col++)
                            {
                                switch (col)
                                {
                                case 1:
                                    //ProductoId
                                    producto.ProductoId = workSheet.Cells[row, col].Text.Trim();
                                    break;

                                case 2:
                                    //Descripcion
                                    producto.Descripcion = workSheet.Cells[row, col].Text.Trim();
                                    break;

                                case 3:
                                    //Stock
                                    succes = false;
                                    succes = int.TryParse(workSheet.Cells[row, col].Text.Trim(), out nIntValue);
                                    if (succes)
                                    {
                                        producto.Stock = nIntValue;
                                    }
                                    else
                                    {
                                        producto.Stock = 0;
                                    }
                                    break;

                                case 4:
                                    //Contenido
                                    producto.Contenido = workSheet.Cells[row, col].Text.Trim().Length == 0 ? "" : workSheet.Cells[row, col].Text.Trim();
                                    break;

                                case 5:
                                    //CategoriaId
                                    var Categoria = Categorias.FirstOrDefault(x => x.CategoriaId == workSheet.Cells[row, col].Text.Trim());
                                    if (Categoria != null)
                                    {
                                        producto.CategoriaId = Categoria.CategoriaId;
                                    }
                                    else
                                    {
                                        producto.CategoriaId = "SYS";
                                    }


                                    break;

                                case 6:
                                    //PresentacionId
                                    var Presentacion = Presentaciones.FirstOrDefault(x => x.PresentacionId == workSheet.Cells[row, col].Text.Trim());
                                    if (Presentacion != null)
                                    {
                                        producto.PresentacionId = Presentacion.PresentacionId;
                                    }
                                    else
                                    {
                                        producto.PresentacionId = "SYS";
                                    }

                                    break;

                                case 7:
                                    //LaboratorioId
                                    var Laboratorio = Laboratorios.FirstOrDefault(x => x.LaboratorioId == workSheet.Cells[row, col].Text.Trim());
                                    if (Laboratorio != null)
                                    {
                                        producto.LaboratorioId = Laboratorio.LaboratorioId;
                                    }
                                    else
                                    {
                                        producto.LaboratorioId = "SYS";
                                    }

                                    break;

                                case 8:
                                    //Unidades
                                    producto.Unidades = workSheet.Cells[row, col].Text.Trim().Length == 0 ? "" : workSheet.Cells[row, col].Text.Trim();
                                    break;

                                case 9:
                                    //PrecioCompra
                                    succes = false;
                                    succes = decimal.TryParse(workSheet.Cells[row, col].Text.Trim(), out nDecValue);
                                    if (succes)
                                    {
                                        producto.PrecioCompra = nDecValue;
                                    }
                                    else
                                    {
                                        producto.PrecioCompra = 1M;
                                    }

                                    break;

                                case 10:
                                    //PrecioCaja
                                    succes = false;
                                    succes = decimal.TryParse(workSheet.Cells[row, col].Text.Trim(), out nDecValue);
                                    if (succes)
                                    {
                                        producto.PrecioCaja = nDecValue;
                                    }
                                    else
                                    {
                                        producto.PrecioCaja = 1M;
                                    }

                                    break;

                                case 11:
                                    //Precio1
                                    succes = false;
                                    succes = decimal.TryParse(workSheet.Cells[row, col].Text.Trim(), out nDecValue);
                                    if (succes)
                                    {
                                        producto.Precio1 = nDecValue;
                                    }
                                    else
                                    {
                                        producto.Precio1 = 1M;
                                    }

                                    break;

                                case 12:
                                    //Precio2
                                    succes = false;
                                    succes = decimal.TryParse(workSheet.Cells[row, col].Text.Trim(), out nDecValue);
                                    if (succes)
                                    {
                                        producto.Precio2 = nDecValue;
                                    }
                                    else
                                    {
                                        producto.Precio2 = 1M;
                                    }

                                    break;

                                case 13:
                                    //Utilidad1
                                    succes = false;
                                    succes = decimal.TryParse(workSheet.Cells[row, col].Text.Trim(), out nDecValue);
                                    if (succes)
                                    {
                                        producto.Utilidad1 = nDecValue;
                                    }
                                    else
                                    {
                                        producto.Utilidad1 = 1M;
                                    }

                                    break;

                                case 14:
                                    //Utilidad2
                                    succes = false;
                                    succes = decimal.TryParse(workSheet.Cells[row, col].Text.Trim(), out nDecValue);
                                    if (succes)
                                    {
                                        producto.Utilidad2 = nDecValue;
                                    }
                                    else
                                    {
                                        producto.Utilidad2 = 1M;
                                    }

                                    break;

                                case 15:
                                    //TieneLote
                                    if (workSheet.Cells[row, col].Text.Trim().Equals("VERDADERO"))
                                    {
                                        producto.TieneLote = true;
                                    }
                                    else
                                    {
                                        producto.TieneLote = false;
                                    }

                                    break;

                                case 16:
                                    //UnidadMedidaId
                                    var UnidadMedida = UnidadMedidas.FirstOrDefault(x => x.UnidadMedidaId == workSheet.Cells[row, col].Text.Trim());
                                    if (UnidadMedida != null)
                                    {
                                        producto.UnidadMedidaId = UnidadMedida.UnidadMedidaId;
                                    }
                                    else
                                    {
                                        producto.UnidadMedidaId = "SYS";
                                    }

                                    break;

                                case 17:
                                    //ClaveCfdiId

                                    var ClaveProdServ = ClavesSat.FirstOrDefault(x => x.ClaveProdServId == workSheet.Cells[row, col].Text.Trim());
                                    if (ClaveProdServ != null)
                                    {
                                        producto.ClaveProdServId = ClaveProdServ.ClaveProdServId;
                                    }
                                    else
                                    {
                                        producto.ClaveUnidadId = "01010101";
                                    }

                                    break;

                                case 18:
                                    //UnidadCfdi
                                    producto.ClaveUnidadId = workSheet.Cells[row, col].Text.Trim().Length == 0 ? "H87" : workSheet.Cells[row, col].Text.Trim();

                                    break;

                                case 19:
                                    //RutaImg
                                    producto.RutaImg   = workSheet.Cells[row, col].Text.Trim().Length == 0 ? null : (Ambiente.Empresa.DirectorioImg + workSheet.Cells[row, col].Text.Trim());
                                    producto.CratedAt  = DateTime.Now;
                                    producto.UpdatedAt = DateTime.Now;
                                    producto.CratedBy  = Ambiente.LoggedUser.UsuarioId;

                                    if (producto.ProductoId == null || producto.ProductoId.Length == 0)
                                    {
                                        Errores.Add("SE OMITIÓ, " + producto.ProductoId + ", A CAUSA DE FILA: " + row + " COLUMNA: " + col + "\n");
                                    }
                                    else
                                    {
                                        Productos.Add(producto);
                                    }

                                    break;

                                default:
                                    MessageBox.Show("Columna no encontrada");
                                    break;
                                }
                                Bgw.ReportProgress(row);
                            }
                        }
                        excelPackage.Save();
                    }
                    if (new ProductoController().InsertRange(Productos))
                    {
                        exito = true;
                    }
                }
                catch (Exception ex)
                {
                    Ambiente.Mensaje(" ALGO SALIO MAL EN FILA: " + row + " COLUMNA: " + col + "\n" + ex.ToString());
                }
            }
        }