Example #1
0
        public void LoadData(Action callBack = null)
        {
            // путь к папке с исполняемым файлом программы
            string executionPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            string fileName      = System.IO.Path.Combine(executionPath, "data");

            if (System.IO.File.Exists(fileName))
            {
                ViewModel.IMainViewModel vm = _mainWindow.DataContext as ViewModel.IMainViewModel;

                vm.IsBusy = true;
                vm.Status = "загрузка данных";

                try
                {
                    _mainWindow.Dispatcher.BeginInvoke((Action)(() =>
                    {
                        _mainWindow.TaskbarItemInfo = new System.Windows.Shell.TaskbarItemInfo();
                        _mainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Indeterminate;
                    }));
                    _task = new Task <Data>(() => Serializer.GzJsonDeSerialize(fileName, e => System.Diagnostics.Debugger.Log(0, "ERROR", e.Message)));
                    _task.ContinueWith(t =>
                    {
                        _mainWindow.Dispatcher.BeginInvoke((Action)(() => _mainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Error));
                        MessageBox.Show("Не удалось загрузить ранее сохраненные данные.\n" + App.GetExceptionDetails(t.Exception), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                        _mainWindow.Dispatcher.BeginInvoke((Action)(() => _mainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None));
                        vm.IsBusy = false;
                        vm.Status = String.Empty;
                    }, TaskContinuationOptions.OnlyOnFaulted);
                    _task.ContinueWith(t =>
                    {
                        Settings = t.Result;
                        RaisePropertyChanged("Settings");
                        RaisePropertyChanged("Enterprises");
                        RaisePropertyChanged("Reses");
                        RaisePropertyChanged("FesWithReses");

                        vm.IsBusy = false;
                        vm.Status = String.Empty;
                        _mainWindow.Dispatcher.BeginInvoke((Action)(() => _mainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None));

                        if (callBack != null)
                        {
                            callBack();
                        }
                    }, TaskContinuationOptions.OnlyOnRanToCompletion);
                    _task.Start();
                }
                catch (Exception ex)
                {
#if DEBUG
                    App.ToDebug(ex);
#endif
                }
            }
        }
Example #2
0
        private static void DoGroup(HierarchicalItem field)
        {
            if (field == null)
            {
                return;
            }

            ViewModel.IMainViewModel mainViewModel = TMPApplication.TMPApp.Instance.MainViewModel as ViewModel.IMainViewModel;
            if (mainViewModel == null)
            {
                return;
            }
            ViewModel.IViewModelWithDataView viewModel = mainViewModel.CurrentViewModel as ViewModel.IViewModelWithDataView;
            if (viewModel == null)
            {
                return;
            }

            if (viewModel.View == null)
            {
                return;
            }

            if (viewModel.View.CanSort == false)
            {
                return;
            }

            using (viewModel.View.DeferRefresh())
            {
                GroupingFields = string.Empty;
                viewModel.View.GroupDescriptions.Clear();
                if (field.Name == None)
                {
                    return;
                }

                Stack <string>   stack = new();
                HierarchicalItem item  = field;
                while (item != null)
                {
                    stack.Push(item.Name);
                    item = item.Parent;
                }

                string[] values = stack.ToArray();
                GroupingFields = string.Join(" > ", values.Select(s => s.Replace("_", " ", AppSettings.StringComparisonMethod)));
                foreach (string value in values)
                {
                    viewModel.View.GroupDescriptions.Add(new PropertyGroupDescription(value));
                }
            }
        }
Example #3
0
        // Серилизация и сохранение в файл
        public void SaveData(Action callBack = null)
        {
            // путь к папке с исполняемым файлом программы
            string executionPath = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);
            string fileName      = System.IO.Path.Combine(executionPath, "data");

            ViewModel.IMainViewModel vm = _mainWindow.DataContext as ViewModel.IMainViewModel;

            vm.IsBusy = true;
            vm.Status = "сохранение данных";

            try
            {
                _mainWindow.Dispatcher.BeginInvoke((Action)(() =>
                {
                    _mainWindow.TaskbarItemInfo = new System.Windows.Shell.TaskbarItemInfo();
                    _mainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Indeterminate;
                }));
                var task = new Task(() => Serializer.GzJsonSerialize(Settings, fileName, e => System.Diagnostics.Debugger.Log(0, "ERROR", e.Message)));
                task.ContinueWith(t =>
                {
                    _mainWindow.Dispatcher.BeginInvoke((Action)(() => _mainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.Error));
                    MessageBox.Show("Не удалось сохранить данные." + Environment.NewLine + App.GetExceptionDetails(t.Exception), "Ошибка", MessageBoxButton.OK, MessageBoxImage.Error);
                    _mainWindow.Dispatcher.BeginInvoke((Action)(() => _mainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None));
                    vm.IsBusy = false;
                    vm.Status = String.Empty;
                }, TaskContinuationOptions.OnlyOnFaulted);
                task.ContinueWith(t =>
                {
                    vm.IsBusy = false;
                    vm.Status = String.Empty;
                    _mainWindow.Dispatcher.BeginInvoke((Action)(() => _mainWindow.TaskbarItemInfo.ProgressState = System.Windows.Shell.TaskbarItemProgressState.None));

                    if (callBack != null)
                    {
                        callBack();
                    }
                }, TaskContinuationOptions.OnlyOnRanToCompletion);
                task.Start();
            }
            catch (Exception ex)
            {
#if DEBUG
                App.ToDebug(ex);
#endif
            }
        }