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

📄 fteainfo.cs

📁 简单的教师录入成绩系统
💻 CS
📖 第 1 页 / 共 3 页
字号:
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(720, 533);
			this.Controls.Add(this.textBox11);
			this.Controls.Add(this.label11);
			this.Controls.Add(this.textBox10);
			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.label10);
			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.groupBox1);
			this.Controls.Add(this.dataGrid1);
			this.Controls.Add(this.toolBar1);
			this.Name = "Form3";
			this.Text = "教师信息";
			this.Load += new System.EventHandler(this.Form3_Load);
			((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
			((System.ComponentModel.ISupportInitialize)(this.dataSet31)).EndInit();
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void Form3_Load(object sender, System.EventArgs e)
		{
			this.myConnection = new SqlConnection(connectionString);
			this.da = new SqlDataAdapter(this.StrSQL,this.myConnection);
			this.ds.Clear();
			this.da.Fill(ds,tempTableName);
			this.myTable = ds.Tables[0];
			this.Set(true);
			this.dataGrid1.Enabled = false;
			try
			{
				this.sqlDataAdapter1.SelectCommand.Parameters[0].Value = "%";
			}
			catch(Exception ex)
			{
				MessageBox.Show(ex.Message);
			}

			this.sqlDataAdapter1.SelectCommand.Parameters[1].Value = "%";
			this.sqlDataAdapter1.SelectCommand.Parameters[2].Value = "%";
			
			this.sqlDataAdapter1.Fill(this.dataSet31);
			this.cmOrders=(CurrencyManager) BindingContext[this.dataSet31,"教师基本信息"];
			this.textBox11.Enabled = false;
			this.textbox_change();
		}

		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.Close();
			}

			if(e.Button == this.toolBarButton7)
			{
				this.textBox5.Focus();
				cmOrders.AddNew();//新增一条记录
				
				
				this.Set(false);
	
				

			}
			if(e.Button == this.toolBarButton8)
			{
				SetModifyMode(true);
				this.Set(false);
			}
			if(e.Button == this.toolBarButton9)
			{
				bool canSubmit;
				canSubmit=this.CheckNotNull();
				if(canSubmit==false)//有非空值字段为空,不允许提交
				{
					return;
				}
				cmOrders.EndCurrentEdit();
				this.Set(true);
				if(dataSet31.GetChanges()!=null)
				{
					string ap ;
					ap = this.textBox6.Text;
					
						try
						{
							this.sqlDataAdapter1.Update(dataSet31);
							SetModifyMode(false);
						}
						catch(Exception express)
						{
							MessageBox.Show(express.ToString(),"提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
							dataSet31.RejectChanges();
						}
					
					
				}
				this.SetModifyMode(false);
				
				this.textbox_change();
				return;
			}
			if(e.Button == this.toolBarButton10)
			{
				this.Set(true);
				DialogResult result=MessageBox.Show("确认删除?","删除数据",MessageBoxButtons.OKCancel);
				if(result==DialogResult.OK)
					if(cmOrders.Count>0)//立即从数据集中删除
					{
						cmOrders.RemoveAt(cmOrders.Position);						
						this.sqlDataAdapter1.Update(dataSet31);
					}
					else
						MessageBox.Show("表中为空,已无可删除数据","提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
				this.textbox_change();
			}
		
			
			
		
		}

		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.dataSet31.Clear();//刷新数据
			this.sqlDataAdapter1.Fill(this.dataSet31);
		}
		
		
		//------------供窗体重载,检查非空字段-----------------
		protected virtual bool CheckNotNull()
		{
			return(true);
		}
		
		protected  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;
			this.textBox10.Enabled =!bln;
			
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			for (int i=0;i<myTable.Rows.Count;i++)
			{
				this.myRow = myTable.Rows[i];
				//只有当输入的用户名和密码同时对应上数据库中记录时,才能通过校验
				if (myRow[0].ToString().Trim()==this.textBox1.Text.ToString().Trim() && myRow[7].ToString().Trim()==this.textBox2.Text.ToString().Trim())
				{					
					
					
					this.Close();//关闭窗体

					return;
				}
			}
			MessageBox.Show( "您输入的用户号或密码不正确!");
			return;
		
		
			
		}
		private void textbox_change()
		{
			
			int count=this.BindingContext[this.dataSet31,"教师基本信息"].Count;
			this.textBox11.Text= count+"条记录";  
		}

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

		
	}
}

⌨️ 快捷键说明

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