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

📄 scyg.cs

📁 这是本人学习语言来第一次写的程序
💻 CS
📖 第 1 页 / 共 3 页
字号:
				this.oleDbDataAdapter1.Fill(this.dataSet21,"ygxxb");
				this.oleDbConnection1.Close();
			}
			catch(Exception Exc)
			{
				MessageBox.Show(Exc.Message);
				this.oleDbConnection1.Close();
			}
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			string ComStr="";
			try
			{
				System.Data.OleDb.OleDbCommand MySelect = this.oleDbConnection1.CreateCommand();
				if( this.textBox1.Text != "")
				{
					ComStr="SELECT * FROM ygxxb WHERE 用户名='"+this.textBox1.Text+"'";
				}
				else
				{
					if(this.textBox2.Text != "")
					{
						if(ComStr == "")
						{
							ComStr="SELECT * FROM ygxxb WHERE 姓名='"+this.textBox2.Text+"'";
						}
						else
						{
							ComStr+=" AND 姓名='"+this.textBox2.Text+"'";
						}
					}
					if(this.textBox3.Text != "")
					{
						if(ComStr == "")
						{
							ComStr="SELECT * FROM ygxxb WHERE 手机='"+this.textBox3.Text+"'";
						}
						else
						{
							ComStr+=" AND 手机='"+this.textBox3.Text+"'";
						}
					}
					if(ComStr=="")
					{
						MessageBox.Show("无查询条件,默认查找所有记录.","查找提示: ",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
						ComStr="SELECT * FROM ygxxb";
					}
				}
				MySelect.CommandText=ComStr;
				this.oleDbDataAdapter1.SelectCommand=MySelect;
				this.dataSet21.Clear();
				this.oleDbConnection1.Open();
				this.oleDbDataAdapter1.Fill(dataSet21,"ygxxb");
				this.oleDbConnection1.Close();
			}
			catch(Exception Exc)
			{
				MessageBox.Show(Exc.Message);
				this.oleDbConnection1.Close();
			}
		}

		private void button2_Click(object sender, System.EventArgs e)
		{
			try
			{
				int ReN = this.dataGrid1.CurrentRowIndex;
				if(ReN == -1)
				{
					MessageBox.Show("当前没有记录可以删除!!!","删除提示:",MessageBoxButtons.OK,MessageBoxIcon.Error);
				}
				else
				{
					string YHM=dataSet21.Tables["ygxxb"].Rows[ReN]["用户名"].ToString();
					System.Data.OleDb.OleDbCommand MyDel=this.oleDbConnection1.CreateCommand();
					MyDel.CommandText="DELETE * FROM ygxxb WHERE 用户名='"+YHM+"'";
					this.oleDbDataAdapter1.DeleteCommand=MyDel;
					if(MessageBox.Show("删除是不可恢复的,真的要删除吗?","删除提示:",MessageBoxButtons.YesNo,MessageBoxIcon.Exclamation) == DialogResult.Yes)
					{
						this.oleDbConnection1.Open();
						MyDel.ExecuteNonQuery();
						this.oleDbConnection1.Close();
						button3_Click(null,null);
					}
				}
			}
			catch(Exception Exc)
			{
				MessageBox.Show(Exc.Message);
				this.oleDbConnection1.Close();
			}
		}

		private void scyg_Load(object sender, System.EventArgs e)
		{
			this.textBox1.Focus();
		}

		private void textBox1_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			switch((int)e.KeyCode)
			{
				case 27:
					this.Close();
					break;
				case 13:
					if(this.button1.Focused || this.textBox1.Focused || this.textBox2.Focused || this.textBox3.Focused)
					{
						 button1_Click(null,null);
					}
					if(this.button2.Focused)
					{
						 button2_Click(null,null);
					}
					if(this.button3.Focused)
					{
						button3_Click(null,null);
					}
					if(this.button4.Focused)
					{
						this.Close();
					}
					break;
				case 38:
				case 37:
					if(this.textBox3.Focused)
					{
						this.textBox2.Focus();
					}
					else
					{
						if(this.textBox2.Focused)
						{
							this.textBox1.Focus();
						}
						else
						{
								if(this.textBox1.Focused)
								{
									this.textBox3.Focus();
								}
						}
					}
					break;
				case 40:
				case 39:
					if(this.textBox1.Focused)
					{
						this.textBox2.Focus();
					}
					else
					{
						if(this.textBox2.Focused)
						{ 
							this.textBox3.Focus();
						}
						else
						{
							if(this.textBox3.Focused)
							{
								this.textBox1.Focus();
							}
						}
					}
					break;
			}
		}

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

		private void button4_KeyDown(object sender, System.Windows.Forms.KeyEventArgs e)
		{
			textBox1_KeyDown(null,null);
		}

		private void textBox3_TextChanged(object sender, System.EventArgs e)
		{
			string s="";
			for(int i=0;i<textBox3.Text.Length;i++)
				if(Char.IsDigit(textBox3.Text[i])==true)
					s=s+textBox3.Text[i].ToString();
			textBox3.Text=s;
			textBox3.SelectionStart=textBox3.Text.Length;
		}

		private void dataGrid1_DoubleClick(object sender, System.EventArgs e)
		{
			button2_Click(null,null);
		}
	}
}

⌨️ 快捷键说明

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