📄 mainform.cs
字号:
using System;
using System.Data;
using System.Data.OleDb;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using StudentsMIS.DataAccess;
using StudentsMIS.Business;
namespace StudentsMIS.WinForm
{
/// <summary>
/// MainForm 是学生管理信息系统的主窗体。
/// </summary>
public class MainForm : System.Windows.Forms.Form
{
private System.Windows.Forms.StatusBar statusBar1;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.TreeView treeView1;
private System.Windows.Forms.ListView listView1;
private System.Windows.Forms.MainMenu mainMenuMain;
private System.Windows.Forms.ColumnHeader clmHeadStuSex;
private System.Windows.Forms.ColumnHeader clmHeadStuCollege;
private System.Windows.Forms.ColumnHeader clmHeadStuSpeciality;
private System.Windows.Forms.ColumnHeader clmHeadStuEnterYear;
private System.Windows.Forms.ColumnHeader clmHeadStuType;
private System.Windows.Forms.ColumnHeader clmHeadStuNative;
private System.Windows.Forms.ImageList imageListLarge;
private System.Windows.Forms.ImageList imageListSmall;
private System.Windows.Forms.MenuItem menuItem11;
private System.Windows.Forms.MenuItem menuItemLargeIcon;
private System.Windows.Forms.MenuItem menuItemSmallIcon;
private System.Windows.Forms.MenuItem menuItemList;
private System.Windows.Forms.MenuItem menuItemDetail;
private System.Windows.Forms.MenuItem menuItemStatuBar;
private System.Windows.Forms.MenuItem menuItemToolBar;
private System.Windows.Forms.MenuItem menuItemView;
private System.Windows.Forms.MenuItem menuItemHelp;
private System.Windows.Forms.MenuItem menuItemSetting;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem12;
private System.Windows.Forms.MenuItem menuItem13;
private System.Windows.Forms.MenuItem menuItem14;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.ImageList imageListTools;
private System.Windows.Forms.ToolBarButton toolBarBtnNew;
private System.Windows.Forms.ToolBarButton toolBarBtnPropties;
private System.Windows.Forms.ToolBarButton toolBarBtnEdit;
private System.Windows.Forms.ToolBarButton toolBarBtnDelete;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.MenuItem menuItemDelete;
private System.Windows.Forms.MenuItem menuItemEdit;
private System.Windows.Forms.MenuItem menuItemNew;
private System.Windows.Forms.MenuItem menuItemPropties;
private System.Windows.Forms.ColumnHeader clmHeadStuName;
private System.Windows.Forms.ColumnHeader clmHeadStuID;
private System.Windows.Forms.MenuItem menuItemOrgSettings;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItemUserMng;
private System.Windows.Forms.MenuItem menuItemChgPwd;
private System.Windows.Forms.MenuItem menuItemTypeSting;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItemRefeash;
private System.Windows.Forms.ToolBarButton toolBarBtnRefeash;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private StudentManager manager = new StudentManager();
public MainForm()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
BindCollegeTreeNode();
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
private void BindCollegeTreeNode()
{
treeView1.Nodes.Clear();
OleDbDataReader objReader = CommandBuilder.BuildOleDbDataReader("Select * From colleges");
while(objReader.Read())
{
TreeNode node = new TreeNode(objReader["college_name"].ToString() + "-" + objReader["college_ID"].ToString());
node.Tag = objReader["college_ID"].ToString().Trim();
BindClassTreeNode(node,objReader["college_ID"].ToString().Trim());
treeView1.Nodes.Add(node);
}
objReader.Close();
}
private void BindClassTreeNode(TreeNode parent,string key)
{
parent.Nodes.Clear();
OleDbDataReader objReader = CommandBuilder.BuildOleDbDataReader("SELECT class_ID,class_name FROM (colleges INNER JOIN speciality ON colleges.college_ID = speciality.speciality_college) INNER JOIN classes ON speciality.speciality_ID = classes.class_speciality Where College_ID='"+key+"'");
while(objReader.Read())
{
TreeNode node = new TreeNode(objReader["class_name"].ToString().Trim() + "-" +objReader["class_ID"].ToString().Trim());
node.Tag = objReader["class_ID"].ToString().Trim();
parent.Nodes.Add(node);
}
if(parent.Nodes.Count==0)
{
parent.Nodes.Add("(无)");
parent.Nodes[0].Tag = 0;
}
objReader.Close();
}
private void BindStudentsList()
{
if(treeView1.SelectedNode == null)
return;
this.ButtonEnabled = false;
listView1.Items.Clear();
OleDbDataReader objReader = CommandBuilder.BuildOleDbDataReader("SELECT students.student_ID, students.student_name, students.student_sex,student_enterYear,student_stuType,student_native,classes.class_name, speciality.speciality_name, colleges.college_name FROM colleges INNER JOIN (speciality INNER JOIN (classes INNER JOIN students ON classes.class_ID = students.student_class) ON speciality.speciality_ID = classes.class_speciality) ON colleges.college_ID = speciality.speciality_college Where student_class='"+ treeView1.SelectedNode.Tag.ToString() +"' Order By student_ID asc");
while(objReader.Read())
{
string[] item = {
objReader["student_name"].ToString().Trim(),
objReader["student_ID"].ToString().Trim(),
objReader["student_sex"].ToString().Trim(),
objReader["college_name"].ToString().Trim(),
objReader["speciality_name"].ToString().Trim(),
objReader["student_enterYear"].ToString().Trim() + "年",
objReader["student_stuType"].ToString().Trim() + "年",
objReader["student_Native"].ToString().Trim()
};
ListViewItem l = new ListViewItem(item);
l.ImageIndex = objReader["student_sex"].ToString().Trim()=="男" ? 0:1;
listView1.Items.Add(l);
}
statusBar1.Text = listView1.Items.Count.ToString()+"个对象";
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(MainForm));
this.mainMenuMain = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItemNew = new System.Windows.Forms.MenuItem();
this.menuItemPropties = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItemEdit = new System.Windows.Forms.MenuItem();
this.menuItemDelete = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItemSetting = new System.Windows.Forms.MenuItem();
this.menuItemOrgSettings = new System.Windows.Forms.MenuItem();
this.menuItemTypeSting = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItemUserMng = new System.Windows.Forms.MenuItem();
this.menuItemChgPwd = new System.Windows.Forms.MenuItem();
this.menuItemView = new System.Windows.Forms.MenuItem();
this.menuItemToolBar = new System.Windows.Forms.MenuItem();
this.menuItemStatuBar = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.menuItemLargeIcon = new System.Windows.Forms.MenuItem();
this.menuItemSmallIcon = new System.Windows.Forms.MenuItem();
this.menuItemList = new System.Windows.Forms.MenuItem();
this.menuItemDetail = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItemRefeash = new System.Windows.Forms.MenuItem();
this.menuItemHelp = new System.Windows.Forms.MenuItem();
this.menuItem12 = new System.Windows.Forms.MenuItem();
this.menuItem14 = new System.Windows.Forms.MenuItem();
this.menuItem13 = new System.Windows.Forms.MenuItem();
this.statusBar1 = new System.Windows.Forms.StatusBar();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarBtnNew = new System.Windows.Forms.ToolBarButton();
this.toolBarBtnPropties = new System.Windows.Forms.ToolBarButton();
this.toolBarBtnEdit = new System.Windows.Forms.ToolBarButton();
this.toolBarBtnDelete = new System.Windows.Forms.ToolBarButton();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarBtnRefeash = new System.Windows.Forms.ToolBarButton();
this.imageListTools = new System.Windows.Forms.ImageList(this.components);
this.treeView1 = new System.Windows.Forms.TreeView();
this.listView1 = new System.Windows.Forms.ListView();
this.clmHeadStuName = new System.Windows.Forms.ColumnHeader();
this.clmHeadStuID = new System.Windows.Forms.ColumnHeader();
this.clmHeadStuSex = new System.Windows.Forms.ColumnHeader();
this.clmHeadStuCollege = new System.Windows.Forms.ColumnHeader();
this.clmHeadStuSpeciality = new System.Windows.Forms.ColumnHeader();
this.clmHeadStuEnterYear = new System.Windows.Forms.ColumnHeader();
this.clmHeadStuType = new System.Windows.Forms.ColumnHeader();
this.clmHeadStuNative = new System.Windows.Forms.ColumnHeader();
this.imageListLarge = new System.Windows.Forms.ImageList(this.components);
this.imageListSmall = new System.Windows.Forms.ImageList(this.components);
this.splitter1 = new System.Windows.Forms.Splitter();
this.SuspendLayout();
//
// mainMenuMain
//
this.mainMenuMain.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItemSetting,
this.menuItemView,
this.menuItemHelp});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemNew,
this.menuItemPropties,
this.menuItem4,
this.menuItemEdit,
this.menuItemDelete,
this.menuItem9,
this.menuItem10});
this.menuItem1.Text = "学生(&X)";
//
// menuItemNew
//
this.menuItemNew.Index = 0;
this.menuItemNew.Shortcut = System.Windows.Forms.Shortcut.CtrlN;
this.menuItemNew.Text = "新建(&N)";
this.menuItemNew.Click += new System.EventHandler(this.menuItemNew_Click);
//
// menuItemPropties
//
this.menuItemPropties.Index = 1;
this.menuItemPropties.Text = "属性(&P)...";
this.menuItemPropties.Click += new System.EventHandler(this.menuItemPropties_Click);
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "-";
//
// menuItemEdit
//
this.menuItemEdit.Index = 3;
this.menuItemEdit.Shortcut = System.Windows.Forms.Shortcut.CtrlE;
this.menuItemEdit.Text = "编辑(&E)";
this.menuItemEdit.Click += new System.EventHandler(this.menuItemEdit_Click);
//
// menuItemDelete
//
this.menuItemDelete.Index = 4;
this.menuItemDelete.Shortcut = System.Windows.Forms.Shortcut.CtrlDel;
this.menuItemDelete.Text = "删除(&D)";
this.menuItemDelete.Click += new System.EventHandler(this.menuItemDelete_Click);
//
// menuItem9
//
this.menuItem9.Index = 5;
this.menuItem9.Text = "-";
//
// menuItem10
//
this.menuItem10.Index = 6;
this.menuItem10.Shortcut = System.Windows.Forms.Shortcut.AltF4;
this.menuItem10.Text = "关闭(&X)";
this.menuItem10.Click += new System.EventHandler(this.menuItem10_Click);
//
// menuItemSetting
//
this.menuItemSetting.Index = 1;
this.menuItemSetting.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItemOrgSettings,
this.menuItemTypeSting,
this.menuItem3,
this.menuItemUserMng,
this.menuItemChgPwd});
this.menuItemSetting.Text = "设置(&S)";
//
// menuItemOrgSettings
//
this.menuItemOrgSettings.Index = 0;
this.menuItemOrgSettings.Text = "组织机构设置(&O)";
this.menuItemOrgSettings.Click += new System.EventHandler(this.menuItemOrgSettings_Click);
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -