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

📄 frmsubject.cs

📁 三层体系结构的应用-学员管理系统 一个学校需要一个学生管理系统。分以下功能: 管理班档案 管理学生档案 学校开了多门课程
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Student
{
	using Aptech.Student.DataAccess;

	/// <summary>
	/// frmSubject 的摘要说明。
	/// </summary>
	public class frmSubject : System.Windows.Forms.Form
	{
		private System.Windows.Forms.ToolBar toolBar1;
		private System.Windows.Forms.ToolBarButton tlbNew;
		private System.Windows.Forms.ToolBarButton tlbModify;
		private System.Windows.Forms.ToolBarButton tlbDelete;
		private System.Windows.Forms.ImageList imageList1;
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.ComponentModel.IContainer components;

		public frmSubject()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();

			//
			// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
			//
		}

		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		private void CreateDataGridStyle()
		{
			DataGridTableStyle tableStyle = new DataGridTableStyle();
			
			DataGridTextBoxColumn textBoxColumn = new DataGridTextBoxColumn();
			
			textBoxColumn.MappingName = "SubjectId";
			tableStyle.GridColumnStyles.Add(textBoxColumn);
			textBoxColumn.Width = 40;
			textBoxColumn.ReadOnly = true;
			
			textBoxColumn = new DataGridTextBoxColumn();
			textBoxColumn.HeaderText = "科目名称";
			textBoxColumn.MappingName = "SubjectName";
			tableStyle.GridColumnStyles.Add(textBoxColumn);
			textBoxColumn.Width = dataGrid1.Width / 2 - 40;

			textBoxColumn = new DataGridTextBoxColumn();
			textBoxColumn.MappingName = "Remark";
			textBoxColumn.HeaderText = "备注";
			tableStyle.GridColumnStyles.Add(textBoxColumn);
			textBoxColumn.Width = dataGrid1.Width / 2 - 40;

			dataGrid1.TableStyles.Add(tableStyle);

		}

		private void GetSubject()
		{
			Subjects subjects = new Subjects();
			DataSet dataSet = new DataSet();
			dataSet = subjects.SelectSubject(
				-1,
				"");
			dataGrid1.DataSource = dataSet.Tables[0];
			dataGrid1.TableStyles[0].MappingName = dataSet.Tables[0].TableName;
		}


		#region Windows 窗体设计器生成的代码
		/// <summary>
		/// 设计器支持所需的方法 - 不要使用代码编辑器修改
		/// 此方法的内容。
		/// </summary>
		private void InitializeComponent()
		{
			this.components = new System.ComponentModel.Container();
			System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(frmSubject));
			this.toolBar1 = new System.Windows.Forms.ToolBar();
			this.tlbNew = new System.Windows.Forms.ToolBarButton();
			this.tlbModify = new System.Windows.Forms.ToolBarButton();
			this.tlbDelete = new System.Windows.Forms.ToolBarButton();
			this.imageList1 = new System.Windows.Forms.ImageList(this.components);
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// toolBar1
			// 
			this.toolBar1.Buttons.AddRange(new System.Windows.Forms.ToolBarButton[] {
																						this.tlbNew,
																						this.tlbModify,
																						this.tlbDelete});
			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(480, 41);
			this.toolBar1.TabIndex = 0;
			this.toolBar1.ButtonClick += new System.Windows.Forms.ToolBarButtonClickEventHandler(this.toolBar1_ButtonClick);
			// 
			// tlbNew
			// 
			this.tlbNew.ImageIndex = 0;
			this.tlbNew.Text = "新建";
			// 
			// tlbModify
			// 
			this.tlbModify.ImageIndex = 1;
			this.tlbModify.Text = "更改";
			// 
			// tlbDelete
			// 
			this.tlbDelete.ImageIndex = 2;
			this.tlbDelete.Text = "删除";
			// 
			// imageList1
			// 
			this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth24Bit;
			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;
			// 
			// dataGrid1
			// 
			this.dataGrid1.CaptionVisible = false;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(0, 41);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.RowHeadersVisible = false;
			this.dataGrid1.Size = new System.Drawing.Size(480, 252);
			this.dataGrid1.TabIndex = 1;
			// 
			// frmSubject
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(480, 293);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.toolBar1);
			this.MaximizeBox = false;
			this.MinimizeBox = false;
			this.Name = "frmSubject";
			this.Text = "科目管理";
			this.Load += new System.EventHandler(this.frmSubject_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void frmSubject_Load(object sender, System.EventArgs e)
		{
			CreateDataGridStyle();
			GetSubject();
		}

		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if(e.Button.Text == "新建")
			{
				CreateSubject();
			}
			else if(e.Button.Text == "删除")
			{
				DeleteSubject();
			}
			else
			{
				ModifySubject();
			}
		}

		private void CreateSubject()
		{
			if(dataGrid1[dataGrid1.CurrentRowIndex,0].ToString() == ""
				&& dataGrid1[dataGrid1.CurrentRowIndex, 1].ToString() != "")
			{
				Subjects subjects = new Subjects();
				subjects.InsertSubject(
					dataGrid1[dataGrid1.CurrentRowIndex,1].ToString(),
					dataGrid1[dataGrid1.CurrentRowIndex,2].ToString());
				MessageBox.Show("建立成功。");
				GetSubject();
			}
		}

		private void DeleteSubject()
		{
			if(dataGrid1[dataGrid1.CurrentRowIndex, 0].ToString() != "" 
				&& dataGrid1[dataGrid1.CurrentRowIndex, 0].ToString() != "null")
			{
				Subjects subjects = new Subjects();
				subjects.DeleteSubject(
					Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex, 0].ToString()));
				MessageBox.Show("删除成功。");
				GetSubject();
			}
		}

		private void ModifySubject()
		{
			if(dataGrid1[dataGrid1.CurrentRowIndex, 0].ToString() != "" 
				&& dataGrid1[dataGrid1.CurrentRowIndex, 0].ToString() != "null")
			{
				Subjects subjects = new Subjects();
				subjects.UpdateSubject(
					Convert.ToInt32(dataGrid1[dataGrid1.CurrentRowIndex, 0].ToString()),
					dataGrid1[dataGrid1.CurrentRowIndex, 1].ToString(),
					dataGrid1[dataGrid1.CurrentRowIndex, 2].ToString());
				MessageBox.Show(" 更改成功。");
				GetSubject();
			}
		}
	}
}

⌨️ 快捷键说明

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