后台学生管理系统

使用C#和SQL语句来制作一个简单的后台登录系统

开发工具主要是运用到了VS2017和Sql大数据
在这里插入图片描述登录界面,通过输入账号和密码进行登录 代码如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp3
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {

    }
    /// <summary>
    /// 登录按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button1_Click(object sender, EventArgs e)
    {
        string name = textBox1.Text;
        string pwd = textBox2.Text;
        if (name==""||pwd=="")
        {
            MessageBox.Show("用户名或密码为空,请重新输入!!!");
        }
        else
        {
            string sql = string.Format("select *from Users where Uname='{0}' and Upwd='{1}'",name,pwd);
            DataTable dt = DBHelper.GetDataTable(sql);
            if (dt.Rows.Count>0)
            {
                MessageBox.Show("登陆成功!!");
                Form2 f2 = new Form2();
                f2.Show();
                this.Hide();
            }
            else
            {
                MessageBox.Show("登录失败!!");
            }
        }
    }
    /// <summary>
    /// 取消按钮
    /// </summary>
    /// <param name="sender"></param>
    /// <param name="e"></param>
    private void button2_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }
}

}

在这里插入图片描述
登录成功之后可以自动显示数据库中的数据,我们也可以对数据进行查询和修改等操作 代码如下:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp3
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 窗体加载显示表格中的数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Form2_Load(object sender, EventArgs e)
        {
            //将数据显示到表格中
            string sql = string.Format("select*from Students");
            DataTable dt = DBHelper.GetDataTable(sql);
            dataGridView1.DataSource = dt;
        }
        /// <summary>
        /// 搜索按钮 判断搜索内容
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {

            if (comboBox1.Text == "姓名")
            {
                string sql = string.Format("select * from Students where name like '%{0}%'", textBox1.Text);
                DataTable dt = DBHelper.GetDataTable(sql);
                dataGridView1.DataSource = dt;
            }
            else if (comboBox1.Text == "班级")
            {
                string sql = string.Format("select*from Students where class like '%{0}%'", textBox1.Text);
                DataTable dt = DBHelper.GetDataTable(sql);
                dataGridView1.DataSource = dt;
            }
            else if (comboBox1.Text == "学号")
            {
                string sql = string.Format("select*from Students where xuehao like'%{0}%'", textBox1.Text);
                DataTable dt = DBHelper.GetDataTable(sql);
                dataGridView1.DataSource = dt;
            }
            else if (comboBox1.Text == "地址")
            {
                string sql = string.Format("select*from Students where address like'%{0}%'", textBox1.Text);
                DataTable dt = DBHelper.GetDataTable(sql);
                dataGridView1.DataSource = dt;
            }
            else
            {
                MessageBox.Show("下拉框中的值不可以修改和为空!!!!");
            }
        }
        /// <summary>
        /// 添加按钮 跳转到添加窗体
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 添加学生信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form3 f3 = new Form3();
            f3.Show();
            
        }
        /// <summary>
        /// 刷新修改后的数据 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 刷新学生信息ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Form2_Load(sender, e);
        }
        /// <summary>
        /// 将表格中的值显示到textBox当中进行修改
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {

            string sql = string.Format("select * from students where id ={0}",
                dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
           DataTable dt =  DBHelper.GetDataTable(sql);
            //赋值textBox2.Text = dt.Rows[0]["xuehao"].ToString();
            if (dt !=null && dt.Rows.Count>0)
            {
                textBox2.Text = dt.Rows[0]["xuehao"].ToString();
                textBox3.Text = dt.Rows[0]["name"].ToString();
                textBox4.Text = dt.Rows[0]["sex"].ToString();
                textBox5.Text = dt.Rows[0]["class"].ToString();
                textBox6.Text = dt.Rows[0]["address"].ToString();
            }

        }
        /// <summary>
        /// 修改按钮的代码
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button2_Click(object sender, EventArgs e)
        {
            
            if (textBox2.Text=="")
            {
                MessageBox.Show("请输入您需要修改的值!!!");
            }
            else if(MessageBox.Show("是否进行修改???","修改",MessageBoxButtons.YesNo)==DialogResult.Yes)
            {
                string sql = string.Format("update Students set xuehao='{0}',name='{1}',sex='{2}',class='{3}',address='{4}' where id='{5}'",
                Convert.ToString(textBox2.Text), Convert.ToString(textBox3.Text), Convert.ToString(textBox4.Text),
                Convert.ToString(textBox5.Text), Convert.ToString(textBox6.Text), dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                if (DBHelper.Zsg(sql))
                {
                    MessageBox.Show("修改成功!!!请进行刷新!!");
                }
                else
                {
                    MessageBox.Show("修改失败!!!请重新输入!!");
                }
            }
        }
        /// <summary>
        /// 删除代码样式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            if (MessageBox.Show("是否删除??","删除:",MessageBoxButtons.YesNo)==DialogResult.Yes)
            {
                string sql = string.Format("delete from Students where id='{0}'", dataGridView1.SelectedRows[0].Cells[0].Value.ToString());
                if (DBHelper.Zsg(sql))
                {
                    MessageBox.Show("删除成功!!!");
                }
                else
                {
                    MessageBox.Show("删除失败!!");
                }
            }
        }
        /// <summary>
        /// 通过下拉框显示“在读”“退学”“全部”状态的学生
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void comboBox2_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox2.Text=="全部")
            {
                Form2_Load(sender, e);
            }
            else
            {
                string sql = string.Format("select*from Students where zhuatai='{0}'", comboBox2.Text);
                DataTable dt = DBHelper.GetDataTable(sql);
                dataGridView1.DataSource = dt;
            }
            
        }
        /// <summary>
        /// 取消按钮 清空textBox中的数据
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button3_Click(object sender, EventArgs e)
        {
            textBox2.Text = null;
            textBox3.Text = null;
            textBox4.Text = null;
            textBox5.Text = null;
            textBox6.Text = null;
        }
    }
}

在这里插入图片描述
添加界面 代码如下

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApp3
{
    public partial class Form3 : Form
    {
        public Form3()
        {
            InitializeComponent();
        }
        /// <summary>
        /// 添加代码样式
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void button1_Click(object sender, EventArgs e)
        {
            string sql = string.Format("insert into Students select '{0}','{1}','{2}','{3}','{4}','{5}'"
                ,textBox1.Text,textBox2.Text,textBox3.Text,textBox4.Text,textBox5.Text,textBox6.Text);
            if (DBHelper.Zsg(sql))
            {
                MessageBox.Show("添加成功!!!");
                this.Hide();
            }
            else
            {
                MessageBox.Show("添加失败!!!数据输入有误!!");
            }
        }

        private void Form3_Load(object sender, EventArgs e)
        {

        }
    }
}

DBHlper类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using System.Data.SqlClient;
namespace WindowsFormsApp3
{
    class DBHelper
    {
        //数据库链接字符串
        public static string sqlconn = "Data Source=.;Initial Catalog=Student;Integrated Security=True";
        public static SqlConnection conn = new SqlConnection(sqlconn);
        //封装方法 断开连接
        public static DataTable GetDataTable(string sql)
        {
            SqlDataAdapter da = new SqlDataAdapter(sql,conn);
            DataSet ds = new DataSet();
            da.Fill(ds);
            return ds.Tables[0];
        }
        //增删改
        public static bool Zsg(string sql)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql,conn);
            int result = cmd.ExecuteNonQuery();
            conn.Close();
            return result > 0;
        }
        //聚合函数
        public static object Juhe(string sql)
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql,conn);
            object result = cmd.ExecuteScalar();
            conn.Close();
            return result;
        }
    }
}

当然除了以上的代码外还有许多控件的属性需要调整比如:
通过键盘的Enter键来点击登录按钮:在Form1窗体属性中的AcceptButton属性
Esc键来点击取消按钮:在Form1窗体属性中的CancelButton属性
右键菜单:ContextMenuStrip属性等

说明:纯属分享自己最近学习时写的作业,不喜勿喷!谢谢!如果您有什么更好的建议可以在下方评论出来,大家可以一起学习!

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Javawed学生后台管理系统是一款为学校、学院或教育机构设计的学生管理软件。该系统可以帮助学校管理学生的基本信息、课程安排、成绩记录、考勤情况以及其他与学生相关的管理工作。这个系统拥有友好的用户界面和强大的功能,可以帮助学校实现信息化管理,提高管理效率和服务质量。 Javawed学生后台管理系统主要包括学生信息管理、课程管理、成绩管理、考勤管理和教师管理等模块。学校可以在系统中录入学生的基本信息,包括姓名、学号、班级、家庭住址等。同时,可以根据学生的选课情况进行课程安排,记录学生的平时成绩和考试成绩,并进行统计分析。学校还可以通过系统对学生的考勤情况进行管理,包括请假、迟到、早退等情况的记录和处理。另外,系统还能够进行教师信息管理,包括基本信息、任教课程、教学评价等方面的管理。 Javawed学生后台管理系统还具有数据安全和灵活性的两大优点。系统采用了先进的数据加密和权限控制技术,能够确保学生个人信息的安全性。另外,该系统支持定制化的开发,可以根据学校的实际需求进行个性化定制,符合学校的管理特点。 总的来说,Javawed学生后台管理系统是一款功能强大、操作简便的学生管理软件,能够帮助学校实现信息化管理,提高管理效率,提升教学质量,是学校管理工作的得力助手。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值