using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.SqlClient;
namespace 图书馆管理系统
{
/// <summary>
/// Book 的摘要说明。
/// </summary>
public class Query : System.Windows.Forms.Form
{
private System.Windows.Forms.ComboBox comboDataTable;
private System.Windows.Forms.Label iblSelectDataTable;
private System.Windows.Forms.DataGrid dataGrid1;
private System.Windows.Forms.Button btnExit;
private System.Windows.Forms.Button btnQuery;
private System.Data.SqlClient.SqlConnection sqlConnection1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapterReader;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapterBook;
private System.Windows.Forms.GroupBox groupBox1;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapterPublish;
private System.Data.SqlClient.SqlCommand sqlSelectCommand1;
private System.Data.SqlClient.SqlCommand sqlInsertCommand1;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand1;
private System.Data.SqlClient.SqlCommand sqlSelectCommand2;
private System.Data.SqlClient.SqlCommand sqlInsertCommand2;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand2;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand2;
private System.Data.SqlClient.SqlCommand sqlSelectCommand4;
private System.Data.SqlClient.SqlCommand sqlInsertCommand4;
private System.Data.SqlClient.SqlCommand sqlSelectCommand3;
private System.Data.SqlClient.SqlCommand sqlInsertCommand3;
private System.Data.SqlClient.SqlCommand sqlUpdateCommand3;
private System.Data.SqlClient.SqlCommand sqlDeleteCommand3;
private System.Data.SqlClient.SqlDataAdapter sqlDataAdapterBorrow;
private string SqlString;
private System.Windows.Forms.Label iblSelectQuery;
private System.Windows.Forms.Label iblInputNumber;
private System.Windows.Forms.Label iblQueryCodition;
private System.Windows.Forms.TextBox txtInputNumber;
private System.Windows.Forms.ComboBox cmbQueryItem;
private System.Windows.Forms.ComboBox cmbQueryCondition;
private System.Windows.Forms.Button btnClear;
private 图书馆管理系统.DataSetQuery dataSetQuery1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Query()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
Windows窗体设计器生成的代码
private void btnExit_Click(object sender, System.EventArgs e)
{
this.Close();
}
private void cmbSelectDataTable_SelectedIndexChanged(object sender, System.EventArgs e)
{
// string strTable=this.comboDataTable.SelectedItem.ToString();
// string mySelectQuery="select * from "+strTable;
// SqlCommand myCommand=new SqlCommand(mySelectQuery,this.sqlConnection1);
// if(this.sqlConnection1.State==ConnectionState.Closed) this.sqlConnection1.Open();
// SqlDataReader myReader=myCommand.ExecuteReader();
// myReader.Close();
// this.sqlConnection1.Close();
}
private void btnQuery_Click(object sender, System.EventArgs e)
{
SqlString="select * from "+this.comboDataTable.Text;
MessageBox.Show(SqlString.ToString());
switch(this.comboDataTable.SelectedIndex)
{
case 0:
this.sqlSelectCommand1.CommandText=SqlString;
break;
case 1:
this.sqlSelectCommand2.CommandText=SqlString;
break;
case 2:
this.sqlSelectCommand3.CommandText=SqlString;
break;
case 3:
this.sqlSelectCommand4.CommandText=SqlString;
break;
}
try
{
this.dataSetQuery1.EnforceConstraints=false;
this.sqlConnection1.Open();
this.dataSetQuery1.Clear();
this.sqlDataAdapterReader.Fill(this.dataSetQuery1,"Reader");
this.sqlDataAdapterBook.Fill(this.dataSetQuery1,"Book");
this.sqlDataAdapterPublish.Fill(this.dataSetQuery1,"PublishCompany");
this.sqlDataAdapterBorrow.Fill(this.dataSetQuery1,"Borrow");
this.dataSetQuery1.EnforceConstraints=true;
this.sqlConnection1.Close();
this.dataGrid1.DataSource=this.dataSetQuery1;
this.dataGrid1.DataMember=this.comboDataTable.Text.Trim();
}
catch(System.Exception E)
{
MessageBox.Show(E.ToString());
}
}
}
}