Exemplo n.º 1
0
        public MainWindow()
        {
            InitializeComponent();

            KeyUp += WindowKeyPressEventHandler;

            InitializeTemplates();

            log4net.Config.XmlConfigurator.Configure();
            m_settings = RegistrySettings.GetInstance();
            m_logger = log4net.LogManager.GetLogger("ManagerMainWindow");
            m_workersPool = new List<BackgroundWorker>(0);
            m_selectedView = ServiceTreeNodes.None;

            Application.Current.Exit += ApplicationExitEventHandler;

            cbSearchFieldType.Items.Add(new ComboBoxItem()
                {
                    Tag = TableSearchType.Title,
                    Content = "Наименование (Имя)",
                    IsSelected = true

                });
            cbSearchFieldType.Items.Add(new ComboBoxItem()
            {
                Tag = TableSearchType.CodeNumber,
                Content = "Артикул (Код)"
            });

            // создать каталог галереи
            try
            {
                Directory.CreateDirectory(m_settings.GalleryPath);
                Directory.CreateDirectory(m_settings.ReportsPath);
            }
            catch
            {

            }

            FillAlbumsListAsync();
        }
Exemplo n.º 2
0
        private void FillAlbumsListAsync()
        {
            var bg = new BackgroundWorker {WorkerReportsProgress = true, WorkerSupportsCancellation = true};
            bg.ProgressChanged += (sender, args) => SetStatus(args.UserState.ToString());
            bg.DoWork += (sender, args) =>
                {
                    var worker = sender as BackgroundWorker;
                    worker.ReportProgress(0, "Инициализация");
                    DbManger db;
                    try
                    {
                        db = DbManger.GetInstance();
                    }
                    catch (Exception exception)
                    {
                        m_logger.ErrorException(exception);
                        throw new BgWorkerException("Ошибка: Не удалось инициализировать БД");
                    }

                    var albumRepo = db.GetAlbumsRepository();

                    List<Album> albums;
                    try
                    {
                        albums = albumRepo.GetAll();

                    }
                    catch (Exception e)
                    {
                        m_logger.ErrorException(e);
                        throw new BgWorkerException("Не удалось получить список альбомов. Проверьте настройки БД");
                    }

                    albums.Sort((a1, a2) => String.Compare(a1.GetCleanTitle(), a2.GetCleanTitle(), StringComparison.CurrentCultureIgnoreCase));
                    args.Result = albums;
                };
            bg.RunWorkerCompleted += (sender, args) =>
                {
                    AlbumsView.Items.Clear();

                    SelectedAlbum = null;
                    m_selectedView = ServiceTreeNodes.None;

                    if (args.Cancelled) return;
                    if (args.Error != null)
                    {
                        this.ShowError(args.Error.Message);
                        return;
                    }

                    var albums = args.Result as List<Album>;
                    if (albums != null)
                    {
                        var hiddens = m_settings.GetHiddenList();
                        foreach (Album album in albums)
                        {
                            if (hiddens.Contains(album.VkId)) continue;

                            var tvi = CreateTreeItem(album, album.GetCleanTitle(),
                                                     @"pack://*****:*****@"pack://application:,,,/Images/group.png");
                            tvi.Items.Add(usersNode);

                            var prodsNode = CreateTreeItem(ServiceTreeNodes.AlbumProducts, "Товары",
                                                           @"pack://*****:*****@"pack://application:,,,/Images/coins.png");
                            tvi.Items.Add(payNode);

                            AlbumsView.Items.Add(tvi);
                        }
                    }

                    SetStatus();
                };

            bg.RunWorkerAsync();
        }
Exemplo n.º 3
0
        private void AlbumsView_OnSelected(object sender, RoutedEventArgs e)
        {
            e.Handled = false;
            SetStatus();

            HeaderedItemsControl item = null;
            if (e.Source is TextBlock)
            {
                var panel = (e.Source as TextBlock).Parent as StackPanel;
                if (panel == null) return;
                item = panel.Parent as HeaderedItemsControl;
            }
            else if (e.Source is TreeViewItem)
            {
                item = e.Source as HeaderedItemsControl;
            }
            else if (e.Source is Image)
            {
                var panel = (e.Source as Image).Parent as StackPanel;
                if (panel == null) return;
                item = panel.Parent as HeaderedItemsControl;
            }
            if (item == null || item.Parent == null) return;

            ClearDetailsView();

            if (item.Tag is Album)
            {
                SelectedAlbum = item.Tag as Album;
            }
            else
            {
                SelectedAlbum = (item.Parent as HeaderedItemsControl).Tag as Album;
            }

            tbSearchBox.Clear();
            if (item.Tag.Equals(ServiceTreeNodes.AlbumProducts))
            {
                m_selectedView = ServiceTreeNodes.AlbumProducts;
                ShowAlbumProductsDetails(SelectedAlbum);
            }
            else if (item.Tag.Equals(ServiceTreeNodes.AlbumCustomers))
            {
                m_selectedView = ServiceTreeNodes.AlbumCustomers;
                ShowAlbumCutomersDetails(SelectedAlbum);
            }
            else if (item.Tag.Equals(ServiceTreeNodes.AlbumPaymets))
            {
                m_selectedView = ServiceTreeNodes.AlbumPaymets;
                ShowAlbumPaymentsDetails(SelectedAlbum);
            }
            else
            {
                m_selectedView = ServiceTreeNodes.None;
            }
        }