Example #1
0
        public savinggoal saveSavingGoals(savinggoal goals)
        {
            int status = 1;

            try
            {
                dbDataContext ct = new dbDataContext();

                ct.savinggoals.InsertOnSubmit(goals);
                ct.SubmitChanges();
            }
            catch (Exception e)
            {
                status = 0;
                string str = e.Message;
            }

            if (status == 0)
            {
                goals = null;
            }

            return goals;
        }
        private void populateSavingGoal(savinggoal savingGoal, assumption assmptn, string caseid)
        {
            double shortfallSurplus = 0;

            savingGoalNeeded2.Selected = true;

            if (savingGoal != null)
            {
                savingGoalNeeded.SelectedValue = savingGoal.savingGoalNeeded.ToString();

                goal.Text = savingGoal.goal;
                yrstoAccumulate.Text = savingGoal.yrstoaccumulate;

                if(savingGoal.amtneededfv!=null && savingGoal.amtneededfv!="")
                {
                    futureValue.Text = savingGoal.amtneededfv;
                }
                else
                {
                    futureValue.Text = "0";
                }

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

                assetList.DataSource = savingGoal.existingassetsgs;
                assetList.DataBind();

                if (savingGoal.existingassetsgs != null)
                {
                    ViewState["noofassets"] = savingGoal.existingassetsgs.Count;

                    if (savingGoal.existingassetstotal != null && savingGoal.existingassetstotal != "")
                    {
                        existingAssets.Text = savingGoal.existingassetstotal;
                    }
                    else
                    {
                        existingAssets.Text = "0";
                    }

                }

                shortfallSurplus = (double.Parse(existingAssets.Text) + double.Parse(maturityValue.Text)) - double.Parse(futureValue.Text);
                totalShortfallSurplus.Text = Math.Abs(shortfallSurplus).ToString();

            }

            if (shortfallSurplus < 0)
            {
                ttlSS.Text = "Shortfall";
                ttlSS.Style.Add("color", "red");
            }
            else if (shortfallSurplus > 0)
            {
                ttlSS.Text = "Surplus";
                ttlSS.Style.Add("color", "black");
            }
            else
            {
                ttlSS.Text = "Shortfall / Surplus";
                ttlSS.Style.Add("color", "black");
            }

            activityId.Value = caseid;
        }
        protected void submitSavingGoals(object sender, EventArgs e)
        {
            savinggoal goals = new savinggoal();

            goals.savingGoalNeeded = Convert.ToInt16(savingGoalNeeded.SelectedValue);

            if (goals.savingGoalNeeded == 2)
            {
                goals.goal = goal.Text;
                goals.yrstoaccumulate = yrstoAccumulate.Text;
                goals.amtneededfv = futureValue.Text;
                goals.maturityvalue = maturityValue.Text;

                if (totalShortfallSurplus.Text != null && totalShortfallSurplus.Text != "")
                {
                    double ttl = double.Parse(totalShortfallSurplus.Text);
                    if (ttl < 0)
                    {
                        totalShortfallSurplus.Text = Math.Abs(ttl).ToString();
                    }
                }
                goals.total = totalShortfallSurplus.Text;

                goals.existingassetstotal = existingAssets.Text;
            }
            else if (goals.savingGoalNeeded == 1 || goals.savingGoalNeeded == 0)
            {
                goals.goal = "";
                goals.yrstoaccumulate = "0";
                goals.amtneededfv = "0";
                goals.maturityvalue = "0";
                goals.total = "0";
                goals.existingassetstotal = "0";
            }

            goals.deleted = false;

            string caseid = "";
            if (ViewState["caseid"] != null)
            {
                caseid = ViewState["caseid"].ToString();
                goals.caseid = caseid;
            }

            int noofea = 0;
            if (goals.savingGoalNeeded == 2)
            {
                if (noofmembers.Value != "")
                {
                    noofea = Int16.Parse(noofmembers.Value);
                }
            }

            EntitySet<existingassetsg> easgList = new EntitySet<existingassetsg>();
            if (noofea > 0)
            {
                for (int i = 1; i <= noofea; i++)
                {
                    existingassetsg easg = new existingassetsg();
                    easg.asset = Request.Form["pridesc-" + i];
                    easg.presentvalue = Request.Form["pri_" + i];
                    easg.percentpa = Request.Form["sec_" + i];

                    if ((Request.Form["pridesc-" + i] != null) && (Request.Form["pri_" + i] != null) && (Request.Form["sec_" + i]!=null))
                    {
                        easgList.Add(easg);
                    }

                }
                goals.existingassetsgs = easgList;
            }

            int sgid = 0;
            if (ViewState["sgid"] != null)
            {
                sgid = Int32.Parse(ViewState["sgid"].ToString());
            }

            if (ViewState["casetype"] != null && ViewState["casetype"].ToString() == "new")
            {
                goals = savingGoalsDao.saveSavingGoals(goals);
            }
            else if (ViewState["casetype"] != null && ViewState["casetype"].ToString() == "update")
            {
                goals = savingGoalsDao.updateSavingGoals(goals, sgid);
            }

            string actv = "";
            if (ViewState["activity"] != null)
            {
                actv = ViewState["activity"].ToString();
            }

            string status = activityStatusCheck.getSavingGoalStatus(caseid);
            activityStatusDao.saveOrUpdateActivityStatus(caseid, actv, status);

            markStatusOnTab(caseid);

            string caseStatus = activityStatusCheck.getZPlanStatus(caseid);

            string url = Server.MapPath("~/_layouts/Zurich/Printpages/");
            pdfData = activityStatusCheck.sendDataToSalesPortal(caseid, caseStatus, url, sendPdf);

            /*if (st == 1)
            {
                lblStatusSubmitted.Visible = false;
            }
            else
            {
                lblStatusSubmissionFailed.Visible = true;
            }*/

            if (goals != null)
            {
                lblSavingGoalSuccess.Visible = true;

                savingGoal = savingGoalsDao.getSavingGoal(caseid);

                savinggoal displaysg = null;
                if (savingGoal != null && savingGoal.Count > 0)
                {
                    if (addandsave.Value == "1")
                    {
                        displaysg = savingGoal[savingGoal.Count-1];
                    }
                    else
                    {
                        bool found = false;
                        int count = 0;
                        foreach (savinggoal sgl in savingGoal)
                        {
                            if (sgid == sgl.id)
                            {
                                found = true;
                                break;
                            }
                            count++;
                        }

                        if (found)
                        {
                            displaysg = savingGoal[count];
                        }
                        else
                        {
                            displaysg = savingGoal[0];
                        }
                    }

                    savinggoalid.Value = displaysg.id.ToString();
                    addandsave.Value = "";
                }
                populateSavingGoal(displaysg, assmptn, caseid);

                List<savinggoal> gridgoal = savingGoal;
                foreach (savinggoal s in gridgoal)
                {
                    double damtfv = 0;
                    double dmaturityval = 0;
                    double deattl = 0;

                    if (s.amtneededfv != null && s.amtneededfv != "")
                    {
                        damtfv = double.Parse(s.amtneededfv);
                    }
                    if (s.maturityvalue != null && s.maturityvalue != "")
                    {
                        dmaturityval = double.Parse(s.maturityvalue);
                    }
                    if (s.existingassetstotal != null && s.existingassetstotal != "")
                    {
                        deattl = double.Parse(s.existingassetstotal);
                    }

                    if (((dmaturityval + deattl) - damtfv) < 0)
                    {
                        s.total = "-" + s.total;
                    }
                }

                //existingsggrid.DataSource = savingGoal;
                existingsggrid.DataSource = gridgoal;
                existingsggrid.DataBind();

                //refreshSavingGoal();
            }
            else
            {
                lblSavingGoalFailed.Visible = true;
            }
        }
Example #4
0
        public savinggoal updateSavingGoals(savinggoal goals, int sgid)
        {
            savinggoal retrievedGoal = null;

            try
            {
                dbDataContext ct = new dbDataContext();

                //retrieve existing saving goal
                var querySavingGoals = from sg in ct.savinggoals
                                       where sg.caseid == goals.caseid && sg.id == sgid
                                       select sg;
                foreach (savinggoal sgoals in querySavingGoals)
                {
                    retrievedGoal = sgoals;
                }

                //retrievedGoal = goals;

                //update saving goal attributes
                retrievedGoal.amtneededfv = goals.amtneededfv;
                retrievedGoal.goal = goals.goal;
                retrievedGoal.maturityvalue = goals.maturityvalue;
                retrievedGoal.regularannualcontrib = goals.regularannualcontrib;
                retrievedGoal.total = goals.total;
                retrievedGoal.yrstoaccumulate = goals.yrstoaccumulate;
                retrievedGoal.existingassetstotal = goals.existingassetstotal;
                retrievedGoal.savingGoalNeeded = goals.savingGoalNeeded;

                //delete existing assets for the saving goal
                var queryExistingAssets = from easg in ct.existingassetsgs
                                          where easg.savinggoalsid == retrievedGoal.id
                                       select easg;
                foreach (existingassetsg easgoals in queryExistingAssets)
                {
                    ct.existingassetsgs.DeleteOnSubmit(easgoals);
                    //ct.SubmitChanges();
                }

                //update existing assets list for the saving goal
                if (goals.existingassetsgs != null && goals.existingassetsgs.Count > 0)
                {
                    EntitySet<existingassetsg> easgList = new EntitySet<existingassetsg>();
                    foreach (existingassetsg sgea in goals.existingassetsgs)
                    {
                        easgList.Add(sgea);
                    }
                    retrievedGoal.existingassetsgs = easgList;
                }

                if (retrievedGoal.savingGoalNeeded == 1 || retrievedGoal.savingGoalNeeded == 0)
                {
                    var sgGoalRecords = from sgids in ct.savinggoals
                                        where sgids.caseid == goals.caseid
                                        select sgids;
                    int[] arrRecordIds = null;

                    if (sgGoalRecords != null)
                    {
                        int size = sgGoalRecords.ToArray().Length;
                        arrRecordIds = new int[size];
                    }

                    int index = 0;
                    foreach (savinggoal sgl in sgGoalRecords)
                    {
                        arrRecordIds[index] = sgl.id;
                        index++;
                    }

                    var todelExistingAssets = from easg in ct.existingassetsgs
                                              where arrRecordIds.Contains(easg.savinggoalsid)
                                              select easg;
                    foreach (existingassetsg easgoals in todelExistingAssets)
                    {
                        ct.existingassetsgs.DeleteOnSubmit(easgoals);
                    }

                    var toDeleteSgGoals = from sg in ct.savinggoals
                                          where sg.caseid == goals.caseid && sg.id != sgid
                                          select sg;
                    foreach (savinggoal s in toDeleteSgGoals)
                    {
                        ct.savinggoals.DeleteOnSubmit(s);
                    }
                }

                ct.SubmitChanges();

            }
            catch (Exception e)
            {
                string str = e.Message;
            }

            return retrievedGoal;
        }
Example #5
0
 partial void Deletesavinggoal(savinggoal instance);
Example #6
0
 partial void Updatesavinggoal(savinggoal instance);
Example #7
0
 partial void Insertsavinggoal(savinggoal instance);