Beispiel #1
0
 /// <summary>
 /// 查询用户信息
 /// </summary>
 private void getUserInfo()
 {
     user = new User();
     try
     {
         //查询
         string txtUsername = this.txtUsername.Text.Trim();
         if (txtUsername != string.Empty)
         {
             user.Name = txtUsername;
         }
         mysql_login.CreateCommand("select id,userServers from uw_account where name ='" + txtUsername + "'");
         DataTable dt = mysql_login.selectExecute();
         if (dt.Rows.Count != 0)
         {
             accountId = Convert.ToInt32(dt.Rows[0][0]);
             user.Id   = Convert.ToInt32(dt.Rows[0][0]);
             string     str             = dt.Rows[0][1].ToString();
             List <int> userServersList = JsonConvert.DeserializeObject <List <int> >(str);
             ArrayList  areaList        = new ArrayList();
             for (int i = 0; i < userServersList.Count; i++)
             {
                 areaList.Add(new DictionaryEntry(userServersList[i], userServersList[i] + "区"));
             }
             //设置用户所在区
             combArea.DataSource    = areaList;
             combArea.DisplayMember = "Value";
             combArea.ValueMember   = "Key";
             mysql_server.CreateCommand("select nickName,diamond,gold,vip from uw_user where accountid =" + accountId);
             DataTable dt2 = mysql_server.selectExecute();
             if (dt2.Rows.Count != 0)
             {
                 user.Nick    = dt2.Rows[0][0].ToString();
                 user.Diamond = Convert.ToInt32(dt2.Rows[0][1]);
                 user.Gold    = Convert.ToInt32(dt2.Rows[0][2]);
                 user.Vip     = Convert.ToInt32(dt2.Rows[0][3]);
                 //显示到界面上
                 this.panelUserInfo.Visible = true;
                 this.panelAbout.Visible    = false;
                 this.labNickname.Text      = user.Nick;
                 this.labDiamond.Text       = user.Diamond.ToString();
                 this.labGold.Text          = user.Gold.ToString();
                 this.labVip.Text           = "VIP" + user.Vip.ToString();
             }
         }
         else
         {
             this.panelUserInfo.Visible = false;
             this.panelAbout.Visible    = true;
         }
     }
     catch (Exception)
     {
         this.panelUserInfo.Visible = false;
         this.panelAbout.Visible    = true;
         MessageBox.Show("数据库连接失败,请检查是否已导入数据库。", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
     }
 }
Beispiel #2
0
        private void btnRecharge_Click(object sender, EventArgs e)
        {
            //查询
            string txtUsername = this.txtUsername.Text.Trim();

            if (txtUsername == string.Empty)
            {
                MessageBox.Show("游戏账号不能为空", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            //元宝
            string txtDiamond = this.txtDiamond.Text.Trim();

            if (txtDiamond == string.Empty)
            {
                MessageBox.Show("元宝数量不能为空", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            int diamond = Convert.ToInt32(txtDiamond);

            if (diamond <= 0)
            {
                MessageBox.Show("充值元宝数量必须大于0", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            try
            {
                mysql_server.CreateCommand("select id,vipscore from uw_user where accountid =" + accountId);
                DataTable dt = mysql_server.selectExecute();
                if (dt.Rows.Count != 0)
                {
                    //计算会员积分
                    int vipscore = Convert.ToInt32(dt.Rows[0][1]);
                    vipscore += diamond;
                    int vip = 10;
                    if (vipscore > 0 && vipscore < 61)
                    {
                        vip = 1;
                    }
                    else if (vipscore > 60 && vipscore < 421)
                    {
                        vip = 2;
                    }
                    else if (vipscore > 420 && vipscore < 981)
                    {
                        vip = 3;
                    }
                    else if (vipscore > 980 && vipscore < 1981)
                    {
                        vip = 4;
                    }
                    else if (vipscore > 1980 && vipscore < 4981)
                    {
                        vip = 5;
                    }
                    else if (vipscore > 4980 && vipscore < 9981)
                    {
                        vip = 6;
                    }
                    else if (vipscore > 9980 && vipscore < 20001)
                    {
                        vip = 7;
                    }
                    else if (vipscore > 20000 && vipscore < 36001)
                    {
                        vip = 8;
                    }
                    else if (vipscore > 36000 && vipscore < 58001)
                    {
                        vip = 9;
                    }
                    else if (vipscore > 58000 && vipscore < 98001)
                    {
                        vip = 10;
                    }
                    else if (vipscore > 98000 && vipscore < 150001)
                    {
                        vip = 11;
                    }
                    else if (vipscore > 150000 && vipscore < 210001)
                    {
                        vip = 12;
                    }
                    else if (vipscore > 210000 && vipscore < 280001)
                    {
                        vip = 13;
                    }
                    else if (vipscore > 280000 && vipscore < 360001)
                    {
                        vip = 14;
                    }
                    else if (vipscore > 360000 && vipscore < 450001)
                    {
                        vip = 15;
                    }
                    else if (vipscore > 450000 && vipscore < 550001)
                    {
                        vip = 16;
                    }
                    else if (vipscore > 550000 && vipscore < 720001)
                    {
                        vip = 17;
                    }
                    else if (vipscore > 720000 && vipscore < 980001)
                    {
                        vip = 18;
                    }
                    else if (vipscore > 980000 && vipscore < 1280001)
                    {
                        vip = 19;
                    }
                    else if (vipscore > 1280000 && vipscore < 1980001)
                    {
                        vip = 20;
                    }
                    else if (vipscore >= 1980000)
                    {
                        vip = 21;
                    }
                    else
                    {
                        vip = 0;
                    }
                    //更新
                    string sql_update = String.Format("update uw_user set diamond = diamond+{0}, vipScore=vipScore+{0} where accountid ={1}", diamond, accountId);
                    if (vip > 10)
                    {
                        sql_update = String.Format("update uw_user set diamond = diamond+{0}, vipScore=vipScore+{0},vip={1} where accountid ={2}", diamond, vip, accountId);
                    }
                    mysql_server.CreateCommand(sql_update);
                    int res = mysql_server.commonExecute();
                    if (res > 0)
                    {
                        MessageBox.Show("充值元宝成功");
                        //读取用户信息
                        getUserInfo();
                    }
                    else
                    {
                        MessageBox.Show("充值元宝失败");
                    }
                }
                else
                {
                    MessageBox.Show("账号不存在", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                    return;
                }
            }
            catch (Exception)
            {
                MessageBox.Show("数据库连接失败,请检查是否已导入数据库。", "提示:", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }