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

📄 newclass.cs

📁 c#+SQL Server 中小型信息系统开发实例精选书上代码
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace StudentManagementsystem
{
	/// <summary>
	/// NewClass 的摘要说明。
	/// </summary>
	public class NewClass : System.Windows.Forms.Form
	{
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label2;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.TextBox Grade;
		private System.Windows.Forms.TextBox ClassName;
		private System.Windows.Forms.TextBox MaxNum;
		private System.Windows.Forms.Button NewClassCanl;
		private System.Windows.Forms.Button NewClassOk;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		/// 

		private string NewClassStrConn;
		private SqlConnection NewClassConn;
		private SqlCommand NewClassComd;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.GroupBox groupBox2;

		private System.ComponentModel.Container components = null;

		public NewClass()
		{
			//
			// 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.NewClassCanl = new System.Windows.Forms.Button();
			this.NewClassOk = new System.Windows.Forms.Button();
			this.Grade = new System.Windows.Forms.TextBox();
			this.ClassName = new System.Windows.Forms.TextBox();
			this.label3 = new System.Windows.Forms.Label();
			this.label2 = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.MaxNum = new System.Windows.Forms.TextBox();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.groupBox2 = new System.Windows.Forms.GroupBox();
			this.SuspendLayout();
			// 
			// NewClassCanl
			// 
			this.NewClassCanl.Location = new System.Drawing.Point(120, 120);
			this.NewClassCanl.Name = "NewClassCanl";
			this.NewClassCanl.Size = new System.Drawing.Size(72, 24);
			this.NewClassCanl.TabIndex = 15;
			this.NewClassCanl.Text = "退出";
			this.NewClassCanl.Click += new System.EventHandler(this.NewClassCanl_Click);
			// 
			// NewClassOk
			// 
			this.NewClassOk.Location = new System.Drawing.Point(24, 120);
			this.NewClassOk.Name = "NewClassOk";
			this.NewClassOk.Size = new System.Drawing.Size(72, 24);
			this.NewClassOk.TabIndex = 14;
			this.NewClassOk.Text = "确认";
			this.NewClassOk.Click += new System.EventHandler(this.NewClassOk_Click);
			// 
			// Grade
			// 
			this.Grade.Location = new System.Drawing.Point(96, 48);
			this.Grade.Name = "Grade";
			this.Grade.Size = new System.Drawing.Size(104, 21);
			this.Grade.TabIndex = 13;
			this.Grade.Text = "";
			// 
			// ClassName
			// 
			this.ClassName.Location = new System.Drawing.Point(96, 24);
			this.ClassName.Name = "ClassName";
			this.ClassName.Size = new System.Drawing.Size(104, 21);
			this.ClassName.TabIndex = 12;
			this.ClassName.Text = "";
			// 
			// label3
			// 
			this.label3.Location = new System.Drawing.Point(16, 72);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(72, 16);
			this.label3.TabIndex = 11;
			this.label3.Text = "最大人数:";
			// 
			// label2
			// 
			this.label2.Location = new System.Drawing.Point(16, 48);
			this.label2.Name = "label2";
			this.label2.Size = new System.Drawing.Size(72, 16);
			this.label2.TabIndex = 10;
			this.label2.Text = "年   级:";
			// 
			// label1
			// 
			this.label1.Location = new System.Drawing.Point(16, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(72, 16);
			this.label1.TabIndex = 9;
			this.label1.Text = "班级名称:";
			// 
			// MaxNum
			// 
			this.MaxNum.Location = new System.Drawing.Point(96, 72);
			this.MaxNum.Name = "MaxNum";
			this.MaxNum.Size = new System.Drawing.Size(104, 21);
			this.MaxNum.TabIndex = 16;
			this.MaxNum.Text = "";
			// 
			// groupBox1
			// 
			this.groupBox1.Location = new System.Drawing.Point(8, 8);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(200, 96);
			this.groupBox1.TabIndex = 17;
			this.groupBox1.TabStop = false;
			this.groupBox1.Text = "信息";
			// 
			// groupBox2
			// 
			this.groupBox2.Location = new System.Drawing.Point(8, 104);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(200, 48);
			this.groupBox2.TabIndex = 18;
			this.groupBox2.TabStop = false;
			// 
			// NewClass
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(216, 157);
			this.Controls.Add(this.MaxNum);
			this.Controls.Add(this.NewClassCanl);
			this.Controls.Add(this.NewClassOk);
			this.Controls.Add(this.Grade);
			this.Controls.Add(this.ClassName);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.label2);
			this.Controls.Add(this.label1);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.groupBox2);
			this.Name = "NewClass";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "添加新班级";
			this.ResumeLayout(false);

		}
		#endregion

		private void NewClassOk_Click(object sender, System.EventArgs e)
		{
			try
			{
				string SqlStr="insert into class(Class_name,grade,MaxNum)values"+"( "+"'"+this.ClassName.Text.ToString().Trim()+"'"+","+"'"+this.Grade.Text.ToString().Trim()+"'"+","+"'"+this.MaxNum.Text.ToString().Trim()+"'"+")";
				NewClassStrConn="workstation id=localhost;Integrated Security=SSPI;database=StuMagSys";
				NewClassConn=new SqlConnection(NewClassStrConn);

				NewClassConn.Open();
				NewClassComd=new SqlCommand(SqlStr,NewClassConn);
				int Succnum=NewClassComd.ExecuteNonQuery();
				if(Succnum>0) MessageBox.Show("录入成功");
			}
			catch(Exception Ex)
			{
				MessageBox.Show(Ex.ToString(),"错误");
			}
		}

		private void NewClassCanl_Click(object sender, System.EventArgs e)
		{
			if(MessageBox.Show("您确认要退出?","确认",MessageBoxButtons.YesNo)==DialogResult.Yes)
				this.Close();
		}


	}
}

⌨️ 快捷键说明

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