Example #1
0
 private void m_ProcessPayment(object sender, System.DateTime period)
 {
     if (this.m_Request == null)
     {
         Messages.ShowError("ОПЛАТА НЕВОЗМОЖНА. ЗАКРОЙТЕ И ОТКРОЙТЕ ФОРМУ ПЛАТЕЖЕЙ");
     }
     else
     {
         lock (LockProcessPayment)
         {
             PayPaymentMoreFixedSum sum = new PayPaymentMoreFixedSum();
             if (this.m_TotalPaid >= PersonsCashSearchForm.FixedSumm)
             {
                 PersonsCashSearchForm form = new PersonsCashSearchForm();
                 if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                 {
                     base.ParentForm.Close();
                     goto Label_0374;
                 }
                 sum.PersonId = form.SelectPerson.Id;
             }
             PayRequest payment = null;
             bool flag = false;
             try
             {
                 DALSql.ExecuteNonQuery("begin transaction", null);
                 this.m_Request.IsConfirmed = true;
                 this.m_Request.ConfirmedAt = DALSql.GetDatabaseTime();
                 this.m_Request.PaidSumm = this.m_TotalPaid;
                 this.m_Request.RequestTypeFasetId = Mappers.FasetItemMapper.FindByName(FasetsEnum.PaymentOperationType, "Оплата наличными").Id;
                 this.m_Request.IsManualReturn = Settings.Default.CashierReturnMode;
                 PayLocalTransaction transaction = new PayLocalTransaction {
                     RequestId = this.m_Request.Id
                 };
                 transaction.SaveChanges();
                 this.m_Request.ExternalTransactionId = ((long) transaction.Id).ToString();
                 this.m_Request.AgentId = this.m_Agent.Id;
                 this.m_Request.PackNumber = this.m_PackNumber;
                 this.m_Request.PaymentOrderNumber = this.m_OrderNumber;
                 this.m_Request.PaymentOrderDate = this.m_OrderDate;
                 this.m_Request.PaymentOrderPackId = this.m_PaymentOrderPackId;
                 this.m_Request.UseBankrupt = this.chbxUseAccountServiceBankrupts.get_Checked();
                 this.m_Request.NeedServiceCollapse = Settings.Default.NeedServiceCollapse;
                 this.m_Request.SubService = this.m_subService;
                 this.m_Request.SaveChanges();
                 ObjectList<PayRequestCounter> list = this.m_PayRequestCounters.get_DataSource() as ObjectList<PayRequestCounter>;
                 if (list != null)
                 {
                     foreach (PayRequestCounter counter in list)
                     {
                         counter.SaveChanges();
                     }
                 }
                 this.m_Request.ProcessPayment();
                 this.m_Request.ProcessPayment_ValidateSumm();
                 if (this.m_TotalPaid >= PersonsCashSearchForm.FixedSumm)
                 {
                     PayRequest request2 = ObjectWithId.FindById<PayRequest>(this.m_Request.Id);
                     sum.GroupOperationId = request2.GroupOperId;
                     sum.SpPaymentUno = transaction.Id;
                     sum.UserId = User.CurrentUser.Id;
                     sum.Summ = this.m_TotalPaid;
                     sum.SaveChanges();
                 }
                 DALSql.ExecuteNonQuery("commit transaction", null);
                 payment = this.m_Request;
                 this.m_Request = null;
                 if (!Settings.Default.CashierQuestApplyPrintPayment || (System.Windows.Forms.DialogResult.Yes == System.Windows.Forms.MessageBox.Show(null, "ОПЛАТА ПРОВЕДЕНА УСПЕШНО. ПЕЧАТАТЬ КВИТАНЦИЮ?", "ПЕЧАТЬ КВИТАНЦИИ", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Exclamation, System.Windows.Forms.MessageBoxDefaultButton.Button1)))
                 {
                     flag = true;
                 }
                 if (!Settings.Default.CashierReturnMode)
                 {
                     this.m_posView.AddToAccumulatePaySum(payment.PaidSumm, payment.Commission);
                 }
                 else
                 {
                     this.m_posView.AddToAccumulatePaySum(-payment.PaidSumm, -payment.Commission);
                 }
             }
             catch (System.Exception exception)
             {
                 try
                 {
                     DALSql.ExecuteNonQuery("rollback transaction", null);
                 }
                 catch (System.Exception)
                 {
                 }
                 throw new System.ApplicationException("Возникла ошибка при проведении платежа", exception);
             }
             finally
             {
                 this.m_PaymentButton.set_Image(null);
                 if (flag)
                 {
                     this.m_posView.Print(payment, payment, Settings.Default.CashierReturnMode);
                     if (!Settings.Default.CashierReturnMode)
                     {
                         ReceiptReport.ShowDialog(this, payment);
                     }
                 }
                 base.ParentForm.set_DialogResult(System.Windows.Forms.DialogResult.OK);
             }
         Label_0374:;
         }
     }
 }
 private void butOplApply_Click(object sender, System.EventArgs e)
 {
     if (!this.IsBusy)
     {
         this.butOplApply.set_Enabled((bool) !(this.IsBusy = true));
         if (this.m_PrintPOS.IsBusy)
         {
             System.Windows.Forms.MessageBox.Show("Фискальный регистратор занят. " + System.Environment.get_NewLine() + "Дождитесь выполнения операции.");
             this.butOplApply.set_Enabled((bool) !(this.IsBusy = false));
         }
         else
         {
             User currentUser;
             this.Payments_Fill();
             ObjectList<SpPayment> payments = new ObjectList<SpPayment>();
             decimal num = 0M;
             decimal commission = 0M;
             PayPaymentMoreFixedSum sum = new PayPaymentMoreFixedSum();
             foreach (SpPayment payment2 in this.m_payments)
             {
                 if (!(payment2.Summ == 0M))
                 {
                     num += payment2.Summ;
                     commission += payment2.Commission;
                     SpPayment payment = new SpPayment {
                         AccountId = payment2.AccountId,
                         ServiceName = payment2.ServiceName,
                         Summ = payment2.Summ,
                         Commission = 0M
                     };
                     payments.Add(payment);
                 }
             }
             commission = decimal.Round(commission, 2);
             if (payments.get_Count() == 0)
             {
                 this.butOplApply.set_Enabled((bool) !(this.IsBusy = false));
                 throw new System.ApplicationException("Ошибка, нет ни одной услуги для оплаты, проверте суммы оплаты.");
             }
             payments.get_Item(0).Commission = commission;
             string cashierTerminal = Settings.Default.CashierTerminal;
             if (num >= PersonsCashSearchForm.FixedSumm)
             {
                 PersonsCashSearchForm form = new PersonsCashSearchForm();
                 if (form.ShowDialog() == System.Windows.Forms.DialogResult.Cancel)
                 {
                     base.Close();
                     return;
                 }
                 sum.PersonId = form.SelectPerson.Id;
             }
             try
             {
                 currentUser = User.GetCurrentUser();
                 currentUser.GetOrg();
             }
             catch (System.Exception)
             {
                 this.butOplApply.set_Enabled((bool) !(this.IsBusy = false));
                 throw new System.ApplicationException("Ошибка, проверьте настройки пользователя, организаций пункта приема и платежного агента.");
             }
             sum.UserId = currentUser.Id;
             PayLocalTransaction transaction = AccountOther.MakePaymentTry(payments, currentUser.Id, cashierTerminal);
             AccountOther.MakeCommit();
             if (num >= PersonsCashSearchForm.FixedSumm)
             {
                 sum.SpPaymentUno = transaction.Id;
                 sum.Summ = num;
                 sum.SaveChanges();
             }
             this.m_PrintPOS.AddToAccumulatePaySum(num, commission);
             this.m_PrintPOS.PrintPayment(this.m_Accounts.get_Item(0), payments, ((long) transaction.Id).ToString(), false, num, commission, false, delegate {
                 Messages.ShowMessage("Платеж успешно проведен.");
                 this.butOplApply.set_Enabled((bool) !(this.IsBusy = false));
                 base.Close();
             }, delegate {
                 Messages.ShowMessage("Платеж успешно проведен.");
                 this.butOplApply.set_Enabled((bool) !(this.IsBusy = false));
                 base.Close();
             });
         }
     }
 }