public List<Breed> GetBreedList(int sid, PetfirstCustomer mCustomer)
        {
            List<Breed> lstReturn = null;
            string cacheKey = string.Concat("$BreedList_sid$" ,sid);
            object CachedList = m_Cache.Get(cacheKey) as List<Breed>;
            if (CachedList == null)//get from the service
            {
                CoreServiceReference.CoreServiceClient cs = new CoreServiceClient();
                CoreServiceGetBreedListRequest cRequest = new CoreServiceGetBreedListRequest();
                cRequest.SpeciesId = sid;
                CoreServiceGetBreedListResponse cbResponse = cs.GetBreedList(cRequest);
                //insert select breed on the top
                if (string.IsNullOrEmpty(cbResponse.Error.ErrorText))//check error
                {

                    if (cbResponse.Breeds != null)
                    {
                        lstReturn = ModifyMixedBreed(sid, cbResponse.Breeds);
                        m_Cache.Add(cacheKey, lstReturn);
                    }
                }
                else
                {
                    lstReturn = null;
                    LogException le = new LogException();
                    try
                    {

                        le.LogError(HttpContext.Current.Request.Url.AbsoluteUri, "Error during getting breed list", cbResponse.Error.ErrorText, mCustomer);
                        ///Test email server
                        //le.SendErrorEmail(string.Concat(Request.Url.AbsoluteUri, "<br/><hr />", msg, "<hr />User Input:", le.BuildUserDataString(mCustomer)));
                    }
                    catch (Exception ex)
                    {
                        ///Test email server
                        //lblError.Text = ex.ToString();
                        try
                        {
                            le.SendErrorEmail(string.Concat(HttpContext.Current.Request.Url.AbsoluteUri, "<br/><hr />", ex.Message, "<br />StackTrace: ", ex.StackTrace, "<br /><hr />User Input:", le.BuildUserDataString(mCustomer)));
                        }
                        catch { }
                    }
                }
            }
            else
            {
                lstReturn = (List<Breed>)CachedList;
            }
            return lstReturn;
        }
        public PetColor[] GetColorList(PetfirstCustomer mCustomer)
        {
            PetColor[] lstReturn = null;
            string cacheKey = "$ColorList$";
            object CachedList = m_Cache.Get(cacheKey) as PetColor[];
            if (CachedList == null)//get from the service
            {
                CoreServiceReference.CoreServiceClient cs = new CoreServiceClient();
                CoreServiceGetColorListResponse ccResponse = cs.GetColorList();
                //insert select breed on the top
                if (string.IsNullOrEmpty(ccResponse.Error.ErrorText))//check error
                {
                    if (ccResponse.Colors !=null)
                    {
                        lstReturn = ccResponse.Colors;
                        m_Cache.Add(cacheKey, lstReturn);
                    }
                }
                else
                {
                    lstReturn = null;
                    LogException le = new LogException();
                    try
                    {

                        le.LogError(HttpContext.Current.Request.Url.AbsoluteUri, "Error during getting color list", ccResponse.Error.ErrorText, mCustomer);
                        ///Test email server
                        //le.SendErrorEmail(string.Concat(Request.Url.AbsoluteUri, "<br/><hr />", msg, "<hr />User Input:", le.BuildUserDataString(mCustomer)));
                    }
                    catch (Exception ex)
                    {
                        ///Test email server
                        //lblError.Text = ex.ToString();
                        try
                        {
                            le.SendErrorEmail(string.Concat(HttpContext.Current.Request.Url.AbsoluteUri, "<br/><hr />", ex.Message, "<br />StackTrace: ", ex.StackTrace, "<br /><hr />User Input:", le.BuildUserDataString(mCustomer)));
                        }
                        catch { }
                    }
                }
            }
            else
            {
                lstReturn = (PetColor[])CachedList;
            }
            return lstReturn;
        }
 private QuoteServiceReference.Customer CreateQuoteCustomer(PetfirstCustomer mCustomer)
 {
     return new QuoteServiceReference.Customer()
     {
         FirstName = mCustomer.MembershipInfo.FirstName,
         LastName = mCustomer.MembershipInfo.LastName,
         StreetAddress = mCustomer.MembershipInfo.Address1,
         StreetAddress2 = mCustomer.MembershipInfo.Address2,
         CityName = mCustomer.MembershipInfo.City,
         StateId = mCustomer.MembershipInfo.StateId,
         ZipCode = mCustomer.MembershipInfo.Zip,
         EmailAddress = mCustomer.MembershipInfo.Email,
         HomePhone = mCustomer.MembershipInfo.Phone,
         MobilePhone = String.Empty,
         WorkPhone = String.Empty
     };
 }
        private void SetQuoteOtherAttributes(ref QuoteServiceCreateNewQuoteRequest qRequest, PetfirstCustomer mCustomer, List<Pet> lstPets,bool bMontly)
        {
            qRequest.UnderwriterID = mCustomer.Underwriter;
            qRequest.IncludeRoutine = false;
            qRequest.IncludeRoutine125 = false;
            qRequest.IncludeRoutine250 = false;
            qRequest.IncludeRoutine400 = false;
            qRequest.MilitaryDiscount = mCustomer.DiscountMilitarySelected;
            qRequest.InternetDiscount = mCustomer.DiscountInternetPurchase;
            qRequest.VetDiscount = mCustomer.DiscountVetSelected;

            if (!lstPets[0].Routine.ToLower().Equals("0"))
            {
                qRequest.IncludeRoutine = true;
                switch (lstPets[0].Routine.ToLower())
                {
                    case "routine125":
                        qRequest.IncludeRoutine125 = true;
                        break;
                    case "routine250":
                        qRequest.IncludeRoutine250 = true;
                        break;
                    case "routine400": qRequest.IncludeRoutine400 = true;
                        break;

                }
            }
            qRequest.PlanId = lstPets[0].PlanId;
            if (bMontly)
                qRequest.PaymentFrequencyId = 1;//1 monthly, 2: annually
            else
                qRequest.PaymentFrequencyId = 2;
            qRequest.IncludeBreeders = lstPets[0].Breeder;

            if(lstPets[0].Hereditary.ToLower().Equals("hereditary100"))
            {
              qRequest.IncludeHereditary100 =true;
            }
            else if (lstPets[0].Hereditary.ToLower().Equals("hereditary25"))
            {
                qRequest.IncludeHereditary25 = true;
            }
            else
            {
                qRequest.IncludeHereditary100 = false;
                qRequest.IncludeHereditary25 = false;

            }
            qRequest.IncludePrescriptionFood = lstPets[0].PrescriptionFood;
            qRequest.KrogerLoyaltyNumber = String.Empty;
            qRequest.EnrollmentCode = mCustomer.EnrollmentCode;
            qRequest.Deductible = lstPets[0].DeductibleAmount;
            qRequest.CoInsurance = 1-lstPets[0].Reimbursement;
            qRequest.UnderwriterID = mCustomer.Underwriter;

            try
            {

                int nPlan = lstPets[0].PlanId;
                qRequest.FilingID = (from pts in context.v_PlansToStates
                                     where pts.stateProvinceID.Equals(mCustomer.MembershipInfo.StateId) &&
                                         pts.UnderwriterID.Equals(mCustomer.Underwriter) &&
                                         pts.plan_id == nPlan
                                     select pts.FilingID).First();
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        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);
        }
        public void StoreLeadCapture(ref PetfirstCustomer mCustomer, List<Pet> lstPets)
        {
            //lead capture
            string[,] petData = new string[3, 5] { { "", "", "", "", "" }, { "", "", "", "", "" }, { "", "", "", "", "" } };
            int count = lstPets.Count;
            if (count == 1)
            {
                SetLeadPet1(ref petData, lstPets);
            }
            else if (count == 2)
            {
                SetLeadPet2(ref petData, lstPets);
            }
            else if (count ==3)
            {
                SetLeadPet3(ref petData, lstPets);
            }
            decimal reimbursement = 0;
            decimal dedcutible = 0;
            decimal coverage = 0;
            int quoteId = 0;
            string planName = "";
            string policyNumber = "";
            string leadId = "";
            Int64 policyId = 0;
            foreach(Pet pet in lstPets)//only create one lead
            {
                reimbursement = pet.Reimbursement;
                dedcutible = pet.DeductibleAmount;
                coverage = pet.LimitAmount;
                quoteId = pet.QuoteId;
                planName = pet.PlanName;
                policyNumber = pet.PolicyNumber;
                leadId = pet.LeadId;
                policyId = pet.PolicyId;
                break;
            }
            LeadCaptureServiceStoreLeadCaptureRequest lRequest = new LeadCaptureServiceStoreLeadCaptureRequest()
            {
                Email = mCustomer.MembershipInfo.Email,
                //ExtensionData = null,
                City = !String.IsNullOrEmpty(mCustomer.MembershipInfo.City) ? mCustomer.MembershipInfo.City : "",
                Company = "PetFirst Web",
                EnrollmentCode = mCustomer.EnrollmentCode,
                PlanCopay = reimbursement != 0m ? ((1 - reimbursement) * 100).ToString() : null,
                PlanDeductible = dedcutible != 0m ? dedcutible.ToString() : null,
                Coverage = coverage != -0m ? coverage.ToString("C0") : null,
                PlanSelected = planName,
                EmailNow = false, //what value??
                FirstName = mCustomer.MembershipInfo.FirstName,
                LastName = mCustomer.MembershipInfo.LastName,
                LoyaltyCard = string.Empty,
                PaymentType = mCustomer.PayFrequency.ToString(),
                Pet1Name = petData[0, 0],
                Pet1BDay = petData[0, 1],
                Pet1Breed = petData[0, 2],
                Pet1Species = petData[0, 3],
                Pet1Gender = petData[0, 4],
                Pet2Name = petData[1, 0],
                Pet2BDay = petData[1, 1],
                Pet2Breed = petData[1, 2],
                Pet2Species = petData[1, 3],
                Pet2Gender = petData[1, 4],
                Pet3Name = petData[2, 0],
                Pet3BDay = petData[2, 1],
                Pet3Breed = petData[2, 2],
                Pet3Species = petData[2, 3],
                Pet3Gender = petData[2, 4],
                PetsCovered = count.ToString(),
                PhoneNumber = mCustomer.MembershipInfo.Phone,
                //PolicyId = policyNumber,
                PolicyId = policyId.ToString(),
                QuoteId = quoteId.ToString(),
                State = mCustomer.MembershipInfo.StateId != 0 ? mCustomer.MembershipInfo.StateId.ToString() : null,
                StreetAddress1 = mCustomer.MembershipInfo.Address1,
                StreetAddress2 = mCustomer.MembershipInfo.Address2,
                ZipCode = mCustomer.MembershipInfo.Zip,
                PolicySold = !String.IsNullOrEmpty(policyNumber),
                LeadId = leadId
            };
            Lead_CaptureServiceClient lsClient = new Lead_CaptureServiceClient();
            try
            {

                LeadCaptureServiceStoreLeadCaptureResponse response = lsClient.InsertLeadCapture(lRequest);
                if (string.IsNullOrEmpty(response.Error.ErrorText))
                {
                    foreach (Pet pet in lstPets)//only create one lead
                    {
                        pet.LeadId = response.LeadId;
                    }
                    mCustomer.WebserviceErrorMsg = "";
                }
                else
                {
                    mCustomer.WebserviceErrorMsg = response.Error.ErrorText;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                try
                {
                    if (lsClient.State == CommunicationState.Faulted)
                        lsClient.Abort();
                    else if(lsClient.State == CommunicationState.Opened)
                        lsClient.Close();
                }
                catch { }
            }
        }
        public string BuildUserDataString(PetfirstCustomer mCustomer)
        {
            StringBuilder sb = null;
            if (mCustomer != null)
            {
                //capture the user input data
                sb = new StringBuilder(3000);
                sb.Append(string.Concat("Enrollment:", mCustomer.EnrollmentCode,","));
                if (mCustomer.MyPets != null)
                {
                    int i = 1;
                    foreach (Pet pet in mCustomer.MyPets)
                    {
                        sb.Append(string.Concat("Pet",i,"Name:", pet.PetName, ","));
                        sb.Append(string.Concat("Pet",i,"Species:", pet.SpeciesId.ToString(), ","));
                        sb.Append(string.Concat("Pet",i,"bDay:", pet.Birthday.ToShortDateString(), ","));
                        sb.Append(string.Concat("Pet",i,"Breed:", pet.BreedId.ToString(), ","));
                        if (pet.LimitAmount != 0)
                            sb.Append(string.Concat("Pet", i, "Limit:", pet.LimitAmount.ToString("C0"), ","));
                        if (pet.DeductibleAmount != 0)
                            sb.Append(string.Concat("Pet", i, "Deductible:", pet.DeductibleAmount.ToString("C0"), ","));
                        if (pet.Reimbursement != 0)
                        {
                            sb.Append(string.Concat("Pet", i, "Copay:", pet.Reimbursement.ToString("0%"), ","));
                            sb.Append(string.Concat("Pet", i, "Routine:", pet.Routine.ToString(), ","));
                            sb.Append(string.Concat("Pet", i, "PlanId:", pet.PlanId.ToString(), ","));
                        }
                        i++;
                    }

                }

                if (!string.IsNullOrEmpty(mCustomer.MembershipInfo.FirstName))
                    sb.Append(string.Concat("MemberFirstName:", mCustomer.MembershipInfo.FirstName, ","));
                if (!string.IsNullOrEmpty(mCustomer.MembershipInfo.LastName))
                    sb.Append(string.Concat("MemberLastName:", mCustomer.MembershipInfo.LastName, ","));
                if (!string.IsNullOrEmpty(mCustomer.MembershipInfo.Address1))
                    sb.Append(string.Concat("MemberAddress1:", mCustomer.MembershipInfo.Address1, ","));
                if (!string.IsNullOrEmpty(mCustomer.MembershipInfo.Address2))
                    sb.Append(string.Concat("MemberAddress2:", mCustomer.MembershipInfo.Address2, ","));
                if (!string.IsNullOrEmpty(mCustomer.MembershipInfo.City))
                    sb.Append(string.Concat("MemberCity:", mCustomer.MembershipInfo.City, ","));
                if( mCustomer.MembershipInfo.StateId!=0)
                    sb.Append(string.Concat("MemberStateId:", mCustomer.MembershipInfo.StateId.ToString(), ","));
                if(!string.IsNullOrEmpty(mCustomer.MembershipInfo.Zip))
                    sb.Append(string.Concat("MemberZip:", mCustomer.MembershipInfo.Zip, ","));
                if (!string.IsNullOrEmpty(mCustomer.MembershipInfo.Phone))
                    sb.Append(string.Concat("MemberPhone:", mCustomer.MembershipInfo.Phone, ","));
                if (!string.IsNullOrEmpty(mCustomer.MembershipInfo.Email))
                    sb.Append(string.Concat("MemberEmail:", mCustomer.MembershipInfo.Email, ","));
                if (!mCustomer.IsBillSameAsMembership)
                {
                    if (!string.IsNullOrEmpty(mCustomer.BillingInfo.FirstName))
                        sb.Append(string.Concat("BillingFirstName:", mCustomer.BillingInfo.FirstName, ","));
                    if (!string.IsNullOrEmpty(mCustomer.BillingInfo.LastName))
                        sb.Append(string.Concat("BillingLastName:", mCustomer.BillingInfo.LastName, ","));
                    if (!string.IsNullOrEmpty(mCustomer.BillingInfo.Address1))
                        sb.Append(string.Concat("BillingAddress1:", mCustomer.BillingInfo.Address1, ","));
                    if (!string.IsNullOrEmpty(mCustomer.BillingInfo.Address2))
                        sb.Append(string.Concat("BillingAddress2:", mCustomer.BillingInfo.Address2, ","));
                    if (!string.IsNullOrEmpty(mCustomer.BillingInfo.City))
                        sb.Append(string.Concat("BillingCity:", mCustomer.BillingInfo.City, ","));
                    if (mCustomer.BillingInfo.StateId != 0)
                        sb.Append(string.Concat("BillingStateId:", mCustomer.BillingInfo.StateId.ToString(), ","));
                    if (!string.IsNullOrEmpty(mCustomer.BillingInfo.Zip))
                        sb.Append(string.Concat("BillingZip:", mCustomer.BillingInfo.Zip, ","));
                }
                if (!string.IsNullOrEmpty(mCustomer.CcNumber))
                    sb.Append(string.Concat("CC:", GetCCLast4(mCustomer.CcNumber), ","));
                if (!string.IsNullOrEmpty(mCustomer.SecCode))
                    sb.Append(string.Concat("Cvv2:", mCustomer.SecCode, ","));
                if (mCustomer.ExpirationMonth != 0)
                    sb.Append(string.Concat("CCExpireMonth:", mCustomer.ExpirationMonth.ToString(), ","));
                if (mCustomer.ExpirationYear != 0)
                    sb.Append(string.Concat("CCExpireYear:", mCustomer.ExpirationYear.ToString(), ","));
                if (mCustomer.PayFrequency != 0)
                    sb.Append(string.Concat("PaymentFrequency:", mCustomer.PayFrequency.ToString()));
                if (mCustomer.GiftCards != null)
                {
                    int i = 1;
                    foreach (GiftCard gc in mCustomer.GiftCards)
                    {
                        sb.Append(string.Concat("GC", i, "Number:", gc.Number, ","));
                        sb.Append(string.Concat("GC", i, "Pin:", gc.Pin, ","));
                        i++;
                    }
                }
            }
            else
            {
                sb = new StringBuilder(30);
                sb.Append("Session data is null");
            }
            return sb.ToString();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            mCustomer = (PetfirstCustomer)Session["Customer"];
            if (mCustomer == null)
            {
                Response.Redirect("Default.aspx", false);
                Context.ApplicationInstance.CompleteRequest();
            }
            else
            {
                if (String.IsNullOrEmpty(mCustomer.MembershipInfo.Email))// add check to deal with android browser cache
                {
                    Response.Redirect("Default.aspx", false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    if (!Page.IsPostBack)
                    {
                        if (Request.UrlReferrer != null)////kp: 2015-05-04 retrieve quote - show quote retrieved pop up modal ////if it comes from default.aspx page
                        {
                            if (Request.UrlReferrer.AbsoluteUri.ToLower().Contains("default.aspx") || Request.UrlReferrer.AbsoluteUri.ToLower().EndsWith("petfirst.com/") || Request.UrlReferrer.AbsoluteUri.ToLower().Contains("petfirst.com/?"))
                            {
                                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                                sb.Append("$('#retrieve_quote').modal('show');");
                                ClientScript.RegisterStartupScript(typeof(Page), "ShowModalCheckout", sb.ToString(), true );
                            }
                        }

                        PopulateCCExpiration();
                        rblPayFrequency.SelectedValue = "1";
                        //lblpetcount.Text = mCustomer.MyPets.Count.ToString();

                        List<Pet> myPet = new List<Pet>();
                        foreach (Pet p in mCustomer.MyPets)
                        {
                            myPet.Add(p);
                        }
                        FakeMultiPet(ref myPet);
                        CreatePetsTable(myPet);
                        CalculateTotals();
                        BindPlanRepeater();
                        load_states();
                        lblCoverageDate.Text = (DateTime.Now.AddDays(1)).ToShortDateString();

                        //load from session
                        LoadCustomerInfo();
                        txtAddress1.Attributes.Add("onchange", "TextBoxChange()");
                        txtAddress2.Attributes.Add("onchange", "TextBoxChange()");
                        txtCity.Attributes.Add("onchange", "TextBoxChange()");
                        txtZip.Attributes.Add("onchange", "TextBoxChange()");
                        ddlState.Attributes.Add("onchange", "DropdownListChange()");

                    }
                    this.Master.PhoneNumber = mCustomer.CallCenter;

                }
            }
        }
 private void SaveCustomerToDb(PetfirstCustomer mCustomer, wsQCustomer dbCustomer, bool bAdd)
 {
     dbCustomer.BillCity = mCustomer.BillingInfo.City;
     dbCustomer.BillFirstName = mCustomer.BillingInfo.FirstName;
     dbCustomer.BillLastName = mCustomer.BillingInfo.LastName;
     dbCustomer.BillState = mCustomer.BillingInfo.State;
     dbCustomer.BillStateId = mCustomer.BillingInfo.StateId;
     dbCustomer.BillStreetAddress = mCustomer.BillingInfo.Address1;
     dbCustomer.BillStreetAddress2 = mCustomer.BillingInfo.Address2;
     dbCustomer.BillZipcode = mCustomer.BillingInfo.Zip;
     dbCustomer.City = mCustomer.MembershipInfo.City;
     dbCustomer.FirstName = mCustomer.MembershipInfo.FirstName;
     dbCustomer.LastName = mCustomer.MembershipInfo.LastName;
     dbCustomer.State = mCustomer.MembershipInfo.State;
     dbCustomer.StateId = mCustomer.MembershipInfo.StateId;
     dbCustomer.StreetAddress = mCustomer.MembershipInfo.Address1;
     dbCustomer.StreetAddress2 = mCustomer.MembershipInfo.Address2;
     dbCustomer.Zipcode = mCustomer.MembershipInfo.Zip;
     dbCustomer.Email = mCustomer.MembershipInfo.Email;
     dbCustomer.EnrollmentCode = mCustomer.EnrollmentCode;
     dbCustomer.Phone = mCustomer.MembershipInfo.Phone;
     dbCustomer.PaymentFrequency = mCustomer.PayFrequency;
     if (!bAdd)
         dbCustomer.ModifyDate = DateTime.Now;
     else
         context.wsQCustomers.AddObject(dbCustomer);
     context.SaveChanges();
     if (mCustomer.CustomerId == 0)
         mCustomer.CustomerId = dbCustomer.QCustomerID;
 }
 protected void Page_Load(object sender, EventArgs e)
 {
     mCustomer = (PetfirstCustomer)Session["Customer"];
     if (mCustomer == null)
     {
         Response.Redirect("Default.aspx", false);
         Context.ApplicationInstance.CompleteRequest();
     }
     else
     {
         if (String.IsNullOrEmpty(mCustomer.MembershipInfo.Email))// add check to deal with android browser cache
         {
             Response.Redirect("Default.aspx", false);
             Context.ApplicationInstance.CompleteRequest();
         }
         else
         {
             if (!Page.IsPostBack)
             {
                 lblEmail.Text = mCustomer.MembershipInfo.Email;
                 txtEmail.Text = mCustomer.MembershipInfo.Email;
                 //kp: 2015-06-29
                 //loadColorList();
                 LoadBirthYear();
                 //end 2015-06-29
                 ResetInput();//this will default to dog and load breed
                 ////kp: 2015-05-04 retrieve quote
                 //try
                 //{
                 //    if (mCustomer.OldCustData)
                 //    {
                 //        RetrieveSavedData();
                 //    }
                 //}
                 //catch{ }
                ////end 2015-05-04
                 bindPets();
                 DetermineButtonText();
             }
             this.Master.PhoneNumber = mCustomer.CallCenter;
         }
     }
 }
        public void RetrieveSavedData(ref PetfirstCustomer mCustomer)
        {
            wsQCustomer dbCustomer = GetCustomerById(mCustomer.CustomerId);
            if (dbCustomer != null)
            {
                mCustomer.BillingInfo.City = dbCustomer.BillCity;
                mCustomer.BillingInfo.FirstName = dbCustomer.BillFirstName;
                mCustomer.BillingInfo.LastName = dbCustomer.BillLastName;
                mCustomer.BillingInfo.State = dbCustomer.BillState;
                if(dbCustomer.BillStateId !=null)
                    mCustomer.BillingInfo.StateId = (int)dbCustomer.BillStateId;
                mCustomer.BillingInfo.Address1 = dbCustomer.BillStreetAddress;
                mCustomer.BillingInfo.Address2 = dbCustomer.BillStreetAddress2;
                mCustomer.BillingInfo.Zip = dbCustomer.BillZipcode;
                mCustomer.MembershipInfo.City = dbCustomer.City;
                mCustomer.MembershipInfo.FirstName = dbCustomer.FirstName;
                mCustomer.MembershipInfo.LastName = dbCustomer.LastName;
                mCustomer.MembershipInfo.State = dbCustomer.State;
                if(dbCustomer.StateId !=null)
                    mCustomer.MembershipInfo.StateId = (int)dbCustomer.StateId;
                mCustomer.MembershipInfo.Address1 = dbCustomer.StreetAddress;
                mCustomer.MembershipInfo.Address2 = dbCustomer.StreetAddress2;
                mCustomer.MembershipInfo.Zip = dbCustomer.Zipcode;
                mCustomer.MembershipInfo.Email = dbCustomer.Email;
                mCustomer.EnrollmentCode = dbCustomer.EnrollmentCode;
                mCustomer.MembershipInfo.Phone = dbCustomer.Phone;
                if(dbCustomer.PaymentFrequency !=null)
                    mCustomer.PayFrequency = (short)dbCustomer.PaymentFrequency;
            }
            int custId =mCustomer.CustomerId;
            ////kp:2015-05-04 Retrieve Quote
            DateTime endDate = DateTime.Today.AddDays(90);// prinsloo wants to data from 90 days back//TODO: verify with Prinsloo
            //end 2015-05-04
            //retrieve pets
            if (custId != 0)
            {
                mCustomer.MyPets.Clear();
                //find the pets that does not have a policy but have plandata

                var lstDbPet1 = (from p in context.wsQPets
                                 join
                                     pl in context.wsQPlans on p.QPlanID equals pl.QPlanID
                                 where p.QCustomerID == custId
                                 && (pl.PolicyNumber.Equals("") || pl.PolicyNumber == null)
                                 && pl.CreateDate <= endDate
                                 select p).ToList();
                //list of pets that does not have a quote yet
                var lstDbPet2 = (from p in context.wsQPets
                                 where p.QCustomerID == custId
                                 && (p.QPlanID==0 ||p.QPlanID ==null)
                                 //&& p.CreateDate <=endDate
                                 select p).ToList();
                var lstDbPet = lstDbPet1.Concat(lstDbPet2).ToList();
                //this filter dup
                //var lstDbPet = new List<wsQPet>(lstDbPet1);
                //lstDbPet.AddRange(lstDbPet2.Where(p2 => lstDbPet1.All(p1 => p1.QPetID != p2.QPetID)));
                foreach (wsQPet dbPet in lstDbPet)
                {
                    Pet pet = new Pet();
                    pet.PetId = dbPet.QPetID;
                    if(dbPet.Birthdate !=null)
                        pet.Birthday =(DateTime) dbPet.Birthdate;

                    if (dbPet.BreedId != null)
                    {
                        pet.BreedId = (int)dbPet.BreedId;
                        pet.BreedName = dbPet.BreedName;
                    }
                    if (dbPet.ColorId != null)
                    {
                        pet.ColorId = (int)dbPet.ColorId;
                        pet.ColorName = dbPet.ColorName;
                    }
                    pet.PetName = dbPet.PetName;
                    pet.Gender = dbPet.Gender;
                    if (dbPet.Gender.Equals("M"))
                        pet.GenderFull = "Male";
                    else if (dbPet.Gender.Equals("F"))
                        pet.GenderFull = "Female";
                    custId = dbPet.QCustomerID;
                    if(dbPet.QPlanID !=null)
                        pet.QPlanId =(int) dbPet.QPlanID;
                    if(dbPet.SpayedOrNeutered !=null)
                        pet.SpayedOrNeutered = (bool)dbPet.SpayedOrNeutered;
                    if (dbPet.SpeciesId != null)
                    {
                        pet.SpeciesId = (int)dbPet.SpeciesId;
                        pet.SpeciesName = dbPet.SpeciesName;
                    }
                    if(dbPet.WeightId!=null)
                        pet.WeightId =(int) dbPet.WeightId;
                    if (dbPet.QPlanID !=null)
                    {
                        pet.QPlanId = (int)dbPet.QPlanID;
                    }
                    else
                        pet.Enrolled = false;
                    if (dbPet.ModifyDate == null)
                        pet.ModifiedDate = dbPet.CreateDate;
                    else
                        pet.ModifiedDate = (DateTime)dbPet.ModifyDate;
                    mCustomer.MyPets.Add(pet);
                }
               //retrieve plans
                var lstDbPlan = (from p in context.wsQPets
                                 join
                                     pl in context.wsQPlans on p.QPlanID equals pl.QPlanID
                                 where p.QCustomerID == custId
                                 && (pl.PolicyNumber.Equals("") || pl.PolicyNumber == null)
                                 && pl.CreateDate <= endDate
                                 ////kp: 2015-05-21 delete standard plan site wide
                                 && pl.PlanId >=61 //only retrieve lifetime
                                 ////end 2015-05-21
                                 select pl).ToList();
                foreach (wsQPlan dbQPlan in lstDbPlan)
                {
                    foreach (Pet p in mCustomer.MyPets)
                    {
                        int count = 0;
                        if (p.QPlanId == dbQPlan.QPlanID)
                        {
                            count++;
                            if (dbQPlan.Deductible != null)
                                p.DeductibleAmount = (decimal)dbQPlan.Deductible;
                            p.LeadId = dbQPlan.LeadId;
                            if (dbQPlan.PlanId != null)
                                p.PlanId = (int)dbQPlan.PlanId;
                            if (dbQPlan.PlanTypeId != null)
                                p.PlanType = dbQPlan.PlanTypeId.ToString();
                            p.PlanName = dbQPlan.PlanName;
                            if (dbQPlan.QuoteId != null)
                                p.QuoteId = (int)dbQPlan.QuoteId;
                            if (dbQPlan.Limit != null)
                                p.LimitAmount = (decimal)dbQPlan.Limit;
                            if (dbQPlan.Reimbursement != null)
                                p.Reimbursement = (decimal)dbQPlan.Reimbursement;
                            p.Breeder = dbQPlan.RiderBreeders;
                            if (dbQPlan.RiderHereditary100)
                                p.Hereditary = "hereditary100";
                            else if (dbQPlan.RiderHereditary25)
                                p.Hereditary = "hereditary25";
                            p.PrescriptionFood = dbQPlan.RiderPrescriptionFood;
                            if (dbQPlan.RiderRoutine125)
                                p.Routine = "routine125";
                            else if (dbQPlan.RiderRoutine250)
                                p.Routine = "routine250";
                            else if (dbQPlan.RiderRoutine400)
                                p.Routine = "routine400";
                            if (dbQPlan.AnnualPayment != null)
                                p.AnnualPaymentTotal = (decimal)dbQPlan.AnnualPayment;
                            if (dbQPlan.FirstMonthPayment != null)
                                p.FirstMonthPaymentTotal = (decimal)dbQPlan.FirstMonthPayment;
                            if (dbQPlan.FirstMonthTax != null)
                                p.FirstMonthTax = (decimal)dbQPlan.FirstMonthTax;
                            if (dbQPlan.RecurringMonthPayment != null)
                                p.RecurringMonthPaymentTotal = (decimal)dbQPlan.RecurringMonthPayment;
                            if (dbQPlan.RecurringMonthTax != null)
                                p.RecurringMonthTax = (decimal)dbQPlan.RecurringMonthTax;
                            if (dbQPlan.PolicyId != null)
                                p.PolicyId = (Int64)dbQPlan.PolicyId;
                            p.Enrolled = true;
                            p.OldQuoteData = true; //retrieved old quote amount
                            ////kp: 2015-05-04 retrieve quote
                            if (dbQPlan.ModifyDate == null)
                                p.ModifiedDate = dbQPlan.CreateDate;
                            else
                                p.ModifiedDate = (DateTime)dbQPlan.ModifyDate;
                            //concat rider name to display on the page
                            string ridername = string.Empty;
                            bool hasRider = false;
                            //routine
                            if (p.Routine.Equals("routine125"))
                            {
                                hasRider = true;
                                ridername = "Routine Care 125";
                            }
                            else if (p.Routine.Equals("routine250"))
                            {
                                hasRider = true;
                                ridername = "Routine Care 250";
                            }
                            else if (p.Routine.Equals("routine400"))
                            {
                                hasRider = true;
                                ridername = "Routine Care 400";
                            }
                            //prescrption food
                            if (hasRider && p.PrescriptionFood)
                            {
                                ridername += "<br />" + "Prescription Food";
                            }
                            else if (p.PrescriptionFood)
                            {
                                hasRider = true;
                                ridername = "Prescription Food";
                            }
                            //hereditary
                            if (hasRider && p.Hereditary.Equals("hereditary25"))
                            {
                                ridername += "<br />" + "Hereditary & Chronic 25%";
                            }
                            else if (hasRider && p.Hereditary.Equals("hereditary100"))
                            {
                                ridername += "<br />" + "Hereditary & Chronic 100%";
                            }
                            else if (p.Hereditary.Equals("hereditary25"))
                            {
                                hasRider = true;
                                ridername = "Hereditary & Chronic 25%";
                            }
                            else if (p.Hereditary.Equals("hereditary100"))
                            {
                                hasRider = true;
                                ridername = "Hereditary & Chronic 100%";
                            }
                            //breeder
                            if (hasRider && p.Breeder)
                            {
                                ridername += "<br />" + "Breeder Coverage";
                            }
                            else if (p.Breeder)
                            {
                                ridername = "Breeder Coverage";
                            }
                            p.RiderName = ridername;
                            ////end 2015-05-04
                        }
                        if (count > 1)
                            p.IsFamilyPlan = true;
                    }
                }

            }
        }
 public void SaveCustomer(PetfirstCustomer mCustomer)
 {
     wsQCustomer dbCustomer = null;
     bool bAdd = false;
     dbCustomer = GetCustomerByEmailZip(mCustomer.MembershipInfo.Email, mCustomer.MembershipInfo.Zip);//tries to get by email and zip
     if (dbCustomer == null)
     {
         if (mCustomer.CustomerId==0)
         {
             dbCustomer = new wsQCustomer();
             bAdd = true;
             dbCustomer.CreateDate = DateTime.Now;
         }
         else
             dbCustomer = GetCustomerById(mCustomer.CustomerId);
     }
     else
     {
         mCustomer.OldCustData = true;//customer saved in db
         mCustomer.CustomerId = dbCustomer.QCustomerID;
     }
     if (dbCustomer == null)
     {
         dbCustomer = new wsQCustomer();
         bAdd = true;
         dbCustomer.CreateDate = DateTime.Now;
         SaveCustomerToDb(mCustomer, dbCustomer, bAdd);
     }
     else {
         SaveCustomerToDb(mCustomer, dbCustomer, bAdd);
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            HandleMenuItems();

            mCustomer = (PetfirstCustomer)Session["Customer"];
            mthisPet = (Pet)Session["Pet"];
            if (mCustomer == null)
            {
                Response.Redirect("Default.aspx", false);
                Context.ApplicationInstance.CompleteRequest();
            }
            else
            {
                if (!Page.IsPostBack)
                {
                    if (mCustomer != null)
                    {
                        ListsManager lm = new ListsManager();
                        PopulatePlanDetails(lm);
                    }

                    if (mthisPet != null)
                    {
                        if(!string.IsNullOrEmpty(Request.QueryString["canceladd"])) //see if we are cancelling add pet. If so, then load latest pet.
                        {
                            mthisPet = mCustomer.MyPets.ElementAtOrDefault(mCustomer.MyPets.Count - 1);
                            mCustomer.MyPets.RemoveAt(mCustomer.MyPets.Count - 1);
                        }

                        string jd;
                        PetName.Text = mthisPet.PetName + "'s";
                        ddlLimit.SelectedValue = mthisPet.LimitAmount.ToString("C0");
                        ddlDeductible.SelectedValue  = mthisPet.DeductibleAmount.ToString("C0");
                        ddlReimburse.SelectedValue = jd = (mthisPet.Reimbursement.ToString("P0").Replace(" ", ""));
                        ddlRoutine.SelectedValue = GetRiderNameFromValue(mthisPet.Routine);
                        lblDiscounts.Text = (mthisPet.InternetDiscountAmount +
                                             mthisPet.EBDiscountAmount +
                                             mthisPet.MilitaryDiscountAmount +
                                             mthisPet.VetDiscountAmount).ToString("C2");
                    }
                }

                if (mthisPet != null)
                {
                    UpdateLabels();
                }

                this.Master.NumberofPets = (mCustomer.MyPets.Count + 1).ToString();

            }

            #region debug
            //            if (mCustomer != null && mthisPet != null)
            //            {
            //                CustomerDebug.Text = String.Format(@"  First Name: [{0}], Last Name: [{1}], Add1: [{2}], Add2: [{3}], City: [{4}], State: [{5}], StateCode: [{6}],
            //                                                 Zip: [{7}], Phone: [{8}], Email: [{9}], CustomerID: [{10}], CallCenter: [{11}], EC: [{12}], Pay Freq: [{13}],
            //                                                 CC Num: [{14}], Sec Code: [{15}], Exp: [{16}/{17}], LifeTimeActive: [{18}] DISCOUNTS: EBEC: [{19}], Vet: [{20}],
            //                                                 Military: [{21}], MilBranchID [{22}], MilStatusID[{23}]",
            //                   mCustomer.MembershipInfo.FirstName,
            //                   mCustomer.MembershipInfo.LastName,
            //                   mCustomer.MembershipInfo.Address1,
            //                   mCustomer.MembershipInfo.Address2,
            //                   mCustomer.MembershipInfo.City,
            //                   mCustomer.MembershipInfo.State,
            //                   mCustomer.MembershipInfo.StateId,
            //                   mCustomer.MembershipInfo.Zip,
            //                   mCustomer.MembershipInfo.Phone,
            //                   mCustomer.MembershipInfo.Email,
            //                   mCustomer.CustomerId,
            //                   mCustomer.CallCenter,
            //                   mCustomer.EnrollmentCode,
            //                   mCustomer.PayFrequency,
            //                   mCustomer.CcNumber,
            //                   mCustomer.SecCode,
            //                   mCustomer.ExpirationMonth,
            //                   mCustomer.ExpirationYear,
            //                   mCustomer.LifeTimeActive,
            //                   mCustomer.EBEnrollmentCodeDiscount,
            //                   mCustomer.VetDiscount,
            //                   mCustomer.MilitaryDiscount,
            //                   mCustomer.MilitaryBranchID,
            //                   mCustomer.MilitaryStatusID
            //                   );
            //                CurrentPetDebug.Text = String.Format(@"ID: [{0}], Name: [{1}], SpeciesID: [{2}], SpeciesName: [{3}], BreedID: [{4}], BreedName: [{5}], Age: [{6}],
            //                                                 BirthDay: [{7}], WeightID: [{8}], Gender: [{9}], GenderFull: [{10}], Limit Amount: [{11}], Deductible Amount: [{12}], Reimbursement: [{13}],
            //                                                 Rider Name: [{14}], Routine: [{15}], AnnualPaymentTotal: [{16}], FirstMonthlyPaymentTotal: [{17}], FirstMonthlyPremiumOnly: [{18}],
            //                                                 FirstMonthTax: [{19}], RecurringMonthPaymentTotal: [{20}], RecurringMonthPremiumOnly: [{21}], RecurringMonthTax [{22}], PolicyNumber[{23}],
            //                                                 PolicyID: [{24}], PlanType: [{25}], PlanName: [{26}], PlanID: [{27}], SpayedNeutered: [{28}]",
            //                    mthisPet.PetId,
            //                    mthisPet.PetName,
            //                    mthisPet.SpeciesId,
            //                    mthisPet.SpeciesName,
            //                    mthisPet.BreedId,
            //                    mthisPet.BreedName,
            //                    mthisPet.Age,
            //                    mthisPet.Birthday,
            //                    mthisPet.WeightId,
            //                    mthisPet.Gender,
            //                    mthisPet.GenderFull,
            //                    mthisPet.LimitAmount,
            //                    mthisPet.DeductibleAmount,
            //                    mthisPet.Reimbursement,
            //                    mthisPet.RiderName,
            //                    mthisPet.Routine,
            //                    mthisPet.AnnualPaymentTotal,
            //                    mthisPet.FirstMonthPaymentTotal,
            //                    mthisPet.FirstMonthPremiumOnly,
            //                    mthisPet.FirstMonthTax,
            //                    mthisPet.RecurringMonthPaymentTotal,
            //                    mthisPet.RecurringMonthPremiumOnly,
            //                    mthisPet.RecurringMonthTax,
            //                    mthisPet.PolicyNumber,
            //                    mthisPet.PolicyId,
            //                    mthisPet.PlanType,
            //                    mthisPet.PlanName,
            //                    mthisPet.PlanId,
            //                    mthisPet.SpayedOrNeutered);
            //            }
            #endregion
        }
        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 Page_Load(object sender, EventArgs e)
        {
            mCustomer = (PetfirstCustomer)Session["Customer"];
            if (mCustomer == null)
            {
                Response.Redirect("Default.aspx", false);
                Context.ApplicationInstance.CompleteRequest();
            }
            else
            {
                if (String.IsNullOrEmpty(mCustomer.MembershipInfo.Email))// add check to deal with android browser cache
                {
                    Response.Redirect("Default.aspx", false);
                    Context.ApplicationInstance.CompleteRequest();
                }
                else
                {
                    this.Master.PhoneNumber = mCustomer.CallCenter;
                    if (!Page.IsPostBack)
                    {
                        ////kp: 2015-05-04 retrieve quote--add popup if comes from default.aspx page
                        if (Request.UrlReferrer != null)
                        {
                            //default page url example:
                            //http://quoteuat.petfirst.com/default.aspx
                            //http://quoteuat.petfirst.com/ or https://quotewww.petfirst.com/
                            //http://quoteuat.petfirst.com/?enrollment_code=99-99-20-6120
                            if (Request.UrlReferrer.AbsoluteUri.ToLower().Contains("default.aspx") || Request.UrlReferrer.AbsoluteUri.ToLower().EndsWith("petfirst.com/") || Request.UrlReferrer.AbsoluteUri.ToLower().Contains("petfirst.com/?"))
                            {
                                System.Text.StringBuilder sb = new System.Text.StringBuilder();
                                sb.Append("$('#retrieve_quote').modal('show');");
                                ClientScript.RegisterStartupScript(typeof(Page), "ShowModalPlanInfo", sb.ToString(), true);
                            }
                        }
                        ////end 2015-05-04
                        Session.Remove("EditPlanPet");
                        lblEmail.Text = mCustomer.MembershipInfo.Email;
                        txtEmail.Text = mCustomer.MembershipInfo.Email;
                        BindPetsRepeater();
                        //dvStandard.Visible = false;
                        //dvLifetime.Visible = false;
                        try
                        {
                            ////kp: 2015-05-21 delete standard plan site wide
                            //ListsManager lm = new ListsManager();
                            //List<PlanType> lstPlanType = lm.GetPlanType(mCustomer.EnrollmentCode);
                            //foreach (PlanType pt in lstPlanType)
                            //{
                            //    if (pt.TypeName.ToLower().Contains("standard"))
                            //    {
                            //        dvStandard.Visible = true;
                            //    }
                            //    else if (pt.TypeName.ToLower().Contains("lifetime"))
                            //    {
                            //        dvLifetime.Visible = true;
                            //    }
                            //}
                            ////end 2015-05-21
                            DetermineReviewQuoteStatus();
                            //when edit is clicked on Checkout page, it will redirect to this page with quoteid in session
                            int quoteId = 0;
                            if (Session["qid"] != null)
                            {
                                quoteId = int.Parse(Session["qid"].ToString());
                                SetEditPets(quoteId);
                                Session.Remove("qid");
                            }
                            else
                            {
                                //default to lifetime and calls to populate plan detail: limit, reimbursement, etc and riders
                                ////kp: 2015-05-21 delete standard plan site wide
                                //ToggleButtonActive(false);
                                mCustomer.LifeTimeActive = true;
                                PopulatePlanPanel();
                                ////end 2015-05-21
                                DetermineFamilyOrIndividualPlan();
                            }

                        }
                        catch (Exception ex)
                        {
                            displayError(string.Concat("Error during load plan info by enrollment code:", mCustomer.EnrollmentCode), ex.ToString(), lblStartError);
                        }
                    }
                }
            }
        }
        private void something(PetfirstCustomer mCustomer)
        {
            //int count = 0;
            string[,] petData = new string[3, 5] { { "", "", "", "", "" }, { "", "", "", "", "" }, { "", "", "", "", "" } };
            //foreach (PlanPet pp in mCustomer.PlanPets)
            //{
            //    if (pp.PetsEnrolled.Count != 0)
            //    {
            //        count = 1;
            //        petData[0, 0] = pp.PetsEnrolled[0].PetName; ;
            //        petData[0, 1] = pp.PetsEnrolled[0].Birthday.ToShortDateString();
            //        petData[0, 2] = pp.PetsEnrolled[0].BreedId.ToString();
            //        petData[0, 3] = pp.PetsEnrolled[0].SpeciesId.ToString();
            //        petData[0, 4] = pp.PetsEnrolled[0].Gender;
            //        if (pp.PetsEnrolled[1] != null)
            //        {
            //            petData[1, 0] = pp.PetsEnrolled[1].PetName;
            //            petData[1, 1] = pp.PetsEnrolled[1].Birthday.ToShortDateString();
            //            petData[1, 2] = pp.PetsEnrolled[1].BreedId.ToString();
            //            petData[1, 3] = pp.PetsEnrolled[1].SpeciesId.ToString();
            //            petData[1, 4] = pp.PetsEnrolled[1].Gender;
            //            count++;
            //        }
            //        if (pp.PetsEnrolled[2] != null)
            //        {
            //            petData[2, 0] = pp.PetsEnrolled[2].PetName;
            //            petData[2, 1] = pp.PetsEnrolled[2].Birthday.ToShortDateString();
            //            petData[2, 2] = pp.PetsEnrolled[2].BreedId.ToString();
            //            petData[2, 3] = pp.PetsEnrolled[2].SpeciesId.ToString();
            //            petData[2, 4] = pp.PetsEnrolled[2].Gender;
            //            count++;
            //        }

            //    }

            //}
        }
 public void GetAnnualQuote(ref PetfirstCustomer mCustomer, List<Pet> lstPets)
 {
     mCustomer.WebserviceErrorMsg = "";
     QuoteServiceClient qclient = new QuoteServiceClient();
     QuoteServiceCreateNewQuoteRequest qRequest = new QuoteServiceCreateNewQuoteRequest();
     qRequest.Customer = CreateQuoteCustomer(mCustomer);
     SetQuoteRequestPets(ref qRequest,lstPets);
     SetQuoteOtherAttributes(ref qRequest,mCustomer,lstPets, false);
     try
     {
         QuoteServiceCreateNewQuoteResponse resp = qclient.CreateNewQuote(qRequest);
         if (string.IsNullOrEmpty(resp.Error.ErrorText))
         {
             foreach (Pet p in lstPets)
             {
                 p.AnnualPaymentTotal = resp.FirstDebitAmt;
             }
         }
         else
         {
             mCustomer.WebserviceErrorMsg = resp.Error.ErrorText;
         }
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         try
         {
             if (qclient.State == CommunicationState.Faulted)
                 qclient.Abort();
             else if (qclient.State == CommunicationState.Opened)
                 qclient.Close();
         }
         catch { }
     }
 }
        public void CreatePolicy(ref PetfirstCustomer mCustomer, List<Pet> lstPets)
        {
            mCustomer.WebserviceErrorMsg = "";
            PolicyServiceSellPolicyRequest pRequest = new PolicyServiceSellPolicyRequest();
            if (!string.IsNullOrEmpty(mCustomer.CcNumber))
            {
                pRequest.CreditCard = new CreditCard()
                {
                    Address1 = mCustomer.BillingInfo.Address1,
                    Address2 = mCustomer.BillingInfo.Address2,
                    City = mCustomer.BillingInfo.City,
                    Cvvs2 = mCustomer.SecCode,
                    ExpirationMonth = mCustomer.ExpirationMonth,
                    ExpirationYear = mCustomer.ExpirationYear,
                    FirstName = mCustomer.BillingInfo.FirstName,
                    LastName = mCustomer.BillingInfo.LastName,
                    Number = mCustomer.CcNumber,
                    StateId = mCustomer.BillingInfo.StateId,
                    ZipCode = mCustomer.BillingInfo.Zip

                };
            }
            if (mCustomer.GiftCards != null)
            {
                int gcCount = mCustomer.GiftCards.Count;
                pRequest.GiftCards = new PolicyServiceReference.GiftCard[gcCount];
                int i =0;
                foreach (GiftCard gc in mCustomer.GiftCards)
                {
                    PolicyServiceReference.GiftCard pGC = new PolicyServiceReference.GiftCard();
                    pGC.Pin = gc.Pin;
                    pGC.SrcRefNum = 0;
                    pRequest.GiftCards[i] = pGC;
                    i++;
                }
            }
            pRequest.Customer = new PolicyServiceReference.Customer()
            {
                ZipCode = mCustomer.MembershipInfo.Zip,
                WorkPhone = String.Empty,
                StreetAddress2 = mCustomer.MembershipInfo.Address2,
                StreetAddress = mCustomer.MembershipInfo.Address1,
                StateId = mCustomer.MembershipInfo.StateId,
                MobilePhone = String.Empty,
                LastName = mCustomer.MembershipInfo.LastName,
                FirstName = mCustomer.MembershipInfo.FirstName,
                HomePhone = mCustomer.MembershipInfo.Phone,
                CityName = mCustomer.MembershipInfo.City,
                EmailAddress = mCustomer.MembershipInfo.Email
            };
            pRequest.CoInsurance = 1-lstPets[0].Reimbursement;
            pRequest.Deductible = lstPets[0].DeductibleAmount;
            pRequest.EnrollmentCode = mCustomer.EnrollmentCode;
            pRequest.PlanId = lstPets[0].PlanId;
            pRequest.PaymentFrequencyId = (int)mCustomer.PayFrequency;//annual
            pRequest.IncludeRoutine = false;
            pRequest.IncludeRoutine125 = false;
            pRequest.IncludeRoutine250 = false;
            pRequest.IncludeRoutine400 = false;
            if (!lstPets[0].Routine.ToLower().Equals("0"))
            {
                pRequest.IncludeRoutine = true;
                switch (lstPets[0].Routine.ToLower())
                {
                    case "routine125":
                        pRequest.IncludeRoutine125 = true;
                        break;
                    case "routine250":
                        pRequest.IncludeRoutine250 = true;
                        break;
                    case "routine400": pRequest.IncludeRoutine400 = true;
                        break;

                }
            }

            pRequest.InternetDiscount = mCustomer.DiscountInternetPurchase;
            pRequest.MilitaryDiscount = mCustomer.DiscountMilitarySelected;
            pRequest.VetDiscount = mCustomer.DiscountVetSelected;
            int nPlan = lstPets[0].PlanId;
            int stateid = mCustomer.MembershipInfo.StateId;
            int underwriter = mCustomer.Underwriter;
            pRequest.UnderwriterID = mCustomer.Underwriter;
            pRequest.FilingID = (from pts in context.v_PlansToStates
                                 where pts.stateProvinceID.Equals(stateid) &&
                                     pts.UnderwriterID.Equals(underwriter) &&
                                     pts.plan_id == nPlan
                                 select pts.FilingID).First();

            pRequest.IncludeBreeders = lstPets[0].Breeder;
            if (lstPets[0].Hereditary.ToLower().Equals("hereditary100"))
            {
                pRequest.IncludeHereditary100 = true;
            }
            else if (lstPets[0].Hereditary.ToLower().Equals("hereditary25"))
            {
                pRequest.IncludeHereditary25 = true;
            }
            else
            {
                pRequest.IncludeHereditary100 = false;
                pRequest.IncludeHereditary25 = false;
            }
            pRequest.IncludePrescriptionFood = lstPets[0].PrescriptionFood;
            pRequest.KrogerLoyaltyNumber = string.Empty;

            PolicyServiceReference.Pet p1 = CreatePolicyRequestPet(lstPets[0]);
            if (lstPets.Count ==3)//3 pets
            {
                pRequest.Pets = new PolicyServiceReference.Pet[3];
                pRequest.Pets[0] = p1;
                pRequest.Pets[1] = CreatePolicyRequestPet(lstPets[1]);
                pRequest.Pets[2] = CreatePolicyRequestPet(lstPets[2]);
            }
            else if (lstPets.Count ==2)
            {
                pRequest.Pets = new PolicyServiceReference.Pet[2];
                pRequest.Pets[0] = p1;
                pRequest.Pets[1] = CreatePolicyRequestPet(lstPets[1]);
            }
            else
            {
                pRequest.Pets = new PolicyServiceReference.Pet[1];
                pRequest.Pets[0] = p1;
            }

            PolicyServiceClient pc = new PolicyServiceClient();
            try
            {
                PolicyServiceSellPolicyResponse resp = pc.SellPolicy(pRequest);
                if (string.IsNullOrEmpty(resp.Error))
                {
                    foreach (Pet p in lstPets)
                    {
                        p.PolicyNumber = resp.PolicyNumber;
                        p.PolicyId = resp.PolicyId;
                    }
                }
                else
                {
                    if (!string.IsNullOrEmpty(resp.PolicyNumber))
                    {
                        foreach (Pet p in lstPets)
                        {
                            p.PolicyNumber = resp.PolicyNumber;
                            p.PolicyId = resp.PolicyId;
                        }
                    }
                    mCustomer.WebserviceErrorMsg = resp.Error;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                try
                {
                    if (pc.State == CommunicationState.Faulted)
                        pc.Abort();
                    else if (pc.State == CommunicationState.Opened)
                        pc.Close();
                }
                catch { }
            }
        }
        public List<MilitaryStatus> GetMilitaryStatusList(PetfirstCustomer mCustomer)
        {
            List<MilitaryStatus> lstReturn = new List<MilitaryStatus>();
            string cacheKey = "$MilitaryStatusList$";
            object CachedList = m_Cache.Get(cacheKey) as List<MilitaryBranch>;
            if (CachedList == null)//get from the service
            {
                CoreServiceReference.CoreServiceClient cs = new CoreServiceClient();
                CoreServiceGetMilitaryStatusResponse ccResponse = cs.GetMilitaryStatusList();

                foreach (MilitaryStatus ms in ccResponse.Status)
                {
                    lstReturn.Add(ms);
                }

                if (lstReturn.Count > 0)
                {
                    m_Cache.Add(cacheKey, lstReturn);
                }
                else
                {
                    lstReturn = null;
                    LogException le = new LogException();
                    try
                    {

                        le.LogError(HttpContext.Current.Request.Url.AbsoluteUri, "Error retreiving military status", ccResponse.Error.ErrorText, mCustomer);
                        ///Test email server
                        //le.SendErrorEmail(string.Concat(Request.Url.AbsoluteUri, "<br/><hr />", msg, "<hr />User Input:", le.BuildUserDataString(mCustomer)));
                    }
                    catch (Exception ex)
                    {
                        ///Test email server
                        //lblError.Text = ex.ToString();
                        try
                        {
                            le.SendErrorEmail(string.Concat(HttpContext.Current.Request.Url.AbsoluteUri, "<br/><hr />", ex.Message, "<br />StackTrace: ", ex.StackTrace, "<br /><hr />User Input:", le.BuildUserDataString(mCustomer)));
                        }
                        catch { }
                    }
                }
            }
            else
            {
                lstReturn = (List<MilitaryStatus>)CachedList;
            }

            return lstReturn;
        }
 public void LogError(string source, string msg, string stack, PetfirstCustomer mCustomer)
 {
     //string hostname = GetDnsName();
     string ip = GetIPAddress();
     string userName = GetUserName();
     string userData = BuildUserDataString(mCustomer);
     WebExceptionCaptureServiceRequest wrequest = new WebExceptionCaptureServiceRequest();
     wrequest.CustomizedData = userData;
     wrequest.UserName = userName;
     wrequest.IPAddress = GetIPAddress();
     wrequest.HostName = GetDnsName();
     wrequest.Stacktrace = stack;
     wrequest.ErrorPageUrl = source;
     wrequest.ErrorMessage = msg;
     WebExceptionServiceClient wsc = new WebExceptionServiceClient();
     try
     {
         WebExceptionCaptureServiceResponse resp = wsc.SaveWebException(wrequest);
     }
     catch (Exception)
     {
         throw;
     }
     finally
     {
         try
         {
             if (wsc.State == CommunicationState.Faulted)
                 wsc.Abort();
             else if (wsc.State == CommunicationState.Opened)
                 wsc.Close();
         }
         catch { }
     }
 }
        protected void Page_Load(object sender, EventArgs e)
        {
            mCustomer = (PetfirstCustomer)Session["Customer"];
            mthisPet = (Pet)Session["Pet"];

            HandleMenuItems();

            if (!string.IsNullOrEmpty(Request.QueryString["new_pet"]) && mCustomer != null)//if there is query srtring passed
            {
                bAddPet = true; //adding a new pet only
                CancelLink.HRef = "customizeplan.aspx?canceladd=true";
            }

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

            if (!Page.IsPostBack)
            {
                if(bSamePet)
                {
                    txtZip.Text = mCustomer.MembershipInfo.Zip;
                    txtPetName.Text = mthisPet.PetName;

                    DateTime today = DateTime.Today;
                    int age = today.Year - mthisPet.Birthday.Year;
                    //if (mthisPet.Birthday > today.AddYears(-age)) age--;

                    ddlAge.SelectedIndex = age;
                    load_breeds(mthisPet.SpeciesId);
                    if (mthisPet.BreedId == 54)
                    {
                        ddlBreed.SelectedValue = "10000"; //+ mthisPet.WeightId).ToString();
                        rbRadioButtonListMixed.SelectedValue = mthisPet.WeightId.ToString();
                    }
                    else
                    {
                        ddlBreed.SelectedValue = mthisPet.BreedId.ToString();
                    }

                    rblSpecies.SelectedValue = mthisPet.SpeciesId.ToString();
                }
                else
                {
                    InitiatePetfirstCustomer();
                    InitiateNewPet();
                    rblSpecies.SelectedValue = "1";
                    load_breeds(1);
                    ddlBreed.SelectedIndex = 0;
                    rbRadioButtonListMixed.SelectedValue = "1";
                }

            }

            lblYourPet.Text = mthisPet.PetName;

            if (bAddPet)
            {
                txtZip.Text = mCustomer.MembershipInfo.Zip;
                txtZip.Enabled = false;
            }

            this.Master.NumberofPets = mCustomer.MyPets.Count.ToString();
        }
        public bool GetFastQuote(ref PetfirstCustomer mCustomer, ref Pet thispet, bool bNewQuote)
        {
            bool bReturn = false;

            //Load from prequote;
            if (bNewQuote)
            {
                bReturn = LoadFastQuote(ref mCustomer, ref thispet);
            }

            if (thispet.preQuotes != null)
            {
                Int16 nPlanID = (Int16)thispet.PlanId;
                decimal dDeductible = thispet.DeductibleAmount;
                decimal dCopay = (1 - thispet.Reimbursement);
                Boolean b125 = false;
                Boolean b250 = false;
                Boolean b400 = false;

                switch (thispet.Routine)
                {
                    case "routine125":
                        b125 = true;
                        break;
                    case "routine250":
                        b250 = true;
                        break;
                    case "routine400":
                        b400 = true;
                        break;
                    default:
                        break;
                }

                try
                {
                    FastQuoteResponse thisQuote = (from qr in thispet.preQuotes.AsEnumerable()
                                                   where dDeductible == qr.Field<decimal>("Deductible") &&
                                                         dCopay == qr.Field<decimal>("Copay") &&
                                                         nPlanID == qr.Field<Int16>("PlanId") &&
                                                         b125 == qr.Field<Boolean>("Routine125") &&
                                                         b250 == qr.Field<Boolean>("Routine250") &&
                                                         b400 == qr.Field<Boolean>("Routine400")
                                                   select new FastQuoteResponse
                                                   {
                                                       QuoteID = qr.Field<int>("QuoteID"),
                                                       FilingID = qr.Field<int>("FilingID"),
                                                       AnnualPremiumAmount = qr.Field<decimal>("AnnualPremiumAmount"),
                                                       AdminFee = qr.Field<decimal>("AdminFee"),
                                                       RecurringMonthlyAmount = qr.Field<decimal>("ReccuringMonthlyAmount"),
                                                       FirstMonthPremiumAmount = qr.Field<decimal>("FirstMonthPremiumAmount"),
                                                       AnnualSavings = qr.Field<decimal>("AnnualSavings"),
                                                       AnnualDiscountAmount = qr.Field<decimal>("AnnualDiscountAmount")
                                                   }).FirstOrDefault();

                    if (thisQuote == null)
                    {
                        bReturn = false;
                    }
                    else
                    {

                        thispet.FirstMonthPaymentTotal = thisQuote.FirstMonthPremiumAmount;
                        thispet.FirstMonthTax = thisQuote.AdminFee;
                        thispet.RecurringMonthPaymentTotal = thisQuote.RecurringMonthlyAmount;
                        thispet.RecurringMonthTax = thisQuote.AdminFee;
                        thispet.InternetDiscountAmount = thisQuote.AnnualDiscountAmount;
                        thispet.EBDiscountAmount = 0;
                        thispet.MilitaryDiscountAmount = 0;
                        thispet.VetDiscountAmount = 0;
                        thispet.AnnualPaymentTotal = thisQuote.AnnualPremiumAmount;

                        if (mCustomer.Underwriter == 4)
                        {
                            thispet.FirstMonthPremiumOnly = thisQuote.FirstMonthPremiumAmount - thisQuote.AdminFee;
                            thispet.RecurringMonthPremiumOnly = thisQuote.RecurringMonthlyAmount - thisQuote.AdminFee;
                        }
                        else
                        {
                            thispet.FirstMonthPremiumOnly = thisQuote.FirstMonthPremiumAmount - thisQuote.AdminFee;
                            thispet.RecurringMonthPremiumOnly = thisQuote.RecurringMonthlyAmount - thisQuote.AdminFee;
                        }
                        thispet.QuoteId = thisQuote.QuoteID;
                        thispet.Enrolled = true;
                        thispet.OldQuoteData = false;

                        if (thisQuote.FilingID > 47)
                            thispet.MultiPetAvailable = true;

                        bReturn = true;
                    }
                }
                catch (Exception ex)
                {
                    bReturn = false;
                }
            }

            return (bReturn);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(Request.QueryString["quoteref"])) //Make sure we have a quote
            {
                Response.Redirect("Default.aspx", false);
                Context.ApplicationInstance.CompleteRequest();
            }
            else
            {
                string[] sQuoteRef = (Request.QueryString["quoteref"]).Split('-');

                if (sQuoteRef.Count() == 2)
                {
                    if (!string.IsNullOrEmpty(sQuoteRef[0]) && !string.IsNullOrEmpty(sQuoteRef[1])) //Make sure the quote is well formed
                    {
                        mCustomer = new PetfirstCustomer();

                        if (mCustomer != null)
                        {
                            if (LoadCustomerInfo(ref mCustomer, sQuoteRef[1]))
                            {
                                if (LoadPlanInfo(ref mCustomer, sQuoteRef[0]))
                                {

                                    //Everthing is loaded that we can so move on to checkout.
                                    Session["Customer"] = mCustomer;
                                    Response.Redirect("Checkout.aspx", false);
                                    Context.ApplicationInstance.CompleteRequest();
                                }
                                else
                                {
                                    //couldn't find plan in db.....
                                    Response.Redirect("Default.aspx", false);
                                    Context.ApplicationInstance.CompleteRequest();
                                }
                            }
                            else
                            {
                                //couldn't load customer data from db....
                                Response.Redirect("Default.aspx", false);
                                Context.ApplicationInstance.CompleteRequest();
                            }
                        }
                        else
                        {
                            Response.Redirect("Default.aspx", false);
                            Context.ApplicationInstance.CompleteRequest();
                        }
                    }
                    else
                    {
                        Response.Redirect("Default.aspx", false);
                        Context.ApplicationInstance.CompleteRequest();
                    }
                }
                else
                {
                    Response.Redirect("Default.aspx", false);
                    Context.ApplicationInstance.CompleteRequest();
                }
            }
        }
        public void GetMonthlyQuote(ref PetfirstCustomer mCustomer, List<Pet> lstPets)
        {
            mCustomer.WebserviceErrorMsg = "";
            QuoteServiceClient qclient = new QuoteServiceClient();
            QuoteServiceCreateNewQuoteRequest qRequest = new QuoteServiceCreateNewQuoteRequest();
            qRequest.Customer = CreateQuoteCustomer(mCustomer);
            SetQuoteRequestPets(ref qRequest, lstPets);
            SetQuoteOtherAttributes(ref qRequest, mCustomer,lstPets, true);
            try
            {
                QuoteServiceCreateNewQuoteResponse resp = qclient.CreateNewMonthlyQuote(qRequest);
                if (string.IsNullOrEmpty(resp.Error.ErrorText))
                {
                    foreach (Pet p in lstPets)
                    {
                        p.FirstMonthPaymentTotal = resp.FirstDebitAmt;
                        p.FirstMonthTax = resp.FirstTaxAmt;//this include tax and admin fee
                        p.RecurringMonthPaymentTotal = resp.RecurringDebitAmt;
                        p.RecurringMonthTax = resp.RecurringTaxAmt;//this include tax and admin fee
                        p.InternetDiscountAmount = resp.InternetDiscountAmount;
                        p.EBDiscountAmount = resp.EBDiscountAmount;
                        p.MilitaryDiscountAmount = resp.MilitaryDiscountAmount;
                        p.VetDiscountAmount = resp.VetDiscountAmount;

                        if (mCustomer.Underwriter == 4)
                        {
                            p.FirstMonthPremiumOnly = resp.FirstDebitAmt - resp.FirstTaxAmt;
                            p.RecurringMonthPremiumOnly = resp.RecurringDebitAmt - resp.RecurringTaxAmt;
                        }
                        else
                        {
                            p.FirstMonthPremiumOnly = resp.FirstDebitAmt - resp.FirstTaxAmt;
                            p.RecurringMonthPremiumOnly = resp.RecurringDebitAmt - resp.RecurringTaxAmt;
                        }
                        p.QuoteId = resp.Id;
                        p.Enrolled = true;
                        p.OldQuoteData = false;
                        p.MultiPetAvailable = resp.MultiPolicyDiscountAvailable;
                    }
                }
                else
                {
                    mCustomer.WebserviceErrorMsg = resp.Error.ErrorText;
                }
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                try
                {
                    if (qclient.State == CommunicationState.Faulted)
                        qclient.Abort();
                    else if (qclient.State == CommunicationState.Opened)
                        qclient.Close();
                }
                catch { }
            }
        }
        public bool LoadFastQuote(ref PetfirstCustomer mCustomer, ref Pet thispet)
        {
            bool bReturn = false;

            string sMemberCodeString = "";

            sMemberCodeString += mCustomer.DiscountMilitarySelected ? "M" : "";
            sMemberCodeString += mCustomer.DiscountInternetPurchase ? "I" : "";
            sMemberCodeString += mCustomer.DiscountVetSelected ? "A" : "";

            try
            {
                if (thispet.preQuotes == null)
                {
                    thispet.preQuotes = new DataTable();
                }
                thispet.preQuotes.Clear();
                using (var con = new SqlConnection(ConfigurationManager.ConnectionStrings["PFQuoteDB"].ConnectionString))
                {
                    using (var cmd = new SqlCommand("usp_GetPreQuotes", con))
                    {
                        cmd.Parameters.Add("@StateID", SqlDbType.TinyInt);
                        cmd.Parameters["@StateID"].Value = (byte)mCustomer.MembershipInfo.StateId;
                        cmd.Parameters.Add("@BreedID", SqlDbType.Int);

                        cmd.Parameters.Add("@Age", SqlDbType.Int);
                        cmd.Parameters["@Age"].Value = thispet.Age;
                        cmd.Parameters.Add("@WeightID", SqlDbType.TinyInt);

                        cmd.Parameters.Add("@EnrollmentCode", SqlDbType.VarChar, 20).Value = mCustomer.EnrollmentCode;
                        cmd.Parameters.Add("@MemberCodeString", SqlDbType.VarChar, 20).Value = sMemberCodeString;

                        if (thispet.SpeciesId == 2)
                        {
                            cmd.Parameters["@WeightID"].Value = (byte)1;
                            cmd.Parameters["@BreedID"].Value = 2;
                        }
                        else if (thispet.SpeciesId == 1 && thispet.BreedId == 54)
                        {
                            cmd.Parameters["@WeightID"].Value = (byte)thispet.WeightId;
                            cmd.Parameters["@BreedID"].Value = thispet.BreedId;
                        }
                        else
                        {
                            cmd.Parameters["@WeightID"].Value = (byte)0;
                            cmd.Parameters["@BreedID"].Value = thispet.BreedId;
                        }

                        using (var da = new SqlDataAdapter(cmd))
                        {
                            cmd.CommandType = CommandType.StoredProcedure;
                            da.Fill(thispet.preQuotes);

                            if (thispet.preQuotes.Rows.Count > 0)
                            {
                                bReturn = true;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                bReturn = false;
                mCustomer.WebserviceErrorMsg = ex.Message;
            }
            return (bReturn);
        }
 private void InitiatePetfirstCustomer()
 {
     if (!bAddPet)
     {
         mCustomer = new PetfirstCustomer();
         if (!string.IsNullOrEmpty(Request.QueryString["enrollment_code"]))//if there is query srtring passed
         {
             mCustomer.EnrollmentCode = (string)Request.QueryString["enrollment_code"];
             GetPhoneNumber();
             //mCustomer.DiscountEBEnrollmentCode = 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);
        }