Example #1
0
        protected override void btnEdit_Clicked(object o, EventArgs args)
        {
            if (grid.Selection.Count <= 0)
            {
                MessageError.ShowDialog(Translator.GetString("Please select an operation to edit a payment of."), ErrorSeverity.Error);
                return;
            }

            Payment selectedPayment = entities [grid.Selection [0]];
            string  message;

            if (!BusinessDomain.CanEditPayment(selectedPayment, out message))
            {
                MessageError.ShowDialog(message);
                return;
            }

            selectedId = selectedPayment.Id;
            if (selectedPayment.OperationType == (int)OperationType.AdvancePayment)
            {
                using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                    using (EditNewAdvancePayment dialog = new EditNewAdvancePayment(selectedPayment)) {
                        if (dialog.Run() != ResponseType.Ok || dialog.Payments.Count == 0)
                        {
                            return;
                        }

                        foreach (Payment payment in dialog.Payments)
                        {
                            payment.EditAdvance();
                        }

                        dialog.PrintPayments(dialog.Payments);
                        ReinitializeGrid(true, null);
                        return;
                    }
            }

            Operation operation = GetOperationOfSelectedPayment();

            if (operation == null)
            {
                return;
            }

            using (new DbMasterScope(BusinessDomain.DataAccessProvider))
                using (EditNewPayment dialog = new EditNewPayment(operation)) {
                    if (dialog.Run() != ResponseType.Ok)
                    {
                        return;
                    }

                    operation.CommitPayments();
                    dialog.PrintPayments(dialog.OriginalPayments, operation);
                    ReinitializeGrid(true, null);
                }
        }