/// <summary>
        /// UpdateComments
        /// </summary>
        /// <param name="id_">id_</param>
        public void UpdateComments(string id_)
        {
            // Updating history fields
            //FlatSectionJlinerTDS.FlatSectionJlinerRow lfsJunctionLiner2Row = GetRow(id_);

            //JlinerCommentGateway jlinerCommentGateway = new JlinerCommentGateway();
            //jlinerCommentGateway.LoadByIdRefIdCompanyId(lfsJunctionLiner2Row.ID, lfsJunctionLiner2Row.RefID, lfsJunctionLiner2Row.COMPANY_ID);
            //JlinerComments jlinerComments = new JlinerComments(jlinerCommentGateway.Data);
            //string comments = jlinerComments.GetAllComments(lfsJunctionLiner2Row.ID, lfsJunctionLiner2Row.RefID, lfsJunctionLiner2Row.COMPANY_ID, jlinerCommentGateway.Table.Rows.Count, "<br>");
            //if (comments.Length > 0)
            //{
            //    lfsJunctionLiner2Row.Comments = comments;
            //}
            //else
            //{
            //    lfsJunctionLiner2Row.SetCommentsNull();
            //}

            foreach (FlatSectionJlinerTDS.FlatSectionJlinerRow row in (FlatSectionJlinerTDS.FlatSectionJlinerDataTable)Table)
            {
                JlinerCommentGateway jlinerCommentGateway = new JlinerCommentGateway();
                jlinerCommentGateway.LoadByIdRefId(row.ID, row.RefID, row.COMPANY_ID);
                JlinerComments jlinerComments = new JlinerComments(jlinerCommentGateway.Data);
                string comments = jlinerComments.GetAllComments(row.ID, row.RefID, row.COMPANY_ID, jlinerCommentGateway.Table.Rows.Count, "<br>");

                if (comments.Length > 0)
                {
                    row.Comments = comments;
                }
                else
                {
                    row.SetCommentsNull();
                }
            }
        }
        /// <summary>
        /// Save to Section and Jliner rows
        /// </summary>
        /// <param name="sectionTDS">sectionTDS</param>
        public void Save(SectionTDS sectionTDS)
        {
            FlatSectionJlinerTDS flatSectionJlinerChanges = (FlatSectionJlinerTDS)Data.GetChanges();
            if (flatSectionJlinerChanges.FlatSectionJliner.Rows.Count > 0)
            {
                SectionGateway sectionGateway = new SectionGateway(sectionTDS);
                LiquiForce.LFSLive.BL.CWP.Section.Section section = new LiquiForce.LFSLive.BL.CWP.Section.Section(sectionTDS);
                JlinerGateway jlinerGateway = new JlinerGateway(sectionTDS);
                Jliner jliner = new Jliner(sectionTDS);
                JlinerCommentGateway jlinerCommentGateway = new JlinerCommentGateway(sectionTDS);
                JlinerComments jlinerComments = new JlinerComments(jlinerCommentGateway.Data);
                JlinerHistoryGateway jlinerHistoryGateway = new JlinerHistoryGateway(sectionTDS);
                JlinerHistory jlinerHistory = new JlinerHistory(jlinerHistoryGateway.Data);

                sectionGateway.ClearBeforeFill = false;
                jlinerGateway.ClearBeforeFill = false;
                jlinerCommentGateway.ClearBeforeFill = false;
                jlinerHistoryGateway.ClearBeforeFill = false;

                foreach (FlatSectionJlinerTDS.FlatSectionJlinerRow flatSectionJlinerRow in (FlatSectionJlinerTDS.FlatSectionJlinerDataTable)flatSectionJlinerChanges.FlatSectionJliner)
                {
                    // Load section and jliner
                    // ... Load section
                    try
                    {
                        //... Search section row
                        sectionGateway.GetRow(flatSectionJlinerRow.ID);
                    }
                    catch
                    {
                        //... Load section and section's jliners
                        sectionGateway.LoadById(flatSectionJlinerRow.ID, flatSectionJlinerRow.COMPANY_ID);
                        jlinerGateway.LoadByIdCompanyId(flatSectionJlinerRow.ID, flatSectionJlinerRow.COMPANY_ID);
                        jlinerCommentGateway.LoadById(flatSectionJlinerRow.ID, flatSectionJlinerRow.COMPANY_ID);
                        jlinerHistoryGateway.LoadById(flatSectionJlinerRow.ID, flatSectionJlinerRow.COMPANY_ID);
                    }

                    // Update

                    // ... Update jliner
                    string address = ""; if (!flatSectionJlinerRow.IsNull("Address")) address = flatSectionJlinerRow.Address;
                    DateTime? pipeLocated = null; if (!flatSectionJlinerRow.IsNull("PipeLocated")) pipeLocated = flatSectionJlinerRow.PipeLocated;
                    DateTime? servicesLocated = null; if (!flatSectionJlinerRow.IsNull("ServicesLocated")) servicesLocated = flatSectionJlinerRow.ServicesLocated;
                    DateTime? coInstalled = null; if (!flatSectionJlinerRow.IsNull("CoInstalled")) coInstalled = flatSectionJlinerRow.CoInstalled;
                    DateTime? backfilledConcrete = null; if (!flatSectionJlinerRow.IsNull("BackfilledConcrete")) backfilledConcrete = flatSectionJlinerRow.BackfilledConcrete;
                    DateTime? backfilledSoil = null; if (!flatSectionJlinerRow.IsNull("BackfilledSoil")) backfilledSoil = flatSectionJlinerRow.BackfilledSoil;
                    DateTime? grouted = null; if (!flatSectionJlinerRow.IsNull("Grouted")) grouted = flatSectionJlinerRow.Grouted;
                    DateTime? cored = null; if (!flatSectionJlinerRow.IsNull("Cored")) cored = flatSectionJlinerRow.Cored;
                    DateTime? prepped = null; if (!flatSectionJlinerRow.IsNull("Prepped")) prepped = flatSectionJlinerRow.Prepped;
                    DateTime? measured = null; if (!flatSectionJlinerRow.IsNull("Measured")) measured = flatSectionJlinerRow.Measured;
                    string linerSize = ""; if (!flatSectionJlinerRow.IsNull("LinerSize")) linerSize = flatSectionJlinerRow.LinerSize;
                    DateTime? inProcess = null; if (!flatSectionJlinerRow.IsNull("Inprocess")) inProcess = flatSectionJlinerRow.InProcess;
                    DateTime? inStock = null; if (!flatSectionJlinerRow.IsNull("InStock")) inStock = flatSectionJlinerRow.InStock;
                    DateTime? delivered = null; if (!flatSectionJlinerRow.IsNull("Delivered")) delivered = flatSectionJlinerRow.Delivered;
                    DateTime? preVideo = null; if (!flatSectionJlinerRow.IsNull("PreVideo")) preVideo = flatSectionJlinerRow.PreVideo;
                    DateTime? linerInstalled = null; if (!flatSectionJlinerRow.IsNull("LinerInstalled")) linerInstalled = flatSectionJlinerRow.LinerInstalled;
                    DateTime? finalVideo = null; if (!flatSectionJlinerRow.IsNull("FinalVideo")) finalVideo = flatSectionJlinerRow.FinalVideo;
                    double? distanceFromUSMH = null; if (!flatSectionJlinerRow.IsNull("DistanceFromUSMH")) distanceFromUSMH = flatSectionJlinerRow.DistanceFromUSMH;
                    double? distanceFromDSMH = null; if (!flatSectionJlinerRow.IsNull("DistanceFromDSMH")) distanceFromDSMH = flatSectionJlinerRow.DistanceFromDSMH;
                    string history = ""; if (!flatSectionJlinerRow.IsNull("History")) history = flatSectionJlinerRow.History;
                    string map = "";
                    string issue = flatSectionJlinerRow.Issue;
                    decimal? cost = null; if (!flatSectionJlinerRow.IsNull("Cost")) cost = flatSectionJlinerRow.Cost;
                    bool deleted = flatSectionJlinerRow.Deleted;

                    // ... Delete all comments and history for a jliner
                    if (deleted)
                    {
                        jlinerComments.DeleteAllCommentsForAJliner(flatSectionJlinerRow.ID, flatSectionJlinerRow.RefID, flatSectionJlinerRow.COMPANY_ID);
                        jlinerHistory.DeleteAllHistoryForAJliner(flatSectionJlinerRow.ID, flatSectionJlinerRow.RefID, flatSectionJlinerRow.COMPANY_ID);
                    }

                    DateTime? videoInspection = null; if (!flatSectionJlinerRow.IsNull("VideoInspection")) videoInspection = flatSectionJlinerRow.VideoInspection;
                    bool coRequired = flatSectionJlinerRow.CoRequired;
                    bool pitRequired = flatSectionJlinerRow.PitRequired;
                    string coPitLocation = ""; if (!flatSectionJlinerRow.IsNull("CoPitLocation")) coPitLocation = flatSectionJlinerRow.CoPitLocation;
                    bool postContractDigRequired = flatSectionJlinerRow.PostContractDigRequired;
                    DateTime? coCutDown = null; if (!flatSectionJlinerRow.IsNull("CoCutDown")) coCutDown = flatSectionJlinerRow.CoCutDown;
                    DateTime? finalRestoration = null; if (!flatSectionJlinerRow.IsNull("FinalRestoration")) finalRestoration = flatSectionJlinerRow.FinalRestoration;
                    string clientLateralId = ""; if (!flatSectionJlinerRow.IsNull("ClientLateralID")) clientLateralId = flatSectionJlinerRow.ClientLateralID;
                    string videoLengthToPropertyLine = ""; if (!flatSectionJlinerRow.IsNull("VideoLengthToPropertyLine")) videoLengthToPropertyLine = flatSectionJlinerRow.VideoLengthToPropertyLine;
                    bool liningThruCo = flatSectionJlinerRow.LiningThruCo;
                    string hamiltonInspectionNumber = ""; if (!flatSectionJlinerRow.IsNull("HamiltonInspectionNumber")) hamiltonInspectionNumber = flatSectionJlinerRow.HamiltonInspectionNumber;
                    DateTime? noticeDelivered = null; if (!flatSectionJlinerRow.IsNull("NoticeDelivered")) noticeDelivered = flatSectionJlinerRow.NoticeDelivered;

                    jliner.Update(flatSectionJlinerRow.ID, flatSectionJlinerRow.RefID, flatSectionJlinerRow.COMPANY_ID, flatSectionJlinerRow.DetailID, address, pipeLocated, servicesLocated, coInstalled, backfilledConcrete, backfilledSoil, grouted, cored, prepped, measured, linerSize, inProcess, inStock, delivered, preVideo, linerInstalled, finalVideo, distanceFromUSMH, distanceFromDSMH,map, issue, cost, deleted, videoInspection, coRequired, pitRequired, coPitLocation, postContractDigRequired, coCutDown, finalRestoration, clientLateralId, videoLengthToPropertyLine, liningThruCo, hamiltonInspectionNumber, noticeDelivered);

                    // ... Update section
                    section.UpdateJliners(flatSectionJlinerRow.ID, flatSectionJlinerRow.COMPANY_ID);
                }
            }
        }
        /// <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)
        {
            JlinerAddTDS jlinerAddChanges = (JlinerAddTDS)Data.GetChanges();

            if (jlinerAddChanges != null)
            {
                if (jlinerAddChanges.JunctionLiner2Comment.Rows.Count > 0)
                {
                    JlinerAddJunctionLiner2CommentGateway jlinerAddJunctionLiner2CommentGateway = new JlinerAddJunctionLiner2CommentGateway(jlinerAddChanges);

                    foreach (JlinerAddTDS.JunctionLiner2CommentRow row in (JlinerAddTDS.JunctionLiner2CommentDataTable)jlinerAddChanges.JunctionLiner2Comment)
                    {
                        // Deleted lateral comments
                        if (row.Deleted)
                        {
                            JlinerComments jlinerComments = new JlinerComments(null);
                            jlinerComments.DeleteAllDirect(row.ID, row.RefID, companyId);
                        }
                    }
                }
            }
        }
        /// <summary>
        /// Transfer to Comments
        /// </summary>
        /// <param name="loginId">loginId</param>
        /// <param name="adminPermission">admin Permission</param>
        /// <param name="jlinerComments">jlinerComments</param>
        public void transferToComments(int loginId, bool adminPermission, JlinerComments jlinerComments)
        {
            foreach (SectionTDS.LFS_JUNCTION_LINER2_HISTORYRow historyRow in (SectionTDS.LFS_JUNCTION_LINER2_HISTORYDataTable)Table)
            {
                if (adminPermission)
                {
                    if ((historyRow.ToComments) && (!historyRow.Deleted))
                    {
                        // Insert to comments
                        jlinerComments.Insert(historyRow.ID, historyRow.RefID, historyRow.COMPANY_ID, historyRow.DateTime_, historyRow.LoginID, historyRow.History, historyRow.Deleted, false);

                        // Delete from History
                        historyRow.Deleted = true;
                    }
                }
                else
                {
                    if (historyRow.LoginID == loginId)
                    {
                        if ((historyRow.ToComments) && (!historyRow.Deleted))
                        {
                            // Insert to comments
                            jlinerComments.Insert(historyRow.ID, historyRow.RefID, historyRow.COMPANY_ID, historyRow.DateTime_, historyRow.LoginID, historyRow.History, historyRow.Deleted, false);

                            // Delete from History
                            historyRow.Deleted = true;
                        }
                    }
                }

            }
        }
        /// <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);
                    }
                }
            }
        }