/// <summary>
        /// Get the improvement data from database
        /// </summary>
        private int SaveNewImprovementPlan()
        {
            Thinkgate.Services.Contracts.ImprovementPlanService.ImprovementPlan newImprovementPlan =
                new Thinkgate.Services.Contracts.ImprovementPlanService.ImprovementPlan();

            List<ImprovementPlanActions> actions = new List<ImprovementPlanActions>();
            actions.Add(ImprovementPlanActions.ImprovementPlan);
            newImprovementPlan.Year = Year;
            newImprovementPlan.ImprovementPlanType = ImpType;
            newImprovementPlan.SchoolID = SchoolID;
            return new ImprovementPlanProxy().SaveImprovementPlan(newImprovementPlan, actions, ClientID);

        }
        protected void btnSave_Click(object sender, EventArgs e)
        {
            Thinkgate.Services.Contracts.ImprovementPlanService.ImprovementPlan improvementPlan =
                new Thinkgate.Services.Contracts.ImprovementPlanService.ImprovementPlan();
            List<ImprovementPlanActions> actions = new List<ImprovementPlanActions>();

            List<ImprovementPlanStrategicGoal> strategicGoals = new List<ImprovementPlanStrategicGoal>();

            #region Get Strategic Goal Changes

            foreach (RepeaterItem item in this.rptStrategicGoal.Items.AsParallel())
            {
                TextBox strategicGoalCtrl = (TextBox) item.FindControl("txtStrategicGoal");

                strategicGoals.Add(new ImprovementPlanStrategicGoal
                {
                    StrategicGoal = strategicGoalCtrl.Text,
                    ID = DataIntegrity.ConvertToInt(strategicGoalCtrl.Attributes["StrategicGoalID"]),
                    ImprovementPlanID = ImprovementID
                });
            }

            #endregion Get Strategic Goal Changes


            if (strategicGoals.Count > 0)
            {
                actions.Add(ImprovementPlanActions.StrategicGoal);
                improvementPlan.ImprovementPlanStrategicGoals = strategicGoals;
            }

            actions.Add(ImprovementPlanActions.ImprovementPlan);
            improvementPlan.ID = ImprovementID;
            improvementPlan.Superintendent = txtSuperintendent.Text;
            improvementPlan.Principal = txtPrincipal.Text;
            improvementPlan.SignedDate = rdpCreateDateCoverPage.SelectedDate;
            improvementPlan.IsFinalized = chkFinalized.Checked;



            ImprovementID = new ImprovementPlanProxy().SaveImprovementPlan(improvementPlan, actions, ClientID);
            Button buttonClicked = (Button) sender;
            if (buttonClicked.Text.ToLower().Contains("continue"))
            {
                //Response.Redirect("../ImprovementPlan/ImprovementPlanStrategyPage.aspx?impID=" +
                //                  Cryptography.EncryptInt(ImprovementID, sessionObject.LoggedInUser.CipherKey) +
                //                  "&actType=" +
                //                  Cryptography.EncryptString(ActionType.Edit.ToString(),
                //                      sessionObject.LoggedInUser.CipherKey));

                Response.Redirect("../ImprovementPlan/ImprovementPlanStrategyPage.aspx?impID=" + ImprovementID +
                                  "&actType=" + ActionType.Edit);

            }
            else
            {
                BindImprovementPlanDetails();

            }

        }
        /// <summary>
        /// Save the improvement plan details
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnSave_Click(object sender, EventArgs e)
        {
            try
            {

               var improvementPlan = new Thinkgate.Services.Contracts.ImprovementPlanService.ImprovementPlan();
                improvementPlan.ID = this.ImprovementID;

                List<ImprovementPlanActions> actions = new List<ImprovementPlanActions>();
                ImprovementPlanStrategy planStrategy = default(ImprovementPlanStrategy);
                List<ImprovementPlanSmartGoal> smartGoals = new List<ImprovementPlanSmartGoal>();
                List<ImprovementPlanActionStep> actionSteps = new List<ImprovementPlanActionStep>();

                #region Get Strategy

                //if (eventTargetEnum == EventTargets.btnSaveAndAdd || txtStrategy.Attributes["InitialValue"] != txtStrategy.Text.Trim() ||
                //    this.txtPersonResponsibles.Attributes["InitialValue"].ToString() != this.txtPersonResponsibles.Text.Trim()
                //    )


                if (txtStrategy.Attributes["InitialValue"] != txtStrategy.Text.Trim() ||
                    txtPersonResponsibles.Attributes["InitialValue"] != txtPersonResponsibles.Text.Trim()
                    )
                {                    
                    planStrategy = new ImprovementPlanStrategy
                {
                        ID = ddlStrategy.SelectedValue == String.Empty || ddlStrategy.SelectedIndex == -1 ? default(int) : DataIntegrity.ConvertToInt(ddlStrategy.SelectedValue),
                        ImprovementPlanID = this.ImprovementID,
                        StrategyName = this.txtStrategy.Text.Trim(),
                        PersonResponsible = this.txtPersonResponsibles.Text.Trim()
                    };
                }


                #endregion Get Strategy

                #region Get Smart Goal Changes
                foreach (RepeaterItem item in this.rptSmartGoal.Items.AsParallel())
                {
                    TextBox smartGoalCtrl = (TextBox)item.FindControl("txtSmartGoal");

                    int smartGoalID = DataIntegrity.ConvertToInt(smartGoalCtrl.Attributes["SmartGoalID"].ToString());

                    if (smartGoalCtrl.Text.Trim() != smartGoalCtrl.Attributes["InitialValue"].ToString().Trim())
                        smartGoals.Add(new ImprovementPlanSmartGoal
                        {
                            SmartGoal = smartGoalCtrl.Text,
                            ID = smartGoalID,
                            StrategyID = DataIntegrity.ConvertToInt(this.ddlStrategy.SelectedValue)
                        });
                }
                #endregion Get Smart Goal Changes

                #region Get Action Step Changes
                foreach (DataGridItem item in this.dgActions.Items.AsParallel())
                {
                    HiddenField actionIDCtrl = ((HiddenField)item.FindControl("hidActionID"));
                    DropDownList statusCtrl = ((DropDownList)item.FindControl("ddlStatus"));
                    DropDownList strategyCtrl = ((DropDownList)item.FindControl("ddlStrategyGoal"));
                    TextBox actionStepCtrl = (TextBox)item.FindControl("txtActionSteps");
                    TextBox personResponsibleCtrl = (TextBox)item.FindControl("txtPersonResponsible");
                    RadDatePicker startDateCtrl = ((RadDatePicker)item.FindControl("rdpStartDate"));
                    RadDatePicker finishDateCtrl = ((RadDatePicker)item.FindControl("rdpFinishDate"));
                    TextBox resourceCostsCtrl = (TextBox)item.FindControl("txtResrouceCosts");
                    TextBox expectedResultsCtrl = (TextBox)item.FindControl("txtExpectedResults");


                    if ((statusCtrl.SelectedValue != statusCtrl.Attributes["InitialValue"].ToString()) ||
                        (strategyCtrl.SelectedValue != strategyCtrl.Attributes["InitialValue"].ToString()) ||
                        (actionStepCtrl.Text.Trim() != actionStepCtrl.Attributes["InitialValue"].ToString().Trim()) ||
                        (personResponsibleCtrl.Text.Trim() != personResponsibleCtrl.Attributes["InitialValue"].ToString().Trim()) ||
                        (startDateCtrl.SelectedDate != DataIntegrity.ConvertToNullableDate(startDateCtrl.Attributes["InitialValue"].ToString())) ||
                        (finishDateCtrl.SelectedDate != DataIntegrity.ConvertToNullableDate(finishDateCtrl.Attributes["InitialValue"].ToString())) ||
                        (resourceCostsCtrl.Text.Trim() != resourceCostsCtrl.Attributes["InitialValue"].ToString().Trim()) ||
                        (expectedResultsCtrl.Text.Trim() != expectedResultsCtrl.Attributes["InitialValue"].ToString().Trim()))
                        actionSteps.Add(CreateActionStepFromControl(actionIDCtrl, statusCtrl, strategyCtrl,
                                                                          actionStepCtrl, personResponsibleCtrl, startDateCtrl,
                                                                          finishDateCtrl, resourceCostsCtrl, expectedResultsCtrl));

                }
                #endregion Get Action Step Changes

                if (planStrategy != default(ImprovementPlanStrategy))
                {
                    actions.Add(ImprovementPlanActions.StrategyPlan);
                    improvementPlan.ImprovementPlanStrategies = planStrategy;
                }

                if (smartGoals.Count > 0)
                {
                    actions.Add(ImprovementPlanActions.SmartGoal);
                    improvementPlan.ImprovementPlanSmartGoals = smartGoals;
                }

                if (actionSteps.Count > 0)
                {
                    actions.Add(ImprovementPlanActions.ActionStep);
                    improvementPlan.ImprovementPlanActionSteps = actionSteps;
                }

                int strategyID = new ImprovementPlanProxy().SaveImprovementPlan(improvementPlan, actions, this.ClientID);

                #region Reload the details after save to maintain consistency

                currentStrategyValue = strategyID;

                if (actions.Contains(ImprovementPlanActions.StrategyPlan))
                    ReplaceStrategyDropDown(
                        new ListItem
                        {
                            Value = strategyID.ToString(),
                            Text = txtStrategy.Text.Trim(),
                            Selected = true
                        }, false);

                #endregion Reload the details after save to maintain consistency

                if (eventTargetEnum == EventTargets.btnSaveAndAdd)
                {
                   ReplaceStrategyDropDown(
                            new ListItem
                            {
                                Value = "",
                                Text = string.Empty,
                                Selected = true
                            }, true);

                }

            }
            catch (Exception exception)
            {

            }
        }