项目效果
把管理员的登录放在了panel里。
共有登录,注册,加载,管理 ,修改,管理员操作6个窗体。
登录:
a.Open();
string uid = textBox1.Text.Trim();
string pwd = textBox2.Text.Trim();
if (textBox1.Text==""||textBox2.Text=="")
{
MessageBox.Show("账号或密码不能为空","提醒");
a.Close();
}
else
{
string sqlstr="select uid,pwd from 班级表 where uid = " + uid + " and pwd = " + pwd ;
SqlCommand sqlCommand = new SqlCommand(sqlstr, a);
SqlDataReader dataReader = sqlCommand.ExecuteReader();
try
{
if( dataReader.HasRows )
{
MessageBox.Show("登录成功","恭喜您");
this.Hide();
Form1 c = new Form1();
c.Show();
}
else
{
MessageBox.Show("账号或者密码错误");
}
}
catch
{
MessageBox.Show("失败");
}
finally
{
a.Close();
dataReader.Dispose();
}
}
注册:
if (textBox1.Text == "" || textBox2.Text == "" || textBox3.Text == "" || textBox4.Text == "")
{
MessageBox.Show("请把信息填写完整");
}
else
{
sql.Open();
string s2 = Convert.ToString(textBox2.Text);
string s3 = Convert.ToString(textBox3.Text);
string s4 = Convert.ToString(textBox4.Text);
string sqladd = "insert into 班级表 (uid,pwd ,name ,class) values ( " + textBox1.Text + " , ' " + s2 + " ' , '" + s3 + " ' ,'" + s4 + " ' " + " ) ";
SqlCommand n = new SqlCommand(sqladd, sql);
try
{
n.ExecuteNonQuery();
MessageBox.Show("注册成功!", "恭喜你");
}
catch
{
MessageBox.Show("失败");
}
finally
{
sql.Close();
}
}
修改的bug1:直接在注册界面退出程序:
在formclosing事件中:
DialogResult result = MessageBox.Show("直接退出得到话会直接退出程序", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);
if (result == DialogResult.OK)
{
Dispose();
Application.Exit();
}
else
{
a.Cancel = true;
}
修改:
conn.Open();
string s1 = textBox1.Text;
string s2 = textBox2.Text;
string s3 = textBox3.Text;
for (int i = Form1.form1.dataGridView1.SelectedRows.Count; i > 0; i--)
{
int ID = Convert.ToInt32(Form1.form1.dataGridView1.SelectedRows[i - 1].Cells[0].Value);
string updata = "update 属性表 set name= '" + s1 + "',sex = '" + s2 + "',occupation = '" + s3 + " ' where id = "+ID;
SqlCommand sqlupdata = new SqlCommand(updata, conn);
try
{
sqlupdata.ExecuteNonQuery();
MessageBox.Show("成功");
}
catch
{
MessageBox.Show("失败");
}
} conn.Close();