📄 form2.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using 报刊管理.类; //添加引用
using System.Data.SqlClient;
namespace 报刊管理
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
SqlBaseClass SqlClass = new SqlBaseClass(); //声明数据库操作类的对象
WinOperationClass WinFormClass = new WinOperationClass();//声明对窗体操作的类对象
private void ClearControls()
{
this.textBox1.Text = "";
this.textBox2.Text = "";
this.textBox3.Text = "";
this.textBox4.Text = "";
this.textBox5.Text = "";
this.textBox6.Text = "";
this.textBox7.Text = "";
this.textBox8.Text = "";
}
private void button1_Click(object sender, EventArgs e)
{
if (this.textBox1.Text.Length == 0)
{
MessageBox.Show("用户名不能为空!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
string cmd = "SELECT UserID FROM N_User WHERE UserID = '" + this.textBox1.Text + "' ";
SqlDataReader de = SqlClass.GetReader(cmd);
de.Read();
if (de.HasRows)
{
MessageBox.Show("该用户已存在,请重新输入!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
de.Close();
}
if (this.textBox2.Text.Length < 6)
{
MessageBox.Show("密码不能小于6位!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (this.textBox2.Text!=this.textBox8.Text)
{
MessageBox.Show("密码输入不同,请重新输入!", "提示框", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (this.textBox5.Text.Length == 0)
{
MessageBox.Show("部门名不能为空!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
if (!WinFormClass.validateEmail(textBox6.Text.Trim()))
{
MessageBox.Show("E-mail地址输入格式不正确!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
else
{
string P_cmdtxt = "SELECT * FROM N_Dept WHERE DeptName = '" + this.textBox5.Text + "'";
SqlDataReader dk = SqlClass.GetReader(P_cmdtxt);
dk.Read();
string deptID = dk["DeptID"].ToString();
dk.Close();
string Str_sqlcmd = "INSERT INTO N_User VALUES( '" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox4.Text + "'";
Str_sqlcmd += ",'" + this.textBox6.Text + "','" + this.textBox7.Text + "','" + deptID + "','用户')";
if (SqlClass.GetExecute(Str_sqlcmd))
{
MessageBox.Show("注册成功!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
Form1 login = new Form1();
this.Hide();
login.Show();
}
else
{
MessageBox.Show("注册失败,请重新注册!", "输入提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
}
private void button2_Click(object sender, EventArgs e)
{
ClearControls();
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
}
private void button3_Click(object sender, EventArgs e)
{
Form f1 = new Form1();
this.Hide();
f1.Show();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -