吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 14044|回复: 65
收起左侧

[其他原创] 【C#】学生成绩管理系统设计 终

  [复制链接]
夏沫梦影 发表于 2019-6-2 03:37
本帖最后由 夏沫梦影 于 2019-6-6 07:05 编辑

功能介绍:
          这是
一个学生成绩管理系统。包括“登录窗体”、“主窗体”和“学生信息管理模块”、“课程信息管理模块”、“成绩管理模块”。项目运行以后只显示登录窗体,当输入正确的“用户名”和“密码”以后点击登录按钮,打开主窗体。主窗体上通过“主菜单”和“子菜单”触发相应模块功能。




数据库设计:
相关资源下载:(包含数据库文件Access,图片资源以及。。。)
2019/6/6更新说明:
       登录窗体新增注册按钮、权限选项,主窗体新增改密按钮,修复一些异常报错,还有一些想法就不一一实践了,这是最后一次更新。



1.窗体设计:



    点击“登录”按钮以后连接数据库,验证用户输入信息是否正确,如正确,打开主窗体,隐藏登录窗体;如不正确,给出提示信息。点击“退出”按钮,关闭程序。



2.创建公共类DataAccess:

[Visual Basic .NET] 纯文本查看 复制代码
class DataAccess
    {
        string conStr;
        OleDbConnection con;

        //连接数据库
        public void dataCon()
        {
            conStr = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" + Application.StartupPath + "\\student.mdb";
            con = new OleDbConnection(conStr);
        }

        //查询数据库
        public DataSet getDataSet(string sql)
        {
            DataSet ds = new DataSet();

            try
            {
                con.Open();
                OleDbCommand cmd = new OleDbCommand(sql, con);
                OleDbDataAdapter da = new OleDbDataAdapter(cmd);
                da.Fill(ds);
                return ds;
            }
            catch (Exception ex)
            {
                throw new Exception(ex.ToString());
            }
            finally
            {
                con.Close();
            }
        }
        public bool sqlExec(string sql)
        {
            try
            {
                con.Open();
            }
            catch
            {
                MessageBox.Show("数据库未连接!");
            }
            try
            {
                OleDbCommand oledbCom = new OleDbCommand(sql, con);
                oledbCom.ExecuteNonQuery();
                return true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "提示");
                return false;
            }
            finally
            {
                con.Close();
            }
        }
    }


3.“登录”按钮及“退出”按钮点击事件:
[Visual Basic .NET] 纯文本查看 复制代码
        public static string Uname;
        public static string Upsw;
        private void BtLogin_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text.Trim();
            string password = txtPassword.Text.Trim();
            if (txtUsername.Text.Trim() != "" && txtPassword.Text.Trim()!=" ")
            {
            //连接数据库
                DataAccess data = new DataAccess();
                data.dataCon();
   
            //查询数据库
            string cmdStr = "Select * from Userinfo where Userid='"+username+"' and Userpwd='"+password+"'";
            DataSet ds;
            ds = data.getDataSet(cmdStr);
            if (ds.Tables[0].Rows.Count == 1)
            {
                  Uname = txtUsername.Text.Trim();
                  Upsw = txtPassword.Text.Trim();
                  FormMain fmain = new FormMain();
                    if (ds.Tables[0].Rows[0]["Userlevel"].ToString() == "学生" && level.SelectedIndex == 0)
                    {
                        fmain.学生信息添加ToolStripMenuItem.Enabled = false;
                        fmain.学生信息修改ToolStripMenuItem.Enabled = false;
                        fmain.学生信息删除ToolStripMenuItem.Enabled = false;
                        fmain.课程信息ToolStripMenuItem.Enabled = false;
                        fmain.课程信息修改ToolStripMenuItem.Enabled = false;
                        fmain.课程信息删除ToolStripMenuItem.Enabled = false;
                        fmain.成绩添加ToolStripMenuItem.Enabled = false;
                        fmain.成绩删除ToolStripMenuItem.Enabled = false;
                        fmain.成绩修改ToolStripMenuItem.Enabled = false;
                        fmain.Show();
                        this.Hide();
                    }
                    else if (ds.Tables[0].Rows[0]["Userlevel"].ToString() == "教师" && level.SelectedIndex == 1)
                    {
                        fmain.Show();
                        this.Hide();
                    }
                    else
                    {
                        MessageBox.Show("权限选择错误!!");
                    }

            }else
            {
                MessageBox.Show("账号或密码错误!");
            }
            }
            else
            {
                MessageBox.Show("用户名和密码不能为空!");   
            }
            }

        private void BtCanel_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void FormLogin_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }

        private void FormLogin_Load(object sender, EventArgs e)
        {
            level.SelectedIndex = 0;
        }

        private void linkLabel_Regist_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            FormRegist Regist = new FormRegist();
            Regist.Show();
        }

4.主窗体:

通过点击各个子菜单项及工具栏按钮打开相应子窗体。

5.主窗体菜单、工具按钮点击事件:
[Visual Basic .NET] 纯文本查看 复制代码
private void FormMain_FormClosing(object sender, FormClosingEventArgs e)
        {
            Application.Exit();
        }
        private void FormMain_Load(object sender, EventArgs e)
        {
            timer1.Interval = 1000;
            timer1.Start();
        }
        
        private void timer1_Tick(object sender, EventArgs e)
        {
            this.toolStripStatusLabel3.Text = "登录时间:" + DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss");
        }
        private void 学生信息查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageStu ManageStu = new frmManageStu();
            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            DataAccess data = new DataAccess();
            data.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds;
            ds = data.getDataSet(cmdStr);
            if (ds.Tables[0].Rows[0]["Userlevel"].ToString() == "学生" )
            {
                ManageStu.btnDel.Enabled = false;
                ManageStu.btnEdit.Enabled = false;
            }
            ManageStu.MdiParent = this;
            ManageStu.Show();
        }
        private void 学生信息添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAddStu Addstu = new frmAddStu();
            Addstu.MdiParent = this;
            Addstu.Show();
        }

        private void 学生信息修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageStu ManageStu = new frmManageStu();
            ManageStu.MdiParent = this;
            ManageStu.Show();
        }
        private void 学生信息删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageStu ManageStu = new frmManageStu();
            ManageStu.MdiParent = this;
            ManageStu.Show();
        }

        private void 课程信息查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageCourse ManageCourse = new frmManageCourse();
            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            DataAccess data = new DataAccess();
            data.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds;
            ds = data.getDataSet(cmdStr);
            if (ds.Tables[0].Rows[0]["Userlevel"].ToString() == "学生")
            {
                ManageCourse.btnDel.Enabled = false;
                ManageCourse.btnEdit.Enabled = false;
            }
            ManageCourse.MdiParent = this;
            ManageCourse.Show();
        }

        private void 课程信息修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAddCourse AddCourse = new frmAddCourse();
            AddCourse.MdiParent = this;
            AddCourse.Show();
        }
        private void 课程信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageCourse ManageCourse = new frmManageCourse();
            ManageCourse.MdiParent = this;
            ManageCourse.Show();
        }
        private void 课程信息删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageCourse ManageCourse = new frmManageCourse();
            ManageCourse.MdiParent = this;
            ManageCourse.Show();
        }

        private void 成绩查询ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageScore ManageScore = new frmManageScore();
            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            DataAccess data = new DataAccess();
            data.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds;
            ds = data.getDataSet(cmdStr);
            if (ds.Tables[0].Rows[0]["Userlevel"].ToString() == "学生")
            {
                ManageScore.btnDel.Enabled = false;
                ManageScore.btnEdit.Enabled = false;
            }
            ManageScore.MdiParent = this;
            ManageScore.Show();
        }
        private void 成绩修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageScore ManageScore = new frmManageScore();
            ManageScore.MdiParent = this;
            ManageScore.Show();
        }
        private void 成绩删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmManageScore ManageScore = new frmManageScore();
            ManageScore.MdiParent = this;
            ManageScore.Show();
        }

        private void 成绩添加ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmAddCredit AddCredit = new frmAddCredit();
            AddCredit.MdiParent = this;
            AddCredit.Show();
        }
        private void toolStripButton1_Click(object sender, EventArgs e)
        {
            frmManageStu ManageStu = new frmManageStu();
            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            DataAccess data = new DataAccess();
            data.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds;
            ds = data.getDataSet(cmdStr);
            if (ds.Tables[0].Rows[0]["Userlevel"].ToString() == "学生")
            {
                ManageStu.btnDel.Enabled = false;
                ManageStu.btnEdit.Enabled = false;
            }
            ManageStu.MdiParent = this;
            ManageStu.Show();
        }
        private void toolStripButton2_Click(object sender, EventArgs e)
        {
            frmManageCourse ManageCourse = new frmManageCourse();
            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            DataAccess data = new DataAccess();
            data.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds;
            ds = data.getDataSet(cmdStr);
            if (ds.Tables[0].Rows[0]["Userlevel"].ToString() == "学生")
            {
                ManageCourse.btnDel.Enabled = false;
                ManageCourse.btnEdit.Enabled = false;
            }
            ManageCourse.MdiParent = this;
            ManageCourse.Show();
        }
        private void toolStripButton3_Click(object sender, EventArgs e)
        {
            frmManageScore ManageScore = new frmManageScore();
            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            DataAccess data = new DataAccess();
            data.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds;
            ds = data.getDataSet(cmdStr);
            if (ds.Tables[0].Rows[0]["Userlevel"].ToString() == "学生")
            {
                ManageScore.btnDel.Enabled = false;
                ManageScore.btnEdit.Enabled = false;
            }
            ManageScore.MdiParent = this;
            ManageScore.Show();
        }
        private void 关于AToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("终于完工了。。。开森 ^ _ ^");
        }

        private void 修改密码PToolStripMenuItem_Click(object sender, EventArgs e)
        {
            frmPswChange PC = new frmPswChange();
            PC.MdiParent = this;
            PC.Show();
        }

6.学生信息添加窗体。能够将学生信息添加到数据库中。


按钮点击事件:

[Visual Basic .NET] 纯文本查看 复制代码
private void btnAdd_Click(object sender, EventArgs e)
        {
            string strSql;
            DataAccess data = new DataAccess();
            strSql = "insert into Studentinfo (Sid,Sname,Sex,Birthday,Class,Tel,Address) values ('" + txtSid.Text + "','" + txtSname.Text + "','" + cboSex.Text + "','" + txtBirthday.Text + "','" + txtClass.Text + "','" + txtTel.Text + "','" + txtAddress.Text + "')";
            data.dataCon();
            if (data.sqlExec(strSql))
            {
                MessageBox.Show("添加成功!!");
            }
            else
            {
                MessageBox.Show("添加失败!!");
            }
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }


7.学生信息管理窗体。能够“查询”、“删除”及“修改”学生信息。


按钮点击事件:

[Visual Basic .NET] 纯文本查看 复制代码
      public frmManageStu()
        {
            InitializeComponent();
            check();
        }
        public static string sid;
        public static string Sid
        {
            get { return sid; }
            set { sid = value; }
        }
        public void check()
        {
            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            DataAccess data1 = new DataAccess();
            data1.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds1;
            ds1 = data1.getDataSet(cmdStr);
            if (ds1.Tables[0].Rows[0]["Userlevel"].ToString() == "学生")
            {
                string strSql;
                DataAccess data = new DataAccess();
                DataSet ds;
                strSql = "select Sid as 学号,Sname as 姓名,Sex as 性别,Birthday as 出生日期,Class as 班级,Tel as 电话,Address as 家庭地址 from Studentinfo where Sid='" + username + "'";
                data.dataCon();
                ds = data.getDataSet(strSql);
                txtSid.Text = ds.Tables[0].Rows[0][0].ToString();
                txtSid.Enabled = false;
                txtSname.Text = ds.Tables[0].Rows[0][1].ToString();
                txtSname.Enabled = false;
                cboSex.Text = ds.Tables[0].Rows[0][2].ToString();
                cboSex.Enabled = false;
                txtClass.Text = ds.Tables[0].Rows[0][4].ToString();
                txtClass.Enabled = false;
            }
        }
        private void btnSeach_Click(object sender, EventArgs e)
        {
            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            DataAccess data1 = new DataAccess();
            data1.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds1;
            ds1 = data1.getDataSet(cmdStr);
            if (ds1.Tables[0].Rows[0]["Userlevel"].ToString() == "学生")
            {
                string strSql;
                DataAccess data = new DataAccess();
                DataSet ds;
                strSql = "select Sid as 学号,Sname as 姓名,Sex as 性别,Birthday as 出生日期,Class as 班级,Tel as 电话,Address as 家庭地址 from Studentinfo where Sid='"+username+"'";
                data.dataCon();
                ds = data.getDataSet(strSql);
                dgvInfo.DataSource = ds.Tables[0];
            }
            else
            {
                string strSql;
                string condition = "";
                DataAccess data = new DataAccess();
                DataSet ds;
                if (txtSid.Text != "")
                {
                    condition += "and Sid='" + txtSid.Text + "'";
                }
                if (txtSname.Text != "")
                {
                    condition += "and Sname='" + txtSname.Text + "'";
                }
                if (txtClass.Text != "")
                {
                    condition += "and Class='" + txtClass.Text + "'";
                }
                if (cboSex.Text != "")
                {
                    condition += "and Sex='" + cboSex.Text + "'";
                }
                strSql = "select Sid as 学号,Sname as 姓名,Sex as 性别,Birthday as 出生日期,Class as 班级,Tel as 电话,Address as 家庭地址 from Studentinfo where 1=1" + condition;
                data.dataCon();
                ds = data.getDataSet(strSql);
                dgvInfo.DataSource = ds.Tables[0];
            }
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (dgvInfo.CurrentRow == null)
            {
                MessageBox.Show("请先查询!!"); 
            }
            else 
            {
                string strSql;
                DataAccess data = new DataAccess();
                strSql = "delete from Studentinfo where Sid='" + dgvInfo.CurrentRow.Cells[0].Value.ToString() + "'";
                data.dataCon();
                if (data.sqlExec(strSql))
                {
                    string Strsql;
                    DataAccess data1 = new DataAccess();
                    DataSet ds;
                    Strsql = "select Sid as 学号,Sname as 姓名,Sex as 性别,Birthday as 出生日期,Class as 班级,Tel as 电话,Address as 家庭地址 from Studentinfo where 1=1";
                    data1.dataCon();
                    ds = data1.getDataSet(Strsql);
                    dgvInfo.DataSource = ds.Tables[0];
                    MessageBox.Show("删除成功!!");
                }
                else
                {
                    MessageBox.Show("删除失败!!");
                }
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {

            if (dgvInfo.CurrentRow == null)
            {

                MessageBox.Show("请先查询!!");  
                
            }
            else 
            {
                frmManageStu.sid = dgvInfo.CurrentRow.Cells[0].Value.ToString();
                frmEditStu s1 = new frmEditStu();
                s1.txtSid.Enabled = false;
                s1.Show();
            }
        }


8.学生信息修改窗体。当在学生信息管理窗体上点击“修改”按钮时,能弹出修改学生信息窗体,该窗体够修改学生信息。


按钮点击事件:

[Visual Basic .NET] 纯文本查看 复制代码
private void btnEdit_Click(object sender, EventArgs e)
        {
            string strSql = "";
            if (txtSname.Text != "" && txtBirthday.Text != "" && txtClass.Text != "" && txtTel.Text != "" && txtAddress.Text != "")
            {
                strSql = "update Studentinfo set Sname='" + txtSname.Text + "',Sex='" + cboSex.Text + "',Birthday='" + txtBirthday.Text + "',Class='" + txtClass.Text + "',Tel='" + txtTel.Text + "',Address='" + txtAddress.Text + "' where Sid='" + frmManageStu.sid + "'";
                DataAccess data = new DataAccess();
                data.dataCon();
                if (data.sqlExec(strSql))
                {
                    MessageBox.Show("修改成功!!");
                }
                else
                {
                    MessageBox.Show("修改失败!!");
                }
            }
            else
            {
                MessageBox.Show("输入未完全!!");
            }
        }

        private void frmEditStu_Load(object sender, EventArgs e)
        {
            txtSid.Text = frmManageStu.sid;
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }


9.课程信息添加窗体。能够将课程信息添加到数据库中。


按钮点击事件:

[Visual Basic .NET] 纯文本查看 复制代码
private void btnAdd_Click(object sender, EventArgs e)
        {
            string strSql;
            DataAccess data = new DataAccess();
            strSql = "insert into Courseinfo (Cid,Cname,Credit) values ('" + txtCid.Text + "','" + txtCname.Text + "','" + txtCredit.Text + "')";
            data.dataCon();
            if (data.sqlExec(strSql))
            {
                MessageBox.Show("添加成功!!");
            }
            else
            {
                MessageBox.Show("添加失败!!");
            }
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }


10.课程信息管理窗体。能够“查询”、“删除”及“修改”课程信息。


按钮点击事件:

[Visual Basic .NET] 纯文本查看 复制代码
 public static string cid;
        public static string Cid
        {
            get { return cid; }
            set { cid = value; }
        }
        private void btnSeach_Click(object sender, EventArgs e)
        {
            string strSql;
            string condition = "";
            DataAccess data = new DataAccess();
            DataSet ds;
            if (txtCid.Text != "")
            {
                condition += "and Cid='" + txtCid.Text + "'";
            }
            if (txtCname.Text != "")
            {
                condition += "and Cname='" + txtCname.Text + "'";
            }
            strSql = "select Cid as 课程编号,Cname as 课程名称,Credit as 学分 from Courseinfo where 1=1" + condition;
            data.dataCon();
            ds = data.getDataSet(strSql);
            dgvInfo.DataSource = ds.Tables[0];
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (dgvInfo.CurrentRow == null)
            {

                MessageBox.Show("请先查询!!");
            }
            else
            {
                string strSql;
                DataAccess data = new DataAccess();
                strSql = "delete from Courseinfo where Cid='" + dgvInfo.CurrentRow.Cells[0].Value.ToString()+"'";
                data.dataCon();
                if (data.sqlExec(strSql))
                {                
                    string Strsql;
                    DataAccess data1 = new DataAccess();
                    DataSet ds;
                    Strsql = "select Cid as 课程编号,Cname as 课程名称,Credit as 学分 from Courseinfo where 1=1";
                    data1.dataCon();
                    ds = data1.getDataSet(Strsql);
                    dgvInfo.DataSource = ds.Tables[0];
                    MessageBox.Show("删除成功!!");
                }
                else
                {
                    MessageBox.Show("删除失败!!");
                }
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dgvInfo.CurrentRow == null)
            {

                MessageBox.Show("请先查询!!");

            }
            else
            {
                frmManageCourse.cid = dgvInfo.CurrentRow.Cells[0].Value.ToString();
                frmEditCourse s1 = new frmEditCourse();
                s1.txtCid.Enabled = false;
                s1.Show();
            }

        }


11.课程信息修改窗体。当在课程信息管理窗体上点击“修改”按钮时,能够弹出修改课程信息窗体,该窗体能够修改课程信息。


按钮点击事件:

[Visual Basic .NET] 纯文本查看 复制代码
private void btnEdit_Click(object sender, EventArgs e)
        {
            string strSql = "";
            if (txtCid.Text != "" && txtCname.Text != "" && txtCredit.Text != "")
            {
                strSql = "update Courseinfo set Cname='" + txtCname.Text + "',Credit='" + txtCredit.Text + "' where Cid='" + frmManageCourse.cid + "'";
                DataAccess data = new DataAccess();
                data.dataCon();
                if (data.sqlExec(strSql))
                {
                    MessageBox.Show("修改成功!!");
                }
                else
                {
                    MessageBox.Show("修改失败!!");
                }
            }
            else
            {
                MessageBox.Show("输入未完全!!");
            }
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void frmEditCourse_Load(object sender, EventArgs e)
        {
            txtCid.Text = frmManageCourse.cid;
        }


12.成绩添加窗体。能够添加学生相应课程的成绩到数据库中。


按钮点击事件:

[Visual Basic .NET] 纯文本查看 复制代码
private void btnAdd_Click(object sender, EventArgs e)
        {
            string strSql;
            DataAccess data = new DataAccess();
            strSql = "insert into Scoreinfo (Sid,Cid,Score) values ('" + txtSid.Text + "','" + txtCid.Text + "','" + txtScore.Text + "')";
            data.dataCon();
            if (data.sqlExec(strSql))
            {
                MessageBox.Show("添加成功!!");
            }
            else
            {
                MessageBox.Show("添加失败!!");
            }
        }

        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }


13.成绩管理窗体。能够“查询”、“删除”及“修改”学生的成绩。


按钮点击事件:

[Visual Basic .NET] 纯文本查看 复制代码
 public frmManageScore()
        {
            InitializeComponent();
            check();
        }
        public void check()
        {
            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            DataAccess data1 = new DataAccess();
            data1.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds1;
            ds1 = data1.getDataSet(cmdStr);
            if (ds1.Tables[0].Rows[0]["Userlevel"].ToString() == "学生")
            {
                string strSql;
                DataAccess data = new DataAccess();
                DataSet ds;
                strSql = "select Sid as 学号,Sname as 姓名,Sex as 性别,Birthday as 出生日期,Class as 班级,Tel as 电话,Address as 家庭地址 from Studentinfo where Sid='" + username + "'";
                data.dataCon();
                ds = data.getDataSet(strSql);
                txtSid.Text = ds.Tables[0].Rows[0][0].ToString();
                txtSid.Enabled = false;
                txtSname.Text = ds.Tables[0].Rows[0][1].ToString();
                txtSname.Enabled = false;
                txtClass.Text = ds.Tables[0].Rows[0][4].ToString();
                txtClass.Enabled = false;
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {

            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            DataAccess data1 = new DataAccess();
            data1.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds1;
            ds1 = data1.getDataSet(cmdStr);
            if (ds1.Tables[0].Rows[0]["Userlevel"].ToString() == "学生")
            {
                string strSql;
                string condition = "";
                DataAccess data = new DataAccess();
                DataSet ds;
                if (txtCid.Text != "")
                {

                    if (txtCid.Text == "all")
                    {
                        strSql = " SELECT Courseinfo.Cid as 课程号, Courseinfo.Cname as 课程名称, Studentinfo.Sname as 姓名, Studentinfo.Class as 班级, Studentinfo.Sid as 学号, Scoreinfo.Score  as 成绩 FROM Studentinfo ,Courseinfo , Scoreinfo where Courseinfo.Cid = Scoreinfo.Cid and Studentinfo.Sid = Scoreinfo.Sid and Studentinfo.Sid='" + txtSid.Text + "' ";
                        data.dataCon();
                        ds = data.getDataSet(strSql);
                        dgvInfo.DataSource = ds.Tables[0];
                    }
                    else
                    {
                        MessageBox.Show("输入all查询所有成绩");
                        condition += "and Courseinfo.Cid='" + txtCid.Text + "'";
                        strSql = " SELECT Courseinfo.Cid as 课程号, Courseinfo.Cname as 课程名称, Studentinfo.Sname as 姓名, Studentinfo.Class as 班级, Studentinfo.Sid as 学号, Scoreinfo.Score  as 成绩 FROM Studentinfo ,Courseinfo , Scoreinfo where Courseinfo.Cid = Scoreinfo.Cid and Studentinfo.Sid = Scoreinfo.Sid and Studentinfo.Sid='" + txtSid.Text + "' " + condition;
                        data.dataCon();
                        ds = data.getDataSet(strSql);
                        dgvInfo.DataSource = ds.Tables[0];
                    }                               
                }
                else
                {
                    MessageBox.Show("请输入要查的课程编号!!");
                }
            }
            else
            {
                string strSql;
                string condition = "";
                DataAccess data = new DataAccess();
                DataSet ds;
                if (txtSid.Text != "")
                {
                    condition += "and Studentinfo.Sid='" + txtSid.Text + "'";
                }
                if (txtSname.Text != "")
                {
                    condition += "and Sname='" + txtSname.Text + "'";
                }
                if (txtClass.Text != "")
                {
                    condition += "and Class='" + txtClass.Text + "'";
                }
                if (txtCid.Text != "")
                {
                    condition += "and Courseinfo.Cid='" + txtCid.Text + "'";
                }
                strSql = " SELECT Courseinfo.Cid as 课程号, Courseinfo.Cname as 课程名称, Studentinfo.Sname as 姓名, Studentinfo.Class as 班级, Studentinfo.Sid as 学号, Scoreinfo.Score  as 成绩 FROM Studentinfo ,Courseinfo , Scoreinfo where Courseinfo.Cid = Scoreinfo.Cid and Studentinfo.Sid = Scoreinfo.Sid  " + condition;
                data.dataCon();
                ds = data.getDataSet(strSql);
                dgvInfo.DataSource = ds.Tables[0];
            }
        }

        private void btnEdit_Click(object sender, EventArgs e)
        {
            if (dgvInfo.CurrentRow == null)
            {

                MessageBox.Show("请先查询!!");

            }
            else
            {
                string strSql;
                DataAccess data = new DataAccess();
                strSql = " update Scoreinfo set Score='" + dgvInfo.CurrentRow.Cells[5].Value.ToString() + "' where Sid='" + dgvInfo.CurrentRow.Cells[4].Value.ToString() + "'and Cid='" + dgvInfo.CurrentRow.Cells[0].Value.ToString() + "'";
                data.dataCon();
                if (data.sqlExec(strSql))
                {
                    MessageBox.Show("修改成功!!");
                }
                else
                {
                    MessageBox.Show("修改失败!!");
                }
            }
        }

        private void btnDel_Click(object sender, EventArgs e)
        {
            if (dgvInfo.CurrentRow == null)
            {

                MessageBox.Show("请先查询!!");

            }
            else
            {
                string strSql;
                DataAccess data = new DataAccess();
                strSql = "delete from Scoreinfo where Cid='" + dgvInfo.CurrentRow.Cells[0].Value.ToString() + "' and Sid='" + dgvInfo.CurrentRow.Cells[4].Value.ToString() + "'";
                data.dataCon();
                if (data.sqlExec(strSql))
                {
                    string Strsql;
                    DataAccess data1 = new DataAccess();
                    DataSet ds;
                    Strsql = " SELECT Courseinfo.Cid as 课程号, Courseinfo.Cname as 课程名称, Studentinfo.Sname as 姓名, Studentinfo.Class as 班级, Studentinfo.Sid as 学号, Scoreinfo.Score  as 成绩 FROM Studentinfo ,Courseinfo , Scoreinfo where Courseinfo.Cid = Scoreinfo.Cid and Studentinfo.Sid = Scoreinfo.Sid  ";
                    data1.dataCon();
                    ds = data1.getDataSet(Strsql);
                    dgvInfo.DataSource = ds.Tables[0];
                    MessageBox.Show("删除成功!!");

                }
                else
                {
                    MessageBox.Show("删除失败!!");
                }
            }
        }


14.注册窗口
按钮点击事件:
[Visual Basic .NET] 纯文本查看 复制代码
public FormRegist()
        {
            InitializeComponent();
            data();
        }
        public void data()
        {
            string strSql;
            DataAccess data = new DataAccess();
            data.dataCon();
            strSql = "select Sid from Studentinfo";
            DataSet ds;
            ds = data.getDataSet(strSql);
            if (ds.Tables[0].Rows.Count>0)
              {
                  for (int i = 0; i <ds.Tables[0].Rows.Count; i++)
                  {
                      txtUsername.Items.Add(ds.Tables[0].Rows[i][0].ToString());
                  }
              }       
        }
        private void btnRegist_Click(object sender, EventArgs e)
        {
            string Username = txtUsername.Text.Trim();
            string UserPsw = txtPsw.Text.Trim();
            string UserRPsw = txtRPsw.Text.Trim();
            string UserLevel = cboLevel.Text.Trim();
            string StrSql;
            DataAccess data0 = new DataAccess();
            data0.dataCon();
            StrSql = "select Userid from Userinfo where Userid='" + Username + "'";
            DataSet ds0;
            ds0 = data0.getDataSet(StrSql);
            if (ds0.Tables[0].Rows.Count == 1)
            {
                MessageBox.Show("该账号已注册,请重新输入!!");
                txtUsername.Text = "";
                txtUsername.Focus();
            }
            else
            {
                if (Username == "")
                {
                    MessageBox.Show("用户名不能为空!!");
                }
                else
                {
                    if (UserPsw == "")
                    {
                        MessageBox.Show("密码不能为空!!");
                    }
                    else
                    {
                        if (UserPsw != UserRPsw)
                        {
                            MessageBox.Show("输入密码不一致!!");
                        }
                        else
                        {
                            if (cboLevel.Text == "学生")
                            {
                                string strSql;
                                DataAccess data = new DataAccess();
                                strSql = "insert into Userinfo (Userid,Userpwd,Userlevel) values ('" + Username + "','" + UserPsw + "','" + UserLevel + "')";
                                data.dataCon();
                                DialogResult Result = MessageBox.Show("信息无误确定注册", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                                if (Result == DialogResult.Yes)
                                {
                                    string Strsql;
                                    DataAccess data1 = new DataAccess();
                                    data1.dataCon();
                                    Strsql = "select Sid from Studentinfo where Sid='" + Username + "'";
                                    DataSet ds;
                                    ds = data.getDataSet(Strsql);
                                    if (ds.Tables[0].Rows.Count == 1)
                                    {
                                        if (data.sqlExec(strSql))
                                        {
                                            MessageBox.Show("成功注册!");
                                            this.Close();
                                        }
                                        else
                                        {
                                            MessageBox.Show("注册失败!");
                                        }
                                    }
                                    else
                                    {
                                        MessageBox.Show("未查找到此学号,请重新输入!!");
                                        txtUsername.Text = "";
                                        txtUsername.Focus();
                                    }
                                }
                            }
                        }
                        if (cboLevel.Text == "教师")
                        {
                            string strSql;
                            DataAccess data = new DataAccess();
                            strSql = "insert into Userinfo (Userid,Userpwd,Userlevel) values ('" + Username + "','" + UserPsw + "','" + UserLevel + "')";
                            data.dataCon();
                            DialogResult Result = MessageBox.Show("信息无误确定注册", "提示", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                            if (Result == DialogResult.Yes)
                            {
                                if (data.sqlExec(strSql))
                                {
                                    MessageBox.Show("成功注册!");
                                    this.Close();
                                }
                                else
                                {
                                    MessageBox.Show("注册失败!");
                                }
                            }
                        }
                    }
                }
            }
        }
        private void btnCancle_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FormRegist_Load(object sender, EventArgs e)
        {
            cboLevel.SelectedIndex =0;
        }
15.改密窗口


按钮点击事件:

[Visual Basic .NET] 纯文本查看 复制代码
 private void PswChange_Load(object sender, EventArgs e)
        {
            txtUsername.Text = FormLogin.Uname;
        }

        private void btnchange_Click(object sender, EventArgs e)
        {
            string username = FormLogin.Uname;
            string password = FormLogin.Upsw;
            string strSql = "";
            DataAccess data = new DataAccess();
            data.dataCon();
            string cmdStr = "Select * from Userinfo where Userid='" + username + "' and Userpwd='" + password + "'";
            DataSet ds;
            ds = data.getDataSet(cmdStr);
            if (txtPassword.Text==password)
            {
                strSql = "update Userinfo set Userpwd='" + txtNewPsd.Text.Trim()+ "' where Userid='" + username + "'";
                DataAccess data1 = new DataAccess();
                data1.dataCon();
                if (data1.sqlExec(strSql))
                {
                    MessageBox.Show("修改密码成功!!");
                    this.Close();
                }
                else
                {
                    MessageBox.Show("修改密码失败!!");
                }
            }
            else
            {
                MessageBox.Show("原密码不正确!!");
            }

        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }
相关资源下载请移步数据库设计。。。


免费评分

参与人数 21吾爱币 +23 热心值 +16 收起 理由
汪苏打 + 1 + 1 谢谢@Thanks!
panzhengdong + 1 + 1 热心回复!
jsh007 + 1 + 1 谢谢@Thanks!
kingsleylr99 + 1 这可以当毕设交了吧。。。。
时光里的一缕风 + 1 谢谢@Thanks!
liqingkai + 1 + 1 用心讨论,共获提升!
x45351346 + 1 我很赞同!
lixu1999 + 1 + 1 热心回复!
wisdomnet + 1 + 1 我很赞同!
TinySoul + 1 + 1 谢谢@Thanks!
tgdq5 + 1 + 1 谢谢@Thanks!
yanglinman + 1 热心回复!
Wgq890224 + 1 谢谢@Thanks!
wangxp + 1 + 1 谢谢@Thanks!
苏紫方璇 + 5 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
根号三先生 + 1 + 1 热心回复!
nutcheer + 1 我很赞同!
bg_yx + 1 我很赞同!
love559 + 1 + 1 我很赞同!
喝易拉罐呀 + 1 + 1 天哪噜可以的!
qaz003 + 1 + 1 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

 楼主| 夏沫梦影 发表于 2020-6-19 10:25
本帖最后由 夏沫梦影 于 2020-6-19 10:34 编辑
Yanderedev 发表于 2020-6-18 22:56
怎么登录?小白,总是提示帐号或者密码错误?不是按照ACCESS表里的??怎么连上自己的数据库。

数据库扔在启动目录下,bin/Debug密码见下表,登陆的时候记得选对权限
[C#] 纯文本查看 复制代码
        //连接数据库
        public void dataCon()
        {
            conStr = "Provider=Microsoft.Jet.OleDB.4.0;Data Source=" + Application.StartupPath + "\\student.mdb";   
            con = new OleDbConnection(conStr);
        }

想要换自己的数据库,就把DataAccess里的 上段代码中的student.mdb改成自己的,不建议换,修改一下数据库里的东西就可以了
QQ图片20200619103327.png
LisonLin 发表于 2019-6-12 03:16
不知道楼主是不是和我一样是大学生    我现在学的.net web里面就有个教育管理系统     里面包含了楼主那个学生成绩系统    还有缴费系统    还有宿舍管理系统      
如果是一样的      希望楼主能抽空做个宿舍管理系统    &#128514;      要交作业。。。
qaz003 发表于 2019-6-2 05:02
不续年华 发表于 2019-6-2 05:17
这个很好&#128077;
TinySoul 发表于 2019-6-2 07:35
可以,谢谢楼主
yu13740000 发表于 2019-6-2 07:42
谢谢分享,学习一下
yangyuan7730 发表于 2019-6-2 07:45
不错,谢谢楼主。
xglys 发表于 2019-6-2 07:46
青鸟的课程对吗 ?
0fifa 发表于 2019-6-2 07:55
不错,虽然简陋了点儿。
森林阳光 发表于 2019-6-2 08:03
一般情况下,我记得要加上权限管理及报错弹窗比较好
c3097 发表于 2019-6-2 08:06
不错,学习了。
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则 警告:本版块禁止灌水或回复与主题无关内容,违者重罚!

快速回复 收藏帖子 返回列表 搜索

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-4-24 10:38

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表