private void UpdateDatabaseForTemplate()
        {
            try
            {
                TeamProjectTime2Gateway teamProjectTime2Gateway = new TeamProjectTime2Gateway(teamProjectTime2TDSToSave);
                teamProjectTime2Gateway.UpdateForTemplate();

                teamProjectTime2TDS.AcceptChanges();
                teamProjectTime2TDSToSave.AcceptChanges();

                // Store dataset
                Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
                template = teamProjectTime2TDS.Template;
                Session["template"] = teamProjectTime2TDS.Template;
                teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
                Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP; ;
            }
            catch (Exception ex)
            {
                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void GrdTeamProjectTimeDetailAdd()
        {
            Page.Validate();
            if (Page.IsValid)
            {
                Page.Validate("footerValidData");
                if (Page.IsValid)
                {
                    Page.Validate("footerData");
                    if (Page.IsValid)
                    {
                        int teamProjectTimeId = Int32.Parse(hdfTeamProjectTimeID.Value);
                        int employeeId = Int32.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEmployeesFooter")).SelectedValue);
                        int companiesId = int.Parse(ddlClient.SelectedValue);
                        int projectId = int.Parse(ddlProject.SelectedValue);
                        DateTime date_ = tkrdpDate_.SelectedDate.Value;
                        Int64? mealsCountry = null; if (ddlMealsCountry.SelectedValue != "-1") mealsCountry = Int64.Parse(ddlMealsCountry.SelectedValue);

                        string startTimeFooter = "";
                        string startHoursFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeHourFooter")).SelectedValue != "") startHoursFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeHourFooter")).SelectedValue.Trim();
                        string startMinutesFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeMinuteFooter")).SelectedValue != "") startMinutesFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlStartTimeMinuteFooter")).SelectedValue.Trim();

                        if ((startHoursFooter != "") && (startMinutesFooter != ""))
                        {
                            startTimeFooter = startHoursFooter + ":" + startMinutesFooter;
                        }

                        string endTimeFooter = "";
                        string endHoursFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeHourFooter")).SelectedValue != "") endHoursFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeHourFooter")).SelectedValue.Trim();
                        string endMinutesFooter = ""; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeMinuteFooter")).SelectedValue != "") endMinutesFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlEndTimeMinuteFooter")).SelectedValue.Trim();

                        if ((endHoursFooter != "") && (endMinutesFooter != ""))
                        {
                            endTimeFooter = endHoursFooter + ":" + endMinutesFooter;
                        }

                        decimal? offsetFooter = 0; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlLunchFooter")).SelectedValue != "0") offsetFooter = Decimal.Round(decimal.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlLunchFooter")).SelectedValue), 2);
                        double? offsetFooterFinal = null; if (offsetFooter.HasValue) offsetFooterFinal = double.Parse(((decimal)offsetFooter).ToString());
                        string typeOfWorkFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlTypeOfWorkFooter")).SelectedValue;
                        int? unitIdFooter = null; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlUnitFooter")).SelectedValue != "-1") unitIdFooter = Int32.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlUnitFooter")).SelectedValue);
                        int? towedIdFooter = null; if (((DropDownList)grdProjectTime.FooterRow.FindControl("ddlTowedFooter")).SelectedValue != "-1") towedIdFooter = Int32.Parse(((DropDownList)grdProjectTime.FooterRow.FindControl("ddlTowedFooter")).SelectedValue);
                        string workingDetailsFooter = tbxWorkingDetails.Text;
                        bool isMealsAllowanceFooter = false;// ((CheckBox)grdProjectTime.FooterRow.FindControl("ckbxMealsAllowanceFooter")).Checked;
                        string commentsFooter = ((TextBox)grdProjectTime.FooterRow.FindControl("tbxCommentsFooter")).Text;
                        int companyId = Int32.Parse(hdfCompanyId.Value);
                        bool fairWageFooter = false; if (hdfFairWage.Value == "True") fairWageFooter = true;

                        string jobClassTypeFooter = ((DropDownList)grdProjectTime.FooterRow.FindControl("ddlJobClassTypeFooter")).SelectedValue;

                        string projectTimeState = "For Approval"; if ((string)ViewState["LHMode"] == "Partial") projectTimeState = "Approved";

                        string work_ = "";
                        string function_ = "";
                        if (typeOfWorkFooter != "(Select)")
                        {
                            string[] workFunction = typeOfWorkFooter.ToString().Trim().Split('.');
                            work_ = workFunction[0].Trim();
                            function_ = workFunction[1].Trim();
                        }

                        ProjectGateway projectGateway = new ProjectGateway(new DataSet());
                        projectGateway.LoadByProjectId(projectId);
                        CountryGateway countryGateway = new CountryGateway(new DataSet());
                        countryGateway.LoadByCountryId(projectGateway.GetCountryID(projectId));
                        string location = countryGateway.GetName(projectGateway.GetCountryID(projectId));

                        // Insert Data
                        TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
                        teamProjectTime2DetailTemp.Insert(teamProjectTimeId, employeeId, companiesId, projectId, date_, startTimeFooter, endTimeFooter, offsetFooterFinal, workingDetailsFooter, location, mealsCountry, isMealsAllowanceFooter, unitIdFooter, towedIdFooter, projectTimeState, commentsFooter, work_, function_, typeOfWorkFooter, fairWageFooter, jobClassTypeFooter);

                        // Store Dataset
                        Session.Remove("teamProjectTimeDetailTempDummy");
                        Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
                        teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
                        Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP; ;

                        grdProjectTime.DataBind();
                        grdProjectTime.PageIndex = grdProjectTime.PageCount - 1;
                    }
                }
            }
        }
        private void PostStepDataChanges()
        {
            int teamProjectTimeId = (int)ViewState["teamProjectTimeId"];
            string templateName = "";
            int companiesId = int.Parse(ddlClient.SelectedValue);
            int projectId = int.Parse(ddlProject.SelectedValue);
            DateTime date_ = tkrdpDate_.SelectedDate.Value;
            string workingDetails = ""; if (tbxWorkingDetails.Text != "(Select)") workingDetails = tbxWorkingDetails.Text;
            string work_ = ddlTypeOfWork.SelectedValue;
            string function_ = ddlFunction.SelectedValue;

            ProjectGateway projectGateway = new ProjectGateway(new DataSet());
            projectGateway.LoadByProjectId(projectId);

            CountryGateway countryGateway = new CountryGateway(new DataSet());
            countryGateway.LoadByCountryId(projectGateway.GetCountryID(projectId));

            string location = countryGateway.GetName(projectGateway.GetCountryID(projectId));

            DateTime? startTime = null;
            if ((ddlStartTimeHour.SelectedValue.Trim() != "") && (ddlStartTimeMinute.SelectedValue.Trim() != "") )
            {
                startTime = new DateTime(date_.Year, date_.Month, date_.Day, Int32.Parse(ddlStartTimeHour.SelectedValue), Int32.Parse(ddlStartTimeMinute.SelectedValue), 0);
            }

            DateTime? endTime = null;
            if ((ddlEndTimeHour.SelectedValue.Trim() != "") && (ddlEndTimeMinute.SelectedValue.Trim() != "") )
            {
                endTime = new DateTime(date_.Year, date_.Month, date_.Day, Int32.Parse(ddlEndTimeHour.SelectedValue), Int32.Parse(ddlEndTimeMinute.SelectedValue), 0);
            }

            double? offset = 0; if (ddlLunch.SelectedValue != "0") offset = double.Parse(ddlLunch.SelectedValue);
            Int64? mealsCountry = null; if (ddlMealsCountry.SelectedValue != "-1") mealsCountry = Int64.Parse(ddlMealsCountry.SelectedValue);
            string mealsAllowanceType = ""; //if (cbxMealsAllowance.Checked) mealsAllowanceType = "Full Day";
            decimal mealsAllowance = MealsAllowance.GetMealsAllowance(mealsCountry, false, "Full Day");
            string comments = "";
            string type = "Template";
            string state = "Done";
            int loginId = Convert.ToInt32(Session["loginID"]);
            bool deleted = false;
            int? unitId = null;
            int? towedUnitId = null;
            bool fairWage = false; if (hdfFairWage.Value == "True") fairWage = true;

            // New template check
            TeamProjectTime2 teamProjectTime2 = new TeamProjectTime2(teamProjectTime2TDS);
            if (((int)ViewState["teamProjectTimeId"] == 0) && ((string)ViewState["StepFrom"] != "Employees"))
            {
                // ... Insert team project time
                teamProjectTime2.Insert(teamProjectTimeId, templateName, companiesId, projectId, date_, startTime, endTime, offset, workingDetails, location, mealsCountry, mealsAllowanceType, mealsAllowance, unitId, towedUnitId, comments, type, state, loginId, deleted, work_, function_, fairWage);
            }
            else
            {
                // ... Update team project time
                teamProjectTime2.Update(teamProjectTimeId, templateName, companiesId, projectId, date_, startTime, endTime, offset, workingDetails, location, mealsCountry, mealsAllowanceType, mealsAllowance, unitId, towedUnitId, comments, type, state, loginId, deleted, work_, function_, fairWage);
            }

            // Store date in date edit for employees step
            tbxDate.Text = tkrdpDate_.SelectedDate.Value.ToString();
            hdfDate.Value = tkrdpDate_.SelectedDate.Value.ToString();

            // Store data in hidden components for employees step
            hdfTeamProjectTimeID.Value = teamProjectTimeId.ToString();
            hdfCompaniesID.Value = companiesId.ToString();
            hdfProjectID.Value = projectId.ToString();

            string startTimeForNextStep = "";
            if ((ddlStartTimeHour.SelectedValue.Trim() != "") && (ddlStartTimeMinute.SelectedValue.Trim() != ""))
            {
                startTimeForNextStep = ddlStartTimeHour.SelectedValue.Trim() + ":" + ddlStartTimeMinute.SelectedValue.Trim();
            }
            hdfStartTime.Value = startTimeForNextStep;

            string endTimeForNextStep = "";
            if ((ddlEndTimeHour.SelectedValue.Trim() != "") && (ddlEndTimeMinute.SelectedValue.Trim() != ""))
            {
                endTimeForNextStep = ddlEndTimeHour.SelectedValue.Trim() + ":" + ddlEndTimeMinute.SelectedValue.Trim();
            }

            hdfEndTime.Value = endTimeForNextStep;
            if (offset != null) hdfOffset.Value = offset.ToString(); else hdfOffset.Value = "";
            hdfWorkingDetails.Value = workingDetails.ToString();
            hdfLocation.Value = location.ToString();
            hdfMealsCountry.Value = ddlMealsCountry.SelectedValue;
            hdfIsMealsAllowance.Value = "false";// cbxMealsAllowance.Checked.ToString();
            hdfMealsAllowance.Value = mealsAllowance.ToString();
            hdfProjectTimeState.Value = "For Approval"; if ((string)ViewState["LHMode"] == "Partial") hdfProjectTimeState.Value = "Approved";
            //if (cbxClearUnitAssigment.Checked)
            hdfClearUnitAssigment.Value = "false";

            // ... For work and function string
            hdfWork_.Value = work_;
            hdfFunction_.Value = function_;
            hdfWorkFunctionConcat.Value = work_ + " . " + function_;

            // Clear Unit Assigment validation
            //if (cbxClearUnitAssigment.Checked)
            //{
            //    // ... Update detail
            //    TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
            //    teamProjectTime2DetailTemp.UpdateAll(teamProjectTimeId);
            //}
            //else
            //{
                // ... Update detail
                TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
                teamProjectTime2DetailTemp.UpdateAll(teamProjectTimeId, false);
            //}

            // Store datasets
            Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
            teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
            Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
        }
        // ////////////////////////////////////////////////////////////////////////
        // INITIAL EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_FULL_EDITING"]))
                {
                    if (!(Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_ADD"])))
                    {
                        if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT"]))
                        {
                            if (!Convert.ToBoolean(Session["sgLFS_LABOUR_HOURS_OTHERS_TIMESHEETS_MANAGEMENT_WED"]))
                            {
                                Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                            }
                        }
                    }
                }

                // Tag page
                Session.Remove("teamProjectTime2TDS");
                Session.Remove("sectionsReinstatePostVideoSelect");

                Session.Remove("template");
                Session.Remove("templateDummy");

                Session.Remove("teamProjectTimeDetailTemp");
                Session.Remove("teamProjectTimeDetailTempDummy");

                Session.Remove("teamProjectTimeSection");
                Session.Remove("teamProjectTimeSectionDummy");

                Session.Remove("teamProjectTimeSectionLateral");
                Session.Remove("teamProjectTimeSectionLateralDummy");

                Session.Remove("teamProjectTimeSectionMH");
                Session.Remove("teamProjectTimeSectionMHDummy");

                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfBtnNext.Value = "False";

                // Initialize  variables
                lblMessage.Visible = false;

                // ... Initialize viewstate variables
                System.Configuration.AppSettingsReader appSettingReader = new System.Configuration.AppSettingsReader();
                ViewState["LHMode"] = appSettingReader.GetValue("LABOUR_HOURS_OPERATION_MODE", typeof(System.String)).ToString();
                ViewState["StepFrom"] = "Out";
                ViewState["teamProjectTimeId"] = 0;

                // ... Prepare initial data for template
                odsTemplate.SelectParameters.RemoveAt(0);
                odsTemplate.SelectParameters.Add("loginId", Convert.ToInt32(Session["loginID"]).ToString());
                odsTemplate.Select();

                // Store datasets
                teamProjectTime2TDS = new TeamProjectTime2TDS();
                Session["teamProjectTime2TDS"] = teamProjectTime2TDS;

                template = teamProjectTime2TDS.Template;
                Session["template"] = teamProjectTime2TDS.Template;

                teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
                Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;

                teamProjectTimeSection = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION;
                Session["teamProjectTimeSection"] = teamProjectTimeSection;

                teamProjectTimeSectionLateral = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERAL;
                Session["teamProjectTimeSectionLateral"] = teamProjectTimeSectionLateral;

                teamProjectTimeSectionMH = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_MH;
                Session["teamProjectTimeSectionMH"] = teamProjectTimeSectionMH;

                Session["sectionsReinstatePostVideoSelect"] = sectionsReinstatePostVideoSelect;

                // StepSection1In
                wzTeam.ActiveStepIndex = 0;
                StepBeginIn();
            }
            else
            {
                // Restore datasets
                teamProjectTime2TDS = (TeamProjectTime2TDS)Session["teamProjectTime2TDS"];

                template = teamProjectTime2TDS.Template;
                Session["template"] = teamProjectTime2TDS.Template;

                teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
                Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;

                teamProjectTimeSection = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION;
                Session["teamProjectTimeSection"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION;

                teamProjectTimeSectionLateral = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERAL;
                Session["teamProjectTimeSectionLateral"] = teamProjectTimeSectionLateral;

                teamProjectTimeSectionMH = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_MH;
                Session["teamProjectTimeSectionMH"] = teamProjectTimeSectionMH;

                sectionsReinstatePostVideoSelect = (ArrayList)Session["sectionsReinstatePostVideoSelect"];
            }
        }
        protected void grdProjectTime_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            Page.Validate("editValidData");
            if (Page.IsValid)
            {
                Page.Validate("editData");
                if (Page.IsValid)
                {
                    int teamProjectTimeId = (int)e.Keys["TeamProjectTimeID"];
                    int detailId = (int)e.Keys["DetailID"];
                    DateTime date_ = DateTime.Parse(hdfDate.Value);

                    int employeeId = Int32.Parse(((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlEmployeesEdit")).SelectedValue);
                    int companiesId = int.Parse(ddlClient.SelectedValue);
                    int projectId = int.Parse(ddlProject.SelectedValue);
                    Int64? mealsCountry = null; if (ddlMealsCountry.SelectedValue != "-1") mealsCountry = Int64.Parse(ddlMealsCountry.SelectedValue);
                    string startTime = "";
                    string startHoursEdit = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlStartTimeHourEdit")).SelectedValue.Trim();
                    string startMinutesEdit = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlStartTimeMinuteEdit")).SelectedValue.Trim();

                    if ((startHoursEdit != "") && (startMinutesEdit != ""))
                    {
                        startTime = startHoursEdit + ":" + startMinutesEdit;
                    }

                    string endTime = "";
                    string endHoursEdit = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlEndTimeHourEdit")).SelectedValue.Trim();
                    string endMinutesEdit = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlEndTimeMinuteEdit")).SelectedValue.Trim();

                    if ((endHoursEdit != "") && (endMinutesEdit != ""))
                    {
                        endTime = endHoursEdit + ":" + endMinutesEdit;
                    }

                    decimal? offset = 0; if (((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlLunchEdit")).SelectedValue != "0") offset = decimal.Round(Decimal.Parse(((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlLunchEdit")).SelectedValue), 2);
                    double? offsetFinal = null; if (offset.HasValue) offsetFinal = double.Parse(((decimal)offset).ToString());
                    string workingDetails = tbxWorkingDetails.Text;
                    bool isMealsAllowance = false;// ((CheckBox)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ckbxMealsAllowanceEdit")).Checked;
                    int? unitId = null; if (((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlUnitEdit")).SelectedValue != "-1") unitId = Int32.Parse(((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlUnitEdit")).SelectedValue);
                    int? towedUnitId = null; if (((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlTowedEdit")).SelectedValue != "-1") towedUnitId = Int32.Parse(((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlTowedEdit")).SelectedValue);
                    string comments = ((TextBox)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("tbxCommentsEdit")).Text;
                    string workFunctionConcat = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlTypeOfWorkFunctionEdit")).SelectedValue;

                    string work_ = "";
                    string function_ = "";
                    if (workFunctionConcat != "(Select)")
                    {
                        string[] workFunction = workFunctionConcat.ToString().Trim().Split('.');
                        work_ = workFunction[0].Trim();
                        function_ = workFunction[1].Trim();
                    }

                    bool fairWage = false; if (hdfFairWage.Value == "True") fairWage = true;
                    string jobClassType = ((DropDownList)grdProjectTime.Rows[e.RowIndex].Cells[3].FindControl("ddlJobClassTypeEdit")).SelectedValue;

                    ProjectGateway projectGateway = new ProjectGateway(new DataSet());
                    projectGateway.LoadByProjectId(projectId);
                    CountryGateway countryGateway = new CountryGateway(new DataSet());
                    countryGateway.LoadByCountryId(projectGateway.GetCountryID(projectId));
                    string location = countryGateway.GetName(projectGateway.GetCountryID(projectId));

                    // Update data
                    TeamProjectTime2DetailTemp teamProjectTime2DetailTemp = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
                    teamProjectTime2DetailTemp.Update(teamProjectTimeId, detailId, employeeId, date_, startTime, endTime, offsetFinal, workingDetails, location, mealsCountry, isMealsAllowance, unitId, towedUnitId, comments, work_, function_, workFunctionConcat, fairWage, jobClassType);

                    // Store dataset
                    Session.Remove("teamProjectTimeDetailTempDummy");
                    Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
                    Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
                    teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                e.Cancel = true;
            }
        }
        // /////////////////////////////////////////////////////////////////////////////////////////////////////
        //
        // STEP4 - EMPLOYEES
        //
        // ////////////////////////////////////////////////////////////////////////
        // STEP4 - EMPLOYEES - EVENTS
        //
        protected void grdProjectTime_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            // Project Time Gridview, if the gridview is edition mode
            if (grdProjectTime.EditIndex >= 0)
            {
                grdProjectTime.UpdateRow(grdProjectTime.EditIndex, true);
            }

            // Delete project time
            int teamProjectTimeId = (int)e.Keys["TeamProjectTimeID"];
            int detailId = (int)e.Keys["DetailID"];

            // Delete team project time details
            TeamProjectTime2DetailTemp teamProjectTime2Detail = new TeamProjectTime2DetailTemp(teamProjectTime2TDS);
            teamProjectTime2Detail.Delete(teamProjectTimeId, detailId);

            // Store dataset
            Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
            Session.Remove("teamProjectTimeDetailTempDummy");
            teamProjectTimeDetailTemp = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
            Session["teamProjectTimeDetailTemp"] = teamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMP;
        }
        protected void AddProjectTimeNewEmptyFix(GridView grdProjectTime)
        {
            if (grdProjectTime.Rows.Count == 0)
            {
                TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMPDataTable dt = new TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMPDataTable();
                dt.AddLFS_TEAM_PROJECT_TIME_DETAIL_TEMPRow(-1, -1, -1, -1, -1, DateTime.Now, "", "", -1, -1, "", "", -1, false, -1, -1, "", "", false, "", "", "", false, "");
                Session["teamProjectTimeDetailTempDummy"] = dt;

                grdProjectTime.DataBind();
            }

            // normally executes at all postbacks
            if (grdProjectTime.Rows.Count == 1)
            {
                TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMPDataTable dt = (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMPDataTable)Session["teamProjectTimeDetailTempDummy"];
                if (dt != null)
                {
                    grdProjectTime.Rows[0].Visible = false;
                    grdProjectTime.Rows[0].Controls.Clear();
                }
            }
        }
        public TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMPDataTable GetTeamProjectTimeDetail()
        {
            teamProjectTimeDetailTemp = (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMPDataTable)Session["teamProjectTimeDetailTempDummy"];
            if (teamProjectTimeDetailTemp == null)
            {
                teamProjectTimeDetailTemp = ((TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_DETAIL_TEMPDataTable)Session["teamProjectTimeDetailTemp"]);
            }

            return teamProjectTimeDetailTemp;
        }