C# Winform月考学生成绩管理系统

项目地址:https://gitee.com/qiuyuhan/YueKaoXueShengChengJiGuanLiXiTong

mainform.cs

C# Winform月考学生成绩管理系统_第1张图片

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;
using System.Collections;
namespace 月考学生成绩管理系统
{
    public partial class mainForm : Form
    {
        private List _stuList;
        public mainForm()
        {
            InitializeComponent();
            //初始化一些列属性
            this.init();
            //绑定
            this.BindGridview();

        }
        /// 
        /// 初始化
        /// 
        private void  init()
        {
            this.StuList = new List();
          this.StuList.Add(new Student(1231, "小小", 20, "男", 150));
            this.StuList.Add(new Student(12, "红红", 123, "男", 150));
            this.StuList.Add(new Student(11, "John", 6, "女", 150));
            this.StuList.Add(new Student(31, "Smart", 23, "女", 150));
            this.StuList.Add(new Student(1, "邱于涵", 20, "男", 9999999));
        }
        /// 
        /// 绑定gridview
        /// 
        public void BindGridview()
        {
            this.dataGridView1.DataSource = null;
            //设置数据源
            this.dataGridView1.DataSource = new BindingList(this.StuList);
          
        }
        public List StuList { get => _stuList; set => _stuList = value; }

        private void 退出ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void 天机ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            AddForm af = new AddForm(this);
            af.ShowDialog();
        }

        private void 删除ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //选中行的索引
            int selindex = this.dataGridView1.SelectedRows[0].Index;
            if (MessageBox.Show("确定删除?", "确定删除", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                //删除
                this.StuList.RemoveAt(selindex);
                //重新绑定
                this.BindGridview();
            }
           
       
        }

        private void 修改ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //选中行的索引
            int selindex = this.dataGridView1.SelectedRows[0].Index;
            updateForm uf = new updateForm(this, selindex);
            uf.ShowDialog();
        }

        private void btnsearch_Click(object sender, EventArgs e)
        {
            if (this.txtSearch.Text == "")
            {
                this.BindGridview();
            }
            else {
                List tmpList = new List();
                for (int i = 0; i < this.StuList.Count; i++)
                {
                    if (this.StuList[i].Name.IndexOf(this.txtSearch.Text) != -1 ||
                        this.StuList[i].Age.ToString().IndexOf(this.txtSearch.Text) != -1 ||
                         this.StuList[i].Id.ToString().IndexOf(this.txtSearch.Text) != -1 ||
                          this.StuList[i].Sex.ToString().IndexOf(this.txtSearch.Text) != -1
                        )
                    {
                        tmpList.Add(this.StuList[i]);
                    }
                }
                this.dataGridView1.DataSource = new BindingList(tmpList);

            }
           

        }

        private void 关于ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            MessageBox.Show("版权所有");
        }
    }
}

student.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 月考学生成绩管理系统
{
   public  class Student
    {
        //学号
        private int _id;
        //名字
        private string _name;
        //年龄
        private int _age;
        //性别
        private string  _sex;
        //考试成绩
        private int _score;

        /// 
        /// 构造方法
        /// 
        /// 
        /// 
        /// 
        /// 
        /// 
        public Student(int id, string name, int age, string sex, int score)
        {
            this.Id = id;
            this.Name = name;
            this.Age = age;
            this.Sex = sex;
            this.Score = score;
        }
        public Student()
        { }
        public int Id { get => _id; set => _id = value; }
        public string Name { get => _name; set => _name = value; }
        public int Age { get => _age; set => _age = value; }
        
        public int Score { get => _score; set => _score = value; }
        public string Sex { get => _sex; set => _sex = value; }
    }
}
AddForm.cs

C# Winform月考学生成绩管理系统_第2张图片

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 月考学生成绩管理系统
{
    public partial class AddForm : Form
    {

        private mainForm _mform;
        public AddForm(mainForm mform)
        {
            InitializeComponent();
            this._mform = mform;
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            Student stu1 = new Student();
            stu1.Id = Convert.ToInt32(txtId.Text);
            stu1.Name = txtName.Text;
            stu1.Score = Convert.ToInt32(txtScore.Text);
            stu1.Age = Convert.ToInt32(txtAge.Text);
            stu1.Sex = this.radionan.Checked == true ? "男" : "女";
            this._mform.StuList.Add(stu1);
            this._mform.BindGridview();
            MessageBox.Show("添加成功");
            this.Close();
        }
    }
}
updateform.cs

C# Winform月考学生成绩管理系统_第3张图片

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 月考学生成绩管理系统
{
    public partial class updateForm : Form
    {
        private mainForm _mform;
        private int _selectindex;
        public updateForm(mainForm  mform,int selindex)
        {
            InitializeComponent();
            _mform = mform;
            _selectindex = selindex;
            //////
            Student stu = this._mform.StuList[_selectindex];
            txtId.Text = stu.Id.ToString();
            txtName.Text = stu.Name;
            txtscore.Text = stu.Score.ToString();
            txtAge.Text = stu.Age.ToString();
            if (stu.Sex == "男")
                radionan.Checked = true;
            else
                radionv.Checked = true;


        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            Student stu = this._mform.StuList[_selectindex];
            stu.Id = Convert.ToInt32(txtId.Text);
            stu.Name = txtName.Text;
            stu.Score = Convert.ToInt32(txtscore.Text);
            stu.Age = Convert.ToInt32(txtAge.Text);
            stu.Sex = this.radionan.Checked == true ? "男" : "女";
            this._mform.BindGridview();
          //  MessageBox.Show("修改成功");
            this.Close();
        }
    }
}
Program.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 月考学生成绩管理系统
{
    static class Program
    {
        /// 
        /// 应用程序的主入口点。
        /// 
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new mainForm());
        }
    }
}



你可能感兴趣的:(.NET,FrameWork)