Exemplo n.º 1
0
        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();
            }
        }