//Equates to a QuickBooks customer private long EnterBCOrderBillingAddress() { using (PreferredFloristDBDataContext pfDB = new PreferredFloristDBDataContext()) { var bcOrderAddressObj = new Site_Manager.DataModel.BC_BillingAddress(); bcOrderAddressObj.bc_order_id = bcOrder.id; bcOrderAddressObj.city = bcOrder.billing_address.city; bcOrderAddressObj.company = bcOrder.billing_address.company; bcOrderAddressObj.country = bcOrder.billing_address.country; bcOrderAddressObj.country_iso2 = bcOrder.billing_address.country_iso2; bcOrderAddressObj.email = bcOrder.billing_address.email; bcOrderAddressObj.first_name = bcOrder.billing_address.first_name; bcOrderAddressObj.last_name = bcOrder.billing_address.last_name; var validateField = new ValidateFieldLength(); bcOrderAddressObj.phone = validateField.PhoneNumber(bcOrder.billing_address.phone); bcOrderAddressObj.state = bcOrder.billing_address.state; bcOrderAddressObj.street_1 = bcOrder.billing_address.street_1; bcOrderAddressObj.street_2 = bcOrder.billing_address.street_2; bcOrderAddressObj.zip = bcOrder.billing_address.zip; if (null != bcOrder.total_tax && bcOrder.total_tax > 0) { bcOrderAddressObj.IsTaxable = true; } else { bcOrderAddressObj.IsTaxable = false; } var GetAccountNumber = new GetNextIDNumber(); bcOrderAddressObj.PF_accountNumber = GetAccountNumber.GetCustomerNumber(); pfDB.BC_BillingAddresses.InsertOnSubmit(bcOrderAddressObj); pfDB.SubmitChanges(); return (long)bcOrderAddressObj.PF_accountNumber; } }
public QBRequest DoInvoiceAdd(QBRequest wqObject) { bool sessionBegun = false; bool connectionOpen = false; //Create the session Manager object var sessionManager = new Interop.QBFC11.QBSessionManager(); try { IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", wqObject.QBVersion, 0); //originally was 7 qbxml version supported # 1.1 March 2002 # 2.0 November 2002 # 2.1 June 2003 # 3.0 November 2003 # 4.0 November 2004 # 4.1 June 2005 # 5.0 November 2005 # 6.0 October 2006 requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; try { using (var db = new PreferredFloristDBDataContext()) { customer = db.BC_BillingAddresses.FirstOrDefault(p => p.PF_accountNumber == wqObject.CustomerID); } } catch (Exception ex) { CatchHandler ch = new CatchHandler(); ch.CaptureError(ex); } BuildInvoiceAddRq(requestMsgSet, customer, wqObject); //Connect to QuickBooks and begin a session sessionManager.OpenConnection("", "Site Manager"); connectionOpen = true; try { sessionManager.BeginSession("", ENOpenMode.omMultiUser); } catch { sessionManager.BeginSession("", ENOpenMode.omSingleUser); } sessionBegun = true; //Send the request and get the response from QuickBooks IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet); //End the session and close the connection to QuickBooks sessionManager.EndSession(); sessionBegun = false; sessionManager.CloseConnection(); connectionOpen = false; WalkInvoiceAddRs(responseMsgSet); } catch (Exception ex) { if (sessionBegun) { sessionManager.EndSession(); } if (connectionOpen) { sessionManager.CloseConnection(); } qbTranasctionResponse = 99; qbTransactionResponseDetail = String.Format("AddInvoiceInQuickBooks failed. {0} {1}", ex.InnerException.Message, qbTransactionResponseDetail); CatchHandler ch = new CatchHandler(); ch.CaptureError(ex); } wqObject.QBListID = qbListIDforThisTransaction; wqObject.Status = qbTranasctionResponse; wqObject.StatusMessage = qbTransactionResponseDetail; return wqObject; }