Пример #1
0
        private void buttonExit_Click(object sender, EventArgs e)   //退出
        {
            int number     = Int32.Parse(labelChenshu.Text);
            int lv         = Int32.Parse(labelLV.Text);
            int life       = Int32.Parse(labelShenming.Text);
            int attack     = Int32.Parse(labelGongji.Text);
            int defense    = Int32.Parse(labelFangyu.Text);
            int experience = Int32.Parse(labelJingyan.Text);
            int gold       = Int32.Parse(labelJingbi.Text);
            int keyyellow  = Int32.Parse(labelKeyYellow.Text);
            int keyblue    = Int32.Parse(labelKeyBlue.Text);
            int keyred     = Int32.Parse(labelKeyRed.Text);
            int keyqing    = Int32.Parse(labelKeyQin.Text);
            int id         = User.Id;
            int x          = People.X;
            int y          = People.Y;


            string sql = "update tb_game set number = '" + number + "',lv ='" + lv + "',life='" + life +
                         "',attack='" + attack + "',defense='" + defense + "',experience='" + experience + "',gold='" +
                         gold + "',keyyellow='" + keyyellow + "',keyblue='" + keyblue + "',keyred='" + keyred +
                         "',keyqing='" + keyqing + "',x='" + x + "',y='" + y + "' where uid='" + id + "'";

            MyMeans.get_cmdsql();
            if (MyMeans.b)
            {
                MyMeans.con_close();
                MessageBox.Show("退出成功");
                FormMain formMain = new FormMain();
                formMain.Close();
            }
        }
        private void buttonRegister_Click(object sender, EventArgs e)
        {
            string name           = textBoxName.Text.Trim();
            string password       = textBoxPassword.Text.Trim();
            string affirmpassword = textBoxAffirmPassword.Text.Trim();
            string phone          = textBoxPhone.Text.Trim();

            MyMeans.sqlstr = "select name from tb_user where name ='" + name + "'";
            MyMeans.get_cmd();

            if (name != "")
            {
                MyMeans.reader.Read();
                if (MyMeans.reader.HasRows)             //查到有值,则已经注册。
                {
                    MessageBox.Show("用户名已存在");
                }
                else
                {
                    MyMeans.cmd_close();     //关闭连接
                    if (password != "")
                    {
                        if (affirmpassword != "")
                        {
                            if (password.Equals(affirmpassword))
                            {
                                if (phone != "")
                                {
                                    MyMeans.sqlstr = "insert into tb_user(name,password,phone) values('" + name + "','" + password + "','" + phone + "')"; //添加用户
                                    MyMeans.get_cmdsql();
                                    if (MyMeans.b)                                                                                                         //判断是否执行成功
                                    {
                                        MyMeans.con_close();
                                        MyMeans.sqlstr = "select id from tb_user where name ='" + name + "'";   //找用户id
                                        MyMeans.get_cmd();
                                        MyMeans.reader.Read();
                                        if (MyMeans.reader.HasRows)
                                        {
                                            int id = MyMeans.reader.GetInt32(0);
                                            MyMeans.cmd_close();
                                            MyMeans.sqlstr = "insert into tb_game(uid,number,lv,life,attack,defense,experience,gold,keyyellow,keyblue,keyred,keyqing) values('" + id + "','" + 1 + "','" + 1 + "','" + 100 + "','" + 5 + "','" + 5 + "','" + 0 + "','" + 0 + "','" + 0 + "','" + 0 + "','" + 1 + "','" + 1 + "')";
                                            MyMeans.get_cmdsql();
                                            if (MyMeans.b)
                                            {
                                                MyMeans.con_close();
                                                MessageBox.Show("注册成功");
                                                textBoxName.Text           = "";
                                                textBoxPassword.Text       = "";
                                                textBoxAffirmPassword.Text = "";
                                                textBoxPhone.Text          = "";
                                            }
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("注册失败");
                                    }
                                }
                                else
                                {
                                    MessageBox.Show("请输入手机号");
                                }
                            }
                            else
                            {
                                MessageBox.Show("两次输入密码不一致");
                            }
                        }
                        else
                        {
                            MessageBox.Show("请输入确认密码");
                        }
                    }
                    else
                    {
                        MessageBox.Show("请输入密码");
                    }
                }
            }
            else
            {
                MessageBox.Show("请输入用户名");
            }
        }   //注册