Exemplo n.º 1
0
        protected void Page_Load(object sender, EventArgs e)
        {
            int?propID = _Request.Get <int>("id");

            if (propID == null)
            {
                ShowError("缺少必要的参数");
            }

            m_Prop = PropBO.Instance.GetPropByID(propID.Value);

            if (m_Prop == null)
            {
                ShowError("指定的道具不存在");
            }

            PropType propType = PropBO.GetPropType(m_Prop.PropType);

            if (propType == null)
            {
                ShowError("道具类型不存在,请联系管理员");
            }

            m_AutoUse = propType.IsAutoUse(m_Prop.PropParam);

            if (_Request.IsClick("buy"))
            {
                int count = _Request.Get <int>("count", 1);

                if (count <= 0)
                {
                    ShowError("够买数量必须大于0");
                    return;
                }

                using (ErrorScope es = new ErrorScope())
                {
                    if (m_AutoUse)
                    {
                        count = 1;
                    }

                    if (PropBO.Instance.BuyProp(My, propID.Value, count))
                    {
                        m_DisplayMessage = true;

                        if (m_AutoUse)
                        {
                            PropResult result = PropBO.Instance.UseProp(My, propID.Value, Request);

                            if (result.Type == PropResultType.Succeed)
                            {
                                ShowSuccess("道具购买并使用成功", 1);
                            }
                            else
                            {
                                ShowError("道具购买成功,但使用失败了,请联系网站管理员");
                            }
                        }
                        else
                        {
                            ShowSuccess("道具购买成功", 1);
                        }
                    }
                    else
                    {
                        m_DisplayMessage = true;

                        es.CatchError <ErrorInfo>(delegate(ErrorInfo error)
                        {
                            ShowError(error.Message);
                        });
                    }
                }
            }
        }