protected void btnRemove_Click(object sender, CommandEventArgs e)
        {
            if (mCustomer != null)
            {
                if (e.CommandName.Equals("lbtnRemove"))
                {
                    var mypet = (from p in mCustomer.MyPets
                                 where p.QuoteId == int.Parse(e.CommandArgument.ToString())
                                 select p).ToList();
                    if (mypet != null)
                    {
                        int quoteId = 0;
                        using (PetfirstData pfData = new PetfirstData())
                        {
                            foreach (Pet p in mypet)//release pet from enrolledplan
                            {
                                quoteId = p.QuoteId;
                                p.QuoteId = 0;
                                p.Enrolled = false;
                                p.FirstMonthPaymentTotal = 0;
                                p.FirstMonthTax = 0;
                                p.PlanId = 0;
                                p.PlanName = string.Empty;
                                p.RecurringMonthPaymentTotal = 0;
                                p.RecurringMonthTax = 0;
                                p.AnnualPaymentTotal = 0;
                                p.FirstMonthPremiumOnly = 0;
                                p.RecurringMonthPremiumOnly = 0;
                                //p.LeadId = "";
                                try
                                {
                                    pfData.BreakPlanForPet(p.PetId);//set qplanid =0 in qpet table
                                    pfData.RemoveEnrolledPlan(p.QPlanId); //delete qplan entry
                                }
                                catch (Exception ex)
                                {
                                    displayError("Removing Enrolled Plan ", ex.ToString(), null);
                                }

                                p.QPlanId = 0;
                            }

                        }
                        BindPetsRepeater();
                        DetermineFamilyOrIndividualPlan();
                        DetermineReviewQuoteStatus();
                        //user may come to this page from checkout page and then delete the plan first
                        Session.Remove("EditPlanPet");
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        sb.Append(@"<script type='text/javascript'>");
                        sb.Append("$('#remove_plan').modal('show');");
                        sb.Append(@"</script>");
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ShowPetRemovedModal", sb.ToString(), false);

                    }
                }
            }
        }
        protected void btnContinue_Click(object sender, EventArgs e)
        {
            string url = "checkout.aspx";

            using (PetfirstData pfData = new PetfirstData())
            {
                mCustomer.MyPets.Add(mthisPet);
                pfData.SaveCustomer(mCustomer);
            }

            Response.Redirect(url, false);
            Context.ApplicationInstance.CompleteRequest();
        }
 protected void btnEmailSave_Click(object sender, EventArgs e)
 {
     if (!string.IsNullOrEmpty(txtEmail.Text))
     {
         mCustomer.MembershipInfo.Email = txtEmail.Text;
         try
         {
             using (PetfirstData pfData = new PetfirstData())
             {
                 pfData.SaveCustomer(mCustomer);
             }
         }
         catch { }
         lblEmail.Text = txtEmail.Text;
     }
     //the following line close the dialog but the main page UI still grayed-out
     //btnEmailSave.Attributes.Add("data-dismiss","modal");
 }
 private void RetrieveSavedData()
 {
     using (PetfirstData pfData = new PetfirstData())
     {
         pfData.RetrieveSavedData(ref mCustomer);
     }
 }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                if (mCustomer != null)
                {
                    try
                    {
                        var mypet = (from p in mCustomer.MyPets
                                     where p.PetName.ToLower().Equals(txtPetName.Text.ToLower())
                                     select p).FirstOrDefault();
                        if (mypet != null)
                        {
                            SavePet(true, ref mypet);//update//note: this is different than current, not allow pets have same name
                            if (mypet.Enrolled)
                            {
                                int quoteId = mypet.QuoteId;
                                List<Pet> lstEnrolled = (from p in mCustomer.MyPets
                                                         where p.QuoteId == quoteId
                                                         select p).ToList();
                                //first check if there is senior pet in family plan
                                bool bSenior = false;
                                string seniorName = "";
                                if (lstEnrolled.Count > 1)
                                {
                                    foreach (Pet p in lstEnrolled)
                                    {
                                        if (p.Age > 9)
                                        {
                                            bSenior = true;
                                            seniorName = p.PetName;
                                            break;
                                        }
                                    }
                                }
                                if (bSenior)
                                {
                                    lblError.Text = string.Format("Pet {0} is considered senior pet, senior pet is not allowed to be in the family plan, please remove this pet from the enrolled plan before edit", seniorName);
                                    return;
                                }
                                else
                                {
                                    //requote
                                    PetfirstBL pfBl = new PetfirstBL();
                                    DoRequote(pfBl, lstEnrolled);
                                }
                            }
                        }
                        else
                        {
                            mypet = new Pet();
                            mypet.Enrolled = false;
                            SavePet(false, ref mypet);
                        }
                        try
                        {
                            using (PetfirstData pfData = new PetfirstData())
                            {
                                pfData.SavePet(mypet, mCustomer.CustomerId);
                            }
                        }
                        catch (Exception ex)
                        {
                            LoggingError("Saving Pet", ex.ToString());
                        }//don't do anything if store data fails

                        if (this.Request.Url.AbsoluteUri.ToLower().Contains("addpets_xs.aspx"))
                        {
                            Response.Redirect("~/AddPets.aspx", false);
                            Context.ApplicationInstance.CompleteRequest();
                        }
                        else
                        {
                            bindPets();
                            ResetInput();
                            DetermineButtonText();
                        }
                    }
                    catch (Exception ex)
                    {
                        displayError("saving pet", ex.ToString(), true);
                    }
                }
            }
        }
        protected void btnRemove_Click(object sender, CommandEventArgs e)
        {
            if (mCustomer != null)
            {
                if (e.CommandName.Equals("lbtnRemove"))
                {
                    var mypet = (from p in mCustomer.MyPets
                                 where p.PetName.ToLower().Equals(e.CommandArgument.ToString().ToLower())
                                 select p).FirstOrDefault();
                    if (mypet != null)
                    {
                        mCustomer.MyPets.Remove(mypet);
                        bindPets();
                        DetermineButtonText();
                        try
                        {
                            using (PetfirstData pfData = new PetfirstData())
                            {
                                pfData.RemovePet(mypet.PetId);
                            }
                        }
                        catch (Exception ex)
                        {
                            LoggingError("Removing Pet", ex.ToString());
                        }//don't do anything if store data fails
                    }

                }
            }
        }
        private bool LoadPlanInfo(ref PetfirstCustomer mCustomer, string splanLookup)
        {
            bool bReturn = true;
            SqlConnection con = GetConnection();
            SqlDataReader sdr = null;
            SqlCommand cmd = new SqlCommand("usp_pricecompare_prequote_get_by_quote_id", con);
            string sMemberCodeString = "I";

            if (mCustomer.DiscountMilitarySelected)
            {
                sMemberCodeString += "M";
            }

            if (mCustomer.DiscountVetSelected)
            {
                sMemberCodeString += "A";
            }

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@pre_quote_id", SqlDbType.BigInt));
            cmd.Parameters["@pre_quote_id"].Value = Int32.Parse(splanLookup);

            cmd.Parameters.Add(new SqlParameter("@membercodestring", SqlDbType.VarChar, 20));
            cmd.Parameters["@membercodestring"].Value = sMemberCodeString;

            try
            {
                con.Open();
                sdr = cmd.ExecuteReader();

                while (sdr.Read())
                {
                    foreach (Pet mp in mCustomer.MyPets)
                    {
                        mp.AnnualPaymentTotal = sdr.GetDecimal(PTANNUALTOTAL);
                        mp.DeductibleAmount = sdr.GetDecimal(PTDEDUCTIBLE);
                        mp.Enrolled = true;
                        mp.FirstMonthPaymentTotal = sdr.GetDecimal(PTFIRSTMONTHTOTAL);
                        mp.FirstMonthPremiumOnly = sdr.GetDecimal(PTFIRSTMONTHTOTAL);
                        mp.FirstMonthTax = sdr.GetDecimal(PTFIRSTMONTHTAXFEE);
                        mp.IsFamilyPlan = false;
                        mp.PlanId = sdr.GetByte(PTPLANID);
                        mp.QuoteId = sdr.GetInt32(PTQUOTEID);
                        mp.RecurringMonthPaymentTotal = sdr.GetDecimal(PTRECURRINGMONTHTOTAL);
                        mp.RecurringMonthPremiumOnly = sdr.GetDecimal(PTRECURRINGMONTHTOTAL);
                        mp.RecurringMonthTax = sdr.GetDecimal(PTRECURRINGMONTHTAXFEE);
                        mp.Reimbursement = 1 - sdr.GetDecimal(PTCOPAY);
                        mp.InternetDiscountAmount = sdr.GetDecimal(PTDISCOUNTS);

                        using (PetfirstData pfData = new PetfirstData())
                        {
                            mp.LimitAmount = pfData.GetPlanLimitByPlanId(mp.PlanId);
                            mp.PlanName = pfData.GetPlanShortNameByPlanId(mp.PlanId);
                            pfData.SavePet(mp, mCustomer.CustomerId);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                bReturn = false;
                LoggingError(ex.Message, ex.StackTrace);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                    con.Dispose();
                    con = null;
                }
                if (cmd != null)
                {
                    cmd.Dispose();
                    cmd = null;
                }
            }

            return (bReturn);
        }
        protected void btnContinue_Click(object sender, EventArgs e)
        {
            bool bError = false;

            if (mCustomer == null)
            {
                InitiatePetfirstCustomer();
            }

            string url;

            try
            {

                mthisPet.PetName = txtPetName.Text;
                mthisPet.Birthday = DateTime.Today.AddYears(-(ddlAge.SelectedIndex - 1));
                mthisPet.Birthday = mthisPet.Birthday.AddMonths(-6);
                mthisPet.BreedId = int.Parse(ddlBreed.SelectedValue.ToString());
                mthisPet.BreedName = ddlBreed.SelectedItem.Text;
                mthisPet.ColorId = 146;
                mthisPet.ColorName = "Any";

                mthisPet.SpeciesId = int.Parse(rblSpecies.SelectedValue.ToString());
                mthisPet.SpeciesName = rblSpecies.SelectedItem.Text;

                //Handle Mixed
                if (ddlBreed.SelectedValue.ToString() == "10000")
                {
                    mthisPet.WeightId = int.Parse(rbRadioButtonListMixed.SelectedValue);
                    mthisPet.BreedId = 54;
                }

                if (bAddPet)
                {
                    try
                    {

                        mthisPet.DeductibleAmount = 250;
                        mthisPet.LimitAmount = 5000;
                        mthisPet.Reimbursement = .8m;
                        mthisPet.RiderName = "";
                        mthisPet.Routine = "";

                        int planId = 0;
                        Int16 typeid = (short)(mCustomer.LifeTimeActive ? 2 : 1);

                        using (PetfirstData pfData = new PetfirstData())
                        {
                            planId = pfData.GetPlanId(mthisPet.LimitAmount, typeid);
                            mCustomer.Underwriter = pfData.GetUnderwriterID(mCustomer.EnrollmentCode);
                            mthisPet.PlanId = planId;
                            mthisPet.QuoteId = 0;
                        }

                        PetfirstBL pfBl = new PetfirstBL();

                        if (!pfBl.GetFastQuote(ref mCustomer, ref mthisPet, true))
                        {
                            List<Pet> lstEnrollPet = new List<Pet>();
                            lstEnrollPet.Add(mthisPet);

                            pfBl.GetMonthlyQuote(ref mCustomer, lstEnrollPet);

                            if (mCustomer.WebserviceErrorMsg.Equals(""))
                            {
                                pfBl.GetAnnualQuote(ref mCustomer, lstEnrollPet);
                            }
                            else
                            {
                                displayError("getting quote ", mCustomer.WebserviceErrorMsg, true);
                                bError = true;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        displayError("getting quote ", ex.ToString(), true);
                        bError = true;
                    }

                    if (!bError)
                    {
                        url = "CustomizePlan.aspx";
                        Response.Redirect(url, false);
                        Context.ApplicationInstance.CompleteRequest();
                    }

                }
                else if (bSamePet)
                {
                    CoreServiceClient csc = new CoreServiceClient();
                    CoreServiceGetStateByZipResponse resp = csc.GetStateByZip(txtZip.Text);
                    if (string.IsNullOrEmpty(resp.Error.ErrorText))
                    {
                        mCustomer.MembershipInfo.StateId = resp.State.Id;
                        mCustomer.MembershipInfo.City = resp.State.CityName;
                        mCustomer.MembershipInfo.State = resp.State.StateName;
                        mCustomer.MembershipInfo.Zip = txtZip.Text;

                        mCustomer.DiscountMilitaryAvailable = mCustomer.DiscountMilitarySelected = false;
                        mCustomer.DiscountVetAvailable = mCustomer.DiscountVetSelected = false;

                        using (PetfirstData pfData = new PetfirstData())
                        {
                            mCustomer.Underwriter = pfData.GetUnderwriterID(mCustomer.EnrollmentCode);

                            if (mCustomer.Underwriter == 4)
                            {

                                CoreServiceGetDiscountByStateResponse response = csc.GetDiscountsByState(mCustomer.MembershipInfo.StateId);

                                if (string.IsNullOrEmpty(resp.Error.ErrorText))
                                {
                                    foreach (Discount d in response.Discounts)
                                    {
                                        switch (d.DiscountID)
                                        {
                                            case 356:
                                                mCustomer.DiscountMilitaryAvailable = true;
                                                break;
                                            case 333:
                                                mCustomer.DiscountVetAvailable = true;
                                                break;
                                            default:
                                                break;
                                        }

                                    }
                                }
                            }
                        }

                        try
                        {

                            mthisPet.DeductibleAmount = 250;
                            mthisPet.LimitAmount = 5000;
                            mthisPet.Reimbursement = .8m;
                            mthisPet.RiderName = "";
                            mthisPet.Routine = "";

                            int planId = 0;
                            Int16 typeid = (short)(mCustomer.LifeTimeActive ? 2 : 1);

                            using (PetfirstData pfData = new PetfirstData())
                            {
                                planId = pfData.GetPlanId(mthisPet.LimitAmount, typeid);
                                mCustomer.Underwriter = pfData.GetUnderwriterID(mCustomer.EnrollmentCode);
                                mthisPet.PlanId = planId;
                                mthisPet.QuoteId = 0;
                            }

                            PetfirstBL pfBl = new PetfirstBL();

                            if (!pfBl.GetFastQuote(ref mCustomer, ref mthisPet, true))
                            {
                                List<Pet> lstEnrollPet = new List<Pet>();
                                lstEnrollPet.Add(mthisPet);

                                pfBl.GetMonthlyQuote(ref mCustomer, lstEnrollPet);

                                if (mCustomer.WebserviceErrorMsg.Equals(""))
                                {
                                    pfBl.GetAnnualQuote(ref mCustomer, lstEnrollPet);
                                }
                                else
                                {
                                    displayError("getting quote ", mCustomer.WebserviceErrorMsg, true);
                                    bError = true;
                                }
                            }
                        }

                        catch (Exception ex)
                        {
                            displayError("getting quote ", ex.ToString(), true);
                            bError = true;
                        }

                        if (!bError)
                        {
                            url = "YourInformation.aspx?current_customer=true";
                            Response.Redirect(url, false);
                            Context.ApplicationInstance.CompleteRequest();
                        }
                    }
                }
                else
                {
                    CoreServiceClient csc = new CoreServiceClient();
                    CoreServiceGetStateByZipResponse resp = csc.GetStateByZip(txtZip.Text);
                    if (string.IsNullOrEmpty(resp.Error.ErrorText))
                    {
                        mCustomer.MembershipInfo.StateId = resp.State.Id;
                        mCustomer.MembershipInfo.City = resp.State.CityName;
                        mCustomer.MembershipInfo.State = resp.State.StateName;
                        mCustomer.MembershipInfo.Zip = txtZip.Text;

                        using (PetfirstData pfData = new PetfirstData())
                        {
                            mCustomer.Underwriter = pfData.GetUnderwriterID(mCustomer.EnrollmentCode);

                            if (mCustomer.Underwriter == 4)
                            {

                                CoreServiceGetDiscountByStateResponse response = csc.GetDiscountsByState(mCustomer.MembershipInfo.StateId);

                                if (string.IsNullOrEmpty(resp.Error.ErrorText))
                                {
                                    foreach (Discount d in response.Discounts)
                                    {
                                        switch (d.DiscountID)
                                        {
                                            case 356:
                                                mCustomer.DiscountMilitaryAvailable = true;
                                                break;
                                            case 333:
                                                mCustomer.DiscountVetAvailable = true;
                                                break;
                                            default:
                                                break;
                                        }

                                    }
                                }
                            }
                        }

                        url = "YourInformation.aspx";
                        Response.Redirect(url, false);
                        Context.ApplicationInstance.CompleteRequest();
                    }
                    else
                    {
                        lblError.Text = string.Concat("Sorry, we cannot find the zip you entered, please make sure the zip you entered is correct.<br />If you continue to get this message, please call ", mCustomer.CallCenter);
                    }

                }
            }
            catch (Exception ex)
            {
                DisplayError("verifying your zip", ex.ToString(), true);
            }
        }
 public List<Reimbursement> GetReimbursement(string enrollmentcode, short typeid)
 {
     string cacheKey = string.Concat("$Deductible_ec_type$", enrollmentcode, "_", typeid);
     object CachedList = m_Cache.Get(cacheKey) as List<Reimbursement>;
     List<Reimbursement> lstReturn = null;
     if (CachedList == null)//get from the db call
     {
         PetfirstData pfData = new PetfirstData();
         lstReturn = pfData.GetReimbursement(enrollmentcode, typeid);
         if (lstReturn.Count > 0)
         {
             double defaultValue = 0;
             defaultValue = (from l in lstReturn
                             where l.IsDefault
                             select l.Amount).FirstOrDefault();
             if (defaultValue != 0)
             {
                 lstReturn.RemoveAll(x => x.IsDefault == false && x.Amount == defaultValue);
             }
             m_Cache.Add(cacheKey, lstReturn);
         }
         else if (!enrollmentcode.Equals(_defaultEnrollment))
         {
             lstReturn = pfData.GetReimbursement(_defaultEnrollment, typeid);
             if (lstReturn.Count > 0)
             {
                 double defaultValue = 0;
                 defaultValue = (from l in lstReturn
                                 where l.IsDefault
                                 select l.Amount).FirstOrDefault();
                 if (defaultValue != 0)
                 {
                     lstReturn.RemoveAll(x => x.IsDefault == false && x.Amount == defaultValue);
                 }
                 m_Cache.Add(cacheKey, lstReturn);
             }
         }
     }
     else
         lstReturn = (List<Reimbursement>)CachedList;
     return lstReturn;
 }
        private void DoRequote()
        {
            var planGroup = from p in mCustomer.MyPets
                            where p.Enrolled == true
                            group p by p.QuoteId into g
                            select g;
            PetfirstBL pfBL = new PetfirstBL();
            bool error = false;
            foreach (var pg in planGroup)
            {

                List<Pet> lstPets = (from p in mCustomer.MyPets
                                     where p.QuoteId == pg.Key
                                     select p).ToList();

                if (!pfBL.GetFastQuote(ref mCustomer, ref mthisPet, true))
                {
                    try
                    {
                        pfBL.GetMonthlyQuote(ref mCustomer, lstPets);

                        if (mCustomer.WebserviceErrorMsg.Equals(""))
                        {
                            //save to database
                            try
                            {
                                using (PetfirstData pfData = new PetfirstData())
                                {
                                    pfData.SaveCustomer(mCustomer);
                                    pfData.SaveEnrolledPlan(lstPets, mCustomer.PayFrequency);
                                }
                            }
                            catch (Exception ex)
                            {
                                displayError("Requote ", ex.ToString(), true);
                                error = true;
                            }
                            //get AnuallyQuote
                            try
                            {
                                pfBL.GetAnnualQuote(ref mCustomer, lstPets);
                            }
                            catch (Exception ex)
                            {
                                displayError("Requote ", ex.ToString(), true);
                                error = true;
                            }
                        }
                        else
                        {
                            displayError("Requote ", mCustomer.WebserviceErrorMsg, true);
                            error = true;
                        }
                    }
                    catch (Exception ex)
                    {
                        displayError("Requote ", ex.ToString(), true);
                        error = true;
                    }
                }
                if (error)
                    break;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            HandleMenuItems();
            bCurrentCustomer = false;

            if (!string.IsNullOrEmpty(Request.QueryString["current_customer"]))
            {
                bCurrentCustomer = true;
            }

            mCustomer = (PetfirstCustomer)Session["Customer"];
            mthisPet = (Pet)Session["Pet"];
            if (mCustomer == null)
            {
                Response.Redirect("Default.aspx", false);
                Context.ApplicationInstance.CompleteRequest();
            }
            else
            {
                if (!Page.IsPostBack)
                {
                    if (bCurrentCustomer)
                    {
                        chkInternetDiscount.Checked = mCustomer.DiscountInternetPurchase;
                        MilitaryBlock.Visible = mCustomer.DiscountMilitaryAvailable;
                        chkMilitary.Checked = mCustomer.DiscountMilitarySelected;
                        chkEmployeeGroup.Checked = mCustomer.DiscountEBEnrollmentCode;
                        txtEmployer.Text = mCustomer.EBEnrollmentCodeCompany;
                        VetBlock.Visible = mCustomer.DiscountVetAvailable;
                        chkVetEmp.Checked = mCustomer.DiscountVetSelected;
                        txtEmail.Text = mCustomer.MembershipInfo.Email;
                        load_militarybranches();
                        ddlBranch.SelectedIndex = mCustomer.MilitaryBranchID;
                        load_militarystatus();
                        rblServiceType.SelectedIndex = mCustomer.MilitaryStatusID;
                        bCurrentCustomer = true;

                    }
                    else
                    {
                        chkInternetDiscount.Checked = mCustomer.DiscountInternetPurchase;
                        PetfirstData pfData = new PetfirstData();
                        chkEmployeeGroup.Checked = mCustomer.DiscountEBEnrollmentCode = pfData.IsCorporateDiscount(mCustomer.EnrollmentCode);
                        MilitaryBlock.Visible = mCustomer.DiscountMilitaryAvailable;
                        VetBlock.Visible = mCustomer.DiscountVetAvailable;
                        load_militarystatus();
                        load_militarybranches();
                    }
                }

                this.Master.NumberofPets = mCustomer.MyPets.Count.ToString();
            }
        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            //quote price, put quoteid back to pets
            if (Page.IsValid)
            {
                if (mCustomer != null)
                {
                    //validation:
                    string pet1 = ddlPet1.SelectedValue;
                    string pet2 = string.Empty;
                    string pet3 = string.Empty;
                    bool bSamePet = false;
                    if (dvPet2.Visible && dvPet3.Visible)
                    {
                        pet2 = ddlPet2.SelectedValue;
                        pet3 = ddlPet3.SelectedValue;
                        if (pet1.Equals(pet2) || pet1.Equals(pet3) || pet2.Equals(pet3))
                            bSamePet = true;
                    }
                    else if (dvPet2.Visible)
                    {
                        pet2 = ddlPet2.SelectedValue;
                        if (pet1.Equals(pet2))
                            bSamePet = true;
                    }//dvpet3 cannot be visible if dvpet2 is not
                    if (bSamePet)
                    {
                        System.Text.StringBuilder sb = new System.Text.StringBuilder();
                        sb.Append(@"<script type='text/javascript'>");
                        sb.Append("$('#same_pet').modal('show');");
                        sb.Append(@"</script>");
                        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ShowSamePetModal", sb.ToString(), false);
                        return;
                    }
                    List<Pet> lstPets = (List<Pet>)Session["EditPlanPet"];
                    //need to reset the pets that are being edited.
                    if (lstPets != null)
                    {
                        foreach (Pet p in lstPets)
                        {
                            p.QuoteId = 0;
                            p.RecurringMonthPaymentTotal = 0;
                            p.RecurringMonthTax = 0;
                            p.PlanId = 0;
                            p.PlanName = string.Empty;
                            p.PlanType = "0";
                            p.FirstMonthPaymentTotal = 0;
                            p.FirstMonthTax = 0;
                            p.FirstMonthPremiumOnly = 0;
                            p.RecurringMonthPremiumOnly = 0;
                            p.AnnualPaymentTotal = 0;
                            //p.LeadId = "";//what commercial site doing currently- recreate lead when plan is removed//this is not correct, if the customer bought the policy, the old leadid not getting updated, they still get the spam email
                            ////kp: 2015-05-04 retrieve quote: logged exception bug fix--if multi-pets in a family plan, when they edit it and switch one pet to individual plan
                            ////and then later to edit the plan for remaining pets this will cause exception during bindingeditcontorl.
                            p.Enrolled = false;//if multi-pets in a family plan, when they edit to individual plan, need to force reselection of the remaining pet
                            p.QPlanId = 0;//if multi-pets in a family plan, when they edit to individual plan, they need to have its own qplanid
                            ////end 2015-05-04
                        }
                        Session.Remove("EditPlanPet");
                    }
                    mCustomer.WebserviceErrorMsg = "";
                    List<Pet> lstEnrollPets = new List<Pet>();
                    Pet p1 = (Pet)(from p in mCustomer.MyPets
                                   where p.PetName.Equals(ddlPet1.SelectedValue)
                                   select p).FirstOrDefault();
                    if (p1 != null)
                    {
                        SavePetAttributes(ref p1);
                        int planId = 0;
                        Int16 typeid = (short)(mCustomer.LifeTimeActive ? 2 : 1);
                        try
                        {
                            using (PetfirstData pfData = new PetfirstData())
                            {
                                //planId = pfData.GetPlanId(p1.LimitAmount, Int16.Parse(rblPlanType.SelectedValue));
                                planId = pfData.GetPlanId(p1.LimitAmount, typeid);
                                mCustomer.Underwriter = pfData.GetUnderwriterID(mCustomer.EnrollmentCode);
                                p1.PlanId = planId;
                                p1.QuoteId = 0;//reset
                                //p1.LeadId = "";
                                lstEnrollPets.Add(p1);

                                if (ddlPet2.Visible)
                                {
                                    Pet p2 = (Pet)(from p in mCustomer.MyPets
                                                   where p.PetName.Equals(ddlPet2.SelectedValue)
                                                   select p).FirstOrDefault();
                                    if (p2 != null)
                                    {
                                        SavePetAttributes(ref p2);
                                        p2.PlanId = planId;
                                        p2.QuoteId = 0;
                                        //p2.LeadId = "";
                                        lstEnrollPets.Add(p2);
                                    }
                                }
                                if (ddlPet3.Visible)
                                {
                                    if (ddlPet3.SelectedValue.Equals("0"))
                                    {
                                        Pet p3 = (Pet)(from p in mCustomer.MyPets
                                                       where p.PetName.Equals(ddlPet3.SelectedValue)
                                                       select p).FirstOrDefault();
                                        if (p3 != null)
                                        {
                                            SavePetAttributes(ref p3);
                                            p3.PlanId = planId;
                                            p3.QuoteId = 0;
                                            //p3.LeadId = "";
                                            lstEnrollPets.Add(p3);
                                        }
                                    }
                                }
                                int count = lstEnrollPets.Count;
                                foreach (Pet p in lstEnrollPets)
                                {
                                    p.IsFamilyPlan = count > 1;
                                }
                                PetfirstBL pfBl = new PetfirstBL();
                                try
                                {
                                    pfBl.GetMonthlyQuote(ref mCustomer, lstEnrollPets);
                                    if (mCustomer.WebserviceErrorMsg.Equals(""))
                                    {
                                        pfBl.GetAnnualQuote(ref mCustomer, lstEnrollPets);
                                        BindPetsRepeater();
                                        DetermineReviewQuoteStatus();
                                        ////kp: 2015-05-21 delete standard plan site wide
                                        //ToggleButtonActive(false);//default to lifetime
                                        PopulatePlanPanel();
                                        ////end 2015-05-21
                                        //need to rebind the right panel
                                        DetermineFamilyOrIndividualPlan();
                                        //ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "ScrollToPlanSum", "window.location = '#plansum';", false);//does not work
                                        //lead
                                        try
                                        {
                                            pfBl.StoreLeadCapture(ref mCustomer, lstEnrollPets);
                                        }
                                        catch { }
                                        try
                                        {
                                            pfData.SaveEnrolledPlan(lstEnrollPets, mCustomer.PayFrequency);
                                            pfData.LinkPlanForPet(lstEnrollPets);
                                        }
                                        catch (Exception ex)
                                        {
                                            displayError("Saving Enrolled Plan ", ex.ToString(), null);
                                        }

                                    }
                                    else
                                    {
                                        displayError("getting quote ", mCustomer.WebserviceErrorMsg, lblError);

                                    }
                                }
                                catch (Exception ex)
                                {
                                    displayError("getting quote ", ex.ToString(), lblError);
                                }
                            }
                        }
                        catch (Exception ex1)
                        {
                            displayError("getting quote ", ex1.ToString(), lblError);
                        }
                    }
                    else
                    {
                        lblError.Text = "No pets is selected.";
                    }
                }
            }
        }
        private void SaveInput()
        {
            mCustomer.HasStateChanged=false;
            mCustomer.HasKYAddressChanged=false;
            mCustomer.PayFrequency = short.Parse(rblPayFrequency.SelectedValue);
            //member info
            mCustomer.MembershipInfo.FirstName = txtFirstName.Text.Trim();
            mCustomer.MembershipInfo.LastName = txtLastName.Text.Trim();

            if (!ddlState.SelectedValue.Equals(mCustomer.MembershipInfo.StateId.ToString())) //Cusomter changed state since last quote
                mCustomer.HasStateChanged = true;
            else if (ddlState.SelectedValue.Equals("1")) //ky
            {
                if(!txtCity.Text.Trim().ToLower().Equals(mCustomer.MembershipInfo.City.ToLower()) ||!txtZip.Text.Trim().ToLower().Equals(mCustomer.MembershipInfo.Zip)||!txtAddress1.Text.Trim().ToLower().Equals(mCustomer.MembershipInfo.Address1.ToLower()) ||!txtAddress2.Text.Trim().ToLower().Equals(mCustomer.MembershipInfo.Address2.ToLower()))
                    mCustomer.HasKYAddressChanged=true;
            }
            mCustomer.MembershipInfo.Address1 = txtAddress1.Text.Trim();
            mCustomer.MembershipInfo.Address2 = txtAddress2.Text.Trim();
            mCustomer.MembershipInfo.City = txtCity.Text.Trim();
            mCustomer.MembershipInfo.StateId = int.Parse(ddlState.SelectedValue);
            mCustomer.MembershipInfo.State = ddlState.SelectedItem.Text;
            mCustomer.MembershipInfo.Zip = txtZip.Text.Trim();
            mCustomer.MembershipInfo.Phone = txtPhone.Text.Trim();
            mCustomer.MembershipInfo.Email = txtEmail.Text.Trim();

            //billing info

            mCustomer.BillingInfo.FirstName = txtBFirstName.Text.Trim();
            mCustomer.BillingInfo.LastName = txtBLastName.Text.Trim();
            mCustomer.BillingInfo.Address1 = txtBAddress1.Text.Trim();
            mCustomer.BillingInfo.Address2 = txtBAddress2.Text.Trim();
            mCustomer.BillingInfo.City = txtBCity.Text.Trim();
            mCustomer.BillingInfo.StateId = int.Parse(ddlBState.SelectedValue);
            mCustomer.BillingInfo.State = ddlBState.SelectedItem.Text;
            mCustomer.BillingInfo.Zip = txtBZip.Text;
            //billing same as member
            mCustomer.IsBillSameAsMembership = cbSameAsMember.Checked;
            // pets info need to be saved.

            //cc info
            mCustomer.CcNumber = txtCCNumber.Text;
            mCustomer.SecCode = txtSecCode.Text;
            mCustomer.ExpirationMonth = int.Parse(ddlMonth.SelectedValue);
            mCustomer.ExpirationYear = int.Parse(ddlYear.SelectedValue);
            Session["Customer"] = mCustomer;
            //save customer
            try
            {
                using (PetfirstData pfData = new PetfirstData())
                {
                    pfData.SaveCustomer(mCustomer);
                }
            }
            catch { }
        }
        private void DoRequote()
        {
            lblCheckoutError.Text = "";
            var planGroup = from p in mCustomer.MyPets
                            where p.Enrolled == true
                            group p by p.QuoteId into g
                            select g;
            PetfirstBL pfBL = new PetfirstBL();
            bool error = false;
            foreach (var pg in planGroup)
            {

                List<Pet> lstPets = (from p in mCustomer.MyPets
                                     where p.QuoteId == pg.Key
                                     select p).ToList();
                try
                {
                    pfBL.GetMonthlyQuote(ref mCustomer, lstPets);
                    if (!string.IsNullOrEmpty(mCustomer.WebserviceErrorMsg))
                    {
                        if (!mCustomer.WebserviceErrorMsg.ToLower().Contains("exception"))// not exception, display message directly
                            lblCheckoutError.Text += string.Format("Sorry, error occurred during requoting montly for {0}, error message:{1} <br />", GetPetName(lstPets), mCustomer.WebserviceErrorMsg);
                        else
                            displayCheckOutError(mCustomer.WebserviceErrorMsg, "re-quoting montly", lstPets);
                        error = true;
                    }
                    else
                    {
                        //save to database
                        try
                        {
                            using (PetfirstData pfData = new PetfirstData())
                            {
                                pfData.SaveCustomer(mCustomer);
                                pfData.SaveEnrolledPlan(lstPets, mCustomer.PayFrequency);
                            }
                        }
                        catch (Exception ex){
                            LoggingError("Checkout Requoting", ex.ToString());
                        }
                        //get AnuallyQuote
                        try {
                            pfBL.GetAnnualQuote(ref mCustomer, lstPets);
                            if (!string.IsNullOrEmpty(mCustomer.WebserviceErrorMsg))
                            {
                                if (!mCustomer.WebserviceErrorMsg.ToLower().Contains("exception"))// not exception, display message directly
                                    lblCheckoutError.Text += string.Format("Sorry, error occurred during requoting annualy for {0}, error message:{1} <br />", GetPetName(lstPets), mCustomer.WebserviceErrorMsg);
                                else
                                    displayCheckOutError(mCustomer.WebserviceErrorMsg, "re-quoting annualy", lstPets);
                                error = true;
                            }
                        }
                        catch (Exception ex)
                        {
                            displayCheckOutError(ex.ToString(), "re-quoting annualy", lstPets);
                            error = true;
                        }
                    }
                }
                catch (Exception ex)
                {
                    displayCheckOutError(ex.ToString(), "re-quoting montly", lstPets);
                    error = true;
                }
                if (error)
                    break;
            }
            if (!error)
            {
                BindPlanRepeater();
                CalculateTotals();
            }
        }
        protected void btnCheckout_Click(object sender, EventArgs e)
        {
            if (Page.IsValid)
            {
                //add validation for expiration date
                bool IsExpirationValid = false;
                DateTime today = DateTime.Today;
                DateTime dtExpire = DateTime.Parse(ddlMonth.SelectedValue + "/" + ddlYear.SelectedValue);
                if (dtExpire.Year > today.Year)
                    IsExpirationValid = true;
                else if (dtExpire.Year == today.Year && dtExpire.Month >= today.Month)
                    IsExpirationValid = true;
                if (!IsExpirationValid)
                {
                    lblCheckoutError.Text = "Card has expired";
                    return;
                }
                if (mCustomer != null)
                {
                    SaveInput();
                    if (mCustomer.HasStateChanged)
                    {
                        DoRequote();
                        List<Pet> myPet = new List<Pet>();
                        foreach (Pet p in mCustomer.MyPets)
                        {
                            myPet.Add(p);
                        }
                        FakeMultiPet(ref myPet);
                        CreatePetsTable(myPet);
                        CalculateTotals();

                    }
                    else if (mCustomer.HasKYAddressChanged)//kentucky, need requote
                    {
                        DoRequote();
                        List<Pet> myPet = new List<Pet>();
                        foreach (Pet p in mCustomer.MyPets)
                        {
                            myPet.Add(p);
                        }
                        FakeMultiPet(ref myPet);
                        CreatePetsTable(myPet);
                        CalculateTotals();
                    }
                    else//create policy
                    {
                        lblCheckoutError.Text = "";
                        bool error = false;
                        var planGroup = from p in mCustomer.MyPets
                                        where p.Enrolled == true
                                        group p by p.QuoteId into g
                                        select g;
                        PetfirstBL pfBL = new PetfirstBL();
                        int count = planGroup.Count();
                        foreach (var pg in planGroup)
                        {
                            List<Pet> lstPets2 = (from p in mCustomer.MyPets
                                                 where p.QuoteId == pg.Key
                                                 select p).ToList();
                            if (string.IsNullOrEmpty(lstPets2[0].PolicyNumber))//no policy is created for the batch yet
                            {
                                try
                                {
                                    foreach (Pet p in lstPets2)
                                    {
                                        List<Pet> lstPets = new List<Pet>();
                                        lstPets.Add(p);
                                        pfBL.CreatePolicy(ref mCustomer, lstPets);
                                        if (!string.IsNullOrEmpty(mCustomer.WebserviceErrorMsg))
                                        {
                                            if (!mCustomer.WebserviceErrorMsg.ToLower().Contains("exception"))// not exception, display message directly
                                                lblCheckoutError.Text += string.Format("Sorry, error occurred during creating policy for {0}, error message:{1} <br />", GetPetName(lstPets), mCustomer.WebserviceErrorMsg);
                                            else
                                                displayCheckOutError(mCustomer.WebserviceErrorMsg, "creating policy", lstPets);
                                            error = true;
                                        }
                                        else//policy is created for the batch
                                        {
                                            try
                                            {
                                                pfBL.StoreLeadCapture(ref mCustomer, lstPets);//update lead capture with policy number
                                            }
                                            catch { }
                                            //save to database
                                            try
                                            {
                                                using (PetfirstData pfData = new PetfirstData())
                                                {
                                                    pfData.SaveEnrolledPlan(lstPets, mCustomer.PayFrequency);
                                                }

                                            }
                                            catch (Exception ex)
                                            {
                                                LoggingError("Update QPlan after policy created", ex.ToString());
                                            }

                                            lblCheckoutError.Text += string.Format("Policy:#{0} has created for {1} <br />", lstPets[0].PolicyNumber, lstPets[0].PetName);
                                        }
                                    }
                                }
                                catch (Exception ex)
                                {
                                    displayCheckOutError(ex.ToString(), "creating policy", lstPets2);
                                    error = true;
                                }
                            }
                            if (error)
                                break;

                        }
                        if (!error)
                        {
                            var policyGroup = (from p in mCustomer.MyPets
                                               where !string.IsNullOrEmpty(p.PolicyNumber)
                                               select p.PolicyNumber).Distinct();
                            if (policyGroup.Count() == count) //all policy is created
                            {
                                Response.Redirect("Confirmation.aspx", false);
                                Context.ApplicationInstance.CompleteRequest();
                            }
                        }
                    }
                }
            }
        }
 public List<Limit> GetLimit(string enrollmentcode, short typeid, int stateID, int underwriter)
 {
     string cacheKey = string.Concat("$Limit_ec_type$", enrollmentcode, "_", typeid);
     object CachedList = m_Cache.Get(cacheKey) as List<Limit>;
     List<Limit> lstReturn = null;
     //if (CachedList == null)//get from the service
     {
         PetfirstData pfData = new PetfirstData();
         lstReturn = pfData.GetLimit(enrollmentcode, typeid, stateID, underwriter);
         if (lstReturn.Count > 0)
         {
             //list has dup because of IsDefault is pulled
             //process list to get rid of dup
             decimal defaultValue = 0;
             defaultValue = (from l in lstReturn
                                     where l.IsDefault
                                     select l.Amount).FirstOrDefault();
             if (defaultValue != 0)
             {
                 lstReturn.RemoveAll(x => x.IsDefault == false && x.Amount == defaultValue);
             }
             m_Cache.Add(cacheKey, lstReturn);
         }
         else if (!enrollmentcode.Equals(_defaultEnrollment))
         {
             lstReturn = pfData.GetLimit(_defaultEnrollment, typeid, stateID, underwriter);
             if (lstReturn.Count > 0)
             {
                 decimal defaultValue = 0;
                 defaultValue = (from l in lstReturn
                                 where l.IsDefault
                                 select l.Amount).FirstOrDefault();
                 if (defaultValue != 0)
                 {
                     lstReturn.RemoveAll(x => x.IsDefault == false && x.Amount == defaultValue);
                 }
                 m_Cache.Add(cacheKey, lstReturn);
             }
         }
     }
     //else
        // lstReturn = (List<Limit>)CachedList;
     return lstReturn;
 }
 public List<PlanType> GetPlanType(string enrollmentcode)
 {
     string cacheKey = string.Concat("$Plan_ec$",enrollmentcode);
     object CachedList = m_Cache.Get(cacheKey) as List<PlanType>;
     List<PlanType> lstReturn = null;
     //if (CachedList == null)//get from the service
     {
         PetfirstData pfData = new PetfirstData();
         lstReturn = pfData.GetPlanTypeByEnrollmentCode(enrollmentcode);
         if (lstReturn.Count > 0)
             m_Cache.Add(cacheKey, lstReturn);
         else if (!enrollmentcode.Equals(_defaultEnrollment))
         {
             lstReturn = pfData.GetPlanTypeByEnrollmentCode(_defaultEnrollment);
             if (lstReturn.Count > 0)
                 m_Cache.Add(cacheKey, lstReturn);
         }
     }
     //else
        // lstReturn = (List<PlanType>)CachedList;
     return lstReturn;
 }
        protected void btnContinue_Click(object sender, EventArgs e)
        {
            bool bDiscountsChanged = false;
            bool bQuoteError = false;

            try
            {
                string url = "customizeplan.aspx";
                mCustomer.MembershipInfo.Email = txtEmail.Text;

                //Need to check each one to see if they are same as coming in
                //Important!! If they change something, it has to change for all pets!

                if (mCustomer.DiscountInternetPurchase != chkInternetDiscount.Checked)
                {
                    bDiscountsChanged = true;
                    mCustomer.DiscountInternetPurchase = chkInternetDiscount.Checked;
                }

                if (mCustomer.DiscountEBEnrollmentCode != chkEmployeeGroup.Checked)
                {
                    bDiscountsChanged = true;
                    mCustomer.DiscountEBEnrollmentCode = chkEmployeeGroup.Checked;
                }

                if (mCustomer.DiscountVetSelected != chkVetEmp.Checked)
                {
                    bDiscountsChanged = true;
                    mCustomer.DiscountVetSelected = chkVetEmp.Checked;
                }

                if (mCustomer.DiscountMilitarySelected != chkMilitary.Checked)
                {
                    bDiscountsChanged = true;
                    mCustomer.DiscountMilitarySelected = chkMilitary.Checked;
                }

                if (chkEmployeeGroup.Checked && mCustomer.EnrollmentCode == "99-99-00-9998")
                {
                    //set this up for the generic enrollment code.
                    mCustomer.EnrollmentCode = "99-99-18-6232";
                    mCustomer.EBEnrollmentCodeCompany = txtEmployer.Text.ToString();
                }

                if (chkMilitary.Checked)
                {
                    mCustomer.MilitaryBranchID = (short) ddlBranch.SelectedIndex;
                    mCustomer.MilitaryStatusID = (short) rblServiceType.SelectedIndex;
                }

                if (!bCurrentCustomer)
                {
                    mthisPet.DeductibleAmount = 250;
                    mthisPet.LimitAmount = 5000;
                    mthisPet.Reimbursement = .8m;
                    mthisPet.RiderName = "";
                    mthisPet.Routine = "";
                }

                int planId = 0;
                Int16 typeid = (short)(mCustomer.LifeTimeActive ? 2 : 1);

                PetfirstData pfData = new PetfirstData();
                {
                    planId = pfData.GetPlanId(mthisPet.LimitAmount, typeid);
                    mCustomer.Underwriter = pfData.GetUnderwriterID(mCustomer.EnrollmentCode);

                    //Save our data//
                    //mCustomer.MyPets.Add(mthisPet);
                    pfData.SaveCustomer(mCustomer);
                }

                PetfirstBL pfBl = new PetfirstBL();
                List<Pet> lstEnrollPet = new List<Pet>();
                lstEnrollPet.Add(mthisPet);

                //Now if something has changed we have to go back and
                if (bDiscountsChanged && mCustomer.MyPets.Count > 0)
                {
                    DoRequote();
                }

                try
                {
                    mthisPet.PlanId = planId;
                    mthisPet.QuoteId = 0;

                    if (!pfBl.GetFastQuote(ref mCustomer, ref mthisPet, true))
                    {

                        pfBl.GetMonthlyQuote(ref mCustomer, lstEnrollPet);

                        if (mCustomer.WebserviceErrorMsg.Equals(""))
                        {
                            pfBl.GetAnnualQuote(ref mCustomer, lstEnrollPet);
                        }
                        else
                        {
                            displayError("getting quote ", mCustomer.WebserviceErrorMsg, true);
                            bQuoteError = true;
                        }
                    }

                }
                catch(Exception ex)
                {
                    displayError("getting quote ", ex.ToString(), true);
                    bQuoteError = true;
                }

                //mCustomer.MyPets.Add(mthisPet);
                pfData.SaveCustomer(mCustomer);

                if (!bQuoteError)
                {
                    Response.Redirect(url, false);
                    Context.ApplicationInstance.CompleteRequest();
                }

                try
                {
                    pfBl.StoreLeadCapture(ref mCustomer, lstEnrollPet);
                }
                catch { }
            }
            catch  { }
        }
 public List<Rider> GetRider(string enrollmentcode, short typeid)
 {
     string cacheKey = string.Concat("$Rider_ec$", enrollmentcode,"_", typeid);
     object CachedList = m_Cache.Get(cacheKey) as List<Rider>;
     List<Rider> lstReturn = null;
     if (CachedList == null)//get from the service
     {
         PetfirstData pfData = new PetfirstData();
         lstReturn = pfData.GetRiderByEnrollmentCode(enrollmentcode, typeid);
         if (lstReturn.Count > 0)
             m_Cache.Add(cacheKey, lstReturn);
         else if (!enrollmentcode.Equals(_defaultEnrollment))
         {
             lstReturn = pfData.GetRiderByEnrollmentCode(_defaultEnrollment, typeid);
             if (lstReturn.Count > 0)
                 m_Cache.Add(cacheKey, lstReturn);
         }
     }
     else
         lstReturn = (List<Rider>)CachedList;
     return lstReturn;
 }
        private void RecalculatePlan()
        {
            int planId = 0;
            Int16 typeid = (short)(mCustomer.LifeTimeActive ? 2 : 1);

            using (PetfirstData pfData = new PetfirstData())
            {
                planId = pfData.GetPlanId(mthisPet.LimitAmount, typeid);
                mCustomer.Underwriter = pfData.GetUnderwriterID(mCustomer.EnrollmentCode);
                mthisPet.PlanId = planId;

                mthisPet.QuoteId = 0;

            }

            PetfirstBL pfBl = new PetfirstBL();
            try
            {
                if (!pfBl.GetFastQuote(ref mCustomer, ref mthisPet, false))
                {
                    List<Pet> lstEnrollPet = new List<Pet>();
                    lstEnrollPet.Add(mthisPet);

                    pfBl.GetMonthlyQuote(ref mCustomer, lstEnrollPet);

                    if (mCustomer.WebserviceErrorMsg.Equals(""))
                    {
                        pfBl.GetAnnualQuote(ref mCustomer, lstEnrollPet);
                    }
                    else
                    {
                        displayError("Recalc ", mCustomer.WebserviceErrorMsg, true);
                    }
                }
            }
            catch (Exception ex)
            {
                displayError("Requote ", ex.ToString(), true);
            }

            UpdateLabels();
        }
 private void GetPhoneNumber()
 {
     try
     {
         using (PetfirstData pfData = new PetfirstData())
         {
             mCustomer.CallCenter = pfData.GetPhoneNumber(mCustomer.EnrollmentCode);
         }
     }
     catch (Exception ex)
     {
         DisplayError("Getting phone number by enrollment", ex.ToString(), true);
     }
 }
        private bool LoadCustomerInfo(ref PetfirstCustomer mCustomer, string scustomerLookup)
        {
            bool bReturn = true;
            SqlConnection con = GetConnection();
            SqlDataReader sdr = null;
            SqlCommand cmd = new SqlCommand("usp_pricecompare_tmpcustomer_get_by_customer_id", con);

            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@customer_id", SqlDbType.BigInt));
            cmd.Parameters["@customer_id"].Value = Int32.Parse(scustomerLookup);

            try
            {
                con.Open();
                sdr = cmd.ExecuteReader();

                while (sdr.Read())
                {
                    mCustomer.MembershipInfo.FirstName = sdr.GetString(CTFIRSTNAME);
                    mCustomer.MembershipInfo.LastName = sdr.GetString(CTLASTNAME);
                    mCustomer.EnrollmentCode = sdr.GetString(CTENROLLMENTCODE);

                    using (PetfirstData pfData = new PetfirstData())
                    {
                        mCustomer.CallCenter = pfData.GetPhoneNumber(mCustomer.EnrollmentCode);
                    }

                    mCustomer.MembershipInfo.Email = sdr.GetString(CTEMAIL);
                    mCustomer.MembershipInfo.Zip = sdr.GetString(CTZIP);
                    mCustomer.MembershipInfo.Phone = sdr.GetString(CTPHONE);

                    if ((sdr.GetString(CTPAYFREQUENCY)).ToString().Contains("monthly") == true)
                    {
                        mCustomer.PayFrequency = 1;
                    }
                    else
                    {
                        mCustomer.PayFrequency = 2;
                    }

                    CoreServiceClient csc = new CoreServiceClient();
                    CoreServiceGetStateByZipResponse resp = csc.GetStateByZip(mCustomer.MembershipInfo.Zip);
                    if (string.IsNullOrEmpty(resp.Error.ErrorText))
                    {
                        mCustomer.MembershipInfo.StateId = resp.State.Id;
                        mCustomer.MembershipInfo.City = resp.State.CityName;
                        mCustomer.MembershipInfo.State = resp.State.StateName;
                    }

                    Pet myPet = new Pet();

                    myPet.Birthday = sdr.GetDateTime(CTPETBIRTHDAY);
                    myPet.ColorId = 146; //Any Breed//
                    myPet.ColorName = "Any";

                    if ((sdr.GetString(CTSPECIESNAME)).ToString().Contains("dog") == true)
                    {
                        myPet.SpeciesId = 1;
                        myPet.SpeciesName = "Dog";
                    }
                    else
                    {
                        myPet.SpeciesId = 2;
                        myPet.SpeciesName = "Cat";
                    }

                    myPet.BreedId = sdr.GetInt32(CTBREEDID);
                    myPet.WeightId = sdr.GetByte(CTWEIGHTID);
                    myPet.PetName = sdr.GetString(CTPETNAME);
                    myPet.GenderFull = sdr.GetString(CTPETGENDER);
                    myPet.GenderFull.Trim();

                    if (myPet.GenderFull.Contains("female"))
                    {
                        myPet.Gender = "F";
                    }
                    else
                    {
                        myPet.Gender = "M";
                    }

                    myPet.DeductibleAmount = sdr.GetDecimal(CTDEDUCTIBLE);
                    myPet.Reimbursement = sdr.GetDecimal(CTREIMBURSEMENT);
                    myPet.SpayedOrNeutered = sdr.GetBoolean(CTSPAYORNEUTER);
                    //stored procedure will take care of figuring out if this is true or not.
                    mCustomer.DiscountVetAvailable = true;
                    mCustomer.DiscountMilitaryAvailable = true;
                    mCustomer.DiscountMilitarySelected = sdr.GetBoolean(CTMILITARY);
                    mCustomer.DiscountVetSelected = sdr.GetBoolean(CTVETPROFFESIONAL);

                    mCustomer.MyPets.Add(myPet);

                    try
                    {
                        using (PetfirstData pfData = new PetfirstData())
                        {
                            pfData.SaveCustomer(mCustomer);
                        }
                    }
                    catch
                    {
                        throw;
                    }

                }

                con.Close();
            }
            catch (Exception ex)
            {
                bReturn = false;
                LoggingError(ex.Message, ex.StackTrace);
            }
            finally
            {
                if (con != null)
                {
                    con.Close();
                    con.Dispose();
                    con = null;
                }
                if (cmd != null)
                {
                    cmd.Dispose();
                    cmd = null;
                }
            }

            return (bReturn);
        }