Exemplo n.º 1
0
        public BalanceSubstationView(IBalance balance)
        {
            _balance = balance;

            _task = new Task(() =>
            {
                //System.Threading.Thread.Sleep(5000);
                table.Dispatcher.BeginInvoke(
                    new Action(delegate()
                {
                    table.BeginInit();
                    Create_tableColumns();
                    //ate = State.Idle;
                    table.ItemsSource = _balance.Items;
                    table.EndInit();
                    IsBusy = false;
                }));
            });

            _task.ContinueWith((t) =>
            {
                //State = State.Idle;
                EmcosSiteWrapperApp.LogError("Просмотр баланса подстанции - ошибка: " + t.Exception.Message);
                EmcosSiteWrapperApp.ShowError("Произошла ошибка.\n" + t.Exception.Message);
            }, TaskContinuationOptions.OnlyOnFaulted);

            InitializeComponent();

            _task.Start();

            DataContext          = this;
            rootGrid.DataContext = _balance;

            _balance.PropertyChanged += Balance_PropertyChanged;
        }
Exemplo n.º 2
0
        private void Export_Click(object sender, RoutedEventArgs e)
        {
            //State = State.Busy;
            //wait.Message = "Пожалуйста, подождите..\nПодготовка отчёта...";
            var task = new System.Threading.Tasks.Task(() =>
            {
                var reportFileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), _balance.Substation.Name + ".xlsx");
                int index          = 0;
                while (System.IO.File.Exists(reportFileName) == true)
                {
                    try
                    {
                        System.IO.File.Delete(reportFileName);
                    }
                    catch (System.IO.IOException)
                    {
                        reportFileName = System.IO.Path.Combine(System.IO.Path.GetTempPath(), _balance.Substation.Name + " " + ++index + ".xlsx");
                    }
                }
                using (var sbe = new Export.SubstationExport(_balance))
                    sbe.Export(reportFileName);

                System.Diagnostics.Process.Start(reportFileName);
                //State = State.Idle;
                //DispatcherExtensions.InUi(() => wait.Message = "Пожалуйста, подождите..\nПодготовка данных.");
            }, System.Threading.Tasks.TaskCreationOptions.AttachedToParent);


            task.ContinueWith((s) =>
            {
                var sb       = new System.Text.StringBuilder();
                Exception ex = s.Exception.Flatten();
                while (ex != null)
                {
                    if (ex.InnerException != null)
                    {
                        sb.AppendLine(ex.InnerException.Message);
                        ex = ex.InnerException;
                    }
                }
                EmcosSiteWrapperApp.LogError("Экспорт балансов подстанций - ошибка: " + sb.ToString());
                DispatcherExtensions.InUi(() => EmcosSiteWrapperApp.ShowError("Произошла ошибка при формировании отчёта.\nОбратитесь к разработчику."));
            }, System.Threading.Tasks.TaskContinuationOptions.OnlyOnFaulted);
            task.Start(System.Threading.Tasks.TaskScheduler.Current);
        }
Exemplo n.º 3
0
 public virtual bool Export(string outputFile)
 {
     CreateHeader();
     CreateBody();
     CreateFooter();
     ChangePageSettings();
     try
     {
         package.SaveAs(new System.IO.FileInfo(outputFile));
         return(true);
     }
     catch (Exception e)
     {
         EmcosSiteWrapperApp.ShowError(e, "Ошибка экспорта данных.\n{0}");
         EmcosSiteWrapperApp.LogException(e);
         return(false);
     }
 }