/// ////////////////////////////////////////////////////////////////////////
        /// STEP3 - JLINER - PUBLIC METHODS
        ///
        public JlinerAddTDS.JunctionLiner2DataTable GetJlinerNew()
        {
            jliner2 = (JlinerAddTDS.JunctionLiner2DataTable)Session["jliner2Dummy"];
            if (jliner2 == null)
            {
                jliner2 = (JlinerAddTDS.JunctionLiner2DataTable)Session["jliner2"];
            }

            return jliner2;
        }
        protected void AddJlinerNewEmptyFix(GridView grdView)
        {
            if (grdView.Rows.Count == 0)
            {
                JlinerAddTDS.JunctionLiner2DataTable dt = new JlinerAddTDS.JunctionLiner2DataTable();
                dt.AddJunctionLiner2Row(Guid.NewGuid(), -1, -1, "", "", new DateTime(), new DateTime(), new DateTime(), new DateTime(), new DateTime(), new DateTime(), new DateTime(), new DateTime(), new DateTime(), "", new DateTime(), new DateTime(), new DateTime(), -1, new DateTime(), new DateTime(), new DateTime(), -1, -1, "", "", -1, false, new DateTime(), false, false, "", false, "", "", new DateTime(), new DateTime(), "", "", false, "", new DateTime(), false);
                Session["jliner2Dummy"] = dt;

                grdView.DataBind();
            }

            // normally executes at all postbacks
            if (grdView.Rows.Count == 1)
            {
                JlinerAddTDS.JunctionLiner2DataTable dt = (JlinerAddTDS.JunctionLiner2DataTable)Session["jliner2Dummy"];
                if (dt != null)
                {
                    grdView.Rows[0].Visible = false;
                    grdView.Rows[0].Controls.Clear();
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // STEP3 - JLINER - PRIVATE METHODS
        //
        private void StepJlinerIn()
        {
            // Set instruction
            mWizard2 master = (mWizard2)this.Master;
            master.WizardInstruction = "Please add laterals";

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

            // ... for Section
            string recordId = hdfRecordId.Value;
            Guid id = new Guid(hdfSelectedId.Value);

            hdfID.Value = id.ToString();
            tbxRecordId.Text = recordId;
            tbxStreet.Text = hdfStreet.Value;
            tbxActualLength.Text = hdfActualLength.Value;
            tbxUSMH.Text = hdfUsmh.Value;
            tbxDSMH.Text = hdfDsmh.Value;

            // ... for Jliner
            int companyId = Int32.Parse(Session["companyID"].ToString());
            JlinerAddJunctionLiner2 jlinerAddJunctionLiner2 = new JlinerAddJunctionLiner2(jlinerAddTDS);
            jlinerAddJunctionLiner2.LoadForAdd(id, companyId);

            Session["jlinerAddTDS"] = jlinerAddTDS;
            jliner2 = jlinerAddTDS.JunctionLiner2;
            Session["jliner2"] = jliner2;
            grdJliner2.DataBind();
        }
        private void GrdJLinerAdd()
        {
            Page.Validate("dataFooter");
            if (Page.IsValid)
            {
                if (ValidateJlinerFooter())
                {
                    Guid id = new Guid(hdfSelectedId.Value);
                    int companyId = Convert.ToInt32(Session["companyID"]);
                    string detailId = ""; if (((TextBox)grdJliner2.FooterRow.FindControl("tbxDetailIdFooter")).Text.Trim() != "") detailId = ((TextBox)grdJliner2.FooterRow.FindControl("tbxDetailIdFooter")).Text.Trim();
                    string address = ""; if (((TextBox)grdJliner2.FooterRow.FindControl("tbxAddressFooter")).Text.Trim() != "") address = ((TextBox)grdJliner2.FooterRow.FindControl("tbxAddressFooter")).Text.Trim();
                    double? distanceFromUSMH = null; if (((TextBox)grdJliner2.FooterRow.FindControl("tbxDistanceFromUSMHFooter")).Text.Trim() != "") distanceFromUSMH = double.Parse(((TextBox)grdJliner2.FooterRow.FindControl("tbxDistanceFromUSMHFooter")).Text.Trim());
                    int buildRebuild = 0;
                    bool inDatabase = false;
                    string issue = "No";

                    // Calculate fields
                    double? distanceFromDSMH = null;
                    if (distanceFromUSMH.HasValue)
                    {
                        Distance length = new Distance(tbxActualLength.Text.Trim()) - new Distance(distanceFromUSMH.ToString());
                        distanceFromDSMH = length.ToDoubleInEng3();
                    }

                    JlinerAddJunctionLiner2 model = new JlinerAddJunctionLiner2(jlinerAddTDS);
                    model.Insert(id, companyId, detailId, address, null, null, null, null, null, null, null, null, null, "", null, null, null, buildRebuild, null, null, null, distanceFromUSMH, distanceFromDSMH, "", issue, null, false, null, false, false, "", false, "", "", null, null, "", "", false, "", null, inDatabase);

                    Session.Remove("jliner2Dummy");
                    Session["jlinerAddTDS"] = jlinerAddTDS;
                    jliner2 = jlinerAddTDS.JunctionLiner2;
                    masterArea = jlinerAddTDS.MasterArea;
                    Session["masterArea"] = masterArea;

                    grdJliner2.DataBind();
                    grdJliner2.PageIndex = grdJliner2.PageCount - 1;
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // INITIAL 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_ADD"])))
                {
                    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 jliner_add.aspx");
                }

                // Tag page
                ViewState["client"] = Request.QueryString["client"];

                // Prepare initial data
                jlinerAddTDS = new JlinerAddTDS();
                Session.Remove("masterAreaDummy");
                Session.Remove("jliner2Dummy");

                // ... Initialize viewstate variables
                ViewState["StepFrom"] = "Out";

                // StepSection1In
                wizard.ActiveStepIndex = 0;
                StepSection1In();

                // Create and store datasets
                sectionTDS = new SectionTDS();
                Session["sectionTDSForJlinerAdd"] = sectionTDS;

                Session["jlinerAddTDS"] = jlinerAddTDS;
                masterArea = jlinerAddTDS.MasterArea;
                Session["masterArea"] = masterArea;

                jliner2 = jlinerAddTDS.JunctionLiner2;
                Session["jliner2"] = jliner2;
            }
            else
            {
                // Restore datasets
                sectionTDS = (SectionTDS)Session["sectionTDSForJlinerAdd"];
                jlinerAddTDS = (JlinerAddTDS)Session["jlinerAddTDS"];
            }
        }