コード例 #1
0
        private void CmdTest_OnClick(object sender, RoutedEventArgs e)
        {
            var bg = new BackgroundWorker() {WorkerReportsProgress = true};
            bg.ProgressChanged += (o, args) => m_waitingWindow.SetState(args.UserState);
            bg.DoWork += (o, args) =>
                {
                    var w = (BackgroundWorker) o;

                    w.ReportProgress(0, "Ожидание");
                    System.Threading.Thread.Sleep(1000);

                    w.ReportProgress(0, "Открытие диалога");
                    var h = this.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
                        {
                            var f = new CustomersSelectionWindow(this);
                            f.ShowDialog();
                        }));
                    h.Wait();

                    w.ReportProgress(0, "Ожидание");
                    System.Threading.Thread.Sleep(1000);
                };
            bg.RunWorkerCompleted += (o, args) =>
                {
                    m_waitingWindow.Close();
                    m_waitingWindow = null;
                    if (args.Error != null)
                    {
                        this.ShowError(args.Error.Message);
                    }
                };
            bg.RunWorkerAsync();

            m_waitingWindow = new WaitingWindow(this);
            m_waitingWindow.ShowDialog();
        }
コード例 #2
0
 private void cmdOpenCustomrsList_OnClick(object sender, RoutedEventArgs e)
 {
     var f = new CustomersSelectionWindow(this);
     f.ShowDialog();
 }
コード例 #3
0
        private void btnAddCutomerToProductClickHandler(object sender, RoutedEventArgs e)
        {
            var f = new CustomersSelectionWindow(this);
            f.ShowDialog();
            var selectedCustomer = f.GetSelectedCustomer();
            if (selectedCustomer == null)
            {
                //this.ShowError("Необходимо выбрать минимум одного покупателя из списка.");
                return;
            }
            var order = new Order
                        {
                            Amount = 0,
                            CustomerId = selectedCustomer.Id,
                            Date = DateTime.Now,
                            InitialVkCommentId = 0,
                            ProductId = m_product.Id,
                            Comment = ""
                        };
            var caw = new ChangeAmountWindow(this, order);
            caw.ShowDialog();

            m_bgworker = new BackgroundWorker();
            m_bgworker.DoWork += (o, args) =>
                {
                    var ord = args.Argument as Order;
                    var ordersRepo = Core.Repositories.DbManger.GetInstance().GetOrderRepository();
                    try
                    {
                        var allProductOrders = ordersRepo.GetOrdersForProduct(m_product);
                        if (allProductOrders.Any(productOrder => productOrder.CustomerId == ord.CustomerId))
                        {
                            throw new BgWorkerException("Указанный покупатель уже заказывал данный товар!");
                        }
                    }
                    catch (BgWorkerException)
                    {
                        throw;
                    }
                    catch (Exception)
                    {
                        throw new BgWorkerException("Не удалось получить данные из БД");
                    }
                    try
                    {
                        ordersRepo.Add(order);
                    }
                    catch (Exception)
                    {
                        throw new BgWorkerException("Не удалось сохранить информацию о заказе в БД");
                    }

                    args.Result = new ProductCustomerListViewItem(order, selectedCustomer);
                };
            m_bgworker.RunWorkerCompleted += (o, args) =>
                {
                    if (args.Error != null)
                    {
                        this.ShowError(args.Error.Message);
                        return;
                    }
                    var item = (ProductCustomerListViewItem) args.Result;
                    m_lvi.OrderedAmount += item.SourceOrderInfo.Amount;
                    lvOrderItems.Items.Add(item);
                };

            m_bgworker.RunWorkerAsync(order);
        }