protected void Page_Load(object sender, EventArgs e)
        {
            activity = activityStatusDao.getActivity(4);
            ViewState["activity"] = activity;

            lblPdSummarySaveSuccess.Visible = false;
            lblPdSummarySaveFailed.Visible = false;

            incomeExpense incomeExpense = null;

            if (!IsPostBack)
            {
                string nextCaseId = Request.Form["caseid"];
                string menuCaseId = Request.QueryString["caseid"];
                string helperUsed = Request.Form["helperUsed"];
                string caseId = "";
                IncomeExpenseDAO incomeExpenseDao = new IncomeExpenseDAO();

                if (nextCaseId != null && nextCaseId != "")
                {
                    caseId = nextCaseId;
                }

                if (menuCaseId != null && menuCaseId != "")
                {
                    caseId = menuCaseId;
                }

                if (Session["fnacaseid"] != null)
                {
                    caseId = Session["fnacaseid"].ToString();
                }

                ViewState["caseId"] = caseId;

                if (caseId != null || caseId != "")
                {
                    incomeExpense = incomeExpenseDao.getIncomeExpenseForCase(caseId);

                }

                populateIncomeAndExpenseDetails(incomeExpense, caseId);
            }
        }
        private void populateFamilyNeedIfNoNeed(string caseId)
        {
            IncomeExpenseDAO incomeExpenseDao = new IncomeExpenseDAO();
            incomeExpense incomeExpense = incomeExpenseDao.getIncomeExpenseForCase(caseId);

            AssetAndLiabilityDAO assetLiabilityDao = new AssetAndLiabilityDAO();
            assetAndLiability assetAndLiability = assetLiabilityDao.getAssetLiabilityForCase(caseId);

            string yearsToSupport = getYearsToSupport(caseId);

            txtYrsOfSupport.Text = yearsToSupport;

            float percentage = 70;

            familyIncPrNeeded2.Selected = true;
            mortgagePrNeeded2.Selected = true;

            if (incomeExpense != null)
            {
                if (incomeExpense.netMonthlyIncomeAfterCpf != null && incomeExpense.netMonthlyIncomeAfterCpf != "")
                {
                    txtReplacementIncome.Text = Math.Round((float.Parse(incomeExpense.netMonthlyIncomeAfterCpf) * 12 * percentage * .01)) + "";
                }
                else
                    txtReplacementIncome.Text = "0";
            }
            else
                txtReplacementIncome.Text = "0";

            if (incomeExpense != null)
            {
                if (incomeExpense.emergencyFundsNeeded != null && incomeExpense.emergencyFundsNeeded != "")
                    txtEmergencyFundsNeeded.Text = incomeExpense.emergencyFundsNeeded;
                else
                    txtEmergencyFundsNeeded.Text = "0";
            }
            else
                txtEmergencyFundsNeeded.Text = "0";

                AssumptionDAO assumptionDao = new AssumptionDAO();
                txtInflationAdjustedReturns.Text = assumptionDao.getAssumptionById(4).percentage + "";

            if (assetAndLiability != null)
            {
                float liability = 0;

                if (assetAndLiability.vehicleLoan != null && assetAndLiability.vehicleLoan != "")
                {
                    liability += float.Parse(assetAndLiability.vehicleLoan);
                }

                if (assetAndLiability.cashLoan != null && assetAndLiability.cashLoan != "")
                {
                    liability += float.Parse(assetAndLiability.cashLoan);
                }

                if (assetAndLiability.creditCard != null && assetAndLiability.creditCard != "")
                {
                    liability += float.Parse(assetAndLiability.creditCard);
                }

                if (assetAndLiability.liabilityOthers != null)
                {
                    int count = assetAndLiability.liabilityOthers.Count;

                    EntitySet<liabilityOther> others = assetAndLiability.liabilityOthers;
                    for (int i = 0; i < count; i++)
                    {
                        if (others[i].cash != null && others[i].cash != "")
                            liability += float.Parse(others[i].cash);
                    }
                }

                txtOtherLiabilities.Text = liability + "";
            }
            else
                txtOtherLiabilities.Text = "0";

            float existLifeInsurance = 0;
            if (incomeExpense != null)
            {
                if (incomeExpense.DeathTermInsuranceSA != null && incomeExpense.DeathTermInsuranceSA != "")
                {
                    existLifeInsurance += float.Parse(incomeExpense.DeathTermInsuranceSA);
                }
                if (incomeExpense.DeathWholeLifeInsuranceSA != null && incomeExpense.DeathWholeLifeInsuranceSA != "")
                {
                    existLifeInsurance += float.Parse(incomeExpense.DeathWholeLifeInsuranceSA);
                }
                if (incomeExpense.lifeInsuranceSA != null && incomeExpense.lifeInsuranceSA != "")
                {
                    existLifeInsurance += float.Parse(incomeExpense.lifeInsuranceSA);
                }
            }

            txtExistingLifeInsurance.Text = existLifeInsurance + "";

            if (assetAndLiability != null)
            {
                if (assetAndLiability.homeMortgage != null && assetAndLiability.homeMortgage != "")
                {
                    txtMortgageProtectionOutstanding.Text = assetAndLiability.homeMortgage;
                }
                else
                    txtMortgageProtectionOutstanding.Text = "0";
            }
            else
                txtMortgageProtectionOutstanding.Text = "0";

            if (incomeExpense != null)
            {
                if (incomeExpense.mortgageSA != null && incomeExpense.mortgageSA != "")
                {
                    txtMortgageProtectionInsurances.Text = incomeExpense.mortgageSA;
                }
                else
                    txtMortgageProtectionInsurances.Text = "0";
            }
            else
                txtMortgageProtectionInsurances.Text = "0";
        }
        private void populateFamilyNeed(familyNeed fNeed)
        {
            //txtReplacementIncome.Text = (fNeed.replacementIncomeRequired == null || fNeed.replacementIncomeRequired == "") ? "0" : fNeed.replacementIncomeRequired;

            familyIncPrNeeded.SelectedValue = fNeed.familyIncPrNeeded.ToString();
            mortgagePrNeeded.SelectedValue = fNeed.mortgageNeeded.ToString();

            if(fNeed.yearsOfSupportRequired == null || fNeed.yearsOfSupportRequired == "")
            {
                string yearsToSupport = getYearsToSupport(fNeed.caseId);
                txtYrsOfSupport.Text = yearsToSupport;
            }
            else
                txtYrsOfSupport.Text=fNeed.yearsOfSupportRequired;

            txtInflationAdjustedReturns.Text = (fNeed.inflationAdjustedReturns == null || fNeed.inflationAdjustedReturns == "") ? "0" : fNeed.inflationAdjustedReturns;
            txtLumpSumRequired.Text = (fNeed.lumpSumRequired == null || fNeed.lumpSumRequired == "") ? "0" : fNeed.lumpSumRequired;
            txtOtherLiabilities.Text = (fNeed.otherLiabilities == null || fNeed.otherLiabilities == "") ? "0" : fNeed.otherLiabilities;
            txtEmergencyFundsNeeded.Text = (fNeed.emergencyFundsNeeded == null || fNeed.emergencyFundsNeeded == "") ? "0" : fNeed.emergencyFundsNeeded;
            txtFinalExpenses.Text = (fNeed.finalExpenses == null || fNeed.finalExpenses == "") ? "0" : fNeed.finalExpenses;
            txtOtherFundingNeeds.Text = (fNeed.otherFundingNeeds == null || fNeed.otherFundingNeeds == "") ? "0" : fNeed.otherFundingNeeds;
            //txtotherComments.Text = (fNeed.otherComments == null || fNeed.otherComments == "") ? "0" : fNeed.otherComments;
            txtTotalRequired.Text = (fNeed.totalRequired == null || fNeed.totalRequired == "") ? "0" : fNeed.totalRequired;
            txtExistingLifeInsurance.Text = (fNeed.existingLifeInsurance == null || fNeed.existingLifeInsurance == "") ? "0" : fNeed.existingLifeInsurance;
            //txtExistingAssetsFamilyneeds.Text = (fNeed.existingAssetsFamilyneeds == null || fNeed.existingAssetsFamilyneeds == "") ? "0" : fNeed.existingAssetsFamilyneeds;
            txtTotalShortfallSurplus.Text = (fNeed.totalShortfallSurplus == null || fNeed.totalShortfallSurplus == "") ? "0" : fNeed.totalShortfallSurplus;
            hiddenTotalShortfallSurplus.Value = (fNeed.totalShortfallSurplus == null || fNeed.totalShortfallSurplus == "") ? "0" : fNeed.totalShortfallSurplus;

            txtMortgageProtectionOutstanding.Text = (fNeed.mortgageProtectionOutstanding == null || fNeed.mortgageProtectionOutstanding == "") ? "0" : fNeed.mortgageProtectionOutstanding;
               // txtMortgageProtectionInsurances.Text = (fNeed.mortgageProtectionInsurances == null || fNeed.mortgageProtectionInsurances == "") ? "0" : fNeed.mortgageProtectionInsurances;
            txtMortgageProtectionTotal.Text = (fNeed.mortgageProtectionTotal == null || fNeed.mortgageProtectionTotal == "") ? "0" : fNeed.mortgageProtectionTotal;

            float percentage= 70;

            IncomeExpenseDAO incomeExpenseDao = new IncomeExpenseDAO();
            incomeExpense incomeExpense= incomeExpenseDao.getIncomeExpenseForCase(fNeed.caseId);

            AssetAndLiabilityDAO assetLiabilityDao= new AssetAndLiabilityDAO();
            assetAndLiability assetAndLiability=assetLiabilityDao.getAssetLiabilityForCase(fNeed.caseId);

            if (fNeed.replacementIncomeRequired == null || fNeed.replacementIncomeRequired == "")
            {
                if(incomeExpense!=null)
                {
                    if (incomeExpense.netMonthlyIncomeAfterCpf != null && incomeExpense.netMonthlyIncomeAfterCpf != "")
                    {
                        txtReplacementIncome.Text=Math.Round((float.Parse(incomeExpense.netMonthlyIncomeAfterCpf)*12*percentage*.01))+"";
                    }
                }
                else
                    txtReplacementIncome.Text="0";
            }
            else
                txtReplacementIncome.Text=fNeed.replacementIncomeRequired;

            if (fNeed.emergencyFundsNeeded == null || fNeed.emergencyFundsNeeded == "")
            {
                if(incomeExpense!=null)
                {
                    if (incomeExpense.emergencyFundsNeeded != null &&  incomeExpense.emergencyFundsNeeded == "")
                        txtEmergencyFundsNeeded.Text=incomeExpense.emergencyFundsNeeded;
                }
                else
                    txtEmergencyFundsNeeded.Text="0";
            }
            else
                txtEmergencyFundsNeeded.Text=fNeed.emergencyFundsNeeded;

            if(fNeed.otherLiabilities==null || fNeed.otherLiabilities=="")
            {

                if(assetAndLiability!=null)
                {
                    float liability=0;

                    if (assetAndLiability.vehicleLoan != null && assetAndLiability.vehicleLoan != "")
                    {
                        liability+=float.Parse(assetAndLiability.vehicleLoan);
                    }

                    if (assetAndLiability.cashLoan != null && assetAndLiability.cashLoan != "")
                    {
                        liability+=float.Parse(assetAndLiability.cashLoan);
                    }

                    if (assetAndLiability.creditCard != null && assetAndLiability.creditCard != "")
                    {
                        liability+=float.Parse(assetAndLiability.creditCard);
                    }

                    if(assetAndLiability.liabilityOthers!=null)
                    {
                        int count=assetAndLiability.liabilityOthers.Count;

                        EntitySet<liabilityOther> others = assetAndLiability.liabilityOthers;
                        for (int i = 0; i < count; i++)
                        {
                            if (others[i].cash != null && others[i].cash != "")
                                liability+= float.Parse(others[i].cash);
                        }
                    }

                    txtOtherLiabilities.Text=liability+"";
                }
                else
                    txtOtherLiabilities.Text="0";
            }

            float existLifeInsurance=0;

            if(fNeed.existingLifeInsurance ==null || fNeed.existingLifeInsurance=="")
            {
                if (incomeExpense != null)
                {
                    if (incomeExpense.DeathTermInsuranceSA != null && incomeExpense.DeathTermInsuranceSA != "")
                    {
                        existLifeInsurance += float.Parse(incomeExpense.DeathTermInsuranceSA);
                    }
                    if (incomeExpense.DeathWholeLifeInsuranceSA != null && incomeExpense.DeathWholeLifeInsuranceSA != "")
                    {
                        existLifeInsurance += float.Parse(incomeExpense.DeathWholeLifeInsuranceSA);
                    }
                    if (incomeExpense.lifeInsuranceSA != null && incomeExpense.lifeInsuranceSA != "")
                    {
                        existLifeInsurance += float.Parse(incomeExpense.lifeInsuranceSA);
                    }
                }

                 txtExistingLifeInsurance.Text=existLifeInsurance+"";
            }
            else
                txtExistingLifeInsurance.Text=fNeed.existingLifeInsurance;

            if(fNeed.mortgageProtectionOutstanding ==null || fNeed.mortgageProtectionOutstanding=="")
            {
                if(assetAndLiability!=null)
                {
                    if (assetAndLiability.homeMortgage != null && assetAndLiability.homeMortgage != "")
                    {
                        txtMortgageProtectionOutstanding.Text=assetAndLiability.homeMortgage;
                    }
                    else
                        txtMortgageProtectionOutstanding.Text="0";
                }
            }
            else
                txtMortgageProtectionOutstanding.Text=fNeed.mortgageProtectionOutstanding;

            if(fNeed.mortgageProtectionInsurances ==null || fNeed.mortgageProtectionInsurances=="")
            {
                if(incomeExpense!=null)
                {
                    if (incomeExpense.mortgageSA != null && incomeExpense.mortgageSA != "")
                    {
                        txtMortgageProtectionInsurances.Text=incomeExpense.mortgageSA;
                    }
                    else
                        txtMortgageProtectionInsurances.Text="0";
                }
                else
                   txtMortgageProtectionInsurances.Text="0";
            }
                else
                    txtMortgageProtectionInsurances.Text=fNeed.mortgageProtectionInsurances;

            if (fNeed.inflationAdjustedReturns == null || fNeed.inflationAdjustedReturns == "")
            {
                AssumptionDAO assumptionDao = new AssumptionDAO();
                txtInflationAdjustedReturns.Text = assumptionDao.getAssumptionById(4).percentage+"";
            }
            else
                txtInflationAdjustedReturns.Text = fNeed.inflationAdjustedReturns;

            if (fNeed.familyNeedsAssets!=null)
                noofmembers.Value = fNeed.familyNeedsAssets.Count+"";
            else
                noofmembers.Value = "0";

            familyNeedsAssetList.DataSource = fNeed.familyNeedsAssets;
            familyNeedsAssetList.DataBind();

            if (fNeed.familyNeedsAssets != null)
            {
                ViewState["assetsSize"] = fNeed.familyNeedsAssets.Count;

                double sum = 0;
                txtExistingAssetsFamilyneeds.Text = sum.ToString();
            }
        }
        private void populateRetirementGoal(retirementgoal retirementGoalSelf, assumption inflationAdjustedReturnAsmptn, assumption annualInflationReturn, string caseid)
        {
            double shortfallSurplusSelf = 0;
            int iIntendedRetirementAge = 0;

            PersonalDetailsDAO dao = new PersonalDetailsDAO();
            personaldetail detail = dao.getPersonalDetail(caseid);

            int yrDob = 0;
            int currentYr = DateTime.Now.Year;
            int agePolicyOwner = 0;
            int iYrstoRetirement = 0;

            try
            {
                DateTime dt2 = DateTime.ParseExact(detail.datepicker, "dd/MM/yyyy", System.Globalization.CultureInfo.InvariantCulture);
                yrDob = dt2.Year;

                if (DateTime.Now.Month < dt2.Month)
                {
                    agePolicyOwner = currentYr - yrDob - 1;
                }
                else if (DateTime.Now.Month > dt2.Month)
                {
                    agePolicyOwner = currentYr - yrDob;
                }
                else
                {
                    if (DateTime.Now.Day < dt2.Day)
                    {
                        agePolicyOwner = currentYr - yrDob - 1;
                    }
                    else if ((DateTime.Now.Day > dt2.Day) || (DateTime.Now.Day == dt2.Day))
                    {
                        agePolicyOwner = currentYr - yrDob;
                    }
                }

                iYrstoRetirement = iIntendedRetirementAge - agePolicyOwner;
            }
            catch (Exception e)
            {
                //log exception to db
                exceptionlog exLog = new exceptionlog();
                exLog.message = e.Message + " class: ShowRetirementGoals Method: populateRetirementGoal setting yrs to retirement";
                exLog.source = e.Source;

                string strtmp = e.StackTrace;
                strtmp = strtmp.Replace('\r', ' ');
                strtmp = strtmp.Replace('\n', ' ');
                exLog.stacktrace = strtmp;

                exLog.targetsitename = e.TargetSite.Name;

                activityStatusDao.logException(exLog);
            }
            pownerdob.Value = agePolicyOwner.ToString();

            if (detail != null)
            {
                pownergender.Value = detail.gender;
            }

            IncomeExpenseDAO iedao = new IncomeExpenseDAO();
            incomeExpense iedetail = iedao.getIncomeExpenseForCase(caseid);

            retirementGoalNeeded2.Selected = true;

            //populate self retirement goals
            if (retirementGoalSelf != null)
            {
                retirementGoalNeeded.SelectedValue = retirementGoalSelf.retirementGoalNeeded.ToString();

                if (retirementGoalSelf.intendedretirementage != null && retirementGoalSelf.intendedretirementage != "")
                {
                    intendedRetirementAge.Text = retirementGoalSelf.intendedretirementage;
                }
                else
                {
                    intendedRetirementAge.Text = "62";
                }
                iIntendedRetirementAge = Int32.Parse(intendedRetirementAge.Text);

                //expectedRetirementAgelbl.Text = intendedRetirementAge.Text;

                if (retirementGoalSelf.incomerequired != null && retirementGoalSelf.incomerequired != "")
                {
                    incomeRequiredUponRetirement.Text = retirementGoalSelf.incomerequired;
                }
                else
                {
                    double dincomeReq = 0;
                    if (iedetail!=null && iedetail.netMonthlyIncomeAfterCpf != null && iedetail.netMonthlyIncomeAfterCpf != "")
                    {
                        dincomeReq = 0.7 * 12 * double.Parse(iedetail.netMonthlyIncomeAfterCpf);
                    }

                    incomeRequiredUponRetirement.Text = Math.Round(dincomeReq, 2).ToString();
                }

                //presentIncomeNeededlbl.Text = incomeRequiredUponRetirement.Text;

                if (retirementGoalSelf.yrstoretirement != null && retirementGoalSelf.yrstoretirement != "")
                {
                    yearsToRetirement.Text = retirementGoalSelf.yrstoretirement;
                }
                else
                {
                    yearsToRetirement.Text = iYrstoRetirement.ToString();
                }

                //currentAgelbl.Text = (double.Parse(intendedRetirementAge.Text) - double.Parse(yearsToRetirement.Text)).ToString();

                if (retirementGoalSelf.inflationrate == null || retirementGoalSelf.inflationrate == "")
                {
                    if (annualInflationReturn != null)
                    {
                        annualInflationRate.Text = annualInflationReturn.percentage.Value.ToString();
                    }
                    else
                    {
                        annualInflationRate.Text = "0";
                    }
                }
                else
                {
                    annualInflationRate.Text = retirementGoalSelf.inflationrate;
                }

                //inflationRatelbl.Text = annualInflationRate.Text;

                if (retirementGoalSelf.futureincome != null && retirementGoalSelf.futureincome != "")
                {
                    futureIncomeNeeded.Text = retirementGoalSelf.futureincome;
                }
                else
                {
                    futureIncomeNeeded.Text = "0";
                }

                //futureIncomeNeededChartlbl.Text = futureIncomeNeeded.Text;

                if (retirementGoalSelf.sourcesofincome != null && retirementGoalSelf.sourcesofincome != "")
                {
                    sourcesOfIncome.Text = retirementGoalSelf.sourcesofincome;
                }
                else
                {
                    sourcesOfIncome.Text = "0";
                }

                if (retirementGoalSelf.totalfirstyrincome != null && retirementGoalSelf.totalfirstyrincome != "")
                {
                    totalFirstYearIncomeNeeded.Text = retirementGoalSelf.totalfirstyrincome;
                }
                else
                {
                    totalFirstYearIncomeNeeded.Text = "0";
                }

                //annualAmountlbl.Text = totalFirstYearIncomeNeeded.Text;

                if (retirementGoalSelf.inflationreturnrate == null || retirementGoalSelf.inflationreturnrate == "")
                {
                    if (inflationAdjustedReturnAsmptn != null)
                    {
                        inflationAdjustedReturn.Text = inflationAdjustedReturnAsmptn.percentage.Value.ToString();
                    }
                    else
                    {
                        inflationAdjustedReturn.Text = "0";
                    }
                }
                else
                {
                    inflationAdjustedReturn.Text = retirementGoalSelf.inflationreturnrate;
                }

                //inflationAdjustedReturnslbl.Text = inflationAdjustedReturn.Text;

                if (retirementGoalSelf.durationretirement != null && retirementGoalSelf.durationretirement != "")
                {
                    durationOfRetirement.Text = retirementGoalSelf.durationretirement;
                }
                else
                {
                    int iDurationofRetirement = 0;

                    if (detail.gender == "Male")
                    {
                        iDurationofRetirement = 83 - iIntendedRetirementAge;
                    }
                    else if (detail.gender == "Female")
                    {
                        iDurationofRetirement = 88 - iIntendedRetirementAge;
                    }

                    durationOfRetirement.Text = iDurationofRetirement.ToString();
                }

                //durationOfRetirementValuelbl.Text = durationOfRetirement.Text;
                //ageAtEndOfRetirementlbl.Text = (double.Parse(durationOfRetirement.Text) + double.Parse(intendedRetirementAge.Text)).ToString();

                if (retirementGoalSelf.lumpsumrequired != null && retirementGoalSelf.lumpsumrequired != "")
                {
                    lumpSumRequiredAtRetirement.Text = retirementGoalSelf.lumpsumrequired;
                }
                else
                {
                    lumpSumRequiredAtRetirement.Text = "0";
                }

                if (retirementGoalSelf.maturityvalue != null && retirementGoalSelf.maturityvalue != "")
                {
                    maturityValue2.Text = retirementGoalSelf.maturityvalue;
                }
                else
                {
                    maturityValue2.Text = "0";
                }

                assetListSelf.DataSource = retirementGoalSelf.existingassetrgs;
                assetListSelf.DataBind();

                if (retirementGoalSelf.existingassetrgs != null)
                {
                    ViewState["noofassets"] = retirementGoalSelf.existingassetrgs.Count;
                    if (retirementGoalSelf.existingassetstotal != null && retirementGoalSelf.existingassetstotal != "")
                    existingAssets2.Text = retirementGoalSelf.existingassetstotal;
                    else
                        existingAssets2.Text = "0";

                }

                shortfallSurplusSelf = double.Parse(existingAssets2.Text) + double.Parse(maturityValue2.Text) - double.Parse(lumpSumRequiredAtRetirement.Text);
                if (shortfallSurplusSelf < 0)
                {
                    ttlSSSelf.Text = "Shortfall";
                    ttlSSSelf.Style.Add("color", "red");
                }
                else if (shortfallSurplusSelf > 0)
                {
                    ttlSSSelf.Text = "Surplus";
                    ttlSSSelf.Style.Add("color", "black");
                }
                else
                {
                    ttlSSSelf.Text = "Total (Shortfall / Surplus)";
                    ttlSSSelf.Style.Add("color", "black");
                }

                totalShortfallSurplus2.Text = Math.Abs(shortfallSurplusSelf).ToString();
            }

            activityId.Value = caseid;
        }
        private void populateMyNeedIfNoNeed(string caseId)
        {
            IncomeExpenseDAO IncomeExpenseDAO = new IncomeExpenseDAO();
            incomeExpense incomeExpense = IncomeExpenseDAO.getIncomeExpenseForCase(caseId);

            AssetAndLiabilityDAO assetLiabilityDao = new AssetAndLiabilityDAO();
            assetAndLiability assetAndLiability = assetLiabilityDao.getAssetLiabilityForCase(caseId);

            float criticalIllnessPercentage = 100;
            float disabilityIncomePercentage = 75;

            criticalIllnessPr2.Selected = true;
            disabilityPr2.Selected = true;
            hospitalmedCoverNeeded2.Selected = true;
            accidentalHealthCoverNeeded2.Selected = true;

            if (incomeExpense != null)
            {
                if (incomeExpense.netMonthlyIncomeAfterCpf != null && incomeExpense.netMonthlyIncomeAfterCpf != "")
                {
                    replacementIncomeRequired.Text = Math.Round((float.Parse(incomeExpense.netMonthlyIncomeAfterCpf) * 12 * criticalIllnessPercentage * .01)) + "";
                }
            }
            else
                replacementIncomeRequired.Text = "0";

            if (incomeExpense != null)
            {
                if (incomeExpense.netMonthlyIncomeAfterCpf != null && incomeExpense.netMonthlyIncomeAfterCpf != "")
                {
                    disabilityProtectionReplacementIncomeRequired.Text = (float.Parse(incomeExpense.netMonthlyIncomeAfterCpf) * 12 * disabilityIncomePercentage * .01) + "";
                }
            }
            else
                disabilityProtectionReplacementIncomeRequired.Text = "0";

            if (incomeExpense != null)
            {
                if (incomeExpense.criticalIllnessSA != null && incomeExpense.criticalIllnessSA != "")
                {
                    txtCriticalIllnessInsurance.Text = incomeExpense.criticalIllnessSA;
                }
                else
                    txtCriticalIllnessInsurance.Text = "0";
            }
            else
                txtCriticalIllnessInsurance.Text = "0";

            if (incomeExpense != null)
            {
                if (incomeExpense.tpdcSA != null && incomeExpense.tpdcSA != "")
                {
                    disabilityInsurance.Text = incomeExpense.tpdcSA;
                }
                else
                    disabilityInsurance.Text = "0";
            }
            else
                disabilityInsurance.Text = "0";

            AssumptionDAO assumptionDao = new AssumptionDAO();
            inflationAdjustedReturns.Text = assumptionDao.getAssumptionById(4).percentage + "";
            inflatedAdjustedReturns.Text = assumptionDao.getAssumptionById(4).percentage + "";
            yearsOfSupportRequired.Text = getYearsToSupportCriticalIllness(caseId);
            disabilityYearsOfSupport.Text = getYearsToSupportDisabilityProtection(caseId);
        }
        private void populateMyNeed(myNeed mNeed)
        {
            IncomeExpenseDAO IncomeExpenseDAO = new IncomeExpenseDAO();
            incomeExpense incomeExpense= IncomeExpenseDAO.getIncomeExpenseForCase(mNeed.caseId);

            AssetAndLiabilityDAO assetLiabilityDao = new AssetAndLiabilityDAO();
            assetAndLiability assetAndLiability = assetLiabilityDao.getAssetLiabilityForCase(mNeed.caseId);

            float criticalIllnessPercentage = 100;
            float disabilityIncomePercentage = 75;

            if (mNeed.criticalIllnessPrNeeded != null)
            {
                criticalIllnessPr.SelectedValue = mNeed.criticalIllnessPrNeeded.ToString();
            }
            else
            {
                criticalIllnessPr2.Selected = true;
            }

            if (mNeed.disabilityPrNeeded != null)
            {
                disabilityPr.SelectedValue = mNeed.disabilityPrNeeded.ToString();
            }
            else
            {
                disabilityPr2.Selected = true;
            }

            if (mNeed.hospitalmedCoverNeeded != null)
            {
                hospitalmedCoverNeeded.SelectedValue = mNeed.hospitalmedCoverNeeded.ToString();
            }
            else
            {
                hospitalmedCoverNeeded2.Selected = true;
            }

            if (mNeed.accidentalhealthCoverNeeded != null)
            {
                accidentalHealthCoverNeeded.SelectedValue = mNeed.accidentalhealthCoverNeeded.ToString();
            }
            else
            {
                accidentalHealthCoverNeeded2.Selected = true;
            }

            if (mNeed.replacementIncomeRequired == null || mNeed.replacementIncomeRequired == "")
            {
                if (incomeExpense != null)
                {
                    if (incomeExpense.netMonthlyIncomeAfterCpf != null && incomeExpense.netMonthlyIncomeAfterCpf != "")
                    {
                        replacementIncomeRequired.Text = Math.Round((float.Parse(incomeExpense.netMonthlyIncomeAfterCpf) * 12 * criticalIllnessPercentage * .01)) + "";
                    }
                }
                else
                    replacementIncomeRequired.Text = "0";
            }
            else
                replacementIncomeRequired.Text = mNeed.replacementIncomeRequired;

            if (mNeed.disabilityProtectionReplacementIncomeRequired == null || mNeed.disabilityProtectionReplacementIncomeRequired == "")
            {
                if (incomeExpense != null)
                {
                    if (incomeExpense.netMonthlyIncomeAfterCpf != null && incomeExpense.netMonthlyIncomeAfterCpf != "")
                    {
                        disabilityProtectionReplacementIncomeRequired.Text = (float.Parse(incomeExpense.netMonthlyIncomeAfterCpf) * 12 * disabilityIncomePercentage * .01) + "";
                    }
                }
                else
                    disabilityProtectionReplacementIncomeRequired.Text = "0";
            }
            else
                disabilityProtectionReplacementIncomeRequired.Text = mNeed.disabilityProtectionReplacementIncomeRequired;

            if (mNeed.criticalIllnessInsurance == null || mNeed.criticalIllnessInsurance == "")
            {
                if (incomeExpense != null)
                {
                    if (incomeExpense.criticalIllnessSA != null && incomeExpense.criticalIllnessSA != "")
                    {
                        txtCriticalIllnessInsurance.Text = incomeExpense.criticalIllnessSA;
                    }
                    else
                        txtCriticalIllnessInsurance.Text = "0";
                }
                else
                    txtCriticalIllnessInsurance.Text = "0";
             }
            else
                txtCriticalIllnessInsurance.Text = mNeed.criticalIllnessInsurance;

            if (mNeed.disabilityInsurance == null || mNeed.disabilityInsurance == "")
            {
                if (incomeExpense != null)
                {
                    if (incomeExpense.tpdcSA != null && incomeExpense.tpdcSA != "")
                    {
                        disabilityInsurance.Text = incomeExpense.tpdcSA;
                    }
                    else
                        disabilityInsurance.Text = "0";
                }
                else
                    disabilityInsurance.Text = "0";
            }
            else
                disabilityInsurance.Text = mNeed.disabilityInsurance;

            string yearsToSupportCriticalIllness = getYearsToSupportCriticalIllness(mNeed.caseId);
            string yearsToSupportDisabilityProtection = getYearsToSupportDisabilityProtection(mNeed.caseId);

            if (mNeed.yearsOfSupportRequired == null || mNeed.yearsOfSupportRequired == "")
            {
                yearsOfSupportRequired.Text = yearsToSupportCriticalIllness;
            }
            else
                yearsOfSupportRequired.Text = mNeed.yearsOfSupportRequired;

            if (mNeed.disabilityYearsOfSupport == null || mNeed.disabilityYearsOfSupport == "")
            {
                disabilityYearsOfSupport.Text = yearsToSupportDisabilityProtection;
            }
            else
                disabilityYearsOfSupport.Text = mNeed.disabilityYearsOfSupport;

            //inflatedAdjustedReturns.Text = (mNeed.inflatedAdjustedReturns == null || mNeed.inflatedAdjustedReturns == "") ? "0" : mNeed.inflatedAdjustedReturns;
            replacementAmountRequired.Text = (mNeed.replacementAmountRequired == null || mNeed.replacementAmountRequired == "") ? "0" : mNeed.replacementAmountRequired;
            disabilityReplacementAmountRequired.Text = (mNeed.disabilityReplacementAmountRequired == null || mNeed.disabilityReplacementAmountRequired == "") ? "0" : mNeed.disabilityReplacementAmountRequired;
            //disabilityInsurance.Text = (mNeed.disabilityInsurance == null || mNeed.disabilityInsurance == "") ? "0" : mNeed.disabilityInsurance;
            //inflationAdjustedReturns.Text = (mNeed.inflationAdjustedReturns == null || mNeed.inflationAdjustedReturns == "") ? "0" : mNeed.inflationAdjustedReturns;

            if (mNeed.inflationAdjustedReturns == null || mNeed.inflationAdjustedReturns == "")
            {
                AssumptionDAO assumptionDao = new AssumptionDAO();
                inflationAdjustedReturns.Text = assumptionDao.getAssumptionById(4).percentage + "";
            }
            else
                inflationAdjustedReturns.Text = mNeed.inflationAdjustedReturns;

            if (mNeed.inflatedAdjustedReturns == null || mNeed.inflatedAdjustedReturns == "")
            {
                AssumptionDAO assumptionDao = new AssumptionDAO();
                inflatedAdjustedReturns.Text = assumptionDao.getAssumptionById(4).percentage + "";
            }
            else
                inflatedAdjustedReturns.Text = mNeed.inflatedAdjustedReturns;

            txtlumpSumRequiredForTreatment.Text = (mNeed.lumpSumRequiredForTreatment == null || mNeed.lumpSumRequiredForTreatment == "") ? "0" : mNeed.lumpSumRequiredForTreatment;
            //txtCriticalIllnessInsurance.Text = (mNeed.criticalIllnessInsurance == null || mNeed.criticalIllnessInsurance == "") ? "0" : mNeed.criticalIllnessInsurance;
            txtExistingAssetsMyNeedsCritical.Text = (mNeed.existingAssetsMyneeds == null || mNeed.existingAssetsMyneeds == "") ? "0" : mNeed.existingAssetsMyneeds;
            txtExistingAssetsMyneedsDisability.Text = (mNeed.existingAssetsMyneedsDisability == null || mNeed.existingAssetsMyneedsDisability == "") ? "0" : mNeed.existingAssetsMyneedsDisability;
            ddlHospitalTypeList.SelectedValue = (mNeed.typeOfHospitalCoverage == null || mNeed.typeOfHospitalCoverage == "") ? "" : mNeed.typeOfHospitalCoverage;

            if (mNeed.anyExistingPlans != null)
            {
                ddlExistingPlanList.SelectedValue = mNeed.anyExistingPlans == true ? "1" : "0";
            }
            else
            {
                ddlExistingPlanList.SelectedValue = "";
            }
            ViewState["anyExPl"] = ddlExistingPlanList.SelectedValue;

            if (mNeed.typeOfRoomCoverage != null)
            {
                ddlRoomTypeList.SelectedValue = mNeed.typeOfRoomCoverage.ToString();
            }
            else
            {
                ddlRoomTypeList.SelectedValue = "";
            }

            if (mNeed.coverageOldageYesNo != null)
            {
                ddlCoverageOldageYesNo.SelectedValue = mNeed.coverageOldageYesNo == true ? "1" : "0";
            }
            else
                ddlCoverageOldageYesNo.SelectedValue = "";

            if (mNeed.coverageOutpatientMedExp != null)
            {
                coverageOutpatientMedExp.SelectedValue = mNeed.coverageOutpatientMedExp == true ? "1" : "0";
            }
            else
            {
                coverageOutpatientMedExp.SelectedValue = "";
            }

            if (mNeed.coverageLossOfIncome != null)
            {
                coverageLossOfIncome.SelectedValue = mNeed.coverageLossOfIncome == true ? "1" : "0";
            }
            else
            {
                coverageLossOfIncome.SelectedValue = "";
            }

            if (mNeed.coverageOldageDisabilities != null)
            {
                coverageOldageDisabilities.SelectedValue = mNeed.coverageOldageDisabilities == true ? "1" : "0";
            }
            else
            {
                coverageOldageDisabilities.SelectedValue = "";
            }

            if (mNeed.coverageDentalExp != null)
            {
                coverageDentalExp.SelectedValue = mNeed.coverageDentalExp == true ? "1" : "0";
            }
            else
            {
                coverageDentalExp.SelectedValue = "";
            }

            //ddlEpOldageYesNo.SelectedValue = mNeed.epOldageYesNo == true ? "1" : "0";

            if (mNeed.epOldageYesNo != null)
            {
                ddlEpOldageYesNo.SelectedValue = mNeed.epOldageYesNo == true ? "1" : "0";
            }
            else
            {
                ddlEpOldageYesNo.SelectedValue = "";
            }
            ViewState["oldageExPl"] = ddlEpOldageYesNo.SelectedValue;

            //ddlCoveragePersonalYesNo.SelectedValue = mNeed.coveragePersonalYesNo == true ? "1" : "0";

            if (mNeed.coveragePersonalYesNo != null)
            {
                ddlCoveragePersonalYesNo.SelectedValue = mNeed.coveragePersonalYesNo == true ? "1" : "0";
            }
            else
                ddlCoveragePersonalYesNo.SelectedValue = "";

            //ddlEpPersonalYesNo.SelectedValue = mNeed.epPersonalYesNo == true ? "1" : "0";

            if (mNeed.epPersonalYesNo != null)
            {
                ddlEpPersonalYesNo.SelectedValue = mNeed.epPersonalYesNo == true ? "1" : "0";
            }
            else
            {
                ddlEpPersonalYesNo.SelectedValue = "";
            }
            ViewState["personalExPl"] = ddlEpPersonalYesNo.SelectedValue;

            if (mNeed.epOutpatientMedExp != null)
            {
                epOutpatientMedExp.SelectedValue = mNeed.epOutpatientMedExp == true ? "1" : "0";
            }
            else
            {
                epOutpatientMedExp.SelectedValue = "";
            }
            ViewState["epOutpatientMedExp"] = epOutpatientMedExp.SelectedValue;

            if (mNeed.epLossOfIncome != null)
            {
                epLossOfIncome.SelectedValue = mNeed.epLossOfIncome == true ? "1" : "0";
            }
            else
            {
                epLossOfIncome.SelectedValue = "";
            }
            ViewState["epLossOfIncome"] = epLossOfIncome.SelectedValue;

            if (mNeed.epOldageDisabilities != null)
            {
                epOldageDisabilities.SelectedValue = mNeed.epOldageDisabilities == true ? "1" : "0";
            }
            else
            {
                epOldageDisabilities.SelectedValue = "";
            }
            ViewState["epOldageDisabilities"] = epOldageDisabilities.SelectedValue;

            if (mNeed.epDentalExp != null)
            {
                epDentalExp.SelectedValue = mNeed.epDentalExp == true ? "1" : "0";
            }
            else
            {
                epDentalExp.SelectedValue = "";
            }
            ViewState["epDentalExp"] = epDentalExp.SelectedValue;

            if (mNeed.existingPlansDetail != null)
            {
                DetailsOfExistingPlans.Text = mNeed.existingPlansDetail.ToString();
            }
            else
                DetailsOfExistingPlans.Text = "";

            myNeedsCriticalAssetList.DataSource = mNeed.myNeedsCriticalAssets;
            myNeedsCriticalAssetList.DataBind();

            if (mNeed.myNeedsCriticalAssets != null)
            {
                ViewState["noofcriticalassets"] = mNeed.myNeedsCriticalAssets.Count;

                double sum = 0;
                txtTotalShortfallSurplusMyNeeds.Text = sum.ToString();
            }

            myNeedsDisabilityAssetList.DataSource = mNeed.myNeedsDisabilityAssets;
            myNeedsDisabilityAssetList.DataBind();

            if (mNeed.myNeedsDisabilityAssets != null)
            {
                ViewState["noofdisablityassets"] = mNeed.myNeedsDisabilityAssets.Count;
            }
        }