private OfertaCollections GenerarListadoDesactivo(List <DALC.OFERTA> listaDALC)
        {
            OfertaCollections lista = new OfertaCollections();

            foreach (var item in listaDALC)
            {
                if (item.ESTADO_OFERTA == "0")
                {
                    Oferta of = new Oferta();
                    of.IdOferta          = (int)item.ID_OFERTA;
                    of.ImagenOferta      = item.IMAGEN_OFERTA;
                    of.MinProductos      = (int)item.MIN_PRODUCTO;
                    of.MaxProductos      = (int)item.MAX_PRODUCTO;
                    of.EstadoOferta      = Convert.ToChar(item.ESTADO_OFERTA);
                    of.PrecioOferta      = (int)item.PRECIO_DESPUES;
                    of.PrecioAntes       = (int)item.PRECIO_ANTES;
                    of.FechaOferta       = item.FECHA_OFERTA;
                    of.IdSucursal        = (int)item.SUCURSALES_ID;
                    of.CategoriaIdOferta = (int)item.CATEGORIA_OFERTA_ID;
                    of.Nombre            = item.NOMBRE;
                    of.Descripcion       = item.DESCRIPCION;
                    of.Selec             = false;

                    lista.Add(of);
                }
            }
            return(lista);
        }
        private OfertaCollections GenerarListadoActivoWeb()
        {
            DALC.QueOfrecesEntities ctx = new DALC.QueOfrecesEntities();

            var listaDALC = from o in ctx.OFERTA
                            where o.ESTADO_OFERTA == "1"
                            select o;

            OfertaCollections lista = new OfertaCollections();

            foreach (var item in listaDALC)
            {
                Oferta of = new Oferta();
                of.IdOferta          = (int)item.ID_OFERTA;
                of.ImagenOferta      = item.IMAGEN_OFERTA;
                of.MinProductos      = (int)item.MIN_PRODUCTO;
                of.MaxProductos      = (int)item.MAX_PRODUCTO;
                of.EstadoOferta      = Convert.ToChar(item.ESTADO_OFERTA);
                of.PrecioOferta      = (int)item.PRECIO_DESPUES;
                of.PrecioAntes       = (int)item.PRECIO_ANTES;
                of.FechaOferta       = item.FECHA_OFERTA;
                of.IdSucursal        = (int)item.SUCURSALES_ID;
                of.CategoriaIdOferta = (int)item.CATEGORIA_OFERTA_ID;
                of.Nombre            = item.NOMBRE;
                of.Descripcion       = item.DESCRIPCION;
                of.Selec             = true;

                lista.Add(of);
            }
            return(lista);
        }
        public OfertaCollections(string json)
        {
            DataContractJsonSerializer serializador = new DataContractJsonSerializer(typeof(OfertaCollections));
            MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json));

            OfertaCollections list = (OfertaCollections)serializador.ReadObject(stream);

            this.AddRange(list);
        }
Exemple #4
0
        private async void btnBuscar_Click(object sender, RoutedEventArgs e)
        {
            ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
            string json = proxy.ReadAllOfertas(mainwindow.RetailActual.IdRetail);

            Core.Negocio.OfertaCollections collOf = new Core.Negocio.OfertaCollections(json);

            Core.Negocio.OfertaCollections collOfer = new Core.Negocio.OfertaCollections();

            if (txtBuscar.Text == "")
            {
                dataGridOferta.ItemsSource = collOf;
            }
            else
            {
                try
                {
                    foreach (var item in collOf)
                    {
                        if (txtBuscar.Text.Equals(item.Nombre))
                        {
                            collOfer.Add(item);
                        }
                    }

                    if (collOfer.Count == 0)
                    {
                        await this.ShowMessageAsync("Fallo", "No se encontro la oferta");
                    }
                    else
                    {
                        dataGridOferta.ItemsSource = collOfer;
                    }
                }
                catch (Exception)
                {
                    await this.ShowMessageAsync("Fallo", "No se encontro la oferta");
                }
            }
        }
        private OfertaCollections GenerarListado(int idRetail)
        {
            DALC.QueOfrecesEntities ctx = new DALC.QueOfrecesEntities();

            var listaDALC = from o in ctx.OFERTA
                            join s in ctx.SUCURSALES on o.SUCURSALES_ID equals s.ID_SUCURSAL
                            where s.RETAIL_ID == idRetail
                            select o;

            OfertaCollections lista = new OfertaCollections();

            foreach (var item in listaDALC)
            {
                Oferta of = new Oferta();
                of.IdOferta          = (int)item.ID_OFERTA;
                of.ImagenOferta      = item.IMAGEN_OFERTA;
                of.MinProductos      = (int)item.MIN_PRODUCTO;
                of.MaxProductos      = (int)item.MAX_PRODUCTO;
                of.EstadoOferta      = Convert.ToChar(item.ESTADO_OFERTA);
                of.PrecioOferta      = (int)item.PRECIO_DESPUES;
                of.PrecioAntes       = (int)item.PRECIO_ANTES;
                of.FechaOferta       = item.FECHA_OFERTA;
                of.IdSucursal        = (int)item.SUCURSALES_ID;
                of.CategoriaIdOferta = (int)item.CATEGORIA_OFERTA_ID;
                of.Nombre            = item.NOMBRE;
                of.Descripcion       = item.DESCRIPCION;
                if (of.EstadoOferta == '1')
                {
                    of.Selec = true;
                }
                else
                {
                    of.Selec = false;
                }

                lista.Add(of);
            }
            return(lista);
        }
        private async void btnBusquedaCO_Click(object sender, RoutedEventArgs e)
        {
            var listasu = dgSucCO.Items.OfType <Sucursal>();
            var listaCa = dgCat.Items.OfType <CategoriaOferta>();

            ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
            string json = proxy.ReadAllOfertas(mainwindow.RetailActual.IdRetail);

            Core.Negocio.OfertaCollections collof = new Core.Negocio.OfertaCollections(json);
            var  colloff = new OfertaCollections();
            var  colmost = new OfertaCollections();
            bool pas     = false;

            //primer filtro

            if (txtBusquedaCO.Text.Length > 0)
            {
                foreach (var item in collof)
                {
                    if (item.Nombre.ToUpper().Contains(txtBusquedaCO.Text))
                    {
                        colloff.Add(item);
                    }
                }
                colmost = colloff;
            }
            else
            {
                colloff = collof;
                colmost = colloff;
            }
            // segundo filtro

            collof  = colmost;
            colloff = new OfertaCollections();
            if (cbPublicadasCO.IsChecked == true)
            {
                foreach (var item in collof)
                {
                    if (item.EstadoOferta.Equals('1'))
                    {
                        colloff.Add(item);
                    }
                }
                colmost = colloff;
            }
            else
            {
                foreach (var item in collof)
                {
                    if (item.EstadoOferta.Equals('0'))
                    {
                        colloff.Add(item);
                    }
                }
                colmost = colloff;
            }
            collof  = colmost;
            colloff = new OfertaCollections();
            //tercer filtro
            foreach (var item in listasu)
            {
                if (item.Selec == true)
                {
                    pas = true;
                }
            }

            if (pas)
            {
                foreach (var item in listasu)
                {
                    if (item.Selec == true)
                    {
                        foreach (var item2 in collof)
                        {
                            if (item.IdSucursal == item2.IdSucursal)
                            {
                                colloff.Add(item2);
                            }
                        }
                    }
                }
                colmost = colloff;
            }
            else
            {
                collof = colmost;
            }

            pas = false;

            //Cuarto filtro
            foreach (var item in listaCa)
            {
                if (item.Selec == true)
                {
                    pas = true;
                }
            }

            if (pas)
            {
                foreach (var item in listaCa)
                {
                    if (item.Selec == true)
                    {
                        foreach (var item2 in collof)
                        {
                            if (item.IdCategoria == item2.CategoriaIdOferta)
                            {
                                colloff.Add(item2);
                            }
                        }
                    }
                }
                colmost = colloff;
            }
            else
            {
                collof = colmost;
            }

            if (colmost.Count() > 0)
            {
                colmost.ToList();
                dgOfertasCO.ItemsSource = colmost;
            }
            else
            {
                await this.ShowMessageAsync("Error", "No hay coincidencias para mostrar");

                LimpiarControles();
            }
        }
        private async void btnBusquedaPu_Click(object sender, RoutedEventArgs e)
        {
            ServiceReference1.Service1Client proxy = new ServiceReference1.Service1Client();
            string json = proxy.ReadAllOfertas(mainwindow.RetailActual.IdRetail);

            Core.Negocio.OfertaCollections collof = new Core.Negocio.OfertaCollections(json);
            var colloff = new OfertaCollections();

            if (txtBusquedaPu.Text.Length > 0)
            {
                if (cbPublicadas.IsChecked == true)
                {
                    foreach (var item in collof)
                    {
                        if (item.Nombre.ToUpper().Contains(txtBusquedaPu.Text.ToUpper()) && item.EstadoOferta.Equals('1'))
                        {
                            colloff.Add(item);
                        }
                    }

                    if (colloff.Count > 0)
                    {
                        colloff.ToList();
                        dgOfertas.ItemsSource = colloff;
                    }
                    else
                    {
                        await this.ShowMessageAsync("Error", "No hay ofertas publicadas para mostrar");
                    }
                }
                else
                {
                    foreach (var item in collof)
                    {
                        if (item.EstadoOferta.Equals('0') && item.Nombre.ToUpper().Contains(txtBusquedaPu.Text.ToUpper()))
                        {
                            colloff.Add(item);
                        }
                    }

                    if (colloff.Count > 0)
                    {
                        colloff.ToList();
                        dgOfertas.ItemsSource = colloff;
                    }
                    else
                    {
                        await this.ShowMessageAsync("Error", "No hay ofertas no publicadas para mostrar");
                    }
                }
            }
            else
            {
                if (cbPublicadas.IsChecked == true)
                {
                    foreach (var item in collof)
                    {
                        if (item.EstadoOferta.Equals('1'))
                        {
                            colloff.Add(item);
                        }
                    }

                    if (colloff.Count > 0)
                    {
                        colloff.ToList();
                        dgOfertas.ItemsSource = colloff;
                    }
                    else
                    {
                        await this.ShowMessageAsync("Error", "No hay ofertas publicadas para mostrar");
                    }
                }
                else
                {
                    foreach (var item in collof)
                    {
                        if (item.EstadoOferta.Equals('0'))
                        {
                            colloff.Add(item);
                        }
                    }

                    if (colloff.Count > 0)
                    {
                        colloff.ToList();
                        dgOfertas.ItemsSource = colloff;
                    }
                    else
                    {
                        await this.ShowMessageAsync("Error", "No hay ofertas no publicadas para mostrar");
                    }
                }
            }
        }