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

📄 teachermessagefrm.cs

📁 用C#开发的教师签到系统 具有基本功能
💻 CS
📖 第 1 页 / 共 4 页
字号:
				this.btnFirst.Enabled=true;
				this.btnLast.Enabled=true;
			}
		}

		private void TeacherMessageFrm_Load(object sender, System.EventArgs e)
		{
			this.myoleDbData.Fill(this.myTeacher);
			this.dataGrid1.Select(0);
			this.btnFirst.Enabled = false;
			this.btnPrevious.Enabled = false;
		}
     	private void btnExit_Click(object sender, System.EventArgs e)
		{
			this.Close();
		}

		private void btnFirs_Click(object sender, System.EventArgs e)
		{
			this.dataGrid1.UnSelect(this.dataGrid1.CurrentRowIndex);
			this.BindingContext[this.myTeacher,"教师信息"].Position = 0;
			this.dataGrid1.Select(this.BindingContext[this.myTeacher,"教师信息"].Position);
			this.ButtonPositonChange();
			this.dataGrid1.CurrentRowIndex=0;		
		}

		private void btnPrevious_Click(object sender, System.EventArgs e)
		{
			this.dataGrid1.UnSelect(this.dataGrid1.CurrentRowIndex);
			this.BindingContext[this.myTeacher,"教师信息"].Position-=1;
            this.dataGrid1.Select(this.BindingContext[this.myTeacher,"教师信息"].Position);
			this.ButtonPositonChange();
			this.dataGrid1.CurrentRowIndex-=1;
		}

		private void btnNext_Click(object sender, System.EventArgs e)
		{
			this.dataGrid1.UnSelect(this.dataGrid1.CurrentRowIndex);
			this.BindingContext[this.myTeacher,"教师信息"].Position+=1;
			this.dataGrid1.Select(this.BindingContext[this.myTeacher,"教师信息"].Position);
			this.ButtonPositonChange();
			this.dataGrid1.CurrentRowIndex+=1;
		
		}

		private void btnLast_Click(object sender, System.EventArgs e)
		{
			this.dataGrid1.UnSelect(this.dataGrid1.CurrentRowIndex);
			this.BindingContext[this.myTeacher,"教师信息"].Position=this.BindingContext[this.myTeacher,"教师信息"].Count-1;
			this.dataGrid1.Select(this.BindingContext[this.myTeacher,"教师信息"].Position);
			this.ButtonPositonChange();
			this.dataGrid1.CurrentRowIndex=this.BindingContext[this.myTeacher,"教师信息"].Count-1;
		}
		private void btnAdd_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.BindingContext[this.myTeacher,"教师信息"].AddNew();
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
			this.ButtonPositonChange();
			this.TextEnableControl(true);
			this.ButtonEnableControl(true);
		}
		public void ErrorHandle(System.Exception E)
		{
			MessageBox.Show(E.ToString());
		}
		private void TextEnableControl(bool valid)
		{
			if(valid)
			{
				this.textId.Enabled = true;
				this.textName.Enabled = true;
				this.textAge.Enabled = true;
				this.comsex.Enabled = true;				
				this.textNation.Enabled = true;
				this.textStatus.Enabled = true;
				this.textDuty.Enabled = true;
				this.combDegree.Enabled = true;
				this.textAddress.Enabled = true;
				this.textTel.Enabled = true;
				//this.chkValid.Enabled=true;
				
			}
			else
			{
				this.textId.Enabled = false;
				this.textName.Enabled = false;
				this.textAge.Enabled = false;
				this.comsex.Enabled = false;				
				this.textNation.Enabled = false;
				this.textStatus.Enabled = false;
				this.textDuty.Enabled = false;
				this.combDegree.Enabled = false;
				this.textAddress.Enabled = false;
				this.textTel.Enabled = false;
				//this.chkValid.Enabled=false;
			}
		}
		private void ButtonEnableControl(bool valid)
		{
			if(valid)
			{
				this.btnCancel.Enabled=true;
				this.btnApply.Enabled=true;
			}
			else
			{
				this.btnCancel.Enabled=false;
				this.btnApply.Enabled=false;
			}
		}

		private void btnDelete_Click(object sender, System.EventArgs e)
		{
			if((this.BindingContext[this.myTeacher,"教师信息"].Count>0)&
				(MessageBox.Show("真的要删除此记录吗","确定删除",MessageBoxButtons.OKCancel,MessageBoxIcon.Question).Equals(DialogResult.OK)))
			{
				try
				{
					int currentPosition=this.BindingContext[this.myTeacher,"教师信息"].Position;
					this.BindingContext[this.myTeacher,"教师信息"].RemoveAt(this.BindingContext[this.myTeacher,"教师信息"].Position);
				}
				catch(System.Exception E)
				{
					this.ErrorHandle(E);
				}
				this.ButtonPositonChange();
			}
			else
				return;
		}

		private void btnModify_Click(object sender, System.EventArgs e)
		{
			this.TextEnableControl(true);
			this.ButtonEnableControl(true);
		}

		private void btnCancel_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.BindingContext[this.myTeacher,"教师信息"].CancelCurrentEdit();
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}			
			//this.DatasetPostionChange();
			this.TextEnableControl(false);
			this.TextEnableControl(false);
			this.ButtonEnableControl(false);
		}

		private void btnApply_Click(object sender, System.EventArgs e)
		{
			try
			{
				this.BindingContext[this.myTeacher,"教师信息"].EndCurrentEdit();
				if(this.myTeacher.HasChanges() ==false)
				{
					MessageBox.Show("对不起:记录未做修改!不需提交","提示",MessageBoxButtons.OK,MessageBoxIcon.Warning);
				}
				else
				{
					this.UpdataDataset();
				}	
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}			
			this.ButtonPositonChange();
			this.TextEnableControl(false);
			this.ButtonEnableControl(false);
		}
		private void UpdataDataset()
		{
			try
			{
				this.oleDbConnection1.Open();
				this.myoleDbData.Update(this.myTeacher);
				MessageBox.Show("数据已提交!","提示:",MessageBoxButtons.OK,MessageBoxIcon.Information);
				this.myTeacher.AcceptChanges();
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
			finally
			{
				this.oleDbConnection1.Close();
			}
		}

		private void btnQuery_Click(object sender, System.EventArgs e)
		{	
			try
			{
				this.oleDbConnection1.Open();
				this.TeacherQuaryDataView.Table = this.myTeacher.Tables["教师信息"];
				this.TeacherQuaryDataView.RowFilter = this.TeacherSercher_Made();
				this.dataGrid2.DataSource = this.TeacherQuaryDataView;
			}
			catch(System.Exception E)
			{
				this.ErrorHandle(E);
			}
			finally
			{
				this.oleDbConnection1.Close();
			}
			if(this.TeacherQuaryDataView.Count == 0)
             MessageBox.Show("没有符合查询条件的记录","没有记录",MessageBoxButtons.OK,MessageBoxIcon.Information);
			this.textBox11.Clear();
			this.textBox12.Clear();
		}
		private string TeacherSercher_Made()
		{
			string searchStr=null;
			bool first=true;

			if(this.textBox11.Text!="")
			{				
				searchStr="教师编号="+"'"+this.textBox11.Text+"'";
				first=false;	
			}
			if(this.textBox12.Text!="")
			{
				if(first)
				{
					searchStr="姓名="+"'"+this.textBox12.Text+"'";
					first=false;
				}
				else
				{
					searchStr=searchStr+"and 姓名="+"'"+this.textBox12.Text+"'";
				}

			}		
			return searchStr;
		}

		private void btnClear_Click(object sender, System.EventArgs e)
		{
			this.textBox12.Clear();
			this.textBox11.Clear();
		}
		private void dataGrid1_Click_1(object sender, System.EventArgs e)
		{
		    this.BindingContext[this.myTeacher,"教师信息"].Position = this.dataGrid1.CurrentRowIndex;
		}
	}
}

⌨️ 快捷键说明

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