c++数据库应用--字典查询系统

#pragma once

namespace jelly2 {

	using namespace System;
	using namespace System::ComponentModel;
	using namespace System::Collections;
	using namespace System::Windows::Forms;
	using namespace System::Data;
	using namespace System::Drawing;
	using namespace System::Data::SqlClient;



	/// <summary>
	/// lgd2 摘要
	/// </summary>
	public ref class lgd2 : public System::Windows::Forms::Form
	{
	public:
		lgd2(void)
		{
			InitializeComponent();
			//
			//TODO: 在此处添加构造函数代码
			//
			 con=gcnew SqlConnection();
      	 con->ConnectionString = L"Data Source=WINDOWS-0UHAKQ2;Initial Catalog=cycd;Integrated Security=True";
		}
	private: System::Windows::Forms::MenuStrip^  menuStrip1;
	public: 
	private: System::Windows::Forms::ToolStrip^  toolStrip1;
	private: System::Windows::Forms::ToolStripMenuItem^  查询ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  查询全部ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripSeparator^  toolStripMenuItem1;
	private: System::Windows::Forms::ToolStripMenuItem^  精确查询ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripSeparator^  toolStripMenuItem2;
	private: System::Windows::Forms::ToolStripMenuItem^  模糊查询ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  操作ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  修改ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripSeparator^  toolStripMenuItem3;
	private: System::Windows::Forms::ToolStripMenuItem^  删除ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripSeparator^  toolStripMenuItem4;
	private: System::Windows::Forms::ToolStripMenuItem^  添加ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripButton^  查询全部;
	private: System::Windows::Forms::ToolStripButton^  精确查询;
	private: System::Windows::Forms::ToolStripButton^  模糊查询;



	private: System::Windows::Forms::ToolStripSeparator^  toolStripSeparator1;
	private: System::Windows::Forms::ToolStripButton^  修改;
	private: System::Windows::Forms::ToolStripButton^  删除;
	private: System::Windows::Forms::ToolStripButton^  添加;



	private: System::Windows::Forms::DataGridView^  dataGridView1;
	private: System::Windows::Forms::TextBox^  textBox1;
	private: System::Windows::Forms::TextBox^  textBox2;
	private: System::Windows::Forms::TextBox^  textBox3;
	private: System::Windows::Forms::TextBox^  textBox4;
	private: System::Windows::Forms::ComboBox^  comboBox1;
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::Label^  label2;
	private: System::Windows::Forms::Label^  label3;
	private: System::Windows::Forms::Label^  label4;
	private: System::Windows::Forms::Label^  label5;
	private: System::Windows::Forms::ToolStripMenuItem^  帮助CToolStripMenuItem;
	private: System::Windows::Forms::ToolStripMenuItem^  联系我们ToolStripMenuItem;
	private: System::Windows::Forms::ToolStripSeparator^  toolStripMenuItem5;
	private: System::Windows::Forms::ToolStripMenuItem^  联系作者ToolStripMenuItem;
	private: System::Windows::Forms::Button^  button2;
	private: System::Windows::Forms::Button^  button3;
	private: System::Windows::Forms::Button^  button4;
	private: System::Windows::Forms::Button^  button5;
	private: System::Windows::Forms::Button^  button6;
	private: System::Windows::Forms::Button^  button7;
	private: System::Windows::Forms::Label^  label6;


			 SqlConnection^ con;

	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~lgd2()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Button^  button1;
	private: System::Data::SqlClient::SqlConnection^  sqlConnection1;
	protected: 

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要
		/// 使用代码编辑器修改此方法的内容。
		/// </summary>
	/
#pragma endregion
	private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {

				 //Data Source=WINDOWS-0UHAKQ2;Initial Catalog=cycd;Integrated Security=True
				 SqlConnection^ con=gcnew SqlConnection();
      	 con->ConnectionString = L"Data Source=WINDOWS-0UHAKQ2;Initial Catalog=cycd;Integrated Security=True";
	 try
	{
	 con->Open();
	 if(con->State==ConnectionState::Open)
	MessageBox::Show("连接成功!");
	}
         catch(Exception^ ex)
	{        MessageBox::Show("连接失败!"+ex);}
	  finally
	{	con->Close();	 }



			 }

private: System::Void 查询全部ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 String^ sql= " select * from cyb";
		MessageBox::Show(sql);
		DataSet^ ds=gcnew DataSet();
		SqlDataAdapter^ ourda = gcnew SqlDataAdapter( sql,con);                           
			try
	{  
	 ourda->Fill(ds,"TXL");//把数据适配器的内容添加到数据集内
	 this->dataGridView1->DataSource=ds->Tables["TXL"];
	 }
		catch(System::Data::SqlClient::SqlException^ ex)
	{MessageBox::Show("数据的异常信息是:"+ex->Errors,"提示信息");}
		 }
private: System::Void 精确查询ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			  String^ sql= " select * from cyb where 成语='"+textBox1->Text+"'or 拼音='"+textBox2->Text+"'";
			          
		MessageBox::Show(sql);
		DataSet^ ds=gcnew DataSet();
		SqlDataAdapter^ ourda = gcnew SqlDataAdapter( sql,con);                           
			try
	{  
	 ourda->Fill(ds,"TXL");//把数据适配器的内容添加到数据集内
	 this->dataGridView1->DataSource=ds->Tables["TXL"];
	 }
		catch(System::Data::SqlClient::SqlException^ ex)
	{MessageBox::Show("数据的异常信息是:"+ex->Errors,"提示信息");}
		 }
private: System::Void 模糊查询ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			  String^ sql= " select * from cyb where 成语 like'%"+textBox1->Text+"%'";
		MessageBox::Show(sql);
		DataSet^ ds=gcnew DataSet();
		SqlDataAdapter^ ourda = gcnew SqlDataAdapter( sql,con);                           
			try
	{  
	 ourda->Fill(ds,"TXL");//把数据适配器的内容添加到数据集内
	 this->dataGridView1->DataSource=ds->Tables["TXL"];
	 }
		catch(System::Data::SqlClient::SqlException^ ex)
	{MessageBox::Show("数据的异常信息是:"+ex->Errors,"提示信息");}
		 }
private: System::Void 修改ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 String^ sql= " update cyb  set  "+comboBox1->Text+" ='"+textBox4->Text+"' where 成语='"+textBox1->Text+"' or 拼音='"+textBox2->Text+"' or 含义='"+textBox3->Text+"'";
			
		MessageBox::Show(sql);
		DataTable^ ourtable=gcnew DataTable();
              SqlDataAdapter^ ourda = gcnew SqlDataAdapter( sql,con);                           
			try
		{ourda->Fill(ourtable);	       }
				 catch(System::Data::SqlClient::SqlException^ ex)
		{MessageBox::Show("数据的异常信息是:"+ex->Message,"提示信息");}
		 }
private: System::Void 删除ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 String^ sql= "delete cyb where " +comboBox1->Text+" ='"+textBox4->Text+"'";;
	 MessageBox::Show(sql);
	 DataTable^ ourtable=gcnew DataTable();
        SqlDataAdapter^ ourda = gcnew SqlDataAdapter( sql,con);                           
		try
	 {  ourda->Fill(ourtable);	 }			 catch(System::Data::SqlClient::SqlException^ ex)
	{MessageBox::Show("数据的异常信息是:"+ex->Message,"提示信息");}

		 }
		 
private: System::Void 添加ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 String^ sql= " insert into cyb(成语,拼音,含义) values('"+textBox1->Text+"','"+textBox2->Text+"','"+textBox3->Text+"')";
				 MessageBox::Show(sql);
				 DataTable^ ourtable=gcnew DataTable();
                 SqlDataAdapter^ ourda = gcnew SqlDataAdapter( sql,con);                           
				 try
				 {  ourda->Fill(ourtable);	 }
				 catch(System::Data::SqlClient::SqlException^ ex)
				 {MessageBox::Show("数据的异常信息是:"+ex->Message,"提示信息");}
				 this->Close();
		 }
private: System::Void 联系作者ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 MessageBox::Show("作者是帅气的jelly,本软件创作于2018年1月,略略略");
		 }
private: System::Void 联系我们ToolStripMenuItem_Click(System::Object^  sender, System::EventArgs^  e) {
			 MessageBox::Show("联系方式:QQ:1158161893,邮箱:1158161893@qq.com");
		 }

};
}

计算器
private: System::Void textBox1_KeyPress(System::Object^  sender, System::Windows::Forms::KeyPressEventArgs^  e) {
			 if(e->KeyChar=='\n'||e->KeyChar=='\t')
			 {
				 aa="";
				 i=Convert::ToInt32(textBox1->Text);
				 textBox1->Text=aa;
			 }
		 }
private: System::Void button12_Click(System::Object^  sender, System::EventArgs^  e) {
			 if(aa!="")
			 {
				 aa="";
				 i=Convert::ToInt32(textBox1->Text);
				 textBox1->Text=aa;
			 }
			 k=1;
		 }
///
private: System::Void button11_Click(System::Object^  sender, System::EventArgs^  e) {
			 aa="";
			 j=Convert::ToInt32(textBox1->Text);
			 textBox1->Text=aa;
			 switch(k)
			 {
			 case 1:i=i+j;break;
			 case 2:i=i-j;break;
		     case 3:i=i*j;break;
			 case 4:i=i/j;break;
			 default:aa="";

			 }
			 textBox1->Text=Convert::ToString(i);
		 }
private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
			 aa+="1";
			 textBox1->Text=aa;
		 }
/
			

};
  • 0
    点赞
  • 10
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值