<%@ Page Language="C#" %>
<%@ Import Namespace="System.Collections.Generic" %>
<script runat="server">
    
    
    string tCode = "v12399wan";
    string key = "HR1G4US25FSG57J4";
    
    protected override void OnError(EventArgs e)
    {
       System.Exception error = Server.GetLastError();
       Server.ClearError();
       Response.Write(error.Message);
    }
    com.xykj.business.View.Games.Game _games = new com.xykj.business.View.Games.Game();
    com.xykj.business.View.Games.Server _servers = new com.xykj.business.View.Games.Server();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (com.xykj.business.View.Account.Account.LoginUser==null)
        {
            Response.Redirect("/");
            return;
        }
        com.xykj.business.View.Account.GroupManage gm = new com.xykj.business.View.Account.GroupManage();
        var group = gm.GetGroupById(com.xykj.business.View.Account.Account.LoginUser.Group);
        if (!group.IsAdmin)
        {
            Response.Redirect("/message-9999999.html", true);
        }
        if (!Page.IsPostBack)
        {
          IList<com.xykj.model.xy_games> games=  _games.GetGame();
          select_game.Items.Clear();
          select_server.Items.Clear();
          select_game.Items.Add(new ListItem() { Value="-1", Text="请选择游戏" });
          foreach (var item in games)
          {
              select_game.Items.Add(new ListItem() { Text = item.Name, Value = item.ID+"" });
          }
        }
    }

    void select_game_SelectedIndexChanged(object sender, EventArgs e)
    {
        select_server.Items.Clear();
        int xd=0;
        IList<com.xykj.model.xy_servers> servers = _servers.GetServerByGidWeb(int.Parse(select_game.SelectedValue), 100000, 1, out xd);
        foreach (var item in servers)
        {
            select_server.Items.Add(new ListItem() { Text = item.Name, Value = item.ID + "" });
        }
    }
    protected void FirstPay(object sender, EventArgs e)
    {
        var user = new com.xykj.business.View.Account.User().GetUserByAccount(input_account.Text);
        
        int gid = XY.ToInt(select_game.SelectedValue);
        int sid = XY.ToInt(select_server.SelectedValue);
        var game = new com.xykj.business.View.Games.Game().GetGame(gid)[0];
        var server = new com.xykj.business.View.Games.Server().GetServer(sid);
        var port = new com.xykj.business.View.Games.Port().GetPortByGameId(game.ID); 
        string uid = user.ID + "";
        if (acc_mod_acc.Checked)
        {
            uid = user.Account;
        }
        else
        {
            uid = user.ID + "";
        } 
        string gameNo = port.GameNubmer;
        string serverNo = server.ServerNumber; 
        string md5 = string.Format("{0}&{1}&{2}&{3}&{4}", tCode, uid, gameNo, serverNo, key); 
        string sign = XY.MD5(md5); 
        string parm = string.Format("tCode={0}&uid={1}&gameNo={2}&serverNo={3}&sign={4}", tCode, uid, gameNo, serverNo, sign);
        string url = "http://pay.g.v1.cn/externalPort/hfCharge?" + parm; 
        string temp_res = XY.GetUrlByStream(url, "utf-8");
        fpClass payJson = XY.JToObject<fpClass>(temp_res);
        if (payJson.result=="0")
        {
            ShowMsg("充值录入成功[首冲成功]");
        }
        else
        {
            ShowMsg(payJson.message+"[首冲失败]");
        }
    }
    protected void ShowMsg( string msg ) 
    {
        msg = msg.Replace("'", " ").Replace(";", " ").Replace("<", " ").Replace(">", " ");
        Response.Write("<script>alert('" + msg + "')<"+"/script>");
    }
    class fpClass {
        public string result;
        public string message;
    }
</script>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
<form  runat="server">
 <table>
    <tr><td>游戏首冲</td></tr>
    <tr><td colspan="3">如果选择的不是V1混服游戏,则充值可能出现异常</td></tr>
    <tr><td>游戏:</td><td><asp:DropDownList AutoPostBack="true" OnSelectedIndexChanged="select_game_SelectedIndexChanged" ID="select_game" runat="server"/></td></tr>
    <tr><td>服务器:</td><td><asp:DropDownList AutoPostBack="true" ID="select_server" runat="server"/></td></tr>
    <tr><td>账号:</td><td><asp:TextBox ID="input_account" runat="server" /> </td></tr>
    <%--<tr><td>金额:</td><td><asp:TextBox ID="input_money" runat="server" /> </td></tr>--%>

    <tr><td>账号模式:</td><td>
    <asp:RadioButton runat="server" ID="acc_mod_acc" Checked="true" Text="账号模式" GroupName="acc_model"/>
    <asp:RadioButton runat="server" ID="acc_mod_id" Text="ID模式" GroupName="acc_model" /> </td></tr>


    <tr><td>金额:</td><td><asp:Button  OnClick="FirstPay" OnClientClick="return isFirstPay()" runat="server" Text="确认首冲" /></td></tr>
 </table>
</form>
<script type="text/javascript">
    function isFirstPay() {
        if (!confirm("请确认您的信息准确性\r\n操作是无法撤回的")) {
            return false;
        }
        return true;
    }
</script>
</body>
</html>
