// ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Store navigator state
                StoreNavigatorState();

                hdfUpdate.Value = "yes";
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();

                tbxDescription.Text = Server.UrlDecode(Request.QueryString["subject"].ToString());
                ViewState["refId"] = Request.QueryString["refId"].ToString();
                ViewState["projectId"] = Request.QueryString["project_id"].ToString();
                ViewState["libraryCategoriesId"] = Request.QueryString["library_categories_id"].ToString();

                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectNavigatorTDS = (ProjectNavigatorTDS)Session["projectNavigatorTDS"];
                projectNotes = (ProjectNavigatorTDS.ProjectNotesDataTable)Session["projectNotes"];

                if (Session["lfsLibraryTDS"] != null)
                {
                    libraryTDS = (LibraryTDS)Session["lfsLibraryTDS"];
                }
                else
                {
                    libraryTDS = new LibraryTDS();
                }

                Session["lfsProjectTDS"] = projectTDS;
            }
            else
            {
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectNavigatorTDS = (ProjectNavigatorTDS)Session["projectNavigatorTDS"];
                projectNotes = (ProjectNavigatorTDS.ProjectNotesDataTable)Session["projectNotes"];

                if (Session["lfsLibraryTDS"] != null)
                {
                    libraryTDS = (LibraryTDS)Session["lfsLibraryTDS"];
                }
                else
                {
                    libraryTDS = new LibraryTDS();
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_PROJECTS_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["project_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_engineer_subcontractors_edit.aspx");
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfProjectId.Value = Request.QueryString["project_id"];

                // If coming from

                // ... project_engineer_subcontractors.aspx or project_engineer_subcontractors_edit.aspx
                if ((Request.QueryString["source_page"] == "project_engineer_subcontractors.aspx") || (Request.QueryString["source_page"] == "project_engineer_subcontractors_edit.aspx"))
                {
                    // Restore dataset
                    projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                }

                // Prepare initial data

                // ... for subcontractor
                int companyId = Int32.Parse(hdfCompanyId.Value);
                CompaniesList companiesList = new CompaniesList();
                companiesList.LoadAndAddItem(-1, "(Select)", companyId);
                ddlSubcontractorId.DataSource = companiesList.Table;
                ddlSubcontractorId.DataTextField = "Name";
                ddlSubcontractorId.DataValueField = "COMPANIES_ID";
                ddlSubcontractorId.DataBind();
            }
            else
            {
                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

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

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

                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                assetsTDS = new AssetsTDS();
                lfsAssetsTDS = new LfsAssetsTDS();
                workTDS = new WorkTDS();

                // Tag page
                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"];

                Session.Remove("projectSectionsNavigatorNewDummy");
                Session.Remove("projectSectionsNavigator");

                // Prepare initial data
                lblError.Visible = false;

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

                // ... for client
                int companyId = Int32.Parse(hdfCompanyId.Value.Trim());
                int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));
                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(currentClientId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId);

                hdfClientId.Value = projectGateway.GetClientID(int.Parse(hdfProjectId.Value)).ToString();

                // Store navigator state at projects navigator
                StoreNavigatorState();

                // ... project_sections_navigator.aspx or project_sections_navigator2.aspx
                if ((Request.QueryString["source_page"] == "project_sections_navigator.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator2.aspx"))
                {
                    // Restore navigator state
                    RestoreNavigatorState();

                    // Restore data
                    projectSectionsNavigatorTDS = (ProjectSectionsNavigatorTDS)Session["lfsProjectSectionsNavigatorTDS"];
                    projectSectionsNavigator = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR;

                    // Store data
                    Session["projectSectionsNavigator"] = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR;

                    if (Request.QueryString["update_section"] == "no")
                    {
                        // Restore data
                        projectSectionsNavigatorTDS = (ProjectSectionsNavigatorTDS)Session["lfsProjectSectionsNavigatorTDS"];
                        projectSectionsNavigator = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR;

                        // Store data
                        Session["projectSectionsNavigator"] = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR;
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("lfsProjectSectionsNavigatorTDS");

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

                        // ... store datasets
                        Session["lfsProjectSectionsNavigatorTDS"] = projectSectionsNavigatorTDS;
                        Session["projectSectionsNavigator"] = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR;
                    }

                    //... for the total rows
                    if (projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR.Rows.Count > 0)
                    {
                        lblTotalRows.Text = "Total Rows: " + projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR.Rows.Count;
                        lblTotalRows.Visible = true;
                    }
                    else
                    {
                        lblTotalRows.Visible = false;
                    }
                }
            }
            else
            {
                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectSectionsNavigatorTDS = (ProjectSectionsNavigatorTDS)Session["lfsProjectSectionsNavigatorTDS"];
                assetsTDS = (AssetsTDS)Session["assetsTDS"];
                lfsAssetsTDS = (LfsAssetsTDS)Session["lfsAssetsTDS"];
                workTDS = (WorkTDS)Session["workTDS"];

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

                // ... for client
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));
                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(currentClientId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId);

                // Restore searched data (if any)
                projectSectionsNavigatorTDS = (ProjectSectionsNavigatorTDS)Session["lfsProjectSectionsNavigatorTDS"];
                projectSectionsNavigator = projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR;

                //... for the total rows
                if (projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + projectSectionsNavigatorTDS.LFS_PROJECT_SECTIONS_NAVIGATOR.Rows.Count;
                }
                else
                {
                    lblTotalRows.Visible = false;
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

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

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

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfProjectId.Value = Request.QueryString["project_id"];
                hdfAssetID.Value = Request.QueryString["asset_id"];
                Session.Remove("projectSectionsNavigatorLateralsNewDummy");
                Session.Remove("projectSectionsNavigatorLaterals");

                // Initialize data
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                assetsTDS = new AssetsTDS();
                lfsAssetsTDS = new LfsAssetsTDS();
                workTDS = new WorkTDS();
                projectSectionsNavigatorTDS = new ProjectSectionsNavigatorTDS();

                // Load data
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int assetId = Int32.Parse(hdfAssetID.Value);
                int projectId = Int32.Parse(hdfProjectId.Value);

                AssetSewerSectionGateway assetSewerSectionGateway = new AssetSewerSectionGateway();
                assetSewerSectionGateway.LoadByAssetId(assetId, companyId);

                if (assetSewerSectionGateway.Table.Rows.Count > 0)
                {
                    tbxSectionId.Text = assetSewerSectionGateway.GetFlowOrderID(assetId);
                    tbxStreet.Text = assetSewerSectionGateway.GetStreet(assetId);

                    // ... For usmh
                    if (assetSewerSectionGateway.GetUSMH(assetId).HasValue)
                    {
                        AssetSewerMHGateway assetSewerFindMHGateway = new AssetSewerMHGateway();
                        int USMH = (int)assetSewerSectionGateway.GetUSMH(assetId);

                        assetSewerFindMHGateway.LoadByAssetId(USMH, companyId);
                        tbxUSMH.Text = assetSewerFindMHGateway.GetMHID(USMH);
                    }

                    // ... For usmh
                    if (assetSewerSectionGateway.GetDSMH(assetId).HasValue)
                    {
                        AssetSewerMHGateway assetSewerFindMHGateway = new AssetSewerMHGateway();
                        int DSMH = (int)assetSewerSectionGateway.GetDSMH(assetId);

                        assetSewerFindMHGateway.LoadByAssetId(DSMH, companyId);
                        tbxDSMH.Text = assetSewerFindMHGateway.GetMHID(DSMH);
                    }

                    // ... For Works
                    WorkGateway workGateway = new WorkGateway();
                    if (workGateway.ExistsProjectIdAssetIdWorkTypeCompanyId(assetId, projectId, "Rehab Assessment", companyId))
                        ckbxRehabAssessment.Checked = true;
                    if (workGateway.ExistsProjectIdAssetIdWorkTypeCompanyId(assetId, projectId, "Full Length Lining", companyId))
                        ckbxFullLengthLining.Checked = true;
                    if (workGateway.ExistsProjectIdAssetIdWorkTypeCompanyId(assetId, projectId, "Junction Lining Section", companyId))
                        ckbxJunctionLining.Checked = true;

                    // ... For Laterals
                    if (assetSewerSectionGateway.GetLaterals(int.Parse(hdfAssetID.Value)).HasValue)
                    {
                        tbxTotalLaterals.Text = ((int)assetSewerSectionGateway.GetLaterals(assetId)).ToString();
                    }
                    else
                    {
                        tbxTotalLaterals.Text = "0";
                    }

                    ProjectSectionsNavigatorLateralsGateway projectSectionsNavigatorLateralsGateway = new ProjectSectionsNavigatorLateralsGateway(projectSectionsNavigatorTDS);
                    projectSectionsNavigatorLateralsGateway.LoadBySection_ProjectId(assetId, projectId, companyId);

                    AssetSewerLateralGateway assetSewerLateralGateway = new AssetSewerLateralGateway(assetsTDS);
                    assetSewerLateralGateway.LoadBySectionProjectId(assetId, projectId, companyId);

                    // ... store datasets
                    Session["projectSectionsNavigatorTDS"] = projectSectionsNavigatorTDS;
                    projectSectionsNavigatorLaterals = projectSectionsNavigatorTDS.ProjectSectionNavigatorLaterals;
                    Session["projectSectionsNavigatorLaterals"] = projectSectionsNavigatorLaterals;
                }
            }
            else
            {
                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectSectionsNavigatorTDS = (ProjectSectionsNavigatorTDS)Session["lfsProjectSectionsNavigatorTDS"];
                projectSectionsNavigatorLaterals = (ProjectSectionsNavigatorTDS.ProjectSectionNavigatorLateralsDataTable)Session["projectSectionsNavigatorLaterals"];
                assetsTDS = (AssetsTDS)Session["assetsTDS"];
                lfsAssetsTDS = (LfsAssetsTDS)Session["lfsAssetsTDS"];
                workTDS = (WorkTDS)Session["workTDS"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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_combined_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_combined_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);

                    ProjectCombinedCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGateway = new ProjectCombinedCostingSheetInformationBasicInformationGateway(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_combined_costing_sheets_summary.aspx
                if (Request.QueryString["source_page"] == "project_combined_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
                        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 delete it.");
                        }
                    }
                }
            }
            else
            {
                // Restore datasets
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectCostingSheetInformationTDS = (ProjectCostingSheetInformationTDS)Session["projectCostingSheetInformationTDS"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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"];
            }
        }
        private void PostPageChanges(int originalProjectId)
        {
            // Definition of general variables
            projectTDS = new ProjectTDS();

            // ... Insert project_general
            InsertProject(originalProjectId);

            // ... Get newProjectId
            Project project = new Project(projectTDS);

            // ... Insert project_costing_updates
            InsertProjectCostingUpdates(originalProjectId);

            // ... Insert project_engineer_subcontractors
            InsertProjectEngineerSubcontractors(originalProjectId);

            // ...Insert project_subcontractor
            InsertProjectSubcontractor(originalProjectId);

            // ... Insert project_notes
            InsertProjectNote(originalProjectId);

            // ... Insert project_sale_billing_pricing
            InsertProjectSaleBillingPricing(originalProjectId);

            // ... Insert project_service
            InsertProjectService(originalProjectId);

            // ... Insert project_technical
            InsertProjectTechnical(originalProjectId);

            // ... Insert Terms
            InsertProjectTerms(originalProjectId);
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

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

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

                // If coming from

                // ... Left Menu or Out
                if ((Request.QueryString["source_page"] == "lm") || (Request.QueryString["source_page"] == "out"))
                {
                    // Store Navigator State and Update control
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

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

                    tNoResults.Visible = false;
                }

                // ... project_sections_navigator2.aspx
                if (Request.QueryString["source_page"] == "project_sections_navigator2.aspx")
                {
                    RestoreNavigatorState();

                    if ((string)Request.QueryString["no_results"] == "yes")
                    {
                        tNoResults.Visible = true;
                    }
                    else
                    {
                        tNoResults.Visible = false;
                    }
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfProjectId.Value = Request.QueryString["project_id"];
                ViewState["origin"] = Request.QueryString["origin"];
                ViewState["state"] = Request.QueryString["state"];
                ViewState["active_tab"] = Request.QueryString["active_tab"];

                hdfDataChanged.Value = Request.QueryString["data_changed"];
                hdfDataChangedMessage.Value = "Changes made to this project will not be saved.";

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

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

                // ... for client
                int currentCompanyId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));
                int companyId = Int32.Parse(hdfCompanyId.Value);
                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(currentCompanyId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentCompanyId);

                hdfClientId.Value = projectGateway.GetClientID(int.Parse(hdfProjectId.Value)).ToString();
            }
            else
            {
                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];

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

                // ... for client
                int currentCompanyId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));
                int companyId = Int32.Parse(hdfCompanyId.Value);
                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(currentCompanyId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentCompanyId);
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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)  || ((string)Request.QueryString["costing_sheet_state"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_costing_sheets_state.aspx");
                }

                // Tag Page
                hdfCostingSheetId.Value = Request.QueryString["costing_sheet_id"].ToString();
                hdfCostingSheetState.Value = Request.QueryString["costing_sheet_state"].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"];
                int projectId = Int32.Parse(hdfProjectId.Value);

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

                // If coming from project_costing_sheets_summary.aspx
                if ((string)Request.QueryString["source_page"] == "project_costing_sheets_summary.aspx")
                {
                    ViewState["update"] = Request.QueryString["update"];

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

                    projectCostingSheetInformationTDS = (ProjectCostingSheetInformationTDS)Session["projectCostingSheetInformationTDS"];
                    ProjectCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGateway = new ProjectCostingSheetInformationBasicInformationGateway(projectCostingSheetInformationTDS);
                    projectCostingSheetInformationBasicInformationGateway.LoadByCostingSheetId(costingSheetId, companyId);

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

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

                // Costing Sheet state check
                ProjectCostingSheetInformationBasicInformationGateway projectCostingSheetInformationBasicInformationGatewayToValidate = new ProjectCostingSheetInformationBasicInformationGateway(projectCostingSheetInformationTDS);

                DateTime startDate = projectCostingSheetInformationBasicInformationGatewayToValidate.GetStartDate(Int32.Parse(hdfCostingSheetId.Value));
                DateTime endDate = projectCostingSheetInformationBasicInformationGatewayToValidate.GetEndDate(Int32.Parse(hdfCostingSheetId.Value));

                ProjectCostingSheetGateway projectCostingSheetGateway = new ProjectCostingSheetGateway();
                if (projectCostingSheetGateway.ExistCostingSheetApproved(projectId, startDate, endDate))
                {
                    string msg = "You cannot approve this costing sheet. There are other costing sheets already approved on the same date range. There is an overlaping issue between yours costing sheets.";
                    Response.Redirect("./../../error_page.aspx?error=" + msg);
                }
            }
            else
            {
                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectCostingSheetInformationTDS = (ProjectCostingSheetInformationTDS)Session["projectCostingSheetInformationTDS"];
            }
        }
        private void InsertProjectSaleBillingPricing(int originalProjectId)
        {
            // ... Data for current project
            ProjectTDS projectTDSTemp = new ProjectTDS();
            ProjectSaleBillingPricingGateway projectSaleBillingPricingGatewayTemp = new ProjectSaleBillingPricingGateway(projectTDSTemp);
            projectSaleBillingPricingGatewayTemp.LoadAllByProjectId(originalProjectId);

            ProjectSaleBillingPricingGateway projectSaleBillingPricingGateway = new ProjectSaleBillingPricingGateway(projectTDS);
            projectSaleBillingPricingGateway.LoadAllByProjectId(originalProjectId);

            if (projectSaleBillingPricingGateway.Table.Rows.Count > 0)
            {
                // ... Definition of general variables
                bool saleBidProject = projectSaleBillingPricingGateway.GetSaleBidProject(originalProjectId);
                bool saleRFP = projectSaleBillingPricingGateway.GetSaleRFP(originalProjectId);
                bool saleSoleSource = projectSaleBillingPricingGateway.GetSaleSoleSource(originalProjectId);
                bool saleTermContract = projectSaleBillingPricingGateway.GetSaleTermContract(originalProjectId);
                string saleTermContractDetail = projectSaleBillingPricingGateway.GetSaleTermContractDetail(originalProjectId);
                bool saleOther = projectSaleBillingPricingGateway.GetSaleOther(originalProjectId);
                string saleOtherDetail = projectSaleBillingPricingGateway.GetSaleOtherDetail(originalProjectId);
                int? saleGettingJob = null; if (projectSaleBillingPricingGateway.GetSaleGettingJob(originalProjectId).HasValue) saleGettingJob = (int)projectSaleBillingPricingGateway.GetSaleGettingJob(originalProjectId);
                decimal? billPrice = null; if (projectSaleBillingPricingGateway.GetBillPrice(originalProjectId).HasValue) billPrice = (decimal)projectSaleBillingPricingGateway.GetBillPrice(originalProjectId);
                string billMoney = projectSaleBillingPricingGateway.GetBillMoney(originalProjectId);
                decimal? billSubcontractorAmount = null; if (projectSaleBillingPricingGateway.GetBillSubcontractorAmount(originalProjectId).HasValue) billSubcontractorAmount = (decimal)projectSaleBillingPricingGateway.GetBillSubcontractorAmount(originalProjectId);
                string billBidHardDollar = projectSaleBillingPricingGateway.GetBillBidHardDollar(originalProjectId);
                bool billPerUnit = projectSaleBillingPricingGateway.GetBillPerUnit(originalProjectId);
                bool billHourly = projectSaleBillingPricingGateway.GetBillHourly(originalProjectId);
                string billExpectExtras = projectSaleBillingPricingGateway.GetBillExpectExtras(originalProjectId);
                bool chargesWater = projectSaleBillingPricingGateway.GetChargesWater(originalProjectId);
                decimal? chargesWaterAmount = null; if (projectSaleBillingPricingGateway.GetChargesWaterAmount(originalProjectId).HasValue) chargesWaterAmount = (decimal)projectSaleBillingPricingGateway.GetChargesWaterAmount(originalProjectId);
                bool chargesDisposal = projectSaleBillingPricingGateway.GetChargesDisposal(originalProjectId);
                decimal? chargesDisposalAmount = null; if (projectSaleBillingPricingGateway.GetChargesDisposalAmount(originalProjectId).HasValue) chargesDisposalAmount = (decimal)projectSaleBillingPricingGateway.GetChargesDisposalAmount(originalProjectId);

                // ... Insert Sale/Billing/Pricing
                ProjectSaleBillingPricing projectSaleBillingPricing = new ProjectSaleBillingPricing(projectTDS);
                projectSaleBillingPricing.Insert(0, saleBidProject, saleRFP, saleSoleSource, saleTermContract, saleTermContractDetail, saleOther, saleOtherDetail, saleGettingJob, billPrice, billMoney, billBidHardDollar, billPerUnit, billHourly, billExpectExtras, billSubcontractorAmount, chargesWater, chargesWaterAmount, chargesDisposal, chargesDisposalAmount, Int32.Parse(hdfCompanyId.Value.Trim()));
            }
        }
        private void InsertProjectNote(int originalProjectId)
        {
            // ... Data for current project
            ProjectTDS projectTDSTemp = new ProjectTDS();
            ProjectNotesGateway projectNotesGatewayTemp = new ProjectNotesGateway(projectTDSTemp);
            projectNotesGatewayTemp.LoadAllByProjectId(originalProjectId);

            ProjectNotesGateway projectNotesGateway = new ProjectNotesGateway(projectTDS);
            projectNotesGateway.LoadAllByProjectId(originalProjectId);

            ProjectNotes projectNotes = new ProjectNotes(projectTDS);

            // ... Definition of general variables
            int refId;
            string subject;
            DateTime dateTime;
            int loginId;
            string note;
            bool deleted;
            int? libraryFilesId;

            foreach (ProjectTDS.LFS_PROJECT_NOTERow row in projectTDSTemp.Tables["LFS_PROJECT_NOTE"].Rows)
            {
                // ... Definition of general variables
                refId = row.RefID;
                subject = row.Subject;
                dateTime = row.DateTime;
                loginId = row.LoginID;
                try { note = row.Note; }
                catch { note = ""; }
                deleted = row.Deleted;
                try { libraryFilesId = row.LIBRARY_FILES_ID; }
                catch { libraryFilesId = null; }

                // ... Insert Notes
                projectNotes.Insert(0, subject, dateTime, loginId, note, deleted, libraryFilesId, Int32.Parse(hdfCompanyId.Value.Trim()));
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Store navigator state
                StoreNavigatorState();

                hdfUpdate.Value = "no";

                libraryTDS = new LibraryTDS();
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];

                Session["libraryTDS"] = libraryTDS;
                Session["lfsProjectTDS"] = projectTDS;

                ViewState["projectId"] = int.Parse(Request.QueryString["project_id"].ToString());
            }
            else
            {
                libraryTDS = (LibraryTDS)Session["libraryTDS"];
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // 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"]))
                    {
                        Response.Redirect("./../../error_page.aspx?error=" + "You are not authorized to view this page. Contact your system administrator.");
                    }
                }

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

                // Tag page
                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"];

                // Prepare initial data
                //lblResults.Visible = false;

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

                // ... for client
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int currentCompanyId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));
                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(currentCompanyId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentCompanyId);

                hdfClientId.Value = projectGateway.GetClientID(int.Parse(hdfProjectId.Value)).ToString();

                // Store navigator state at projects navigator
                StoreNavigatorState();

                // If coming from
                // ... project_summary.aspx, project_edit.aspx, project_sections_navigator.aspx or project_sections_navigator2.aspx
                if ((Request.QueryString["source_page"] == "project_summary.aspx") || (Request.QueryString["source_page"] == "project_edit.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator.aspx") || (Request.QueryString["source_page"] == "project_sections_navigator2.aspx"))
                {
                    projectCostingSheetsNavigatorTDS = new ProjectCostingSheetsNavigatorTDS();

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

                    // ... Store datasets
                    Session["projectCostingSheetsNavigatorTDS"] = projectCostingSheetsNavigatorTDS;
                }

                // ... project_costing_sheets_edit.aspx, project_costing_sheets_summary.aspx or project_costing_sheets_delete.aspx
                if ((Request.QueryString["source_page"] == "project_costing_sheets_edit.aspx") || (Request.QueryString["source_page"] == "project_costing_sheets_summary.aspx") || (Request.QueryString["source_page"] == "project_costing_sheets_delete.aspx") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_edit.aspx") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_summary.aspx") || (Request.QueryString["source_page"] == "project_combined_costing_sheets_delete.aspx"))
                {
                    if (Request.QueryString["update"] == "no")
                    {
                        projectCostingSheetsNavigatorTDS = (ProjectCostingSheetsNavigatorTDS)Session["projectCostingSheetsNavigatorTDS"];
                    }
                    else
                    {
                        // ... Delete store data
                        Session.Contents.Remove("projectCostingSheetsNavigatorTDS");

                        projectCostingSheetsNavigatorTDS = SubmitSearch();

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

                // For the grid
                grdCostingSheetsNavigator.DataSource = projectCostingSheetsNavigatorTDS.ProjectCostingSheetsNavigator;
                grdCostingSheetsNavigator.DataBind();

                grdCombinedCostingSheetsNavigator.DataSource = projectCostingSheetsNavigatorTDS.ProjectCombinedCostingSheetsNavigator;
                grdCombinedCostingSheetsNavigator.DataBind();

                //lblResults.Visible = false;

                // ... For the total rows
                if (projectCostingSheetsNavigatorTDS.ProjectCostingSheetsNavigator.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + projectCostingSheetsNavigatorTDS.ProjectCostingSheetsNavigator.Rows.Count;
                    lblTotalRows.Visible = true;
                    //lblResults.Visible = true;
                    btnOpen.Visible = true;
                    btnEdit.Visible = true;
                    btnDelete.Visible = true;
                    ddlAction.Visible = true;
                    pnlHorizontalRule.Visible = true;
                    lblCostingSheetsTitle.Visible = true;
                }
                else
                {
                    lblTotalRows.Visible = false;
                    btnOpen.Visible = false;
                    btnEdit.Visible = false;
                    btnDelete.Visible = false;
                    ddlAction.Visible = false;
                    pnlHorizontalRule.Visible = false;
                    lblCostingSheetsTitle.Visible = false;
                }

                // ... For the total rows
                if (projectCostingSheetsNavigatorTDS.ProjectCombinedCostingSheetsNavigator.Rows.Count > 0)
                {
                    //lblResults.Visible = true;
                    lblCombinedCostingSheetsTotalRows.Text = "Total Rows: " + projectCostingSheetsNavigatorTDS.ProjectCombinedCostingSheetsNavigator.Rows.Count;
                    lblCombinedCostingSheetsTotalRows.Visible = true;
                    lblCombinedCostingSheetsTitle.Visible = true;
                    lblCombinedCostingSheetsTotalRows.Visible = true;
                    btnOpenCombinedCostingSheet.Visible = true;
                    btnEditCombinedCostingSheet.Visible = true;
                    btnDeleteCombinedCostingSheet.Visible = true;
                    pnlHorizontalRuleCombinedCostingSheet.Visible = true;
                    ddlActionCombinedCostingSheet.Visible = true;
                }
                else
                {
                    lblCombinedCostingSheetsTotalRows.Visible = false;
                    lblCombinedCostingSheetsTitle.Visible = false;
                    lblCombinedCostingSheetsTotalRows.Visible = false;
                    btnOpenCombinedCostingSheet.Visible = false;
                    btnEditCombinedCostingSheet.Visible = false;
                    btnDeleteCombinedCostingSheet.Visible = false;
                    pnlHorizontalRuleCombinedCostingSheet.Visible = false;
                    ddlActionCombinedCostingSheet.Visible = false;
                }
            }
            else
            {
                // Restore TDS
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectCostingSheetsNavigatorTDS = (ProjectCostingSheetsNavigatorTDS)Session["projectCostingSheetsNavigatorTDS"];

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

                // ... for client
                int companyId = Int32.Parse(hdfCompanyId.Value);
                int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));
                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(currentClientId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId);

                // ... For the total rows
                if (projectCostingSheetsNavigatorTDS.ProjectCostingSheetsNavigator.Rows.Count > 0)
                {
                    lblTotalRows.Text = "Total Rows: " + projectCostingSheetsNavigatorTDS.ProjectCostingSheetsNavigator.Rows.Count;
                    lblTotalRows.Visible = true;
                    //lblResults.Visible = true;
                    btnOpen.Visible = true;
                    btnEdit.Visible = true;
                    btnDelete.Visible = true;
                    ddlAction.Visible = true;
                    pnlHorizontalRule.Visible = true;
                    lblCostingSheetsTitle.Visible = true;
                }
                else
                {
                    lblTotalRows.Visible = false;
                    btnOpen.Visible = false;
                    btnEdit.Visible = false;
                    btnDelete.Visible = false;
                    ddlAction.Visible = false;
                    pnlHorizontalRule.Visible = false;
                    lblCostingSheetsTitle.Visible = false;
                }

                // ... For the total rows
                if (projectCostingSheetsNavigatorTDS.ProjectCombinedCostingSheetsNavigator.Rows.Count > 0)
                {
                    //lblResults.Visible = true;
                    lblCombinedCostingSheetsTotalRows.Text = "Total Rows: " + projectCostingSheetsNavigatorTDS.ProjectCombinedCostingSheetsNavigator.Rows.Count;
                    lblCombinedCostingSheetsTotalRows.Visible = true;
                    lblCombinedCostingSheetsTitle.Visible = true;
                    lblCombinedCostingSheetsTotalRows.Visible = true;
                    btnOpenCombinedCostingSheet.Visible = true;
                    btnEditCombinedCostingSheet.Visible = true;
                    btnDeleteCombinedCostingSheet.Visible = true;
                    pnlHorizontalRuleCombinedCostingSheet.Visible = true;
                    ddlActionCombinedCostingSheet.Visible = true;
                }
                else
                {
                    lblCombinedCostingSheetsTotalRows.Visible = false;
                    lblCombinedCostingSheetsTitle.Visible = false;
                    lblCombinedCostingSheetsTotalRows.Visible = false;
                    btnOpenCombinedCostingSheet.Visible = false;
                    btnEditCombinedCostingSheet.Visible = false;
                    btnDeleteCombinedCostingSheet.Visible = false;
                    pnlHorizontalRuleCombinedCostingSheet.Visible = false;
                    ddlActionCombinedCostingSheet.Visible = false;
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_PROJECTS_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["project_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_delete.aspx");
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfProjectId.Value = Request.QueryString["project_id"];

                // If coming from project_summary.aspx or projects2.aspx
                if (((string)Request.QueryString["source_page"] == "project_summary.aspx") || ((string)Request.QueryString["source_page"] == "projects2.aspx"))
                {
                    // Store Navigator State and Update control
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    // Get project record
                    projectTDS = new ProjectTDS();
                    ProjectGateway projectGatewayForLoad = new ProjectGateway(projectTDS);
                    projectGatewayForLoad.LoadByProjectId(int.Parse(hdfProjectId.Value));

                    // Store datasets
                    Session["lfsProjectTDS"] = projectTDS;
                }

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

                // Prepare initial data

                // ... for project
                int currentProjectId = Int32.Parse(hdfProjectId.Value.ToString());
                ProjectGateway projectGateway = new ProjectGateway();
                projectGateway.LoadByProjectId(currentProjectId);
                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()));
                int companyId = Int32.Parse(hdfCompanyId.Value);
                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(currentClientId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId);
            }
            else
            {
                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
            }
        }
        private void InsertProjectService(int originalProjectId)
        {
            // ... Data for current project
            ProjectTDS projectTDSTemp = new ProjectTDS();
            ProjectServiceGateway projectServiceGatewayTemp = new ProjectServiceGateway(projectTDSTemp);
            projectServiceGatewayTemp.LoadAllByProjectId(originalProjectId);

            ProjectServiceGateway projectServiceGateway = new ProjectServiceGateway(projectTDS);
            projectServiceGateway.LoadAllByProjectId(originalProjectId);

            // ... Definition of general variables
            int refId;
            int? serviceId = null;
            string description;
            string averageSize;
            decimal? averagePrice = null;
            int quantity;
            bool deleted;
            decimal total;

            foreach (ProjectTDS.LFS_PROJECT_SERVICERow row in projectTDSTemp.Tables["LFS_PROJECT_SERVICE"].Rows)
            {
                refId = row.RefID;
                try { serviceId = row.ServiceID; }
                catch { serviceId = null; }
                try { description = row.Description; }
                catch { description = ""; }
                try { averageSize = row.AverageSize; }
                catch { averageSize = ""; }
                try { averagePrice = row.AveragePrice; }
                catch { averagePrice = null; }
                quantity = row.Quantity;
                deleted = row.Deleted;
                try { total = row.AveragePrice * row.Quantity; }
                catch { total = 0; }

                // ... Insert Service
                ProjectService projectService = new ProjectService(projectTDS);
                projectService.Insert(0, refId, serviceId, description, averageSize, averagePrice, quantity, deleted, total, Int32.Parse(hdfCompanyId.Value.Trim()));
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_PROJECTS_VIEW"]) && Convert.ToBoolean(Session["sgLFS_PROJECTS_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["project_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in project_edit.aspx");
                }

                // Tag page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfProjectId.Value = Request.QueryString["project_id"];
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfDataChanged.Value = Request.QueryString["data_changed"];
                hdfDataChangedMessage.Value = "Changes made to this project will not be saved.";

                // Prepare initial data
                Session.Remove("projectNotesDummy");
                Session.Remove("projectServicesDummy");
                Session.Remove("projectTypeOfWorkFunctionClassificationDummy");
                Session.Remove("projectJobClassClassificationDummy");
                Session.Remove("projectBudgetDummy");
                Session.Remove("subcontractorsBudgetDummy");
                Session.Remove("hotelsBudgetDummy");
                Session.Remove("bondingsBudgetDummy");
                Session.Remove("insurancesBudgetDummy");
                Session.Remove("otherCostsBudgetDummy");

                Session["fairWage"] = "None";

                // ... Set initial tab
                if ((string)Session["dialogOpenedProjects"] != "1")
                {
                    hdfActiveTab.Value = Request.QueryString["active_tab"];
                }
                else
                {
                    hdfActiveTab.Value = (string)Session["activeTabProjects"];
                }

                // ... For Library
                if (Session["lfsLibraryTDS"] != null)
                {
                    libraryTDS = (LibraryTDS)Session["lfsLibraryTDS"];
                }
                else
                {
                    libraryTDS = new LibraryTDS();
                }

                // If coming from
                // ... projects2.aspx or project_add.aspx
                if (Request.QueryString["source_page"] == "projects2.aspx" || Request.QueryString["source_page"] == "project_add.aspx")
                {
                    // Store Navigator State, Update control and Origin
                    StoreNavigatorState();
                    ViewState["update"] = "no";
                    ViewState["origin"] = "navigator";

                    // Get Project Id
                    int projectId = int.Parse(hdfProjectId.Value);

                    // ... Attachment control
                    if (Session["fromAttachment"] != null)
                    {
                        if (Session["fromAttachment"].ToString() == "yes")
                        {
                            // Restore dataset
                            projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                            projectNavigatorTDS = (ProjectNavigatorTDS)Session["projectNavigatorTDS"];
                            projectNotes = (ProjectNavigatorTDS.ProjectNotesDataTable)Session["projectNotes"];
                            projectServices = (ProjectNavigatorTDS.ProjectServiceDataTable)Session["projectServices"];
                            projectJobClassClassification = (ProjectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATEDataTable)Session["projectJobClassClassification"];
                            projectTypeOfWorkFunctionClassification = (ProjectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGEDataTable)Session["projectTypeOfWorkFunctionClassification"];
                            projectBudget = (ProjectNavigatorTDS.ProjectWorkFunctionBudgetDataTable)Session["projectBudget"];
                            unitsBudget = (ProjectNavigatorTDS.ProjectUnitsBudgetDataTable)Session["unitsBudget"];
                            materialsBudget = (ProjectNavigatorTDS.ProjectMaterialsBudgetDataTable)Session["materialsBudget"];
                            subcontractorsBudget = (ProjectNavigatorTDS.ProjectSubcontractorsBudgetDataTable)Session["subcontractorsBudget"];
                            hotelsBudget = (ProjectNavigatorTDS.ProjectHotelsBudgetDataTable)Session["hotelsBudget"];
                            bondingsBudget = (ProjectNavigatorTDS.ProjectBondingsBudgetDataTable)Session["bondingsBudget"];
                            insurancesBudget = (ProjectNavigatorTDS.ProjectInsurancesBudgetDataTable)Session["insurancesBudget"];
                            otherCostsBudget = (ProjectNavigatorTDS.ProjectOtherCostsBudgetDataTable)Session["otherCostsBudget"];
                        }

                        Session.Remove("fromAttachment");
                    }
                    else
                    {
                        // Get dataset
                        projectTDS = new ProjectTDS();
                        projectNavigatorTDS = new ProjectNavigatorTDS();
                        projectNotes = new ProjectNavigatorTDS.ProjectNotesDataTable();
                        projectServices = new ProjectNavigatorTDS.ProjectServiceDataTable();
                        projectTypeOfWorkFunctionClassification = new ProjectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGEDataTable();
                        projectJobClassClassification = new ProjectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATEDataTable();
                        projectBudget = new ProjectNavigatorTDS.ProjectWorkFunctionBudgetDataTable();
                        unitsBudget = new ProjectNavigatorTDS.ProjectUnitsBudgetDataTable();
                        materialsBudget = new ProjectNavigatorTDS.ProjectMaterialsBudgetDataTable();
                        subcontractorsBudget = new ProjectNavigatorTDS.ProjectSubcontractorsBudgetDataTable();
                        hotelsBudget = new ProjectNavigatorTDS.ProjectHotelsBudgetDataTable();
                        bondingsBudget = new ProjectNavigatorTDS.ProjectBondingsBudgetDataTable();
                        insurancesBudget = new ProjectNavigatorTDS.ProjectInsurancesBudgetDataTable();
                        otherCostsBudget = new ProjectNavigatorTDS.ProjectOtherCostsBudgetDataTable();

                        // Get General Data
                        ProjectGateway projectGatewayForLoad = new ProjectGateway(projectTDS);
                        projectGatewayForLoad.LoadByProjectId(projectId);

                        // Get job info
                        ProjectJobInfoGateway projectJobInfoGateway = new ProjectJobInfoGateway(projectNavigatorTDS);
                        projectJobInfoGateway.LoadAllByProjectId(projectId);

                        // Get Sale/Billing/Pricing
                        ProjectSaleBillingPricingGateway projectSaleBillingPricingGatewayForLoad = new ProjectSaleBillingPricingGateway(projectTDS);
                        projectSaleBillingPricingGatewayForLoad.LoadAllByProjectId(projectId);

                        // ... Get Sale/Billing/Pricing - Services
                        ProjectNavigatorProjectService projectNavigatorProjectService = new ProjectNavigatorProjectService(projectNavigatorTDS);
                        projectNavigatorProjectService.LoadAllByProjectId(projectId);
                        projectNavigatorProjectService.UpdateForLoad();

                        // Get Costing Updates
                        ProjectCostingUpdatesGateway projectCostingUpdatesGatewayForLoad = new ProjectCostingUpdatesGateway(projectTDS);
                        projectCostingUpdatesGatewayForLoad.LoadByProjectId(projectId);

                        // Get Project Terms
                        ProjectTermsPOGateway projectTermsPOGatewayForLoad = new ProjectTermsPOGateway(projectTDS);
                        projectTermsPOGatewayForLoad.LoadByProjectId(projectId);

                        // Get Technical
                        ProjectTechnicalGateway projectTechnicalGatewayForLoad = new ProjectTechnicalGateway(projectTDS);
                        projectTechnicalGatewayForLoad.LoadByProjectId(projectId);

                        // Get Engineer Subcontractors
                        ProjectEngineerSubcontractorsGateway projectEngineerSubcontractorsGatewayForLoad = new ProjectEngineerSubcontractorsGateway(projectTDS);
                        projectEngineerSubcontractorsGatewayForLoad.LoadAllByProjectId(projectId);

                        // ... Get Subcontractors
                        ProjectSubcontractorGateway projectSubcontractorGatewayForLoad = new ProjectSubcontractorGateway(projectTDS);
                        projectSubcontractorGatewayForLoad.LoadAllByProjectId(projectId);

                        // Cost Exceptions
                        // ... Get Type Of Work & Function Classification
                        ProjectNavigatorProjectWorkFunctionFairWage projectNavigatorProjectWorkFunctionFairWage = new ProjectNavigatorProjectWorkFunctionFairWage(projectNavigatorTDS);
                        projectNavigatorProjectWorkFunctionFairWage.LoadAllByProjectId(projectId);

                        // ... Get Job Class Classification
                        ProjectNavigatorProjectJobClassTypeRate projectNavigatorProjectJobClassTypeRate = new ProjectNavigatorProjectJobClassTypeRate(projectNavigatorTDS);
                        projectNavigatorProjectJobClassTypeRate.LoadAllByProjectId(projectId);

                        // Get Budget
                        ProjectNavigatorProjectWorkFunctionBudget projectNavigatorProjectWorkFunctionBudget = new ProjectNavigatorProjectWorkFunctionBudget(projectNavigatorTDS);
                        projectNavigatorProjectWorkFunctionBudget.LoadAllByProjectId(projectId);

                        // Get Units Budget
                        ProjectNavigatorProjectUnitsBudget projectNavigatorProjectUnitsBudget = new ProjectNavigatorProjectUnitsBudget(projectNavigatorTDS);
                        projectNavigatorProjectUnitsBudget.LoadAllByProjectId(projectId);

                        // Get Materials Budget
                        ProjectNavigatorProjectMaterialsBudget projectNavigatorProjectMaterialsBudget = new ProjectNavigatorProjectMaterialsBudget(projectNavigatorTDS);
                        projectNavigatorProjectMaterialsBudget.LoadAllByProjectId(projectId);

                        // Get Subcontractors Budget
                        ProjectNavigatorProjectSubcontractorsBudget projectNavigatorProjectSubcontractorsBudget = new ProjectNavigatorProjectSubcontractorsBudget(projectNavigatorTDS);
                        projectNavigatorProjectSubcontractorsBudget.LoadAllByProjectId(projectId);

                        // Get Hotels Budget
                        ProjectNavigatorProjectHotelsBudget projectNavigatorProjectHotelsBudget = new ProjectNavigatorProjectHotelsBudget(projectNavigatorTDS);
                        projectNavigatorProjectHotelsBudget.LoadAllByProjectId(projectId);

                        // Get Bondings Budget
                        ProjectNavigatorProjectBondingsBudget projectNavigatorProjectBondingsBudget = new ProjectNavigatorProjectBondingsBudget(projectNavigatorTDS);
                        projectNavigatorProjectBondingsBudget.LoadAllByProjectId(projectId);

                        // Get Insurances Budget
                        ProjectNavigatorProjectInsurancesBudget projectNavigatorProjectInsurancesBudget = new ProjectNavigatorProjectInsurancesBudget(projectNavigatorTDS);
                        projectNavigatorProjectInsurancesBudget.LoadAllByProjectId(projectId);

                        // Get Other Costs Budget
                        ProjectNavigatorProjectOtherCostsBudget projectNavigatorProjectOtherCostsBudget = new ProjectNavigatorProjectOtherCostsBudget(projectNavigatorTDS);
                        projectNavigatorProjectOtherCostsBudget.LoadAllByProjectId(projectId);

                        // Get Notes
                        ProjectNavigatorProjectNotes projectNavigatorProjectNotes = new ProjectNavigatorProjectNotes(projectNavigatorTDS);
                        projectNavigatorProjectNotes.LoadAllByProjectId(projectId);

                        // Store dataset
                        Session["lfsProjectTDS"] = projectTDS;
                        Session["projectNavigatorTDS"] = projectNavigatorTDS;
                        Session["projectNotes"] = projectNavigatorTDS.ProjectNotes;
                        Session["projectServices"] = projectNavigatorTDS.ProjectService;
                        Session["projectTypeOfWorkFunctionClassification"] = projectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGE;
                        Session["projectJobClassClassification"] = projectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATE;
                        Session["projectBudget"] = projectNavigatorTDS.ProjectWorkFunctionBudget;
                        Session["unitsBudget"] = projectNavigatorTDS.ProjectUnitsBudget;
                        Session["materialsBudget"] = projectNavigatorTDS.ProjectMaterialsBudget;
                        Session["subcontractorsBudget"] = projectNavigatorTDS.ProjectSubcontractorsBudget;
                        Session["hotelsBudget"] = projectNavigatorTDS.ProjectHotelsBudget;
                        Session["bondingsBudget"] = projectNavigatorTDS.ProjectBondingsBudget;
                        Session["insurancesBudget"] = projectNavigatorTDS.ProjectInsurancesBudget;
                        Session["otherCostsBudget"] = projectNavigatorTDS.ProjectOtherCostsBudget;
                    }

                    //grdNotes.DataBind();
                    //grdServices.DataBind();
                    grdTypeOfWorkFunctionClassification.DataBind();
                    grdJobClassClassification.DataBind();
                    grdBudget.DataBind();
                    /*grdSubcontractorsBudget.DataBind();
                    grdHotelsBudget.DataBind();
                    grdBondingsBudget.DataBind();
                    grdInsurancesBudget.DataBind();*/
                    grdOtherCostsBudget.DataBind();
                }

                // ... project_summary.aspx or project_edit.aspx
                if ((Request.QueryString["source_page"] == "project_summary.aspx") || (Request.QueryString["source_page"] == "project_edit.aspx") || (Request.QueryString["source_page"] == "lm"))
                {
                    // Store Navigator State, update control and origin
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];
                    ViewState["origin"] = Request.QueryString["origin"]; //summary

                    // Restore dataset
                    projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                    projectNavigatorTDS = (ProjectNavigatorTDS)Session["projectNavigatorTDS"];
                    projectNotes = (ProjectNavigatorTDS.ProjectNotesDataTable)Session["projectNotes"];
                    projectServices = (ProjectNavigatorTDS.ProjectServiceDataTable)Session["projectServices"];
                    projectJobClassClassification = (ProjectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATEDataTable)Session["projectJobClassClassification"];
                    projectTypeOfWorkFunctionClassification = (ProjectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGEDataTable)Session["projectTypeOfWorkFunctionClassification"];
                    projectBudget = (ProjectNavigatorTDS.ProjectWorkFunctionBudgetDataTable)Session["projectBudget"];
                    unitsBudget = (ProjectNavigatorTDS.ProjectUnitsBudgetDataTable)Session["unitsBudget"];
                    materialsBudget = (ProjectNavigatorTDS.ProjectMaterialsBudgetDataTable)Session["materialsBudget"];
                    subcontractorsBudget = (ProjectNavigatorTDS.ProjectSubcontractorsBudgetDataTable)Session["subcontractorsBudget"];
                    hotelsBudget = (ProjectNavigatorTDS.ProjectHotelsBudgetDataTable)Session["hotelsBudget"];
                    bondingsBudget = (ProjectNavigatorTDS.ProjectBondingsBudgetDataTable)Session["bondingsBudget"];
                    insurancesBudget = (ProjectNavigatorTDS.ProjectInsurancesBudgetDataTable)Session["insurancesBudget"];
                    otherCostsBudget = (ProjectNavigatorTDS.ProjectOtherCostsBudgetDataTable)Session["otherCostsBudget"];

                    // Get Project Id
                    int projectId = int.Parse(hdfProjectId.Value);

                    if (ViewState["update"].ToString().Trim() == "yes")
                    {
                        // Get General Data
                        ProjectGateway projectGatewayForLoad = new ProjectGateway(projectTDS);
                        projectGatewayForLoad.LoadByProjectId(projectId);

                        // Get job info
                        ProjectJobInfoGateway projectJobInfoGateway = new ProjectJobInfoGateway(projectNavigatorTDS);
                        projectJobInfoGateway.LoadAllByProjectId(projectId);

                        // Get Sale/Billing/Pricing
                        ProjectSaleBillingPricingGateway projectSaleBillingPricingGatewayForLoad = new ProjectSaleBillingPricingGateway(projectTDS);
                        projectSaleBillingPricingGatewayForLoad.LoadAllByProjectId(projectId);

                        // ... Get Sale/Billing/Pricing - Services
                        ProjectNavigatorProjectService projectNavigatorProjectService = new ProjectNavigatorProjectService(projectNavigatorTDS);
                        projectNavigatorProjectService.LoadAllByProjectId(projectId);
                        projectNavigatorProjectService.UpdateForLoad();

                        // Get Costing Updates
                        ProjectCostingUpdatesGateway projectCostingUpdatesGatewayForLoad = new ProjectCostingUpdatesGateway(projectTDS);
                        projectCostingUpdatesGatewayForLoad.LoadByProjectId(projectId);

                        // Get Project Terms
                        ProjectTermsPOGateway projectTermsPOGatewayForLoad = new ProjectTermsPOGateway(projectTDS);
                        projectTermsPOGatewayForLoad.LoadByProjectId(projectId);

                        // Get Technical
                        ProjectTechnicalGateway projectTechnicalGatewayForLoad = new ProjectTechnicalGateway(projectTDS);
                        projectTechnicalGatewayForLoad.LoadByProjectId(projectId);

                        // Get Engineer Subcontractors
                        ProjectEngineerSubcontractorsGateway projectEngineerSubcontractorsGatewayForLoad = new ProjectEngineerSubcontractorsGateway(projectTDS);
                        projectEngineerSubcontractorsGatewayForLoad.LoadAllByProjectId(projectId);

                        // ... Get Subcontractors
                        ProjectSubcontractorGateway projectSubcontractorGatewayForLoad = new ProjectSubcontractorGateway(projectTDS);
                        projectSubcontractorGatewayForLoad.LoadAllByProjectId(projectId);

                        // Cost Exceptions
                        // ... Get Type Of Work & Function Classification
                        ProjectNavigatorProjectWorkFunctionFairWage projectNavigatorProjectWorkFunctionFairWage = new ProjectNavigatorProjectWorkFunctionFairWage(projectNavigatorTDS);
                        projectNavigatorProjectWorkFunctionFairWage.LoadAllByProjectId(projectId);

                        // ... Get Job Class Classification
                        ProjectNavigatorProjectJobClassTypeRate projectNavigatorProjectJobClassTypeRate = new ProjectNavigatorProjectJobClassTypeRate(projectNavigatorTDS);
                        projectNavigatorProjectJobClassTypeRate.LoadAllByProjectId(projectId);

                        // Get Budget
                        ProjectNavigatorProjectWorkFunctionBudget projectNavigatorProjectWorkFunctionBudget = new ProjectNavigatorProjectWorkFunctionBudget(projectNavigatorTDS);
                        projectNavigatorProjectWorkFunctionBudget.LoadAllByProjectId(projectId);

                        // Get Units Budget
                        ProjectNavigatorProjectUnitsBudget projectNavigatorProjectUnitsBudget = new ProjectNavigatorProjectUnitsBudget(projectNavigatorTDS);
                        projectNavigatorProjectUnitsBudget.LoadAllByProjectId(projectId);

                        // Get Materials Budget
                        ProjectNavigatorProjectMaterialsBudget projectNavigatorProjectMaterialsBudget = new ProjectNavigatorProjectMaterialsBudget(projectNavigatorTDS);
                        projectNavigatorProjectMaterialsBudget.LoadAllByProjectId(projectId);

                        // Get Subcontractors Budget
                        ProjectNavigatorProjectSubcontractorsBudget projectNavigatorProjectSubcontractorsBudget = new ProjectNavigatorProjectSubcontractorsBudget(projectNavigatorTDS);
                        projectNavigatorProjectSubcontractorsBudget.LoadAllByProjectId(projectId);

                        // Get Hotels Budget
                        ProjectNavigatorProjectHotelsBudget projectNavigatorProjectHotelsBudget = new ProjectNavigatorProjectHotelsBudget(projectNavigatorTDS);
                        projectNavigatorProjectHotelsBudget.LoadAllByProjectId(projectId);

                        // Get Bondings Budget
                        ProjectNavigatorProjectBondingsBudget projectNavigatorProjectBondingsBudget = new ProjectNavigatorProjectBondingsBudget(projectNavigatorTDS);
                        projectNavigatorProjectBondingsBudget.LoadAllByProjectId(projectId);

                        // Get Insurances Budget
                        ProjectNavigatorProjectInsurancesBudget projectNavigatorProjectInsurancesBudget = new ProjectNavigatorProjectInsurancesBudget(projectNavigatorTDS);
                        projectNavigatorProjectInsurancesBudget.LoadAllByProjectId(projectId);

                        // Get Other Costs Budget
                        ProjectNavigatorProjectOtherCostsBudget projectNavigatorProjectOtherCostsBudget = new ProjectNavigatorProjectOtherCostsBudget(projectNavigatorTDS);
                        projectNavigatorProjectOtherCostsBudget.LoadAllByProjectId(projectId);

                        // Get Notes
                        ProjectNavigatorProjectNotes projectNavigatorProjectNotes = new ProjectNavigatorProjectNotes(projectNavigatorTDS);
                        projectNavigatorProjectNotes.LoadAllByProjectId(projectId);

                        //grdNotes.DataBind();
                        //grdServices.DataBind();
                        grdTypeOfWorkFunctionClassification.DataBind();
                        grdJobClassClassification.DataBind();
                        grdBudget.DataBind();
                        /*grdSubcontractorsBudget.DataBind();
                        grdHotelsBudget.DataBind();
                        grdBondingsBudget.DataBind();
                        grdInsurancesBudget.DataBind();*/
                        grdOtherCostsBudget.DataBind();

                        // Store dataset
                        Session["lfsProjectTDS"] = projectTDS;
                        Session["projectNavigatorTDS"] = projectNavigatorTDS;
                        Session["projectNotes"] = projectNavigatorTDS.ProjectNotes;
                        Session["projectServices"] = projectNavigatorTDS.ProjectService;
                        Session["projectTypeOfWorkFunctionClassification"] = projectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGE;
                        Session["projectJobClassClassification"] = projectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATE;
                        Session["projectBudget"] = projectNavigatorTDS.ProjectWorkFunctionBudget;
                        Session["unitsBudget"] = projectNavigatorTDS.ProjectUnitsBudget;
                        Session["materialsBudget"] = projectNavigatorTDS.ProjectMaterialsBudget;
                        Session["subcontractorsBudget"] = projectNavigatorTDS.ProjectSubcontractorsBudget;
                        Session["hotelsBudget"] = projectNavigatorTDS.ProjectHotelsBudget;
                        Session["bondingsBudget"] = projectNavigatorTDS.ProjectBondingsBudget;
                        Session["insurancesBudget"] = projectNavigatorTDS.ProjectInsurancesBudget;
                        Session["otherCostsBudget"] = projectNavigatorTDS.ProjectOtherCostsBudget;
                    }
                }

                // Data for current project
                ProjectGateway projectGateway = new ProjectGateway(projectTDS);

                // ... 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 companyId = Int32.Parse(hdfCompanyId.Value);
                int currentClientId = projectGateway.GetClientID(Int32.Parse(hdfProjectId.Value.ToString()));
                CompaniesGateway companiesGateway = new CompaniesGateway();
                companiesGateway.LoadAllByCompaniesId(currentClientId, companyId);
                lblTitleClientName.Text = "Client: " + companiesGateway.GetName(currentClientId);

                // Load Data
                LoadData();

                // Store Dataset
                Session["lfsProjectTDS"] = projectTDS;

                //// ... For total cost at services
                //ProjectNavigatorProjectService projectNavigatorProjectServiceForCost = new ProjectNavigatorProjectService(projectNavigatorTDS);
                //tbxTotalCost.Text = Decimal.Round(projectNavigatorProjectServiceForCost.GetTotalCost(), 2).ToString();
            }
            else
            {
                // Restore dataset
                projectTDS = (ProjectTDS)Session["lfsProjectTDS"];
                projectNavigatorTDS = (ProjectNavigatorTDS)Session["projectNavigatorTDS"];
                projectNotes = (ProjectNavigatorTDS.ProjectNotesDataTable)Session["projectNotes"];
                projectServices = (ProjectNavigatorTDS.ProjectServiceDataTable)Session["projectServices"];
                projectJobClassClassification = (ProjectNavigatorTDS.LFS_PROJECT_JOB_CLASS_TYPE_RATEDataTable)Session["projectJobClassClassification"];
                projectTypeOfWorkFunctionClassification = (ProjectNavigatorTDS.LFS_PROJECT_WORK_FUNCTION_FAIR_WAGEDataTable)Session["projectTypeOfWorkFunctionClassification"];
                projectBudget = (ProjectNavigatorTDS.ProjectWorkFunctionBudgetDataTable)Session["projectBudget"];
                unitsBudget = (ProjectNavigatorTDS.ProjectUnitsBudgetDataTable)Session["unitsBudget"];
                materialsBudget = (ProjectNavigatorTDS.ProjectMaterialsBudgetDataTable)Session["materialsBudget"];
                subcontractorsBudget = (ProjectNavigatorTDS.ProjectSubcontractorsBudgetDataTable)Session["subcontractorsBudget"];
                hotelsBudget = (ProjectNavigatorTDS.ProjectHotelsBudgetDataTable)Session["hotelsBudget"];
                bondingsBudget = (ProjectNavigatorTDS.ProjectBondingsBudgetDataTable)Session["bondingsBudget"];
                insurancesBudget = (ProjectNavigatorTDS.ProjectInsurancesBudgetDataTable)Session["insurancesBudget"];
                otherCostsBudget = (ProjectNavigatorTDS.ProjectOtherCostsBudgetDataTable)Session["otherCostsBudget"];

                tbxProjectNumber.DataBind();

                if (Session["lfsLibraryTDS"] != null)
                {
                    libraryTDS = (LibraryTDS)Session["lfsLibraryTDS"];
                }
                else
                {
                    libraryTDS = new LibraryTDS();
                }
            }
        }
        private void InsertProjectSubcontractor(int originalProjectId)
        {
            // ... Data for current project
            ProjectTDS projectTDSTemp = new ProjectTDS();
            ProjectSubcontractorGateway projectSubcontractorGatewayTemp = new ProjectSubcontractorGateway(projectTDSTemp);
            projectSubcontractorGatewayTemp.LoadAllByProjectId(originalProjectId);

            ProjectSubcontractorGateway projectSubcontractorGateway = new ProjectSubcontractorGateway(projectTDS);
            projectSubcontractorGateway.LoadAllByProjectId(originalProjectId);

            // ... Definition of general variables
            ProjectSubcontractor projectSubcontractor = new ProjectSubcontractor(projectTDS);

            int refId;
            int subcontractorId;
            bool writtenQuote;
            bool surveyedSite;
            bool workedBefore;
            string role;
            bool agreement;
            string issues;
            bool purchaseOrder;
            bool insuranceCertificate;
            bool wsib;
            string molForm1000;
            bool deleted;
            int? royalties;

            foreach (ProjectTDS.LFS_PROJECT_SUBCONTRACTORRow row in projectTDSTemp.Tables["LFS_PROJECT_SUBCONTRACTOR"].Rows)
            {
                refId = row.RefID;
                subcontractorId = row.SubcontractorID;
                writtenQuote = row.WrittenQuote;
                surveyedSite = row.SurveyedSite;
                workedBefore = row.WorkedBefore;
                try { role = row.Role; }
                catch { role = ""; }
                agreement = row.Agreement;
                try { issues = row.Issues; }
                catch { issues = ""; }
                purchaseOrder = row.PurchaseOrder;
                insuranceCertificate = row.InsuranceCertificate;
                wsib = row.WSIB;
                try { molForm1000 = row.MOLForm1000; }
                catch { molForm1000 = ""; }
                deleted = row.Deleted;
                try {royalties = row.Royalties;}
                catch { royalties = null; }

                // ... Insert Subcontractors
                projectSubcontractor.Insert(0, refId, subcontractorId, writtenQuote, surveyedSite, workedBefore, role, agreement, issues, purchaseOrder, insuranceCertificate, wsib, molForm1000, deleted, Int32.Parse(hdfCompanyId.Value.Trim()), royalties);
            }
        }
 /// <summary>
 /// InitData
 /// </summary>
 protected override void InitData()
 {
     _data = new ProjectTDS();
 }
        private void PostPageChanges()
        {
            // Definition of general variables
            Int64 countryId = Int64.Parse(ddlCountry.SelectedValue);
            int officeId = int.Parse(ddlOffice.SelectedValue);
            Int64 provinceId = Int64.Parse(ddlProvince.SelectedValue);
            Int64 cityId = Int64.Parse(ddlCity.SelectedValue);
            Int64 countyId = Int64.Parse(ddlCounty.SelectedValue);
            int? projectLeadId = null; if ((ddlProjectLead.SelectedValue != "-1") && (ddlProjectLead.SelectedIndex > -1)) projectLeadId = int.Parse(ddlProjectLead.SelectedValue);
            int salesmanId = int.Parse(ddlSalesman.SelectedValue);
            bool deleted = false;
            int? clientPrimaryContactID = null;
            int? clientSecondaryContactID = null;

            projectTDS = new ProjectTDS();
            Project project = new Project(projectTDS);
            ProjectHistory projectHistory = new ProjectHistory(projectTDS);
            string projectNumber = project.GenerateProjectNumber(countryId, officeId, salesmanId, DateTime.Now, Int32.Parse(hdfCompanyId.Value.Trim()));

            // Insert Ballpark
            if (rbtnBallpark.Checked)
            {
                // ... Definition of variables
                string type = "Ballpark";
                string state = "Active";
                string ballparkProjectName = tbxBallparkProjectName.Text.Trim();
                string ballparkProjectDescription = tbxBallparkProjectDescription.Text.Trim();
                int ballparkProjectClientId = int.Parse(ddlBallparkProjectClient.SelectedValue);
                DateTime? ballparkProjectDate = null; if (tkrdpBallparkProjectDate.SelectedDate.HasValue) ballparkProjectDate = DateTime.Parse(tkrdpBallparkProjectDate.SelectedDate.Value.Month.ToString() + '/' + tkrdpBallparkProjectDate.SelectedDate.Value.Day.ToString() + '/' + tkrdpBallparkProjectDate.SelectedDate.Value.Year.ToString());
                DateTime? ballparkProjectStartDate = null; if (tkrdpBallparkProjectPotentialStartDate.SelectedDate.HasValue) ballparkProjectStartDate = DateTime.Parse(tkrdpBallparkProjectPotentialStartDate.SelectedDate.Value.Month.ToString() + '/' + tkrdpBallparkProjectPotentialStartDate.SelectedDate.Value.Day.ToString() + '/' + tkrdpBallparkProjectPotentialStartDate.SelectedDate.Value.Year.ToString());
                DateTime? ballparkProjectEndDate = null; if (tkrdpBallparkProjectPotentialEndDate.SelectedDate.HasValue) ballparkProjectEndDate = DateTime.Parse(tkrdpBallparkProjectPotentialEndDate.SelectedDate.Value.Month.ToString() + '/' + tkrdpBallparkProjectPotentialEndDate.SelectedDate.Value.Day.ToString() + '/' + tkrdpBallparkProjectPotentialEndDate.SelectedDate.Value.Year.ToString());

                // ... Insert
                project.Insert(countryId, officeId, projectLeadId, salesmanId, projectNumber, type, state, ballparkProjectName, ballparkProjectDescription, ballparkProjectDate, ballparkProjectStartDate, ballparkProjectEndDate, ballparkProjectClientId, clientPrimaryContactID, clientSecondaryContactID, "", deleted, null, null, null, provinceId, cityId, Int32.Parse(hdfCompanyId.Value.Trim()), countyId, false);
                projectHistory.Insert(0, 1, state, DateTime.Now, Convert.ToInt32(Session["loginID"]), Int32.Parse(hdfCompanyId.Value.Trim()));
            }

            // ... Insert Proposal
            if (rbtnProposal.Checked)
            {
                // ... Definition of variables
                string type = "Proposal";
                string state = "Bidding";
                string proposalName = tbxProposalName.Text.Trim();
                string proposalDescription = tbxProposalDescription.Text.Trim();
                int proposalClientId = int.Parse(ddlProposalClient.SelectedValue);
                string clientProposalNumber = tbxClientProposalNumber.Text.Trim();
                DateTime? proposalDate = null; if (tkrdpProposalDate.SelectedDate.HasValue) proposalDate = DateTime.Parse(tkrdpProposalDate.SelectedDate.Value.Month.ToString() + '/' + tkrdpProposalDate.SelectedDate.Value.Day.ToString() + '/' + tkrdpProposalDate.SelectedDate.Value.Year.ToString());
                DateTime? proposalStartDate = null; if (tkrdpProposalPotencialStartDate.SelectedDate.HasValue) proposalStartDate = DateTime.Parse(tkrdpProposalPotencialStartDate.SelectedDate.Value.Month.ToString() + '/' + tkrdpProposalPotencialStartDate.SelectedDate.Value.Day.ToString() + '/' + tkrdpProposalPotencialStartDate.SelectedDate.Value.Year.ToString());
                DateTime? proposalEndDate = null; if (tkrdpProposalPotencialEndDate.SelectedDate.HasValue) proposalEndDate = DateTime.Parse(tkrdpProposalPotencialEndDate.SelectedDate.Value.Month.ToString() + '/' + tkrdpProposalPotencialEndDate.SelectedDate.Value.Day.ToString() + '/' + tkrdpProposalPotencialEndDate.SelectedDate.Value.Year.ToString());

                // ... Insert
                project.Insert(countryId, officeId, projectLeadId, salesmanId, projectNumber, type, state, proposalName, proposalDescription, proposalDate, proposalStartDate, proposalEndDate, proposalClientId, clientPrimaryContactID, clientSecondaryContactID, clientProposalNumber, deleted, null, null, null, provinceId, cityId, Int32.Parse(hdfCompanyId.Value.Trim()), countyId, false);
                projectHistory.Insert(0, 1, state, DateTime.Now, Convert.ToInt32(Session["loginID"]), Int32.Parse(hdfCompanyId.Value.Trim()));
            }

            // ... Insert Internal Project
            if (rbtnInternalProject.Checked)
            {
                // ... Definition of variables
                string type = "Internal";
                string state = "Active";
                string internalProjectName = tbxInternalProjectName.Text.Trim();
                string internalProjectDescription = tbxInternalProjectDescription.Text.Trim();
                int internalProjectClientId = int.Parse(ddlInternalProjectClient.SelectedValue);
                DateTime? internalProjectDate = null; if (tkrdpInternalProjectDate.SelectedDate.HasValue) internalProjectDate = DateTime.Parse(tkrdpInternalProjectDate.SelectedDate.Value.Month.ToString() + '/' + tkrdpInternalProjectDate.SelectedDate.Value.Day.ToString() + '/' + tkrdpInternalProjectDate.SelectedDate.Value.Year.ToString());

                // ... Insert
                project.Insert(countryId, officeId, projectLeadId, salesmanId, projectNumber, type, state, internalProjectName, internalProjectDescription, internalProjectDate, null, null, internalProjectClientId, clientPrimaryContactID, clientSecondaryContactID, "", deleted, null, null, null, provinceId, cityId, Int32.Parse(hdfCompanyId.Value.Trim()), countyId, false);
                projectHistory.Insert(0, 1, state, DateTime.Now, Convert.ToInt32(Session["loginID"]), Int32.Parse(hdfCompanyId.Value.Trim()));
            }
        }