Ejemplo n.º 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);
                }
        }
Ejemplo n.º 2
0
        protected override void btnNew_Clicked(object o, EventArgs args)
        {
            Partner partner = null;

            if (BusinessDomain.LoggedUser.LockedPartnerId > 0)
            {
                partner = Partner.GetById(BusinessDomain.LoggedUser.LockedPartnerId);
            }
            else
            {
                using (ChooseEditPartner dialog = new ChooseEditPartner(true, string.Empty))
                    if (dialog.Run() == ResponseType.Ok && dialog.SelectedItems.Length > 0)
                    {
                        partner = dialog.SelectedItems [0];
                    }
            }

            if (partner == null)
            {
                return;
            }

            using (EditNewAdvancePayment dialog = new EditNewAdvancePayment(partner)) {
                if (dialog.Run() != ResponseType.Ok || dialog.Payments.Count <= 0)
                {
                    return;
                }

                BindList <Payment> advances      = dialog.Payments;
                List <Payment>     savedPayments = Payment.DistributeAdvances(advances, partner.Id);
                for (int i = advances.Count - 1; i >= 0; i--)
                {
                    if (advances [i].Sign < 0)
                    {
                        advances.RemoveAt(i);
                    }
                    else
                    {
                        advances [i].CommitAdvance();
                    }
                }

                savedPayments.AddRange(advances);
                if (savedPayments.Count > 0)
                {
                    dialog.PrintPayments(savedPayments);
                }

                ReinitializeGrid(true, null);
            }
        }