protected void grdTeamMembers_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            // Edit items
            if ((e.Row.RowType == DataControlRowType.DataRow) && ((e.Row.RowState == DataControlRowState.Edit) || (e.Row.RowState == (DataControlRowState.Edit | DataControlRowState.Alternate))))
            {
                int costingSheetId = Int32.Parse(((Label)e.Row.FindControl("lblCostingSheetIDEdit")).Text.Trim());
                int employeeId = Int32.Parse(((Label)e.Row.FindControl("lblEmployeeIDEdit")).Text.Trim());
                int refId = Int32.Parse(((Label)e.Row.FindControl("lblRefIDEdit")).Text.Trim());
                string work_ = ((Label)e.Row.FindControl("lblWork_Edit")).Text.Trim();

                ProjectCombinedCostingSheetInformationLabourHoursInformationGateway projectCostingSheetInformationLabourHoursInformationGateway = new ProjectCombinedCostingSheetInformationLabourHoursInformationGateway(projectCostingSheetInformationTDS);
                string unitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetLHUnitOfMeasurement(costingSheetId, work_, employeeId, refId);
                ((DropDownList)e.Row.FindControl("ddlUnitOfMeasurementLHEdit")).SelectedValue = unitOfMeasurement;

                string unitOfMeasurementMeals = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsUnitOfMeasurement(costingSheetId, work_, employeeId, refId);
                ((DropDownList)e.Row.FindControl("ddlUnitsOfMeasurementLHMealsEdit")).SelectedValue = unitOfMeasurementMeals;

                string unitOfMeasurementMotel = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelUnitOfMeasurement(costingSheetId, work_, employeeId, refId);
                ((DropDownList)e.Row.FindControl("ddlUnitsOfMeasurementLHMotelEdit")).SelectedValue = unitOfMeasurementMotel;

                bool inDatabase = projectCostingSheetInformationLabourHoursInformationGateway.GetInDatabase(costingSheetId, work_, employeeId, refId);

                if (inDatabase)
                {
                    ((RadDatePicker)e.Row.FindControl("tkrdpEndDateEdit")).Calendar.Enabled = false;
                    ((RadDatePicker)e.Row.FindControl("tkrdpEndDateEdit")).DateInput.ReadOnly = true;

                    ((RadDatePicker)e.Row.FindControl("tkrdpStartDateEdit")).Calendar.Enabled = false;
                    ((RadDatePicker)e.Row.FindControl("tkrdpStartDateEdit")).DateInput.ReadOnly = true;
                }

                ((RadDatePicker)e.Row.FindControl("hdfFrom")).SelectedDate = Convert.ToDateTime(hdfFromDate.Value);
                ((RadDatePicker)e.Row.FindControl("hdfTo")).SelectedDate = Convert.ToDateTime(hdfToDate.Value);
            }

            // Footer Item
            if (e.Row.RowType == DataControlRowType.Footer)
            {
                ((RadDatePicker)e.Row.FindControl("hdfFrom")).SelectedDate = Convert.ToDateTime(hdfFromDate.Value);
                ((RadDatePicker)e.Row.FindControl("hdfTo")).SelectedDate = Convert.ToDateTime(hdfToDate.Value);
            }
        }
        /// <summary>
        /// Save all LH Costing Sheets
        /// </summary>
        /// <param name="companyId">companyId</param>
        /// <param name="costingSheetId">costingSheetId</param>
        public void Save(int companyId, int costingSheetId)
        {
            ProjectCostingSheetInformationTDS labourHourInformationChanges = (ProjectCostingSheetInformationTDS)Data.GetChanges();

            if (labourHourInformationChanges.CombinedLabourHoursInformation.Rows.Count > 0)
            {
                ProjectCombinedCostingSheetInformationLabourHoursInformationGateway projectCostingSheetInformationLabourHoursInformationGateway = new ProjectCombinedCostingSheetInformationLabourHoursInformationGateway(labourHourInformationChanges);

                foreach (ProjectCostingSheetInformationTDS.CombinedLabourHoursInformationRow row in (ProjectCostingSheetInformationTDS.CombinedLabourHoursInformationDataTable)labourHourInformationChanges.CombinedLabourHoursInformation)
                {
                    // Insert new costing sheet Labour Hours
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        int? mealsQuantity = null; if (!row.IsMealsQuantityNull()) mealsQuantity = row.MealsQuantity;
                        int? motelQuantity = null; if (!row.IsMotelQuantityNull()) motelQuantity = row.MotelQuantity;
                        decimal? measlCostCad = null; if (!row.IsMealsCostCadNull()) measlCostCad = row.MealsCostCad;
                        decimal? motelCostCad = null; if (!row.IsMotelCostCadNull()) motelCostCad = row.MotelCostCad;
                        decimal? measlCostUsd = null; if (!row.IsMealsCostUsdNull()) measlCostUsd = row.MealsCostUsd;
                        decimal? motelCostUsd = null; if (!row.IsMotelCostUsdNull()) motelCostUsd = row.MotelCostUsd;

                        ProjectCombinedCostingSheetLabourHours labourHours = new ProjectCombinedCostingSheetLabourHours(null);
                        labourHours.InsertDirect(costingSheetId, row.Work_, row.EmployeeID, row.RefID, row.LHQuantity, row.LHUnitOfMeasurement, row.MealsUnitOfMeasurement, mealsQuantity, row.MotelUnitOfMeasurement, motelQuantity, row.LHCostCad, measlCostCad, motelCostCad, row.TotalCostCad, row.LHCostUsd, measlCostUsd, motelCostUsd, row.TotalCostUsd, false, companyId, row.StartDate, row.EndDate, row.Function_, row.ProjectID);
                    }

                    // Update costing sheet Labour Hours
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        string work_ = row.Work_;
                        int employeeId = row.EmployeeID;
                        int refId = row.RefID;
                        bool deleted = false;

                        //original values
                        string originalLHUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetLHUnitOfMeasurementOriginal(costingSheetId, work_, employeeId, refId);
                        double originalLHQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetLHQuantityOriginal(costingSheetId, work_, employeeId, refId);
                        string originalMealsUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsUnitOfMeasurementOriginal(costingSheetId, work_, employeeId, refId);
                        int? originalMealsQuantity = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsQuantityOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMealsQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsQuantityOriginal(costingSheetId, work_, employeeId, refId).Value;
                        string originalMotelUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelUnitOfMeasurementOriginal(costingSheetId, work_, employeeId, refId);
                        int? originalMotelQuantity = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelQuantityOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMotelQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelQuantityOriginal(costingSheetId, work_, employeeId, refId).Value;
                        decimal originalLHCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetLHCostCadOriginal(costingSheetId, work_, employeeId, refId);
                        decimal? originalMealsCostCad = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostCadOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMealsCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostCadOriginal(costingSheetId, work_, employeeId, refId);
                        decimal? originalMotelCostCad = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostCadOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMotelCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostCadOriginal(costingSheetId, work_, employeeId, refId);
                        decimal originalTotalCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetTotalCostCadOriginal(costingSheetId, work_, employeeId, refId);
                        decimal originalLHCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetLHCostUsdOriginal(costingSheetId, work_, employeeId, refId);
                        decimal? originalMealsCostUsd = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostUsdOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMealsCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostUsdOriginal(costingSheetId, work_, employeeId, refId);
                        decimal? originalMotelCostUsd = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostUsdOriginal(costingSheetId, work_, employeeId, refId).HasValue) originalMotelCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostUsdOriginal(costingSheetId, work_, employeeId, refId);
                        decimal originalTotalCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetTotalCostUsdOriginal(costingSheetId, work_, employeeId, refId);
                        DateTime originalStartDate = projectCostingSheetInformationLabourHoursInformationGateway.GetStartDateOriginal(costingSheetId, work_, employeeId, refId);
                        DateTime originalEndDate = projectCostingSheetInformationLabourHoursInformationGateway.GetEndDateOriginal(costingSheetId, work_, employeeId, refId);
                        string originalFunction_ = projectCostingSheetInformationLabourHoursInformationGateway.GetFunction_Original(costingSheetId, work_, employeeId, refId);

                        //original values
                        string newLHUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetLHUnitOfMeasurement(costingSheetId, work_, employeeId, refId);
                        double newLHQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetLHQuantity(costingSheetId, work_, employeeId, refId);
                        string newMealsUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsUnitOfMeasurement(costingSheetId, work_, employeeId, refId);
                        int? newMealsQuantity = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsQuantity(costingSheetId, work_, employeeId, refId).HasValue) newMealsQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsQuantity(costingSheetId, work_, employeeId, refId).Value;
                        string newMotelUnitOfMeasurement = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelUnitOfMeasurement(costingSheetId, work_, employeeId, refId);
                        int? newMotelQuantity = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelQuantity(costingSheetId, work_, employeeId, refId).HasValue) newMotelQuantity = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelQuantity(costingSheetId, work_, employeeId, refId).Value;
                        decimal newLHCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetLHCostCad(costingSheetId, work_, employeeId, refId);
                        decimal? newMealsCostCad = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostCad(costingSheetId, work_, employeeId, refId).HasValue) newMealsCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostCad(costingSheetId, work_, employeeId, refId);
                        decimal? newMotelCostCad = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostCad(costingSheetId, work_, employeeId, refId).HasValue) newMotelCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostCad(costingSheetId, work_, employeeId, refId);
                        decimal newTotalCostCad = projectCostingSheetInformationLabourHoursInformationGateway.GetTotalCostCad(costingSheetId, work_, employeeId, refId);
                        decimal newLHCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetLHCostUsd(costingSheetId, work_, employeeId, refId);
                        decimal? newMealsCostUsd = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostUsd(costingSheetId, work_, employeeId, refId).HasValue) newMealsCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetMealsCostUsd(costingSheetId, work_, employeeId, refId);
                        decimal? newMotelCostUsd = null; if (projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostUsd(costingSheetId, work_, employeeId, refId).HasValue) newMotelCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetMotelCostUsd(costingSheetId, work_, employeeId, refId);
                        decimal newTotalCostUsd = projectCostingSheetInformationLabourHoursInformationGateway.GetTotalCostUsd(costingSheetId, work_, employeeId, refId);
                        DateTime newStartDate = projectCostingSheetInformationLabourHoursInformationGateway.GetStartDate(costingSheetId, work_, employeeId, refId);
                        DateTime newEndDate = projectCostingSheetInformationLabourHoursInformationGateway.GetEndDate(costingSheetId, work_, employeeId, refId);
                        string newFunction_ = projectCostingSheetInformationLabourHoursInformationGateway.GetFunction_(costingSheetId, work_, employeeId, refId);

                        ProjectCombinedCostingSheetLabourHours labourHours = new ProjectCombinedCostingSheetLabourHours(null);
                        labourHours.UpdateDirect(costingSheetId, employeeId, refId, work_, originalLHQuantity, originalLHUnitOfMeasurement, originalMealsUnitOfMeasurement, originalMealsQuantity, originalMealsUnitOfMeasurement, originalMotelQuantity, originalLHCostCad, originalMealsCostCad, originalMotelCostCad, originalTotalCostCad, originalLHCostUsd, originalMealsCostUsd, originalMotelCostUsd, originalTotalCostUsd, deleted, companyId, originalStartDate, originalEndDate, originalFunction_, work_, newLHQuantity, newLHUnitOfMeasurement, newMealsUnitOfMeasurement, newMealsQuantity, newMotelUnitOfMeasurement, newMotelQuantity, newLHCostCad, newMealsCostCad, newMotelCostCad, newTotalCostCad, newLHCostUsd, newMealsCostUsd, newMotelCostUsd, newTotalCostUsd, deleted, companyId, newStartDate, newEndDate, newFunction_, row.ProjectID, row.ProjectID);
                    }

                    // Delete costing sheet Labour Hours
                    if ((row.Deleted) && (row.InDatabase))
                    {
                        ProjectCombinedCostingSheetLabourHours labourHours = new ProjectCombinedCostingSheetLabourHours(null);
                        labourHours.DeleteDirect(row.CostingSheetID, row.Work_, row.EmployeeID, row.RefID, row.COMPANY_ID);
                    }
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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_combined_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");

                // If coming from project_combined_costing_sheets_navigator.aspx or project_combined_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_combined_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.CombinedLabourHoursInformationDataTable();
                    unitsInformation = new ProjectCostingSheetInformationTDS.CombinedUnitsInformationDataTable();
                    subcontractorsInformation = new ProjectCostingSheetInformationTDS.CombinedSubcontractorsInformationDataTable();
                    materialsInformation = new ProjectCostingSheetInformationTDS.CombinedMaterialsInformationDataTable();
                    otherCostsInformation = new ProjectCostingSheetInformationTDS.CombinedOtherCostsInformationDataTable();
                    revenueInformation = new ProjectCostingSheetInformationTDS.CombinedRevenueInformationDataTable();

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

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

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

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

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

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

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

                    Session["lfsProjectTDS"] = projectTDS;
                    Session["projectCostingSheetInformationTDS"] = projectCostingSheetInformationTDS;
                    Session["labourHoursInformation"] = projectCostingSheetInformationTDS.CombinedLabourHoursInformation;
                    Session["unitsInformation"] = projectCostingSheetInformationTDS.CombinedUnitsInformation;
                    Session["subcontractorsInformation"] = projectCostingSheetInformationTDS.CombinedSubcontractorsInformation;
                    Session["materialsInformation"] = projectCostingSheetInformationTDS.CombinedMaterialsInformation;
                    Session["otherCostsInformation"] = projectCostingSheetInformationTDS.CombinedOtherCostsInformation;
                    Session["revenueInformation"] = projectCostingSheetInformationTDS.CombinedRevenueInformation;

                    labourHoursInformation = projectCostingSheetInformationTDS.CombinedLabourHoursInformation;
                    unitsInformation = projectCostingSheetInformationTDS.CombinedUnitsInformation;
                    subcontractorsInformation = projectCostingSheetInformationTDS.CombinedSubcontractorsInformation;
                    materialsInformation = projectCostingSheetInformationTDS.CombinedMaterialsInformation;
                    otherCostsInformation = projectCostingSheetInformationTDS.CombinedOtherCostsInformation;
                    revenueInformation = projectCostingSheetInformationTDS.CombinedRevenueInformation;
                }

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

                // ... left menu, project_combined_costing_sheets_edit.aspx, project_combined_costing_sheets_delete.aspx or project_combined_costing_sheets_state.aspx
                if ((Request.QueryString["source_page"] == "lm") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_summary.aspx") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_delete.aspx") || (Request.QueryString["source_page"] == "project_combined_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.CombinedLabourHoursInformationDataTable)Session["labourHoursInformation"];
                unitsInformation = (ProjectCostingSheetInformationTDS.CombinedUnitsInformationDataTable)Session["unitsInformation"];
                subcontractorsInformation = (ProjectCostingSheetInformationTDS.CombinedSubcontractorsInformationDataTable)Session["subcontractorsInformation"];
                materialsInformation = (ProjectCostingSheetInformationTDS.CombinedMaterialsInformationDataTable)Session["materialsInformation"];
                otherCostsInformation = (ProjectCostingSheetInformationTDS.CombinedOtherCostsInformationDataTable)Session["otherCostsInformation"];
                revenueInformation = (ProjectCostingSheetInformationTDS.CombinedRevenueInformationDataTable)Session["revenueInformation"];

                if (!Convert.ToBoolean(Session["sgLFS_PROJECTS_COSTINGSHEETS_ADMIN"]))
                {
                    // Costing Sheet state check
                    ProjectCombinedCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGatewayForValidate = new ProjectCombinedCostingSheetInformationBasicInformationGateway(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.CombinedLabourHoursInformationDataTable)Session["labourHoursInformation"];
                unitsInformation = (ProjectCostingSheetInformationTDS.CombinedUnitsInformationDataTable)Session["unitsInformation"];
                subcontractorsInformation = (ProjectCostingSheetInformationTDS.CombinedSubcontractorsInformationDataTable)Session["subcontractorsInformation"];
                materialsInformation = (ProjectCostingSheetInformationTDS.CombinedMaterialsInformationDataTable)Session["materialsInformation"];
                otherCostsInformation = (ProjectCostingSheetInformationTDS.CombinedOtherCostsInformationDataTable)Session["otherCostsInformation"];
                revenueInformation = (ProjectCostingSheetInformationTDS.CombinedRevenueInformationDataTable)Session["revenueInformation"];
            }
        }
        /// <summary>
        /// UpdateForReport
        /// </summary>
        private void UpdateForReport()
        {
            ProjectCombinedCostingSheetInformationLabourHoursInformationGateway projectCostingSheetInformationLabourHoursInformationGateway = new ProjectCombinedCostingSheetInformationLabourHoursInformationGateway(Data);
            projectCostingSheetInformationLabourHoursInformationGateway.ClearBeforeFill = false;

            ProjectCombinedCostingSheetInformationUnitsInformationGateway projectCostingSheetInformationUnitsInformationGateway = new ProjectCombinedCostingSheetInformationUnitsInformationGateway(Data);
            projectCostingSheetInformationUnitsInformationGateway.ClearBeforeFill = false;

            ProjectCombinedCostingSheetInformationMaterialsInformationGateway projectCostingSheetInformationMaterialsInformationGateway = new ProjectCombinedCostingSheetInformationMaterialsInformationGateway(Data);
            projectCostingSheetInformationMaterialsInformationGateway.ClearBeforeFill = false;

            ProjectCombinedCostingSheetInformationSubcontractorsInformationGateway projectCostingSheetInformationSubcontractorsInformationGateway = new ProjectCombinedCostingSheetInformationSubcontractorsInformationGateway(Data);
            projectCostingSheetInformationSubcontractorsInformationGateway.ClearBeforeFill = false;

            ProjectCombinedCostingSheetInformationOtherCostsInformationGateway projectCostingSheetInformationOtherCostsInformationGateway = new ProjectCombinedCostingSheetInformationOtherCostsInformationGateway(Data);
            projectCostingSheetInformationOtherCostsInformationGateway.ClearBeforeFill = false;

            projectCombinedCostingSheetInformationRevenueInformationGateway projectCostingSheetInformationRevenueInformationGateway = new projectCombinedCostingSheetInformationRevenueInformationGateway(Data);
            projectCostingSheetInformationRevenueInformationGateway.ClearBeforeFill = false;

            foreach (ProjectCostingSheetInformationTDS.CombinedBasicInformationRow row in (ProjectCostingSheetInformationTDS.CombinedBasicInformationDataTable)Table)
            {
                if (row.GrandRevenue > 0)
                {
                    row.GrandGrossMargin = (row.GrandProfit / row.GrandRevenue) * 100;
                }
                else
                {
                    row.GrandGrossMargin = 0;
                }

                projectCostingSheetInformationLabourHoursInformationGateway.LoadByCostingSheetId(row.CostingSheetID, row.COMPANY_ID);
                projectCostingSheetInformationUnitsInformationGateway.LoadByCostingSheetId(row.CostingSheetID, row.COMPANY_ID);
                projectCostingSheetInformationMaterialsInformationGateway.LoadByCostingSheetId(row.CostingSheetID, row.COMPANY_ID);
                projectCostingSheetInformationSubcontractorsInformationGateway.LoadByCostingSheetId(row.CostingSheetID, row.COMPANY_ID);
                projectCostingSheetInformationOtherCostsInformationGateway.LoadByCostingSheetId(row.CostingSheetID, row.COMPANY_ID);
                projectCostingSheetInformationRevenueInformationGateway.LoadByCostingSheetId(row.CostingSheetID, row.COMPANY_ID);
            }
        }