/// <summary>
        /// Save
        /// </summary>
        /// <param name="companyId">companyId</param>
        public void Save(int companyId)
        {
            ProjectCostingSheetInformationTDS projectCostingSheetInformationChanges = (ProjectCostingSheetInformationTDS)Data.GetChanges();

            if (projectCostingSheetInformationChanges.BasicInformation.Rows.Count > 0)
            {
                ProjectCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGateway = new ProjectCostingSheetInformationBasicInformationGateway(projectCostingSheetInformationChanges);

                // Update costing sheet
                foreach (ProjectCostingSheetInformationTDS.BasicInformationRow basicInformationRow in (ProjectCostingSheetInformationTDS.BasicInformationDataTable)projectCostingSheetInformationChanges.BasicInformation)
                {
                    // Unchanged values
                    int costingSheetId = basicInformationRow.CostingSheetID;
                    int projectId = basicInformationRow.ProjectID;
                    DateTime startDate = basicInformationRow.StartDate;
                    DateTime endDate = basicInformationRow.EndDate;

                    // Original values
                    string originalName = projectCostingSheetInformationBasicInformationGateway.GetNameOriginal(costingSheetId);
                    decimal originalTotalLabourHoursCad = projectCostingSheetInformationBasicInformationGateway.GetTotalLabourHoursCadOriginal(costingSheetId);
                    decimal originalTotalLabourHoursUsd = projectCostingSheetInformationBasicInformationGateway.GetTotalLabourHoursUsdOriginal(costingSheetId);
                    decimal originalTotalMaterialsCad = projectCostingSheetInformationBasicInformationGateway.GetTotalMaterialsCadOriginal(costingSheetId);
                    decimal originalTotalMaterialsUsd = projectCostingSheetInformationBasicInformationGateway.GetTotalMaterialsUsdOriginal(costingSheetId);
                    decimal originalTotalUnitsCad = projectCostingSheetInformationBasicInformationGateway.GetTotalUnitsCadOriginal(costingSheetId);
                    decimal originalTotalUnitsUsd = projectCostingSheetInformationBasicInformationGateway.GetTotalUnitsUsdOriginal(costingSheetId);
                    decimal originalTotalOtherCostsCad = projectCostingSheetInformationBasicInformationGateway.GetTotalOtherCostsCadOriginal(costingSheetId);
                    decimal originalTotalOtherCostsUsd = projectCostingSheetInformationBasicInformationGateway.GetTotalOtherCostsUsdOriginal(costingSheetId);
                    decimal originalGrandTotalCad = projectCostingSheetInformationBasicInformationGateway.GetGrandTotalCadOriginal(costingSheetId);
                    decimal originalGrandTotalUsd = projectCostingSheetInformationBasicInformationGateway.GetGrandTotalUsdOriginal(costingSheetId);
                    string originalState = projectCostingSheetInformationBasicInformationGateway.GetStateOriginal(costingSheetId);
                    bool originalDeleted = projectCostingSheetInformationBasicInformationGateway.GetDeletedOriginal(costingSheetId);
                    decimal originalTotalSubcontractorsCad = projectCostingSheetInformationBasicInformationGateway.GetTotalSubcontractorsCadOriginal(costingSheetId);
                    decimal originalTotalSubcontractorsUsd = projectCostingSheetInformationBasicInformationGateway.GetTotalSubcontractorsUsdOriginal(costingSheetId);
                    decimal originalGrandRevenue = projectCostingSheetInformationBasicInformationGateway.GetGrandRevenueOriginal(costingSheetId);
                    decimal originalGrandProfit = projectCostingSheetInformationBasicInformationGateway.GetGrandProfitOriginal(costingSheetId);
                    decimal originalGrandGrossMargin = projectCostingSheetInformationBasicInformationGateway.GetGrandGrossMarginOriginal(costingSheetId);

                    // New variables
                    string newName = projectCostingSheetInformationBasicInformationGateway.GetName(costingSheetId);
                    decimal newTotalLabourHoursCad = projectCostingSheetInformationBasicInformationGateway.GetTotalLabourHoursCad(costingSheetId);
                    decimal newTotalLabourHoursUsd = projectCostingSheetInformationBasicInformationGateway.GetTotalLabourHoursUsd(costingSheetId);
                    decimal newTotalMaterialsCad = projectCostingSheetInformationBasicInformationGateway.GetTotalMaterialsCad(costingSheetId);
                    decimal newTotalMaterialsUsd = projectCostingSheetInformationBasicInformationGateway.GetTotalMaterialsUsd(costingSheetId);
                    decimal newTotalUnitsCad = projectCostingSheetInformationBasicInformationGateway.GetTotalUnitsCad(costingSheetId);
                    decimal newTotalUnitsUsd = projectCostingSheetInformationBasicInformationGateway.GetTotalUnitsUsd(costingSheetId);
                    decimal newTotalOtherCostsCad = projectCostingSheetInformationBasicInformationGateway.GetTotalOtherCostsCad(costingSheetId);
                    decimal newTotalOtherCostsUsd = projectCostingSheetInformationBasicInformationGateway.GetTotalOtherCostsUsd(costingSheetId);
                    decimal newGrandTotalCad = projectCostingSheetInformationBasicInformationGateway.GetGrandTotalCad(costingSheetId);
                    decimal newGrandTotalUsd = projectCostingSheetInformationBasicInformationGateway.GetGrandTotalUsd(costingSheetId);
                    string newState = projectCostingSheetInformationBasicInformationGateway.GetState(costingSheetId);
                    bool newDeleted = projectCostingSheetInformationBasicInformationGateway.GetDeleted(costingSheetId);
                    decimal newTotalSubcontractorsCad = projectCostingSheetInformationBasicInformationGateway.GetTotalSubcontractorsCad(costingSheetId);
                    decimal newTotalSubcontractorsUsd = projectCostingSheetInformationBasicInformationGateway.GetTotalSubcontractorsUsd(costingSheetId);
                    decimal newGrandRevenue = projectCostingSheetInformationBasicInformationGateway.GetGrandRevenue(costingSheetId);
                    decimal newGrandProfit = projectCostingSheetInformationBasicInformationGateway.GetGrandProfit(costingSheetId);
                    decimal newGrandGrossMargin = projectCostingSheetInformationBasicInformationGateway.GetGrandGrossMargin(costingSheetId);

                    // ... Update
                    UpdateCostingSheet(costingSheetId, projectId, originalName, startDate, endDate, originalTotalLabourHoursCad, originalTotalLabourHoursUsd, originalTotalMaterialsCad, originalTotalMaterialsUsd, originalTotalUnitsCad, originalTotalUnitsUsd, originalTotalOtherCostsCad, originalTotalOtherCostsUsd, originalGrandTotalCad, originalGrandTotalUsd, originalState, originalDeleted, companyId, originalTotalSubcontractorsCad, originalTotalSubcontractorsUsd, originalGrandRevenue, originalGrandProfit, originalGrandGrossMargin, projectId, newName, startDate, endDate, newTotalLabourHoursCad, newTotalLabourHoursUsd, newTotalMaterialsCad, newTotalMaterialsUsd, newTotalUnitsCad, newTotalUnitsUsd, newTotalOtherCostsCad, newTotalOtherCostsUsd, newGrandTotalCad, newGrandTotalUsd, newState, newDeleted, companyId, newTotalSubcontractorsCad, newTotalSubcontractorsUsd, newGrandRevenue, newGrandProfit, newGrandGrossMargin);
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"]))
                {
                    if (!(Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_DELETE"])))
                    {
                        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) || ((string)Request.QueryString["costing_sheet_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_costing_sheets_delete.aspx");
                }

                // Tag Page
                hdfCostingSheetId.Value = Request.QueryString["costing_sheet_id"].ToString();
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfProjectId.Value = Request.QueryString["project_id"];
                hdfDataChanged.Value = Request.QueryString["data_changed"];
                hdfDataChangedMessage.Value = "Changes made to this project will not be saved.";
                ViewState["state"] = Request.QueryString["state"];
                ViewState["active_tab"] = Request.QueryString["active_tab"];
                ViewState["origin"] = Request.QueryString["origin"];
                ViewState["update"] = Request.QueryString["update"];

                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];

                // If coming from
                // ... project_costing_sheets_navigator2.aspx
                if (Request.QueryString["source_page"] == "project_costing_sheets_navigator.aspx")
                {
                    StoreNavigatorState();
                    ViewState["update"] = "no";

                    projectCostingSheetInformationTDS = new ProjectCostingSheetInformationTDS();

                    int costingSheetId = Int32.Parse(hdfCostingSheetId.Value);
                    int companyId = Int32.Parse(hdfCompanyId.Value);

                    ProjectCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGateway = new ProjectCostingSheetInformationBasicInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationBasicInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"]))
                    {
                        string state = projectCostingSheetInformationBasicInformationGateway.GetState(costingSheetId);
                        if (state == "Approved")
                        {
                            Response.Redirect("./../../error_page.aspx?error=" + "This costing sheet is approved, you can not delete it.");
                        }
                    }

                    // Store dataset
                    Session["projectCostingSheetInformationTDS"] = projectCostingSheetInformationTDS;
                }

                // ... project_costing_sheets_summary.aspx
                if (Request.QueryString["source_page"] == "project_costing_sheets_summary.aspx")
                {
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    // Restore dataset
                    projectCostingSheetInformationTDS = (ProjectCostingSheetInformationTDS)Session["projectCostingSheetInformationTDS"];

                    if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"]))
                    {
                        // Costing Sheet state check
                        ProjectCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGatewayForValidate = new ProjectCostingSheetInformationBasicInformationGateway(projectCostingSheetInformationTDS);
                        string state = projectCostingSheetInformationBasicInformationGatewayForValidate.GetState(Int32.Parse(hdfCostingSheetId.Value));
                        if (state == "Approved")
                        {
                            Response.Redirect("./../../error_page.aspx?error=" + "This costing sheet is approved, you can not delete it.");
                        }
                    }
                }
            }
            else
            {
                // Restore datasets
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectCostingSheetInformationTDS = (ProjectCostingSheetInformationTDS)Session["projectCostingSheetInformationTDS"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // METHODS
        //
        private void LoadBasicData()
        {
            int costingSheetId = Int32.Parse(hdfCostingSheetId.Value);

            ProjectCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGateway = new ProjectCostingSheetInformationBasicInformationGateway(projectCostingSheetInformationTDS);
            if (projectCostingSheetInformationBasicInformationGateway.Table.Rows.Count > 0)
            {
                // Load costing sheet basic data
                tbxState.Text = projectCostingSheetInformationBasicInformationGateway.GetState(costingSheetId);
                tbxTeamMembersTotalCostCAD.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetTotalLabourHoursCad(costingSheetId), 2).ToString();
                tbxTeamMembersTotalCostUSD.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetTotalLabourHoursUsd(costingSheetId), 2).ToString();
                tbxUnitsTotalCostsCAD.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetTotalUnitsCad(costingSheetId), 2).ToString();
                tbxUnitsTotalCostsUSD.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetTotalUnitsUsd(costingSheetId), 2).ToString();
                tbxMaterialsTotalCostsCAD.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetTotalMaterialsCad(costingSheetId), 2).ToString();
                tbxMaterialsTotalCostsUSD.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetTotalMaterialsUsd(costingSheetId), 2).ToString();
                tbxOtherCostsTotalCostsCAD.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetTotalOtherCostsCad(costingSheetId), 2).ToString();
                tbxOtherCostsTotalCostsUSD.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetTotalOtherCostsUsd(costingSheetId), 2).ToString();
                tbxSubcontractorsTotalCostsCAD.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetTotalSubcontractorsCad(costingSheetId), 2).ToString();
                tbxSubcontractorsTotalCostsUSD.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetTotalSubcontractorsUsd(costingSheetId), 2).ToString();
                tbxTotalCostCad.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetGrandTotalCad(costingSheetId), 2).ToString();
                tbxTotalCostUsd.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetGrandTotalUsd(costingSheetId), 2).ToString();
                GetOtherTotals();

                // Validate grid columns
                int projectId = Int32.Parse(hdfProjectId.Value);
                ProjectGateway projectGateway = new ProjectGateway();
                projectGateway.LoadByProjectId(projectId);

                if (projectGateway.GetCountryID(projectId) == 1) //Canada
                {
                    tbxGrandTotal.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetGrandTotalCad(costingSheetId), 2).ToString();
                }
                else
                {
                    tbxGrandTotal.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetGrandTotalUsd(costingSheetId), 2).ToString();
                }

                tbxGrandRevenue.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetGrandRevenue(costingSheetId), 2).ToString();
                tbxRevenueTotal.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetGrandRevenue(costingSheetId), 2).ToString();
                tbxGrandProfit.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetGrandProfit(costingSheetId), 2).ToString();
                tbxGrandGrossMargin.Text = Math.Round(projectCostingSheetInformationBasicInformationGateway.GetGrandGrossMargin(costingSheetId), 2).ToString() + " %";
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            // Set active toolbar
            mForm6 master = (mForm6)this.Master;
            master.ActiveToolbar = "Projects";

            // Security check
            if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
            {
                tkrpbLeftMenuReports.Visible = false;
            }

            ProjectCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGateway = new ProjectCostingSheetInformationBasicInformationGateway(projectCostingSheetInformationTDS);
            string state = projectCostingSheetInformationBasicInformationGateway.GetState(Int32.Parse(hdfCostingSheetId.Value));

            if (state == "In Progress")
            {
                tkrmTop.Items[3].Visible = false; //Set In Progress
                tkrmTop.Items[4].Visible = true; //Set Approved
            }

            if (state == "Approved")
            {
                tkrmTop.Items[3].Visible = false; //Set In Progress
                tkrmTop.Items[4].Visible = false; //Set Approved

                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"]))
                {
                    tkrmTop.Items[0].Visible = false; //Edit
                    tkrmTop.Items[1].Visible = false; //Delete
                }
            }

            // Validate grid columns
            int projectId = Int32.Parse(hdfProjectId.Value);
            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(projectId);

            grdTeamMembers.Columns[10].Visible = false;
            grdTeamMembers.Columns[11].Visible = false;
            grdTeamMembers.Columns[12].Visible = false;
            grdTeamMembers.Columns[13].Visible = false;
            grdTeamMembers.Columns[15].Visible = false;
            grdTeamMembers.Columns[16].Visible = false;
            grdTeamMembers.Columns[19].Visible = false;
            grdTeamMembers.Columns[20].Visible = false;

            if (projectGateway.GetCountryID(projectId) == 1) //Canada
            {
                // Team Members Grid
                grdTeamMembers.Columns[14].Visible = true;
                grdTeamMembers.Columns[17].Visible = true;
                grdTeamMembers.Columns[18].Visible = false;
                grdTeamMembers.Columns[21].Visible = false;

                // Units Grid
                grdUnits.Columns[11].Visible = true;
                grdUnits.Columns[12].Visible = true;
                grdUnits.Columns[13].Visible = false;
                grdUnits.Columns[14].Visible = false;

                grdUnits.Columns[11].Visible = true;
                grdUnits.Columns[12].Visible = true;
                grdUnits.Columns[13].Visible = false;
                grdUnits.Columns[14].Visible = false;

                grdSubcontractors.Columns[8].Visible = true;
                grdSubcontractors.Columns[9].Visible = true;
                grdSubcontractors.Columns[10].Visible = false;
                grdSubcontractors.Columns[11].Visible = false;

                // Materials grid
                grdMaterials.Columns[9].Visible = true;
                grdMaterials.Columns[10].Visible = true;
                grdMaterials.Columns[11].Visible = false;
                grdMaterials.Columns[12].Visible = false;

                // Other costs
                grdOtherCosts.Columns[8].Visible = true;
                grdOtherCosts.Columns[9].Visible = true;
                grdOtherCosts.Columns[10].Visible = false;
                grdOtherCosts.Columns[11].Visible = false;

                // Totals
                lblGrandTotalCost.Text = "Total Cost (CAD) : ";
                tbxTotalCostCad.Visible = true;
                tbxTotalCostUsd.Visible = false;

                lblTeamMembersTotalCost.Text = "Total Cost (CAD) : ";
                tbxTeamMembersTotalCostCAD.Visible = true;
                tbxTeamMembersTotalCostUSD.Visible = false;

                lblUnitsTotalCosts.Text = "Total Cost (CAD) : ";
                tbxUnitsTotalCostsCAD.Visible = true;
                tbxUnitsTotalCostsUSD.Visible = false;

                lblMaterialsTotalCosts.Text = "Total Cost (CAD) : ";
                tbxMaterialsTotalCostsCAD.Visible = true;
                tbxMaterialsTotalCostsUSD.Visible = false;

                lblOtherCostsTotalCosts.Text = "Total Cost (CAD) : ";
                tbxOtherCostsTotalCostsCAD.Visible = true;
                tbxOtherCostsTotalCostsUSD.Visible = false;

                lblSubcontractorsTotalCosts.Text = "Total Cost (CAD) : ";
                tbxSubcontractorsTotalCostsCAD.Visible = true;
                tbxSubcontractorsTotalCostsUSD.Visible = false;

                lblHotelsTotalCosts.Text = "Total Cost (CAD) : ";
                tbxHotelsTotalCostsCAD.Visible = true;
                tbxHotelsTotalCostsUSD.Visible = false;

                lblBondingsTotalCosts.Text = "Total Cost (CAD) : ";
                tbxBondingsTotalCostsCAD.Visible = true;
                tbxBondingsTotalCostsUSD.Visible = false;

                lblInsurancesTotalCosts.Text = "Total Cost (CAD) : ";
                tbxInsurancesTotalCostsCAD.Visible = true;
                tbxInsurancesTotalCostsUSD.Visible = false;

                lblOtherCategoryTotalCosts.Text = "Total Cost (CAD) : ";
                tbxOtherCategoryTotalCostsCAD.Visible = true;
                tbxOtherCategoryTotalCostsUSD.Visible = false;

                lblGrandTotal.Text = "Grand Total (CAD)";
            }
            else
            {
                if (projectGateway.GetCountryID(projectId) == 2) //USA
                {
                    // Team Members Grid
                    grdTeamMembers.Columns[14].Visible = false;
                    grdTeamMembers.Columns[17].Visible = false;
                    grdTeamMembers.Columns[18].Visible = true;
                    grdTeamMembers.Columns[21].Visible = true;

                    // Units Grid
                    grdUnits.Columns[11].Visible = false;
                    grdUnits.Columns[12].Visible = false;
                    grdUnits.Columns[13].Visible = true;
                    grdUnits.Columns[14].Visible = true;

                    grdSubcontractors.Columns[8].Visible = false;
                    grdSubcontractors.Columns[9].Visible = false;
                    grdSubcontractors.Columns[10].Visible = true;
                    grdSubcontractors.Columns[11].Visible = true;

                    // Materials grid
                    grdMaterials.Columns[9].Visible = false;
                    grdMaterials.Columns[10].Visible = false;
                    grdMaterials.Columns[11].Visible = true;
                    grdMaterials.Columns[12].Visible = true;

                    // Other costs
                    grdOtherCosts.Columns[8].Visible = false;
                    grdOtherCosts.Columns[9].Visible = false;
                    grdOtherCosts.Columns[10].Visible = true;
                    grdOtherCosts.Columns[11].Visible = true;

                    // Totals
                    lblGrandTotalCost.Text = "Total Cost (USD) : ";
                    tbxTotalCostCad.Visible = false;
                    tbxTotalCostUsd.Visible = true;

                    lblTeamMembersTotalCost.Text = "Total Cost (USD) : ";
                    tbxTeamMembersTotalCostCAD.Visible = false;
                    tbxTeamMembersTotalCostUSD.Visible = true;

                    lblUnitsTotalCosts.Text = "Total Cost (USD) : ";
                    tbxUnitsTotalCostsCAD.Visible = false;
                    tbxUnitsTotalCostsUSD.Visible = true;

                    lblSubcontractorsTotalCosts.Text = "Total Cost (USD) : ";
                    tbxSubcontractorsTotalCostsCAD.Visible = false;
                    tbxSubcontractorsTotalCostsUSD.Visible = true;

                    lblHotelsTotalCosts.Text = "Total Cost (USD) : ";
                    tbxHotelsTotalCostsCAD.Visible = false;
                    tbxHotelsTotalCostsUSD.Visible = true;

                    lblBondingsTotalCosts.Text = "Total Cost (USD) : ";
                    tbxBondingsTotalCostsCAD.Visible = false;
                    tbxBondingsTotalCostsUSD.Visible = true;

                    lblInsurancesTotalCosts.Text = "Total Cost (USD) : ";
                    tbxInsurancesTotalCostsCAD.Visible = false;
                    tbxInsurancesTotalCostsUSD.Visible = true;

                    lblOtherCategoryTotalCosts.Text = "Total false (USD) : ";
                    tbxOtherCategoryTotalCostsCAD.Visible = false;
                    tbxOtherCategoryTotalCostsUSD.Visible = true;

                    lblMaterialsTotalCosts.Text = "Total Cost (USD) : ";
                    tbxMaterialsTotalCostsCAD.Visible = false;
                    tbxMaterialsTotalCostsUSD.Visible = true;

                    lblOtherCostsTotalCosts.Text = "Total Cost (USD) : ";
                    tbxOtherCostsTotalCostsCAD.Visible = false;
                    tbxOtherCostsTotalCostsUSD.Visible = true;

                    lblGrandTotal.Text = "Grand Total (USD)";
                }
            }

            if (projectGateway.GetProjectType(Int32.Parse(hdfProjectId.Value)) == "Proposal")
            {
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Proposal";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Proposal";

                lblTitleProject.Text = " > Proposal: ";

                tkrpbLeftMenuCurrentProject.Items[0].Items[3].Visible = false; //mSections
                tkrpbLeftMenuCurrentProject.Items[0].Items[4].Visible = false; //mTools
                tkrpbLeftMenuCurrentProject.Items[0].Items[5].Visible = false; //mSeparator
            }

            if (projectGateway.GetProjectType(Int32.Parse(hdfProjectId.Value)) == "Project")
            {
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Project";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Project";

                lblTitleProject.Text = " > Project: ";
            }

            if (projectGateway.GetProjectType(Int32.Parse(hdfProjectId.Value)) == "Internal")
            {
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Internal Project";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Internal Project";

                lblTitleProject.Text = " > Internal Project: ";

                tkrpbLeftMenuCurrentProject.Items[0].Items[3].Visible = false; //mSections
                tkrpbLeftMenuCurrentProject.Items[0].Items[4].Visible = false; //mTools
                tkrpbLeftMenuCurrentProject.Items[0].Items[5].Visible = false; //mSeparator
            }

            if (projectGateway.GetProjectType(int.Parse(hdfProjectId.Value)) == "Ballpark")
            {
                tkrpbLeftMenuCurrentProject.Items[0].Text = "Current Ballpark";
                tkrpbLeftMenuCurrentProject.Items[0].Items[0].Text = "Ballpark";

                lblTitleProject.Text = " > Ballpark: ";

                tkrpbLeftMenuCurrentProject.Items[0].Items[3].Visible = false; //mSections
                tkrpbLeftMenuCurrentProject.Items[0].Items[4].Visible = false; //mTools
                tkrpbLeftMenuCurrentProject.Items[0].Items[5].Visible = false; //mSeparator
            }

            // Security check
            if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_ADMIN"]))
            {
                tkrpbLeftMenuReports.Visible = false;
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // INITIAL EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"]))
                {
                    if (!(Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_EDIT"])))
                    {
                        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) || ((string)Request.QueryString["costing_sheet_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_costing_sheets_edit.aspx");
                }

                // Tag Page
                hdfCostingSheetId.Value = Request.QueryString["costing_sheet_id"].ToString();
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfProjectId.Value = Request.QueryString["project_id"];
                hdfDataChanged.Value = Request.QueryString["data_changed"];
                hdfDataChangedMessage.Value = "Changes made to this project will not be saved.";

                ViewState["state"] = Request.QueryString["state"];
                ViewState["active_tab"] = Request.QueryString["active_tab"];
                ViewState["origin"] = Request.QueryString["origin"];
                ViewState["update"] = Request.QueryString["update"];

                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];

                Session.Remove("labourHoursInformationDummy");
                Session.Remove("unitsInformationDummy");
                Session.Remove("subcontractorsInformationDummy");
                Session.Remove("materialsInformationDummy");
                Session.Remove("otherCostsInformationDummy");
                Session.Remove("revenueInformationDummy");

                Session.Remove("hotelsInformationDummy");
                Session.Remove("bondingsInformationDummy");
                Session.Remove("insurancesInformationDummy");
                Session.Remove("otherCategoryInformationDummy");

                // If coming from project_costing_sheets_navigator.aspx or project_costing_sheets_add.aspx
                int companyId = Int32.Parse(hdfCompanyId.Value);
                if (Request.QueryString["source_page"] == "project_costing_sheets_navigator.aspx" || Request.QueryString["source_page"] == "project_costing_sheets_add.aspx")
                {
                    // Store Navigator State and Update control
                    StoreNavigatorState();
                    ViewState["update"] = "no";

                    // Get Costing sheet ID
                    int costingSheetId = Int32.Parse(hdfCostingSheetId.Value.Trim());

                    // Get dataset
                    projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                    projectCostingSheetInformationTDS = new ProjectCostingSheetInformationTDS();
                    labourHoursInformation = new ProjectCostingSheetInformationTDS.LabourHoursInformationDataTable();
                    unitsInformation = new ProjectCostingSheetInformationTDS.UnitsInformationDataTable();
                    subcontractorsInformation = new ProjectCostingSheetInformationTDS.SubcontractorsInformationDataTable();
                    materialsInformation = new ProjectCostingSheetInformationTDS.MaterialsInformationDataTable();
                    otherCostsInformation = new ProjectCostingSheetInformationTDS.OtherCostsInformationDataTable();
                    revenueInformation = new ProjectCostingSheetInformationTDS.RevenueInformationDataTable();

                    hotelsInformation = new ProjectCostingSheetInformationTDS.HotelsInformationDataTable();
                    bondingsInformation = new ProjectCostingSheetInformationTDS.BondingsInformationDataTable();
                    insurancesInformation = new ProjectCostingSheetInformationTDS.InsurancesInformationDataTable();
                    otherCategoryInformation = new ProjectCostingSheetInformationTDS.OtherCategoryInformationDataTable();

                    // Get General Data
                    ProjectCostingSheetInformationBasicInformation projectCostingSheetInformationBasicInformation = new ProjectCostingSheetInformationBasicInformation(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationBasicInformation.LoadByCostingSheetId(costingSheetId, companyId);

                    ProjectCostingSheetInformationLabourHoursInformationGateway projectCostingSheetInformationLabourHoursInformationGateway = new ProjectCostingSheetInformationLabourHoursInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationLabourHoursInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    ProjectCostingSheetInformationUnitsInformationGateway projectCostingSheetInformationUnitsInformationGateway = new ProjectCostingSheetInformationUnitsInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationUnitsInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    ProjectCostingSheetInformationSubcontractorsInformationGateway projectCostingSheetInformationSubcontractorsInformationGateway = new ProjectCostingSheetInformationSubcontractorsInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationSubcontractorsInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    ProjectCostingSheetInformationMaterialsInformationGateway projectCostingSheetInformationMaterialsInformationGateway = new ProjectCostingSheetInformationMaterialsInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationMaterialsInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    ProjectCostingSheetInformationOtherCostsInformationGateway projectCostingSheetInformationOtherCostsInformationGateway = new ProjectCostingSheetInformationOtherCostsInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationOtherCostsInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    projectCostingSheetInformationRevenueInformationGateway projectCostingSheetInformationRevenueInformationGateway = new projectCostingSheetInformationRevenueInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationRevenueInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    ProjectCostingSheetInformationHotelsInformationGateway projectCostingSheetInformationHotelsInformationGateway = new ProjectCostingSheetInformationHotelsInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationHotelsInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    ProjectCostingSheetInformationBondingsInformationGateway projectCostingSheetInformationBondingsInformationGateway = new ProjectCostingSheetInformationBondingsInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationBondingsInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    ProjectCostingSheetInformationInsurancesInformationGateway projectCostingSheetInformationInsurancesInformationGateway = new ProjectCostingSheetInformationInsurancesInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationInsurancesInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    ProjectCostingSheetInformationOtherCategoryInformationGateway projectCostingSheetInformationOtherCategoryInformationGateway = new ProjectCostingSheetInformationOtherCategoryInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationOtherCategoryInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

                    Session["lfsProjectTDS"] = projectTDS;
                    Session["projectCostingSheetInformationTDS"] = projectCostingSheetInformationTDS;
                    Session["labourHoursInformation"] = projectCostingSheetInformationTDS.LabourHoursInformation;
                    Session["unitsInformation"] = projectCostingSheetInformationTDS.UnitsInformation;
                    Session["subcontractorsInformation"] = projectCostingSheetInformationTDS.SubcontractorsInformation;
                    Session["materialsInformation"] = projectCostingSheetInformationTDS.MaterialsInformation;
                    Session["otherCostsInformation"] = projectCostingSheetInformationTDS.OtherCostsInformation;
                    Session["revenueInformation"] = projectCostingSheetInformationTDS.RevenueInformation;

                    Session["hotelsInformation"] = projectCostingSheetInformationTDS.HotelsInformation;
                    Session["bondingsInformation"] = projectCostingSheetInformationTDS.BondingsInformation;
                    Session["insurancesInformation"] = projectCostingSheetInformationTDS.InsurancesInformation;
                    Session["otherCategoryInformation"] = projectCostingSheetInformationTDS.OtherCategoryInformation;

                    labourHoursInformation = projectCostingSheetInformationTDS.LabourHoursInformation;
                    unitsInformation = projectCostingSheetInformationTDS.UnitsInformation;
                    subcontractorsInformation = projectCostingSheetInformationTDS.SubcontractorsInformation;
                    materialsInformation = projectCostingSheetInformationTDS.MaterialsInformation;
                    otherCostsInformation = projectCostingSheetInformationTDS.OtherCostsInformation;
                    revenueInformation = projectCostingSheetInformationTDS.RevenueInformation;

                    hotelsInformation = projectCostingSheetInformationTDS.HotelsInformation;
                    bondingsInformation = projectCostingSheetInformationTDS.BondingsInformation;
                    insurancesInformation = projectCostingSheetInformationTDS.InsurancesInformation;
                    otherCategoryInformation = projectCostingSheetInformationTDS.OtherCategoryInformation;
                }

                // ... project_costing_sheets_add.aspx
                if (Request.QueryString["source_page"] == "project_costing_sheets_add.aspx")
                {
                    ViewState["update"] = "yes";
                }

                // ... left menu, project_costing_sheets_edit.aspx, project_costing_sheets_delete.aspx or project_costing_sheets_state.aspx
                if ((Request.QueryString["source_page"] == "lm") || (Request.QueryString["source_page"] == "project_costing_sheets_summary.aspx") || (Request.QueryString["source_page"] == "project_costing_sheets_delete.aspx") || (Request.QueryString["source_page"] == "project_costing_sheets_state.aspx"))
                {
                    // Store Navigator State and Update control
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];
                }

                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectCostingSheetInformationTDS = (ProjectCostingSheetInformationTDS)Session["projectCostingSheetInformationTDS"];

                labourHoursInformation = (ProjectCostingSheetInformationTDS.LabourHoursInformationDataTable)Session["labourHoursInformation"];
                unitsInformation = (ProjectCostingSheetInformationTDS.UnitsInformationDataTable)Session["unitsInformation"];
                subcontractorsInformation = (ProjectCostingSheetInformationTDS.SubcontractorsInformationDataTable)Session["subcontractorsInformation"];
                materialsInformation = (ProjectCostingSheetInformationTDS.MaterialsInformationDataTable)Session["materialsInformation"];
                otherCostsInformation = (ProjectCostingSheetInformationTDS.OtherCostsInformationDataTable)Session["otherCostsInformation"];
                revenueInformation = (ProjectCostingSheetInformationTDS.RevenueInformationDataTable)Session["revenueInformation"];

                hotelsInformation = (ProjectCostingSheetInformationTDS.HotelsInformationDataTable)Session["hotelsInformation"];
                bondingsInformation = (ProjectCostingSheetInformationTDS.BondingsInformationDataTable)Session["bondingsInformation"];
                insurancesInformation = (ProjectCostingSheetInformationTDS.InsurancesInformationDataTable)Session["insurancesInformation"];
                otherCategoryInformation = (ProjectCostingSheetInformationTDS.OtherCategoryInformationDataTable)Session["otherCategoryInformation"];

                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"]))
                {
                    // Costing Sheet state check
                    ProjectCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGatewayForValidate = new ProjectCostingSheetInformationBasicInformationGateway(projectCostingSheetInformationTDS);
                    string state = projectCostingSheetInformationBasicInformationGatewayForValidate.GetState(Int32.Parse(hdfCostingSheetId.Value));
                    if (state == "Approved")
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "This costing sheet is approved, you can not edit it.");
                    }
                }

                ProjectGateway projectGateway = new ProjectGateway(projectTDS);
                hdfClientId.Value = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString())).ToString();

                // ... for project
                int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString());
                string name = projectGateway.GetName(currentProjectId);
                if (name.Length > 23) name = name.Substring(0, 20) + "...";
                lblTitleProjectName.Text = name + " (" + projectGateway.GetProjectNumber(currentProjectId) + ")";

                // ... for client
                int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));

                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(currentClientId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId);

                LoadBasicData();
            }
            else
            {
                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectCostingSheetInformationTDS = (ProjectCostingSheetInformationTDS)Session["projectCostingSheetInformationTDS"];

                labourHoursInformation = (ProjectCostingSheetInformationTDS.LabourHoursInformationDataTable)Session["labourHoursInformation"];
                unitsInformation = (ProjectCostingSheetInformationTDS.UnitsInformationDataTable)Session["unitsInformation"];
                subcontractorsInformation = (ProjectCostingSheetInformationTDS.SubcontractorsInformationDataTable)Session["subcontractorsInformation"];
                materialsInformation = (ProjectCostingSheetInformationTDS.MaterialsInformationDataTable)Session["materialsInformation"];
                otherCostsInformation = (ProjectCostingSheetInformationTDS.OtherCostsInformationDataTable)Session["otherCostsInformation"];
                revenueInformation = (ProjectCostingSheetInformationTDS.RevenueInformationDataTable)Session["revenueInformation"];

                hotelsInformation = (ProjectCostingSheetInformationTDS.HotelsInformationDataTable)Session["hotelsInformation"];
                bondingsInformation = (ProjectCostingSheetInformationTDS.BondingsInformationDataTable)Session["bondingsInformation"];
                insurancesInformation = (ProjectCostingSheetInformationTDS.InsurancesInformationDataTable)Session["insurancesInformation"];
                otherCategoryInformation = (ProjectCostingSheetInformationTDS.OtherCategoryInformationDataTable)Session["otherCategoryInformation"];
            }
        }