Esempio n. 1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            DateTime dtCurrentDate;
            try
            {
                SourcePageName = "wo_editAddInfo.aspx.cs";

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

                if(Request.QueryString["id"] == null || Request.QueryString["equipid"] == null)
                {
                    Session["lastpage"] = "wo_default.aspx";
                    Session["error"] = _functions.ErrorMessage(104);
                    Response.Redirect("error.aspx", false);
                    return;
                }
                try
                {
                    EquipId = Convert.ToInt32(Request.QueryString["equipid"]);
                    OrderId = Convert.ToInt32(Request.QueryString["id"]);
                }
                catch(FormatException fex)
                {
                    Session["lastpage"] = "wo_default.aspx";
                    Session["error"] = _functions.ErrorMessage(105);
                    Response.Redirect("error.aspx", false);
                    return;
                }
                if(EquipId == 0 && OrderId == 0)
                {
                    Session["lastpage"] = "wo_default.aspx";
                    Session["error"] = _functions.ErrorMessage(102);
                    Response.Redirect("error.aspx", false);
                    return;
                }
                m_sLastPage = "wo_editAddInfo.aspx?id=" + OrderId.ToString() + "&equipid=" + EquipId.ToString();
                if(Request.QueryString["back"] != null)
                    if(Request.QueryString["back"] == "past")
                    {
                        IsPast = true;
                        this.PageTitle = "Create the Past Work Order";
                        m_sLastPage = "wo_editAddInfo.aspx?back=past&id=" + OrderId.ToString() + "&equipid=" + EquipId.ToString();
                    }

                NextBackControl.BackVisible = false;
                if(!IsPostBack)
                {
                    dtCurrentDate = DateTime.Now;
                    // getting the main (fixed) data
                    order = new clsWorkOrders();

                    rblWOTypes.DataSource = order.GetTypesList();
                    rblWOTypes.DataBind();

                    order.iOrgId = OrgId;
                    order.iEquipId = EquipId;
                    order.iId = OrderId;

                    if(order.GetInfoForWorkOrder() == -1)
                    {
                        Session["lastpage"] = "wo_default.aspx";
                        Session["error"] = _functions.ErrorMessage(102);
                        Response.Redirect("error.aspx", false);
                        return;
                    }
                    lblEquipId.Text = order.sEquipId.Value;
                    if(order.iTypeId.Value != 0)
                        rblWOTypes.SelectedValue = order.iTypeId.Value.ToString();
                    if(!order.daScheduled.IsNull)
                        adtScheduled.Date = order.daScheduled.Value;
                    else
                        adtScheduled.Date = dtCurrentDate.AddMinutes(60-dtCurrentDate.Minute);

                    if(OrderId != 0)
                    {
                        order.cAction = "S";
                        order.iNoteId = 0;
                        order.iNoteTypeId = (int)NoteTypes.CreationNote;
                        order.iItemId = OrderId;
                        if(order.NoteDetails() != -1)
                        {
                            tbNotes.Text = order.sNote.Value;
                            ViewState["NoteId"] = order.iNoteId.Value;
                        }
                        else
                            ViewState["NoteId"] = 0;
                    }
                    else
                        ViewState["NoteId"] = 0;

                    ShowCustomFields();
                }
            }
            catch(Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"] = "wo_default.aspx";
                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();
                if(equip != null)
                    equip.Dispose();
            }
        }