Exemple #1
0
        public void ProposeRemainingAmount()
        {
            GridView gridView = (GridView)MainView;

            if (gridView.FocusedRowHandle >= 0)
            {
                ARCustomerPaymentDetailsInfo currentPayment = null;
                if (!AllowMultiplePayment && !string.IsNullOrEmpty(RequiredMethod))
                {
                    currentPayment = CustomerPaymentDetailList.Where(cpd => cpd.ARCustomerPaymentDetailPaymentMethodType == RequiredMethod).FirstOrDefault();
                }
                else
                {
                    currentPayment = (ARCustomerPaymentDetailsInfo)gridView.GetRow(gridView.FocusedRowHandle);
                }

                if (AllowMultiplePayment)
                {
                    decimal amount = 0;
                    foreach (ARCustomerPaymentDetailsInfo objCustomerPaymentDetailsInfo in CustomerPaymentDetailList)
                    {
                        if (objCustomerPaymentDetailsInfo.ARCustomerPaymentDetailPaymentMethodType != currentPayment.ARCustomerPaymentDetailPaymentMethodType)
                        {
                            amount += objCustomerPaymentDetailsInfo.ARCustomerPaymentDetailAmount;
                        }
                    }

                    if (PaymentAmount >= amount)
                    {
                        currentPayment.ARCustomerPaymentDetailAmount = PaymentAmount - amount;
                    }
                }
                else
                {
                    ARCustomerPaymentDetailsInfo previousPayment = CustomerPaymentDetailList.Where(cpd => cpd.ARCustomerPaymentDetailID > 0 &&
                                                                                                   cpd.ARCustomerPaymentDetailAmount > 0).FirstOrDefault();
                    if (previousPayment != null)
                    {
                        currentPayment = previousPayment;
                    }
                    CustomerPaymentDetailList.ForEach(cpd => cpd.ARCustomerPaymentDetailAmount = 0);
                    currentPayment.ARCustomerPaymentDetailAmount = PaymentAmount;
                }
                this.RefreshDataSource();
            }
        }
Exemple #2
0
        protected override void GridView_ValidatingEditor(object sender, DevExpress.XtraEditors.Controls.BaseContainerValidateEditorEventArgs e)
        {
            base.GridView_ValidatingEditor(sender, e);

            GridView gridView = (GridView)sender;

            if (gridView.FocusedColumn.FieldName == "ARCustomerPaymentDetailAmount")
            {
                if (e.Value != null)
                {
                    ARCustomerPaymentDetailsInfo currentPayment = (ARCustomerPaymentDetailsInfo)gridView.GetRow(gridView.FocusedRowHandle);
                    if (!AllowMultiplePayment)
                    {
                        if (CustomerPaymentDetailList.Exists(cpd => cpd.ARCustomerPaymentDetailAmount > 0 && cpd.ARCustomerPaymentDetailPaymentMethodType != currentPayment.ARCustomerPaymentDetailPaymentMethodType))
                        {
                            e.ErrorText = "Không thể thực hiện đa thanh toán!";
                            e.Valid     = false;
                            return;
                        }
                    }
                    decimal amount = 0;
                    foreach (ARCustomerPaymentDetailsInfo objDocumentPaymentDetaisInfo in CustomerPaymentDetailList)
                    {
                        if (objDocumentPaymentDetaisInfo.ARCustomerPaymentDetailPaymentMethodType != currentPayment.ARCustomerPaymentDetailPaymentMethodType)
                        {
                            amount += objDocumentPaymentDetaisInfo.ARCustomerPaymentDetailAmount;
                        }
                    }
                    amount += Convert.ToDecimal(e.Value);
                    if (amount > PaymentAmount)
                    {
                        e.ErrorText = "Tổng tiền không được lớn hơn tiền thanh toán!";
                        e.Valid     = false;
                    }
                }
            }
        }