#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;
}
/
};