Click here to Skip to main content
15,922,696 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
good evening..
private void btnAccept_Click(object sender, EventArgs e)
     {
         if (SecurityManager.CheckAuthorization(AccessLevels.Create, SecurityManager.PAYMENT_MANAGEMENT))
         {
             CreditCardPayment cr = new CreditCardPayment();
             CouponPayment coupPay = new CouponPayment();
             ChequePayment chq = new ChequePayment();
             CreditPayment creditpay = new CreditPayment();
             RoomPayment roompay = new RoomPayment();
             if (IsValidate() && totamt >= NetAmount)
             {
                 if (RoomAmount > 0)
                 {
                     if (MessageBox.Show(string.Format("This Bill is being settled to the Room {0}.\nClick 'Yes' to Continue.",
                          ((CheckIn)cmbRoomNo.SelectedItem).Room.Name), "Question", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                          == DialogResult.No)
                         return;
                 }
                 if (cheque > 0)
                 {
                     chq.Cheque_no = txtChequeNo.Text.ToString().Trim();
                     chq.Chq_date = dtpChequeDate.Value;
                     chq.Bank = txtIssueBank.Text.Trim();
                     chq.Issued_by = txtIssuerName.Text.Trim();
                     chequeAmt = cheque;  //(cheque > NetAmount) ? NetAmount : cheque;
                     IsCheque = true;
                 }
                 else
                 {
                     IsCheque = false;
                 }
                 if (creditcard > 0)
                 {
                     cr.Card_no = Convert.ToString(txtCreditCno.Text.Trim());
                     cr.CardHolderName = txtCardHolderName.Text.Trim();
                     cr.Auth_code = Convert.ToString(txtCvc.Text.Trim());
                     cr.Auth_date = dtpAuthDate.Value;
                     cr.Txn_id = "1";
                     if (Common.GetSelectedCCType(cmbCCType) != null)
                         cr.cctypeID = Common.GetSelectedCCType(cmbCCType).ID;
                     IsCreditCard = true;
                     cr.Exp_date = dtpExpireDate.Value;
                 }
                 else
                 {
                     IsCreditCard = false;
                 }
                 if (credit > 0)
                 {
                     creditpay.Comments = txtComments.Text.Trim();
                     if (_Customer != null)
                     {
                         creditpay.CustomerID = _Customer.ID;
                         creditpay.Guest_name = _Customer.Name;
                         if (_Customer.CreditApproved)
                             _Customer.credit_limit_used = _Customer.credit_limit_used.Value + (float)credit;
                     }
                     else if (!HasAcctCreditIntegration && _Customer == null)
                     {
                         creditpay.Guest_name = txtName.Text.Trim();
                         _Customer = new Customer();
                         _Customer.Name = txtName.Text.Trim();
                         _Customer.CreditApproved = false;
                         _Customer.contact_phone = "contact phone";
                     }
                     creditpay.Comments = txtComments.Text.Trim();
                     creditAmt =Math.Round(credit,2);
                     IsCredit = true;
                 }
                 else
                 {
                     IsCredit = false;
                 }
                 if (coupon > 0)
                 {
                     if (Common.GetSelectedCoupon(cmbCouponProvider) != null)
                         coupPay.CouponProviderID = Common.GetSelectedCoupon(cmbCouponProvider).ID;
                     couponAmt =Math.Round(coupon);  //(coupon > NetAmount) ? NetAmount : coupon;
                     IsCoupon = true;
                 }
                 else
                 {
                     IsCoupon = false;
                 }
                 if (Math.Round(RoomAmount) > 0)
                 {
                     roompay.CheckIn_no = Convert.ToString(((CheckIn)cmbRoomNo.SelectedItem).ID);
                     roompay.Room_no = Convert.ToString(((CheckIn)cmbRoomNo.SelectedItem).RoomID);
                     RoomAmt =Math.Round(RoomAmount,2);
                     IsRoomPayment = true;
                 }
                 else
                 {
                     IsRoomPayment = false;
                 }
                 if (Math.Round(cash) > 0)
                 {
                     cashAmt =Math.Round((cash - changeAmt),2);
                     IsCash = true;
                 }
                 if (cheque + creditcard + credit + coupon + RoomAmount >= NetAmount)
                 {
                     IsCash = false;
                 }
                 ReportStatus(PsxMessages.PaymentAcceptAlert);
                 DialogResult res = MessageBox.Show(PsxMessages.PaymentAcceptAlert, "", MessageBoxButtons.OKCancel);
                 if (res == DialogResult.OK)
                 {
                     POSBill pos = (POSBill)gridBillDetails[colPosBill.Index, gridBillDetails.CurrentRow.Index].Value;
                     try
                     {
                         if (_Customer != null)
                         {
                             if (_Customer.ID == 0)
                             {
                                 ServiceManager.AddCustomer(_Customer);
                             }
                             pos.Customer = _Customer;
                         }
                         pos.Tip_amount = (tipAmount > 0) ?Math.Round(tipAmount,2) : 0;
                         pos.Excess_rcpt_amount =Math.Round(excessAmt,2);
                         pos.Comments = _Comments.Trim();
                         pos.IsPrinted = true;
                         using (TransactionScope ts = new TransactionScope())
                         {
                             pos.SettleBill();
                             DateTime transactionTime = ServerTime.Now;
                             if (IsCash) { PaymentManger.MakeCashPayment(pos, (cashAmt), transactionTime); }
                             if (IsCheque) { PaymentManger.MakeChequePayment(pos, chq, (chequeAmt), transactionTime); }
                             if (IsCreditCard) { PaymentManger.MakeCardPayment(pos, cr, (creditcard), transactionTime); }
                             if (IsCoupon) { PaymentManger.MakeCouponPayment(pos, coupPay, (couponAmt), transactionTime); }
                             if (IsCredit)
                             {
                                 PaymentManger.MakeCreditPayment(pos, creditpay, (creditAmt), _Customer, transactionTime);
                                 if (!_Customer.CreditApproved)
                                 {
                                     string GReason = _Customer.Name + " : " + creditpay.Comments;
                                     ServiceManager.AddBizException(pos, null, GReason, 'B', 'G');
                                 }
                             }
                             if (IsRoomPayment) { PaymentManger.MakeRoomPayment(pos, roompay, (RoomAmt), transactionTime); }
                             ts.Complete();
                         }
                         ReportStatus(PsxMessages.PaymentAccepted);
                         ReportStatus((PsxMessages.AmountPaid + ": " + Math.Round(NetAmount, 2) + "  " + PsxMessages.ChangeAmount + ": " + Math.Round(changeAmt, 2)));
                         ClearInputs();
                         gridBillDetails.Rows.RemoveAt(gridBillDetails.CurrentRow.Index);
                         IsEnablecontrols = false;
                         EnableControls();
                     }
                     catch (UniqueKeyException)
                     {
                         ReportStatus("The Bill was modified by another user");
                         ClearInputs();
                         PopulateBills();
                     }
                     catch (Exception ex)
                     {
                        // StoreTransFactory.GenerateExceptionTextFile(ServerTime.Now + ",PaymentForm," + this.Name + "," + ex.Message + "," + ex.StackTrace + "\n", Application.StartupPath + @"\Pos.txt");
                     }
                 }
             }
             else
             {
                 if (Math.Round(totamt,2) <Math.Round(NetAmount,2))
                 {
                     Console.Beep();
                     ReportStatus(PsxMessages.EnterAmount + ":" + Math.Round(NetAmount - totamt, 2));
                 }
             }
         }
     }



it work fine in my system...
but my Client has the following error,

MSIL
0,PaymentForm,PaymentForm,Object reference not set to an instance of an object.,   at System.Data.Linq.SqlClient.SqlConnectionManager.BootUser(IConnectionUser user)
   at System.Data.Linq.SqlClient.SqlConnectionManager.ClearConnection()
   at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.ClearConnection()
   at System.Data.Linq.DataContext.SubmitChanges(ConflictMode failureMode)
   at Prosynergix.Core.ServiceManager.AddCustomer(Customer customer)
   at Prosynergix.Pos.PaymentForm.btnAccept_Click(Object sender, EventArgs e)



any one can help me to solve this issue.
Posted
Updated 14-Mar-11 3:46am
v2

1 solution

From the error message, it is in your ServiceManager.AddCustomer method (which you don't show).
The only place you call it, the parameter "_Customer" is pre-checked for null, so it should be OK. You will have to look at what happens within the routine.



"i cont understand ur msg can u clarify plz"

Please don't use textspeak here: you have a keyboard, learn to use it...
(We have many people for whom English is not a native language, if they can't look up words, they can't understand.)


Your error message says where the exception occurs:
at Prosynergix.Core.ServiceManager.AddCustomer(Customer customer)
at Prosynergix.Pos.PaymentForm.btnAccept_Click(Object sender, EventArgs e)

So, in your method btnAccept_Click you are calling ServiceManager.AddCustomer which is doing a pile of Linq stuff.
Since you only call ServiceManager.AddCustomer from one place in your code fragment, and the parameter is checked for null before you call it, whatever is causing the problem will only be releaved by looking at what ServiceManager.AddCustomer does.

Somewhere in this method, the Linq data is wrong.

So, look at the ServiceManager.AddCustomer method and see what could be null and cause a problem...
 
Share this answer
 
v2
Comments
ajitha.pusapati 14-Mar-11 10:00am    
i cont understand ur msg can u clarify plz
OriginalGriff 14-Mar-11 10:06am    
Answer updated.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900