private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            // проверки корректности
            String errorText = null;

            if (dpkPaymentDate.SelectedDate == null)
            {
                errorText = "Дата оплаты не указана";
            }
            double amount = 0;

            if (tbxAmount.Text.Length > 0 && !Double.TryParse(tbxAmount.Text, out amount))
            {
                errorText = "Ввеедено некорректное значение для стоимости оплаты";
            }
            if (amount < 0)
            {
                errorText = "Стоимость оплаты не может быть отрицательной";
            }
            if (amount > 0 && tbxPaymentNumber.Text.Length == 0)
            {
                errorText = "Не задан номер счета";
            }

            // изменения
            if (errorText == null)
            {
                using (var context = new HostelModelContainer()) {
                    context.Set(typeof(Occupation)).Attach(occupation);
                    Order   order   = occupation.Order;
                    Payment payment = new Payment()
                    {
                        Order       = order,
                        Amount      = amount,
                        PaymentDate = dpkPaymentDate.SelectedDate.Value,
                        Number      = tbxPaymentNumber.Text
                    };
                    context.PaymentSet.Add(payment);
                    context.SaveChanges();
                }
                Close();
            }
            else
            {
                lblError.Content = errorText;
            }
        }
Beispiel #2
0
        private void BtnOk_Click(object sender, RoutedEventArgs e)
        {
            // проверки корректности
            String errorText = null;

            if (dpkFrom.SelectedDate == null)
            {
                errorText = "Дата заселения не указана";
            }
            if (dpkTo.SelectedDate != null && dpkFrom.SelectedDate != null && dpkFrom.SelectedDate > dpkTo.SelectedDate)
            {
                errorText = "Дата заселения должна быть больше даты выселения";
            }
            double price = 0;

            if (tbxPrice.Text.Length > 0 && !Double.TryParse(tbxPrice.Text, out price))
            {
                errorText = "Ввеедено некорректное значение для цены";
            }
            if (price < 0)
            {
                errorText = "Цена не может быть отрицательной";
            }
            if (price > 0 && tbxOrderNumber.Text.Length == 0)
            {
                errorText = "Не задан номер счета";
            }
            if (price > 0 && dpkOrder.SelectedDate == null)
            {
                errorText = "Не задана дата платежа";
            }
            if (price == 0 && payments > 0)
            {
                errorText = "Нельзя удалить счет по которому есть платежи";
            }

            // изменения
            if (errorText == null)
            {
                using (var context = new HostelModelContainer()) {
                    context.Set(typeof(Occupation)).Attach(occupation);
                    occupation.FromDate = dpkFrom.SelectedDate.Value;
                    occupation.ToDate   = dpkTo.SelectedDate;

                    Order order = occupation.Order;
                    if (price > 0)
                    {
                        if (order == null)
                        {
                            order = new Order()
                            {
                                Ocupation = occupation
                            };
                            context.OrderSet.Add(order);
                        }
                        order.Price     = price;
                        order.OrderDate = dpkOrder.SelectedDate.Value;
                        order.Number    = tbxOrderNumber.Text;
                    }

                    if (order != null && price == 0)
                    {
                        context.OrderSet.Remove(order);
                    }
                    context.SaveChanges();
                }
                Close();
            }
            else
            {
                lblError.Content = errorText;
            }
        }