public ICustomerPersonalInfo GetCustomer()
        {
            ICustomerPersonalInfo c = new Customer();
            c.FullName = txtFullName.Text;
            c.Phone = txtPhone.Text;
            c.PoBox = txtPO.Text;
            c.AltContact = txtAltContact.Text;
            c.AltPhone = txtAltPhone.Text;
            c.Email = txtEmail.Text;
            c.EditSequence = _editSequence;
            c.CustomerID = _customerID;

            return c;
        }
        ICustomerPersonalInfo XmlToCustInfo(XElement xCustomer)
        {
            ICustomerPersonalInfo cpi = new Customer();
            cpi.CustomerID = xCustomer.Element("CustomerID").Value;
            cpi.EditSequence = xCustomer.Element("EditSequence").Value;
            cpi.FullName = xCustomer.Element("FullName").Value;
            cpi.Phone = xCustomer.Element("Phone").Value;
            cpi.Email = xCustomer.Element("Email").Value;
            cpi.AltPhone = xCustomer.Element("AltPhone").Value;
            cpi.AltContact = xCustomer.Element("AltContact").Value;

            return cpi;
        }
        XElement CustomerToXml(Customer c)
        {
            XElement xCust = new XElement("Customer");

            xCust.Add(
                        new XElement("CustomerID", c.CustomerID),
                        new XElement("EditSequence", c.EditSequence),
                        new XElement("FullName", c.FullName),
                        new XElement("Phone", c.Phone),
                        new XElement("Email", c.Email),
                        new XElement("AltPhone", c.AltPhone),
                        new XElement("AltContact", c.AltContact)
                        );

            return xCust;
        }
Exemple #4
0
        public List<Customer> SearchCustomers(string searchText)
        {
            bool useFirstAndLast = false;

            string first = string.Empty;
            string last = string.Empty;

            var searchPieces = searchText.Split(" ".ToCharArray()).ToList();

            if (searchPieces.Count == 2)
            {
                useFirstAndLast = true;

                first = searchPieces[0];
                last = searchPieces[1];
            }

            List<Customer> customers = new List<Customer>();

            try
            {
                OpenSession();
                IMsgSetRequest msgSetRequest = _qbSession.CreateMsgSetRequest("US", 8, 0);
                msgSetRequest.ClearRequests();

                ICustomerQuery customerQuery = msgSetRequest.AppendCustomerQueryRq();
                customerQuery.ORCustomerListQuery.CustomerListFilter.MaxReturned.SetValue(150);
                customerQuery.ORCustomerListQuery.CustomerListFilter.ActiveStatus.SetValue(ENActiveStatus.asAll);
                customerQuery.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.Name.SetValue(searchText);

                customerQuery.ORCustomerListQuery.CustomerListFilter.ORNameFilter.NameFilter.MatchCriterion.SetValue(ENMatchCriterion.mcContains);
                customerQuery.OwnerIDList.Add(_settings.CustomerPrivateFieldsID);

                IMsgSetResponse msgSetResponse = _qbSession.DoRequests(msgSetRequest);
                if (((msgSetResponse == null) || (msgSetResponse.ResponseList == null)) || (msgSetResponse.ResponseList.Count <= 0))
                {
                    throw new Exception();
                }
                IResponseList responseList = msgSetResponse.ResponseList;
                if (responseList.Count != 1)
                {
                    throw new Exception();
                }
                IResponse response = responseList.GetAt(0);
                if (response == null)
                {
                    throw new Exception();
                }
                if (response.StatusCode != 0)
                {
                    _logger.Log("Error in GetAllCustomers." + Environment.NewLine +
                        "Status Code: " + response.StatusCode);
                    throw new Exception();
                }
                if (response.Type == null)
                {
                    throw new Exception();
                }
                if (response.Detail == null)
                {
                    throw new Exception();
                }
                if (response.Detail.Type == null)
                {
                    throw new Exception();
                }
                ICustomerRetList customerRetList = (ICustomerRetList)response.Detail;
                for (int i = 0; i < customerRetList.Count; i++)
                {
                    var cust = customerRetList.GetAt(i);

                    Customer customer = new Customer();
                    if (customer == null)
                    {
                        _logger.Log("Error GetAllCustomers.");
                        CloseSession();
                        throw new Exception("Error finding customer by ID");
                    }

                    if (cust.FullName != null && !cust.FullName.IsEmpty())
                        customer.FullName = cust.FullName.GetValue();

                    if (cust.AltContact != null && !cust.AltContact.IsEmpty())
                        customer.AltContact = cust.AltContact.GetValue();

                    if (cust.AltPhone != null && !cust.AltPhone.IsEmpty())
                        customer.AltPhone = cust.AltPhone.GetValue();

                    if (cust.Email != null && !cust.Email.IsEmpty())
                        customer.Email = cust.Email.GetValue();

                    if (cust.ListID != null && !cust.ListID.IsEmpty())
                        customer.CustomerID = cust.ListID.GetValue().ToString();

                    if (cust.EditSequence != null && !cust.EditSequence.IsEmpty())
                        customer.EditSequence = cust.EditSequence.GetValue();

                    if (cust.Phone != null && !cust.Phone.IsEmpty())
                        customer.Phone = cust.Phone.GetValue();
                    if (cust.BillAddress != null)
                    {
                        var ba = cust.BillAddress;
                        if (ba.Addr1 != null && !ba.Addr1.IsEmpty())
                            customer.BillingAddress.Line1 = cust.BillAddress.Addr1.GetValue();
                        if (ba.Addr2 != null && !ba.Addr2.IsEmpty())
                            customer.BillingAddress.Line2 = Environment.NewLine + ba.Addr2.GetValue();
                        if (ba.Addr3 != null && !ba.Addr3.IsEmpty())
                            customer.BillingAddress.Line3 = Environment.NewLine + ba.Addr3.GetValue();
                        if (ba.Addr4 != null && !ba.Addr4.IsEmpty())
                            customer.BillingAddress.Line4 = Environment.NewLine + ba.Addr4.GetValue();

                        if (ba.City != null && !ba.City.IsEmpty())
                            customer.BillingAddress.City = ba.City.GetValue();
                        if (ba.State != null && !ba.State.IsEmpty())
                            customer.BillingAddress.State = ba.State.GetValue();
                        if (ba.PostalCode != null && !ba.PostalCode.IsEmpty())
                            customer.BillingAddress.Zip = ba.PostalCode.GetValue();
                    }

                    if (cust.ShipAddress != null)
                    {
                        var sa = cust.ShipAddress;
                        if (sa.Addr1 != null && !sa.Addr1.IsEmpty())
                            customer.ShippingAddress.Line1 = sa.Addr1.GetValue();
                        if (sa.Addr2 != null && !sa.Addr2.IsEmpty())
                            customer.ShippingAddress.Line2 = sa.Addr2.GetValue();
                        if (sa.Addr3 != null && !sa.Addr3.IsEmpty())
                            customer.ShippingAddress.Line3 = sa.Addr3.GetValue();
                        if (sa.Addr4 != null && !sa.Addr4.IsEmpty())
                            customer.ShippingAddress.Line4 = sa.Addr4.GetValue();

                        if (sa.City != null && !sa.City.IsEmpty())
                            customer.ShippingAddress.City = sa.City.GetValue();
                        if (sa.State != null && !sa.State.IsEmpty())
                            customer.ShippingAddress.State = sa.State.GetValue();
                        if (sa.PostalCode != null && !sa.PostalCode.IsEmpty())
                            customer.ShippingAddress.Zip = sa.PostalCode.GetValue();
                    }

                    if (cust.DataExtRetList != null)
                    {
                        for (int j = 0; j < cust.DataExtRetList.Count; j++)
                        {
                            CreditCard cc1 = customer.CreditCards[0];
                            CreditCard cc2 = customer.CreditCards[1];
                            CreditCard cc3 = customer.CreditCards[2];

                            IDataExtRet field = cust.DataExtRetList.GetAt(j);
                            string name = field.DataExtName.GetValue();
                            string val = field.DataExtValue.GetValue();
                            if (name.StartsWith("CardNameType"))
                            {
                                string[] pieces = val.Split(":".ToCharArray());
                                string cardholderName = string.Empty;
                                Enums.CreditCardType ccType;

                                if (pieces.Length >= 2)
                                {
                                    cardholderName = pieces[1];
                                    string type = string.Empty;
                                    if (pieces[0].StartsWith("V"))
                                        ccType = Enums.CreditCardType.Visa;
                                    else if (pieces[0].StartsWith("M"))
                                        ccType = Enums.CreditCardType.Mastercard;
                                    else if (pieces[0].StartsWith("D"))
                                        ccType = Enums.CreditCardType.Discover;
                                    else if (pieces[0].StartsWith("A"))
                                        ccType = Enums.CreditCardType.Amex;
                                    else ccType = Enums.CreditCardType.UnknownOrNotSet;
                                }
                                else
                                {
                                    ccType = Enums.CreditCardType.UnknownOrNotSet;
                                    cardholderName = string.Empty;
                                }
                                if (name.EndsWith("1"))
                                {
                                    cc1.CreditCardType = ccType;
                                    cc1.CardholderName = cardholderName;
                                }
                                if (name.EndsWith("2"))
                                {
                                    cc2.CreditCardType = ccType;
                                    cc2.CardholderName = cardholderName;
                                }
                                if (name.EndsWith("3"))
                                {
                                    cc3.CreditCardType = ccType;
                                    cc3.CardholderName = cardholderName;
                                }
                            }
                            else if (name.StartsWith("CardNumExp"))
                            {
                                string[] pieces = val.Split(":".ToCharArray());
                                if (pieces.Length >= 2)
                                {
                                    if (name.EndsWith("1"))
                                    {
                                        cc1.CardNumber = pieces[0];

                                        cc1.ExpirationDate = pieces[1];

                                    }
                                    else if (name.EndsWith("2"))
                                    {
                                        cc2.CardNumber = pieces[0];

                                        cc2.ExpirationDate = pieces[1];

                                    }
                                    else if (name.EndsWith("3"))
                                    {
                                        cc3.CardNumber = pieces[0];
                                        cc3.ExpirationDate = pieces[1];
                                    }
                                }
                            }

                        }
                    }
                    if (customer != null)
                        customers.Add(customer);
                }

            }
            catch (QuickBooksException qbe)
            {
                throw qbe;
            }
            catch (Exception ex)
            {
                _logger.LogException("Error in GetAllCustomers.", ex);
            }
            finally
            {
                CloseSession();
            }

            return customers;
        }
Exemple #5
0
        public Customer GetCustomerByID(string id)
        {
            Customer customer = new Customer();

            try
            {
                OpenSession();
                IMsgSetRequest msgSetRequest = _qbSession.CreateMsgSetRequest("US", 8, 0);
                msgSetRequest.ClearRequests();

                ICustomerQuery customerQuery = msgSetRequest.AppendCustomerQueryRq();
                customerQuery.ORCustomerListQuery.ListIDList.Add(id);
                customerQuery.OwnerIDList.Add(_settings.CustomerPrivateFieldsID);
                IMsgSetResponse msgSetResponse = _qbSession.DoRequests(msgSetRequest);
                if (((msgSetResponse == null) || (msgSetResponse.ResponseList == null)) || (msgSetResponse.ResponseList.Count <= 0))
                {
                    throw new Exception();
                }
                IResponseList responseList = msgSetResponse.ResponseList;
                if (responseList.Count != 1)
                {
                    throw new Exception();
                }
                IResponse response = responseList.GetAt(0);
                if (response == null)
                {
                    throw new Exception();
                }
                if (response.StatusCode != 0)
                {
                    _logger.Log("Error in GetAllCustomersByID." + Environment.NewLine +
                        "Status Code: " + response.StatusCode);
                }
                if (response.Type == null)
                {
                    throw new Exception();
                }
                if (response.Detail == null)
                {
                    throw new Exception();
                }
                if (response.Detail.Type == null)
                {
                    throw new Exception();
                }
                ICustomerRetList customerRetList = (ICustomerRetList)response.Detail;
                if (customerRetList.Count > 1)
                {
                    _logger.Log("More than one customer found with id " + id + " in method GetCustomerById");
                    throw new Exception();
                }
                if (customerRetList.Count == 0)
                {
                    _logger.Log("Customer with ID " + id + " not found in GetAllCustomersByID method");
                    throw new Exception();
                }

                var cust = customerRetList.GetAt(0);

                if (cust.FullName != null && !cust.FullName.IsEmpty())
                    customer.FullName = cust.FullName.GetValue();

                if (cust.AltContact != null && !cust.AltContact.IsEmpty())
                    customer.AltContact = cust.AltContact.GetValue();

                if (cust.AltPhone != null && !cust.AltPhone.IsEmpty())
                    customer.AltPhone = cust.AltPhone.GetValue();

                if (cust.Email != null && !cust.Email.IsEmpty())
                    customer.Email = cust.Email.GetValue();

                if (cust.ListID != null && !cust.ListID.IsEmpty())
                    customer.CustomerID = cust.ListID.GetValue().ToString();

                if (cust.EditSequence != null && !cust.EditSequence.IsEmpty())
                    customer.EditSequence = cust.EditSequence.GetValue();

                if (cust.Phone != null && !cust.Phone.IsEmpty())
                    customer.Phone = cust.Phone.GetValue();
                if (cust.BillAddress != null)
                {
                    var ba = cust.BillAddress;
                    if (ba.Addr1 != null && !ba.Addr1.IsEmpty())
                        customer.BillingAddress.Line1 = cust.BillAddress.Addr1.GetValue();
                    if (ba.Addr2 != null && !ba.Addr2.IsEmpty())
                        customer.BillingAddress.Line2 = Environment.NewLine + ba.Addr2.GetValue();
                    if (ba.Addr3 != null && !ba.Addr3.IsEmpty())
                        customer.BillingAddress.Line3 = Environment.NewLine + ba.Addr3.GetValue();
                    if (ba.Addr4 != null && !ba.Addr4.IsEmpty())
                        customer.BillingAddress.Line4 = Environment.NewLine + ba.Addr4.GetValue();

                    if (ba.City != null && !ba.City.IsEmpty())
                        customer.BillingAddress.City = ba.City.GetValue();
                    if (ba.State != null && !ba.State.IsEmpty())
                        customer.BillingAddress.State = ba.State.GetValue();
                    if (ba.PostalCode != null && !ba.PostalCode.IsEmpty())
                        customer.BillingAddress.Zip = ba.PostalCode.GetValue();
                }

                if (cust.ShipAddress != null)
                {
                    var sa = cust.ShipAddress;
                    if (sa.Addr1 != null && !sa.Addr1.IsEmpty())
                        customer.ShippingAddress.Line1 = sa.Addr1.GetValue();
                    if (sa.Addr2 != null && !sa.Addr2.IsEmpty())
                        customer.ShippingAddress.Line2 = sa.Addr2.GetValue();
                    if (sa.Addr3 != null && !sa.Addr3.IsEmpty())
                        customer.ShippingAddress.Line3 = sa.Addr3.GetValue();
                    if (sa.Addr4 != null && !sa.Addr4.IsEmpty())
                        customer.ShippingAddress.Line4 = sa.Addr4.GetValue();

                    if (sa.City != null && !sa.City.IsEmpty())
                        customer.ShippingAddress.City = sa.City.GetValue();
                    if (sa.State != null && !sa.State.IsEmpty())
                        customer.ShippingAddress.State = sa.State.GetValue();
                    if (sa.PostalCode != null && !sa.PostalCode.IsEmpty())
                        customer.ShippingAddress.Zip = sa.PostalCode.GetValue();
                }

                bool fieldsExist = false;
                if (cust.DataExtRetList != null)
                {
                    for (int i = 0; i < cust.DataExtRetList.Count; i++)
                    {
                        if (cust.DataExtRetList.GetAt(i).DataExtName.GetValue().ToString().Equals("CardNameType1"))
                        {
                            fieldsExist = true;
                            break;
                        }
                    }
                }

                if (!fieldsExist)
                {
                    customer.CreditCardFieldsExistInQB = fieldsExist;
                }
                else
                {
                    customer.CreditCardFieldsExistInQB = fieldsExist;
                    for (int j = 0; j < cust.DataExtRetList.Count; j++)
                    {
                        CreditCard cc1 = customer.CreditCards[0];
                        CreditCard cc2 = customer.CreditCards[1];
                        CreditCard cc3 = customer.CreditCards[2];

                        IDataExtRet field = cust.DataExtRetList.GetAt(j);
                        string name = field.DataExtName.GetValue();
                        string val = field.DataExtValue.GetValue();
                        if (name.StartsWith("CardNameType"))
                        {
                            string[] pieces = val.Split(":".ToCharArray());
                            if (pieces.Length >= 2)
                            {
                                Enums.CreditCardType ccType;

                                string type = string.Empty;
                                if (pieces[0].StartsWith("V"))
                                    ccType = Enums.CreditCardType.Visa;
                                else if (pieces[0].StartsWith("M"))
                                    ccType = Enums.CreditCardType.Mastercard;
                                else if (pieces[0].StartsWith("D"))
                                    ccType = Enums.CreditCardType.Discover;
                                else if (pieces[0].StartsWith("A"))
                                    ccType = Enums.CreditCardType.Amex;
                                else ccType = Enums.CreditCardType.UnknownOrNotSet;

                                if (name.EndsWith("1"))
                                {
                                    cc1.CreditCardType = ccType;
                                    cc1.CardholderName = pieces[1];
                                }
                                if (name.EndsWith("2"))
                                {
                                    cc2.CreditCardType = ccType;
                                    cc2.CardholderName = pieces[1];
                                }
                                if (name.EndsWith("3"))
                                {
                                    cc3.CreditCardType = ccType;
                                    cc3.CardholderName = pieces[1];
                                }
                            }
                        }
                        else if (name.StartsWith("CardNumExp"))
                        {
                            string[] pieces = val.Split(":".ToCharArray());
                            if (pieces.Length >= 2)
                            {
                                if (name.EndsWith("1"))
                                {
                                    cc1.CardNumber = pieces[0];

                                    try
                                    {
                                        cc1.ExpirationDate = pieces[1];
                                    }
                                    catch (Exception ex)
                                    {
                                        _logger.LogException(ex);
                                    }
                                }
                                else if (name.EndsWith("2"))
                                {
                                    cc2.CardNumber = pieces[0];
                                    try
                                    {
                                        cc2.ExpirationDate = pieces[1];
                                    }
                                    catch (Exception ex)
                                    {
                                        _logger.LogException(ex);
                                    }
                                }
                                else if (name.EndsWith("3"))
                                {
                                    cc2.CardNumber = pieces[0];
                                    try
                                    {
                                        cc3.ExpirationDate = pieces[1];
                                    }
                                    catch (Exception ex)
                                    {
                                        _logger.LogException(ex);
                                    }
                                }
                            }
                        }

                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogException("Error in GetCustomerById with cust id of " + id, ex);
                throw ex;
            }
            finally
            {
                CloseSession();
            }

            return customer;
        }
Exemple #6
0
        public void ModifyCustomer(Customer c, bool getLatestEditSequence)
        {
            string editSequence = c.EditSequence;

            if (getLatestEditSequence)
            {
                var latestCust = GetCustomerByID(c.CustomerID);
                editSequence = latestCust.EditSequence;
            }

            Address billingAddress = c.BillingAddress;
            Address shippingAddress = c.ShippingAddress;

            try
            {
                OpenSession();
                IMsgSetRequest msgSetRequest = _qbSession.CreateMsgSetRequest("US", 8, 0);
                msgSetRequest.Attributes.OnError = ENRqOnError.roeContinue;
                ICustomerMod modCust = msgSetRequest.AppendCustomerModRq();

                modCust.ListID.SetValue(c.CustomerID);
                modCust.EditSequence.SetValue(editSequence);

                modCust.Name.SetValue(c.FullName);
                modCust.Phone.SetValue(c.Phone);
                modCust.AltPhone.SetValue(c.AltPhone);
                modCust.AltContact.SetValue(c.AltContact);
                modCust.Email.SetValue(c.Email);

                modCust.ShipAddress.Addr1.SetValue(shippingAddress.Line1);
                modCust.ShipAddress.Addr2.SetValue(shippingAddress.Line2);
                modCust.ShipAddress.Addr3.SetValue(shippingAddress.Line3);
                modCust.ShipAddress.Addr4.SetValue(shippingAddress.Line4);
                modCust.ShipAddress.City.SetValue(shippingAddress.City);
                modCust.ShipAddress.State.SetValue(shippingAddress.State);
                modCust.ShipAddress.PostalCode.SetValue(shippingAddress.Zip);

                modCust.BillAddress.Addr1.SetValue(billingAddress.Line1);
                modCust.BillAddress.Addr2.SetValue(billingAddress.Line2);
                modCust.BillAddress.Addr3.SetValue(billingAddress.Line3);
                modCust.BillAddress.Addr4.SetValue(billingAddress.Line4);
                modCust.BillAddress.City.SetValue(billingAddress.City);
                modCust.BillAddress.State.SetValue(billingAddress.State);
                modCust.BillAddress.PostalCode.SetValue(billingAddress.Zip);

                IMsgSetResponse msgSetResponse = _qbSession.DoRequests(msgSetRequest);

                IResponseList responseList = msgSetResponse.ResponseList;
                IResponse rsp = responseList.GetAt(0);
                if (rsp.StatusCode == 3200) //3200 means edit sequence code is out of date
                {
                    if (getLatestEditSequence) //do not allow more than one re-try
                    {
                        _logger.Log(string.Format("First attempt to modify customer {0} failed.  Attempted to get the latest edit sequence id for customer and retry the edit but it also failed.", c.FullName));
                        throw new QuickBooksException("Unable to successfully modify customer.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else //re-try the modification now
                    {
                        CloseSession();
                        _logger.Log(string.Format("Attempting to get the latest edit sequence for customer {0} and retry the ModifyCustomer method.", c.FullName));
                        ModifyCustomer(c, true);
                    }
                }
                else if (rsp.StatusCode != 0)
                {
                    _logger.Log(string.Format("Status code of {0} returned for customer modification for customer {1}", rsp.StatusCode, c.FullName));
                    //throw new QuickBooksException(StatusCode.Failure, string.Format("Error modifying customer {1}", c.FullName), true);  TODO: look at this code again.
                }
                else if (getLatestEditSequence) //success
                {
                    _logger.Log(string.Format("Successfully retrieved latest edit sequence for customer {0}", c.FullName));
                    throw new QuickBooksException("Customer was modified successfully; however, the customer data was stale " +
                        "and had to be merged with newer data." + Environment.NewLine + "It is highly recommended that you perform a customer " +
                        "refresh periodically to prevent this from becoming a regular occurence.", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                }
            }
            catch (QuickBooksException qbe)
            {
                throw qbe;
            }
            catch (Exception ex)
            {
                _logger.LogException(string.Format("Error modifying customer with ID {0} and name {1}", c.CustomerID, c.FullName), ex);
                throw ex;
            }
            finally
            {
                CloseSession();
            }
        }
Exemple #7
0
        public string AddCustomer(Customer c)
        {
            var billingAddress = c.BillingAddress;
            var shippingAddress = c.ShippingAddress;

            OpenSession();
            IMsgSetRequest msgSetRequest = _qbSession.CreateMsgSetRequest("US", 8, 0);

            try
            {
                msgSetRequest.Attributes.OnError = ENRqOnError.roeContinue;
                ICustomerAdd newCust = msgSetRequest.AppendCustomerAddRq();
                newCust.Name.SetValue(c.FullName);
                newCust.Phone.SetValue(c.Phone);
                newCust.AltPhone.SetValue(c.AltPhone);
                newCust.AltContact.SetValue(c.AltContact);
                newCust.Email.SetValue(c.Email);

                newCust.ShipAddress.Addr1.SetValue(shippingAddress.Line1);
                newCust.ShipAddress.Addr2.SetValue(shippingAddress.Line2);
                newCust.ShipAddress.Addr3.SetValue(shippingAddress.Line3);
                newCust.ShipAddress.Addr4.SetValue(shippingAddress.Line4);
                newCust.ShipAddress.City.SetValue(shippingAddress.City);
                newCust.ShipAddress.State.SetValue(shippingAddress.State);
                newCust.ShipAddress.PostalCode.SetValue(shippingAddress.Zip);

                newCust.BillAddress.Addr1.SetValue(billingAddress.Line1);
                newCust.BillAddress.Addr2.SetValue(billingAddress.Line2);
                newCust.BillAddress.Addr3.SetValue(billingAddress.Line3);
                newCust.BillAddress.Addr4.SetValue(billingAddress.Line4);
                newCust.BillAddress.City.SetValue(billingAddress.City);
                newCust.BillAddress.State.SetValue(billingAddress.State);
                newCust.BillAddress.PostalCode.SetValue(billingAddress.Zip);

                IMsgSetResponse msgSetResponse = _qbSession.DoRequests(msgSetRequest);

                IResponseList list = msgSetResponse.ResponseList;
                IResponse resp = list.GetAt(0);
                if (resp.StatusCode != 0)
                {
                    _logger.Log("Error adding customer with name " + c.FullName + ". Status code is " + resp.StatusCode);
                    throw new Exception();
                }
                ICustomerRet cust = (ICustomerRet)resp.Detail;
                string id = cust.ListID.GetValue();

                CloseSession();

                this.AddCreditCardsForCustomer(c.CreditCards, id);
                return id;
            }
            catch (Exception ex)
            {
                _logger.LogException(string.Format("Error adding customer with ID {0} and name {1}", c.CustomerID, c.FullName), ex);
                throw new QuickBooksException("There was an error adding the customer to QuickBooks.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            finally
            {
                CloseSession();
            }
        }
Exemple #8
0
        private List<Customer> GetAllCustomersPersonalInfo()
        {
            List<Customer> customers = new List<Customer>();

            try
            {
                OpenSession();
                IMsgSetRequest msgSetRequest = _qbSession.CreateMsgSetRequest("US", 8, 0);
                msgSetRequest.ClearRequests();

                ICustomerQuery customerQuery = msgSetRequest.AppendCustomerQueryRq();
                IMsgSetResponse msgSetResponse = _qbSession.DoRequests(msgSetRequest);
                if (((msgSetResponse == null) || (msgSetResponse.ResponseList == null)) || (msgSetResponse.ResponseList.Count <= 0))
                {
                    throw new Exception();
                }
                IResponseList responseList = msgSetResponse.ResponseList;
                if (responseList.Count != 1)
                {
                    throw new Exception();
                }
                IResponse response = responseList.GetAt(0);
                if (response == null)
                {
                    throw new Exception();
                }
                if (response.StatusCode != 0)
                {
                    _logger.Log("Error in GetAllCustomers." + Environment.NewLine +
                        "Status Code: " + response.StatusCode);
                    throw new Exception();
                }
                if (response.Type == null)
                {
                    throw new Exception();
                }
                if (response.Detail == null)
                {
                    throw new Exception();
                }
                if (response.Detail.Type == null)
                {
                    throw new Exception();
                }
                ICustomerRetList customerRetList = (ICustomerRetList)response.Detail;
                for (int i = 0; i < customerRetList.Count; i++)
                {
                    var cust = customerRetList.GetAt(i);

                    Customer customer = new Customer();
                    if (customer == null)
                    {
                        _logger.Log("Error GetAllCustomers.");
                        CloseSession();
                        throw new Exception("Error finding customer by ID");
                    }

                    if (cust.FullName != null && !cust.FullName.IsEmpty())
                        customer.FullName = cust.FullName.GetValue();

                    if (cust.AltContact != null && !cust.AltContact.IsEmpty())
                        customer.AltContact = cust.AltContact.GetValue();

                    if (cust.AltPhone != null && !cust.AltPhone.IsEmpty())
                        customer.AltPhone = cust.AltPhone.GetValue();

                    if (cust.Email != null && !cust.Email.IsEmpty())
                        customer.Email = cust.Email.GetValue();

                    if (cust.ListID != null && !cust.ListID.IsEmpty())
                        customer.CustomerID = cust.ListID.GetValue().ToString();

                    if (cust.EditSequence != null && !cust.EditSequence.IsEmpty())
                        customer.EditSequence = cust.EditSequence.GetValue();

                    if (cust.Phone != null && !cust.Phone.IsEmpty())
                        customer.Phone = cust.Phone.GetValue();

                    customers.Add(customer);
                }
            }
            catch (Exception ex)
            {
                _logger.LogException("Error in GetallCustomersPersonalInfo()", ex);
                throw ex;
            }
            finally
            {
                CloseSession();
            }

            return customers;
        }
        Customer GetPopulatedCustomer()
        {
            Customer c = new Customer()
            {
                FullName = RandomString(10),
                CreditCards = new List<CreditCard>(){
                           new CreditCard(){
                                CardholderName = RandomString(10),
                                 CreditCardType = Enums.CreditCardType.Discover,
                                  ExpirationDate = "exp",
                                   CardNumber =  GetRandomNumber(100, 999999).ToString()
                           },
                           new CreditCard(),
                           new CreditCard()
                      }

            };
            return c;
        }
 public CustomerOrderObject()
 {
     _vehicle = new Vehicle();
     _customer = new Customer();
     _order = new Order();
 }
 private void SelectCustomerFromRow()
 {
     if (gvMain.SelectedRows.Count == 1)
     {
         string selectedCustId = gvMain.SelectedRows[0].Cells["CustomerID"].Value.ToString();
         if (_cachedCustomers.ContainsKey(selectedCustId))
             _selectedCustomer = _cachedCustomers[selectedCustId];
         this.Close();
     }
     else
     {
         MessageBox.Show("Select a customer", "QuickBooks", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }