📄 winmain.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Configuration;
using ClassLibrary;
namespace CJGL
{
/// <summary>
/// WinMain 的摘要说明。
/// </summary>
public class WinMain: System.Windows.Forms.Form
{
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.MainMenu mainMenu1;
private System.Windows.Forms.MenuItem menuItem3;
private System.Windows.Forms.MenuItem menuItem4;
private System.Windows.Forms.ToolBar toolBar1;
private System.Windows.Forms.ImageList imageList1;
private System.Windows.Forms.ToolBarButton toolBarButton1;
private System.Windows.Forms.ToolBarButton toolBarButton2;
private System.Windows.Forms.ToolBarButton toolBarButton3;
private System.Windows.Forms.ToolBarButton toolBarButton6;
private System.Windows.Forms.ToolBarButton toolBarButton7;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.ToolBarButton toolBarButton8;
private System.Windows.Forms.MenuItem menuItem5;
private System.Windows.Forms.MenuItem menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
private System.Windows.Forms.MenuItem menuItem6;
private System.Windows.Forms.MenuItem menuItem7;
private DataAccess data;
private System.Windows.Forms.MenuItem menuItem8;
private System.Windows.Forms.ContextMenu contextMenu1;
private System.Windows.Forms.MenuItem 增加学生;
private System.Windows.Forms.MenuItem menuItem9;
private System.Windows.Forms.MenuItem menuItem10;
private System.Windows.Forms.MenuItem menuItem11;
private System.Data.DataTable dt;
public WinMain()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(WinMain));
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.contextMenu1 = new System.Windows.Forms.ContextMenu();
this.增加学生 = new System.Windows.Forms.MenuItem();
this.menuItem9 = new System.Windows.Forms.MenuItem();
this.menuItem10 = new System.Windows.Forms.MenuItem();
this.menuItem11 = new System.Windows.Forms.MenuItem();
this.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem6 = new System.Windows.Forms.MenuItem();
this.menuItem7 = new System.Windows.Forms.MenuItem();
this.menuItem8 = new System.Windows.Forms.MenuItem();
this.menuItem4 = new System.Windows.Forms.MenuItem();
this.menuItem5 = new System.Windows.Forms.MenuItem();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.toolBar1 = new System.Windows.Forms.ToolBar();
this.toolBarButton1 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton2 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton3 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton8 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton6 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton7 = new System.Windows.Forms.ToolBarButton();
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// dataGrid1
//
this.dataGrid1.AlternatingBackColor = System.Drawing.Color.LightGray;
this.dataGrid1.BackColor = System.Drawing.Color.DarkGray;
this.dataGrid1.BackgroundColor = System.Drawing.Color.DimGray;
this.dataGrid1.CaptionBackColor = System.Drawing.Color.White;
this.dataGrid1.CaptionFont = new System.Drawing.Font("Verdana", 10F);
this.dataGrid1.CaptionForeColor = System.Drawing.Color.Navy;
this.dataGrid1.CaptionText = "111222";
this.dataGrid1.CaptionVisible = false;
this.dataGrid1.ContextMenu = this.contextMenu1;
this.dataGrid1.DataMember = "";
this.dataGrid1.ForeColor = System.Drawing.Color.Black;
this.dataGrid1.GridLineColor = System.Drawing.Color.Silver;
this.dataGrid1.HeaderBackColor = System.Drawing.Color.Silver;
this.dataGrid1.HeaderForeColor = System.Drawing.Color.Black;
this.dataGrid1.LinkColor = System.Drawing.Color.Navy;
this.dataGrid1.Location = new System.Drawing.Point(0, 48);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.ParentRowsBackColor = System.Drawing.Color.White;
this.dataGrid1.ParentRowsForeColor = System.Drawing.Color.Black;
this.dataGrid1.ReadOnly = true;
this.dataGrid1.SelectionBackColor = System.Drawing.Color.Navy;
this.dataGrid1.SelectionForeColor = System.Drawing.Color.White;
this.dataGrid1.Size = new System.Drawing.Size(752, 368);
this.dataGrid1.TabIndex = 0;
this.dataGrid1.Paint += new System.Windows.Forms.PaintEventHandler(this.dataGrid1_Paint);
this.dataGrid1.AllowSorting=false;
//
// contextMenu1
//
this.contextMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.增加学生,
this.menuItem9,
this.menuItem10,
this.menuItem11});
this.contextMenu1.Popup += new System.EventHandler(this.contextMenu1_Popup);
//
// 增加学生
//
this.增加学生.Index = 0;
this.增加学生.Text = "增加档案";
//
// menuItem9
//
this.menuItem9.Index = 1;
this.menuItem9.Text = "修改档案";
//
// menuItem10
//
this.menuItem10.Index = 2;
this.menuItem10.Text = "删除档案";
//
// menuItem11
//
this.menuItem11.Index = 3;
this.menuItem11.Text = "保存数据";
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem3,
this.menuItem4});
//
// menuItem3
//
this.menuItem3.Index = 0;
this.menuItem3.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2,
this.menuItem6,
this.menuItem7,
this.menuItem8});
this.menuItem3.Text = "操作(&C)";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Shortcut = System.Windows.Forms.Shortcut.CtrlA;
this.menuItem2.Text = "增加档案 (ctrl+A)";
this.menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
//
// menuItem6
//
this.menuItem6.Index = 1;
this.menuItem6.Shortcut = System.Windows.Forms.Shortcut.CtrlM;
this.menuItem6.Text = "修改档案 (ctrl+M)";
this.menuItem6.Click += new System.EventHandler(this.menuItem6_Click);
//
// menuItem7
//
this.menuItem7.Index = 2;
this.menuItem7.Shortcut = System.Windows.Forms.Shortcut.CtrlD;
this.menuItem7.Text = "删除档案 (ctrl+D)";
this.menuItem7.Click += new System.EventHandler(this.menuItem7_Click);
//
// menuItem8
//
this.menuItem8.Index = 3;
this.menuItem8.Shortcut = System.Windows.Forms.Shortcut.CtrlS;
this.menuItem8.Text = "保存数据 (ctrl+S)";
this.menuItem8.Click += new System.EventHandler(this.menuItem8_Click);
//
// menuItem4
//
this.menuItem4.Index = 1;
this.menuItem4.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem5,
this.menuItem1});
this.menuItem4.Text = "帮助(&E)";
//
// menuItem5
//
this.menuItem5.Index = 0;
this.menuItem5.Shortcut = System.Windows.Forms.Shortcut.CtrlB;
this.menuItem5.Text = "版本信息 (ctrl+B)";
this.menuItem5.Click += new System.EventHandler(this.menuItem5_Click);
//
// menuItem1
//
this.menuItem1.Index = 1;
this.menuItem1.Shortcut = System.Windows.Forms.Shortcut.CtrlH;
this.menuItem1.Text = "系统帮助 (ctrl+H)";
this.menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton8,
this.toolBarButton6,
this.toolBarButton7});
this.toolBar1.ContextMenu = this.contextMenu1;
this.toolBar1.DropDownArrows = true;
this.toolBar1.ImageList = this.imageList1;
this.toolBar1.Location = new System.Drawing.Point(0, 0);
this.toolBar1.Name = "toolBar1";
this.toolBar1.ShowToolTips = true;
this.toolBar1.Size = new System.Drawing.Size(750, 41);
this.toolBar1.TabIndex = 1;
this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
//
// toolBarButton1
//
this.toolBarButton1.ImageIndex = 0;
this.toolBarButton1.Text = "增加档案";
this.toolBarButton1.ToolTipText = "增加学生档案";
//
// toolBarButton2
//
this.toolBarButton2.ImageIndex = 1;
this.toolBarButton2.Text = "修改档案";
this.toolBarButton2.ToolTipText = "修改学生档案";
//
// toolBarButton3
//
this.toolBarButton3.ImageIndex = 2;
this.toolBarButton3.Text = "删除档案";
this.toolBarButton3.ToolTipText = "删除学生档案";
//
// toolBarButton8
//
this.toolBarButton8.ImageIndex = 6;
this.toolBarButton8.Text = "保存数据";
this.toolBarButton8.ToolTipText = "保存数据";
//
// toolBarButton6
//
this.toolBarButton6.ImageIndex = 5;
this.toolBarButton6.Text = "系统帮助";
this.toolBarButton6.ToolTipText = "系统帮助";
//
// toolBarButton7
//
this.toolBarButton7.ImageIndex = 0;
this.toolBarButton7.Text = "退出登录";
this.toolBarButton7.ToolTipText = "退出登录";
//
// imageList1
//
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
//
// WinMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(750, 415);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.dataGrid1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
this.Menu = this.mainMenu1;
this.Name = "WinMain";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "学生成绩管理系统";
this.Load += new System.EventHandler(this.WinMain_Load);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void WinMain_Load(object sender, System.EventArgs e)
{
string sql="select * from student";
data=new DataAccess();
dt=data.GetDataTable(sql);
dataGrid1.DataSource=dt;
DataGridTableStyle ts=new DataGridTableStyle();
dataGrid1.DataSource=dt;
ts.MappingName=dt.TableName;
int numCols=dt.Columns.Count; //数据源的列数
dataGrid1.CaptionText = "学生档案列表";
DataGridTextBoxColumn hh=new DataGridTextBoxColumn();
hh.HeaderText ="行号";
hh.MappingName =dt.Rows.Count.ToString();
ts.PreferredColumnWidth = 60;
ts.PreferredRowHeight = 20;
ts.AlternatingBackColor = Color.LightGray; //设定交替行的背景色
ts.GridColumnStyles.Add(hh); //增加一种自定义的column风格
ts.AllowSorting=false;
for (int i=0;i<numCols;i++)
{
DataGridTextBoxColumn aColumnTextColumn=new DataGridTextBoxColumn();
aColumnTextColumn.HeaderText =ConvertTitle(dt.Columns[i].ColumnName);
aColumnTextColumn.MappingName =dt.Columns[i].ColumnName;
if (i==1)
{
ts.PreferredColumnWidth = 95;
ts.PreferredRowHeight = 25;
}
ts.AlternatingBackColor = Color.LightGray; //设定交替行的背景色
ts.GridColumnStyles.Add(aColumnTextColumn); //增加一种自定义的column风格
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -