找传奇、传世资源到传世资源站!

C#学生管理综合程序(IrisSkin版)

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

非常精美的一款学生管理综合程序
from clipboard
from clipboardusing System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Diagnostics;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;namespace 学生综合程序{ public partial class FrmMain : Form { /// <summary> /// 窗体实例化 /// </summary> /// <param name="userName"></param> public FrmMain(string userName) { InitializeComponent(); this.tslblFirst.Text = String.Format("登录用户:{0} 登录时间:{1}", userName, DateTime.Now); } /// <summary> /// 窗体加载 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void FrmMain_Load(object sender, EventArgs e) { //给TreeView控件添加两个节点:男、女 TreeNode node = new TreeNode(); node.Text = "男生"; node.ImageIndex = 0; this.tvStudent.Nodes.Add(node); node = new TreeNode(); node.Text = "女生"; node.ImageIndex = 1; this.tvStudent.Nodes.Add(node); } private void tvStudent_AfterSelect(object sender, TreeViewEventArgs e) { //让树中的节点在选中后,不改变图标 e.Node.SelectedImageIndex = e.Node.ImageIndex; } /// <summary> /// 添加学生 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbtnAddStudent_Click(object sender, EventArgs e) { FrmStudent frmStudent = new FrmStudent(); DialogResult dr = frmStudent.ShowDialog(); if (DialogResult.OK != dr) { return; } Student student = frmStudent.student; #region 向列表中增加一行 ListViewItem lvi = new ListViewItem(); lvi.Text = student.no; lvi.SubItems.Add(student.name); lvi.SubItems.Add(student.sex); lvi.SubItems.Add(student.grade); lvi.SubItems.Add(student.major); lvi.SubItems.Add(student.remark); lvi.Tag = student; lvi.ImageIndex = student.sex == "男" ? 0 : 1; this.lvStudent.Items.Add(lvi); #endregion #region 向树形控件增加一个节点 TreeNode tn = new TreeNode(); tn.Text = student.name; tn.Tag = student; if (student.sex == "男") { this.tvStudent.Nodes[0].Nodes.Add(tn); } else { tn.ImageIndex = 1; this.tvStudent.Nodes[1].Nodes.Add(tn); } //展开树节点 this.tvStudent.ExpandAll(); #endregion } /// <summary> /// 修改学生 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbtnChangeStudent_Click(object sender, EventArgs e) { //如果学生列表中没有选中任何行,直接返回 if (this.lvStudent.FocusedItem == null) { return; } ListViewItem lvi = this.lvStudent.FocusedItem; Student oldStudent = (Student)lvi.Tag; //记录修改前的学生姓名、性别,以便修改完后还能从TreeView中定位到该学生 FrmStudent frmStudent = new FrmStudent(oldStudent); DialogResult dr = frmStudent.ShowDialog(); if (dr != DialogResult.OK) { return; } Student student = frmStudent.student; lvi.Text = student.no; lvi.SubItems[1].Text = student.name; lvi.SubItems[2].Text = student.sex; lvi.SubItems[3].Text = student.grade; lvi.SubItems[4].Text = student.major; lvi.SubItems[5].Text = student.remark; lvi.Tag = student; lvi.ImageIndex = student.sex == "男" ? 0 : 1; if (oldStudent.sex == "男") { foreach (TreeNode tn in this.tvStudent.Nodes[0].Nodes) { //找到该学生,并修改他 if (tn.Text == oldStudent.name) { tn.Text = student.name; if(student.sex != oldStudent.sex)//如果性别变了 { tn.Remove();//将其从男生节点下方移除, this.tvStudent.Nodes[1].Nodes.Add(tn);//添加到女生节点下方 tn.ImageIndex = tn.Parent.ImageIndex;//修改其图标 } } } } else { foreach (TreeNode tn in this.tvStudent.Nodes[1].Nodes) { //找到该学生,并修改他 if (tn.Text == oldStudent.name) { tn.Text = student.name; if (student.sex != oldStudent.sex)//如果性别变了 { tn.Remove();//将其从女生节点下方移除, this.tvStudent.Nodes[0].Nodes.Add(tn);//添加到男生节点下方 tn.ImageIndex = tn.Parent.ImageIndex;//修改其图标 } } } } } /// <summary> /// 删除学生 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsbtnDeleteStudent_Click(object sender, EventArgs e) { if (this.lvStudent.SelectedItems.Count == 0) return; DialogResult dr = MessageBox.Show("确实要删除选定的学生吗?", "删除确认", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (dr != DialogResult.Yes) return; foreach (ListViewItem lvi in this.lvStudent.SelectedItems) { lvi.Remove(); DeleteFromTreeView(lvi.SubItems[1].Text); } } /// <summary> /// 将指定的学生从TreeView中删除 /// </summary> /// <param name="name"></param> private void DeleteFromTreeView(string name) { foreach (TreeNode tn in tvStudent.Nodes[0].Nodes) { if (tn.Text.Equals(name)) { tn.Remove(); return; } } foreach (TreeNode tn in tvStudent.Nodes[1].Nodes) { if (tn.Text.Equals(name)) { tn.Remove(); return; } } } private void tsbExit_Click(object sender, EventArgs e) { this.Close(); } private void tsmiHelp_Click(object sender, EventArgs e) { Process.Start("帮助文档.pdf"); } /// <summary> /// 关于对话框 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void tsmiAbout_Click(object sender, EventArgs e) { FrmAbout frmAbout = new FrmAbout(); frmAbout.Show(); } /// <summary> /// 按delete键删除选定的学生 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lvStudent_KeyDown(object sender, KeyEventArgs e) { switch (e.KeyCode) { case Keys.Delete: tsbtnDeleteStudent_Click(null, null); break; } } }}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复