private void button1_Click(object sender, EventArgs e) { string name = textBox1.Text; string passwd = textBox2.Text; string firstNew = textBox3.Text; string secondNew = textBox4.Text; md5 md = new md5(); string md5Old = md.md5_passwd(passwd); string md5New = md.md5_passwd(firstNew); if (firstNew != secondNew) { MessageBox.Show("两次输入的密码不一致"); } else { mySql mysql = new mySql(); string query = "SELECT COUNT(*) FROM `user` WHERE `name`='" + name + "' AND `passwd`='" + md5Old + "'"; int returnNumber = mysql.count(query); if (returnNumber == -2) { //do nothing } else if (returnNumber == -1) { //do nothing } else if (returnNumber == 0) { MessageBox.Show("原密码错误"); } else { if (returnNumber == 1) { //change number string updatePasswd = "UPDATE `user` set passwd='" + md5New + "' WHERE name='" + name + "'"; mysql.update(updatePasswd); MessageBox.Show("改密成功"); textBox2.Clear(); textBox3.Clear(); textBox4.Clear(); } else if (returnNumber > 1) { MessageBox.Show("系统缺陷,数据库没有做主键限制,数据库中存在两个或以上的同名用户,无法改密"); } } } }
private void button1_Click(object sender, EventArgs e) { /* * * string name = textBox1.Text; * string passwd = textBox2.Text; * * * string md5Passwd = md5_passwd(passwd); * * string query = "INSERT INTO `his`.`user` (`name`, `passwd`) VALUES ('" + name + "', '" + md5Passwd + "');"; * bool sighResult = mysql.addDate(query); * if (sighResult == true) * { * MessageBox.Show("注册成功"); * } * */ if (textBox2.Text == "") { MessageBox.Show("请填写姓名"); } else if (textBox3.Text == "") { MessageBox.Show("请填写性别"); } else if (textBox5.Text == "") { MessageBox.Show("请填写联系方式"); } else if (textBox6.Text != textBox4.Text) { MessageBox.Show("两次输入的密码不一致"); } else if (comboBox1.SelectedIndex == -1) { MessageBox.Show("请选择职位类别"); } else if (comboBox1.SelectedIndex == 1) { MessageBox.Show("暂不支持医生注册"); } else { string type = (comboBox1.SelectedIndex + 1).ToString(); md5 jiami = new md5(); string hadjiami = jiami.md5_passwd(textBox4.Text); string query = " SELECT COUNT(*) FROM user WHERE type='" + type + "'"; mySql sql = new mySql(); int num = sql.count(query) + 1; string gonghao = "0" + type + num.ToString(); query = "INSERT INTO user (`name`, `passwd`,`realname`,`sex`,`type`,`date`,`phone`) VALUES ('" + gonghao + "', '" + hadjiami + "','" + textBox2.Text + "','" + textBox3.Text + "','" + type + "','" + dateTimePicker1.Value.Date.ToString() + "','" + textBox5.Text + "');"; bool result = sql.addDate(query); if (result) { MessageBox.Show("注册成功,您的工号是" + gonghao); textBox2.Text = textBox3.Text = textBox4.Text = textBox5.Text = textBox6.Text = ""; } else { MessageBox.Show("注册失败,请重试"); } } }