⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 winmain.cs

📁 Microsoft Visual C++ 6.0
💻 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 窗体设计器支持所必需的
			//
			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.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 = "数据库";
			// 
			// 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 = "增加学生档案";
			// 
			// toolBarButton2
			// 
			this.toolBarButton2.ImageIndex = 1;
			this.toolBarButton2.Text = "修改档案";
			this.toolBarButton2.ToolTipText = "修改学生档案";
			// 
			// toolBarButton3
			// 
			this.toolBarButton3.ImageIndex = 2;
			this.toolBarButton3.Text = "删除档案";
			this.toolBarButton3.ToolTipText = "删除学生档案";
			// 
			// toolBarButton4
			// 
			this.toolBarButton4.ImageIndex = 3;
			this.toolBarButton4.Text = "学生分类";
			this.toolBarButton4.ToolTipText = "学生分类";
			// 
			// toolBarButton5
			// 
			this.toolBarButton5.ImageIndex = 4;
			this.toolBarButton5.Text = "名单打印";
			this.toolBarButton5.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;
			// 
			// 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=="学生")
			{
				this.toolBarButton1.Visible=false;
				this.toolBarButton2.Visible=false;
				this.toolBarButton3.Visible=false;
				this.toolBarButton4.Visible=false;
				this.Text="学生成绩查看";
			}
			else 
				this.Text="系统管理";
			
			
			
			
			
			
			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;  //数据源的列数
			dataGrid1.CaptionText = "学生档案列表";
			
			DataGridTextBoxColumn hh=new DataGridTextBoxColumn();
			hh.HeaderText ="行号";
			hh.MappingName =dt.Rows.Count.ToString();
			ts.PreferredColumnWidth = 50;
			ts.PreferredRowHeight = 20;
			ts.AlternatingBackColor = Color.LightGray;    //设定交替行的背景色
			ts.GridColumnStyles.Add(hh);   //增加一种自定义的column风格

			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风格
			}
			 dataGrid1.TableStyles.Add(ts); //增加一种自定义的表风格
			
		}
		private string ConvertTitle(string name)
		{
			switch (name)
			{
				case "stuid":
					return "学号";
				case "name":
					return "姓名";
				case "sex":
					return "性别";
				case "class":
					return "班级";
				case "tel":
					return "电话";
				case "address":
					return "家庭地址";
				case "btime":
					return "入学时间";
				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="添加学生信息";
				winnewuser.Show();

			}
			else if(e.Button==this.toolBarButton2)
				  {
				WinNewUser winnewuser=new WinNewUser();
				winnewuser.Text="修改学生信息";
				
			//    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");
			
                  
				  }

		
		}
		
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -