?? 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;
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 menuItem1;
private System.Windows.Forms.MenuItem menuItem2;
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 toolBarButton4;
private System.Windows.Forms.ToolBarButton toolBarButton5;
private System.Windows.Forms.ToolBarButton toolBarButton6;
private System.Windows.Forms.ToolBarButton toolBarButton7;
private System.ComponentModel.IContainer components;
private System.Windows.Forms.ToolBarButton toolBarButton8;
public string user;
public WinMain()
{
//
// Windows 窗體設(shè)計器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 調(diào)用后添加任何構(gòu)造函數(shù)代碼
//
}
/// <summary>
/// 清理所有正在使用的資源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗體設(shè)計器生成的代碼
/// <summary>
/// 設(shè)計器支持所需的方法 - 不要使用代碼編輯器修改
/// 此方法的內(nèi)容。
/// </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.mainMenu1 = new System.Windows.Forms.MainMenu();
this.menuItem1 = new System.Windows.Forms.MenuItem();
this.menuItem2 = new System.Windows.Forms.MenuItem();
this.menuItem3 = new System.Windows.Forms.MenuItem();
this.menuItem4 = 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.toolBarButton4 = new System.Windows.Forms.ToolBarButton();
this.toolBarButton5 = 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);
this.toolBarButton8 = new System.Windows.Forms.ToolBarButton();
((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.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(8, 40);
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(664, 344);
this.dataGrid1.TabIndex = 0;
//
// mainMenu1
//
this.mainMenu1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem1,
this.menuItem3,
this.menuItem4});
//
// menuItem1
//
this.menuItem1.Index = 0;
this.menuItem1.MenuItems.AddRange(new System.Windows.Forms.MenuItem[] {
this.menuItem2});
this.menuItem1.Text = "數(shù)據(jù)庫";
//
// menuItem2
//
this.menuItem2.Index = 0;
this.menuItem2.Text = "";
//
// menuItem3
//
this.menuItem3.Index = 1;
this.menuItem3.Text = "操作";
//
// menuItem4
//
this.menuItem4.Index = 2;
this.menuItem4.Text = "幫助";
//
// toolBar1
//
this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
this.toolBarButton1,
this.toolBarButton2,
this.toolBarButton3,
this.toolBarButton8,
this.toolBarButton4,
this.toolBarButton5,
this.toolBarButton6,
this.toolBarButton7});
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(664, 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 = "增加學(xué)生檔案";
//
// toolBarButton2
//
this.toolBarButton2.ImageIndex = 1;
this.toolBarButton2.Text = "修改檔案";
this.toolBarButton2.ToolTipText = "修改學(xué)生檔案";
//
// toolBarButton3
//
this.toolBarButton3.ImageIndex = 2;
this.toolBarButton3.Text = "刪除檔案";
this.toolBarButton3.ToolTipText = "刪除學(xué)生檔案";
//
// toolBarButton4
//
this.toolBarButton4.ImageIndex = 3;
this.toolBarButton4.Text = "學(xué)生分類";
this.toolBarButton4.ToolTipText = "學(xué)生分類";
//
// toolBarButton5
//
this.toolBarButton5.ImageIndex = 4;
this.toolBarButton5.Text = "名單打印";
this.toolBarButton5.ToolTipText = "名單打印";
//
// toolBarButton6
//
this.toolBarButton6.ImageIndex = 5;
this.toolBarButton6.Text = "系統(tǒng)幫助";
this.toolBarButton6.ToolTipText = "系統(tǒng)幫助";
//
// 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;
//
// toolBarButton8
//
this.toolBarButton8.ImageIndex = 6;
this.toolBarButton8.Text = "保存記錄";
this.toolBarButton8.ToolTipText = "保存記錄";
//
// WinMain
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(664, 381);
this.Controls.Add(this.toolBar1);
this.Controls.Add(this.dataGrid1);
this.Menu = this.mainMenu1;
this.Name = "WinMain";
this.Text = "WinMain";
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)
{
if(this.user=="學(xué)生")
{
this.toolBarButton1.Visible=false;
this.toolBarButton2.Visible=false;
this.toolBarButton3.Visible=false;
this.toolBarButton4.Visible=false;
this.Text="學(xué)生成績查看";
}
else
this.Text="系統(tǒng)管理";
string sql="select * from student";
DataAccess data=new DataAccess();
DataTable dt=data.GetDataTable(sql);
dataGrid1.DataSource=dt;
DataGridTableStyle ts=new DataGridTableStyle();
dataGrid1.DataSource=dt;
ts.MappingName=dt.TableName;
int numCols=dt.Columns.Count; //數(shù)據(jù)源的列數(shù)
dataGrid1.CaptionText = "學(xué)生檔案列表";
DataGridTextBoxColumn hh=new DataGridTextBoxColumn();
hh.HeaderText ="行號";
hh.MappingName =dt.Rows.Count.ToString();
ts.PreferredColumnWidth = 50;
ts.PreferredRowHeight = 20;
ts.AlternatingBackColor = Color.LightGray; //設(shè)定交替行的背景色
ts.GridColumnStyles.Add(hh); //增加一種自定義的column風(fēng)格
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; //設(shè)定交替行的背景色
ts.GridColumnStyles.Add(aColumnTextColumn); //增加一種自定義的column風(fēng)格
}
dataGrid1.TableStyles.Add(ts); //增加一種自定義的表風(fēng)格
}
private string ConvertTitle(string name)
{
switch (name)
{
case "stuid":
return "學(xué)號";
case "name":
return "姓名";
case "sex":
return "性別";
case "class":
return "班級";
case "tel":
return "電話";
case "address":
return "家庭地址";
case "btime":
return "入學(xué)時間";
default:
return "";
}
}
private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
{
DataAccess data=new DataAccess();
if(e.Button==this.toolBarButton7)
{
this.Close();
}
else if(e.Button==this.toolBarButton1)
{
WinNewUser winnewuser=new WinNewUser();
winnewuser.Text="添加學(xué)生信息";
winnewuser.Show();
}
else if(e.Button==this.toolBarButton2)
{
WinNewUser winnewuser=new WinNewUser();
winnewuser.Text="修改學(xué)生信息";
// winnewuser.stuidtext.Text
winnewuser.Show();
}
else if(e.Button==this.toolBarButton8)
{
System.Data.SqlClient.SqlDataAdapter adapter=new SqlDataAdapter();
string sql="select *from student";
adapter.Fill(data.GetDataSet(sql,"student"));
adapter.Update(data.GetDataSet(sql,"student"),"student");
}
}
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -