コード例 #1
0
        private void Page_Load(object sender, System.EventArgs e)
        {
            try
            {
                if (Request.QueryString["orderid"] == null)
                {
                    Session["lastpage"] = "ok_mainMenu.aspx";
                    Session["error"]    = _functions.ErrorMessage(104);
                    Response.Redirect("error.aspx", false);
                    return;
                }
                try
                {
                    EquipId   = Convert.ToInt32(Request.QueryString["equipid"]);
                    OrderId   = Convert.ToInt32(Request.QueryString["orderid"]);
                    sBackPage = Request.QueryString["back"];
                }
                catch (FormatException fex)
                {
                    Session["lastpage"] = "ok_mainMenu.aspx";
                    Session["error"]    = _functions.ErrorMessage(105);
                    Response.Redirect("error.aspx", false);
                    return;
                }

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

                sBackURL = "ok_mainMenu.aspx";
                if (sBackPage == "maindetails")
                {
                    sBackURL = "ok_mainDetails.aspx?id=" + OrderId.ToString();
                }
                if (sBackPage == "mainmenu2")
                {
                    sBackURL = "ok_mainMenu2.aspx";
                }
                btnBack.Attributes.Add("onclick", "javascript:document.location='" + sBackURL + "'");

                if (!IsPostBack)
                {
                    OperatorInfo op = new OperatorInfo(Request.Cookies["bfp_operator"].Value);
                    lblFirstName1.Text = lblFirstName2.Text = lblFirstName3.Text = op.FirstName;
                    equip         = new clsEquipment();
                    equip.iOrgId  = OrgId;
                    equip.iUserId = op.Id;
                    dtEquipments  = equip.GetEquipListByOperator();
                    if (dtEquipments.Rows.Count < 1)
                    {
                        // none equipments mode
                        pnlFindEquipment.Visible = true;
                    }
                    else if (dtEquipments.Rows.Count == 1)
                    {
                        // one equipment mode
                        pnlOneEquipment.Visible      = true;
                        lblEquipId.Text              = dtEquipments.Rows[0]["EquipId"].ToString();
                        lblEquipType.Text            = dtEquipments.Rows[0]["TypeName"].ToString();
                        lblMakeModel.Text            = dtEquipments.Rows[0]["MakeName"].ToString() + "/" + dtEquipments.Rows[0]["ModelName"].ToString();
                        lblYear.Text                 = dtEquipments.Rows[0]["Year"].ToString();
                        ViewState["SelectedEqiupId"] = dtEquipments.Rows[0]["Id"].ToString();
                    }
                    else if (dtEquipments.Rows.Count > 1)
                    {
                        // manu equipments mode
                        pnlManyEquipment.Visible = true;
                        repEquipments.DataSource = new DataView(dtEquipments);
                        repEquipments.DataBind();
                    }
                    if (OrderId != 0)
                    {
                        pnlFindEquipment.Visible = false;
                        pnlManyEquipment.Visible = false;
                        pnlOneEquipment.Visible  = true;
                        order        = new clsWorkOrders();
                        order.iOrgId = OrgId;
                        order.iId    = OrderId;
                        if (order.GetEquipInfo() == -1)
                        {
                            Session["lastpage"] = sBackURL;
                            Session["error"]    = _functions.ErrorMessage(120);
                            Response.Redirect("error.aspx", false);
                        }
                        else
                        {
                            lblEquipId.Text              = order.sEquipId.Value;
                            lblEquipType.Text            = order.sEquipTypeName.Value;
                            lblMakeModel.Text            = order.sEquipMakeModel.Value;
                            lblYear.Text                 = order.sEquipYear.Value;
                            ViewState["SelectedEqiupId"] = order.iEquipId.Value.ToString();
                        }
                    }
                    else
                    {
                        if (EquipId != 0)
                        {
                            pnlFindEquipment.Visible = false;
                            pnlManyEquipment.Visible = false;
                            pnlOneEquipment.Visible  = true;
                            equip.iId = EquipId;
                            if (equip.GetEquipInfo() == -1)
                            {
                                Session["lastpage"] = sBackURL;
                                Session["error"]    = _functions.ErrorMessage(102);
                                Response.Redirect("error.aspx", false);
                            }
                            else
                            {
                                lblEquipId.Text              = equip.sEquipId.Value;
                                lblEquipType.Text            = equip.sType.Value;
                                lblMakeModel.Text            = equip.sMakeModelName.Value;
                                lblYear.Text                 = equip.iYear.Value.ToString();
                                ViewState["SelectedEqiupId"] = EquipId.ToString();
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                _functions.Log(ex, HttpContext.Current.User.Identity.Name, SourcePageName);
                Session["lastpage"]     = sBackURL;
                Session["error"]        = ex.Message;
                Session["error_report"] = ex.ToString();
                Response.Redirect("error.aspx", false);
            }
            finally
            {
                if (order != null)
                {
                    order.Dispose();
                }
                if (equip != null)
                {
                    equip.Dispose();
                }
            }
        }