Exemple #1
0
        protected Point GetQueuePosition(AbortableBackgroundWorker item)
        {
            int k = AbortableBackgroundWorker.Queue.IndexOf(item);
            AbortableBackgroundWorker prev;

            if (k < 0)
            {
                prev = AbortableBackgroundWorker.Queue.LastOrDefault();
            }
            else
            {
                prev = k > 0 ? AbortableBackgroundWorker.Queue[k] : null;
            }
            Window mainWindow = this.Owner;

            if (prev != null)
            {
                if (prev.WaitWindow.Top - this.ActualHeight - 40 > 0)
                {
                    return(new Point(prev.WaitWindow.Left, prev.WaitWindow.Top - this.ActualHeight - 40));
                }
                else
                {
                    return(new Point(prev.WaitWindow.Left - ActualWidth, Owner.ActualHeight - this.ActualHeight - 40));
                }
            }
            return(new Point(mainWindow.ActualWidth - this.ActualWidth, Math.Min(Owner.ActualHeight, System.Windows.Forms.Screen.PrimaryScreen.WorkingArea.Height) - this.ActualHeight - 40));
        }
 /// <summary>
 /// Асинхронно выполняет загрузку данных и при ошибках показывает сообщение, иначе если все успешно прошло, выполняет делегат
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="caption"></param>
 /// <param name="argument"></param>
 /// <param name="execCommand"></param>
 /// <param name="workSuccessEnded"></param>
 public static void RunAsyncWithWaitDialog(DependencyObject sender, string caption, object argument, UniDbCommand execCommand, RunWorkerCompletedEventHandler workSuccessEnded)
 {
     AbortableBackgroundWorker.RunAsyncWithWaitDialog(sender, caption,
                                                      (p, pw) =>
     {
         UniDbAdapter a = pw.Argument as UniDbAdapter;
         DataSet ds     = new DataSet();
         a.Fill(ds);
         pw.Result = ds;
     }, argument, execCommand,
                                                      (p, pw) =>
     {
         if (pw.Cancelled)
         {
             return;
         }
         else if (pw.Error != null)
         {
             MessageBox.Show(pw.Error.GetFormattedException(), "Ошибка получения данных");
         }
         else
         {
             workSuccessEnded(p, pw);
         }
     });
 }
        public static void RunAsyncWithWaitDialog(DependencyObject sender, string caption, DoWorkEventHandler dowork,
                                                  object argument, UniDbCommand executingCommand, RunWorkerCompletedEventHandler workComplete, bool inQueue = true)
        {
            AbortableBackgroundWorker bw = new AbortableBackgroundWorker();

            bw.WorkerSupportsCancellation = true;
            bw.WorkerReportsProgress      = true;
            bw.DoWork             += dowork;
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
            bw.RunWorkerCompleted += workComplete;
            bw.ProgressChanged    += Bw_ProgressChanged;
            bw.ExecutingCommand    = executingCommand;
            bw.Argument            = argument;
            bw.InQueue             = inQueue;
            bw.CurrentStatus       = caption;
            WaitWindow f = new WaitWindow(bw);

            f.Owner       = Window.GetWindow(sender);
            bw.waitDialog = f;
            f.Show();

            if (bw.InQueue)
            {
                Queue.Enqueue(bw);
            }
            else
            {
                bw.RunWorkerAsync(argument);
            }
        }
Exemple #4
0
 //private string _contentText;
 public WaitWindow(AbortableBackgroundWorker related_worker = null)
 {
     BackWorker = related_worker;
     InitializeComponent();
     this.DataContext = related_worker;
     if (related_worker != null && related_worker.InQueue)
     {
         this.Loaded += WaitWindow_Loaded;
     }
 }
 /// <summary>
 /// Выгружает рдлс репорт в эксель используя метод Render
 /// </summary>
 /// <param name="sender">окно владелец</param>
 /// <param name="path">путь к отчету RDLC</param>
 /// <param name="SaveFileName">имя для сохранения по умолчанию</param>
 /// <param name="tables"> таблицы для отчета</param>
 /// <param name="r">список параметров для отчета</param>
 public static void RenderToExcel(DependencyObject sender, string path, string SaveFileName, string initDirectory, DataTable[] tables, IEnumerable <ReportParameter> r)
 {
     AbortableBackgroundWorker.RunAsyncWithWaitDialog(sender, "Формирование отчета",
                                                      (bwk, e) =>
     {
         LocalReport f = new LocalReport();
         f.LoadReportDefinition(File.OpenRead(AppLocalPath.CurrentAppPath + @"\Reports\" + path));
         f.DataSources.Clear();
         tables = e.Argument as DataTable[];
         if (tables != null)
         {
             for (int i = 1; i <= tables.Length; ++i)
             {
                 f.DataSources.Add(new ReportDataSource(string.Format("DataSet{0}", i), tables[i - 1]));
             }
         }
         if (r != null)
         {
             f.SetParameters(r);
         }
         e.Result = f.Render("Excel");
     },
                                                      tables, null,
                                                      (bwk, e) =>
     {
         if (e.Cancelled)
         {
             return;
         }
         else
         if (e.Error != null)
         {
             System.Windows.MessageBox.Show(e.Error.Message, "Ошибка формирования отчета");
         }
         else
         {
             try
             {
                 SaveFileDialog sf   = new SaveFileDialog();
                 sf.FileName         = SaveFileName;
                 sf.Filter           = "Файлы Excel|*.xls";
                 sf.InitialDirectory = initDirectory;
                 if (sf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                 {
                     File.WriteAllBytes(sf.FileName, (byte[])e.Result);
                     System.Diagnostics.Process.Start(sf.FileName);
                 }
             }
             catch (Exception ex)
             {
                 System.Windows.MessageBox.Show("Ошибка формирования", ex.Message);
             }
         }
     });
 }
 /// <summary>
 /// Асинхронно выполняет команду и при ошибках показывает сообщение, иначе если все успешно прошло, выполняет делегат
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="caption"></param>
 /// <param name="argument"></param>
 /// <param name="execCommand"></param>
 /// <param name="workSuccessEnded"></param>
 public static void RunAsyncWithWaitDialog(DependencyObject sender, string caption, UniDbCommand execCommand, RunWorkerCompletedEventHandler workSuccessEnded)
 {
     AbortableBackgroundWorker.RunAsyncWithWaitDialog(sender, caption,
                                                      (p, pw) =>
     {
         execCommand.ExecuteNonQuery();
     }, null, execCommand,
                                                      (p, pw) =>
     {
         if (pw.Cancelled)
         {
             return;
         }
         else if (pw.Error != null)
         {
             MessageBox.Show(pw.Error.GetFormattedException(), "Ошибка получения данных");
         }
         else
         {
             workSuccessEnded(p, pw);
         }
     });
 }