protected void btnPrintLateralLocationSheet_Click(object sender, EventArgs e)
        {
            // Report call
            Page.Validate();
            if (Page.IsValid)
            {
                PostPageChanges();

                int assetId = GetAssetId();
                if (assetId > 0)
                {
                    int workIdRa = GetWorkId(Int32.Parse(hdfCurrentProjectId.Value), assetId, "Rehab Assessment", Int32.Parse(hdfCompanyId.Value));
                    int workIdFll = GetWorkId(Int32.Parse(hdfCurrentProjectId.Value), assetId, "Full Length Lining", Int32.Parse(hdfCompanyId.Value));

                    RehabAssessmentWorkDetailsGateway rehabAssessmentWorkDetailsGateway = new RehabAssessmentWorkDetailsGateway();
                    rehabAssessmentWorkDetailsGateway.LoadByWorkId(workIdRa, Int32.Parse(hdfCompanyId.Value));
                    string measuredFrom = rehabAssessmentWorkDetailsGateway.GetMeasurementFromMh(workIdRa);

                    Response.Write("<script language='javascript'> {window.open('./../../CWP/Common/lateral_location_sheet_report.aspx?source_page=lm&project_id=" + hdfCurrentProjectId.Value + "&client_id=" + hdfCurrentClientId.Value + "&work_id=" + workIdFll.ToString() + "&measured_from=" + measuredFrom + "&asset_id=" + assetId.ToString() + "', '_blank', 'toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=800, height=680');}</script>");
                }
                else
                {
                    cvSelection.IsValid = false;
                }
            }
        }
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="countryId">countryId</param>
        /// <param name="provinceId">provinceId</param>
        /// <param name="countyId">countyId</param>
        /// <param name="cityId">cityId</param>
        /// <param name="projectId">projectId</param>
        /// <param name="companyId">companyId</param>
        /// <param name="sectionAssetId">sectionAssetId</param>
        public void Save(Int64? countryId, Int64? provinceId, Int64? countyId, Int64? cityId, int projectId, int companyId, int sectionAssetId)
        {
            RehabAssessmentTDS rehabAssessmentChanges = (RehabAssessmentTDS)Data.GetChanges();

            if (rehabAssessmentChanges.WorkDetails.Rows.Count > 0)
            {
                RehabAssessmentWorkDetailsGateway rehabAssessmentWorkDetailsGateway = new RehabAssessmentWorkDetailsGateway(rehabAssessmentChanges);

                // Update sections
                foreach (RehabAssessmentTDS.WorkDetailsRow workDetailsRow in (RehabAssessmentTDS.WorkDetailsDataTable)rehabAssessmentChanges.WorkDetails)
                {
                    // Unchanged values
                    int workId = workDetailsRow.WorkID;

                    // Original values
                    // ... General
                    string originalClientId = rehabAssessmentWorkDetailsGateway.GetClientIdOriginal(workId);
                    DateTime? originalPreFlushDate = rehabAssessmentWorkDetailsGateway.GetPreFlushDateOriginal(workId);
                    DateTime? originalPreVideoDate = rehabAssessmentWorkDetailsGateway.GetPreVideoDateOriginal(workId);

                    // ... P1
                    DateTime? originalP1Date = rehabAssessmentWorkDetailsGateway.GetP1DateOriginal(workId);
                    int? originalCxisRemoved = rehabAssessmentWorkDetailsGateway.GetCxisRemovedOriginal(workId);
                    bool originalRoboticPrepCompleted = rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompletedOriginal(workId);
                    DateTime? originalRoboticPrepCompletedDate = rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompletedDateOriginal(workId);
                    bool originalP1Completed = rehabAssessmentWorkDetailsGateway.GetP1CompletedOriginal(workId);

                    // ... M1
                    DateTime? originalM1Date = rehabAssessmentWorkDetailsGateway.GetM1DateOriginal(workId);
                    string originalMeasurementTakenBy = rehabAssessmentWorkDetailsGateway.GetMeasurementTakenByOriginal(workId);
                    string originalTrafficControl = rehabAssessmentWorkDetailsGateway.GetTrafficControlOriginal(workId);
                    string originalSiteDetails = rehabAssessmentWorkDetailsGateway.GetSiteDetailsOriginal(workId);
                    bool originalPipeSizeChange = rehabAssessmentWorkDetailsGateway.GetPipeSizeChange(workId);
                    bool originalStandardBypass = rehabAssessmentWorkDetailsGateway.GetStandardBypass(workId);
                    string originalStandardBypassComments = rehabAssessmentWorkDetailsGateway.GetStandardBypassCommentsOriginal(workId);
                    string originalTrafficControlDetails = rehabAssessmentWorkDetailsGateway.GetTrafficControlDetailsOriginal(workId);
                    string originalMeasurementType = rehabAssessmentWorkDetailsGateway.GetMeasurementTypeOriginal(workId);
                    string originalMeasurementFromMh = rehabAssessmentWorkDetailsGateway.GetMeasurementFromMhOriginal(workId);
                    string originalVideoDoneFromMh = rehabAssessmentWorkDetailsGateway.GetVideoDoneFromMhOriginal(workId);
                    string originalVideoDoneToMh = rehabAssessmentWorkDetailsGateway.GetVideoDoneToMhOriginal(workId);
                    string originalMaterial = rehabAssessmentWorkDetailsGateway.GetMaterialOriginal(workId);
                    string originalAccessType = rehabAssessmentWorkDetailsGateway.GetAccessTypeOriginal(workId);

                    // ... Comments
                    string originalComments = rehabAssessmentWorkDetailsGateway.GetCommentsOriginal(workId);

                    // ... M2
                    string originalVideoDistance = rehabAssessmentWorkDetailsGateway.GetVideoDistanceOriginal(workId);

                    // New variables
                    // ... General
                    string newClientId = rehabAssessmentWorkDetailsGateway.GetClientId(workId);

                    // ... P1
                    DateTime? newP1Date = rehabAssessmentWorkDetailsGateway.GetP1Date(workId);
                    int? newCxisRemoved = rehabAssessmentWorkDetailsGateway.GetCxisRemoved(workId);
                    bool newRoboticPrepCompleted = rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompleted(workId);
                    DateTime? newRoboticPrepCompletedDate = rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompletedDate(workId);
                    bool newP1Completed = rehabAssessmentWorkDetailsGateway.GetP1Completed(workId);

                    // ... M1
                    DateTime? newM1Date = rehabAssessmentWorkDetailsGateway.GetM1Date(workId);
                    string newMeasurementTakenBy = rehabAssessmentWorkDetailsGateway.GetMeasurementTakenBy(workId);
                    string newTrafficControl = rehabAssessmentWorkDetailsGateway.GetTrafficControl(workId);
                    string newSiteDetails = rehabAssessmentWorkDetailsGateway.GetSiteDetails(workId);
                    bool newPipeSizeChange = rehabAssessmentWorkDetailsGateway.GetPipeSizeChange(workId);
                    bool newStandardBypass = rehabAssessmentWorkDetailsGateway.GetStandardBypass(workId);
                    string newStandardBypassComments = rehabAssessmentWorkDetailsGateway.GetStandardBypassComments(workId);
                    string newTrafficControlDetails = rehabAssessmentWorkDetailsGateway.GetTrafficControlDetails(workId);
                    string newMeasurementType = rehabAssessmentWorkDetailsGateway.GetMeasurementType(workId);
                    string newMeasurementFromMh = rehabAssessmentWorkDetailsGateway.GetMeasurementFromMh(workId);
                    string newVideoDoneFromMh = rehabAssessmentWorkDetailsGateway.GetVideoDoneFromMh(workId);
                    string newVideoDoneToMh = rehabAssessmentWorkDetailsGateway.GetVideoDoneToMh(workId);
                    string newMaterial = rehabAssessmentWorkDetailsGateway.GetMaterial(workId);
                    string newAccessType = rehabAssessmentWorkDetailsGateway.GetAccessType(workId);

                    // ... M2
                    string newVideoDistance = rehabAssessmentWorkDetailsGateway.GetVideoDistance(workId);

                    // ... Comments
                    string newComments = rehabAssessmentWorkDetailsGateway.GetComments(workId);

                    // ... RA
                    DateTime? newPreFlushDate = rehabAssessmentWorkDetailsGateway.GetPreFlushDate(workId);
                    DateTime? newPreVideoDate = rehabAssessmentWorkDetailsGateway.GetPreVideoDate(workId);

                    // ... FLL WorkID
                    int workIdFll = 0; if (!workDetailsRow.IsWorkIDFllNull()) workIdFll = workDetailsRow.WorkIDFll;

                    if (workIdFll != 0) // ... Has Fll work
                    {
                        WorkFullLengthLiningGateway workFullLengthLiningGateway = new WorkFullLengthLiningGateway();
                        workFullLengthLiningGateway.LoadByWorkId(workIdFll, companyId);

                        DateTime? originalProposedLiningDate = workFullLengthLiningGateway.GetProposedLiningDate(workIdFll);
                        DateTime? originalDeadlineLiningDate = workFullLengthLiningGateway.GetDeadlineLiningDate(workIdFll);
                        DateTime? originalM2Date = workFullLengthLiningGateway.GetM2Date(workIdFll);
                        DateTime? originalInstallDate = workFullLengthLiningGateway.GetInstallDate(workIdFll);
                        DateTime? originalFinalVideoDate = workFullLengthLiningGateway.GetFinalVideoDate(workIdFll);
                        bool originalIssueIdentified = workFullLengthLiningGateway.GetIssueIdentified(workIdFll);
                        bool originalIssueLFS = workFullLengthLiningGateway.GetIssueLFS(workIdFll);
                        bool originalIssueClient = workFullLengthLiningGateway.GetIssueClient(workIdFll);
                        bool originalIssueSales = workFullLengthLiningGateway.GetIssueSales(workIdFll);
                        bool originalIssueGivenToClient = workFullLengthLiningGateway.GetIssueGivenToClient(workIdFll);
                        bool originalIssueResolved = workFullLengthLiningGateway.GetIssueResolved(workIdFll);
                        bool originalIssueInvestigation = workFullLengthLiningGateway.GetIssueInvestigation(workIdFll);

                        // ... Update work
                        UpdateFllWork(sectionAssetId, countryId, provinceId, countyId, cityId, workIdFll, originalClientId, originalProposedLiningDate, originalDeadlineLiningDate, originalP1Date, originalM1Date, originalM2Date, originalInstallDate, originalFinalVideoDate, originalIssueIdentified, originalIssueLFS, originalIssueClient, originalIssueSales, originalIssueGivenToClient, originalIssueResolved, originalIssueInvestigation, originalCxisRemoved, originalRoboticPrepCompleted, originalRoboticPrepCompletedDate, originalMeasurementTakenBy, originalTrafficControl, originalSiteDetails, originalPipeSizeChange, originalStandardBypass, originalStandardBypassComments, originalTrafficControlDetails, originalMeasurementType, originalMeasurementFromMh, originalVideoDoneFromMh, originalVideoDoneToMh, originalVideoDistance, originalComments, false, companyId, originalMaterial, originalAccessType, originalP1Completed, newClientId, originalProposedLiningDate, originalDeadlineLiningDate, newP1Date, newM1Date, originalM2Date, originalInstallDate, originalFinalVideoDate, originalIssueIdentified, originalIssueLFS, originalIssueClient, originalIssueSales, originalIssueGivenToClient, originalIssueResolved, originalIssueInvestigation, newCxisRemoved, newRoboticPrepCompleted, newRoboticPrepCompletedDate, newMeasurementTakenBy, newMaterial, newTrafficControl, newSiteDetails, newPipeSizeChange, newStandardBypass, newStandardBypassComments, newTrafficControlDetails, newMeasurementType, newMeasurementFromMh, newVideoDoneFromMh, newVideoDoneToMh, newVideoDistance, newComments, false, companyId, newAccessType, newP1Completed);
                        UpdateRaWork(workId, originalPreFlushDate, originalPreVideoDate, newPreFlushDate, newPreVideoDate, companyId);
                    }
                    else
                    {
                        if (newClientId != "" || newP1Date.HasValue || newCxisRemoved.HasValue || newM1Date.HasValue || newMeasurementTakenBy != "" || newMaterial != "" || newTrafficControl != "" || newMeasurementType != "" || newMeasurementFromMh != "" || newVideoDoneFromMh != "" || newVideoDoneToMh != "" || newStandardBypassComments != "" || newTrafficControlDetails != ""  || newVideoDistance != "") // Insert Fll work
                        {
                            WorkFullLengthLining workFullLengthLining = new WorkFullLengthLining(null);
                            workIdFll = workFullLengthLining.InsertDirectEmptyWorks(projectId, sectionAssetId, null, "", null, null, null, null, null, null, null, false, false, false, false, false, false, false, companyId, false, "", "");

                            WorkFullLengthLiningGateway workFullLengthLiningGateway = new WorkFullLengthLiningGateway();
                            workFullLengthLiningGateway.LoadByWorkId(workIdFll, companyId);

                            DateTime? originalProposedLiningDate = workFullLengthLiningGateway.GetProposedLiningDate(workIdFll);
                            DateTime? originalDeadlineLiningDate = workFullLengthLiningGateway.GetDeadlineLiningDate(workIdFll);
                            DateTime? originalM2Date = workFullLengthLiningGateway.GetM2Date(workIdFll);
                            DateTime? originalInstallDate = workFullLengthLiningGateway.GetInstallDate(workIdFll);
                            DateTime? originalFinalVideoDate = workFullLengthLiningGateway.GetFinalVideoDate(workIdFll);
                            bool originalIssueIdentified = workFullLengthLiningGateway.GetIssueIdentified(workIdFll);
                            bool originalIssueLFS = workFullLengthLiningGateway.GetIssueLFS(workIdFll);
                            bool originalIssueClient = workFullLengthLiningGateway.GetIssueClient(workIdFll);
                            bool originalIssueSales = workFullLengthLiningGateway.GetIssueSales(workIdFll);
                            bool originalIssueGivenToClient = workFullLengthLiningGateway.GetIssueGivenToClient(workIdFll);
                            bool originalIssueResolved = workFullLengthLiningGateway.GetIssueResolved(workIdFll);
                            bool originalIssueInvestigation = workFullLengthLiningGateway.GetIssueInvestigation(workIdFll);

                            // ... Update work
                            UpdateFllWork(sectionAssetId, countryId, provinceId, countyId, cityId, workIdFll, originalClientId, originalProposedLiningDate, originalDeadlineLiningDate, originalP1Date, originalM1Date, originalM2Date, originalInstallDate, originalFinalVideoDate, originalIssueIdentified, originalIssueLFS, originalIssueClient, originalIssueSales, originalIssueGivenToClient, originalIssueResolved, originalIssueInvestigation, originalCxisRemoved, originalRoboticPrepCompleted, originalRoboticPrepCompletedDate, originalMeasurementTakenBy, originalTrafficControl, originalSiteDetails, originalPipeSizeChange, originalStandardBypass, originalStandardBypassComments, originalTrafficControlDetails, originalMeasurementType, originalMeasurementFromMh, originalVideoDoneFromMh, originalVideoDoneToMh, originalVideoDistance, originalComments, false, companyId, originalMaterial, originalAccessType, originalP1Completed, newClientId, originalProposedLiningDate, originalDeadlineLiningDate, newP1Date, newM1Date, originalM2Date, originalInstallDate, originalFinalVideoDate, originalIssueIdentified, originalIssueLFS, originalIssueClient, originalIssueSales, originalIssueGivenToClient, originalIssueResolved, originalIssueInvestigation, newCxisRemoved, newRoboticPrepCompleted, newRoboticPrepCompletedDate, newMeasurementTakenBy, newMaterial, newTrafficControl, newSiteDetails, newPipeSizeChange, newStandardBypass, newStandardBypassComments, newTrafficControlDetails, newMeasurementType, newMeasurementFromMh, newVideoDoneFromMh, newVideoDoneToMh, newVideoDistance, newComments, false, companyId, newAccessType, newP1Completed);
                            UpdateRaWork(workId, originalPreFlushDate, originalPreVideoDate, newPreFlushDate, newPreVideoDate, companyId);
                        }
                        else // ... Do not have Fll work
                        {
                            UpdateRaWork(workId, originalPreFlushDate, originalPreVideoDate, newPreFlushDate, newPreVideoDate, companyId);
                        }
                    }

                    // JL Section WorkID
                    int sectionWorkId = 0;
                    WorkGateway workGatewayForJL = new WorkGateway();
                    workGatewayForJL.LoadByProjectIdAssetIdWorkType(projectId, sectionAssetId, "Junction Lining Section", companyId);

                    if (workGatewayForJL.Table.Rows.Count > 0)
                    {
                        sectionWorkId = workGatewayForJL.GetWorkId(sectionAssetId, "Junction Lining Section", projectId);
                        WorkJunctionLiningSectionGateway workJunctionLiningSectionGateway = new WorkJunctionLiningSectionGateway();
                        workJunctionLiningSectionGateway.LoadByWorkId(sectionWorkId, companyId);

                        // get old values of section
                        int numLats = workJunctionLiningSectionGateway.GetNumLats(sectionWorkId);
                        int notLinedYet = workJunctionLiningSectionGateway.GetNotLinedYet(sectionWorkId);
                        bool allMeasured = workJunctionLiningSectionGateway.GetAllMeasured(sectionWorkId);
                        bool deleted = workJunctionLiningSectionGateway.GetDeleted(sectionWorkId);
                        string issueWithLaterals = workJunctionLiningSectionGateway.GetIssueWithLaterals(sectionWorkId);
                        int notMeasuredYet = workJunctionLiningSectionGateway.GetNotMeasuredYet(sectionWorkId);
                        int notDeliveredYet = workJunctionLiningSectionGateway.GetNotDeliveredYet(sectionWorkId);
                        string trafficControl = workJunctionLiningSectionGateway.GetTrafficControl(sectionWorkId);
                        string trafficControlDetails = workJunctionLiningSectionGateway.GetTrafficControlDetails(sectionWorkId);
                        bool standardBypass = workJunctionLiningSectionGateway.GetStandardBypass(sectionWorkId);
                        string standardBypassComments = workJunctionLiningSectionGateway.GetStandardBypassComments(sectionWorkId);
                        int availableToLine = workJunctionLiningSectionGateway.GetAvailableToLine(sectionWorkId);

                        WorkJunctionLiningSection workJunctionLiningSection = new WorkJunctionLiningSection(null);
                        workJunctionLiningSection.UpdateDirect(sectionWorkId, numLats, notLinedYet, allMeasured, deleted, issueWithLaterals, notMeasuredYet, notDeliveredYet, companyId, trafficControl, trafficControlDetails, standardBypass, standardBypassComments, availableToLine, numLats, notLinedYet, allMeasured, issueWithLaterals, notMeasuredYet, notDeliveredYet, newTrafficControl, newTrafficControlDetails, newStandardBypass, newStandardBypassComments, availableToLine);
                    }
                }
            }
        }
 // ////////////////////////////////////////////////////////////////////////
 // PUBLIC METHODS
 //
 /// <summary>
 /// LoadByWorkId
 /// </summary>
 /// <param name="workId">workId</param>
 /// <param name="companyId">companyId</param>
 public void LoadByWorkId(int workId, int companyId)
 {
     RehabAssessmentWorkDetailsGateway rehabAssessmentWorkDetailsGateway = new RehabAssessmentWorkDetailsGateway(Data);
     rehabAssessmentWorkDetailsGateway.LoadByWorkId(workId, companyId);
 }
        private void LoadWorkData(int workId, int assetId)
        {
            RehabAssessmentWorkDetailsGateway rehabAssessmentWorkDetailsGateway = new RehabAssessmentWorkDetailsGateway(rehabAssessmentTDS);

            if (rehabAssessmentWorkDetailsGateway.Table.Rows.Count > 0)
            {
                // For Header
                tbxVideoLength.Text = rehabAssessmentWorkDetailsGateway.GetVideoDistance(workId);

                // Load general data
                tbxGeneralClientId.Text = rehabAssessmentWorkDetailsGateway.GetClientId(workId);

                if (rehabAssessmentWorkDetailsGateway.GetP1Date(workId).HasValue)
                {
                    tkrdpPrepDataP1Date.SelectedDate = (DateTime)rehabAssessmentWorkDetailsGateway.GetP1Date(workId);
                }

                if (rehabAssessmentWorkDetailsGateway.GetM1Date(workId).HasValue)
                {
                    tkrdpM1DataM1Date.SelectedDate = (DateTime)rehabAssessmentWorkDetailsGateway.GetM1Date(workId);
                }

                // for RA data
                if (rehabAssessmentWorkDetailsGateway.GetPreFlushDate(workId).HasValue)
                {
                    tkrdpGeneralPreFlushDate.SelectedDate = (DateTime)rehabAssessmentWorkDetailsGateway.GetPreFlushDate(workId);
                }

                if (rehabAssessmentWorkDetailsGateway.GetPreVideoDate(workId).HasValue)
                {
                    tkrdpGeneralPreVideoDate.SelectedDate = (DateTime)rehabAssessmentWorkDetailsGateway.GetPreVideoDate(workId);
                }

                // For FullLengthLiningP1 data
                tbxPrepDataCXIsRemoved.Text = ""; if (rehabAssessmentWorkDetailsGateway.GetCxisRemoved(workId).HasValue) tbxPrepDataCXIsRemoved.Text = rehabAssessmentWorkDetailsGateway.GetCxisRemoved(workId).ToString();
                ckbxPrepDataRoboticPrepCompleted.Checked = rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompleted(workId);
                if (rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompletedDate(workId).HasValue)
                {
                    tkrdpPrepDataRoboticPrepCompletedDate.SelectedDate = (DateTime)rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompletedDate(workId);
                }
                ckbxPrepDataP1Completed.Checked = rehabAssessmentWorkDetailsGateway.GetP1Completed(workId);

                // For FullLengthLiningM1 data
                // ... for material
                ddlM1DataMaterial.SelectedValue = rehabAssessmentWorkDetailsGateway.GetMaterial(workId);

                // ... For m1 data
                tbxM1DataMeasurementsTakenBy.Text = rehabAssessmentWorkDetailsGateway.GetMeasurementTakenBy(workId);
                ddlM1DataTrafficControl.SelectedValue = rehabAssessmentWorkDetailsGateway.GetTrafficControl(workId);
                if (rehabAssessmentWorkDetailsGateway.GetSiteDetails(workId) == "") ddlM1DataSiteDetails.SelectedIndex = 0; else ddlM1DataSiteDetails.SelectedValue = rehabAssessmentWorkDetailsGateway.GetSiteDetails(workId);
                if (rehabAssessmentWorkDetailsGateway.GetAccessType(workId) == "") ddlM1DataAccessType.SelectedIndex = 0; else ddlM1DataAccessType.SelectedValue = rehabAssessmentWorkDetailsGateway.GetAccessType(workId);
                ckbxM1DataPipeSizeChange.Checked = rehabAssessmentWorkDetailsGateway.GetPipeSizeChange(workId);
                ckbxM1DataStandardBypass.Checked = rehabAssessmentWorkDetailsGateway.GetStandardBypass(workId);
                tbxM1DataStandardBypassComments.Text = rehabAssessmentWorkDetailsGateway.GetStandardBypassComments(workId);
                tbxM1DataTrafficControlDetails.Text = rehabAssessmentWorkDetailsGateway.GetTrafficControlDetails(workId);
                ddlM1DataMeasurementType.SelectedValue = rehabAssessmentWorkDetailsGateway.GetMeasurementType(workId);
                ddlM1DataMeasuredFromMh.SelectedValue = rehabAssessmentWorkDetailsGateway.GetMeasurementFromMh(workId);
                ddlM1DataVideoDoneFromMh.SelectedValue = rehabAssessmentWorkDetailsGateway.GetVideoDoneFromMh(workId);
                tbxM1DataMeasuredFromMh.Text = rehabAssessmentWorkDetailsGateway.GetMeasurementFromMh(workId);
                tbxM1DataVideoDoneFromMh.Text = rehabAssessmentWorkDetailsGateway.GetVideoDoneFromMh(workId);
                ddlM1DataVideoDoneToMh.SelectedValue = rehabAssessmentWorkDetailsGateway.GetVideoDoneToMh(workId);

                // For comments
                tbxCommentsDataComments.Text = rehabAssessmentWorkDetailsGateway.GetComments(workId);
            }
        }
        protected void Page_PreRender(object sender, EventArgs e)
        {
            // Set active toolbar
            mForm8 master = (mForm8)this.Master;
            master.ActiveToolbar = "eSewers";

            // For error message
            hdfErrorFieldList.Value = "";

            // For Video Done From MH and Measured From MH
            int companyId = Int32.Parse(hdfCompanyId.Value);
            int assetId = Int32.Parse(hdfAssetId.Value);
            int workId = Int32.Parse(hdfWorkId.Value);
            int workIdFll = Int32.Parse(hdfWorkIdFll.Value);
            int currentProjectId = Int32.Parse(hdfCurrentProjectId.Value.ToString());

            RehabAssessmentWorkDetailsGateway raWorkDetailsGateway = new RehabAssessmentWorkDetailsGateway();
            raWorkDetailsGateway.LoadByWorkId(workId, companyId);
            RehabAssessmentLateralDetails raLateralDetails = new RehabAssessmentLateralDetails();
            raLateralDetails.LoadForEdit(workIdFll, assetId, companyId, currentProjectId);

            if (Int32.Parse(tbxLaterals.Text) > 0)
            {
                ddlM1DataVideoDoneFromMh.Visible = false;
                tbxM1DataVideoDoneFromMh.Visible = true;
                tbxM1DataVideoDoneFromMh.Text = ddlM1DataVideoDoneFromMh.SelectedValue;

                ddlM1DataVideoDoneToMh.Visible = false;
                tbxM1DataVideoDoneToMh.Visible = true;
                tbxM1DataVideoDoneToMh.Text = ddlM1DataVideoDoneToMh.SelectedValue;

                ddlM1DataMeasuredFromMh.Visible = false;
                tbxM1DataMeasuredFromMh.Visible = true;
                tbxM1DataMeasuredFromMh.Text = ddlM1DataMeasuredFromMh.SelectedValue;

                btnClear.Visible = false;
            }
            else
            {
                ddlM1DataVideoDoneFromMh.Visible = true;
                tbxM1DataVideoDoneFromMh.Visible = false;

                ddlM1DataVideoDoneToMh.Visible = true;
                tbxM1DataVideoDoneToMh.Visible = false;

                ddlM1DataMeasuredFromMh.Visible = true;
                tbxM1DataMeasuredFromMh.Visible = false;

                btnClear.Visible = true;
            }

            // For materials
            // ... Load material for m1
            MaterialInformationGateway materialInformationGateway = new MaterialInformationGateway();
            materialInformationGateway.LoadLastMaterialByAssetId(assetId, companyId);

            if (materialInformationGateway.Table.Rows.Count > 0)
            {
                ddlM1DataMaterial.SelectedValue = materialInformationGateway.GetLastMaterialType(assetId);
            }

            // Hide or show the Old CWP ID field
            if (tbxOldCwpId.Text == "")
            {
                lblOldCwpId.Visible = false;
                tbxOldCwpId.Visible = false;
            }

            if (tbxFlowOrderId.Text == "")
            {
                LoadRehabAssessmentData(currentProjectId, assetId, companyId);
            }
        }
        private void LoadWorkData(int workId, int assetId)
        {
            RehabAssessmentWorkDetailsGateway rehabAssessmentWorkDetailsGateway = new RehabAssessmentWorkDetailsGateway(rehabAssessmentTDS);

            if (rehabAssessmentWorkDetailsGateway.Table.Rows.Count > 0)
            {
                // For Header
                tbxVideoLength.Text = rehabAssessmentWorkDetailsGateway.GetVideoDistance(workId);

                // Load general data
                tbxGeneralClientId.Text = rehabAssessmentWorkDetailsGateway.GetClientId(workId);

                tbxPrepDataP1Date.Text = "";
                if (rehabAssessmentWorkDetailsGateway.GetP1Date(workId).HasValue)
                {
                    DateTime p1Date = (DateTime)rehabAssessmentWorkDetailsGateway.GetP1Date(workId);
                    tbxPrepDataP1Date.Text = p1Date.Month.ToString() + "/" + p1Date.Day.ToString() + "/" + p1Date.Year.ToString();
                }

                tbxM1DataM1Date.Text = "";
                if (rehabAssessmentWorkDetailsGateway.GetM1Date(workId).HasValue)
                {
                    DateTime m1Date = (DateTime)rehabAssessmentWorkDetailsGateway.GetM1Date(workId);
                    tbxM1DataM1Date.Text = m1Date.Month.ToString() + "/" + m1Date.Day.ToString() + "/" + m1Date.Year.ToString();
                }

                // ... for RA data
                tbxGeneralPreFlushDate.Text = "";
                if (rehabAssessmentWorkDetailsGateway.GetPreFlushDate(workId).HasValue)
                {
                    DateTime preFlushDate = (DateTime)rehabAssessmentWorkDetailsGateway.GetPreFlushDate(workId);
                    tbxGeneralPreFlushDate.Text = preFlushDate.Month.ToString() + "/" + preFlushDate.Day.ToString() + "/" + preFlushDate.Year.ToString();
                }

                tbxGeneralPreVideoDate.Text = "";
                if (rehabAssessmentWorkDetailsGateway.GetPreVideoDate(workId).HasValue)
                {
                    DateTime preVideoDate = (DateTime)rehabAssessmentWorkDetailsGateway.GetPreVideoDate(workId);
                    tbxGeneralPreVideoDate.Text = preVideoDate.Month.ToString() + "/" + preVideoDate.Day.ToString() + "/" + preVideoDate.Year.ToString();
                }

                // For FullLengthLiningP1 data
                tbxPrepDataCXIsRemoved.Text = ""; if (rehabAssessmentWorkDetailsGateway.GetCxisRemoved(workId).HasValue) tbxPrepDataCXIsRemoved.Text = rehabAssessmentWorkDetailsGateway.GetCxisRemoved(workId).ToString();
                ckbxPrepDataRoboticPrepCompleted.Checked = rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompleted(workId);
                tbxPrepDataRoboticPrepCompletedDate.Text = "";
                if (rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompletedDate(workId).HasValue)
                {
                    DateTime prePrepDataRoboticPrepCompletedDate = (DateTime)rehabAssessmentWorkDetailsGateway.GetRoboticPrepCompletedDate(workId);
                    tbxPrepDataRoboticPrepCompletedDate.Text = prePrepDataRoboticPrepCompletedDate.Month.ToString() + "/" + prePrepDataRoboticPrepCompletedDate.Day.ToString() + "/" + prePrepDataRoboticPrepCompletedDate.Year.ToString();
                }
                ckbxPrepDataP1Completed.Checked = rehabAssessmentWorkDetailsGateway.GetP1Completed(workId);

                // For FullLengthLiningM1 data
                // ... for material
                tbxM1DataMaterial.Text = rehabAssessmentWorkDetailsGateway.GetMaterial(workId);

                // ... For m1 data
                tbxM1DataMeasurementsTakenBy.Text = rehabAssessmentWorkDetailsGateway.GetMeasurementTakenBy(workId);
                tbxM1DataTrafficControl.Text = rehabAssessmentWorkDetailsGateway.GetTrafficControl(workId);
                tbxM1DataSiteDetails.Text = rehabAssessmentWorkDetailsGateway.GetSiteDetails(workId);
                tbxM1DataAccessType.Text = rehabAssessmentWorkDetailsGateway.GetAccessType(workId);
                ckbxM1DataPipeSizeChange.Checked = rehabAssessmentWorkDetailsGateway.GetPipeSizeChange(workId);
                ckbxM1DataStandardBypass.Checked = rehabAssessmentWorkDetailsGateway.GetStandardBypass(workId);
                //tbxM1DataIssue.Text = GetIssueSelected (rehabAssessmentWorkDetailsGateway.GetIssue(workId));
                tbxM1DataStandardBypassComments.Text = rehabAssessmentWorkDetailsGateway.GetStandardBypassComments(workId);
                tbxM1DataTrafficControlDetails.Text = rehabAssessmentWorkDetailsGateway.GetTrafficControlDetails(workId);
                tbxM1DataMeasurementType.Text = rehabAssessmentWorkDetailsGateway.GetMeasurementType(workId);
                tbxM1DataMeasuredFromMH.Text = rehabAssessmentWorkDetailsGateway.GetMeasurementFromMh(workId);
                hdfMeasuredFrom.Value = rehabAssessmentWorkDetailsGateway.GetMeasurementFromMh(workId);
                tbxM1DataVideoDoneFromMH.Text = rehabAssessmentWorkDetailsGateway.GetVideoDoneFromMh(workId);
                tbxM1DataToMH.Text = rehabAssessmentWorkDetailsGateway.GetVideoDoneToMh(workId);

                //tbxM1DataRoboticPrepDate.Text = "";
                //if (rehabAssessmentWorkDetailsGateway.GetRoboticPrepDate(workId).HasValue)
                //{
                //    DateTime roboticPrepDate = (DateTime)rehabAssessmentWorkDetailsGateway.GetRoboticPrepDate(workId);
                //    tbxM1DataRoboticPrepDate.Text = roboticPrepDate.Month.ToString() + "/" + roboticPrepDate.Day.ToString() + "/" + roboticPrepDate.Year.ToString();
                //}

                // For comments
                tbxCommentsDataComments.Text = rehabAssessmentWorkDetailsGateway.GetComments(workId);
            }
        }