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

📄 frmtongxin.cs

📁 毕业生管理系统:分为六个模块:身份验证模块、毕业生资料模块,考试成绩录入模块、通信录及数据输出与系统设置模块、毕业生成绩统计模块、数据库维护模块。
💻 CS
📖 第 1 页 / 共 3 页
字号:
			if(myUser.isPublicUser == false)
			{
				this.btnAgain.Enabled=false;this.btnDel.Enabled=false;
				this.btnIns.Enabled=false;this.btnUpdata.Enabled=false;
			}
			else
			{
				this.btnAgain.Enabled=true;this.btnDel.Enabled=true;
				this.btnIns.Enabled=true;this.btnUpdata.Enabled=true;
			}
		}

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

		private void btnPrint_Click(object sender, System.EventArgs e)
		{
			if(this.printDialog1.ShowDialog()==DialogResult.OK )
			{
				this.pdocOrderDetails.Print();
			}
		}

		private void pdocOrderDetails_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
		{
			Font objFont = new Font("Tahoma",11,FontStyle.Regular);
			Brush objBrush = Brushes.Black;
			Pen objPen=new Pen(objBrush);
			objPen.Width=2;

			int nLeft=this.pageSetupDialog1.PageSettings.Margins.Left;
			int nTop=this.pageSetupDialog1.PageSettings.Margins.Top;
			int nWidth=this.pageSetupDialog1.PageSettings.PaperSize.Width-(this.pageSetupDialog1.PageSettings.Margins.Left +this.pageSetupDialog1.PageSettings.Margins.Right );
			int nHeight=this.pageSetupDialog1.PageSettings.PaperSize.Height -(this.pageSetupDialog1.PageSettings.Margins.Top  +this.pageSetupDialog1.PageSettings.Margins.Bottom  );
			
			e.Graphics.DrawLine(objPen,nLeft,nTop,nLeft+nWidth,nTop);
			e.Graphics.DrawLine(objPen,nLeft,nTop+nHeight,nLeft+nWidth,nTop+nHeight);
			e.Graphics.DrawLine(objPen,nLeft,nTop,nLeft,nTop+nHeight);
			e.Graphics.DrawLine(objPen,nLeft+nWidth,nTop,nLeft+nWidth,nTop+nHeight);	
			//设置标题以及信息的高度
			e.Graphics.DrawString("通信录",new Font("Garamond",20,FontStyle.Bold),objBrush,nLeft+250,nTop+10);
			e.Graphics.DrawString("姓名",objFont,objBrush,nLeft+45,nTop+60);
			e.Graphics.DrawString("年龄",objFont,objBrush,nLeft+120,nTop+60);
			e.Graphics.DrawString("籍贯",objFont,objBrush,nLeft+180,nTop+60);
			e.Graphics.DrawString("QQ",objFont,objBrush,nLeft+280,nTop+60);
			e.Graphics.DrawString("邮政编码",objFont,objBrush,nLeft+360,nTop+60);
			e.Graphics.DrawString("联系电话",objFont,objBrush,nLeft+480,nTop+60);
			
			try
			{
				string strConnection="Provider=Microsoft.Jet.OLEDB.4.0;";
				strConnection+=@"Data Source=Student.mdb";
				objSqlConn=new OleDbConnection(strConnection);
				objSqlConn.Open();
				OleDbCommand objSqlCommand = new OleDbCommand("Select * from Tongxuelu",objSqlConn);
				objOleDbDataReader = objSqlCommand.ExecuteReader();
				
				int nLine=1;
				while(objOleDbDataReader.Read())
				{
					//设置信息内容的高度
					e.Graphics.DrawString(objOleDbDataReader["姓名"].ToString(),objFont,objBrush,nLeft+45,nTop+60+nLine*30);
					e.Graphics.DrawString(objOleDbDataReader["年龄"].ToString(),objFont,objBrush,nLeft+120,nTop+60+nLine*30);
					e.Graphics.DrawString(objOleDbDataReader["籍贯"].ToString(),objFont,objBrush,nLeft+180,nTop+60+nLine*30);
					e.Graphics.DrawString(objOleDbDataReader["QQ"].ToString(),objFont,objBrush,nLeft+260,nTop+60+nLine*30);
					e.Graphics.DrawString(objOleDbDataReader["邮政编码"].ToString(),objFont,objBrush,nLeft+370,nTop+60+nLine*30);
					e.Graphics.DrawString(objOleDbDataReader["联系电话"].ToString(),objFont,objBrush,nLeft+480,nTop+60+nLine*30);
					nLine++;
				}
			}
			catch(OleDbException ex)
			{
				MessageBox.Show(ex.Message);
			}
		}

		private void btnSetup_Click_1(object sender, System.EventArgs e)
		{
			this.pageSetupDialog1.ShowDialog();
		}

		private void btnPrintPrev_Click(object sender, System.EventArgs e)
		{
			this.printPreviewDialog1.ShowDialog();
		}

		private void dbgBooksDt_Click(object sender, System.EventArgs e)
		{
			//点对点显示
			this.txtname.Text=(string)dbgBooksDt[dbgBooksDt.CurrentCell.RowNumber,0];
			this.txtAge.Text=(string)dbgBooksDt[dbgBooksDt.CurrentCell.RowNumber,1].ToString();
			this.txtJiguan.Text=(string)dbgBooksDt[dbgBooksDt.CurrentCell.RowNumber,2].ToString();
			this.txtQQ.Text=(string)dbgBooksDt[dbgBooksDt.CurrentCell.RowNumber,3].ToString();
			this.txtTel.Text=(string)dbgBooksDt[dbgBooksDt.CurrentCell.RowNumber,4].ToString();
			this.txtYouzheng.Text=(string)dbgBooksDt[dbgBooksDt.CurrentCell.RowNumber,5].ToString();
			this.txtEmail.Text=(string)dbgBooksDt[dbgBooksDt.CurrentCell.RowNumber,6].ToString();
			this.txtAdd.Text=(string)dbgBooksDt[dbgBooksDt.CurrentCell.RowNumber,7].ToString();
		}
		private void btnAgain_Click(object sender, System.EventArgs e)
		{
			this.txtname.Clear();
			this.txtAge.Clear();this.txtJiguan.Clear();
			this.txtQQ.Clear();this.txtTel.Clear();
			this.txtYouzheng.Clear();this.txtEmail.Clear();
			this.txtAdd.Clear();
			this.txtname.Focus();
		}

		private void btnUpdata_Click(object sender, System.EventArgs e)
		{
			int inRow =dbgBooksDt.CurrentRowIndex;
			//更新命令
			updCmd = "update Tongxuelu set 姓名 ='"+this.txtname.Text+"',年龄='"+this.txtAge.Text+"',籍贯='"+this.txtJiguan.Text+"',QQ='"+this.txtQQ.Text+"',联系电话='"+this.txtTel.Text+"',邮政编码='"+this.txtYouzheng.Text+"',Email='"+this.txtEmail.Text+"',地址='"+this.txtAdd.Text+"' where 姓名='"+this.dbgBooksDt[inRow,0].ToString()+"'";

			//初始化命令对象
			objOleDbCommand = new OleDbCommand(updCmd,objSqlConn);
			try
			{
				if(this.txtname.Text!=String.Empty&&this.txtAge.Text!=string.Empty&&this.txtJiguan.Text!=string.Empty&&this.txtQQ.Text!=string.Empty&&this.txtTel.Text!=string.Empty&&this.txtYouzheng.Text!=string.Empty&&this.txtEmail.Text!=string.Empty&&this.txtAdd.Text!=string.Empty)

				{
					if(ValidateFields())
					{
						//打开连接
						objSqlConn.Open();
						//执行更新语句
						objOleDbCommand.ExecuteNonQuery();
						objSqlDataAdapter.Update(objDataSet,"Tongxuelu");
						MessageBox.Show("已成功更新记录!");
						this.txtname.Clear();
						this.txtAge.Clear();
						this.txtJiguan.Clear();
						this.txtQQ.Clear();
						this.txtTel.Clear();
						this.txtYouzheng.Clear();
						this.txtEmail.Clear();
						this.txtAdd.Clear();
						this.dbgBooksDt.Update();
						this.txtname.Focus();
						objSqlConn.Close();
						ShowDataGird();
					}
				}	
				else
					MessageBox.Show("无信息可以更新!!");
			}
			catch(OleDbException ex)
			{
				MessageBox.Show(ex.Message);
				objSqlConn.Close();
			}
		
		}

		private void btnDel_Click(object sender, System.EventArgs e)
		{
			int inRow =dbgBooksDt.CurrentRowIndex;
			//删除命令
			delCmd = "delete from Tongxuelu where 姓名='"+this.dbgBooksDt[inRow,1].ToString()+"'";			
			//初始化命令对象
			objOleDbCommand = new OleDbCommand(delCmd,objSqlConn);
			
			try
			{
				//初始化 DialogResult
				DialogResult objDialogResult = MessageBox.Show("确定要删除当前记录吗?","确定",MessageBoxButtons.YesNo);
				if(this.txtname.Text!=String.Empty&&this.txtAge.Text!=string.Empty&&this.txtJiguan.Text!=string.Empty&&this.txtQQ.Text!=string.Empty&&this.txtTel.Text!=string.Empty&&this.txtYouzheng.Text!=string.Empty&&this.txtEmail.Text!=string.Empty&&this.txtAdd.Text!=string.Empty)
				{
					//确定用户响应
					if(objDialogResult.Equals(DialogResult.Yes))
					{
						//打开连接
						objSqlConn.Open();
						objOleDbCommand.ExecuteNonQuery();
						objSqlDataAdapter.Update(objDataSet,"Tongxuelu");
						MessageBox.Show("已经删除记录");
						this.txtname.Clear();
						this.txtAge.Clear();
						this.txtJiguan.Clear();
						this.txtQQ.Clear();
						this.txtTel.Clear();
						this.txtYouzheng.Clear();
						this.txtEmail.Clear();
						this.txtAdd.Clear();
						this.dbgBooksDt.Update();
						this.txtname.Focus();
						ShowDataGird();
					}
				}
				else
					MessageBox.Show("无信息可以删除!");
			}
			catch(OleDbException ex)
			{
				MessageBox.Show(ex.Message);
			}
			finally
			{
				//关闭连接
				objSqlConn.Close();
			}
		
		}

		private void btnIns_Click(object sender, System.EventArgs e)
		{
			string insCmd="insert into Tongxuelu values(@姓名,@年龄,@籍贯,@QQ,@联系电话,@邮政编码,@Email,@地址)";
			this.objSqlDataAdapter.InsertCommand=new OleDbCommand(insCmd,this.objSqlConn);
			objParam=objSqlDataAdapter.InsertCommand.Parameters.Add(new System.Data.OleDb.OleDbParameter("@姓名",System.Data.OleDb.OleDbType.VarChar,50));
			objParam.SourceColumn="姓名";
			objParam.SourceVersion=DataRowVersion.Current;

			objParam=objSqlDataAdapter.InsertCommand.Parameters.Add(new System.Data.OleDb.OleDbParameter("@年龄",System.Data.OleDb.OleDbType.VarChar,50));
			objParam.SourceColumn="年龄";
			objParam.SourceVersion=DataRowVersion.Current;

			objParam=objSqlDataAdapter.InsertCommand.Parameters.Add(new System.Data.OleDb.OleDbParameter("@籍贯",System.Data.OleDb.OleDbType.VarChar,50));
			objParam.SourceColumn="籍贯";
			objParam.SourceVersion=DataRowVersion.Current;

			objParam=objSqlDataAdapter.InsertCommand.Parameters.Add(new System.Data.OleDb.OleDbParameter("@QQ",System.Data.OleDb.OleDbType.Decimal,9));
			objParam.SourceColumn="QQ";
			objParam.SourceVersion=DataRowVersion.Current;

			objParam=objSqlDataAdapter.InsertCommand.Parameters.Add(new System.Data.OleDb.OleDbParameter("@联系电话",System.Data.OleDb.OleDbType.Integer,4));
			objParam.SourceColumn="联系电话";
			objParam.SourceVersion=DataRowVersion.Current;

			objParam=objSqlDataAdapter.InsertCommand.Parameters.Add(new System.Data.OleDb.OleDbParameter("@邮政编码",System.Data.OleDb.OleDbType.VarChar,50));
			objParam.SourceColumn="邮政编码";
			objParam.SourceVersion=DataRowVersion.Current;

			objParam=objSqlDataAdapter.InsertCommand.Parameters.Add(new System.Data.OleDb.OleDbParameter("@Email",System.Data.OleDb.OleDbType.VarChar,50));
			objParam.SourceColumn="Email";
			objParam.SourceVersion=DataRowVersion.Current;
		
			objParam=objSqlDataAdapter.InsertCommand.Parameters.Add(new System.Data.OleDb.OleDbParameter("@地址",System.Data.OleDb.OleDbType.VarChar,50));
			objParam.SourceColumn="地址";
			objParam.SourceVersion=DataRowVersion.Current;

			try
			{
				if(this.txtname.Text!=String.Empty&&this.txtAge.Text!=string.Empty&&this.txtJiguan.Text!=string.Empty&&this.txtQQ.Text!=string.Empty&&this.txtTel.Text!=string.Empty&&this.txtYouzheng.Text!=string.Empty&&this.txtEmail.Text!=string.Empty&&this.txtAdd.Text!=string.Empty)
					
				{
					if(ValidateFields())
					{
						DataRow objDataRow = objDataSet.Tables["Tongxuelu"].NewRow();
						objDataRow["姓名"] = this.txtname.Text;
						objDataRow["年龄"] = this.txtAge.Text;
						objDataRow["籍贯"] = this.txtJiguan.Text;
						objDataRow["QQ"] = this.txtQQ.Text;
						objDataRow["联系电话"] = this.txtTel.Text;
						objDataRow["邮政编码"] = this.txtYouzheng.Text;
						objDataRow["Email"] = this.txtEmail.Text;
						objDataRow["地址"] = this.txtAdd.Text;
						objDataSet.Tables["Tongxuelu"].Rows.Add(objDataRow);
						objSqlDataAdapter.Update(objDataSet,"Tongxuelu");
						MessageBox.Show("记录已经成功录入!");
						
						this.txtname.Clear();
						this.txtAge.Clear();
						this.txtJiguan.Clear();
						this.txtQQ.Clear();
						this.txtTel.Clear();
						this.txtYouzheng.Clear();
						this.txtEmail.Clear();
						this.txtAdd.Clear();
						this.txtname.Focus();
						DialogResult objDialogResult=MessageBox.Show("是否回到主界面继续操作?","确认",MessageBoxButtons.YesNo,MessageBoxIcon.Question);
						if(objDialogResult==DialogResult.Yes)
						{
							this.Close();
						}
						else
						{
							return;
						}
					}
				}
				else
					MessageBox.Show("请提供完整的详细信息!");
			}
				
			catch(OleDbException ex)
			{
				MessageBox.Show(ex.Message.ToString());

			}
				
			catch(Exception genEx)
			{
				MessageBox.Show(genEx.Message.ToString());
			}
		
		}

		private void textBox1_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			if(this.comboBox1.SelectedIndex==1)              
			{
				objSqlConn.Open(); this.dbgBooksDt.DataSource=null;//清空数据源
				objSqlDataAdapter=new OleDbDataAdapter();
				objSqlDataAdapter.SelectCommand=new OleDbCommand("select * from Tongxuelu where 姓名 like '%"+this.textBox1.Text+"%'",objSqlConn);
				objDataSet=new DataSet();
				objSqlDataAdapter.Fill(objDataSet,"Tongxuelu");
				this.dbgBooksDt.SetDataBinding(objDataSet,"Tongxuelu");
				this.objSqlConn.Close();
			}
			else if(this.comboBox1.SelectedIndex==2)              
			{
				objSqlConn.Open(); this.dbgBooksDt.DataSource=null;//清空数据源
				objSqlDataAdapter=new OleDbDataAdapter();
				objSqlDataAdapter.SelectCommand=new OleDbCommand("select * from Tongxuelu where 年龄 like '%"+this.textBox1.Text+"%'",objSqlConn);
				objDataSet=new DataSet();
				objSqlDataAdapter.Fill(objDataSet,"Tongxuelu");
				this.dbgBooksDt.SetDataBinding(objDataSet,"Tongxuelu");
				this.objSqlConn.Close();
			}
			else if(this.comboBox1.SelectedIndex==3)              
			{
				objSqlConn.Open(); this.dbgBooksDt.DataSource=null;//清空数据源
				objSqlDataAdapter=new OleDbDataAdapter();
				objSqlDataAdapter.SelectCommand=new OleDbCommand("select * from Tongxuelu where 籍贯 like '%"+this.textBox1.Text+"%'",objSqlConn);
				objDataSet=new DataSet();
				objSqlDataAdapter.Fill(objDataSet,"Tongxuelu");
				this.dbgBooksDt.SetDataBinding(objDataSet,"Tongxuelu");
				this.objSqlConn.Close();
			}
			else if(this.comboBox1.SelectedIndex==4)              
			{
				objSqlConn.Open(); this.dbgBooksDt.DataSource=null;//清空数据源
				objSqlDataAdapter=new OleDbDataAdapter();
				objSqlDataAdapter.SelectCommand=new OleDbCommand("select * from Tongxuelu where 邮政编码 like '%"+this.textBox1.Text+"%'",objSqlConn);
				objDataSet=new DataSet();
				objSqlDataAdapter.Fill(objDataSet,"Tongxuelu");
				this.dbgBooksDt.SetDataBinding(objDataSet,"Tongxuelu");
				this.objSqlConn.Close();
			}
			else{}
		}

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

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

⌨️ 快捷键说明

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