public ActualCostsNavigatorTDS.BondingCompaniesCostsDataTable GetBondingCompaniesNavigator()
        {
            bondingCompaniesCosts = (ActualCostsNavigatorTDS.BondingCompaniesCostsDataTable)Session["bondingCompaniesCostsNewDummy"];
            if (bondingCompaniesCosts == null)
            {
                bondingCompaniesCosts = ((ActualCostsNavigatorTDS.BondingCompaniesCostsDataTable)Session["bondingCompaniesCosts"]);
            }

            return bondingCompaniesCosts;
        }
        protected void AddNewBondingEmptyFix(GridView grdBondingNavigator)
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);

            if (grdBondingNavigator.Rows.Count == 0)
            {
                ActualCostsNavigatorTDS.BondingCompaniesCostsDataTable dt = new ActualCostsNavigatorTDS.BondingCompaniesCostsDataTable();
                dt.AddBondingCompaniesCostsRow(-1, -1, -1, DateTime.Now, "", "", "", -1, -1, "", false, companyId, false);
                Session["bondingCompaniesCostsNewDummy"] = dt;

                grdBondingNavigator.DataBind();
            }

            // normally executes at all postbacks
            if (grdBondingNavigator.Rows.Count == 1)
            {
                ActualCostsNavigatorTDS.BondingCompaniesCostsDataTable dt = (ActualCostsNavigatorTDS.BondingCompaniesCostsDataTable)Session["bondingCompaniesCostsNewDummy"];
                if (dt != null)
                {
                    grdBondingNavigator.Rows[0].Visible = false;
                    grdBondingNavigator.Rows[0].Controls.Clear();
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

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

                    // Validate query string
                    if ((string)Request.QueryString["source_page"] == null)
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in actual_costs_navigator.aspx");
                    }
                }

                // Tag Page
                hdfCompanyId.Value = Session["companyID"].ToString();
                tkrdpStartDate.SelectedDate = DateTime.Now;
                tkrdpEndDate.SelectedDate = DateTime.Now;

                Session.Remove("subcontractorCostsNewDummy");
                Session.Remove("hotelCostsNewDummy");
                Session.Remove("insuranceCompaniesCostsNewDummy");
                Session.Remove("bondingCompaniesCostsNewDummy");
                Session.Remove("OtherCostsNewDummy");

                // ... for conditions
                ddlCategory.SelectedIndex = 0;
                tbxTextForSearch.Visible = true;
                ddlSubcontractor.Visible = false;
                ddlHotels.Visible = false;
                ddlInsurance.Visible = false;
                ddlBonding.Visible = false;

                // RestoreNavigator
                RestoreNavigatorState();

                // If coming from
                // ... actual_costs_navigator.aspx or actual_costs_navigator2.aspx
                if ((Request.QueryString["source_page"] == "actual_costs_navigator.aspx") || (Request.QueryString["source_page"] == "actual_costs_navigator2.aspx"))
                {
                    actualCostsNavigatorTDS = (ActualCostsNavigatorTDS)Session["actualCostsNavigatorTDS"];
                }

                // ... actual_costs_edit.aspx, actual_costs_summary.aspx or actual_costs_delete.aspx
                if ((Request.QueryString["source_page"] == "actual_costs_edit.aspx") || (Request.QueryString["source_page"] == "actual_costs_summary.aspx") || (Request.QueryString["source_page"] == "actual_costs_delete.aspx"))
                {
                    RestoreNavigatorState();

                    if (Request.QueryString["update"] == "no")
                    {
                        actualCostsNavigatorTDS = (ActualCostsNavigatorTDS)Session["actualCostsNavigatorTDS"];
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("actualCostsNavigatorTDS");

                        // ... Search data with updates
                        actualCostsNavigatorTDS = SubmitSearch();

                        // ... store datasets
                        Session["actualCostsNavigatorTDS"] = actualCostsNavigatorTDS;
                    }
                }

                Session["actualCostsNavigatorTDS"] = actualCostsNavigatorTDS;
                Session["subcontractorCosts"] = actualCostsNavigatorTDS.SubcontractorCosts;
                Session["hotelCosts"] = actualCostsNavigatorTDS.HotelCosts;
                Session["insuranceCompaniesCosts"] = actualCostsNavigatorTDS.InsuranceCompaniesCosts;
                Session["bondingCompaniesCosts"] = actualCostsNavigatorTDS.BondingCompaniesCosts;
                Session["otherCosts"] = actualCostsNavigatorTDS.OtherCosts;

                // ... For total rows
                // ... ... for the subcontractors total rows
                if (actualCostsNavigatorTDS.SubcontractorCosts.Rows.Count > 0)
                {
                    lblSubcontratorRowsLabel.Text = " Total Subcontractors Rows: " + actualCostsNavigatorTDS.SubcontractorCosts.Rows.Count;
                }

                // ... ... for the hotels total rows
                if (actualCostsNavigatorTDS.HotelCosts.Rows.Count > 0)
                {
                    lblHotelRowsLabel.Text = " Total Hotel Rows: " + actualCostsNavigatorTDS.HotelCosts.Rows.Count;
                }

                // ... ... for the insurance companies total rows
                if (actualCostsNavigatorTDS.InsuranceCompaniesCosts.Rows.Count > 0)
                {
                    lblInsuranceRowsLabel.Text = " Total Insurance Companies Rows: " + actualCostsNavigatorTDS.InsuranceCompaniesCosts.Rows.Count;
                }

                // ... ... for the bonding companies total rows
                if (actualCostsNavigatorTDS.BondingCompaniesCosts.Rows.Count > 0)
                {
                    lblBondingRowsLabel.Text = " Total Bonding Companies Rows: " + actualCostsNavigatorTDS.BondingCompaniesCosts.Rows.Count;
                }

                // ... ... for the other total rows
                if (actualCostsNavigatorTDS.OtherCosts.Rows.Count > 0)
                {
                    lblOtherRowsLabel.Text = " Total Other Costs Rows: " + actualCostsNavigatorTDS.OtherCosts.Rows.Count;
                }

                // Make grids visible
                if (actualCostsNavigatorTDS.SubcontractorCosts.Rows.Count <= 0)
                {
                    pnlGrid.Visible = false;
                }

                if (actualCostsNavigatorTDS.HotelCosts.Rows.Count <= 0)
                {
                    pnlHotelGrid.Visible = false;
                }

                if (actualCostsNavigatorTDS.InsuranceCompaniesCosts.Rows.Count <= 0)
                {
                    pnlInsuranceGrid.Visible = false;
                }

                if (actualCostsNavigatorTDS.BondingCompaniesCosts.Rows.Count <= 0)
                {
                    pnlBondingGrid.Visible = false;
                }

                if (actualCostsNavigatorTDS.OtherCosts.Rows.Count <= 0)
                {
                    pnlOtherGrid.Visible = false;
                }
            }
            else
            {
                // Restore searched data (if any)
                actualCostsNavigatorTDS = (ActualCostsNavigatorTDS)Session["actualCostsNavigatorTDS"];
                subcontractorCosts = actualCostsNavigatorTDS.SubcontractorCosts;
                hotelCosts = actualCostsNavigatorTDS.HotelCosts;
                insuranceCompaniesCosts = actualCostsNavigatorTDS.InsuranceCompaniesCosts;
                bondingCompaniesCosts = actualCostsNavigatorTDS.BondingCompaniesCosts;
                otherCosts = actualCostsNavigatorTDS.OtherCosts;

                // ... For total rows
                // ... ... for the subcontractors total rows
                if (actualCostsNavigatorTDS.SubcontractorCosts.Rows.Count > 0)
                {
                    lblSubcontratorRowsLabel.Text = " Total Subcontractors Rows: " + actualCostsNavigatorTDS.SubcontractorCosts.Rows.Count;
                }

                // ... ... for the hotels total rows
                if (actualCostsNavigatorTDS.HotelCosts.Rows.Count > 0)
                {
                    lblHotelRowsLabel.Text = " Total Hotel Rows: " + actualCostsNavigatorTDS.HotelCosts.Rows.Count;
                }

                // ... ... for the insurance companies total rows
                if (actualCostsNavigatorTDS.InsuranceCompaniesCosts.Rows.Count > 0)
                {
                    lblInsuranceRowsLabel.Text = " Total Insurance Companies Rows: " + actualCostsNavigatorTDS.InsuranceCompaniesCosts.Rows.Count;
                }

                // ... ... for the bonding companies total rows
                if (actualCostsNavigatorTDS.BondingCompaniesCosts.Rows.Count > 0)
                {
                    lblBondingRowsLabel.Text = " Total Bonding Companies Rows: " + actualCostsNavigatorTDS.BondingCompaniesCosts.Rows.Count;
                }

                // ... ... for the other total rows
                if (actualCostsNavigatorTDS.OtherCosts.Rows.Count > 0)
                {
                    lblOtherRowsLabel.Text = " Total Other Costs Rows: " + actualCostsNavigatorTDS.OtherCosts.Rows.Count;
                }

                // Make grids visible
                if (actualCostsNavigatorTDS.SubcontractorCosts.Rows.Count <= 0)
                {
                    pnlGrid.Visible = false;
                }

                if (actualCostsNavigatorTDS.HotelCosts.Rows.Count <= 0)
                {
                    pnlHotelGrid.Visible = false;
                }

                if (actualCostsNavigatorTDS.InsuranceCompaniesCosts.Rows.Count <= 0)
                {
                    pnlInsuranceGrid.Visible = false;
                }

                if (actualCostsNavigatorTDS.BondingCompaniesCosts.Rows.Count <= 0)
                {
                    pnlBondingGrid.Visible = false;
                }

                if (actualCostsNavigatorTDS.OtherCosts.Rows.Count <= 0)
                {
                    pnlOtherGrid.Visible = false;
                }
            }
        }