public TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERALDataTable GetLateralsInformation()
        {
            teamProjectTimeSectionLateral = (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERALDataTable)Session["teamProjectTimeSectionLateralDummy"];

            if (teamProjectTimeSectionLateral == null)
            {
                teamProjectTimeSectionLateral = (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERALDataTable)Session["teamProjectTimeSectionLateral"];
            }

            teamProjectTimeSectionLateral.DefaultView.Sort = "SectionID ASC";

            return teamProjectTimeSectionLateral;
        }
        private void LateralsProcessGrid()
        {
            TeamProjectTime2SectionLateral model = new TeamProjectTime2SectionLateral(teamProjectTime2TDS);

            foreach (GridViewRow rowSections in grdSectionsReinstatePostVideo.Rows)
            {
                int totalSelected = 0;
                int totalBrushed = 0;
                int totalOpened = 0;

                string sectionIdReinstatePostVideo = ((Label)rowSections.FindControl("lblSectionID")).Text;

                bool selectedSection = ((CheckBox)rowSections.FindControl("cbxSelected")).Checked;

                if (selectedSection)
                {
                    foreach (GridViewRow row in grdLaterals.Rows)
                    {
                        string sectionId = ((Label)row.FindControl("lblSectionID")).Text;
                        if (sectionId != "")
                        {
                            if (sectionId == sectionIdReinstatePostVideo)
                            {
                                bool selected = ((CheckBox)row.FindControl("cbxSelected")).Checked;
                                bool opened = ((CheckBox)row.FindControl("cbxOpened")).Checked;
                                bool brushed = ((CheckBox)row.FindControl("cbxBrushed")).Checked;
                                string lateralId = ((Label)row.FindControl("lblLateralID")).Text;

                                if (selected)
                                {
                                    totalSelected++;

                                    if (opened)
                                    {
                                        totalOpened++;
                                    }

                                    if (brushed)
                                    {
                                        totalBrushed++;
                                    }
                                }

                                model.Update(sectionId, lateralId, opened, brushed, selected);
                            }
                        }
                    }

                    if (totalSelected > 0)
                    {
                        if (totalOpened == totalSelected)
                        {
                            ((Label)rowSections.FindControl("lblPercentageOpened")).Text = "50";
                        }
                        else
                        {
                            double percentageOpened = ((double)totalOpened / (double)totalSelected) * 50;

                            if (percentageOpened >= 25)
                            {
                                ((Label)rowSections.FindControl("lblPercentageOpened")).Text = "25";
                            }
                            else
                            {
                                ((Label)rowSections.FindControl("lblPercentageOpened")).Text = "0";
                            }
                        }

                        if (totalBrushed == totalSelected)
                        {
                            ((Label)rowSections.FindControl("lblPercentageBrushed")).Text = "50";
                        }
                        else
                        {
                            double percentageBrushed = ((double)totalBrushed / (double)totalSelected) * 50;

                            if (percentageBrushed >= 25)
                            {
                                ((Label)rowSections.FindControl("lblPercentageBrushed")).Text = "25";
                            }
                            else
                            {
                                ((Label)rowSections.FindControl("lblPercentageBrushed")).Text = "0";
                            }
                        }

                        if ((totalOpened == totalSelected) && (totalBrushed == totalSelected))
                        {
                            ((CheckBox)rowSections.FindControl("cbxCompleted")).Checked = true;
                        }
                        else
                        {
                            ((CheckBox)rowSections.FindControl("cbxCompleted")).Checked = false;
                        }
                    }
                }
            }

            model.Table.AcceptChanges();

            teamProjectTimeSectionLateral = (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERALDataTable)model.Table;
            Session["teamProjectTimeSectionLateral"] = teamProjectTimeSectionLateral;
            Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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 cbxSelectedSectionReinstatePostVideo_CheckedChanged(object sender, EventArgs e)
        {
            CheckBox checkbox = (CheckBox)sender;
            GridViewRow row = (GridViewRow)checkbox.NamingContainer;
            string sectionId = ((Label)row.FindControl("lblSectionID")).Text;
            TeamProjectTime2SectionLateral model = new TeamProjectTime2SectionLateral(teamProjectTime2TDS);

            if (sectionsReinstatePostVideoSelect == null)
            {
                sectionsReinstatePostVideoSelect = new ArrayList();
            }

            if (checkbox.Checked)
            {
                if (!sectionsReinstatePostVideoSelect.Contains(sectionId))
                {
                    LateralsProcessGrid();
                    model.Load(sectionId);
                    sectionsReinstatePostVideoSelect.Add(sectionId);
                }

                // Store tables
                teamProjectTimeSectionLateral = (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERALDataTable)model.Table;

                Session["teamProjectTimeSectionLateral"] = teamProjectTimeSectionLateral;
                Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
                Session.Remove("teamProjectTimeSectionLateralDummy");

                grdLaterals.DataBind();

                upnlFullLengthReinstatePostVideo.Update();
            }
            else
            {
                if (sectionsReinstatePostVideoSelect.Contains(sectionId))
                {
                    sectionsReinstatePostVideoSelect.Remove(sectionId);

                    model.Delete(sectionId);

                    // Store tables
                    teamProjectTimeSectionLateral = (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERALDataTable)model.Table;

                    Session["teamProjectTimeSectionLateral"] = teamProjectTimeSectionLateral;
                    Session["teamProjectTime2TDS"] = teamProjectTime2TDS;
                    Session.Remove("teamProjectTimeSectionLateralDummy");

                    grdLaterals.DataBind();

                    upnlFullLengthReinstatePostVideo.Update();
                }
            }

            Session["sectionsReinstatePostVideoSelect"] = sectionsReinstatePostVideoSelect;
        }
        protected void LateralsInformationEmptyFix(GridView grdLaterals)
        {
            if (grdLaterals.Rows.Count == 0)
            {
                TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERALDataTable dt = new TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERALDataTable();
                dt.AddLFS_TEAM_PROJECT_TIME_SECTION_LATERALRow("A", "A", false, false, false, 1);
                Session["teamProjectTimeSectionLateralDummy"] = dt;

                grdLaterals.DataBind();
            }

            // Normally executes at all postbacks
            if (grdLaterals.Rows.Count == 1)
            {
                TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERALDataTable dt = (TeamProjectTime2TDS.LFS_TEAM_PROJECT_TIME_SECTION_LATERALDataTable)Session["teamProjectTimeSectionLateralDummy"];
                if (dt != null)
                {
                    // Hide row
                    grdLaterals.Rows[0].Visible = false;
                    grdLaterals.Rows[0].Controls.Clear();
                }
            }
        }