/// ////////////////////////////////////////////////////////////////////////
        /// PUBLIC METHODS
        ///
        public ViewJLinersheetTDS.JunctionLinerDataTable GetJlinerNew()
        {
            jliner = (ViewJLinersheetTDS.JunctionLinerDataTable)Session["jlinerDummy"];
            if (jliner == null)
            {
                jliner = (ViewJLinersheetTDS.JunctionLinerDataTable)Session["jliner"];
            }

            return jliner;
        }
        protected void AddJlinersheetNewEmptyFix(GridView grdView)
        {
            if (grdView.Rows.Count == 0)
            {
                ViewJLinersheetTDS.JunctionLinerDataTable dt = new ViewJLinersheetTDS.JunctionLinerDataTable();
                dt.AddJunctionLinerRow(Guid.NewGuid(), -1, -1, "", "", -1, "", "", "", false, false, false, "", "", false, false, false, false, new DateTime(), "", "", new DateTime(), new DateTime(), false, false, false, -1, "", false, false, false);
                Session["jlinerDummy"] = dt;

                grdView.DataBind();
            }

            // normally executes at all postbacks
            if (grdView.Rows.Count == 1)
            {
                ViewJLinersheetTDS.JunctionLinerDataTable dt = (ViewJLinersheetTDS.JunctionLinerDataTable)Session["jlinerDummy"];
                if (dt != null)
                {
                    grdView.Rows[0].Visible = false;
                    grdView.Rows[0].Controls.Clear();
                }
            }
        }
        private void GrdJlinerSheetAdd()
        {
            if (ValidateFooter())
            {
                Page.Validate("dataFooter");
                if (Page.IsValid)
                {
                    Guid id = new Guid(tbxID.Text);
                    int companyId = Convert.ToInt32(Session["companyID"]);
                    ViewJLinersheetJunctionLiner viewJLinersheetJunctionLinerForDetailId = new ViewJLinersheetJunctionLiner(viewJLinersheetTDS);
                    string detailId = viewJLinersheetJunctionLinerForDetailId.GetNewDetailId(viewJLinersheetTDS);
                    string mn = ""; if (((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxMnFooter")).Text.Trim() != "") mn = ((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxMnFooter")).Text.Trim();
                    double? distanceFromUsmh = null; if (((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxDistanceFromUsmhFooter")).Text.Trim() != "") distanceFromUsmh = double.Parse(((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxDistanceFromUsmhFooter")).Text.Trim());
                    string confirmedLatSize = ""; if (((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxConfirmedLatSizeFooter")).Text.Trim() != "") confirmedLatSize = ((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxConfirmedLatSizeFooter")).Text.Trim();
                    string lateralMaterial = ""; if (((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxLateralMaterialFooter")).Text.Trim() != "") lateralMaterial = ((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxLateralMaterialFooter")).Text.Trim();
                    string sharedLateral = ""; if (((DropDownList)grdJlinerSheet.FooterRow.FindControl("ddlSharedLateralFooter")).Text.Trim() != "") sharedLateral = ((DropDownList)grdJlinerSheet.FooterRow.FindControl("ddlSharedLateralFooter")).SelectedValue;
                    bool cleanoutRequired = ((CheckBox)grdJlinerSheet.FooterRow.FindControl("ckbxCleanoutRequiredFooter")).Checked;
                    bool pitRequired = ((CheckBox)grdJlinerSheet.FooterRow.FindControl("ckbxPitRequiredFooter")).Checked;
                    bool mHShot = ((CheckBox)grdJlinerSheet.FooterRow.FindControl("ckbxMhShotFooter")).Checked;
                    string mainConnection = ""; if (((DropDownList)grdJlinerSheet.FooterRow.FindControl("ddlMainConnectionFooter")).Text.Trim() != "") mainConnection = ((DropDownList)grdJlinerSheet.FooterRow.FindControl("ddlMainConnectionFooter")).SelectedValue;
                    string transition = ""; if (((DropDownList)grdJlinerSheet.FooterRow.FindControl("ddlTransitionFooter")).Text.Trim() != "") transition = ((DropDownList)grdJlinerSheet.FooterRow.FindControl("ddlTransitionFooter")).SelectedValue;
                    bool cleanoutInstalled = ((CheckBox)grdJlinerSheet.FooterRow.FindControl("ckbxCleanoutInstalledFooter")).Checked;
                    bool pitInstalled = ((CheckBox)grdJlinerSheet.FooterRow.FindControl("ckbxPitInstalledFooter")).Checked;
                    bool cleanoutGrouted = ((CheckBox)grdJlinerSheet.FooterRow.FindControl("ckbxCleanoutGroutedFooter")).Checked;
                    bool cleanoutCored = ((CheckBox)grdJlinerSheet.FooterRow.FindControl("ckbxCleanoutCoredFooter")).Checked;
                    DateTime? prepCompleted = null; if (((RadDatePicker)grdJlinerSheet.FooterRow.FindControl("tkrdpPrepCompletedFooter")).SelectedDate.HasValue) prepCompleted = ((RadDatePicker)grdJlinerSheet.FooterRow.FindControl("tkrdpPrepCompletedFooter")).SelectedDate.Value;
                    string measuredLatLength = ""; if (((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxMeasuredLatLengthFooter")).Text.Trim() != "") measuredLatLength = ((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxMeasuredLatLengthFooter")).Text.Trim();
                    string measurementsTakenBy = ""; if (((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxMeasurementsTakenByFooter")).Text.Trim() != "") measurementsTakenBy = ((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxMeasurementsTakenByFooter")).Text.Trim();
                    DateTime? linerInstalled = null; if (((RadDatePicker)grdJlinerSheet.FooterRow.FindControl("tkrdpLinerInstalledFooter")).SelectedDate.HasValue) linerInstalled = ((RadDatePicker)grdJlinerSheet.FooterRow.FindControl("tkrdpLinerInstalledFooter")).SelectedDate.Value;
                    DateTime? finalVideo = null; if (((RadDatePicker)grdJlinerSheet.FooterRow.FindControl("tkrdpFinalVideoFooter")).SelectedDate.HasValue) finalVideo = ((RadDatePicker)grdJlinerSheet.FooterRow.FindControl("tkrdpFinalVideoFooter")).SelectedDate.Value;
                    bool restorationComplete = ((CheckBox)grdJlinerSheet.FooterRow.FindControl("ckbxRestorationCompleteFooter")).Checked;
                    bool linerOrdered = ((CheckBox)grdJlinerSheet.FooterRow.FindControl("ckbxLinerOrderedFooter")).Checked;
                    bool linerInStock = ((CheckBox)grdJlinerSheet.FooterRow.FindControl("ckbxLinerInStockFooter")).Checked;
                    decimal? linerPrice = null; if (((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxLinerPriceFooter")).Text.Trim() != "") linerPrice = decimal.Parse(((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxLinerPriceFooter")).Text.Trim());
                    string comments = ""; if (((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxCommentFooter")).Text.Trim() != "") comments = ((TextBox)grdJlinerSheet.FooterRow.FindControl("tbxCommentFooter")).Text.Trim();
                    bool archived = false;
                    bool deleted = false;
                    bool inDatabase = false;

                    ViewJLinersheetJunctionLiner model = new ViewJLinersheetJunctionLiner(viewJLinersheetTDS);
                    model.Insert(id, companyId, detailId, mn, distanceFromUsmh, confirmedLatSize, lateralMaterial, sharedLateral, cleanoutRequired, pitRequired, mHShot, mainConnection, transition, cleanoutInstalled, pitInstalled, cleanoutGrouted, cleanoutCored, prepCompleted, measuredLatLength, measurementsTakenBy, linerInstalled, finalVideo, restorationComplete, linerOrdered, linerInStock, linerPrice, comments, deleted, archived, inDatabase);

                    Session.Remove("jlinerDummy");
                    Session["viewJLinersheetTDS"] = viewJLinersheetTDS;
                    jliner = viewJLinersheetTDS.JunctionLiner;
                    Session["jliner"] = jliner;

                    grdJlinerSheet.DataBind();
                    grdJlinerSheet.PageIndex = grdJlinerSheet.PageCount - 1;
                }
            }
        }
        /// ////////////////////////////////////////////////////////////////////////
        /// EVENTS
        ///
        protected void Page_Load(object sender, System.EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

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

                // Prepare initial data
                Session.Remove("jlinerDummy");
                lblMaxNumber.Visible = false;

                // If coming from navigator2.aspx or view_jlinersheet.aspx
                if (((string)Request.QueryString["source_page"] == "navigator2.aspx") || ((string)Request.QueryString["source_page"] == "view_jlinersheet.aspx"))
                {
                    //... Get lfs master area record
                    LFSRecordGateway lfsRecordGateway = new LFSRecordGateway();
                    viewJLinersheetTDS = new ViewJLinersheetTDS();

                    ViewJLinersheetJunctionLinerGateway viewJLinersheetJunctionLinerGateway = new ViewJLinersheetJunctionLinerGateway(viewJLinersheetTDS);
                    viewJLinersheetJunctionLinerGateway.LoadById((Guid)Session["lfsMasterAreaId"], Convert.ToInt32(Session["companyID"]));

                    tdsLfsRecord = lfsRecordGateway.GetRecordByIdCompanyId((Guid)Session["lfsMasterAreaId"], Convert.ToInt32(Session["companyID"]));

                    //... Store datasets
                    Session["tdsLfsRecord"] = tdsLfsRecord;
                    Session["viewJLinersheetTDS"] = viewJLinersheetTDS;
                    jliner = viewJLinersheetTDS.JunctionLiner;
                    Session["jliner"] = jliner;
                }

                // If coming from delete_record.aspx
                if ((string)Request.QueryString["record_deleted"] == "false")
                {
                    //... Restore dataset lfs record
                    tdsLfsRecord = (TDSLFSRecord)Session["tdsLfsRecord"];
                    viewJLinersheetTDS = (ViewJLinersheetTDS)Session["viewJLinersheetTDS"];
                }

                // ... for client
                CompaniesGateway companiesGateway = new CompaniesGateway();
                tbxCOMPANIES_ID.Text = companiesGateway.GetName((int)tdsLfsRecord.LFS_MASTER_AREA.Rows[0]["COMPANIES_ID"], Convert.ToInt32(Session["companyID"]));

                // Databind
                Page.DataBind();

                ddlMainLined.SelectedIndex = (tdsLfsRecord.LFS_MASTER_AREA[0].IsMainLinedNull()) ? 2 : ((tdsLfsRecord.LFS_MASTER_AREA[0].MainLined == "Yes") ? 0 : 1);
                ddlBenchingIssue.SelectedIndex = (tdsLfsRecord.LFS_MASTER_AREA[0].IsBenchingIssueNull()) ? 2 : ((tdsLfsRecord.LFS_MASTER_AREA[0].BenchingIssue == "Yes") ? 0 : 1);
            }
            else
            {
                //--- Restore dataset lfs record
                tdsLfsRecord = (TDSLFSRecord)Session["tdsLfsRecord"];
                viewJLinersheetTDS = (ViewJLinersheetTDS)Session["viewJLinersheetTDS"];
            }
        }