private static void buildCustomerRequest(string[,] customers, ref IMsgSetRequest requestSet) { //Walk customers array and build CustomerAdd xmls int length = customers.GetLength(0); for (int x = 0; x < length; x++) { string firstname = (customers[x, 0] != null) ? customers[x, 0] : ""; string lastname = (customers[x, 1] != null) ? customers[x, 1] : ""; string addr1 = (customers[x, 2] != null) ? customers[x, 2] : ""; string addr2 = (customers[x, 3] != null) ? customers[x, 3] : ""; string city = (customers[x, 4] != null) ? customers[x, 4] : ""; string state = (customers[x, 5] != null) ? customers[x, 5] : ""; string zip = (customers[x, 6] != null) ? customers[x, 6] : ""; string phone = (customers[x, 7] != null) ? customers[x, 7] : ""; string email = (customers[x, 8] != null) ? customers[x, 8] : ""; ICustomerAdd CustAdd = requestSet.AppendCustomerAddRq(); CustAdd.Name.SetValue(firstname + " " + lastname); CustAdd.FirstName.SetValue(firstname); CustAdd.LastName.SetValue(lastname); CustAdd.BillAddress.Addr1.SetValue(addr1); CustAdd.BillAddress.Addr2.SetValue(addr2); CustAdd.BillAddress.City.SetValue(city); CustAdd.BillAddress.State.SetValue(state); CustAdd.BillAddress.PostalCode.SetValue(zip); CustAdd.Phone.SetValue(phone); CustAdd.Email.SetValue(email); } }
private ICustomerRet addCustomer(Quickbooks qb, CheckToWrite r) { IMsgSetRequest msgRequest = qb.newRequest(); msgRequest.Attributes.OnError = ENRqOnError.roeStop; ICustomerAdd addCustomer = msgRequest.AppendCustomerAddRq(); addCustomer.AccountNumber.SetValue(r.RecipientId); addCustomer.Name.SetValue(r.FullName); addCustomer.BillAddress.Addr1.SetValue(addCustomer.Name.GetValue()); addCustomer.BillAddress.Addr2.SetValue(r.Address1); addCustomer.BillAddress.Addr3.SetValue(r.Address2); addCustomer.Contact.SetValue(addCustomer.Name.GetValue()); addCustomer.BillAddress.City.SetValue(r.City); addCustomer.BillAddress.State.SetValue(r.State); addCustomer.BillAddress.PostalCode.SetValue(r.Zip); IMsgSetResponse response = qb.performRequest(msgRequest); if (response.ResponseList.GetAt(0).StatusCode == 0) { ICustomerRet result = (ICustomerRet)response.ResponseList.GetAt(0).Detail; return(result); } else { throw new Exception("Unable to add customer " + response.ResponseList.GetAt(0).StatusMessage); } }
private void button_Click(object sender, RoutedEventArgs e) { bool sessionBegun = false; bool connectionOpen = false; QBSessionManager sessionManager = null; try { //Create the session Manager object sessionManager = new QBSessionManager(); //Create the message set request object to hold our request IMsgSetRequest requestMsgSet = sessionManager.CreateMsgSetRequest("US", 8, 0); requestMsgSet.Attributes.OnError = ENRqOnError.roeContinue; //Connect to QuickBooks and begin a session sessionManager.OpenConnection("", "WpfApplication1"); connectionOpen = true; sessionManager.BeginSession("", ENOpenMode.omDontCare); sessionBegun = true; ICustomerAdd customerAddRq = requestMsgSet.AppendCustomerAddRq(); customerAddRq.Name.SetValue(Customer.Text); //Send the request and get the response from QuickBooks IMsgSetResponse responseMsgSet = sessionManager.DoRequests(requestMsgSet); IResponse response = responseMsgSet.ResponseList.GetAt(0); ICustomerRet customerRet = (ICustomerRet)response.Detail; QuickBooksID.Text = customerRet.ListID.GetValue(); } catch (Exception ex) { MessageBox.Show(ex.Message, "Error"); } finally { //End the session and close the connection to QuickBooks if (sessionBegun) { sessionManager.EndSession(); } if (connectionOpen) { sessionManager.CloseConnection(); } } }
public Dictionary <string, string> Create(CustomerEntity entity) { Dictionary <string, string> data = null; try { IMsgSetRequest requestMsgSet = QuickBooksConection(); //add items ICustomerAdd customerAdd = requestMsgSet.AppendCustomerAddRq(); if (!string.IsNullOrEmpty(entity.Name)) { customerAdd.Name.SetValue(entity.Name); } if (!string.IsNullOrEmpty(entity.CompanyName)) { customerAdd.CompanyName.SetValue(entity.CompanyName); } if (!string.IsNullOrEmpty(entity.Email)) { customerAdd.Email.SetValue(entity.Email); } if (!string.IsNullOrEmpty(entity.Phone)) { customerAdd.Phone.SetValue(entity.Phone); } if (entity.Balance > 0) { customerAdd.OpenBalance.SetValue(entity.Balance.Value); } if (entity.IsActive.HasValue) { customerAdd.IsActive.SetValue(entity.IsActive.Value); } // end add items data = QuickBooksExcuet(requestMsgSet); } catch (Exception ex) { data = new Dictionary <string, string>(); } return(data); }