protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        SimplicityCommLib.DataSets.Common.Address.AddressRow accountAddress = null;
        SimplicityCommLib.DataSets.Common.Address.AddressRow billingAddress = null;
        SimplicityCommLib.DataSets.Common.Address.AddressRow shippingAddress = null;

        SetAddresses(ref accountAddress, ref billingAddress, ref shippingAddress);
        SimplicityCommLib.DataSets.Common.AddressTableAdapters.AddressTableAdapter addressTA = new SimplicityCommLib.DataSets.Common.AddressTableAdapters.AddressTableAdapter();
        if (imgBtnBilling.ImageUrl.Equals("~/images/checkbox_checked.png"))
        {
            if (billingAddress != null)
            {
                addressTA.Update(false, Constants.AddressCategories.UserAddress, LoggedInUser.UserId, true, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.BILLING),
                    null, null, null, null, null, null, null, null, null, null, null, null, null, LoggedInUser.UserId, DateTime.Now, LoggedInUser.UserId, DateTime.Now, null, null, null, billingAddress.AddressId,billingAddress.AddressId);
            }
            else
            {
                addressTA.Insert(false, Constants.AddressCategories.UserAddress, LoggedInUser.UserId, true, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.BILLING),
                    null, null, null, null, null, null, null, null, null, null, null, null, null, LoggedInUser.UserId, DateTime.Now, LoggedInUser.UserId, DateTime.Now, null, null, null);
            }
        }
        else
        {
            if (billingAddress != null)
            {
                addressTA.Update(false, Constants.AddressCategories.UserAddress, LoggedInUser.UserId, true, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.BILLING),
                    null, txtBillingAddressNo.Text, txtBillingAddressLine1.Text, txtBillingAddressLine2.Text, txtBillingAddressLine3.Text, txtBillingAddressLine4.Text, txtBillingAddressLine5.Text,
                    txtBillingPostCode.Text, null, txtBillingTele1.Text, txtBillingTele2.Text, txtBillingFax.Text, txtBillingMobile.Text, LoggedInUser.UserId, DateTime.Now,
                    LoggedInUser.UserId, DateTime.Now, txtBillingTown.Text, txtBillingCounty.Text, txtBillingCountry.Text, billingAddress.AddressId);
            }
            else
            {
                addressTA.Insert(false, Constants.AddressCategories.UserAddress, LoggedInUser.UserId, true, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.BILLING),
                    null, txtBillingAddressNo.Text, txtBillingAddressLine1.Text, txtBillingAddressLine2.Text, txtBillingAddressLine3.Text, txtBillingAddressLine4.Text, txtBillingAddressLine5.Text,
                    txtBillingPostCode.Text, null, txtBillingTele1.Text, txtBillingTele2.Text, txtBillingFax.Text, txtBillingMobile.Text, LoggedInUser.UserId, DateTime.Now,
                    LoggedInUser.UserId, DateTime.Now, txtBillingTown.Text, txtBillingCounty.Text, txtBillingCountry.Text);
            }
        }
        if (imgBtnShipping.ImageUrl.Equals("~/images/checkbox_checked.png"))
        {
            if (shippingAddress != null)
            {
                addressTA.Update(false, Constants.AddressCategories.UserAddress, LoggedInUser.UserId, true, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.SHIPPING),
                    null, null, null, null, null, null, null, null, null, null, null, null, null, LoggedInUser.UserId, DateTime.Now, LoggedInUser.UserId, DateTime.Now, null, null, null, shippingAddress.AddressId);
            }
            else
            {
                addressTA.Insert(false, Constants.AddressCategories.UserAddress, LoggedInUser.UserId, true, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.SHIPPING),
                    null, null, null, null, null, null, null, null, null, null, null, null, null, LoggedInUser.UserId, DateTime.Now, LoggedInUser.UserId, DateTime.Now, null, null, null);
            }
        }
        else
        {
            if (shippingAddress != null)
            {
                addressTA.Update(false, Constants.AddressCategories.UserAddress, LoggedInUser.UserId, true, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.SHIPPING),
                    null, txtShippingAddressNo.Text, txtShippingAddressLine1.Text, txtShippingAddressLine2.Text, txtShippingAddressLine3.Text, txtShippingAddressLine4.Text, txtShippingAddressLine5.Text,
                    txtShippingPostCode.Text, null, txtShippingTele1.Text, txtShippingTele2.Text, txtShippingFax.Text, txtShippingMobile.Text, LoggedInUser.UserId, DateTime.Now,
                    LoggedInUser.UserId, DateTime.Now, txtShippingTown.Text, txtShippingCounty.Text, txtShippingCountry.Text, shippingAddress.AddressId);
            }
            else
            {
                addressTA.Insert(false, Constants.AddressCategories.UserAddress, LoggedInUser.UserId, true, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.SHIPPING),
                    null, txtShippingAddressNo.Text, txtShippingAddressLine1.Text, txtShippingAddressLine2.Text, txtShippingAddressLine3.Text, txtShippingAddressLine4.Text, txtShippingAddressLine5.Text,
                    txtShippingPostCode.Text, null, txtShippingTele1.Text, txtShippingTele2.Text, txtShippingFax.Text, txtShippingMobile.Text, LoggedInUser.UserId, DateTime.Now,
                    LoggedInUser.UserId, DateTime.Now, txtShippingTown.Text, txtShippingCounty.Text, txtShippingCountry.Text);
            }
        }
        Response.Redirect("~/pages/ConfirmCheckout.aspx");
    }
    protected void btnSave_Click(object sender, ImageClickEventArgs e)
    {
        if (ValidateFields())
        {
            try
            {
                //CustomerTableAdapters.CustomerTableAdapter customerTA = new CustomerTableAdapters.CustomerTableAdapter();
                //IEnumerator ieCustomer = customerTA.InsertAndReturn(false, false, false, 0, 0, GetFullName(), null, null, txtSurname.Text, txtFirstName.Text, txtJobTitle.Text, txtEmail.Text,
                //    Utility.GetMd5Sum(txtPassword.Text), byte.Parse(listForgotPasswordQuestion.SelectedValue), listForgotPasswordQuestion.SelectedItem.Text, Utility.GetMd5Sum(txtForgotPasswordAnswer.Text), null, false, false, 0,
                //    false, null, null, DateTime.Now, null, DateTime.Now, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ENTITY_TYPE), ShoppingTrolley.Web.utils.Enums.ENTITY_TYPE.USER)).GetEnumerator();

                //mjaved.sim.CommonLib Insert User
                /*CommLibController userOBJ = new CommLibController();
                IEnumerator<UserInsertResult> ieUser = userOBJ.InsertAndReturnUser(cbEmails.Selected, false, false, 0, 0, GetFullName(), null, null, txtSurname.Text, txtFirstName.Text, txtJobTitle.Text, txtEmail.Text,
                    Utility.GetMd5Sum(txtPassword.Text), byte.Parse(listForgotPasswordQuestion.SelectedValue), listForgotPasswordQuestion.SelectedItem.Text, Utility.GetMd5Sum(txtForgotPasswordAnswer.Text), false, false, 0,
                    false, null, 0, DateTime.Now, 0, DateTime.Now, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ENTITY_TYPE), ShoppingTrolley.Web.utils.Enums.ENTITY_TYPE.USER));*/

                SimplicityCommLib.DataSets.Common.UsersTableAdapters.UsersTableAdapter userTA = new SimplicityCommLib.DataSets.Common.UsersTableAdapters.UsersTableAdapter();
                IEnumerator<SimplicityCommLib.DataSets.Common.Users.UsersRow> ieUsers = userTA.InsertAndReturn(System.Guid.NewGuid().ToString(), System.Guid.NewGuid().ToString(), cbEmails.Selected, false, false, 0, null, GetFullName(), "",
                    GetInitials(), txtFirstName.Text, txtSurname.Text, txtJobTitle.Text, txtEmail.Text, txtPassword.Text, byte.Parse(listForgotPasswordQuestion.SelectedValue),
                    "", txtForgotPasswordAnswer.Text, false, false, 0, false, "", null, DateTime.Now, null, DateTime.Now, SimplicityCommLib.Constants.Roles.User).GetEnumerator();

                if (ieUsers.MoveNext())
                {

                    SimplicityCommLib.DataSets.Common.CompanyTableAdapters.CompanyTableAdapter companyTA = new SimplicityCommLib.DataSets.Common.CompanyTableAdapters.CompanyTableAdapter();
                    IEnumerator<SimplicityCommLib.DataSets.Common.Company.CompanyRow> ieCompany = companyTA.InsertAndReturn(false, txtCompanyName.Text, txtCompanyName.Text, txtJobTitle.Text, GetInitials(), txtFirstName.Text, txtSurname.Text,
                        "", false, ieUsers.Current.UserId, DateTime.Now, ieUsers.Current.UserId, DateTime.Now).GetEnumerator();

                    if (ieCompany.MoveNext())
                    {
                        SimplicityCommLib.DataSets.Common.DepartmentsTableAdapters.DepartmentsTableAdapter deptTA = new SimplicityCommLib.DataSets.Common.DepartmentsTableAdapters.DepartmentsTableAdapter();
                        IEnumerator<SimplicityCommLib.DataSets.Common.Departments.DepartmentsRow> ieDepts = deptTA.InsertAndReturn(ieCompany.Current.CompanyId, false, txtCompanyName.Text, txtCompanyName.Text, txtJobTitle.Text, GetInitials(), txtFirstName.Text, txtSurname.Text, "",
                            ieUsers.Current.UserId, DateTime.Now, ieUsers.Current.UserId, DateTime.Now).GetEnumerator();

                        if (ieDepts.MoveNext())
                        {
                            SimplicityCommLib.DataSets.Common.AddressTableAdapters.AddressTableAdapter addressTA = new SimplicityCommLib.DataSets.Common.AddressTableAdapters.AddressTableAdapter();
                            addressTA.Insert(false, SimplicityCommLib.Constants.AddressCategories.UserAddress, ieCompany.Current.CompanyId, false, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.PERSONAL), txtCompanyName.Text,
                                txtAddressNo.Text, txtAddressLine1.Text, txtAddressLine2.Text, txtAddressLine3.Text, txtAddressLine4.Text, txtAddressLine5.Text, txtPostCode.Text,
                                GetFullAddress(), txtTele1.Text, txtTele2.Text, txtFax.Text, txtMobile.Text, ieUsers.Current.UserId, DateTime.Now, ieUsers.Current.UserId, DateTime.Now,
                                txtTown.Text, txtCounty.Text, txtCounty.Text);

                            addressTA.Insert(false, SimplicityCommLib.Constants.AddressCategories.UserAddress, ieUsers.Current.UserId, false, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.PERSONAL), txtCompanyName.Text,
                                txtAddressNo.Text, txtAddressLine1.Text, txtAddressLine2.Text, txtAddressLine3.Text, txtAddressLine4.Text, txtAddressLine5.Text, txtPostCode.Text,
                                GetFullAddress(), txtTele1.Text, txtTele2.Text, txtFax.Text, txtMobile.Text, ieUsers.Current.UserId, DateTime.Now, ieUsers.Current.UserId, DateTime.Now,
                                txtTown.Text, txtCounty.Text, txtCounty.Text);

                            addressTA.Insert(false, SimplicityCommLib.Constants.AddressCategories.DepartmentAddress, ieDepts.Current.DepartmentId, false, false, Enum.GetName(typeof(ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE), ShoppingTrolley.Web.utils.Enums.ADDRESS_TYPE.PERSONAL), txtCompanyName.Text,
                                txtAddressNo.Text, txtAddressLine1.Text, txtAddressLine2.Text, txtAddressLine3.Text, txtAddressLine4.Text, txtAddressLine5.Text, txtPostCode.Text,
                                GetFullAddress(), txtTele1.Text, txtTele2.Text, txtFax.Text, txtMobile.Text, ieUsers.Current.UserId, DateTime.Now, ieUsers.Current.UserId, DateTime.Now,
                                txtTown.Text, txtCounty.Text, txtCounty.Text);

                            EmailUtility.SendAccountCreationEmail(txtEmail.Text, ieUsers.Current.UserUid, ieUsers.Current.VerificationCode);
                            Response.Redirect("~/pages/ConfirmMail.aspx");
                        }
                    }
                }
            }
            catch
            {
                SetErrorMessage("Unable to process your transaction, please contact the administrator");
            }
        }
    }