Пример #1
0
        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 dgFuturePMItems_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
        {
            try
            {
                int FutureOrderId;
                if(e.CommandName == "Assign")
                {
                    order = new clsWorkOrders();
                    order.cAction = "S";
                    order.iOrgId = OrgId;
                    order.iPMItemId = Convert.ToInt32(e.Item.Cells[0].Text);
                    // getting the undone repair information
                    if(order.WorkOrderPMItemsDetail() == -1)
                    {
                        Session["lastpage"] = m_sCurrentUrl;
                        Session["error"] = _functions.ErrorMessage(123);
                        Response.Redirect("error.aspx", false);
                    }
                    FutureOrderId = order.iId.Value;
                    // 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.WorkOrderPMItemsDetail() == -1)
                    {
                        Session["lastpage"] = m_sCurrentUrl;
                        Session["error"] = _functions.ErrorMessage(123);
                        Response.Redirect("error.aspx", false);
                    }
                    // check future work order
                    // if it is empty then to delete it
                    order.iId = FutureOrderId;
                    if(order.DeleteFutureWorkOrder() == -1)
                    {
                        Session["lastpage"] = m_sCurrentUrl;
                        Session["error"] = _functions.ErrorMessage(120);
                        Response.Redirect("error.aspx", false);
                    }

                    // show updated PM Items
                    order.iId = OrderId;
                    dtPMServices = order.GetPMServicesListForWorkOrder();
                    dgPMServices.DataSource = new DataView(dtPMServices);
                    dgPMServices.DataBind();

                    dtFuturePMService = order.GetFuturePMItems();
                    if(dtFuturePMService.Rows.Count > 0)
                    {
                        dgFuturePMItems.DataSource = new DataView(dtFuturePMService);
                        dgFuturePMItems.DataBind();
                    }
                    else
                    {
                        tblMain.Rows[2].Visible = false;
                        tblMain.Rows[3].Visible = false;
                    }
                }
            }
            catch(Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"] = m_sCurrentUrl;
                Session["error"] = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if(order != null)
                    order.Dispose();
            }
        }