📄 tushuxinxichaxun.cs
字号:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace tsh
{
public partial class tushuxinxichaxun : Form
{
public tushuxinxichaxun()
{
InitializeComponent();
}
DB.ClsSQL sql = new DB.ClsSQL(".", "mylw", "sa", "", 3);
DataSet ds;
private void tushuxinxichaxun_Load(object sender, EventArgs e)
{
}
private string bookno;
public string BookNo
{
get
{
return bookno;
}
set
{
bookno = value;
}
}
private void buttui_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.Cancel;
this.Close();
}
private void butque_Click(object sender, EventArgs e)
{
// int n = 0;
switch (tabControl1.SelectedTab.Text)
{
case "按编号查询":
bookno=dataGridView1.CurrentRow.Cells[0].Value.ToString();
break;
case "按书名查询":
bookno = dataGridView2.CurrentRow.Cells[0].Value.ToString();
break;
case "按类别查询":
bookno = dataGridView3.CurrentRow.Cells[0].Value.ToString();
break;
case "按作者查询":
bookno = dataGridView4.CurrentRow.Cells[0].Value.ToString();
break;
case "按出版社查询":
bookno = dataGridView5.CurrentRow.Cells[0].Value.ToString();
break;
//case "按编号查询":
// n = dataGridView1.CurrentRow["tushubianhao"].To
// if (n != -1)
// bookno = ds.Tables["book"].Rows[n]["tushubianhao"].ToString().Trim();
// break;
//case "按书名查询":
// n = dataGridView2.CurrentRowIndex;
// if (n != -1)
// bookno = ds.Tables["book"].Rows[n]["tushubianhao"].ToString().Trim();
// break;
//case " 按类别查询":
// n = dataGridView3.CurrentRowIndex;
// if (n != -1)
// bookno = ds.Tables["book"].Rows[n]["tushubianhao"].ToString().Trim();
// break;
//case "按作者查询":
// n = dataGridView4.CurrentRowIndex;
// if (n != -1)
// bookno = ds.Tables["book"].Rows[n]["tushubianhao"].ToString().Trim();
// break;
//case "按出版社查询":
// n = dataGridView5.CurrentRowIndex;
// if (n != -1)
// bookno = ds.Tables["book"].Rows[n]["tushubianhao"].ToString().Trim();
// break;
}
this.DialogResult = DialogResult.OK;
this.Close();
}
private void but1_Click(object sender, EventArgs e)
{
if (textBox1.Text == "")
{
string s = "select * from book ";
ds = sql.DBToDS(s, "book");
dataGridView1.DataSource = ds.Tables["book"];
// sql.DBToDG(s, dataGridView1, "book");
}
else
{
string s = "select * from book where tushubianhao='" + textBox1.Text.Trim() + "'";
ds = sql.DBToDS(s, "book");
if (ds.Tables["book"].Rows.Count == 0)
{
MessageBox.Show("无此图书编号!!", "查询信息");
textBox1.Text = "";
textBox1.Focus();
}
else
{
dataGridView1.DataSource = ds.Tables["book"];
}
}
}
private void but2_Click(object sender, EventArgs e)
{
if (textBox2.Text == "")
{
string s = "select * from book ";
ds = sql.DBToDS(s, "book");
dataGridView2.DataSource = ds.Tables["book"];
// sql.DBToDG(s, dataGridView1, "book");
}
else
{
string ml = textBox2.Text.Trim();
string s = "select * from book where shuming like '%"+ml+"%'";
ds = sql.DBToDS(s, "book");
if (ds.Tables["book"].Rows.Count == 0)
{
MessageBox.Show("无此书名!!", "查询信息");
textBox2.Text = "";
textBox2.Focus();
}
else
{
dataGridView2.DataSource = ds.Tables["book"];
}
}
}
private void but3_Click(object sender, EventArgs e)
{
if (textBox3.Text == "")
{
string s = "select * from book ";
ds = sql.DBToDS(s, "book");
dataGridView3.DataSource = ds.Tables["book"];
// sql.DBToDG(s, dataGridView1, "book");
}
else
{
string s = "select * from book where leibie like '%" + textBox3.Text.Trim() + "%'";
ds = sql.DBToDS(s, "book");
if (ds.Tables["book"].Rows.Count == 0)
{
MessageBox.Show("无此图书类别!!", "查询信息");
textBox3.Text = "";
textBox3.Focus();
}
else
{
dataGridView3.DataSource = ds.Tables["book"];
}
}
}
private void but4_Click(object sender, EventArgs e)
{
if (textBox4.Text == "")
{
string s = "select * from book ";
ds = sql.DBToDS(s, "book");
dataGridView4.DataSource = ds.Tables["book"];
// sql.DBToDG(s, dataGridView1, "book");
}
else
{
string s = "select * from book where zuozhe like '%" + textBox4.Text.Trim() + "%'";
ds = sql.DBToDS(s, "book");
if (ds.Tables["book"].Rows.Count == 0)
{
MessageBox.Show("无此图书作者!!", "查询信息");
textBox4.Text = "";
textBox4.Focus();
}
else
{
dataGridView4.DataSource = ds.Tables["book"];
}
}
}
private void but5_Click(object sender, EventArgs e)
{
if (textBox5.Text == "")
{
string s = "select * from book ";
ds = sql.DBToDS(s, "book");
dataGridView5.DataSource = ds.Tables["book"];
// sql.DBToDG(s, dataGridView1, "book");
}
else
{
string s = "select * from book where chubanshe like '%" + textBox5.Text.Trim() + "%'";
ds = sql.DBToDS(s, "book");
if (ds.Tables["book"].Rows.Count == 0)
{
MessageBox.Show("无此图书出版社!!", "查询信息");
textBox5.Text = "";
textBox5.Focus();
}
else
{
dataGridView5.DataSource = ds.Tables["book"];
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -