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");
 }
        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  { }
        }
        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;
            }
        }
        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();
            }
        }
        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);
        }