private void Page_Load(object sender, System.EventArgs e)
        {
            string sDomenName, sReportPath;

            try
            {
                OrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);

                if (Session["reload"] != null)
                {
                    if ((bool)Session["reload"] == true)
                    {
                        Session["reload"] = null;
                        Response.Redirect((string)Session["RedirectPath"], false);
                        Session["RedirectPath"] = null;
                        return;
                    }
                }

                if (Request.QueryString["id"] == null || Request.QueryString["inspectid"] == null)
                {
                    Session["lastpage"] = "main.aspx";
                    Session["error"]    = _functions.ErrorMessage(104);
                    Response.Redirect("error.aspx", false);
                    return;
                }
                try
                {
                    OrderId   = Convert.ToInt32(Request.QueryString["id"]);
                    InspectId = Convert.ToInt32(Request.QueryString["inspectid"]);
                }
                catch (FormatException fex)
                {
                    Session["lastpage"] = "main.aspx";
                    Session["error"]    = _functions.ErrorMessage(105);
                    Response.Redirect("error.aspx", false);
                    return;
                }

                // getting the Bread Crumbs from Cookie and add last item
                if (Request.Cookies.Count > 0 && Request.Cookies["bfp_navigate"] != null)
                {
                    Header.BrdCrumbsSerialization = Request.Cookies["bfp_navigate"].Value;
                }
                Header.AddBreadCrumb("Work Order Detail", "/wo_viewWorkOrder.aspx?id=" + OrderId.ToString());

                SaveCancelControl.ParentPageURL = ParentPageURL;
                SaveCancelControl.EnableSave    = true;
                SaveCancelControl.ButtonText    = " Complete/Sign ";
                SaveCancelControl.CancelText    = " Back ";

                if (!IsPostBack)
                {
                    sReportPath = _functions.GetValueFromConfig("SQLRS.Folder");
                    hlPrintInspectRequest.NavigateUrl   = "ReportViewer.aspx?Report=" + sReportPath + "%2fInspectionRequest&OrgId=" + OrgId.ToString() + "&OrderId=" + OrderId.ToString() + "&InspectId=" + InspectId.ToString();
                    hlPrintCompletedInstect.NavigateUrl = "ReportViewer.aspx?Report=" + sReportPath + "%2fCompletedInspection&OrgId=" + OrgId.ToString() + "&OrderId=" + OrderId.ToString() + "&InspectId=" + InspectId.ToString();

                    user                = new clsUsers();
                    order               = new clsWorkOrders();
                    order.iOrgId        = OrgId;
                    order.iId           = OrderId;
                    order.iInspectionId = InspectId;
                    order.iTechId       = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true);
                    switch (order.GetInfoForInspection())
                    {
                    case 1:
                        tableMain.Rows[19].Visible   = false;
                        tableMain.Rows[20].Visible   = false;
                        tableMain.Rows[21].Visible   = false;
                        tableMain.Rows[22].Visible   = true;
                        tableMain.Rows[23].Visible   = true;
                        tableMain.Rows[24].Visible   = false;
                        tableMain.Rows[25].Visible   = false;
                        SaveCancelControl.EnableSave = false;

                        order.iDocumentId     = InspectId;
                        order.iDocumentTypeId = (int)DocumentTypes.InspectionCompleted;
                        if (order.GetSignedDocument() != -1)
                        {
                            hlPrintInspectRequest.Enabled   = false;
                            hlPrintCompletedInstect.Enabled = true;
                            lblSign.Text     = order.sUserName.Value;
                            lblSignDate.Text = order.daReportDate.Value.ToShortDateString() + " " + order.daReportDate.Value.ToShortTimeString();
                        }
                        else
                        {
                            hlPrintInspectRequest.Enabled   = true;
                            hlPrintCompletedInstect.Enabled = false;
                            lblSign.Text = "                  ";
                        }
                        break;

                    case -1:
                        Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                        Session["error"]    = _functions.ErrorMessage(124);
                        Response.Redirect("error.aspx", false);
                        return;

                    default:
                        hlPrintCompletedInstect.Enabled = false;
                        adtInspection.Date         = DateTime.Now;
                        tableMain.Rows[22].Visible = false;
                        break;
                    }
                    if (!user.IsTechnician(_functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true)))
                    {
                        SaveCancelControl.EnableSave = false;
                    }
                    ViewState["EquipId"] = order.iEquipId.Value;
                    ViewState["InspectSchedDetailId"] = order.iInspectSchedDetailId.Value;
                    lblInspectName.Text     = order.sInspectionName.Value;
                    lblInspectSchedule.Text = order.sInspectSchedule.Value;
                    lblTargetDaysOut.Text   = order.iInspectTargetDays.Value.ToString() + " days";
                    lblEquipId.Text         = order.sEquipId.Value;
                    lblEquipMake.Text       = order.sEquipMake.Value;
                    lblEquipModel.Text      = order.sEquipModel.Value;

                    repInspectItems.DataSource = new DataView(order.GetWorkOrderInspectItems());
                    repInspectItems.DataBind();
                }
            }
            catch (Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"]     = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                Session["error"]        = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if (user != null)
                {
                    user.Dispose();
                }
                if (order != null)
                {
                    order.Dispose();
                }
            }
        }