Esempio n. 1
0
        }//右

        private void FormMain_Load(object sender, EventArgs e)
        {
            PictureBox[,] pb = new PictureBox[11, 11]
            {
                { pictureBox1_1, pictureBox1_2, pictureBox1_3, pictureBox1_4, pictureBox1_5, pictureBox1_6, pictureBox1_7, pictureBox1_8, pictureBox1_9, pictureBox1_10, pictureBox1_11 },
                { pictureBox2_1, pictureBox2_2, pictureBox2_3, pictureBox2_4, pictureBox2_5, pictureBox2_6, pictureBox2_7, pictureBox2_8, pictureBox2_9, pictureBox2_10, pictureBox2_11 },
                { pictureBox3_1, pictureBox3_2, pictureBox3_3, pictureBox3_4, pictureBox3_5, pictureBox3_6, pictureBox3_7, pictureBox3_8, pictureBox3_9, pictureBox3_10, pictureBox3_11 },
                { pictureBox4_1, pictureBox4_2, pictureBox4_3, pictureBox4_4, pictureBox4_5, pictureBox4_6, pictureBox4_7, pictureBox4_8, pictureBox4_9, pictureBox4_10, pictureBox4_11 },
                { pictureBox5_1, pictureBox5_2, pictureBox5_3, pictureBox5_4, pictureBox5_5, pictureBox5_6, pictureBox5_7, pictureBox5_8, pictureBox5_9, pictureBox5_10, pictureBox5_11 },
                { pictureBox6_1, pictureBox6_2, pictureBox6_3, pictureBox6_4, pictureBox6_5, pictureBox6_6, pictureBox6_7, pictureBox6_8, pictureBox6_9, pictureBox6_10, pictureBox6_11 },
                { pictureBox7_1, pictureBox7_2, pictureBox7_3, pictureBox7_4, pictureBox7_5, pictureBox7_6, pictureBox7_7, pictureBox7_8, pictureBox7_9, pictureBox7_10, pictureBox7_11 },
                { pictureBox8_1, pictureBox8_2, pictureBox8_3, pictureBox8_4, pictureBox8_5, pictureBox8_6, pictureBox8_7, pictureBox8_8, pictureBox8_9, pictureBox8_10, pictureBox8_11 },
                { pictureBox9_1, pictureBox9_2, pictureBox9_3, pictureBox9_4, pictureBox9_5, pictureBox9_6, pictureBox9_7, pictureBox9_8, pictureBox9_9, pictureBox9_10, pictureBox9_11 },
                { pictureBox10_1, pictureBox10_2, pictureBox10_3, pictureBox10_4, pictureBox10_5, pictureBox10_6, pictureBox10_7, pictureBox10_8, pictureBox10_9, pictureBox10_10, pictureBox10_11 },
                { pictureBox11_1, pictureBox11_2, pictureBox11_3, pictureBox11_4, pictureBox11_5, pictureBox11_6, pictureBox11_7, pictureBox11_8, pictureBox11_9, pictureBox11_10, pictureBox11_11 }
            };
            Label[] label = new Label[] { labelChenshu, labelLV, labelShenming, labelGongji, labelFangyu, labelJingyan, labelJingbi, labelKeyYellow, labelKeyBlue, labelKeyRed, labelKeyQin, label3, label11 };

            for (int j = 0; j <= 18; j++)
            {
                string map = "map" + j;
                MainSql.mapxytable(j, map);
                for (int i = 0; i < Int32.Parse(MyMeans.dt.Rows.Count.ToString()); i++)
                {
                    pb[Int32.Parse(MyMeans.dt.Rows[i][1].ToString()) - 1, Int32.Parse(MyMeans.dt.Rows[i][0].ToString()) - 1].Image = imageList1.Images[j];
                }
            }
            int uid = User.Id;

            MyMeans.sqlstr = "select number,lv,life,attack,defense,experience,gold,keyyellow,keyblue,keyred,keyqing,x,y from tb_game where uid ='" + uid + "'";
            MyMeans.get_cmd();
            if (MyMeans.reader.HasRows)
            {
                if (MyMeans.reader.Read())
                {
                    for (int m = 0; m < 13; m++)
                    {
                        label[m].Text = MyMeans.reader.GetInt32(m).ToString();
                    }
                    pictureBoxPeople.Left = pictureBoxPeople.Left + ((People.X - 1) * 45);
                    pictureBoxPeople.Top  = pictureBoxPeople.Top - ((People.Y - 1) * 45);
                    MyMeans.cmd_close();
                }
            }
            else
            {
                MessageBox.Show("找不到数据");
                MyMeans.cmd_close();
            }
        }
Esempio n. 2
0
        private void buttonLogin_Click(object sender, EventArgs e)
        {
            //获取窗体数据
            string name     = textName.Text.Trim();
            string password = textPassword.Text.Trim();

            //执行语句
            MyMeans.sqlstr = "select password,id from tb_user where name = '" + name + "'";
            MyMeans.get_cmd();

            if (name != "" & password != "")
            {
                MyMeans.reader.Read();
                if (MyMeans.reader.HasRows)       //判断是否有值,没有的话用户名错误
                {
                    string pwd = MyMeans.reader.GetString(MyMeans.reader.GetOrdinal("password"));
                    if (password.Equals(pwd))
                    {
                        User.Id = MyMeans.reader.GetInt32(1); //将用户ID传到静态变量里
                        MyMeans.cmd_close();                  //关闭连接
                        FormMain formMain = new FormMain();
                        formMain.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("密码错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    }
                }
                else
                {
                    MessageBox.Show("用户名错误", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
            }
            else
            {
                MessageBox.Show("用户名或密码为空", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }                                                                  //登录
        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("请输入用户名");
            }
        }   //注册