// ////////////////////////////////////////////////////////////////////////
        // PUBLIC METHODS
        //
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="companyId">companyId</param>
        public void Delete(int workId, int companyId)
        {
            WorkFullLengthLiningM1LateralGateway workFullLengthLiningM1LateralGateway = new WorkFullLengthLiningM1LateralGateway();
            workFullLengthLiningM1LateralGateway.LoadByWorkId(workId, companyId);

            foreach (WorkTDS.LFS_WORK_FULLLENGTHLINING_M1_LATERALRow row in (WorkTDS.LFS_WORK_FULLLENGTHLINING_M1_LATERALDataTable)workFullLengthLiningM1LateralGateway.Table)
            {
                // delete lfs lateral client
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(workId, companyId);
                int currentProjectId = workGateway.GetProjectId(workId);

                ProjectGateway projectGateway = new ProjectGateway();
                projectGateway.LoadByProjectId(currentProjectId);
                int clientId = projectGateway.GetClientID(currentProjectId);

                LfsAssetSewerLateralClientGateway lfsAssetSewerLateralClientGateway = new LfsAssetSewerLateralClientGateway();
                lfsAssetSewerLateralClientGateway.LoadByAssetIdClientId(row.Lateral, clientId, companyId);

                if (lfsAssetSewerLateralClientGateway.Table.Rows.Count > 0)
                {
                    LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                    lfsAssetSewerLateralClient.DeleteDirect(row.Lateral, clientId, companyId);
                }

                // Delete work lateral
                workFullLengthLiningM1LateralGateway.Delete(workId, row.Lateral, companyId);

                // Delete section
                LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
                lfsAssetSewerLateral.DeleteDirect(row.Lateral, companyId);
            }
        }
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="workId">workId</param>
        /// <param name="assetIdLateral">assetIdLateral</param>
        /// <param name="sectionWorkId">sectionWorkId</param>
        /// <param name="companyId">companyId</param>
        private void Delete(int workId, int assetIdLateral, int sectionWorkId, int companyId)
        {
            WorkGateway workGateway = new WorkGateway();
            workGateway.LoadByWorkId(workId, companyId);
            int currentProjectId = workGateway.GetProjectId(workId);

            ProjectGateway projectGateway = new ProjectGateway();
            projectGateway.LoadByProjectId(currentProjectId);
            int clientId = projectGateway.GetClientID(currentProjectId);

            // delete lateral work
            WorkJunctionLiningLateral workJunctionLiningLateral = new WorkJunctionLiningLateral(null);
            workJunctionLiningLateral.DeleteDirect(workId, sectionWorkId, companyId);

            // delete lfs lateral
            LfsAssetSewerLateral lfsAssetSewerLateral = new LfsAssetSewerLateral(null);
            bool isDeleted = lfsAssetSewerLateral.DeleteDirect(assetIdLateral, companyId);

            if (isDeleted)
            {
                // delete lfs lateral client
                LfsAssetSewerLateralClientGateway lfsAssetSewerLateralClientGateway = new LfsAssetSewerLateralClientGateway();
                lfsAssetSewerLateralClientGateway.LoadByAssetIdClientId(assetIdLateral, clientId, companyId);

                if (lfsAssetSewerLateralClientGateway.Table.Rows.Count > 0)
                {
                    LfsAssetSewerLateralClient lfsAssetSewerLateralClient = new LfsAssetSewerLateralClient(null);
                    lfsAssetSewerLateralClient.DeleteDirect(assetIdLateral, clientId, companyId);
                }
            }
        }
        /// <summary>
        /// UpdateForReport
        /// </summary>        
        /// <param name="companyId">companyId</param>
        public void UpdateForReport(int companyId)
        {
            foreach (JlLiningPlanTDS.JlLiningPlanJlinerRow row in (JlLiningPlanTDS.JlLiningPlanJlinerDataTable)Table)
            {
                // Update comments
                int jlWorkId = row.SectionWorkID;
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(jlWorkId, companyId);
                int assetId = workGateway.GetAssetId(jlWorkId);
                int projectId = workGateway.GetProjectId(jlWorkId);

                // ... Get raWorkId
                int raWorkId = 0;
                WorkGateway raWorkGateway = new WorkGateway();
                raWorkGateway.LoadByProjectIdAssetIdWorkType(projectId, row.Section_, "Rehab Assessment", companyId);
                if (raWorkGateway.Table.Rows.Count > 0)
                {
                    raWorkId = raWorkGateway.GetWorkId(row.Section_, "Rehab Assessment", projectId);
                }

                // ... Get raWorkId
                int flWorkId = 0;
                WorkGateway flWorkGateway = new WorkGateway();
                flWorkGateway.LoadByProjectIdAssetIdWorkType(projectId, row.Section_, "Full Length Lining", companyId);
                if (flWorkGateway.Table.Rows.Count > 0)
                {
                    flWorkId = flWorkGateway.GetWorkId(row.Section_, "Full Length Lining", projectId);
                }

                // ... Load All Comments
                FlatSectionJLAllComments flatSectionJLAllComments = new FlatSectionJLAllComments();
                flatSectionJLAllComments.LoadAllByJlWorkIdFlWorkIdRaWorkId(jlWorkId, flWorkId, raWorkId, companyId);

                row.Comments = flatSectionJLAllComments.GetJLOrFLOrRAComments(companyId, flatSectionJLAllComments.Table.Rows.Count, "\n");

                // Add M1 comments
                WorkFullLengthLiningM1LateralGateway workFullLengthLiningM1LateralGateway = new WorkFullLengthLiningM1LateralGateway();
                workFullLengthLiningM1LateralGateway.LoadByWorkIdLateral(flWorkId, row.AssetID, companyId);
                if (workFullLengthLiningM1LateralGateway.Table.Rows.Count > 0)
                {
                    string m1LateralComment = workFullLengthLiningM1LateralGateway.GetComments(flWorkId, row.AssetID);
                    if (m1LateralComment != "")
                    {
                        row.Comments = row.Comments + "\n\nType: M1 Lateral Comments\nComment: " + m1LateralComment;
                    }
                }

                if (!row.IsCommentsNull())
                {
                    row.Comments = row.Comments.Replace("<br>", "\n");
                }

                // Round PullInDistance
                if (Validator.IsValidDecimal(row.PullInDistance))
                {
                    row.PullInDistance = decimal.Round(decimal.Parse(row.PullInDistance), 1).ToString();
                }
                else
                {
                    row.PullInDistance = "0";
                }

                // Update Main size
                if (!row.IsMainSizeNull())
                {
                    if (Distance.IsValidDistance(row.MainSize))
                    {
                        Distance distance = new Distance(row.MainSize);

                        switch (distance.DistanceType)
                        {
                            case 2:
                                row.MainSize = distance.ToStringInEng1();
                                break;
                            case 3:
                                if (Convert.ToDouble(row.MainSize) > 99)
                                {
                                    double newMainSize = 0;
                                    newMainSize = Convert.ToDouble(row.MainSize) * 0.03937;
                                    row.MainSize = Convert.ToString(Math.Ceiling(newMainSize)) + "\"";
                                }
                                else
                                {
                                    row.MainSize = row.MainSize + "\"";
                                }
                                break;
                            case 4:
                                row.MainSize = distance.ToStringInEng1();
                                break;
                            case 5:
                                row.MainSize = distance.ToStringInEng1();
                                break;
                        }
                    }
                }
            }
        }
        /// <summary>
        /// UpdateCommentsHistoryForSummaryEdit
        /// </summary>
        /// <param name="jlWorkId">jlWorkId</param>
        /// <param name="workType">workType</param>
        /// <param name="companyId">companyId</param>
        /// <returns>comments</returns>
        public void UpdateCommentsHistoryForSummaryEdit(int jlWorkId, string workType, int companyId)
        {
            foreach (FlatSectionJlTDS.FlatSectionJlRow row in (FlatSectionJlTDS.FlatSectionJlDataTable)Table)
            {
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(jlWorkId, companyId);
                int assetId = workGateway.GetAssetId(jlWorkId);
                int projectId = workGateway.GetProjectId(jlWorkId);

                if (row.AssetID == assetId)
                {
                    // Update Comments
                    // ... Get raWorkId
                    int raWorkId = 0;
                    WorkGateway raWorkGateway = new WorkGateway();
                    raWorkGateway.LoadByProjectIdAssetIdWorkType(projectId, row.Section_, "Rehab Assessment", companyId);
                    if (raWorkGateway.Table.Rows.Count > 0)
                    {
                        raWorkId = raWorkGateway.GetWorkId(row.Section_, "Rehab Assessment", projectId);
                    }

                    // ... Get flWorkId
                    int flWorkId = 0;
                    WorkGateway flWorkGateway = new WorkGateway();
                    flWorkGateway.LoadByProjectIdAssetIdWorkType(projectId, row.Section_, "Full Length Lining", companyId);
                    if (flWorkGateway.Table.Rows.Count > 0)
                    {
                        flWorkId = flWorkGateway.GetWorkId(row.Section_, "Full Length Lining", projectId);
                    }

                    // ... Load All Comments
                    FlatSectionJLAllComments flatSectionJLAllComments = new FlatSectionJLAllComments();
                    flatSectionJLAllComments.LoadAllByJlWorkIdFlWorkIdRaWorkId(jlWorkId, flWorkId, raWorkId, companyId);

                    row.Comments = flatSectionJLAllComments.GetJLOrFLOrRAComments(companyId, flatSectionJLAllComments.Table.Rows.Count, "\n");

                    // Add M1 comments
                    WorkFullLengthLiningM1LateralGateway workFullLengthLiningM1LateralGateway = new WorkFullLengthLiningM1LateralGateway();
                    workFullLengthLiningM1LateralGateway.LoadByWorkIdLateral(flWorkId, row.AssetID, companyId);
                    if (workFullLengthLiningM1LateralGateway.Table.Rows.Count > 0)
                    {
                        string m1LateralComments = workFullLengthLiningM1LateralGateway.GetComments(flWorkId, row.AssetID);
                        if (m1LateralComments != "")
                        {
                            row.Comments = row.Comments + "\n\nType: M1 Lateral Comments\nComment: " + m1LateralComments;
                        }
                    }

                    WorkFullLengthLiningM1Gateway workFullLengthLiningM1Gateway = new WorkFullLengthLiningM1Gateway();
                    workFullLengthLiningM1Gateway.LoadByWorkId(flWorkId, companyId);
                    if (workFullLengthLiningM1Gateway.Table.Rows.Count > 0)
                    {
                        string trafficControlDetails = workFullLengthLiningM1Gateway.GetTrafficControlDetails(flWorkId);
                        if (trafficControlDetails != "")
                        {
                            row.Comments = row.Comments + "\n\nType: Traffic Control Details\nComment: " + trafficControlDetails ;
                        }

                        string standardByPassComments = workFullLengthLiningM1Gateway.GetStandardBypassComments(flWorkId);
                        if (standardByPassComments != "")
                        {
                            row.Comments = row.Comments + "\n\nType: Standard Bypass Comments\nComment: " + standardByPassComments ;
                        }
                    }

                    if (!row.IsCommentsNull())
                    {
                        row.Comments = row.Comments.Replace("<br>", "\n");
                    }

                    // Update History
                    FlatSectionJLAllHistory flatSectionJLAllHistory = new FlatSectionJLAllHistory();
                    flatSectionJLAllHistory.LoadAllByJlWorkIdFlWorkIdRaWorkId(jlWorkId, flWorkId, raWorkId, companyId);

                    row.History = flatSectionJLAllHistory.GetJLOrFLOrRAHistory(companyId, flatSectionJLAllHistory.Table.Rows.Count, "\n");

                    if (!row.IsHistoryNull())
                    {
                        row.History = row.History.Replace("<br>", "\n");
                    }
                }
            }
        }
        /// <summary>
        /// UpdateComments
        /// </summary>
        /// <param name="jlWorkId">workIdjlWorkIdparam>
        /// <param name="workType">workType</param>
        /// <param name="companyId">companyId</param>
        public void UpdateComments(int jlWorkId, string workType, int companyId)
        {
            foreach (JlNavigatorTDS.JlNavigatorRow row in (JlNavigatorTDS.JlNavigatorDataTable)Table)
            {
                WorkGateway workGateway = new WorkGateway();
                workGateway.LoadByWorkId(jlWorkId, companyId);
                int assetId = workGateway.GetAssetId(jlWorkId);
                int projectId = workGateway.GetProjectId(jlWorkId);

                if (row.AssetID_ == assetId)
                {
                    // Update Comments
                    // ... Get raWorkId
                    int raWorkId = 0;

                    // ... Get raWorkId
                    int flWorkId = 0;

                    // ... Load All Comments
                    FlatSectionJLAllComments flatSectionJLAllComments = new FlatSectionJLAllComments();
                    flatSectionJLAllComments.LoadAllByJlWorkIdFlWorkIdRaWorkId(jlWorkId, flWorkId, raWorkId, companyId);

                    row.Comments = flatSectionJLAllComments.GetJLOrFLOrRAComments(companyId, flatSectionJLAllComments.Table.Rows.Count, "\n");

                    if (!row.IsHistoryNull())
                    {
                        row.Comments = row.Comments.Replace("<br>", "\n");
                    }

                    // Update History
                    FlatSectionJLAllHistory flatSectionJLAllHistory = new FlatSectionJLAllHistory();
                    flatSectionJLAllHistory.LoadAllByJlWorkIdFlWorkIdRaWorkId(jlWorkId, flWorkId, raWorkId, companyId);

                    row.History = flatSectionJLAllHistory.GetJLOrFLOrRAHistory(companyId, flatSectionJLAllHistory.Table.Rows.Count, "\n");

                    if (!row.IsHistoryNull())
                    {
                        row.History = row.History.Replace("<br>", "\n");
                    }

                    // Save work
                    // ... Get original variables
                    workGateway.LoadByWorkId(jlWorkId, companyId);

                    string originalWorkType = workGateway.GetWorkTypeOriginal(jlWorkId);
                    int? originalLibraryCategoriesId = workGateway.GetLibraryCategoriesIdOriginal(jlWorkId);
                    string originalComment = workGateway.GetCommentsOriginal(jlWorkId);
                    string originalHistory = workGateway.GetHistoryOriginal(jlWorkId);

                    Work work = new Work(null);
                    work.UpdateDirect(jlWorkId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, originalComment, originalHistory, jlWorkId, projectId, assetId, originalWorkType, originalLibraryCategoriesId, false, companyId, row.Comments, row.History);
                }
            }
        }