private void repIssues_ItemCommand(object source, System.Web.UI.WebControls.RepeaterCommandEventArgs e)
        {
            try
            {
                int ServiceCheckId;
                int ServiceResultId;

                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("IssueId")).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.iReportedIssueId = ItemId;
                    switch(e.CommandName)
                    {
                        case "Delete":
                            order.cAction = "D";
                            int iResult = order.WorkOrderReportedIssuesDetail();
                            if(iResult < 0)
                            {
                                Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                                if(iResult == -1)
                                    Session["error"] = _functions.ErrorMessage(121);
                                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.SetIssueChecks() == -1)
                            {
                                Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                                Session["error"] = _functions.ErrorMessage(121);
                                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.SetIssueChecks() == -1)
                            {
                                Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                                Session["error"] = _functions.ErrorMessage(121);
                                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.SetIssueChecks() == -1)
                            {
                                Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                                Session["error"] = _functions.ErrorMessage(121);
                                Response.Redirect("error.aspx", false);
                                return;
                            }
                            break;
                        case "NoService":
                            if(ServiceResultId > 0) // значит ремонт у этого итема был и мы удаляем его
                            {
                                order.iServiceCheckId = (int)ServiceChecks._CheckRepairs_Needed;
                                order.iServiceResultId = ServiceResultId;
                                if(order.SetIssueChecks() == -1)
                                {
                                    Session["lastpage"] = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();
                                    Session["error"] = _functions.ErrorMessage(121);
                                    Response.Redirect("error.aspx", false);
                                    return;
                                }
                            }
                            break;
                        case "Repaired":
                            Response.Redirect("wo_updateRepair.aspx?mode=Add&repairid=0&inspectid=0&type=RI&op=Repair&id=" + OrderId.ToString() + "&itemid=" + ItemId.ToString(), false);
                            return;
                        case "Replaced":
                            Response.Redirect("wo_updateRepair.aspx?mode=Add&repairid=0&inspectid=0&type=RI&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);

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

                    repIssues.DataSource = new DataView(dtIssues);
                    repIssues.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 dgUnAssignedIssues_UpdateCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                order = new clsWorkOrders();
                equip = new clsEquipment();
                equip.iId = EquipId;
                equip.iOrgId = OrgId;
                order.cAction = "S";
                order.iOrgId = OrgId;
                order.iReportedIssueId = Convert.ToInt32(((Label)e.Item.FindControl("lblReportIssueId")).Text);
                if(order.WorkOrderReportedIssuesDetail() == -1)
                {
                    Session["lastpage"] = sCurrentPage;
                    Session["error"] = _functions.ErrorMessage(121);
                    Response.Redirect("error.aspx", false);
                    return;
                }
                order.cAction = "U";
                order.sReportDesc = ((TextBox)e.Item.FindControl("tbIssueName")).Text;
                if(order.WorkOrderReportedIssuesDetail() == -1)
                {
                    Session["lastpage"] = sCurrentPage;
                    Session["error"] = _functions.ErrorMessage(121);
                    Response.Redirect("error.aspx", false);
                    return;
                }
                dgUnAssignedIssues.EditItemIndex = -1;

                ShowIssues();
            }
            catch(Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"] = sCurrentPage;
                Session["error"] = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if(equip != null)
                    equip.Dispose();
                if(order != null)
                    order.Dispose();
            }
        }
        private void btnAddRepair_Click(object sender, System.EventArgs e)
        {
            try
            {
                order = new clsWorkOrders();
                equip = new clsEquipment();
                equip.iId = EquipId;
                equip.iOrgId = OrgId;
                order.cAction = "U";
                order.iOrgId = OrgId;
                order.iEquipId = EquipId;
                order.iReportedIssueId = 0;
                order.iRepairCatId = Convert.ToInt32(ddlCategory.SelectedValue);
                order.sReportDesc = tbDesc.Text;
                order.iId = SqlInt32.Null;
                order.iServiceResultId = SqlInt32.Null;
                order.iServiceCheckId = SqlInt32.Null;
                order.iRepairMultId = SqlInt32.Null;
                if(order.WorkOrderReportedIssuesDetail() == -1)
                {
                    Session["lastpage"] = sCurrentPage;
                    Session["error"] = _functions.ErrorMessage(121);
                    Response.Redirect("error.aspx", false);
                }
                tbDesc.Text = "";
                ddlCategory.SelectedIndex = 0;

                ShowIssues();
            }
            catch(Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"] = sCurrentPage;
                Session["error"] = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if(equip != null)
                    equip.Dispose();
                if(order != null)
                    order.Dispose();
            }
        }
 private void dgRepairs_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
 {
     try
     {
         switch(e.CommandName)
         {
             case "Unassign":
                 order = new clsWorkOrders();
                 order.cAction = "S";
                 order.iOrgId = OrgId;
                 order.iReportedIssueId = Convert.ToInt32(e.Item.Cells[0].Text);
                 if(order.WorkOrderReportedIssuesDetail() == -1)
                 {
                     Session["lastpage"] = m_sBackUrl;
                     Session["error"] = _functions.ErrorMessage(121);
                     Response.Redirect("error.aspx", false);
                     return;
                 }
                 order.cAction = "U";
                 order.iLastWorkOrderId = order.iId;
                 order.iId = SqlInt32.Null;
                 order.WorkOrderReportedIssuesDetail();
                 ShowIssues(OrderId);
                 break;
             case "Delete":
                 order = new clsWorkOrders();
                 order.cAction = "D";
                 order.iOrgId = OrgId;
                 order.iReportedIssueId = Convert.ToInt32(e.Item.Cells[0].Text);
                 if(order.WorkOrderReportedIssuesDetail() == -1)
                 {
                     Session["lastpage"] = m_sBackUrl;
                     Session["error"] = _functions.ErrorMessage(121);
                     Response.Redirect("error.aspx", false);
                     return;
                 }
                 ShowIssues(OrderId);
                 break;
             default:
                 break;
         }
     }
     catch(Exception ex)
     {
         _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
         Session["lastpage"] = m_sBackUrl;
         Session["error"] = ex.Message;
         Session["error_report"] = ex.ToString();
         Response.Redirect("error.aspx", false);
     }
     finally
     {
         if(order != null)
             order.Dispose();
     }
 }
 private void dgPreviousRepairs_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
 {
     try
     {
         if(e.CommandName == "Assign")
         {
             order = new clsWorkOrders();
             order.cAction = "S";
             order.iOrgId = OrgId;
             order.iReportedIssueId = Convert.ToInt32(e.Item.Cells[1].Text);
             // getting the undone repair information
             if(order.WorkOrderReportedIssuesDetail() == -1)
             {
                 Session["lastpage"] = m_sBackUrl;
                 Session["error"] = _functions.ErrorMessage(121);
                 Response.Redirect("error.aspx", false);
             }
             // updating the old undone repair
             order.cAction = "U";
             order.iId = OrderId;
             order.iServiceResultId = SqlInt32.Null;
             //order.iServiceCheckId = SqlInt32.Null;
             order.iRepairMultId = SqlInt32.Null;
             if(order.WorkOrderReportedIssuesDetail() == -1)
             {
                 Session["lastpage"] = m_sBackUrl;
                 Session["error"] = _functions.ErrorMessage(121);
                 Response.Redirect("error.aspx", false);
             }
             // assigning the undone repair in the new (current) work order
             // creating the new repair
             ShowIssues(OrderId);
         }
     }
     catch(Exception ex)
     {
         _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
         Session["lastpage"] = m_sBackUrl;
         Session["error"] = ex.Message;
         Session["error_report"] = ex.ToString();
         Response.Redirect("error.aspx", false);
     }
     finally
     {
         if(order != null)
             order.Dispose();
     }
 }
 private void btSave_FormSubmit(object sender, EventArgs e)
 {
     try
     {
         if(ddlCategory.SelectedIndex != 0 && tbDesc.Text.Length != 0)
         {
             order = new clsWorkOrders();
             order.cAction = "U";
             order.iOrgId = OrgId;
             order.iReportedIssueId = 0;
             order.iRepairCatId = Convert.ToInt32(ddlCategory.SelectedValue);
             order.sReportDesc = tbDesc.Text;
             order.iId = OrderId;
             order.iServiceResultId = SqlInt32.Null;
             order.iServiceCheckId = SqlInt32.Null;
             order.iRepairMultId = SqlInt32.Null;
             if(order.WorkOrderReportedIssuesDetail() == -1)
             {
                 Session["lastpage"] = m_sBackUrl;
                 Session["error"] = _functions.ErrorMessage(121);
                 Response.Redirect("error.aspx", false);
                 return;
             }
         }
         Response.Redirect("wo_viewWorkOrder.aspx?id=" + OrderId.ToString() + "&#Issues", false);
     }
     catch(Exception ex)
     {
         _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
         Session["lastpage"] = m_sBackUrl;
         Session["error"] = ex.Message;
         Session["error_report"] = ex.ToString();
         Response.Redirect("error.aspx", false);
     }
     finally
     {
         if(order != null)
             order.Dispose();
     }
 }
        private void btNext_FormSubmit(object sender, EventArgs e)
        {
            try
            {
                order = new clsWorkOrders();

                if(ddlCategory.SelectedIndex != 0 && tbDesc.Text.Length != 0)
                {
                    order.cAction = "U";
                    order.iOrgId = OrgId;
                    order.iReportedIssueId = 0;
                    order.iRepairCatId = Convert.ToInt32(ddlCategory.SelectedValue);
                    order.sReportDesc = tbDesc.Text;
                    order.iId = OrderId;
                    order.iServiceResultId = SqlInt32.Null;
                    order.iServiceCheckId = SqlInt32.Null;
                    order.iRepairMultId = SqlInt32.Null;
                    if(order.WorkOrderReportedIssuesDetail() == -1)
                    {
                        Session["lastpage"] = m_sBackUrl;
                        Session["error"] = _functions.ErrorMessage(121);
                        Response.Redirect("error.aspx", false);
                        return;
                    }
                }
                if(m_sBack == "open")
                    Response.Redirect("wo_addPreventiveMaintenance.aspx?id=" + OrderId.ToString(), false);
                else
                {
                    // redirect to finish screen
                    order.iOrgId = OrgId;
                    order.iId = OrderId;

                    if(order.GetWorkOrderId() == -1)
                    {
                        Session["lastpage"] = m_sBackUrl;
                        Session["error"] = _functions.ErrorMessage(102);
                        Response.Redirect("error.aspx", false);
                        return;
                    }

                    BackFinishScreen finish = new BackFinishScreen();
                    finish.sMainText = "The Work Order " + order.daCreated.Value.ToString("yyyy-MM-dd") + "-" + order.iWorkOrderNumber.Value.ToString() + " has been created successfully!";

                    finish.bMainMenuVisible = true;
                    finish.sMainMenuText = "[Return to Main Menu]";
                    finish.sMainMenuURL = "main.aspx";

                    finish.bContinueVisible = true;
                    finish.sContinueText = "[Continue to Check-In Equipment by Technician]";
                    finish.sContinueURL = "wo_viewCheckIn.aspx?id=" + OrderId.ToString();

                    finish.bViewVisible = true;
                    finish.sViewText = "[View the Scheduled Work Order]";
                    finish.sViewURL = "wo_viewWorkOrder.aspx?id=" + OrderId.ToString();

                    finish.bAdditionalVisible = true;
                    finish.sAdditionalText = "[Create a New Work Order]";
                    finish.sAdditionalURL = "wo_default.aspx";

                    finish.bPrintVisible = false;

                    Session["BackFinish"] = finish;

                    Response.Redirect("wo_finish.aspx", false);
                }
            }
            catch(Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"] = m_sBackUrl;
                Session["error"] = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if(order != null)
                    order.Dispose();
            }
        }
 private void btnSaveNote_Click(object sender, System.EventArgs e)
 {
     try
     {
         if(ViewState["CatId"] != null && tbNotes.Text.Length != 0)
         {
             order = new clsWorkOrders();
             order.cAction = "U";
             order.iOrgId = OrgId;
             order.iReportedIssueId = 0;
             order.iRepairCatId = Convert.ToInt32(ViewState["CatId"]);
             order.sReportDesc = tbNotes.Text;
             order.iId = OrderId;
             order.iServiceResultId = SqlInt32.Null;
             order.iServiceCheckId = SqlInt32.Null;
             order.iRepairMultId = SqlInt32.Null;
             if(order.WorkOrderReportedIssuesDetail() == -1)
             {
                 Session["lastpage"] = CurrentPage;
                 Session["error"] = _functions.ErrorMessage(121);
                 Response.Redirect("error.aspx", false);
                 return;
             }
             else
             {
                 if(Operation == "AddIssueReOpen")
                 {
                     Response.Redirect(BackPage + "&op=AddIssueReOpen", false);
                     return;
                 }
                 else
                 {
                     pnlViewIssues.Visible = true;
                     pnlEnterIssue.Visible = false;
                     pnlSelectCategory.Visible = false;
                     lblFirstName.Text = op.FirstName;
                     order.iEquipId = EquipId;
                     dtIssues = order.GetReportedIssueListsOperatorKiosk();
                     if(dtIssues.Rows.Count > 0)
                     {
                         html_tblNoneIssues.Visible = false;
                         repIssues.DataSource = new DataView(dtIssues);
                         repIssues.DataBind();
                     }
                     else
                         html_tblNoneIssues.Visible = true;
                 }
             }
         }
         else
             rfvNotes.Visible = true;
     }
     catch(Exception ex)
     {
         _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
         Session["lastpage"] = CurrentPage;
         Session["error"] = ex.Message;
         Session["error_report"] = ex.ToString();
         Response.Redirect("error.aspx", false);
     }
     finally
     {
         if(order != null)
             order.Dispose();
     }
 }