Exemplo n.º 1
0
        /*
         * This method will add/update a customer
         * @author nazmul hasan on 5th january 2016
         */
        private void OnAdd()
        {
            if (!ValidateCustomer())
            {
                MessageBox.Show(ErrorMessage);
                return;
            }
            ProfileInfo profileInfo = new ProfileInfo();

            profileInfo.setId(CustomerInfoNJ.ProfileInfoNJ.Id);
            profileInfo.setFirstName(CustomerInfoNJ.ProfileInfoNJ.FirstName);
            profileInfo.setLastName(CustomerInfoNJ.ProfileInfoNJ.LastName);
            profileInfo.setEmail(CustomerInfoNJ.ProfileInfoNJ.Email);
            profileInfo.setPhone(CustomerInfoNJ.ProfileInfoNJ.Phone);
            profileInfo.setFax(CustomerInfoNJ.ProfileInfoNJ.Fax);
            profileInfo.setWebsite(CustomerInfoNJ.ProfileInfoNJ.Website);
            CustomerInfo customerInfo = new CustomerInfo();

            customerInfo.setProfileInfo(profileInfo);
            CustomerManager customerManager = new CustomerManager();

            CustomerInfoNJ customerInfoNJ = new CustomerInfoNJ();

            customerInfoNJ.ProfileInfoNJ.Id        = CustomerInfoNJ.ProfileInfoNJ.Id;
            customerInfoNJ.ProfileInfoNJ.FirstName = CustomerInfoNJ.ProfileInfoNJ.FirstName;
            customerInfoNJ.ProfileInfoNJ.LastName  = CustomerInfoNJ.ProfileInfoNJ.LastName;
            customerInfoNJ.ProfileInfoNJ.Email     = CustomerInfoNJ.ProfileInfoNJ.Email;
            customerInfoNJ.ProfileInfoNJ.Phone     = CustomerInfoNJ.ProfileInfoNJ.Phone;
            customerInfoNJ.ProfileInfoNJ.Fax       = CustomerInfoNJ.ProfileInfoNJ.Fax;
            customerInfoNJ.ProfileInfoNJ.Website   = CustomerInfoNJ.ProfileInfoNJ.Website;

            ResultEvent resultEvent = new ResultEvent();

            if (CustomerInfoNJ.ProfileInfoNJ.Id > 0)
            {
                resultEvent = customerManager.updateCustomer(customerInfo);
            }
            else
            {
                resultEvent = customerManager.createCustomer(customerInfo);
            }
            if (resultEvent.getResponseCode() == Responses.RESPONSE_CODE_SUCCESS)
            {
                if (CustomerInfoNJ.ProfileInfoNJ.Id > 0)
                {
                    for (int counter = 0; counter < CustomerList.Count; counter++)
                    {
                        CustomerInfoNJ tempCustomerInfoNJ = CustomerList.ElementAt(counter);

                        if (tempCustomerInfoNJ.ProfileInfoNJ.Id == CustomerInfoNJ.ProfileInfoNJ.Id)
                        {
                            CustomerList.RemoveAt(counter);
                            CustomerList.Insert(counter, customerInfoNJ);
                        }
                    }
                }
                else
                {
                    CustomerInfo responseCustomerInfo = (CustomerInfo)resultEvent.getResult();
                    CustomerInfoNJ.ProfileInfoNJ.Id = responseCustomerInfo.getProfileInfo().getId();
                    customerInfoNJ.ProfileInfoNJ.Id = CustomerInfoNJ.ProfileInfoNJ.Id;
                    if (CustomerList.Count == 0)
                    {
                        CustomerList.Add(customerInfoNJ);
                    }
                    else
                    {
                        CustomerList.Insert(0, customerInfoNJ);
                    }
                }
            }
            MessageBox.Show(resultEvent.getMessage());
            //reset create Customer fields
            OnReset();
        }