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 Login() { try { if (txtUserName.Text != "" & txtUserPwd.Text != "") { //用自定义方法getcom()在Login数据表中查找是否有当前登陆用户 SqlDataReader temDR = MyClass.getcom("select * from tb_UserLogin where name='" + txtUserName.Text.Trim() + "'and password='******'"); bool ifcom = temDR.Read(); //当有记录时,表示用户名和密码正确 if (ifcom) { string today = DateTime.Now.ToString("yyyy年MM月"); //获取当天时间 DataClass.MyMeans.Login_Name = txtUserName.Text.Trim(); //将用户名记录到公共变量中 DataClass.MyMeans.Login_ID = temDR.GetValue(temDR.GetOrdinal("popenum")).ToString(); //获取权限下的编号 DataClass.MyMeans.Login_Time = DateTime.Now.ToString(); //获取当前登录时间 DataClass.MyMeans.User_Pope = temDR.GetString(temDR.GetOrdinal("pope")); //获取当前登录者权限 DataClass.MyMeans.User_Pwd = temDR.GetString(temDR.GetOrdinal("password")); //获取当前登录者密码 DataClass.MyMeans.User_ID = Convert.ToInt32(temDR.GetValue(temDR.GetOrdinal("IDU"))); //获取当前登录者ID this.Hide(); //关闭当前窗口 F_Parent Main = new F_Parent(); //建立新窗口 Main.Show(); //显示新窗口 } else { MessageBox.Show("用户名或密码错误!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information); //显示具有指定内容的消息框 txtUserName.Text = ""; //用户名密码错误时将会把用户名和密码栏都清空 txtUserPwd.Text = ""; txtUserName.Focus(); //鼠标焦点指向用户名栏便于用户重新输入 } MyClass.con_close(); //关闭数据库连接 } else { MessageBox.Show("请将登录信息添加完整!", "信息输入不完整", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show(ex.Message, "警告"); } }
private void buttonLogin_Click(object sender, EventArgs e) { if (textUsername.Text != null & textPassword.Text != null) { String SQLstr = "select * from tbl_user where username='******'and password='******'"; SqlDataReader user = MyMeans.getcom(SQLstr); bool ifcom = user.Read(); if (ifcom) { MyMeans.con_close(); string time = DateTime.Now.ToString(); this.Hide(); fm.toolStripMenuuser.Text = textUsername.Text; fm.ShowDialog(); } else { i++; if (i >= 3) { buttonLogin.Enabled = false; textError.Text = "密码错误3次,请退出!"; } else { textError.Text = "用户名或密码错误,请重新输入!"; textPassword.Text = ""; textPassword.Focus(); } } MyMeans.con_close(); } else { textError.Text = "请将登录信息填写完整!"; textPassword.Focus(); } }
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("请输入用户名"); } } //注册