📄 searchborrowedbook.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>
/// SearchBorrowedBook 的摘要说明。
/// </summary>
public class SearchBorrowedBook : System.Windows.Forms.Form
{
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.DataGrid dataGrid1;
private string username;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public SearchBorrowedBook(string username)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
this.username=username;
//
// 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.button1 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.label1 = new System.Windows.Forms.Label();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.groupBox1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Anchor = System.Windows.Forms.AnchorStyles.None;
this.groupBox1.Controls.Add(this.button1);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.Controls.Add(this.label1);
this.groupBox1.Location = new System.Drawing.Point(8, 8);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(408, 72);
this.groupBox1.TabIndex = 0;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "借阅查询";
//
// button1
//
this.button1.Anchor = System.Windows.Forms.AnchorStyles.Left;
this.button1.Location = new System.Drawing.Point(280, 32);
this.button1.Name = "button1";
this.button1.TabIndex = 2;
this.button1.Text = "查询";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// textBox1
//
this.textBox1.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)));
this.textBox1.Location = new System.Drawing.Point(112, 32);
this.textBox1.Name = "textBox1";
this.textBox1.ReadOnly = true;
this.textBox1.Size = new System.Drawing.Size(112, 21);
this.textBox1.TabIndex = 1;
//this.textBox1.Text = "";
//
// label1
//
this.label1.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.label1.Location = new System.Drawing.Point(24, 32);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(80, 23);
this.label1.TabIndex = 0;
this.label1.Text = "用户名:";
//
// dataGrid1
//
this.dataGrid1.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dataGrid1.DataMember = "";
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(8, 88);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(408, 248);
this.dataGrid1.TabIndex = 1;
//
// SearchBorrowedBook
//
this.AcceptButton = this.button1;
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(424, 350);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.groupBox1);
this.Name = "SearchBorrowedBook";
this.Text = "SearchBorrowedBook";
this.Load += new System.EventHandler(this.SearchBorrowedBook_Load);
this.groupBox1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
if(textBox1.Text!="")
{
if(Exists(textBox1.Text))
{
string cmdSelect="SELECT *"+
"FROM BorrowedBook WHERE BorrowedBook.用户名='"+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"];
}
}
else
{
MessageBox.Show("用户名不能为空!");
}
}
private bool Exists(string str)
{
bool result;
string strConn="INTEGRATED SECURITY=TRUE;Initial Catalog=Bookmanagement;Data Source=127.0.0.1";
SqlConnection myConnection=new SqlConnection(strConn);
myConnection.Open();
string cmdString="select * from BorrowedBook where BorrowedBook.用户名='"+str+"'";
SqlCommand cmd=new SqlCommand(cmdString,myConnection);
SqlDataReader reader=cmd.ExecuteReader();
if(reader.Read())
{
result=true;
}
else
{
result=false;
}
reader.Close();
myConnection.Close();
return result;
}
private void SearchBorrowedBook_Load(object sender, System.EventArgs e)
{
textBox1.Text=username;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -