Ejemplo n.º 1
0
        private void ListOfArticle_OnMouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            try
            {
                ListBoxItem item;
                var         lstItem = sender as ListBox;
                var         elem    = lstItem.InputHitTest(e.GetPosition(lstItem)) as UIElement;

                while (elem != lstItem)
                {
                    if (elem is ListBoxItem)
                    {
                        item = (ListBoxItem)elem;
                        lstItem.SelectedItems.Clear();
                        int id = int.Parse(item.Name.Replace("article_", ""));
                        if (IocHelper.ArticleService == null)
                        {
                            JustHelper.ToggleToRightSource(isXml);
                        }
                        var article = IocHelper.ArticleService.GetArticleById(id);
                        _viewingArticle = article;
                        FillContent(article);
                        CreateMatchingSelection(Finder.Text);
                        item.IsSelected = true;
                        return;
                    }
                    elem = (UIElement)VisualTreeHelper.GetParent(elem);
                }
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message, "Ошибка", MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
 private void UpdateToXml_OnClick(object sender, RoutedEventArgs e)
 {
     try
     {
         Article article;
         if (!_isGroupsVisible)
         {
             article = GetArticlesFromListBox().FirstOrDefault() ?? _viewingArticle;
         }
         else
         {
             article = TreeViewHelper.Instance.GetArticleFromTreeView(ArticleTreeView, Articles) ?? _viewingArticle;
         }
         if (!isXml)
         {
             IocHelper.ToggleToXml();
         }
         if (article == null)
         {
             throw new Exception("Не выбран элемент для обновления.");
         }
         IocHelper.ArticleService.UpdateArticle(article);
         JustHelper.ToggleToRightSource(isXml);
         ShowMessage(string.Format("Статья \"{0}\" успешно обновлена в XML.", article.ArticleName));
     }
     catch (Exception ex)
     {
         ShowMessage(ex.Message, "Ошибка", MessageBoxImage.Error);
         JustHelper.ToggleToRightSource(isXml);
     }
 }
Ejemplo n.º 3
0
 private void SaveToDB_Click(object sender, RoutedEventArgs e)
 {
     try
     {
         IocHelper.ToggleToDb();
         SaveArticles();
         JustHelper.ToggleToRightSource(isXml);
     }
     catch (Exception ex)
     {
         ShowMessage(ex.Message, "Ошибка", MessageBoxImage.Error);
         JustHelper.ToggleToRightSource(isXml);
     }
 }
Ejemplo n.º 4
0
        private void CreateNewArticle()
        {
            _creatableAtricle.ArticleName = Name.Text;
            _creatableAtricle.InitialText = Text.Text;
            _creatableAtricle.Link        = Link.Text;
            _creatableAtricle.AuthorName  = AuthorNameTextBox.Text;

            InitGroups(_creatableAtricle);

            JustHelper.ToggleToRightSource(_isXml);
            IocHelper.ArticleService.SaveArticle(_creatableAtricle);
            _mainWindow.CreatedArticle = _creatableAtricle;
            MessageBox.Show("Статья успешно сохранена", "Информация", MessageBoxButton.OK, MessageBoxImage.Information);
        }
Ejemplo n.º 5
0
        private void Remove_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (
                    MessageBox.Show("Вы действительно хотите удалить статьи?", "Сообщение", MessageBoxButton.YesNo,
                                    MessageBoxImage.Question) == MessageBoxResult.Yes)
                {
                    IEnumerable <Article> articles;
                    if (_isGroupsVisible)
                    {
                        articles = new List <Article>();
                        var res = TreeViewHelper.Instance.GetArticleFromTreeView(ArticleTreeView, Articles);
                        if (res == null)
                        {
                            var group = TreeViewHelper.Instance.GetGroupFromTreeView(ArticleTreeView, Articles);
                            var arts  = group.Articles;
                            var art   = articles.ToList();
                            art.AddRange(arts);
                            articles = art;

                            IocHelper.GroupService.DeleteGroup(group);
                            Groups.Remove(Groups.First(c => c.GroupName == group.GroupName));
                            JustHelper.ToggleToRightSource(isXml);
                        }
                        else
                        {
                            var art = articles.ToList();
                            art.Add(res);
                            articles = art;
                        }
                    }
                    else
                    {
                        articles = GetArticlesFromListBox();
                    }
                    if (articles != null && articles.Any())
                    {
                        IocHelper.ArticleService.DeleteManyArticles(articles, IocHelper.GroupService);
                    }
                    else if (_viewingArticle != null)
                    {
                        var lst = new List <Article>
                        {
                            _viewingArticle
                        };

                        IocHelper.ArticleService.DeleteManyArticles(lst, IocHelper.GroupService);
                        ShowMessage(string.Format("Статья \"{0}\" успешно удалена.", _viewingArticle.ArticleName));

                        Articles.Remove(_viewingArticle);
                        CreateListOfArticles(Articles);
                        ListOfArticle.Items.Refresh();
                        InvokeCounter();
                    }

                    if (articles != null && articles.Any())
                    {
                        string joinedNames = string.Join(",", articles.Select(c => c.ArticleName));
                        ShowMessage(string.Format("Статьи \"{0}\" успешно удалены.", joinedNames));
                        var forRemovinf = Article.Clone(articles);
                        foreach (var article in forRemovinf)
                        {
                            var index = Articles.IndexOf(Articles.Find(c => c.ArticleId == article.ArticleId));
                            Articles.RemoveAt(index);
                        }
                        if (_isGroupsVisible)
                        {
                            TreeViewHelper.Instance.FillTreeView(Groups, Articles, ArticleTreeView);
                            TreeViewHelper.Instance.SelectAndExpand(ArticleTreeView, Articles.FirstOrDefault());
                        }
                        else
                        {
                            CreateListOfArticles(Articles);
                        }
                        InvokeCounter();
                    }

                    JustHelper.ToggleToRightSource(isXml);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 6
0
 private void ToggleToRightSource()
 {
     JustHelper.ToggleToRightSource(_isXml);
 }