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

📄 history.cs

📁 数据库的课程设计作业。管理有关学生、课程的基本信息
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;

namespace 教务管理系统1
{
	/// <summary>
	/// history 的摘要说明。
	/// </summary>
	public class history : System.Windows.Forms.Form
	{
		private System.Windows.Forms.DataGrid dataGrid1;
		private System.Windows.Forms.Button button1;
		private System.Data.SqlClient.SqlConnection sqlConnection1;
		private 教务管理系统1.DataSet6 dataSet61;
		private System.Data.SqlClient.SqlDataAdapter da1;
		private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
		private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
		private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
		private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public history()
		{
			//
			// 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.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.dataSet61 = new 教务管理系统1.DataSet6();
			this.button1 = new System.Windows.Forms.Button();
			this.da1 = new System.Data.SqlClient.SqlDataAdapter();
			this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
			this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
			this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSet61)).BeginInit();
			this.SuspendLayout();
			// 
			// dataGrid1
			// 
			this.dataGrid1.CaptionVisible = false;
			this.dataGrid1.DataMember = "";
			this.dataGrid1.DataSource = this.dataSet61.历史表;
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(40, 88);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.Size = new System.Drawing.Size(472, 240);
			this.dataGrid1.TabIndex = 0;
			this.dataGrid1.Navigate += new System.Windows.Forms.NavigateEventHandler(this.dataGrid1_Navigate);
			// 
			// dataSet61
			// 
			this.dataSet61.DataSetName = "DataSet6";
			this.dataSet61.Locale = new System.Globalization.CultureInfo("zh-CN");
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(48, 32);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(144, 32);
			this.button1.TabIndex = 1;
			this.button1.Text = "转存毕业学生信息";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// da1
			// 
			this.da1.DeleteCommand = this.sqlDeleteCommand1;
			this.da1.InsertCommand = this.sqlInsertCommand1;
			this.da1.SelectCommand = this.sqlSelectCommand1;
			this.da1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
																						  new System.Data.Common.DataTableMapping("Table", "历史表", new System.Data.Common.DataColumnMapping[] {
																																																 new System.Data.Common.DataColumnMapping("学号", "学号"),
																																																 new System.Data.Common.DataColumnMapping("姓名", "姓名"),
																																																 new System.Data.Common.DataColumnMapping("课程名", "课程名"),
																																																 new System.Data.Common.DataColumnMapping("成绩", "成绩"),
																																																 new System.Data.Common.DataColumnMapping("上课开始日期", "上课开始日期"),
																																																 new System.Data.Common.DataColumnMapping("上课结束日期", "上课结束日期")})});
			this.da1.UpdateCommand = this.sqlUpdateCommand1;
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=\"IBM-1A298E66873\";packet size=4096;integrated security=SSPI;initia" +
				"l catalog=\"study&teach\";persist security info=False";
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT 学号, 姓名, 课程名, 成绩, 上课开始日期, 上课结束日期 FROM 历史表";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			// 
			// sqlInsertCommand1
			// 
			this.sqlInsertCommand1.CommandText = "INSERT INTO 历史表(学号, 姓名, 课程名, 成绩, 上课开始日期, 上课结束日期) VALUES (@学号, @姓名, @课程名, @成绩, @上课" +
				"开始日期, @上课结束日期); SELECT 学号, 姓名, 课程名, 成绩, 上课开始日期, 上课结束日期 FROM 历史表 WHERE (学号 = @学号)" +
				"";
			this.sqlInsertCommand1.Connection = this.sqlConnection1;
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@学号", System.Data.SqlDbType.VarChar, 8, "学号"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@姓名", System.Data.SqlDbType.VarChar, 8, "姓名"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@课程名", System.Data.SqlDbType.VarChar, 40, "课程名"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@成绩", System.Data.SqlDbType.Int, 4, "成绩"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@上课开始日期", System.Data.SqlDbType.DateTime, 8, "上课开始日期"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@上课结束日期", System.Data.SqlDbType.DateTime, 8, "上课结束日期"));
			// 
			// sqlUpdateCommand1
			// 
			this.sqlUpdateCommand1.CommandText = @"UPDATE 历史表 SET 学号 = @学号, 姓名 = @姓名, 课程名 = @课程名, 成绩 = @成绩, 上课开始日期 = @上课开始日期, 上课结束日期 = @上课结束日期 WHERE (学号 = @Original_学号) AND (上课开始日期 = @Original_上课开始日期 OR @Original_上课开始日期 IS NULL AND 上课开始日期 IS NULL) AND (上课结束日期 = @Original_上课结束日期 OR @Original_上课结束日期 IS NULL AND 上课结束日期 IS NULL) AND (姓名 = @Original_姓名) AND (成绩 = @Original_成绩 OR @Original_成绩 IS NULL AND 成绩 IS NULL) AND (课程名 = @Original_课程名); SELECT 学号, 姓名, 课程名, 成绩, 上课开始日期, 上课结束日期 FROM 历史表 WHERE (学号 = @学号)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection1;
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@学号", System.Data.SqlDbType.VarChar, 8, "学号"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@姓名", System.Data.SqlDbType.VarChar, 8, "姓名"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@课程名", System.Data.SqlDbType.VarChar, 40, "课程名"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@成绩", System.Data.SqlDbType.Int, 4, "成绩"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@上课开始日期", System.Data.SqlDbType.DateTime, 8, "上课开始日期"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@上课结束日期", System.Data.SqlDbType.DateTime, 8, "上课结束日期"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_学号", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "学号", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_上课开始日期", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "上课开始日期", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_上课结束日期", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "上课结束日期", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_姓名", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "姓名", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_成绩", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "成绩", System.Data.DataRowVersion.Original, null));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_课程名", System.Data.SqlDbType.VarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "课程名", System.Data.DataRowVersion.Original, null));
			// 
			// sqlDeleteCommand1
			// 
			this.sqlDeleteCommand1.CommandText = @"DELETE FROM 历史表 WHERE (学号 = @Original_学号) AND (上课开始日期 = @Original_上课开始日期 OR @Original_上课开始日期 IS NULL AND 上课开始日期 IS NULL) AND (上课结束日期 = @Original_上课结束日期 OR @Original_上课结束日期 IS NULL AND 上课结束日期 IS NULL) AND (姓名 = @Original_姓名) AND (成绩 = @Original_成绩 OR @Original_成绩 IS NULL AND 成绩 IS NULL) AND (课程名 = @Original_课程名)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection1;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_学号", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "学号", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_上课开始日期", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "上课开始日期", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_上课结束日期", System.Data.SqlDbType.DateTime, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "上课结束日期", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_姓名", System.Data.SqlDbType.VarChar, 8, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "姓名", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_成绩", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "成绩", System.Data.DataRowVersion.Original, null));
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_课程名", System.Data.SqlDbType.VarChar, 40, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "课程名", System.Data.DataRowVersion.Original, null));
			// 
			// history
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(568, 366);
			this.Controls.Add(this.button1);
			this.Controls.Add(this.dataGrid1);
			this.Name = "history";
			this.Text = "history";
			this.Load += new System.EventHandler(this.history_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSet61)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void dataGrid1_Navigate(object sender, System.Windows.Forms.NavigateEventArgs ne)
		{
			
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			SqlConnection cn = new SqlConnection ("workstation id=locolhost;integrated Security=sspi;database=study&teach;");
			cn.Open();
			SqlCommand cmd=cn.CreateCommand();
			cmd.CommandType=CommandType.StoredProcedure;
			cmd.CommandText="updatehistory";
			cmd.ExecuteNonQuery();
			da1.Update(dataSet61.历史表);
			dataSet61.Clear();
			da1.Fill(dataSet61);
		}

		private void history_Load(object sender, System.EventArgs e)
		{
			da1.Fill(dataSet61);
		}
	}
}

⌨️ 快捷键说明

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