Пример #1
0
        /// <summary>
        /// 载入后执行参数对应的sql请求
        /// </summary>
        public override void Load(object sender, EventArgs e)
        {
            if (UserType == 0 && param.Equals(""))
            {
                Response.Redirect("../PayFor/UserLogin.aspx");
            }

            DB = new DataBase(ScTool.DBName("pre"), ScTool.UserName, ScTool.Password);

            if (Page.IsPostBack)
            {
                //Timer1.Enabled = true;
                return;
            }

            body1.Visible = false;

            TYPE = Request["TYPE"];
            if (TYPE == null)
            {
                TYPE = "";
            }

            if (param.Contains("TYPE"))
            {
                int index = param.IndexOf("TYPE");
                int start = param.IndexOf("&", index + 4);
                param = param.Substring(start + 1);
            }

            //DB.DeletTable(ScTool.ORDER);
            confirmOrderTab();

            //DB = new DataBase("master", ScTool.UserName, ScTool.Password);
            //DB.DeletDataBase(ScTool.DBName("pre"));
            //DB.DeletDataBase(ScTool.DBName(ScTool.PayTypeAli));
            //DB.DeletDataBase(ScTool.DBName(ScTool.PayTypeWechat));

            if (TYPE.Equals("PreOrder"))            // 生成新的pre订单
            {
                //if (!ContainsAuthorInfo()) return;
                this.Controls.Clear();

                string id = createOrder(param);
                Response.Write(ScTool.Reslut(id));
                return;
            }
            else if (TYPE.Equals("ShowPreOrder"))   // 显示预备下单订单号,对应的二维码待支付页面
            {
                string preOrderId = Request["preOrderId"];

                LabelPreOrderId.Text    = "当前订单号:" + preOrderId;
                LabelPreOrderPrice.Text = getNeedPayMoney(preOrderId);

                if (preOrderId != null && !preOrderId.Equals(""))
                {
                    string data = url + "?" + "TYPE=" + "CreateOrder" + "&" + "preOrderId=" + preOrderId;
                    showQR(data);
                }
                else
                {
                    Response.Write("支付失败!Pay.aspx创建订单失败");
                }
            }
            else if (TYPE.Equals("OrderResult"))    // 查询指定订单支付结果http://60.205.185.168:8002/pages/pay.aspx?TYPE=OrderResult&machinCode=J78Z-A906-E9ST-RING
            {
                this.Controls.Clear();

                string order_param = Request["P"];
                if (order_param == null || order_param.Equals(""))
                {
                    string result = OrderResult(Request["preOrderId"]); // 通过订单号查询支付结果
                    Response.Write(ScTool.Reslut(result));
                }
                else
                {
                    string result = OrderResult_param(order_param);     // 通过订单参数查询支付结果
                    Response.Write(ScTool.Reslut(result));
                }
                return;
            }
            else if (TYPE.Equals("OrderResultX"))
            {
                this.Controls.Clear();

                if (Request["preOrderId"] != null)
                {
                    string result = OrderResult(Request["preOrderId"], false); // 通过订单号查询支付结果
                    Response.Write(ScTool.Reslut(result));
                }
                else
                {
                    string machinCode = Request["machinCode"];
                    string soft       = Request["soft"];

                    string result = OnlineCode.Check(DB, OnlineCode.TAB, machinCode, soft);     // 查询指定的机器码对应订单是否已支付
                    Response.Write(ScTool.Reslut(result));
                }
                return;
            }
            else if (TYPE.Equals("CreateOrder"))    // 使用预下单信息,创建正式订单
            {
                string preOrderId = Request["preOrderId"];
                if (preOrderId != null && !preOrderId.Equals(""))
                {
                    Dictionary <string, string> row = DB.SelectValue(ScTool.ORDER, preOrderId, "ID").RowDic();
                    if (row.Count > 0 && row.ContainsKey("param"))
                    {
                        string oparam    = row["param"];
                        string isSuccess = row["isSuccess"].ToLower();

                        if (isSuccess.Equals("true"))
                        {
                            Response.Write(ScTool.Alert("订单" + preOrderId + "已支付成功!"));
                        }
                        else
                        {
                            // 获取客户端类型
                            string agent   = Request.Params.Get("HTTP_USER_AGENT");
                            string payType = ScTool.payType(agent);

                            // 创建订单时,指定类型
                            if (payType.Equals(""))
                            {
                                string payTypeParam = Request["PayType"];
                                if (payTypeParam != null && (payTypeParam.Equals("Ali") || payTypeParam.Equals("Wechat")))
                                {
                                    payType = payTypeParam;
                                }
                            }

                            //param = HttpUtility.UrlDecode(param);
                            //Response.Redirect("Order.aspx?" + "PayType=" + payType + "&" + param);

                            Order.StaticParam = "PayType=" + payType + "&" + oparam + "&preOrderId=" + preOrderId;
                            Server.Transfer("Order.aspx");
                        }
                    }
                    else
                    {
                        Response.Write(ScTool.Alert("订单" + preOrderId + "不存在!请重新下单"));
                    }
                }
            }
            else
            {
                if (!param.Equals(""))
                {
                    //if (!ContainsAuthorInfo()) return;

                    //param = HttpUtility.UrlEncode(param);
                    string preOrderId = createOrder(param);
                    LabelPreOrderId.Text = "当前订单号:" + preOrderId;

                    string needMoney = Request["money"];
                    if (needMoney != null)
                    {
                        LabelPreOrderPrice.Text = "待支付金额:" + needMoney + " 元";
                    }

                    if (!preOrderId.Equals(""))
                    {
                        string data = url + "?" + "TYPE=" + "CreateOrder" + "&" + "preOrderId=" + preOrderId;
                        //Response.Redirect("QRTool.aspx?" + data);

                        //QRTool.StaticParam = data;
                        //Server.Transfer("QRTool.aspx");

                        showQR(data);
                    }
                    else
                    {
                        Response.Write("支付失败!Pay.aspx创建订单失败");
                    }
                }
                else
                {
                    if (UserType == 2)
                    {
                        ScTool.showTable(this.Controls, DB, ScTool.ORDER);
                    }
                    else if (UserType == 1)
                    {
                        ScTool.showTable(this.Controls, DB, ScTool.ORDER, "where param like '%" + "author(" + UserAccount + ")" + "%' ");
                    }
                    NoteInfo();
                }
            }
        }