📄 seach.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace 图书馆管理系统
{
/// <summary>
/// 查询 的摘要说明。
/// </summary>
public class Seach: System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.RadioButton radioButton3;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.TextBox textBox2;
private System.Windows.Forms.TextBox textBox3;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
private System.Windows.Forms.Button button3;
// private System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
// private System.Data.SqlClient.SqlConnection sqlConnection1;
// private 图书馆管理系统.DataSet1 dataSet11;
// private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Seach()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radioButton3 = new System.Windows.Forms.RadioButton();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.textBox3 = new System.Windows.Forms.TextBox();
this.textBox2 = new System.Windows.Forms.TextBox();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.label1 = new System.Windows.Forms.Label();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.radioButton3);
this.groupBox1.Controls.Add(this.radioButton2);
this.groupBox1.Controls.Add(this.radioButton1);
this.groupBox1.Location = new System.Drawing.Point(296, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(128, 136);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "查询类型";
//
// radioButton3
//
this.radioButton3.Location = new System.Drawing.Point(8, 96);
this.radioButton3.Name = "radioButton3";
this.radioButton3.TabIndex = 2;
this.radioButton3.Text = "按出版社查询";
this.radioButton3.CheckedChanged += new System.EventHandler(this.radioButton3_CheckedChanged);
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(8, 56);
this.radioButton2.Name = "radioButton2";
this.radioButton2.TabIndex = 1;
this.radioButton2.Text = "按作者查询";
this.radioButton2.CheckedChanged += new System.EventHandler(this.radioButton2_CheckedChanged);
//
// radioButton1
//
this.radioButton1.Location = new System.Drawing.Point(8, 16);
this.radioButton1.Name = "radioButton1";
this.radioButton1.TabIndex = 0;
this.radioButton1.Text = "按书名查询";
this.radioButton1.CheckedChanged += new System.EventHandler(this.radioButton1_CheckedChanged);
//
// groupBox2
//
this.groupBox2.Controls.Add(this.textBox3);
this.groupBox2.Controls.Add(this.textBox2);
this.groupBox2.Controls.Add(this.textBox1);
this.groupBox2.Controls.Add(this.label3);
this.groupBox2.Controls.Add(this.label2);
this.groupBox2.Controls.Add(this.label1);
this.groupBox2.Location = new System.Drawing.Point(8, 8);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(272, 136);
this.groupBox2.TabIndex = 1;
this.groupBox2.TabStop = false;
//
// textBox3
//
this.textBox3.Location = new System.Drawing.Point(96, 96);
this.textBox3.Name = "textBox3";
this.textBox3.Size = new System.Drawing.Size(128, 21);
this.textBox3.TabIndex = 5;
this.textBox3.Text = "";
this.textBox3.Visible = false;
//
// textBox2
//
this.textBox2.Location = new System.Drawing.Point(96, 56);
this.textBox2.Name = "textBox2";
this.textBox2.Size = new System.Drawing.Size(128, 21);
this.textBox2.TabIndex = 4;
this.textBox2.Text = "";
this.textBox2.Visible = false;
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(96, 16);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(128, 21);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "";
this.textBox1.Visible = false;
//
// label3
//
this.label3.Location = new System.Drawing.Point(16, 96);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(64, 23);
this.label3.TabIndex = 2;
this.label3.Text = "出版社:";
this.label3.Visible = false;
//
// label2
//
this.label2.Location = new System.Drawing.Point(16, 56);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(64, 23);
this.label2.TabIndex = 1;
this.label2.Text = "作者:";
this.label2.Visible = false;
//
// label1
//
this.label1.Location = new System.Drawing.Point(16, 16);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(64, 23);
this.label1.TabIndex = 0;
this.label1.Text = "书名:";
this.label1.Visible = false;
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(0, 152);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(528, 312);
this.dataGrid1.TabIndex = 2;
//
// button1
//
this.button1.Location = new System.Drawing.Point(440, 16);
this.button1.Name = "button1";
this.button1.TabIndex = 3;
this.button1.Text = "确定";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// button2
//
this.button2.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.button2.Location = new System.Drawing.Point(440, 72);
this.button2.Name = "button2";
this.button2.TabIndex = 4;
this.button2.Text = "取消";
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// button3
//
this.button3.Location = new System.Drawing.Point(440, 120);
this.button3.Name = "button3";
this.button3.TabIndex = 5;
this.button3.Text = "全部列出";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// Seach
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.CancelButton = this.button2;
this.ClientSize = new System.Drawing.Size(528, 462);
this.Controls.Add(this.button3);
this.Controls.Add(this.button2);
this.Controls.Add(this.button1);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.Name = "Seach";
this.Text = "查询";
this.Load += new System.EventHandler(this.Seach_Load);
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void sqlConnection1_InfoMessage(object sender, System.Data.SqlClient.SqlInfoMessageEventArgs e)
{
}
private void Seach_Load(object sender, System.EventArgs e)
{
//string strConn= "workstation id=\"127.0.0.1\";packet size=4096;integrated security=SSPI;data s" +
// "ource=\"127.0.0.1\";persist security info=True;initial catalog=Bookmanageme" +
// "nt";
string strConn="INTEGRATED SECURITY=TRUE;Initial Catalog=Bookmanagement;Data Source=127.0.0.1";
SqlConnection myConnection=new SqlConnection(strConn);
myConnection.Open();
SqlDataAdapter myDataAdapter = new SqlDataAdapter ();
DataSet myDataSet = new DataSet();
string cmdSelect="SELECT *"+"FROM Books,Bookdetails WHERE Bookdetails.书名 = Books.书名";
myDataAdapter.SelectCommand = new SqlCommand (cmdSelect,myConnection);
myDataAdapter.Fill(myDataSet,"a");
dataGrid1.DataSource=myDataSet.Tables["a"];
}
private void button1_Click(object sender, System.EventArgs e)
{
if(radioButton1.Checked==true)
{
//string str=;
string cmdSelect="SELECT *"+
"FROM Bookdetails ,Books WHERE Bookdetails.书名=Books.书名 AND Books.书名='"+textBox1.Text+"'";
SqlDataAdapter myDataAdapter = new SqlDataAdapter();
DataSet myDataSet = new DataSet();
string strConn="INTEGRATED SECURITY=TRUE;Initial Catalog=Bookmanagement;Data Source=127.0.0.1";
SqlConnection myConnection=new SqlConnection(strConn);
myConnection.Open();
myDataAdapter.SelectCommand=new SqlCommand(cmdSelect,myConnection);
myDataSet.Clear();
myDataAdapter.Fill(myDataSet,"a");
dataGrid1.DataSource=myDataSet.Tables["a"];
}
if(radioButton2.Checked==true)
{
string cmdSelect="SELECT *"+
"FROM Bookdetails ,Books WHERE Bookdetails.书名 = Books.书名 AND Bookdetails.作者='"+textBox2.Text+"'";
SqlDataAdapter myDataAdapter = new SqlDataAdapter ();
DataSet myDataSet = new DataSet();
string strConn="INTEGRATED SECURITY=TRUE;Initial Catalog=Bookmanagement;Data Source=127.0.0.1";
SqlConnection myConnection=new SqlConnection(strConn);
myDataAdapter.SelectCommand=new SqlCommand(cmdSelect,myConnection);
myDataAdapter.Fill(myDataSet,"a");
dataGrid1.DataSource=myDataSet.Tables["a"];
}
if(radioButton3.Checked==true)
{
string cmdSelect="SELECT *"+
"FROM Bookdetails ,Books WHERE Bookdetails.书名 = Books.书名 AND Bookdetails.出版社='"+textBox3.Text+"'";
SqlDataAdapter myDataAdapter = new SqlDataAdapter ();
DataSet myDataSet = new DataSet();
string strConn="INTEGRATED SECURITY=TRUE;Initial Catalog=Bookmanagement;Data Source=127.0.0.1";
SqlConnection myConnection=new SqlConnection(strConn);
myDataAdapter.SelectCommand=new SqlCommand(cmdSelect,myConnection);
myDataAdapter.Fill(myDataSet,"a");
dataGrid1.DataSource=myDataSet.Tables["a"];
}
}
private void radioButton1_CheckedChanged(object sender, System.EventArgs e)
{
if(radioButton1.Checked)
{
textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
label1.Visible=true;
label2.Visible=false;
label3.Visible=false;
textBox1.Visible=true;
textBox2.Visible=false;
textBox3.Visible=false;
}
}
private void radioButton2_CheckedChanged(object sender, System.EventArgs e)
{
if(radioButton2.Checked)
{
textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
label1.Visible=false;
label2.Visible=true;
label3.Visible=false;
textBox1.Visible=false;
textBox2.Visible=true;
textBox3.Visible=false;
}
}
private void radioButton3_CheckedChanged(object sender, System.EventArgs e)
{
if(radioButton3.Checked)
{
textBox1.Text="";
textBox2.Text="";
textBox3.Text="";
label1.Visible=false;
label2.Visible=false;
label3.Visible=true;
textBox1.Visible=false;
textBox2.Visible=false;
textBox3.Visible=true;
}
}
private void button2_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void button3_Click(object sender, System.EventArgs e)
{
string strConn="INTEGRATED SECURITY=TRUE;Initial Catalog=Bookmanagement;Data Source=127.0.0.1";
SqlConnection myConnection=new SqlConnection(strConn);
myConnection.Open();
SqlDataAdapter myDataAdapter = new SqlDataAdapter ();
DataSet myDataSet = new DataSet();
string cmdSelect="SELECT *"+"FROM Books,Bookdetails WHERE Bookdetails.书名 = Books.书名";
myDataAdapter.SelectCommand = new SqlCommand (cmdSelect,myConnection);
myDataAdapter.Fill(myDataSet,"a");
dataGrid1.DataSource=myDataSet.Tables["a"];
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -