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

📄 score_into.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 chaxun
{
	/// <summary>
	/// Score_into 的摘要说明。
	/// </summary>
	public class Score_into : System.Windows.Forms.Form
	{
		private System.Windows.Forms.GroupBox groupBox2;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.ComboBox cmbType;

		private SqlDataAdapter thisAdapter;
		private DataSet mydataset;
		BindingManagerBase bManager;
		private System.Windows.Forms.Button button4;
		private System.Windows.Forms.Button button3;
		private System.Windows.Forms.Button button2;
		private System.Windows.Forms.TextBox textBox2;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.Label lblNumber;
		private System.Windows.Forms.TextBox txtscore;
		private System.Windows.Forms.Label lbl006;
		private System.Windows.Forms.TextBox textBox1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.Button button5;
		private System.Windows.Forms.Button button6;
		private System.Windows.Forms.DataGrid dataGrid1;
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		private System.ComponentModel.Container components = null;

		public Score_into()
		{
			//
			// Windows 窗体设计器支持所必需的
			//
			InitializeComponent();
			SqlConnection thisConnection=new SqlConnection("integrated security=SSPI;data source=.;persist security info=False;initial catalog=xxgcx");  
			thisAdapter=new SqlDataAdapter("SELECT id as 编号 ,xh as 学号,Test_Id as 课程编号,Scores as 成绩,Student_Xq as 学期 from score",thisConnection);
			SqlCommandBuilder thisBuilder=new SqlCommandBuilder(thisAdapter);
			mydataset=new DataSet();
			thisAdapter.Fill(mydataset,"score");

			//
			// 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.groupBox2 = new System.Windows.Forms.GroupBox();
			this.label3 = new System.Windows.Forms.Label();
			this.cmbType = new System.Windows.Forms.ComboBox();
			this.button4 = new System.Windows.Forms.Button();
			this.button3 = new System.Windows.Forms.Button();
			this.button2 = new System.Windows.Forms.Button();
			this.textBox2 = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.lblNumber = new System.Windows.Forms.Label();
			this.txtscore = new System.Windows.Forms.TextBox();
			this.lbl006 = new System.Windows.Forms.Label();
			this.textBox1 = new System.Windows.Forms.TextBox();
			this.button1 = new System.Windows.Forms.Button();
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.button5 = new System.Windows.Forms.Button();
			this.button6 = new System.Windows.Forms.Button();
			this.dataGrid1 = new System.Windows.Forms.DataGrid();
			this.groupBox1.SuspendLayout();
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
			this.SuspendLayout();
			// 
			// groupBox2
			// 
			this.groupBox2.Location = new System.Drawing.Point(72, 255);
			this.groupBox2.Name = "groupBox2";
			this.groupBox2.Size = new System.Drawing.Size(414, 8);
			this.groupBox2.TabIndex = 43;
			this.groupBox2.TabStop = false;
			// 
			// label3
			// 
			this.label3.Font = new System.Drawing.Font("宋体", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(134)));
			this.label3.ForeColor = System.Drawing.Color.Black;
			this.label3.Location = new System.Drawing.Point(354, 224);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(66, 16);
			this.label3.TabIndex = 34;
			this.label3.Text = "请选择学期:";
			// 
			// cmbType
			// 
			this.cmbType.Items.AddRange(new object[] {
														 "2005-2006/2",
														 "2006-2007/1",
														 "2006-2007/2"});
			this.cmbType.Location = new System.Drawing.Point(432, 224);
			this.cmbType.Name = "cmbType";
			this.cmbType.Size = new System.Drawing.Size(72, 20);
			this.cmbType.TabIndex = 31;
			// 
			// button4
			// 
			this.button4.Location = new System.Drawing.Point(444, 286);
			this.button4.Name = "button4";
			this.button4.Size = new System.Drawing.Size(75, 32);
			this.button4.TabIndex = 51;
			this.button4.Text = "返回";
			this.button4.Click += new System.EventHandler(this.button4_Click);
			// 
			// button3
			// 
			this.button3.Location = new System.Drawing.Point(102, 156);
			this.button3.Name = "button3";
			this.button3.Size = new System.Drawing.Size(56, 24);
			this.button3.TabIndex = 60;
			this.button3.Text = "上一位";
			this.button3.Click += new System.EventHandler(this.button3_Click);
			// 
			// button2
			// 
			this.button2.Location = new System.Drawing.Point(354, 286);
			this.button2.Name = "button2";
			this.button2.Size = new System.Drawing.Size(75, 32);
			this.button2.TabIndex = 59;
			this.button2.Text = "保存";
			this.button2.Click += new System.EventHandler(this.button2_Click);
			// 
			// textBox2
			// 
			this.textBox2.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textBox2.Location = new System.Drawing.Point(60, 56);
			this.textBox2.Name = "textBox2";
			this.textBox2.Size = new System.Drawing.Size(104, 21);
			this.textBox2.TabIndex = 58;
			this.textBox2.Text = "";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(0, 56);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(60, 19);
			this.label5.TabIndex = 55;
			this.label5.Text = "课程号:";
			this.label5.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// lblNumber
			// 
			this.lblNumber.Location = new System.Drawing.Point(6, 25);
			this.lblNumber.Name = "lblNumber";
			this.lblNumber.Size = new System.Drawing.Size(48, 19);
			this.lblNumber.TabIndex = 54;
			this.lblNumber.Text = "学 号:";
			this.lblNumber.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// txtscore
			// 
			this.txtscore.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.txtscore.Location = new System.Drawing.Point(96, 93);
			this.txtscore.MaxLength = 5;
			this.txtscore.Name = "txtscore";
			this.txtscore.Size = new System.Drawing.Size(48, 21);
			this.txtscore.TabIndex = 53;
			this.txtscore.TabStop = false;
			this.txtscore.Text = "";
			this.txtscore.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
			// 
			// lbl006
			// 
			this.lbl006.Location = new System.Drawing.Point(12, 93);
			this.lbl006.Name = "lbl006";
			this.lbl006.Size = new System.Drawing.Size(78, 17);
			this.lbl006.TabIndex = 52;
			this.lbl006.Text = "请输入成绩:";
			this.lbl006.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
			// 
			// textBox1
			// 
			this.textBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
			this.textBox1.Location = new System.Drawing.Point(60, 25);
			this.textBox1.Name = "textBox1";
			this.textBox1.Size = new System.Drawing.Size(104, 21);
			this.textBox1.TabIndex = 57;
			this.textBox1.Text = "";
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(18, 156);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(56, 24);
			this.button1.TabIndex = 56;
			this.button1.Text = "下一位";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.button3);
			this.groupBox1.Controls.Add(this.button1);
			this.groupBox1.Controls.Add(this.txtscore);
			this.groupBox1.Controls.Add(this.lbl006);
			this.groupBox1.Controls.Add(this.textBox2);
			this.groupBox1.Controls.Add(this.label5);
			this.groupBox1.Controls.Add(this.lblNumber);
			this.groupBox1.Controls.Add(this.textBox1);
			this.groupBox1.Location = new System.Drawing.Point(354, 0);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(180, 199);
			this.groupBox1.TabIndex = 61;
			this.groupBox1.TabStop = false;
			this.groupBox1.Enter += new System.EventHandler(this.groupBox1_Enter);
			// 
			// button5
			// 
			this.button5.Location = new System.Drawing.Point(264, 286);
			this.button5.Name = "button5";
			this.button5.Size = new System.Drawing.Size(75, 32);
			this.button5.TabIndex = 62;
			this.button5.Text = "更新";
			this.button5.Click += new System.EventHandler(this.button5_Click);
			// 
			// button6
			// 
			this.button6.Location = new System.Drawing.Point(180, 286);
			this.button6.Name = "button6";
			this.button6.Size = new System.Drawing.Size(75, 32);
			this.button6.TabIndex = 63;
			this.button6.Text = "删除";
			this.button6.Click += new System.EventHandler(this.button6_Click_1);
			// 
			// dataGrid1
			// 
			this.dataGrid1.DataMember = "";
			this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
			this.dataGrid1.Location = new System.Drawing.Point(12, 6);
			this.dataGrid1.Name = "dataGrid1";
			this.dataGrid1.ReadOnly = true;
			this.dataGrid1.Size = new System.Drawing.Size(336, 249);
			this.dataGrid1.TabIndex = 64;
			// 
			// Score_into
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(546, 366);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.button6);
			this.Controls.Add(this.button5);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.button4);
			this.Controls.Add(this.groupBox2);
			this.Controls.Add(this.label3);
			this.Controls.Add(this.cmbType);
			this.Controls.Add(this.button2);
			this.Name = "Score_into";
			this.Text = "成绩录入";
			this.Load += new System.EventHandler(this.Score_into_Load);
			this.groupBox1.ResumeLayout(false);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			this.ResumeLayout(false);

		}
		#endregion

		private void Score_into_Load(object sender, System.EventArgs e)
		{
			dataGrid1.SetDataBinding(mydataset,"score");
			textBox1.DataBindings.Add("text",mydataset,"score.学号");
			txtscore.DataBindings.Add("text",mydataset,"score.成绩");
			textBox2.DataBindings.Add("text",mydataset,"score.课程编号");
			//cmbType
			cmbType.DataBindings.Add("text",mydataset,"score.学期");


			bManager = this.BindingContext[mydataset,"score"];
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			try
			{
				DataTable dt = mydataset.Tables["score"];			
				DataRow newRow = dt.NewRow();
				newRow["学号"] = textBox1.Text.Trim();			
				newRow["课程编号"] = textBox2.Text.Trim();
				newRow["成绩"] = txtscore.Text.Trim();
				newRow["学期"] = cmbType.Text.Trim();	
				dt.Rows.Add(newRow);
				thisAdapter.Update(mydataset,"score");
				dt.AcceptChanges();
				MessageBox.Show("你的信息已经被成功的保存到数据库","恭喜");
				
			}
			catch(Exception e1)
			{
				//					MessageBox.Show("数据库'用户名'被占用,本窗体将关闭","出错");					
				MessageBox.Show(e1.Message);
				this.Close();				
				return;
			}
		}

		private void groupBox1_Enter(object sender, System.EventArgs e)
		{
		
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			bManager.Position +=1;
		}

		private void button3_Click(object sender, System.EventArgs e)
		{
			bManager.Position -=1;
		}

		private void button4_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		

		private void button5_Click(object sender, System.EventArgs e)
		{
			if(txtscore.Text == "")
			{
				MessageBox.Show("请认真操作,“错误”");
			}
			else
			{
				try
				{
					SqlConnection thisConnection=new SqlConnection("integrated security=SSPI;data source=.;persist security info=False;initial catalog=xxgcx");
					thisAdapter = new SqlDataAdapter("update score set Test_Id='"+this.textBox2.Text.Trim()+"',Scores='"+this.txtscore.Text.Trim()+"' ,Student_Xq='"+this.cmbType.Text.Trim()+"'where xh = '"+this.textBox1.Text.Trim()+"'",thisConnection);
					SqlCommandBuilder thisBuilder=new SqlCommandBuilder(thisAdapter);
//					DataSet ds = new DataSet();			
					thisAdapter.Fill(mydataset,"score");
					MessageBox.Show("恭喜 ,修改成功");
					dataGrid1.SetDataBinding(mydataset,"score");
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
			}
		}

		private void button6_Click_1(object sender, System.EventArgs e)
		{
			DialogResult result = MessageBox.Show("你是否真的要删除该项","注意",MessageBoxButtons.YesNo,MessageBoxIcon.Stop);
			if(result == DialogResult.Yes)
			{
				try
				{	
					
					DataTable dataTable = mydataset.Tables["score"];					
					int c = dataGrid1.CurrentRowIndex;
					dataTable.Rows[c].Delete();
					int nRows = thisAdapter.Update(mydataset,"score");
					mydataset.AcceptChanges();
					dataGrid1.SetDataBinding(mydataset,"score");	
				}
				catch(Exception e1)
				{
					MessageBox.Show(e1.Message);
				}
			}
			
		}
	}
}

⌨️ 快捷键说明

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