public JlLiningPlanTDS.JlLiningPlanJlinerDataTable GetJlinersNew()
        {
            jlLiners = (JlLiningPlanTDS.JlLiningPlanJlinerDataTable)Session["jlLinersDummy"];
            if (jlLiners == null)
            {
                jlLiners = ((JlLiningPlanTDS.JlLiningPlanJlinerDataTable)Session["jlLiners"]);
            }

            return jlLiners;
        }
        protected void AddJlinersNewEmptyFix(GridView grdLiningPlanLiners)
        {
            if (grdLiningPlanLiners.Rows.Count == 0)
            {
                JlLiningPlanTDS.JlLiningPlanJlinerDataTable dt = new JlLiningPlanTDS.JlLiningPlanJlinerDataTable();
                dt.AddJlLiningPlanJlinerRow(-1, -1, -1, "", "", "",  "", "",  "", "", "", "", "", "", 30, "", "", 0, "");
                Session["jlLinersDummy"] = dt;

                grdLiningPlanLiners.DataBind();
            }

            // Normally executes at all postbacks
            if (grdLiningPlanLiners.Rows.Count == 1)
            {
                JlLiningPlanTDS.JlLiningPlanJlinerDataTable dt = (JlLiningPlanTDS.JlLiningPlanJlinerDataTable)Session["jlLinersDummy"];
                if (dt != null)
                {
                    grdLiningPlanLiners.Rows[0].Visible = false;
                    grdLiningPlanLiners.Rows[0].Controls.Clear();
                }
            }
        }
        // ////////////////////////////////////////////////////////////////////////
        // EVENTS
        //
        protected void Page_Load(object sender, EventArgs e)
        {
            // Register client scripts
            this.RegisterClientScripts();

            if (!IsPostBack)
            {
                // Security check
                if (!(Convert.ToBoolean(Session["sgLFS_CWP_JUNCTIONLINING_VIEW"]) && Convert.ToBoolean(Session["sgLFS_CWP_JUNCTIONLINING_EDIT"])))
                {
                    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_id"] == null) || ((string)Request.QueryString["project_id"] == null)|| ((string)Request.QueryString["work_type"] == null))
                {
                    Response.Redirect("./../../error_page.aspx?error=" + "Invalid query string in jl_lining_plan_laterals.aspx");
                }

                // Tag Page
                hdfCompanyId.Value = Session["companyID"].ToString();
                hdfCurrentProjectId.Value = Request.QueryString["project_id"].ToString();
                hdfCurrentClientId.Value = Request.QueryString["client_id"].ToString();
                hdfWorkType.Value = Request.QueryString["work_type"].ToString();

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

                // If coming from
                if (Request.QueryString["source_page"] == "jl_lining_plan.aspx")
                {
                    // ... for the grid
                    jlLiningPlanTDS = (JlLiningPlanTDS)Session["jlLiningPlanTDS"];
                    jlLiners = jlLiningPlanTDS.JlLiningPlanJliner;

                    // Load data
                    int companyId = Int32.Parse(hdfCompanyId.Value);
                    JlLiningPlanJliner jlLiningPlanJliner  =  new JlLiningPlanJliner();
                    jlLiningPlanJliner.LoadLiners(jlLiningPlanTDS, companyId);

                    jlLiningPlanTDS.JlLiningPlanJliner.DefaultView.Sort = " ParentInstallOrder DESC";

                    // Store dataset
                    Session["jlLiningPlanTDS"] = jlLiningPlanTDS;
                    jlLiners = jlLiningPlanTDS.JlLiningPlanJliner;
                    Session["jlLiners"] = jlLiners;
                    grdLiningPlanLiners.DataBind();

                    // Check results
                    JlLiningPlanJlinerGateway jlLiningPlanJlinerGateway = new JlLiningPlanJlinerGateway(jlLiningPlanTDS);
                    if (jlLiningPlanJlinerGateway.Table.Rows.Count > 0)
                    {
                        tdNoResults.Visible = false;
                        btnPreview.Visible = true;
                        btnOrder.Visible = true;
                        ddlOrder.Visible = true;
                        lblOrder.Visible = true;
                    }
                    else
                    {
                        tdNoResults.Visible = true;
                        btnPreview.Visible = false;
                        btnOrder.Visible = false;
                        ddlOrder.Visible = false;
                        lblOrder.Visible = false;
                    }
                }
            }
            else
            {
                // Restore datasets
                jlLiningPlanTDS = (JlLiningPlanTDS)Session["jlLiningPlanTDS"];
                jlLiners = jlLiningPlanTDS.JlLiningPlanJliner;

                // Store
                Session["jlLiners"] = jlLiningPlanTDS.JlLiningPlanJliner;
            }
        }