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

                #region Header Section
                OrgId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, false);

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

                if((string)Session["PathToViewOrder"] != "Monthly-Daily")
                    l_iCount = 2;
                else
                    l_iCount = 3;

                Header.AddJavaScriptFile("/OpenWindows.js");

                Header.AddBreadCrumb("Home", "/main.aspx");

                switch((string)Session["PathToViewOrder"])
                {
                    case "Monthly-Daily":
                        Header.AddBreadCrumb("Monthly Work Orders View", "/wo_showOrdersForMonthly.aspx");
                        Header.AddBreadCrumb("Daily Work Orders View", "/wo_showOrdersForDaily.aspx");
                        m_sLastPage = "wo_showOrdersForDaily.aspx";
                        break;
                    case "Monthly":
                        Header.AddBreadCrumb("Monthly Work Orders View", "/wo_showOrdersForMonthly.aspx");
                        m_sLastPage = "wo_showOrdersForMonthly.aspx";
                        break;
                    case "Daily":
                        Header.AddBreadCrumb("Daily Work Orders View", "/wo_showOrdersForDaily.aspx");
                        m_sLastPage = "wo_showOrdersForDaily.aspx";
                        break;
                    case "Today":
                        Header.AddBreadCrumb("Work Orders Overview", "/wo_showOrdersForToday.aspx");
                        m_sLastPage = "wo_showOrdersForToday.aspx";
                        break;
                    case "Weekly":
                        Header.AddBreadCrumb("Weekly Work Orders View", "/wo_showOrdersForWeekly.aspx");
                        m_sLastPage = "wo_showOrdersForWeekly.aspx";
                        break;
                    case "Scheduled":
                        Header.AddBreadCrumb("The Scheduled Orders", "/wo_showUnassignedOrders.aspx");
                        m_sLastPage = "wo_showUnassignedOrders.aspx";
                        break;
                    case "Completed":
                        Header.AddBreadCrumb("Completed Work Orders", "/wo_showCompletedOrders.aspx");
                        m_sLastPage = "wo_showCompletedOrders.aspx";
                        break;
                    case "EquipWOReport":
                        Header.AddBreadCrumb("Equipment Work Order Report", "/wo_viewEquipWorkOrderReport.aspx");
                        m_sLastPage = "wo_viewEquipWorkOrderReport.aspx";
                        break;
                    default:
                        Header.AddBreadCrumb("Work Orders Overview", "/wo_showOrdersForToday.aspx");
                        m_sLastPage = "wo_showOrdersForToday.aspx";
                        break;
                }
                Response.Cookies["bfp_navigate"].Value = Header.BrdCrumbsSerialization;
                Response.Cookies["bfp_navigate"].Path = "/";
                Response.Cookies["bfp_navigate"].Expires = DateTime.Now.AddYears(1);
                //Session["BrdCrumbs"] = arrBrdCrumbs;
                #endregion

                if(!IsPostBack)
                {
                    dtCustomFields = new DataTable();
                    dtCustomFields.Columns.Add("ValueName");
                    dtCustomFields.Columns.Add("Value");

                    order = new clsWorkOrders();
                    user = new clsUsers();
                    order.cAction = "S";
                    order.iOrgId = OrgId;
                    order.iId = OrderId;
                    if(order.WorkOrderDetails() == -1)
                    {
                        Session["lastpage"] = m_sLastPage;
                        Session["error"] = _functions.ErrorMessage(120);
                        Response.Redirect("error.aspx", false);
                        return;
                    }

                    #region Processing of the Operation Area

                    hlMainEdit.NavigateUrl = "wo_editWorkOrder.aspx?id=" + OrderId.ToString();
                    hlCloseOrder.NavigateUrl = "wo_closeWorkOrder.aspx?id=" + OrderId.ToString();
                    hlOpenOrder.NavigateUrl = "wo_openWorkOrder.aspx?id=" + OrderId.ToString();
                    hlDeleteOrder.NavigateUrl = "wo_deleteWorkOrder.aspx?id=" + OrderId.ToString();

                    hlCheckIn.NavigateUrl = "wo_viewCheckIn.aspx?id=" + OrderId.ToString();
                    hlCheckOut.NavigateUrl = "wo_viewCheckOut.aspx?id=" + OrderId.ToString();
                    hlTimeLog.NavigateUrl = "wo_updateTimeLog.aspx?id=" + OrderId.ToString();

                    hlReportedIssues.NavigateUrl = "wo_addRepairs.aspx?id=" + OrderId.ToString() + "&back=view";
                    hlPMItems.NavigateUrl  = "wo_addPreventiveMaintenance.aspx?id=" + OrderId.ToString() + "&back=view";
                    hlInspections.NavigateUrl = "wo_addInspections.aspx?id=" + OrderId.ToString() + "&back=view";

                    sReportPath = _functions.GetValueFromConfig("SQLRS.Folder");
                    hlPrintPartUsed.NavigateUrl = "ReportViewer.aspx?Report=" + sReportPath + "%2fPartsList&OrderId=" + OrderId.ToString() + "&OrgId=" + OrgId.ToString();
                    hlPrintOrderRequest.NavigateUrl = "ReportViewer.aspx?Report=" + sReportPath + "%2fWorkOrderRequest&OrderId=" + OrderId.ToString() + "&OrgId=" + OrgId.ToString();
                    hlPrintCompletedOrder.NavigateUrl = "ReportViewer.aspx?Report=" + sReportPath + "%2fCompletedOrder&OrderId=" + OrderId.ToString()+ "&OrgId=" + OrgId.ToString();

                    hlAddRepair.NavigateUrl = "wo_updateRepair.aspx?mode=Edit&repairid=0&inspectid=0&type=FREE&op=Repair&id=" + OrderId.ToString() + "&itemid=0";

                    status = (WorkOrderStatus)order.iStatusId.Value;
                    opstatus = order.iOperatorStatusId.IsNull?WorkOrderOperatorStatus.Null:(WorkOrderOperatorStatus)order.iOperatorStatusId.Value;

                    ViewState["status"] = status;
                    ViewState["opstatus"] = opstatus;
                    switch(status)
                    {
                        case WorkOrderStatus.Scheduled: // Scheduled status
                            hlMainEdit.Enabled = true;
                            hlMainEdit.Text = "[Change the Scheduled Date]";
                            hlReportedIssues.Enabled = true;
                            hlPMItems.Enabled = true;
                            hlInspections.Enabled = true;
                            hlCloseOrder.Enabled = false;
                            hlDeleteOrder.Enabled = true;
                            hlTimeLog.Enabled = false;
                            if(opstatus == WorkOrderOperatorStatus.Checked_In)
                            {
                                // check-in status
                                hlOpenOrder.Enabled = true;
                            }
                            else
                            {
                                // not check-in status
                                hlCheckIn.Enabled = true;
                            }
                            break;
                        case WorkOrderStatus.Open: // Opened status
                            hlMainEdit.Enabled = true;
                            hlReportedIssues.Enabled = true;
                            hlPMItems.Enabled = true;
                            hlInspections.Enabled = true;
                            hlPrintOrderRequest.Enabled = true;
                            hlPrintPartUsed.Enabled = true;
                            hlAddRepair.Enabled = true;
                            lbSaveNotes.Enabled = true;
                            hlTimeLog.Enabled = true;
                            break;
                        case WorkOrderStatus.ReOpened: // ReOpened status
                            hlMainEdit.Enabled = true;
                            hlReportedIssues.Enabled = true;
                            hlPMItems.Enabled = true;
                            hlInspections.Enabled = true;
                            hlPrintOrderRequest.Enabled = true;
                            hlPrintPartUsed.Enabled = true;
                            hlAddRepair.Enabled = true;
                            lbSaveNotes.Enabled = true;
                            hlTimeLog.Enabled = true;
                            break;
                        case WorkOrderStatus.Closed: // Closed Status
                            hlMainEdit.Enabled = true;
                            hlMainEdit.Text = "[Change the Order Dates]";
                            hlPrintCompletedOrder.Enabled = true;
                            hlPrintPartUsed.Enabled = true;
                            hlTimeLog.Enabled = true;
                            if(opstatus == WorkOrderOperatorStatus.Checked_In)
                            {
                                // check-in status
                                hlCheckOut.Enabled = true;
                            }
                            break;
                    }
                    #endregion

                    #region Processing of the Information Area
                    if(status == WorkOrderStatus.Closed)
                        Session["CurrentDay"] = order.daClosed.Value;
                    else
                        Session["CurrentDay"] = order.daScheduled.Value;
                    lblWorkOrderN.Text = order.daCreated.Value.ToString("yyyy-MM-dd") + "-" + order.iWorkOrderNumber.Value.ToString();
                    lblWOType.Text = order.sType.Value;
                    lblStatus.Text = order.sStatusId.Value;
                    lblOperatorStatus.Text = order.sOperatorStatus.Value;
                    lblStaying.Text = order.bStaying.IsNull?"not defined":(order.bStaying.Value?"Yes":"No");
                    lblSpare.Text = order.sSpareEquipId.Value;
                    lblTech.Text = order.sTechName.Value;
                    lblOperator.Text = order.sOperatorName.Value;
                    lblDroppedOffBy.Text = order.sDropedOffBy.Value;
                    lblReleasedTo.Text = order.sReleasedTo.Value;
                    lblCleanliness.Text = order.sCleanliness.Value;

                    hlServiceDates.Attributes.Add("onclick", "window.open('wo_viewDates.aspx?id=" + OrderId.ToString() + "', 'popupcal', 'width=350,height=200,left=' + event.screenX + ',top=' + event.screenY + ',scrollbars=no');");

                    // showing equipment info
                    hlEquipId.Text = order.sEquipId.Value;
                    hlEquipId.NavigateUrl = "e_view.aspx?id=" + order.iEquipId.Value.ToString();
                    lblType.Text = order.sEquipTypeName.Value;
                    lblMakeModel.Text = order.sEquipMakeModel.Value;
                    lblYear.Text = (order.sEquipYear.Value == "0")?"unknown":order.sEquipYear.Value;
                    lblSerial.Text = order.sEquipVinSerial.Value;
                    lblUnits.Text = Convert.ToDouble(order.dmMileage.Value).ToString();
                    #endregion

                    #region Processing of the Issues Area
                    order.iTechId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true);
                    dtPMItems = order.GetWorkOrderPMItems();
                    if(dtPMItems.Rows.Count > 0)
                        html_tblNonePMItems.Visible = false;
                    else
                        html_tblNonePMItems.Visible = true;
                    repPMItems.DataSource = new DataView(dtPMItems);
                    repPMItems.DataBind();

                    dtIssues = order.GetWorkOrderReportedIssues();
                    if(dtIssues.Rows.Count > 0)
                        html_tblNoneIssues.Visible = false;
                    else
                        html_tblNoneIssues.Visible = true;

                    repIssues.DataSource = new DataView(dtIssues);
                    repIssues.DataBind();

                    dtInspections = order.GetWorkOrderInspections();
                    if(dtInspections.Rows.Count > 0)
                        html_tblNoneInspections.Visible = false;
                    else
                        html_tblNoneInspections.Visible = true;
                    repInspections.DataSource = new DataView(dtInspections);
                    repInspections.DataBind();
                    #endregion

                    #region Processing of the Serviced Repairs Area and the Time Log Area
                    ShowRepairList();
                    #endregion

                    #region Processing of the Notes Area
                    order.iItemId = OrderId;
                    order.iNoteTypeId = (int)NoteTypes.CreationNote;
                    repCreationNotes.DataSource = new DataView(order.GetNotesList());
                    repCreationNotes.DataBind();

                    order.iNoteTypeId = (int)NoteTypes.OperatorNote;
                    repOperatorNotes.DataSource = new DataView(order.GetNotesList());
                    repOperatorNotes.DataBind();

                    order.iNoteTypeId = (int)NoteTypes.TechnicianNote;
                    repTechNotes.DataSource = new DataView(order.GetNotesList());
                    repTechNotes.DataBind();
                    #endregion

                    #region Processing of the Signatures Area
                    order.iDocumentId = OrderId;
                    order.iDocumentTypeId = (int)DocumentTypes.WorkOrderCheckedIn;
                    if(order.GetSignedDocument() != -1)
                    {
                        lblSignCheckInBy.Text = order.sUserName.Value;
                        lblSignCheckInByUnder.Text = order.sUserName.Value;
                        lblSignDateCheckInBy.Text = order.daReportDate.Value.ToShortDateString() + " " + order.daReportDate.Value.ToShortTimeString();
                    }
                    else
                    {
                        lblSignCheckInBy.Text = "                  ";
                    }
                    order.iDocumentTypeId = (int)DocumentTypes.WorkOrderReOpened;
                    if(order.GetSignedDocument() != -1)
                    {
                        lblSignOpenedBy.Text = order.sUserName.Value;
                        lblSignOpenedByUnder.Text = order.sUserName.Value;
                        lblSignDateOpenedBy.Text = order.daReportDate.Value.ToShortDateString() + " " + order.daReportDate.Value.ToShortTimeString();
                    }
                    else
                    {
                        order.iDocumentTypeId = (int)DocumentTypes.WorkOrderOpen;
                        if(order.GetSignedDocument() != -1)
                        {
                            lblSignOpenedBy.Text = order.sUserName.Value;
                            lblSignOpenedByUnder.Text = order.sUserName.Value;
                            lblSignDateOpenedBy.Text = order.daReportDate.Value.ToShortDateString() + " " + order.daReportDate.Value.ToShortTimeString();
                        }
                        else
                        {
                            lblSignOpenedBy.Text = "                  ";
                        }
                    }
                    if(status == WorkOrderStatus.Closed)
                    {
                        order.iDocumentTypeId = (int)DocumentTypes.WorkOrderClosed;
                        if(order.GetSignedDocument() != -1)
                        {
                            lblSignClosedBy.Text = order.sUserName.Value;
                            lblSignClosedByUnder.Text = order.sUserName.Value;
                            lblSignDateClosedBy.Text = order.daReportDate.Value.ToShortDateString() + " " + order.daReportDate.Value.ToShortTimeString();
                        }
                    }
                    if(opstatus == WorkOrderOperatorStatus.Checked_Out)
                    {
                        order.iDocumentTypeId = (int)DocumentTypes.WorkOrderCheckedOut;
                        if(order.GetSignedDocument() != -1)
                        {
                            lblSignCheckOutBy.Text = order.sUserName.Value;
                            lblSignCheckOutByUnder.Text = order.sUserName.Value;
                            lblSignDateCheckOutBy.Text = order.daReportDate.Value.ToShortDateString() + " " + order.daReportDate.Value.ToShortTimeString();
                        }
                    }
                    #endregion

                    #region Processing of the Custom Fields
                    dtCustomFieldsFromDB = order.WorkOrderDetail_CustomFields(null);

                    if(dtCustomFieldsFromDB.Rows.Count > 0)
                    {
                        arrCFD = _functions.GetCustomFields(CFDataType.WorkOrder, 0, HttpContext.Current.User.Identity.Name);
                        if(arrCFD.Count > 0)
                        {
                            // fill custom fields
                            for(int j = 0; j < arrCFD.Count; j++)
                            {
                                cfd = (clsCustomFieldsDef)arrCFD[j];
                                sTypeName = _functions.GetFieldTypeText(cfd.FieldTypeId) + cfd.NumberColumn.ToString();

                                switch(cfd.FieldTypeId)
                                {
                                    case DBFieldType._lookup:
                                        switch(cfd.NameLookupTable)
                                        {
                                            case "EquipModels":
                                                if(dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                                {
                                                    dtCustomFields.Rows.Add(new object []{"Make/Model", ""});
                                                }
                                                else
                                                {
                                                    mm = new clsMakesModels();
                                                    mm.iOrgId = OrgId;
                                                    mm.iModelId = Convert.ToInt32(dtCustomFieldsFromDB.Rows[0][sTypeName]);
                                                    mm.GetModelMakes();
                                                    dtCustomFields.Rows.Add(new object []{"Make/Model", mm.sMakeName + "/" + mm.sModelName});
                                                    if(mm != null)
                                                        mm.Dispose();
                                                }
                                                break;
                                            case "Departments":
                                                if(dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                                {
                                                    dtCustomFields.Rows.Add(new object []{cfd.NameText, ""});
                                                }
                                                else
                                                {
                                                    dep =  new clsDepartments();
                                                    dep.cAction = "S";
                                                    dep.iOrgId = OrgId;
                                                    dep.iId = Convert.ToInt32(dtCustomFieldsFromDB.Rows[0][sTypeName]);
                                                    if(dep.DepartmentDetail() == 0)
                                                    {
                                                        dtCustomFields.Rows.Add(new object []{cfd.NameText, dep.sName.Value});
                                                    }
                                                    else
                                                    {
                                                        dtCustomFields.Rows.Add(new object []{cfd.NameText, ""});
                                                    }
                                                    if(dep != null)
                                                        dep.Dispose();
                                                }
                                                break;
                                            case "Locations":
                                                if(dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                                {
                                                    dtCustomFields.Rows.Add(new object []{cfd.NameText, ""});
                                                }
                                                else
                                                {
                                                    loc = new clsLocations();
                                                    loc.cAction = "S";
                                                    loc.iOrgId = OrgId;
                                                    loc.iId = Convert.ToInt32(dtCustomFieldsFromDB.Rows[0][sTypeName]);
                                                    if(loc.LocationDetail() == 0)
                                                    {
                                                        dtCustomFields.Rows.Add(new object []{cfd.NameText, loc.sName.Value});
                                                    }
                                                    else
                                                    {
                                                        dtCustomFields.Rows.Add(new object []{cfd.NameText, ""});
                                                    }
                                                    if(loc != null)
                                                        loc.Dispose();
                                                }
                                                break;
                                            default:
                                                break;
                                        }
                                        break;
                                    case DBFieldType._datetime:
                                        if(dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                        {
                                            dtCustomFields.Rows.Add(new object []{cfd.NameText, ""});
                                        }
                                        else
                                        {
                                            dtCustomFields.Rows.Add(new object []{cfd.NameText, ((DateTime)dtCustomFieldsFromDB.Rows[0][sTypeName]).ToShortDateString()});
                                        }
                                        break;
                                    case DBFieldType._bit:
                                        if(dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                        {
                                            dtCustomFields.Rows.Add(new object []{cfd.NameText, ""});
                                        }
                                        else
                                        {
                                            if(((bool)dtCustomFieldsFromDB.Rows[0][sTypeName]) == true)
                                                dtCustomFields.Rows.Add(new object []{cfd.NameText, "Yes"});
                                            else
                                                dtCustomFields.Rows.Add(new object []{cfd.NameText, "No"});
                                        }
                                        break;
                                    default:
                                        if(dtCustomFieldsFromDB.Rows[0][sTypeName] == DBNull.Value)
                                        {
                                            dtCustomFields.Rows.Add(new object []{cfd.NameText, ""});
                                        }
                                        else
                                        {
                                            dtCustomFields.Rows.Add(new object []{cfd.NameText, dtCustomFieldsFromDB.Rows[0][sTypeName]});
                                        }
                                        break;
                                }
                                cfd = null;
                            }

                            // showing a Equipment's data from custom fields
                            repCustomFields.DataSource = new DataView(dtCustomFields);
                            repCustomFields.DataBind();
                        }
                    }
                    #endregion
                }
            }
            catch(Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"] = m_sLastPage;
                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();
            }
        }
        private void repPMItems_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
        {
            int ServiceCheckId;
            int ServiceResultId;
            try
            {
                if(e.CommandName.Length > 0)
                {
                    status = (WorkOrderStatus)ViewState["status"];
                    opstatus = (WorkOrderOperatorStatus)ViewState["opstatus"];

                    if(status == WorkOrderStatus.Scheduled
                        && e.CommandName != "Delete")
                    {
                        if(opstatus == WorkOrderOperatorStatus.Null)
                        {
                            Response.Redirect("wo_viewCheckIn.aspx?id=" + OrderId.ToString(), false);
                            return;
                        }
                        else
                        {
                            Response.Redirect("wo_openWorkOrder.aspx?id=" + OrderId.ToString(), false);
                            return;
                        }
                    }

                    Header.BodyOnloadScript = "javascript:document.location='#Issues'";
                    //Header.Render();

                    ItemId = Convert.ToInt32(((Label)e.Item.FindControl("PMItemId")).Text);
                    ServiceCheckId = Convert.ToInt32(((Label)e.Item.FindControl("ServiceCheckId")).Text);
                    ServiceResultId = Convert.ToInt32(((Label)e.Item.FindControl("ServiceResultId")).Text);
                    order = new clsWorkOrders();
                    order.iOrgId = OrgId;
                    order.iId = OrderId;
                    order.iPMItemId = ItemId;
                    switch(e.CommandName)
                    {
                        case "Delete":
                            order.cAction = "D";
                            int iResult = order.WorkOrderPMItemsDetail();
                            if(iResult < 0)
                            {
                                Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                                if(iResult == -1)
                                    Session["error"] = _functions.ErrorMessage(123);
                                else
                                    Session["error"] = _functions.ErrorMessage(126);
                                Response.Redirect("error.aspx", false);
                            }
                            break;
                        case "OK":	// if the status already okay then ServiceCheckId = null else
                            // see what was status of ServiceResultId, if more than 0 then ServiceResultId = null
                            if(ServiceCheckId == (int)ServiceChecks._CheckOK)
                            {
                                order.iServiceCheckId = SqlInt32.Null;
                                order.iServiceResultId = SqlInt32.Null;
                            }
                            else
                            {
                                order.iServiceCheckId = (int)ServiceChecks._CheckOK;
                                order.iServiceResultId = ServiceResultId;
                            }
                            if(order.SetPMItemChecks() == -1)
                            {
                                Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                                Session["error"] = _functions.ErrorMessage(133);
                                Response.Redirect("error.aspx", false);
                                return;
                            }
                            break;
                        case "FAIR":
                            if(ServiceCheckId == (int)ServiceChecks._CheckFair)
                            {
                                order.iServiceCheckId = SqlInt32.Null;
                                order.iServiceResultId = SqlInt32.Null;
                            }
                            else
                            {
                                order.iServiceCheckId = (int)ServiceChecks._CheckFair;
                                order.iServiceResultId = ServiceResultId;
                            }
                            if(order.SetPMItemChecks() == -1)
                            {
                                Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                                Session["error"] = _functions.ErrorMessage(133);
                                Response.Redirect("error.aspx", false);
                                return;
                            }
                            break;
                        case "RepairNeeded":
                            if(ServiceCheckId == (int)ServiceChecks._CheckRepairs_Needed)
                            {
                                order.iServiceCheckId = SqlInt32.Null;
                                order.iServiceResultId = ServiceResultId;
                            }
                            else
                            {
                                order.iServiceCheckId = (int)ServiceChecks._CheckRepairs_Needed;
                                order.iServiceResultId = SqlInt32.Null;
                            }
                            if(order.SetPMItemChecks() == -1)
                            {
                                Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                                Session["error"] = _functions.ErrorMessage(133);
                                Response.Redirect("error.aspx", false);
                                return;
                            }
                            break;
                        case "NoService":
                            if(ServiceResultId > 0) // значит ремонт у этого итема был и мы удаляем его
                            {
                                order.iServiceCheckId = (int)ServiceChecks._CheckRepairs_Needed;
                                order.iServiceResultId = ServiceResultId;
                                if(order.SetPMItemChecks() == -1)
                                {
                                    Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                                    Session["error"] = _functions.ErrorMessage(133);
                                    Response.Redirect("error.aspx", false);
                                    return;
                                }
                            }
                            break;
                        case "Repaired":
                            Response.Redirect("wo_updateRepair.aspx?mode=Add&repairid=0&inspectid=0&type=PMI&op=Repair&id=" + OrderId.ToString() + "&itemid=" + ItemId.ToString(), false);
                            return;
                        case "Replaced":
                            Response.Redirect("wo_updateRepair.aspx?mode=Add&repairid=0&inspectid=0&type=PMI&op=Replace&id=" + OrderId.ToString() + "&itemid=" + ItemId.ToString(), false);
                            return;
                        default:
                            break;
                    }
                    order.cAction = "S";
                    order.iId = OrderId;
                    order.iTechId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true);

                    dtPMItems = order.GetWorkOrderPMItems();
                    if(dtPMItems.Rows.Count > 0)
                        html_tblNonePMItems.Visible = false;
                    else
                        html_tblNonePMItems.Visible = true;

                    repPMItems.DataSource = new DataView(dtPMItems);
                    repPMItems.DataBind();

                    ShowRepairList();
                }
            }
            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(order != null)
                    order.Dispose();
            }
        }
        private void repRepairs_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
        {
            try
            {
                if(e.CommandName == "Delete")
                {
                    Header.BodyOnloadScript = "javascript:document.location='#Repairs'";
                    //Header.Render();

                    order = new clsWorkOrders();
                    order.cAction = "D";
                    order.iOrgId = OrgId;
                    order.iId = OrderId;
                    order.iRepairId = Convert.ToInt32(e.CommandArgument);
                    order.iTechId = _functions.GetUserOrgId(HttpContext.Current.User.Identity.Name, true);
                    if(order.RepairCommonDetails() == -1)
                    {
                        Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                        Session["error"] = _functions.ErrorMessage(128);
                        Response.Redirect("error.aspx", false);
                    }
                    else
                    {
                        repIssues.DataSource = new DataView(order.GetWorkOrderReportedIssues());
                        repIssues.DataBind();

                        repPMItems.DataSource = new DataView(order.GetWorkOrderPMItems());
                        repPMItems.DataBind();

                        repInspections.DataSource = new DataView(order.GetWorkOrderInspections());
                        repInspections.DataBind();

                        ShowRepairList();
                    }
                }
            }
            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(order != null)
                    order.Dispose();
            }
        }