/// <summary>
        /// Save all sections & works to database (direct)
        /// </summary>
        /// <param name="id">id</param>
        /// <param name="companyId">companyId</param>
        public void Save(Guid id, int companyId)
        {
            FlatSectionJlinerTDS jlinerChanges = (FlatSectionJlinerTDS)Data.GetChanges();

            if (jlinerChanges.JuntionLiner2Comment.Rows.Count > 0)
            {
                FlatSectionJlinerJuntionLiner2CommentGateway flatSectionJlinerJuntionLiner2CommentGateway = new FlatSectionJlinerJuntionLiner2CommentGateway(jlinerChanges);

                foreach (FlatSectionJlinerTDS.JuntionLiner2CommentRow row in (FlatSectionJlinerTDS.JuntionLiner2CommentDataTable)jlinerChanges.JuntionLiner2Comment)
                {
                    // Insert new comments
                    if ((!row.Deleted) && (!row.InDatabase))
                    {
                        JlinerComments jlinerComments = new JlinerComments(null);
                        jlinerComments.InsertDirect(row.ID, row.RefID, row.COMPANY_ID, row.CommentID, row.DateTime_, row.LoginID, row.Comment, row.Deleted);
                    }

                    // Update comments
                    if ((!row.Deleted) && (row.InDatabase))
                    {
                        int refId = row.RefID;
                        int commentId = row.CommentID;

                        // original values
                        int originalLoginId = flatSectionJlinerJuntionLiner2CommentGateway.GetLoginIDOriginal(id, refId, companyId, commentId);
                        DateTime? originalDateTime = null; if (flatSectionJlinerJuntionLiner2CommentGateway.GetDateTime_Original(id, refId, companyId, commentId) != null) originalDateTime = flatSectionJlinerJuntionLiner2CommentGateway.GetDateTime_Original(id, refId, companyId, commentId);
                        string originalComment = flatSectionJlinerJuntionLiner2CommentGateway.GetCommentOriginal(id, refId, companyId, commentId);

                        // new values
                        string newComment = flatSectionJlinerJuntionLiner2CommentGateway.GetComment(id, refId, companyId, commentId);

                        JlinerComments jlinerComments = new JlinerComments(null);
                        jlinerComments.UpdateDirect(id, refId, companyId, commentId, originalDateTime, originalLoginId, originalComment, false, id, refId, companyId, commentId, originalDateTime, originalLoginId, newComment, false);
                    }

                    // Deleted lateral comments
                    if ((row.Deleted)&& (row.InDatabase))
                    {
                        JlinerComments jlinerComments = new JlinerComments(null);
                        jlinerComments.DeleteDirect(row.ID, row.RefID, companyId, row.CommentID);
                    }
                }
            }
        }
        /// <summary>
        /// UpdateCommentsHistoryForSummaryEdit
        /// </summary>
        public void UpdateCommentsHistoryForSummaryEdit()
        {
            FlatSectionJlinerJuntionLiner2CommentGateway flatSectionJlinerJuntionLiner2CommentGateway = new FlatSectionJlinerJuntionLiner2CommentGateway();
            FlatSectionJlinerJuntionLiner2Comment jlinerComments = new FlatSectionJlinerJuntionLiner2Comment(flatSectionJlinerJuntionLiner2CommentGateway.Data);

            FlatSectionJlinerJuntionLiner2HistoryGateway flatSectionJlinerJuntionLiner2HistoryGateway = new FlatSectionJlinerJuntionLiner2HistoryGateway();
            FlatSectionJlinerJuntionLiner2History jlinerHistory = new FlatSectionJlinerJuntionLiner2History(flatSectionJlinerJuntionLiner2HistoryGateway.Data);

            foreach (FlatSectionJlinerTDS.FlatSectionJlinerRow row in (FlatSectionJlinerTDS.FlatSectionJlinerDataTable)Table)
            {
                flatSectionJlinerJuntionLiner2CommentGateway.LoadByIdRefId(row.ID, row.RefID, row.COMPANY_ID);
                row.Comments = jlinerComments.GetAllComments(row.ID, row.RefID, row.COMPANY_ID, flatSectionJlinerJuntionLiner2CommentGateway.Table.Rows.Count, "\n");

                flatSectionJlinerJuntionLiner2HistoryGateway.LoadByIdRefId(row.ID, row.RefID, row.COMPANY_ID);
                row.History = jlinerHistory.GetAllHistory(row.ID, row.RefID, row.COMPANY_ID, flatSectionJlinerJuntionLiner2HistoryGateway.Table.Rows.Count, "\n");
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

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

                // Tag page
                hdfCurrentClient.Value = (string)Request.QueryString["client"];
                hdfLoginId.Value = Convert.ToInt32(Session["loginID"]).ToString();
                hdfId.Value = Convert.ToString(Request.QueryString["rowId"]);
                hdfRefId.Value = Convert.ToString(Request.QueryString["rowRefId"]);
                hdfCompanyId.Value = Convert.ToString(Request.QueryString["rowCompanyId"]);
                hdfAdminPermission.Value = Convert.ToBoolean(Session["sgLFS_APP_ADMIN"]).ToString();
                hdfUpdate.Value = "yes";

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

                // ... Names for UserList
                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 comming from
                // ... flat_section_jliner_summary.aspx
                if (Request.QueryString["source_page"] == "flat_section_jliner_summary.aspx" || Request.QueryString["source_page"] == "flat_section_jliner_edit.aspx")
                {
                    StoreNavigatorState();
                    ViewState["update"] = Request.QueryString["update"];
                    Session["rowFocus"] = Convert.ToInt32(Request.QueryString["rowFocus"].ToString());

                    // ... Load comments to edit
                    sectionTDS = new SectionTDS();
                    flatSectionJlinerTDS = (FlatSectionJlinerTDS)Session["flatSectionJlinerTDS"];

                    SectionGateway sectionGateway = new SectionGateway(sectionTDS);
                    sectionGateway.LoadById(new Guid(hdfId.Value), Convert.ToInt32(hdfCompanyId.Value));

                    JlinerGateway jlinerGateway = new JlinerGateway(sectionTDS);
                    jlinerGateway.LoadByIdCompanyIdRefId(new Guid(hdfId.Value), Convert.ToInt32(hdfCompanyId.Value), Convert.ToInt32(hdfRefId.Value));

                    FlatSectionJlinerJuntionLiner2CommentGateway flatSectionJlinerJuntionLiner2CommentGateway = new FlatSectionJlinerJuntionLiner2CommentGateway(flatSectionJlinerTDS);
                    flatSectionJlinerJuntionLiner2CommentGateway.LoadAllByIdRefId(new Guid(hdfId.Value), Convert.ToInt32(hdfRefId.Value), Convert.ToInt32(hdfCompanyId.Value));

                    FlatSectionJlinerJuntionLiner2Comment flatSectionJlinerJuntionLiner2Comment = new FlatSectionJlinerJuntionLiner2Comment(flatSectionJlinerJuntionLiner2CommentGateway.Data);
                    flatSectionJlinerJuntionLiner2Comment.UpdateForProcess();

                    // ... Load history for transfers
                    FlatSectionJlinerJuntionLiner2HistoryGateway flatSectionJlinerJuntionLiner2HistoryGateway = new FlatSectionJlinerJuntionLiner2HistoryGateway(flatSectionJlinerTDS);
                    flatSectionJlinerJuntionLiner2HistoryGateway.LoadAllByIdRefId(new Guid(hdfId.Value), Convert.ToInt32(hdfRefId.Value), Convert.ToInt32(hdfCompanyId.Value));

                    // ... Store datasets
                    Session["sectionTDS"] = sectionTDS;
                    Session["flatSectionJlinerTDS"] = flatSectionJlinerTDS;
                    comments = flatSectionJlinerTDS.JuntionLiner2Comment;
                    Session["comments"] = comments;
                }
            }
            else
            {
                // Restore datasets
                sectionTDS = (SectionTDS)Session["sectionTDS"];
                flatSectionJlinerTDS = (FlatSectionJlinerTDS)Session["flatSectionJlinerTDS"];
                Session["flatSectionJlinerTDS"] = flatSectionJlinerTDS;
                comments = flatSectionJlinerTDS.JuntionLiner2Comment;
                Session["comments"] = comments;
            }
        }