示例#1
0
 private void DeleteButton_Click(object sender, RoutedEventArgs e)
 {
     if (EstimateDataGrid.SelectedValue != null)
     {
         EstimateAndService estimateAndService = (EstimateAndService)EstimateDataGrid.SelectedValue;
         string             content            = $"Данная услуга '{estimateAndService.ServiceName}' будет удалена из сметы, продолжить?";
         string             caption            = "Удаление услуги";
         var result = MessageBox.Show(content, caption, MessageBoxButton.YesNo, MessageBoxImage.Question);
         if (result == MessageBoxResult.Yes)
         {
             TotalAmount -= (int)estimateAndService.EstimateFullPrice;
             TotalAmountEstimate.Text = $"Итоговая сумма: {TotalAmount} руб.";
             Contract contract = _context.Contracts.Where(c => c.ID == CurrentContract.ID).FirstOrDefault();
             contract.TotalAmount = TotalAmount;
             _context.Estimates.Remove(_context.Estimates.OrderByDescending(c => c.ID).FirstOrDefault());
             _context.SaveChanges();
             estimatesAndServices.Remove(estimatesAndServices.Where(c => c.EstimateID == estimateAndService.EstimateID).FirstOrDefault());
             EstimateDataGrid.Items.Refresh();
         }
     }
     else
     {
         MessageBox.Show("Выберите услугу в таблице сверху");
     }
 }
        public EstimateForContractWindow(DatabaseContext context, int id)
        {
            InitializeComponent();
            _context   = context;
            this.Title = "Смета для договора №" + id;
            double fullPriceEstimate = 0;
            List <EstimateAndService> estimateAndServices = new List <EstimateAndService>();

            foreach (var estimate in _context.Estimates.Include(t => t.Service).Where(c => c.ContractID == id))
            {
                EstimateAndService estimateAndService = new EstimateAndService
                {
                    ContractID        = estimate.ContractID,
                    EstimateID        = estimate.ID,
                    ServiceName       = estimate.Service.Name,
                    ServiceUnit       = estimate.Service.UnitOfMeasurement,
                    ServicePrice      = estimate.Service.Price,
                    EstimateCount     = estimate.Quantity,
                    EstimateFullPrice = estimate.Service.Price * estimate.Quantity
                };
                estimateAndServices.Add(estimateAndService);
                fullPriceEstimate += estimate.Service.Price * estimate.Quantity;
            }
            EstimateAndServices             = new ObservableCollection <EstimateAndService>(estimateAndServices);
            EstimateForContract.ItemsSource = EstimateAndServices;
            FullPriceEstimate.Text          = "Полная цена за все услуги: " + fullPriceEstimate + "руб.";
        }
示例#3
0
        private void AddButton_Click(object sender, RoutedEventArgs e)
        {
            Service service = (Service)ServiceComboBox.SelectedItem;
            int     count   = 0;

            foreach (var estim in estimatesAndServices)
            {
                if (service.Name == estim.ServiceName)
                {
                    count = 1;
                }
            }
            //Contract contract = new Contract { DateConclusionContract = DateTime.Now, DateOfCompletion = DateTime.Now, TotalAmount = 0, ClientID = client.ID };
            //_context.Contracts.Add(contract);
            //_context.SaveChanges();
            if (count == 0)
            {
                if (Count.Text != "")
                {
                    Estimate estimate = new Estimate {
                        ContractID = CurrentContract.ID, Quantity = Int32.Parse(Count.Text), ServiceID = service.ID
                    };
                    //estimate.Services.Add(service);
                    _context.Estimates.Add(estimate);
                    EstimateAndService estimateAndService = new EstimateAndService
                    {
                        ContractID        = estimate.ContractID,
                        EstimateID        = estimate.ID,
                        ServiceName       = service.Name,
                        ServiceUnit       = service.UnitOfMeasurement,
                        ServicePrice      = service.Price,
                        EstimateCount     = estimate.Quantity,
                        EstimateFullPrice = (service.Price * (double)estimate.Quantity)
                    };
                    TotalAmount += Int32.Parse(TotalSum.Text);
                    TotalAmountEstimate.Text = "Итоговая сумма: " + TotalAmount + "руб.";
                    estimatesAndServices.Add(estimateAndService);
                    EstimateDataGrid.ItemsSource = estimatesAndServices;
                    _context.SaveChanges();

                    EstimateDataGrid.Items.Refresh();

                    TotalSum.Text = "";
                    Unit.Text     = "";
                    Count.Text    = "";
                    ServiceComboBox.SelectedIndex = -1;
                }
                else
                {
                    MessageBox.Show("Введите размер работ!");
                }
            }
            else
            {
                MessageBox.Show("Выбраная работа уже добавлена в смету!");
            }
        }