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

📄 courseinfo.cs

📁 简单的教师录入成绩系统
💻 CS
📖 第 1 页 / 共 2 页
字号:
			// textBox9
			// 
			this.textBox9.DataBindings.Add(new System.Windows.Forms.Binding("Text", this.dataSet11, "课程基本信息.学时"));
			this.textBox9.Location = new System.Drawing.Point(416, 480);
			this.textBox9.Name = "textBox9";
			this.textBox9.TabIndex = 8;
			this.textBox9.Text = "";
			// 
			// label4
			// 
			this.label4.Location = new System.Drawing.Point(56, 368);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(64, 23);
			this.label4.TabIndex = 9;
			this.label4.Text = "课程编号";
			// 
			// label5
			// 
			this.label5.Location = new System.Drawing.Point(48, 416);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(64, 23);
			this.label5.TabIndex = 10;
			this.label5.Text = "课程名称";
			// 
			// label6
			// 
			this.label6.Location = new System.Drawing.Point(48, 472);
			this.label6.Name = "label6";
			this.label6.Size = new System.Drawing.Size(64, 23);
			this.label6.TabIndex = 11;
			this.label6.Text = "开课教师";
			// 
			// label7
			// 
			this.label7.Location = new System.Drawing.Point(304, 368);
			this.label7.Name = "label7";
			this.label7.Size = new System.Drawing.Size(48, 23);
			this.label7.TabIndex = 12;
			this.label7.Text = "学分";
			// 
			// label8
			// 
			this.label8.Location = new System.Drawing.Point(296, 424);
			this.label8.Name = "label8";
			this.label8.Size = new System.Drawing.Size(56, 23);
			this.label8.TabIndex = 13;
			this.label8.Text = "开课系别";
			// 
			// label9
			// 
			this.label9.Location = new System.Drawing.Point(304, 480);
			this.label9.Name = "label9";
			this.label9.Size = new System.Drawing.Size(56, 23);
			this.label9.TabIndex = 14;
			this.label9.Text = "学时";
			// 
			// sqlDataAdapter1
			// 
			this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
			this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
			this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
			this.sqlDataAdapter1.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.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
			// 
			// 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_开课教师 OR @Original_开课教师 IS NULL AND 开课教师 IS NULL) AND (开课系别 = @Original_开课系别 OR @Original_开课系别 IS NULL AND 开课系别 IS NULL) AND (课程名称 = @Original_课程名称 OR @Original_课程名称 IS NULL AND 课程名称 IS NULL)";
			this.sqlDeleteCommand1.Connection = this.sqlConnection1;
			this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_课程编号", System.Data.SqlDbType.VarChar, 10, 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.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, 10, 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, 10, 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, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "课程名称", System.Data.DataRowVersion.Original, null));
			// 
			// sqlConnection1
			// 
			this.sqlConnection1.ConnectionString = "workstation id=3366359E777E4EE;packet size=4096;integrated security=SSPI;data sou" +
				"rce=3366359E777E4EE;persist security info=False;initial catalog=jiaoshi";
			// 
			// 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, 10, "课程名称"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@课程编号", System.Data.SqlDbType.VarChar, 10, "课程编号"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@开课教师", System.Data.SqlDbType.VarChar, 10, "开课教师"));
			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.VarChar, 10, "开课系别"));
			this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@学时", System.Data.SqlDbType.Int, 4, "学时"));
			// 
			// sqlSelectCommand1
			// 
			this.sqlSelectCommand1.CommandText = "SELECT 课程名称, 课程编号, 开课教师, 学分, 开课系别, 学时 FROM 课程基本信息 WHERE (课程编号 LIKE @a) AND (课程名称 " +
				"LIKE @b) AND (开课教师 LIKE @c)";
			this.sqlSelectCommand1.Connection = this.sqlConnection1;
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@a", System.Data.SqlDbType.VarChar, 10, "课程编号"));
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@b", System.Data.SqlDbType.VarChar, 10, "课程名称"));
			this.sqlSelectCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@c", System.Data.SqlDbType.VarChar, 10, "开课教师"));
			// 
			// 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_开课教师 OR @Original_开课教师 IS NULL AND 开课教师 IS NULL) AND (开课系别 = @Original_开课系别 OR @Original_开课系别 IS NULL AND 开课系别 IS NULL) AND (课程名称 = @Original_课程名称 OR @Original_课程名称 IS NULL AND 课程名称 IS NULL); SELECT 课程名称, 课程编号, 开课教师, 学分, 开课系别, 学时 FROM 课程基本信息 WHERE (课程编号 = @课程编号)";
			this.sqlUpdateCommand1.Connection = this.sqlConnection1;
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@课程名称", System.Data.SqlDbType.VarChar, 10, "课程名称"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@课程编号", System.Data.SqlDbType.VarChar, 10, "课程编号"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@开课教师", System.Data.SqlDbType.VarChar, 10, "开课教师"));
			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.VarChar, 10, "开课系别"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@学时", System.Data.SqlDbType.Int, 4, "学时"));
			this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_课程编号", System.Data.SqlDbType.VarChar, 10, 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.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, 10, 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, 10, 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, 10, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "课程名称", System.Data.DataRowVersion.Original, null));
			// 
			// CourseInfo
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(640, 573);
			this.Controls.Add(this.label9);
			this.Controls.Add(this.label8);
			this.Controls.Add(this.label7);
			this.Controls.Add(this.label6);
			this.Controls.Add(this.label5);
			this.Controls.Add(this.label4);
			this.Controls.Add(this.textBox9);
			this.Controls.Add(this.textBox8);
			this.Controls.Add(this.textBox7);
			this.Controls.Add(this.textBox6);
			this.Controls.Add(this.textBox5);
			this.Controls.Add(this.textBox4);
			this.Controls.Add(this.groupBox1);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.toolBar1);
			this.Name = "CourseInfo";
			this.Text = "CourseInfo";
			this.Load += new System.EventHandler(this.CourseInfo_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void toolBar1_ButtonClick(object sender, System.Windows.Forms.ToolBarButtonClickEventArgs e)
		{
			if(e.Button == this.toolBarButton1)
			{
				try
				{
					this.dataGrid1.UnSelect(cmOrders.Position); //取消原选中的行
					cmOrders.Position = 0;
					this.dataGrid1.Select(cmOrders.Position); //选中当前行
					this.dataGrid1.CurrentRowIndex = cmOrders.Position; //移动表头指示图标
					return;
				}
				catch(Exception ex)
				{
					MessageBox.Show(ex.Message);
				}
			}
			if(e.Button == this.toolBarButton2)
			{
				if (cmOrders.Position >= 0)
				{
					this.dataGrid1.UnSelect(cmOrders.Position); 
					cmOrders.Position++;
					this.dataGrid1.Select(cmOrders.Position);      
					this.dataGrid1.CurrentRowIndex = cmOrders.Position; 
				}
				return;
			}
			if(e.Button == this.toolBarButton3)
			{
				if (cmOrders.Position >= 0)
				{
					this.dataGrid1.UnSelect(cmOrders.Position); 
					cmOrders.Position--;
					this.dataGrid1.Select(cmOrders.Position);      
					this.dataGrid1.CurrentRowIndex = cmOrders.Position; 
				}
				return;
			}
			if(e.Button == this.toolBarButton4)
			{
				this.dataGrid1.UnSelect(cmOrders.Position); 
				cmOrders.Position = cmOrders.Count-1;
				this.dataGrid1.Select(cmOrders.Position);       
				this.dataGrid1.CurrentRowIndex = cmOrders.Position; 
				return;
			}
			if(e.Button == this.toolBarButton6)
			{
				this.Set(true);
				DialogResult result=MessageBox.Show("确认删除?","删除数据",MessageBoxButtons.OKCancel);
				if(result==DialogResult.OK)
					if(cmOrders.Count>0)//立即从数据集中删除
					{
						cmOrders.RemoveAt(cmOrders.Position);						
						this.sqlDataAdapter1.Update(dataSet11);
					}
					else
						MessageBox.Show("表中为空,已无可删除数据","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
			}
			if(e.Button == this.toolBarButton7)
			{
				SetModifyMode(true);
				this.Set(false);
			}
			if(e.Button == this.toolBarButton8)
			{
				bool canSubmit;
				canSubmit=this.CheckNotNull();
				if(canSubmit==false)//有非空值字段为空,不允许提交
				{
					return;
				}
				cmOrders.EndCurrentEdit();
				if(dataSet11.GetChanges()!=null)
				{
					try
					{
						this.sqlDataAdapter1.Update(dataSet11);
						SetModifyMode(false);
					}
					catch(Exception express)
					{
						MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
						dataSet11.RejectChanges();
					}
				}
				this.SetModifyMode(false);
				this.Set(true);
				return;
			}
			if(e.Button == this.toolBarButton9)
			{
				textBox4.Focus();
				cmOrders.AddNew();//新增一条记录
				SetDefaultValue();//设置默认值				
				SetModifyMode(true);//设置控件只读等属性
				this.Set(false);
	
				

			}
			if(e.Button == this.toolBarButton10)
			{
				this.Close();
			}
		}
		

		private void CourseInfo_Load(object sender, System.EventArgs e)
		{
			this.Set(true);
			this.dataGrid1.Enabled = false;
			
			this.sqlDataAdapter1.SelectCommand.Parameters[0].Value = "%%";
			this.sqlDataAdapter1.SelectCommand.Parameters[1].Value = "%%";
			this.sqlDataAdapter1.SelectCommand.Parameters[2].Value = "%%";
			try
			{
				sqlDataAdapter1.Fill(dataSet11,"课程基本信息");
//				this.sqlDataAdapter1.Update (this.dataSet11);
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}
			
			
			
			this.cmOrders=(CurrencyManager) BindingContext[dataSet11,"课程基本信息"];
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			this.sqlDataAdapter1.SelectCommand.Parameters[0].Value="%%";
			this.sqlDataAdapter1.SelectCommand.Parameters[1].Value="%%";
			this.sqlDataAdapter1.SelectCommand.Parameters[2].Value="%%";
			if(this.textBox1.Text != "")
			{
				this.sqlDataAdapter1.SelectCommand.Parameters[0].Value="%"+this.textBox1.Text+"%";

			}
			if(this.textBox2.Text != "")
			{
				this.sqlDataAdapter1.SelectCommand.Parameters[1].Value="%"+this.textBox2.Text+"%";

			}
			if(this.textBox3.Text != "")
			{
				this.sqlDataAdapter1.SelectCommand.Parameters[2].Value="%"+this.textBox3.Text+"%";

			}
			this.dataSet11.Clear();//刷新数据
			this.sqlDataAdapter1.Fill(this.dataSet11);
		}
		protected virtual void SetDefaultValue()
		{
			return;
		}
		
		//------------供窗体重载,检查非空字段-----------------
		protected virtual bool CheckNotNull()
		{
			return(true);
		}
		//------------控制各个控件的只读属性-----------
		protected virtual void SetModifyMode(bool blnEdit)
		{
			this.button1.Enabled=!blnEdit;
		}
		protected  void Set(bool bln)
		{
			this.textBox4.Enabled =!bln;
			this.textBox5.Enabled =!bln;
			this.textBox6.Enabled =!bln;
			this.textBox7.Enabled =!bln;
			this.textBox8.Enabled =!bln;
			this.textBox9.Enabled =!bln;
			
		}
		
	}
}

⌨️ 快捷键说明

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