// ////////////////////////////////////////////////////////////////////////
        //  METHODS
        //
        public FullLengthLiningTDS.CommentDetailsDataTable GetCommentsNew()
        {
            fullLengthLiningCommentDetails = (FullLengthLiningTDS.CommentDetailsDataTable)Session["fullLengthLiningCommentDetailsDummy"];
            if (fullLengthLiningCommentDetails == null)
            {
                fullLengthLiningCommentDetails = ((FullLengthLiningTDS.CommentDetailsDataTable)Session["fullLengthLiningCommentDetails"]);
            }

            return fullLengthLiningCommentDetails;
        }
        protected void AddCommentsNewEmptyFix(GridView grdComments)
        {
            if (grdComments.Rows.Count == 0)
            {
                int companyId = Int32.Parse(hdfCompanyId.Value);
                FullLengthLiningTDS.CommentDetailsDataTable dt = new FullLengthLiningTDS.CommentDetailsDataTable();
                dt.AddCommentDetailsRow(-1, -1, "", "", -1, DateTime.Now, "", -1, false, companyId, false, "", false, "");
                Session["fullLengthLiningCommentDetailsDummy"] = dt;

                grdComments.DataBind();
            }

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

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_CWP_FULLLENGTHLINING_VIEW"]) && Convert.ToBoolean(Session["sgLFS_CWP_FULLLENGTHLINING_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["client_id"] == null) || ((string)Request.QueryString["project_id"] == null) || ((string)Request.QueryString["work_id"] == null) || ((string)Request.QueryString["asset_id"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in fl_comments.aspx");
                }

                // Tag Page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
                hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfAdminPermission.Value = Convert.ToBoolean(Session["sgLFS_CWP_FULLLENGTHLINING_ADMIN"]).ToString();
                hdfWorkType.Value = "Full Length Lining";
                hdfWorkId.Value = Request.QueryString["work_id"].ToString();
                hdfAssetId.Value = Request.QueryString["asset_id"].ToString();
                hdfUpdate.Value = "yes";

                // ... Names for UserList
                string workType = hdfWorkType.Value.Trim();
                int companyId = Int32.Parse(hdfCompanyId.Value);

                LoginGateway loginGateway = new LoginGateway();
                loginGateway.LoadByLoginId(Convert.ToInt32(hdfLoginId.Value), companyId);
                hdfCreatedBy.Value = loginGateway.GetLastName(Convert.ToInt32(hdfLoginId.Value), companyId) + " " + loginGateway.GetFirstName(Convert.ToInt32(hdfLoginId.Value), companyId);

                // Prepare initial data
                Session.Remove("fullLengthLiningCommentDetailsDummy");

                // If coming from
                // ... flsummary.aspx and fl_edit.aspx
                if (Request.QueryString["source_page"] == "fl_summary.aspx" || Request.QueryString["source_page"] == "fl_edit.aspx")
                {
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    fullLengthLiningTDS = (FullLengthLiningTDS)Session["fullLengthLiningTDS"];

                    int assetId = Int32.Parse(hdfAssetId.Value.Trim());
                    int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
                    int flWorkId = Int32.Parse(hdfWorkId.Value.Trim());
                    int raWorkId = 0;

                    // ... If the project has fl works
                    if (flWorkId != 0)
                    {
                        WorkGateway workGateway = new WorkGateway();
                        workGateway.LoadByProjectIdAssetIdWorkType(currentProjectId, assetId, "Rehab Assessment", companyId);
                        if (workGateway.Table.Rows.Count > 0)
                        {
                            raWorkId = workGateway.GetWorkId(assetId, "Rehab Assessment", currentProjectId);
                        }

                        // ... update fl and ra comments
                        FullLengthLiningCommentDetailsGateway fullLengthLiningCommentDetailsGateway = new FullLengthLiningCommentDetailsGateway(fullLengthLiningTDS);
                        fullLengthLiningCommentDetailsGateway.LoadAllByFlWorkIdRaWorkId(flWorkId, raWorkId, companyId);

                        FullLengthLiningCommentDetails fullLengthLiningCommentDetailsForLoad = new FullLengthLiningCommentDetails(fullLengthLiningCommentDetailsGateway.Data);
                        fullLengthLiningCommentDetailsForLoad.UpdateForProcess();
                    }

                    // ... Store datasets
                    Session["fullLengthLiningTDS"] = fullLengthLiningTDS;
                    Session["fullLengthLiningCommentDetails"] = fullLengthLiningTDS.CommentDetails;
                }
            }
            else
            {
                // Restore datasets
                fullLengthLiningTDS = (FullLengthLiningTDS)Session["fullLengthLiningTDS"];
                fullLengthLiningCommentDetails = fullLengthLiningTDS.CommentDetails;

                // Store
                Session["fullLengthLiningCommentDetails"] = fullLengthLiningTDS.CommentDetails;
            }
        }