Пример #1
0
        /// <summary>
        /// Carga los clientes desde un servicio web
        /// </summary>
        /// <param name="session">
        ///El identificador de sesion del usuario
        /// </param>
        /// <returns>
        /// true si lo cargo exitosamente, false en caso contrario
        /// </returns>
        public bool Load(string session)
        {
            Clear();

            try
            {
                foreach (ServiceEntity entity in Services.Service.GetAllService(true, session))
                {
                    ComboBoxItemWithEntity item = new ComboBoxItemWithEntity();
                    item.Entity  = entity;
                    item.Content = entity.Name;
                    comboBoxService.Items.Add(item);
                }
            }
            catch (TargetInvocationException)
            {
                return(false);
            }
            catch (EndpointNotFoundException)
            {
                return(false);
            }
            catch (CommunicationException)
            {
                return(false);
            }

            return(true);
        }
        private void comboBoxStore_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            ComboBoxItemWithEntity storeItem        = (comboBoxStore.SelectedItem as ComboBoxItemWithEntity);
            ComboBoxItem           dataModalityItem = (comboBoxDataModality.SelectedItem as ComboBoxItem);

            // Verifica si hay un elemento seleccionado en los combos
            if (storeItem != null && dataModalityItem != null)
            {
                list.Items.Clear();

                StoreEntity store = storeItem.Entity as StoreEntity;

                if (store.Id == 0)
                {
                    // Todas las tiendas están seleccionadas
                    if ((dataModalityItem.Content as string).Equals("Time"))
                    {
                        foreach (DictionaryEntry item in Services.StatisticsAnalyzer.GetCustomersTimeAmount(session))
                        {
                            list.Items.Add(item);
                        }
                    }
                    else
                    {
                        foreach (DictionaryEntry item in Services.StatisticsAnalyzer.GetCustomersAccessAmount(session))
                        {
                            list.Items.Add(item);
                        }
                    }
                }
                else
                {
                    // Se ha seleccionado una tienda
                    List <ServiceEntity> services = new List <ServiceEntity>(Services.Service.GetServiceWhereEqual(ServiceEntity.DBIdStore, store.Id.ToString(), true, session));

                    if ((dataModalityItem.Content as string).Equals("Time"))
                    {
                        foreach (DictionaryEntry item in Services.StatisticsAnalyzer.GetCustomersTimeAmountByStore(store, session))
                        {
                            list.Items.Add(item);
                        }
                    }
                    else
                    {
                        foreach (DictionaryEntry item in Services.StatisticsAnalyzer.GetCustomersAccessAmountByStore(store, session))
                        {
                            list.Items.Add(item);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Carga los clientes desde un servicio web
        /// </summary>
        /// <param name="session">
        /// El identificador de sesión
        /// </param>
        /// <returns>
        /// true si la carga se realizó con éxito
        /// </returns>
        public bool Load(string session)
        {
            this.session = session;

            Clear();

            try
            {
                // Carga una clase auxiliar como primer elemento de la lista.
                ComboBoxItemWithEntity fakeStoreItem = new ComboBoxItemWithEntity();
                fakeStoreItem.Entity    = new StoreEntity();
                fakeStoreItem.Entity.Id = 0;
                (fakeStoreItem.Entity as StoreEntity).Name = "All Stores";

                fakeStoreItem.Content = "All Stores";
                comboBoxStore.Items.Add(fakeStoreItem);

                foreach (StoreEntity storeEntity in Services.Store.GetAllStore(true, session))
                {
                    ComboBoxItemWithEntity item = new ComboBoxItemWithEntity();

                    // Evita referencias circulares de categorías de tiendas
                    foreach (StoreCategoryEntity storeCategory in storeEntity.StoreCategory)
                    {
                        storeCategory.Category.Childs = new Collection <CategoryEntity>();
                        storeCategory.Category.ParentCategory.Childs = new Collection <CategoryEntity>();
                    }

                    // Añade un nuevo elemento a la tienda
                    item.Entity  = storeEntity;
                    item.Content = storeEntity.Name;
                    comboBoxStore.Items.Add(item);
                }
            }
            catch (TargetInvocationException)
            {
                return(false);
            }
            catch (EndpointNotFoundException)
            {
                return(false);
            }
            catch (CommunicationException)
            {
                return(false);
            }
            return(true);
        }