예제 #1
0
 public ActionResult SaveToDb(int?articleId)
 {
     try
     {
         if (articleId.HasValue)
         {
             var helper = new IocHelper();
             helper.ToggleToXml(true);
             var artilce = helper.ArticleService.GetArticleById(articleId.Value);
             var group   =
                 helper.GroupService.GetAllGroups(c => c.GroupId).FirstOrDefault(c => c.Groups.Contains(artilce.ArticleName));
             artilce.ArticleGroup = new ArticleGroup {
                 GroupName = group == null ? "Без группы" : group.GroupName
             };
             helper.ToggleToDb(true);
             helper.ArticleService.SaveArticle(artilce);
             helper.ToggleToXml(true);
             return(Json(true));
         }
         else
         {
             throw new Exception("Статьи не существует");
         }
     }
     catch (Exception e)
     {
         throw new HttpException(500, e.Message);
     }
 }
예제 #2
0
        private void EmailSender_OnClick(object sender, RoutedEventArgs e)
        {
            var before = EmailSender.Header;

            try
            {
                EmailSender.Header = "Подаждите идет загрузка";
                IocHelper.ToggleToXml();
                Task task1 = Task.Factory.StartNew(() =>
                {
                    this.Dispatcher.Invoke((Action)(() =>
                    {
                        EmailSender.IsEnabled = false;
                    }));
                    Try(() => EmailService.Instance.SendMail("*****@*****.**", "Говно", "Получи говно"),
                        () => this.Dispatcher.Invoke((Action)(() =>
                    {
                        EmailSender.IsEnabled = true;
                        EmailSender.Header = before.ToString();
                    })));
                });
            }
            catch (Exception ex)
            {
                ShowMessage(ex.Message, "Ошибка", MessageBoxImage.Error);
            }
        }
예제 #3
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);
     }
 }
예제 #4
0
파일: Plan.xaml.cs 프로젝트: fafnir901/fwd
 protected override void OnClosed(EventArgs e)
 {
     if (_isXml)
     {
         IocHelper.ToggleToXml();
     }
     else
     {
         IocHelper.ToggleToDb();
     }
     _isFirstTime = true;
     base.OnClosed(e);
 }
예제 #5
0
 private void SaveToXML_OnClick(object sender, RoutedEventArgs e)
 {
     try
     {
         IocHelper.ToggleToXml();
         SaveArticles();
         JustHelper.ToggleToRightSource(isXml);
     }
     catch (Exception ex)
     {
         ShowMessage(ex.Message, "Ошибка", MessageBoxImage.Error);
         JustHelper.ToggleToRightSource(isXml);
     }
 }
예제 #6
0
        private void XMLChecker_Click(object sender, RoutedEventArgs e)
        {
            isXml = !isXml;
            if (isXml)
            {
                IocHelper.ToggleToXml();
                var result = IocHelper.ArticleService.GetAllArticles(c => c.ArticleName);
                Articles = result == null ? new List <Article>() : result.ToList();
                if (_isGroupsVisible)
                {
                    TreeViewHelper.Instance.FillTreeView(Groups, Articles, ArticleTreeView);
                    TreeViewHelper.Instance.SelectAndExpand(ArticleTreeView, Articles.FirstOrDefault());
                }
                else
                {
                    CreateListOfArticles(Articles);
                }
            }
            else
            {
                IocHelper.ToggleToDb();
                var result = IocHelper.ArticleService.GetAllArticles(c => c.ArticleName);
                Articles = result == null ? new List <Article>() : result.ToList();
                if (_isGroupsVisible)
                {
                    TreeViewHelper.Instance.FillTreeView(Groups, Articles, ArticleTreeView);
                    TreeViewHelper.Instance.SelectAndExpand(ArticleTreeView, Articles.FirstOrDefault());
                }
                else
                {
                    CreateListOfArticles(Articles);
                }
            }
            var message = isXml ? "Контекст переключен на работу с XML" : "Контекст переключен на работу с БД";

            ShowMessage(message);
            InvokeCounter();
            if (!isXml && !_isGroupsVisible)
            {
                SortButton.Visibility = Visibility.Visible;
            }
            else
            {
                SortButton.Visibility = Visibility.Hidden;
            }
        }
예제 #7
0
 public ActionResult ToggleSource(string source)
 {
     try
     {
         var helper = new IocHelper();
         if (source == "db")
         {
             helper.ToggleToDb(true);
         }
         else
         {
             helper.ToggleToXml(true);
         }
         return(Json(IocHelper.CurrentToggle));
     }
     catch (Exception e)
     {
         throw new HttpException(500, e.Message);
     }
 }
예제 #8
0
 public ActionResult SaveToXml(int?articleId)
 {
     try
     {
         if (articleId.HasValue)
         {
             var helper = new IocHelper();
             helper.ToggleToDb(true);
             var artilce = helper.ArticleService.GetArticleById(articleId.Value);
             helper.ToggleToXml(true);
             helper.ArticleService.SaveArticle(artilce);
             helper.ToggleToDb(true);
             return(Json(true));
         }
         else
         {
             throw new Exception("Статьи не существует");
         }
     }
     catch (Exception e)
     {
         throw new HttpException(500, e.Message);
     }
 }
예제 #9
0
        public MainWindow()
        {
            InitializeComponent();
            Remove.IsEnabled      = false;
            Edit.IsEnabled        = false;
            Statisticks.IsEnabled = false;
            ArticlesCountChanged += MainWindow_ArticlesCountChanged;
            FontSizeLabel.Content = Description.FontSize;
            _windowHeight         = (int)this.Height;
            try
            {
                if (!UserConfigService.IsMissingAuth)
                {
                    IocHelper.ToggleToDb();
                    InitListOfArticles();
                }
                else
                {
                    IocHelper.ToggleToXml();
                    isXml = true;
                    InitListOfArticles();
                }
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("Отсутствует подключение к БД.") || ex is InvalidOperationException)
                {
                    MessageBox.Show(string.Format("{0}. Отсутствует подключение к БД. Переключение на контекст XML.", ex.Message), "Ошибка", MessageBoxButton.OK,
                                    MessageBoxImage.Error);
                    IocHelper.ToggleToXml();
                    isXml = true;

                    InitListOfArticles();

                    XMLChecker.IsEnabled = false;
                    SaveToDB.IsEnabled   = false;
                }
                else
                {
                    ShowMessage(ex.Message, "Ошибка", MessageBoxImage.Error);
                }
            }
            Find.Background        = _buttonBackgroundInit;
            Find.Foreground        = _initialForegroundColorBrush;
            Find.MouseEnter       += Button_MouseEnter;
            Find.MouseLeave       += Button_MouseLeave;
            SortButton.Background  = _buttonBackgroundInit;
            SortButton.Foreground  = _initialForegroundColorBrush;
            SortButton.MouseEnter += Button_MouseEnter;
            SortButton.MouseLeave += Button_MouseLeave;
            if (UserConfigService.IsMissingAuth)
            {
                SaveToDB.IsEnabled   = false;
                SaveToXML.IsEnabled  = false;
                SaveToDB.Visibility  = Visibility.Hidden;
                SaveToXML.Visibility = Visibility.Hidden;

                XMLChecker.IsEnabled   = false;
                XMLChecker.Visibility  = Visibility.Hidden;
                UpdateToXml.IsEnabled  = false;
                UpdateToXml.Visibility = Visibility.Hidden;
                Xml.IsEnabled          = false;
                Xml.Visibility         = Visibility.Collapsed;
                Save.IsEnabled         = false;
                Save.Visibility        = Visibility.Collapsed;
                LoginItem.Visibility   = Visibility.Hidden;
            }
            else
            {
                LoginItem.Header = string.Format("Добро пожаловать,{0} {1}", UserConfigService.LoggedUser.FirstName,
                                                 UserConfigService.LoggedUser.LastName);
            }
            //TextBoxStyle.ApplyOldDisplayStyle(Description);
        }