protected void btnSave_Click(object sender, EventArgs e) { if (Page.IsValid) { if (mCustomer != null) { try { var mypet = (from p in mCustomer.MyPets where p.PetName.ToLower().Equals(txtPetName.Text.ToLower()) select p).FirstOrDefault(); if (mypet != null) { SavePet(true, ref mypet);//update//note: this is different than current, not allow pets have same name if (mypet.Enrolled) { int quoteId = mypet.QuoteId; List<Pet> lstEnrolled = (from p in mCustomer.MyPets where p.QuoteId == quoteId select p).ToList(); //first check if there is senior pet in family plan bool bSenior = false; string seniorName = ""; if (lstEnrolled.Count > 1) { foreach (Pet p in lstEnrolled) { if (p.Age > 9) { bSenior = true; seniorName = p.PetName; break; } } } if (bSenior) { lblError.Text = string.Format("Pet {0} is considered senior pet, senior pet is not allowed to be in the family plan, please remove this pet from the enrolled plan before edit", seniorName); return; } else { //requote PetfirstBL pfBl = new PetfirstBL(); DoRequote(pfBl, lstEnrolled); } } } else { mypet = new Pet(); mypet.Enrolled = false; SavePet(false, ref mypet); } try { using (PetfirstData pfData = new PetfirstData()) { pfData.SavePet(mypet, mCustomer.CustomerId); } } catch (Exception ex) { LoggingError("Saving Pet", ex.ToString()); }//don't do anything if store data fails if (this.Request.Url.AbsoluteUri.ToLower().Contains("addpets_xs.aspx")) { Response.Redirect("~/AddPets.aspx", false); Context.ApplicationInstance.CompleteRequest(); } else { bindPets(); ResetInput(); DetermineButtonText(); } } catch (Exception ex) { displayError("saving pet", ex.ToString(), true); } } } }
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); }