📄 frmadduser.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace 学生宿舍管理系统
{
public partial class FrmAddUser : Form
{
public FrmAddUser()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string s1 = "select 用户名 from 登录信息表 where 用户名='" + textBox1.Text + "'";
MyData mydata=new MyData ();
OleDbDataReader dr=mydata .getDataReader (s1);
if (dr.HasRows)
{
while (dr.Read())
{
string strusername = dr["用户名"].ToString().Trim();
if (this.textBox1.Text == strusername)
{
MessageBox.Show("用户名已经存在!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.textBox1.Text = "";
this.textBox2.Text = "";
this.textBox3.Text = "";
this.textBox1.Focus();
}
}dr.Close();
}
else if (this.textBox2.Text.Trim() == "")
{
MessageBox.Show("请输入密码!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else if (this.textBox2.Text != this.textBox3.Text)
{
MessageBox.Show("两次密码输入不一致!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.textBox2.Text = "";
this.textBox3.Text = "";
this.textBox1.Focus();
}
else if (this.comboBox1.Text == "")
{
MessageBox.Show("请选择身份!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
return;
}
else
{
string s2 = "insert into 登录信息表(用户名,密码,身份) values ('" + textBox1.Text + "','" + textBox2.Text + "','" + comboBox1.Text + "')";
mydata.updateSql(s2);
MessageBox.Show(" 注册成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.textBox1.Text = "";
this.textBox2.Text = "";
this.textBox3.Text = "";
this.comboBox1.Text = "";
this.textBox1.Focus();
}
mydata.closeConnection();
}
private void button2_Click_1(object sender, EventArgs e)
{
this.Close();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -