你调用的对象是空的

你调用的对象是空的

本文介绍了你调用的对象是空的.按钮点击错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚上好..

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,

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.

推荐答案

at Prosynergix.Core.ServiceManager.AddCustomer(Customer customer)
at Prosynergix.Pos.PaymentForm.btnAccept_Click(Object sender, EventArgs e)


因此,在方法btnAccept_Click中,您正在调用ServiceManager.AddCustomer,这正在处理大量的Linq东西.
由于您只能从代码片段中的一个位置调用ServiceManager.AddCustomer,并且在调用该参数之前会将其检查为null,因此,仅通过查看ServiceManager.AddCustomer的作用即可消除引起问题的原因.
用这种方法的某个地方,Linq数据是错误的.

因此,请查看ServiceManager.AddCustomer方法,看看可能为null并导致问题...


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...


这篇关于你调用的对象是空的.按钮点击错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-14 10:27