学生管理系统后感

 首先,我先给大家主要说明下学生管理系统的部分组成:登录界面;管理员窗体;学生窗体.

(1)登录界面

学生管理系统后感_第1张图片

上面展示的就是我们华丽的登录界面了,是不是很漂漂呀,谢谢夸奖~!

登录的这个界面有需要注意的地方就是当我们登录的时候后台执行的就是"核对";那个"核对"是什么呢;下面给大家简单的介绍下:

    private void btnLogin_Click(object sender, EventArgs e)
          {
              string str = DBHelper.str;
             SqlConnection con = new SqlConnection(str);
              string sql = "select count(1) from student where studentname='" + txtnamea.Text + "' and loginpwd='" + txtpwdtu.Text + "' ";
              SqlCommand cmd = new SqlCommand(sql,con);
              con.Open();
              int count = Convert.ToInt32(cmd.ExecuteScalar());
             if (count > 0)
             {
                 //MessageBox.Show("登陆成功");
                 this.Hide();
                 //Welcome frm = new Welcome();
               
                 //frm.name= txtnamea.Text;
                 //frm.Show();
             }
             con.Close();
             //用户名,密码和登录类型都不能为空
             if (CheckInput())
             {
                 //显示系统管理员主窗体                                          
                 //隐藏登录窗体
                 this.Hide();
            }
            FrmAdminMain frm = new FrmAdminMain();
            //方法1:
             //frm.pwd=txtpwdtu.Text;
             //方法2:
             Tool.pwd = txtpwdtu.Text;
             frm.Show();
         }
   if (this.txtnamea.Text.Trim().Equals(string.Empty))
              {
                MessageBox.Show("请输入用户名", caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                this.txtnamea.Focus();
                return false;
             }
           else if (this.txtpwdtu.Text.Trim().Equals(string.Empty))
             {
                MessageBox.Show("请输入密码", caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.txtpwdtu.Focus();
                 return false;
             }
             else if (this.cboLoginType.Text.Trim().Equals(string.Empty))
             {
                 MessageBox.Show("请输入登录类型", caption, MessageBoxButtons.OK, MessageBoxIcon.Information);
                 this.cboLoginType.Focus();
                 return false;
             }
             else
             {
                return true;
             }

 这里注意的地方就是登录的信息是否和数据库的信息相符合.后台也就执行了这个任务.

当然这个伟大的程序也是可以修改密码,通过你的要求来查找某个同学的相关信息:

首先介绍的是修改密码的部分:

学生管理系统后感_第2张图片

这个华丽的界面就展示在我们的眼前了;修改部分的代码如下:

1  private void FrmChangePwd_Load(object sender, EventArgs e)
 2         {
 3             //颜色变化,根据个人爱好设置不同的颜色
 4             this.BackColor = Color.Black;
 5             //显示旧密码到就文本框里面;方便;
6 txtoldpwd.Text = Tool.pwd; 7 } 8 9 private void btnqueren_Click(object sender, EventArgs e) 10 { 11 string num = txtnewpwd.Text; 12 string str = DBHelper.str; 13 14 string sql = "update student set loginpw
    d='" + num + "' where loginpwd='" + txtoldpwd.Text + "'"; 15 SqlConnection con = new SqlConnection(str); 16 SqlCommand cmd = new SqlCommand(sql, con); 17 con.Open(); 18 if (txtconfrimpwd.Text.Equals(num)) 19 { 20 int com = Convert.ToInt32(cmd.ExecuteScalar()); 21 } 22 23 DialogResult result = MessageBox.Show
("确定要修改密码吗?","温馨提示",MessageBoxButtons.YesNo,MessageBoxIcon.Question); 24 if (result==DialogResult.Yes) 25 { 26 this.Close(); 27 } 28 con.Close();

 (2)学生管理界面:

学生管理系统后感_第3张图片

问题一:如何获取年级代号:

1     //加载年级到下拉框信息
 2         public void LoadGrade() {
 3 
 4             //拿到所有年级名称
 5             string str = DBHelper.str;
 6             SqlConnection con = new SqlConnection(str);
 7             string sql = "select gradename from grade";
 8             SqlCommand cmd = new SqlCommand(sql, con);
 9 
10             con.Open();
11             SqlDataReader dr = cmd.ExecuteReader();
12 
13             if (dr != null)
14             {
15                 if (dr.HasRows)
16                 {
17                     while (dr.Read())
18                     {
19                         string gname = dr["gradename"].ToString();
20                         //将年级放到下拉框中
21                         cbograde.Items.Add(gname);
22                     }
23                 }
24             }

 问题二:获取所有学生信息:

//通过学生学号更改信息
 2         public void LoadStudentbyStudentno() {
 3             string str = DBHelper.str;
 4             SqlConnection con = new SqlConnection(str);
 5          
 6             string sql = "select *from student where studentno=" + studentNo + "";
 7             SqlCommand cmd = new SqlCommand(sql,con);
 8           
 9             try
10             {
11                 con.Open();
12                 SqlDataReader dr = cmd.ExecuteReader();
13                 //一列拆解,复制到当前的文本框
14                 while (dr.Read())
15                 {
16                   //获取名字
17                     string stuname = dr["studentname"].ToString();
18                     txtname.Text = stuname;
19                     //获取电话
20                     string stuphone = dr["phone"].ToString();
21                     txtphone.Text = stuphone;
22                     //获取地址
23                     string stuadress = dr["address"].ToString();
24                     txtadress.Text = stuadress;
25                     //获取邮件
26                     string stuemail= dr["email"].ToString();
27                     txtemail.Text = stuemail;
28                     ////获取密码
29                     //string strpwd=dr["LoginPwd"].ToString();
30                     //txtpwd.Text = strpwd;
31                     ////确认密码
32                     //txttruepwd.Text = strpwd;                               
33                     //获取出生日期
34                     DateTime day =Convert.ToDateTime( dr["birthday"]);
35                     cbobirthdatetime.Value = day;
36                     //获取年级名称
37                     int getid = Convert.ToInt32(dr["gradeid"]);
38                     string gradename = GetidName(getid);
39                     cbograde.Text = gradename;
40                     //获取性别
41                     string genders=dr["gender"].ToString();
42                     if (genders.Equals("0"))
43                     {
44                         rbtnFemale.Checked = true;
45                     }
46                     if(genders.Equals("1")) {
47 
48                         rbtnMale.Checked = true;
49                   }

 问题三:将年级编号转为年纪名称:

 

//将年级编号转换为年级名称
 2         public string GetidName(int getid)
 3         {
 4             string str = DBHelper.str;
 5             SqlConnection con = new SqlConnection(str);
 6          
 7                string sql = "select gradename from grade where gradeid=" + getid + "";
 8             SqlCommand cmd = new SqlCommand(sql, con);
 9             string getname = "";
10             try
11             {
12                 con.Open();
13                 getname = cmd.ExecuteScalar().ToString();
14             }
15             catch (Exception)
16             {
17 
18             }
19             finally
20             {
21                con.Close();
22             }
23             return getname;
24                 }

 

 问题四:修改部分(就是将编辑窗体改为修改窗体):

private void FrmEditStudent_Load(object sender, EventArgs e)
 2         {
 3             LoadGrade();
 4             //当点修改按钮时,变成修改窗体
 5             if (studentNo != 0)
 6             {
 7                 this.Text = "修改学生信息";
 8                 btnsave.Text = "修改";
 9             }
10             else {
11                 this.Text = "编辑学生信息";
12                 btnsave.Text = "保存";          
13             }
14                         
15             txtnano.Text = studentNo.ToString();
16             LoadStudentbyStudentno();
17         }

 问题五:修改学生信息:

public void updateInfo() {
 2             //修改密码
 3             string pwd = txtpwd.Text;
 4             //修改姓名
 5             string studentname = txtname.Text;
 6             //修改性别
 7             string studentgender = string.Empty;
 8             if (rbtnFemale.Checked)//女
 9             {
10                 studentgender = "0";
11             }
12             else if (rbtnMale.Checked)//男
13             {
14                 studentgender = "1";
15             }
16             //如何给下拉框绑定数据
17             int getid = GetIdByName();
18             //修改电话
19             string phone = txtphone.Text;
20             //修改地址
21             string adrers = txtadress.Text;
22             //修改日期
23             DateTime birthdate = this.cbobirthdatetime.Value;
24             //修改邮件
25             string emailt = txtemail.Text;
26             string sql =string.Format("update student set loginpwd='{0}',studentname='{1}',gender='{2}',gradeid='{3}',phone='{4}',address='{5}',birthday='{6}',email='{7}' where studentno={8}", pwd, studentname, studentgender, getid, phone, adrers, birthdate, emailt,studentNo);
27             string str = DBHelper.str;
28             SqlConnection con = new SqlConnection(str);
29             SqlCommand cmd = new SqlCommand(sql, con);
30             con.Open();
31             int count = cmd.ExecuteNonQuery();
32             if (count>0)
33             {
34                 //调用查询窗口的一个DataSelect()方法
35                 frmselectInfo.DataSelect();
36                 MessageBox.Show("修改成功");
37             }
38             else
39             {
40                 MessageBox.Show("失败");
41             }
  //根据学号是否为0,判定该按钮用来执行“添加”还是“修改”
              if (studentNo != 0)
              {
                  //修改
                  updateInfo();
              }
              else
            {
                 //添加
                AddStudent();
             

 问题六:

//该方法将年级名称转换成年级编号
 2         public int GetIdByName()
 3         {
 4             string str = DBHelper.str;
 5             SqlConnection con = new SqlConnection(str);
 6             string sql = "select gradeid from grade where gradename='" + cbograde.Text + "'";
 7             SqlCommand cmd = new SqlCommand(sql, con);
 8             int getid = 0;
 9             try
10             {
11                 con.Open();
12                 getid = Convert.ToInt32(cmd.ExecuteScalar());
          }

(3)查询学生信息:

学生管理系统后感_第4张图片

查询前的提示代码显示部分:

1     private void FrmSearchByName_Load(object sender, EventArgs e)
 2         {
 3             //在Load事件中编写代码提前显示
 4             //查询
 5             string sql = @"select Studentno,Studentname,Gender,gradename
 6                             from student,grade
 7                             where student.gradeid=grade.gradeid ";
 8             LoadFrmListView(sql);
 9         }
10         //查询数据
11         public void DataSelect()
12         {
13             lvlistview.Items.Clear();
14             string sql = @"select studentno,studentname,Gender,gradename from student,grade   
15            where student.gradeid=grade.gradeid and studentname like '%" + txtsearchname.Text + "%'";
16             LoadFrmListView(sql);
17         }

获取学号代码:

 1   private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
 2         {
 3 
 4             if (this.lvlistview.SelectedItems.Count > 0)
 5             {
 6                 FrmEditStudent frm = new FrmEditStudent();
 7                 //将选中的学号传递到"编辑学生信息窗体"
 8                 //frm.studentNo = Convert.ToInt32(this.lvlistview.SelectedItems[0].Text);也可以
 9                 frm.studentNo = Convert.ToInt32(this.lvlistview.SelectedItems[0].SubItems[0].Text);
10                 frm.MdiParent = this.MdiParent;
11                 frm.frmselectInfo = this;
12                 frm.Show();

 获取学生信息:

   //获取学号
 2                             int stuNo = Convert.ToInt32(dr["studentno"]);
 3                             //第二列获取姓名 stuname
 4                             string stuName = Convert.ToString(dr["studentname"]);
 5                             //第三列 获取 性别
 6                             string stugender = Convert.ToString(dr["gender"]);
 7                             //获取年级名称
 8                             string gname = Convert.ToString(dr["gradename"]);
 9                             //
10                             ListViewItem lvItem = new ListViewItem(stuNo.ToString());
11                             lvItem.SubItems.Add(stuName);//接收学生名字
12                             lvItem.SubItems.Add(stugender);//接收学生性别
13                             lvItem.SubItems.Add(gname);//接收学生年级名称
14                             //让lvItem和ListView关联
15                             lvlistview.Items.Add(lvItem);
16                         }

 

以上就是学生管理系统经常遇到的问题,可能还有不足之处,请大家多提提建议,谢谢

 

你可能感兴趣的:(学生管理系统后感)