private void UpdateDatabase()
        {
            // Get ids
            int costingSheetId = Int32.Parse(hdfCostingSheetId.Value);
            int companyId = Int32.Parse(hdfCompanyId.Value);

            // Delete
            DB.Open();
            DB.BeginTransaction();
            try
            {
                ProjectCombinedCostingSheetInformationBasicInformation projectCostingSheetInformationBasicInformation = new ProjectCombinedCostingSheetInformationBasicInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationBasicInformation.DeleteDirect(costingSheetId, companyId);

                DB.CommitTransaction();
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void Generate()
        {
            mReport1 master = (mReport1)this.Master;
            int companyId = Convert.ToInt32(Session["companyID"]);
            string type = Request.QueryString["type"].ToString();
            int costingSheetId = 0;
            int projectId = 0;
            int clientId = 0;
            string combinedProjects = "";

            ProjectCombinedCostingSheetInformationBasicInformation projectCostingSheetInformationBasicInformation = new ProjectCombinedCostingSheetInformationBasicInformation();

            if (ddlCostingSheets.SelectedValue != "-1")
            {
                // Get Data
                costingSheetId = Convert.ToInt32(ddlCostingSheets.SelectedValue);
                projectCostingSheetInformationBasicInformation.LoadByCostingSheetIdForPreviewReport(costingSheetId, companyId);

                ProjectCombinedCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGateway = new ProjectCombinedCostingSheetInformationBasicInformationGateway(projectCostingSheetInformationBasicInformation.Data);

                // ... set properties to master page
                master.Data = projectCostingSheetInformationBasicInformation.Data;
                master.Table = projectCostingSheetInformationBasicInformation.TableName;
                master.Report = new ProjectCombinedCostingSheetsPreview(); //TODO

                // Get report
                if (projectCostingSheetInformationBasicInformation.Table.Rows.Count > 0)
                {
                    LoginGateway loginGateway = new LoginGateway();
                    loginGateway.LoadByLoginId(Convert.ToInt32(Session["loginID"]), companyId);
                    string user = loginGateway.GetLastName(Convert.ToInt32(Session["loginID"]), companyId) + " " + loginGateway.GetFirstName(Convert.ToInt32(Session["loginID"]), companyId);
                    master.SetParameter("User", user.Trim());

                    // For process code
                    master.SetParameter("CostingSheet", projectCostingSheetInformationBasicInformationGateway.GetName(costingSheetId));

                    clientId = projectCostingSheetInformationBasicInformationGateway.GetClientID(costingSheetId);
                    combinedProjects = projectCostingSheetInformationBasicInformationGateway.GetCombinedProjects(costingSheetId);

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

                    CompaniesGateway companiesGateway = new CompaniesGateway();
                    companiesGateway.LoadByCompaniesId(clientId, companyId);

                    master.SetParameter("Client", companiesGateway.GetName(clientId));

                    master.SetParameter("Project", combinedProjects);

                    if (type == "resume")
                    {
                        ((Section)master.Report.ReportDefinition.Sections["detailsLabourHours"]).SectionFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["detailsLabourHours2"]).SectionFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["detailsUnits"]).SectionFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["detailsUnits2"]).SectionFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["detailsMaterials"]).SectionFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["detailsMaterials2"]).SectionFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["detailsOtherCosts"]).SectionFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["detailsOtherCosts2"]).SectionFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["detailsSubcontractors"]).SectionFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["detailsSubcontractors2"]).SectionFormat.EnableSuppress = true;
                    }
                    else
                    {
                        ((Section)master.Report.ReportDefinition.Sections["detailsLabourHours"]).SectionFormat.EnableSuppress = false;
                        ((Section)master.Report.ReportDefinition.Sections["detailsLabourHours2"]).SectionFormat.EnableSuppress = false;
                        ((Section)master.Report.ReportDefinition.Sections["detailsUnits"]).SectionFormat.EnableSuppress = false;
                        ((Section)master.Report.ReportDefinition.Sections["detailsUnits2"]).SectionFormat.EnableSuppress = false;
                        ((Section)master.Report.ReportDefinition.Sections["detailsMaterials"]).SectionFormat.EnableSuppress = false;
                        ((Section)master.Report.ReportDefinition.Sections["detailsMaterials2"]).SectionFormat.EnableSuppress = false;
                        ((Section)master.Report.ReportDefinition.Sections["detailsOtherCosts"]).SectionFormat.EnableSuppress = false;
                        ((Section)master.Report.ReportDefinition.Sections["detailsOtherCosts2"]).SectionFormat.EnableSuppress = false;
                        ((Section)master.Report.ReportDefinition.Sections["detailsSubcontractors"]).SectionFormat.EnableSuppress = false;
                        ((Section)master.Report.ReportDefinition.Sections["detailsSubcontractors2"]).SectionFormat.EnableSuppress = false;
                    }

                    if (1 == 1)//Canada
                    {
                        // General
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["Text32"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["Text34"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["Text36"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["Text38"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["Text2"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["headerTotalSubcontractorsUsd"].ObjectFormat.EnableSuppress = true;

                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["TotalLabourHoursUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["TotalUnitsUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["TotalMaterialsUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["TotalOtherCostsUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["GrandTotalUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["TotalSubcontractorsUsd1"].ObjectFormat.EnableSuppress = true;

                        ((Section)master.Report.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["Text5"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["GrandTotalUsd2"].ObjectFormat.EnableSuppress = true;

                        // Labour Hours
                        ReportDocument rpLabourHoursDetails = master.Report.OpenSubreport("LabourHoursDetails");
                        ReportDocument rpLabourHoursResume = master.Report.OpenSubreport("LabourHoursResume");

                        ((Section)rpLabourHoursDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text5"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text2"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["LHCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["TotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursDetails.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostUsd2"].ObjectFormat.EnableSuppress = true;

                        ((Section)rpLabourHoursResume.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text2"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursResume.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofTotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursResume.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostUsd2"].ObjectFormat.EnableSuppress = true;

                        // Units
                        ReportDocument rpUnitsDetails = master.Report.OpenSubreport("UnitsDetails");
                        ReportDocument rpUnitsResume = master.Report.OpenSubreport("UnitsResume");

                        ((Section)rpUnitsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text3"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text2"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["CostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["TotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsDetails.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostUsd2"].ObjectFormat.EnableSuppress = true;

                        ((Section)rpUnitsResume.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text6"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsResume.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofTotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsResume.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostUsd2"].ObjectFormat.EnableSuppress = true;

                        // Materials
                        ReportDocument rpMaterialsDetails = master.Report.OpenSubreport("MaterialsDetails");
                        ReportDocument rpMaterialsResune = master.Report.OpenSubreport("MaterialsResume");

                        ((Section)rpMaterialsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text3"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text2"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["CostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["TotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsDetails.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostUsd2"].ObjectFormat.EnableSuppress = true;

                        ((Section)rpMaterialsResune.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text6"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsResune.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofTotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsResune.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostUsd2"].ObjectFormat.EnableSuppress = true;

                        // Subcontractors
                        ReportDocument rpSubcontractorsDetails = master.Report.OpenSubreport("SubcontractorsDetails");
                        ReportDocument rpSubcontractorsResune = master.Report.OpenSubreport("SubcontractorsResume");

                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text3"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text2"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["CostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["TotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofSubTotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostUsd1"].ObjectFormat.EnableSuppress = true;

                        ((Section)rpSubcontractorsResune.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["lblTotalCostUsd"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsResune.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofTotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsResune.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostUsd2"].ObjectFormat.EnableSuppress = true;

                        // Other Costs
                        ReportDocument rpOtherCostsDetails = master.Report.OpenSubreport("OtherCostsDetails");
                        ReportDocument rpOtherCostsResume = master.Report.OpenSubreport("OtherCostsResume");

                        ((Section)rpOtherCostsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text3"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text2"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["CostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["TotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsDetails.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostUsd2"].ObjectFormat.EnableSuppress = true;

                        ((Section)rpOtherCostsResume.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text6"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsResume.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofTotalCostUsd1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsResume.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostUsd2"].ObjectFormat.EnableSuppress = true;
                    }
                    else//USA
                    {
                        // General
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["Text31"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["Text33"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["Text35"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["Text37"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["Text1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupHeaderSection1"]).ReportObjects["headerTotalSubcontractorsCad"].ObjectFormat.EnableSuppress = true;

                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["TotalLabourHoursCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["TotalUnitsCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["TotalMaterialsCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["TotalOtherCostsCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["GrandTotalCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["Section3"]).ReportObjects["TotalSubcontractorsCad1"].ObjectFormat.EnableSuppress = true;

                        ((Section)master.Report.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["Text4"].ObjectFormat.EnableSuppress = true;
                        ((Section)master.Report.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["GrandTotalCad2"].ObjectFormat.EnableSuppress = true;

                        // Labour Hours
                        ReportDocument rpLabourHoursDetails = master.Report.OpenSubreport("LabourHoursDetails");
                        ReportDocument rpLabourHoursResume = master.Report.OpenSubreport("LabourHoursResume");

                        ((Section)rpLabourHoursDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text9"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text6"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["LHCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["TotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursDetails.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostCad2"].ObjectFormat.EnableSuppress = true;

                        ((Section)rpLabourHoursResume.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text4"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursResume.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofTotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpLabourHoursResume.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostCad2"].ObjectFormat.EnableSuppress = true;

                        // Units
                        ReportDocument rpUnitsDetails = master.Report.OpenSubreport("UnitsDetails");
                        ReportDocument rpUnitsResume = master.Report.OpenSubreport("UnitsResume");

                        ((Section)rpUnitsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text5"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text4"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["CostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["TotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsDetails.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostCad2"].ObjectFormat.EnableSuppress = true;

                        ((Section)rpUnitsResume.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text4"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsResume.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofTotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpUnitsResume.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostCad2"].ObjectFormat.EnableSuppress = true;

                        // Materials
                        ReportDocument rpMaterialsDetails = master.Report.OpenSubreport("MaterialsDetails");
                        ReportDocument rpMaterialsResune = master.Report.OpenSubreport("MaterialsResume");

                        ((Section)rpMaterialsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text5"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text4"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["CostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["TotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsDetails.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostCad2"].ObjectFormat.EnableSuppress = true;

                        ((Section)rpMaterialsResune.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text4"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsResune.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofTotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpMaterialsResune.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostCad2"].ObjectFormat.EnableSuppress = true;

                        // Subcontractors
                        ReportDocument rpSubcontractorsDetails = master.Report.OpenSubreport("SubcontractorsDetails");
                        ReportDocument rpSubcontractorsResune = master.Report.OpenSubreport("SubcontractorsResume");

                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text5"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text4"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["CostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["TotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofSubTotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsDetails.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostCad1"].ObjectFormat.EnableSuppress = true;

                        ((Section)rpSubcontractorsResune.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["lblTotalCostCad"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsResune.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofTotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpSubcontractorsResune.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostCad2"].ObjectFormat.EnableSuppress = true;

                        // Other Costs
                        ReportDocument rpOtherCostsDetails = master.Report.OpenSubreport("OtherCostsDetails");
                        ReportDocument rpOtherCostsResume = master.Report.OpenSubreport("OtherCostsResume");

                        ((Section)rpOtherCostsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text5"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsDetails.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text4"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["CostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsDetails.ReportDefinition.Sections["DetailSection1"]).ReportObjects["TotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsDetails.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostCad2"].ObjectFormat.EnableSuppress = true;

                        ((Section)rpOtherCostsResume.ReportDefinition.Sections["ReportHeaderSection2"]).ReportObjects["Text4"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsResume.ReportDefinition.Sections["GroupFooterSection1"]).ReportObjects["SumofTotalCostCad1"].ObjectFormat.EnableSuppress = true;
                        ((Section)rpOtherCostsResume.ReportDefinition.Sections["ReportFooterSection1"]).ReportObjects["SumofTotalCostCad2"].ObjectFormat.EnableSuppress = true;
                    }
                }
            }
        }
        private void Delete()
        {
            Page.Validate();

            if (Page.IsValid)
            {
                // Delete all data for service
                int costingSheetId = Int32.Parse(hdfCostingSheetId.Value);

                ProjectCombinedCostingSheetInformationBasicInformation projectCostingSheetInformationBasicInformation = new ProjectCombinedCostingSheetInformationBasicInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationBasicInformation.Delete(costingSheetId);

                // Update databse
                UpdateDatabase();

                // Store datasets
                Session["projectCostingSheetInformationTDS"] = projectCostingSheetInformationTDS;

                // Redirect
                string url = "";

                url = "./project_costing_sheets_navigator.aspx?source_page=project_combined_costing_sheets_delete.aspx&costing_sheet_id=" + hdfCostingSheetId.Value + "&project_id=" + hdfProjectId.Value + "&active_tab=" + (string)ViewState["active_tab"] + GetNavigatorState() + "&origin=" + (string)ViewState["origin"] + "&update=yes&data_changed=" + hdfDataChanged.Value + "&state=" + (string)ViewState["state"];

                Response.Redirect(url);
            }
        }
        private void UpdateDatabase()
        {
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int costingSheetId = Int32.Parse(hdfCostingSheetId.Value);

            DB.Open();
            DB.BeginTransaction();
            try
            {
                ProjectCombinedCostingSheetInformationBasicInformation projectCostingSheetInformationBasicInformation = new ProjectCombinedCostingSheetInformationBasicInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationBasicInformation.Save(companyId);

                // Save costs information
                ProjectCombinedCostingSheetInformationLabourHoursInformation projectCostingSheetInformationLabourHoursInformation = new ProjectCombinedCostingSheetInformationLabourHoursInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationLabourHoursInformation.Save(companyId, costingSheetId);

                ProjectCombinedCostingSheetInformationUnitsInformation projectCostingSheetInformationUnitsInformation = new ProjectCombinedCostingSheetInformationUnitsInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationUnitsInformation.Save(companyId, costingSheetId);

                ProjectCombinedCostingSheetInformationMaterialsInformation projectCostingSheetInformationMaterialsInformation = new ProjectCombinedCostingSheetInformationMaterialsInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationMaterialsInformation.Save(companyId, costingSheetId);

                ProjectCombinedCostingSheetInformationOtherCostsInformation projectCostingSheetInformationOtherCostsInformation = new ProjectCombinedCostingSheetInformationOtherCostsInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationOtherCostsInformation.Save(companyId, costingSheetId);

                ProjectCombinedCostingSheetInformationSubcontractorsInformation projectCostingSheetInformationSubcontractorsInformation = new ProjectCombinedCostingSheetInformationSubcontractorsInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationSubcontractorsInformation.Save(companyId, costingSheetId);

                DB.CommitTransaction();

                // Store datasets
                projectCostingSheetInformationTDS.AcceptChanges();
                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;
            }
            catch (Exception ex)
            {
                DB.RollbackTransaction();

                string url = string.Format("./../../error_page.aspx?error={0}", ex.Message.Replace('\n', ' '));
                Response.Redirect(url);
            }
        }
        private void Save()
        {
            // Validate data
            bool validData = true;

            // Validate general data
            Page.Validate("general");

            // For valid data
            if (validData)
            {
                // Team Members Gridview, if the gridview is edition mode
                if (grdTeamMembers.EditIndex >= 0)
                {
                    grdTeamMembers.UpdateRow(grdTeamMembers.EditIndex, true);
                }

                // Units Gridview, if the gridview is edition mode
                if (grdUnits.EditIndex >= 0)
                {
                    grdUnits.UpdateRow(grdUnits.EditIndex, true);
                }

                // Materials Gridview, if the gridview is edition mode
                if (grdMaterials.EditIndex >= 0)
                {
                    grdMaterials.UpdateRow(grdMaterials.EditIndex, true);
                }

                // Other Costs Gridview, if the gridview is edition mode
                if (grdOtherCosts.EditIndex >= 0)
                {
                    grdOtherCosts.UpdateRow(grdOtherCosts.EditIndex, true);
                }

                // Subcontractors Costs Gridview, if the gridview is edition mode
                if (grdSubcontractors.EditIndex >= 0)
                {
                    grdSubcontractors.UpdateRow(grdSubcontractors.EditIndex, true);
                }

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

                // General
                string state = tbxState.Text;
                decimal teamMembersTotalCostCad = decimal.Parse(tbxTeamMembersTotalCostCAD.Text);
                decimal teamMembersTotalCostUsd = decimal.Parse(tbxTeamMembersTotalCostUSD.Text);
                decimal unitsTotalCostCad = decimal.Parse(tbxUnitsTotalCostsCAD.Text);
                decimal unitsTotalCostUsd = decimal.Parse(tbxUnitsTotalCostsUSD.Text);
                decimal materialsTotalCostCad = decimal.Parse(tbxMaterialsTotalCostsCAD.Text);
                decimal materialsTotalCostUsd = decimal.Parse(tbxMaterialsTotalCostsUSD.Text);
                decimal otherCostsTotalCostCad = decimal.Parse(tbxOtherCostsTotalCostsCAD.Text);
                decimal otherCostsTotalCostUsd = decimal.Parse(tbxOtherCostsTotalCostsUSD.Text);
                decimal grandTotalCostCad = decimal.Parse(tbxTotalCostCad.Text);
                decimal grandTotalCostUsd = decimal.Parse(tbxTotalCostUsd.Text);
                decimal subcontractorsTotalCostCad = decimal.Parse(tbxSubcontractorsTotalCostsCAD.Text);
                decimal subcontractorsTotalCostUsd = decimal.Parse(tbxSubcontractorsTotalCostsUSD.Text);

                decimal grandRevenue = 0.0M; if (tbxGrandRevenue.Text != "") grandRevenue = decimal.Parse(tbxGrandRevenue.Text);
                decimal grandProfit = 0.0M; if (tbxGrandProfit.Text != "") grandProfit = decimal.Parse(tbxGrandProfit.Text);
                decimal grandGrossMargin = 0.0M; if (tbxGrandGrossMargin.Text != "") { tbxGrandGrossMargin.Text = tbxGrandGrossMargin.Text.Replace('%', ' '); grandGrossMargin = decimal.Parse(tbxGrandGrossMargin.Text.Trim()); }

                // Update unit data
                ProjectCombinedCostingSheetInformationBasicInformation projectCostingSheetInformationBasicInformation = new ProjectCombinedCostingSheetInformationBasicInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationBasicInformation.Update(costingSheetId, hdfCostingSheetName.Value, teamMembersTotalCostCad, teamMembersTotalCostUsd, materialsTotalCostCad, materialsTotalCostUsd, unitsTotalCostCad, unitsTotalCostUsd, otherCostsTotalCostCad, otherCostsTotalCostUsd, grandTotalCostCad, grandTotalCostUsd, subcontractorsTotalCostCad, subcontractorsTotalCostUsd, grandRevenue, grandProfit, grandGrossMargin);

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

                // Update database
                UpdateDatabase();

                ViewState["update"] = "yes";

                // Redirect
                string url = "";
                if (Request.QueryString["source_page"] == "project_costing_sheets_navigator.aspx" || Request.QueryString["source_page"] == "project_combined_costing_sheets_add.aspx")
                {
                    url = "./project_costing_sheets_navigator.aspx?source_page=project_combined_costing_sheets_edit.aspx&costing_sheet_id=" + hdfCostingSheetId.Value + "&project_id=" + hdfProjectId.Value + "&costing_sheet_state=Approved&active_tab=" + (string)ViewState["active_tab"] + GetNavigatorState() + "&origin=" + (string)ViewState["origin"] + "&update=" + (string)ViewState["update"] + "&data_changed=" + hdfDataChanged.Value + "&state=" + (string)ViewState["state"];
                }

                if (Request.QueryString["source_page"] == "project_combined_costing_sheets_summary.aspx")
                {
                    url = "./project_combined_costing_sheets_summary.aspx?source_page=project_combined_costing_sheets_edit.aspx&costing_sheet_id=" + hdfCostingSheetId.Value + "&project_id=" + hdfProjectId.Value + "&costing_sheet_state=Approved&active_tab=" + (string)ViewState["active_tab"] + GetNavigatorState() + "&origin=" + (string)ViewState["origin"] + "&update=" + (string)ViewState["update"] + "&data_changed=" + hdfDataChanged.Value + "&state=" + (string)ViewState["state"];
                }

                Response.Redirect(url);
            }
        }
        private void Apply()
        {
            // Validate data
            bool validData = true;

            // Validate general data
            Page.Validate("general");

            // For valid data
            if (validData)
            {
                // Team Members Gridview, if the gridview is edition mode
                if (grdTeamMembers.EditIndex >= 0)
                {
                    grdTeamMembers.UpdateRow(grdTeamMembers.EditIndex, true);
                }

                // Units Gridview, if the gridview is edition mode
                if (grdUnits.EditIndex >= 0)
                {
                    grdUnits.UpdateRow(grdUnits.EditIndex, true);
                }

                // Materials Gridview, if the gridview is edition mode
                if (grdMaterials.EditIndex >= 0)
                {
                    grdMaterials.UpdateRow(grdMaterials.EditIndex, true);
                }

                // Other Costs Gridview, if the gridview is edition mode
                if (grdOtherCosts.EditIndex >= 0)
                {
                    grdOtherCosts.UpdateRow(grdOtherCosts.EditIndex, true);
                }

                // Subcontractors Costs Gridview, if the gridview is edition mode
                if (grdSubcontractors.EditIndex >= 0)
                {
                    grdSubcontractors.UpdateRow(grdSubcontractors.EditIndex, true);
                }

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

                // General
                string state = tbxState.Text;
                decimal teamMembersTotalCostCad = decimal.Parse(tbxTeamMembersTotalCostCAD.Text);
                decimal teamMembersTotalCostUsd = decimal.Parse(tbxTeamMembersTotalCostUSD.Text);
                decimal unitsTotalCostCad = decimal.Parse(tbxUnitsTotalCostsCAD.Text);
                decimal unitsTotalCostUsd = decimal.Parse(tbxUnitsTotalCostsUSD.Text);
                decimal materialsTotalCostCad = decimal.Parse(tbxMaterialsTotalCostsCAD.Text);
                decimal materialsTotalCostUsd = decimal.Parse(tbxMaterialsTotalCostsUSD.Text);
                decimal otherCostsTotalCostCad = decimal.Parse(tbxOtherCostsTotalCostsCAD.Text);
                decimal otherCostsTotalCostUsd = decimal.Parse(tbxOtherCostsTotalCostsUSD.Text);
                decimal grandTotalCostCad = decimal.Parse(tbxTotalCostCad.Text);
                decimal grandTotalCostUsd = decimal.Parse(tbxTotalCostUsd.Text);
                decimal subcontractorsTotalCostCad = decimal.Parse(tbxSubcontractorsTotalCostsCAD.Text);
                decimal subcontractorsTotalCostUsd = decimal.Parse(tbxSubcontractorsTotalCostsUSD.Text);

                decimal grandRevenue = 0.0M; if (tbxGrandRevenue.Text != "") grandRevenue = decimal.Parse(tbxGrandRevenue.Text);
                decimal grandProfit = 0.0M; if (tbxGrandProfit.Text != "") grandProfit = decimal.Parse(tbxGrandProfit.Text);
                decimal grandGrossMargin = 0.0M; if (tbxGrandGrossMargin.Text != "") { tbxGrandGrossMargin.Text = tbxGrandGrossMargin.Text.Replace('%', ' '); grandGrossMargin = decimal.Parse(tbxGrandGrossMargin.Text.Trim()); }

                // Update unit data
                ProjectCombinedCostingSheetInformationBasicInformation projectCostingSheetInformationBasicInformation = new ProjectCombinedCostingSheetInformationBasicInformation(projectCostingSheetInformationTDS);
                projectCostingSheetInformationBasicInformation.Update(costingSheetId, hdfCostingSheetName.Value, teamMembersTotalCostCad, teamMembersTotalCostUsd, materialsTotalCostCad, materialsTotalCostUsd, unitsTotalCostCad, unitsTotalCostUsd, otherCostsTotalCostCad, otherCostsTotalCostUsd, grandTotalCostCad, grandTotalCostUsd, subcontractorsTotalCostCad, subcontractorsTotalCostUsd, grandRevenue, grandProfit, grandGrossMargin);

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

                // Update database
                UpdateDatabase();

                ViewState["update"] = "yes";
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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"];
            }
        }