// ////////////////////////////////////////////////////////////////////////
        //  PUBLIC METHODS
        //
        public RehabAssessmentTDS.CommentDetailsDataTable GetCommentsNew()
        {
            rehabAssessmentCommentDetails = (RehabAssessmentTDS.CommentDetailsDataTable)Session["rehabAssessmentCommentDetailsDummy"];
            if (rehabAssessmentCommentDetails == null)
            {
                rehabAssessmentCommentDetails = ((RehabAssessmentTDS.CommentDetailsDataTable)Session["rehabAssessmentCommentDetails"]);
            }

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

                grdComments.DataBind();
            }

            // Normally executes at all postbacks
            if (grdComments.Rows.Count == 1)
            {
                RehabAssessmentTDS.CommentDetailsDataTable dt = (RehabAssessmentTDS.CommentDetailsDataTable)Session["rehabAssessmentCommentDetailsDummy"];
                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_REHABASSESSMENT_VIEW"]) && Convert.ToBoolean(Session["sgLFS_CWP_REHABASSESSMENT_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 ra_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_REHABASSESSMENT_ADMIN"]).ToString();
                hdfWorkType.Value = "Rehab Assessment";
                hdfWorkId.Value = Request.QueryString["work_id"].ToString();
                hdfAssetId.Value = Request.QueryString["asset_id"].ToString();
                hdfUpdate.Value = "yes";

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

                // ... 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);
                hdfCreationDateTime.Value = DateTime.Now.ToString();

                // If coming from
                // ... ra_summary.aspx or ra_edit.aspx
                if (Request.QueryString["source_page"] == "ra_summary.aspx" || Request.QueryString["source_page"] == "ra_edit.aspx")
                {
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];

                    // For RA
                    rehabAssessmentTDS = (RehabAssessmentTDS)Session["rehabAssessmentTDS"];

                    int assetId = Int32.Parse(hdfAssetId.Value.Trim());
                    int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.Trim());
                    int workId = Int32.Parse(hdfWorkId.Value.Trim());

                    if (workId != 0)
                    {
                        // ... update comments
                        RehabAssessmentCommentDetailsGateway rehabAssessmentCommentDetailsGateway = new RehabAssessmentCommentDetailsGateway(rehabAssessmentTDS);
                        rehabAssessmentCommentDetailsGateway.LoadAllByWorkIdWorkType(workId, companyId, workType);

                        RehabAssessmentCommentDetails rehabAssessmentCommentDetails = new RehabAssessmentCommentDetails(rehabAssessmentCommentDetailsGateway.Data);
                        rehabAssessmentCommentDetails.UpdateForProcess();
                    }

                    // For FLL
                    int workIdFll = GetWorkId(currentProjectId, assetId, "Full Length Lining", companyId);
                    hdfWorkIdFll.Value = workIdFll.ToString();

                    if (workIdFll != 0)
                    {
                        // ... update comments
                        FullLengthLiningCommentDetailsGateway fullLengthLiningCommentDetailsGateway = new FullLengthLiningCommentDetailsGateway();
                        fullLengthLiningCommentDetailsGateway.LoadAllByWorkIdWorkType(workIdFll, companyId, "Full Length Lining");

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

                    // ... Store datasets
                    Session["rehabAssessmentTDS"] = rehabAssessmentTDS;
                    Session["rehabAssessmentCommentDetails"] = rehabAssessmentTDS.CommentDetails;
                }
            }
            else
            {
                // Restore datasets
                rehabAssessmentTDS = (RehabAssessmentTDS)Session["rehabAssessmentTDS"];
                rehabAssessmentCommentDetails = rehabAssessmentTDS.CommentDetails;
            }
        }