📄 lookup.cs
字号:
using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
namespace Library
{
/// <summary>
/// LookUp 的摘要说明。
/// </summary>
public class LookUp : System.Windows.Forms.Form
{
public static System.Windows.Forms.ListView listView1;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.Button button3;
private System.Windows.Forms.Button btnClose;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button4;
private System.Windows.Forms.ToolTip toolTip1;
private System.Windows.Forms.Label label2;
public static System.Windows.Forms.ComboBox comboBox1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.RadioButton radioButton1;
private System.Windows.Forms.RadioButton radioButton2;
private System.Windows.Forms.Button button1;
private System.ComponentModel.IContainer components;
/// <summary>
/// 临时数据表
/// </summary>
private static DataTable tableTemp = null;
/// <summary>
///
/// </summary>
private static string dtNow = DateTime.Now.Year.ToString() +
"-" + DateTime.Now.Month.ToString() +
"-" + DateTime.Now.Day.ToString();
/// <summary>
/// 超期图书
/// </summary>
private static string cqBooks = @"SELECT TOP 100 PERCENT dbo.流通.图书条码号, dbo.图书资料.分类号,
dbo.图书资料.书名, dbo.图书资料.ISBN, dbo.图书资料.作者, dbo.图书资料.单价,
dbo.图书资料.出版社, dbo.图书资料.出版日期, dbo.图书资料.图书类型,
dbo.图书资料.编码日期, dbo.图书资料.入库日期, dbo.图书资料.书架名称,
dbo.图书资料.借阅次数, dbo.流通.借书日期, dbo.流通.还书日期,
dbo.流通.归还标志
FROM dbo.流通 INNER JOIN
dbo.图书资料 ON dbo.流通.图书条码号 = dbo.图书资料.条形码
WHERE dbo.流通.归还标志 = 1 and dbo.流通.还书日期<'" + dtNow +
"' ORDER BY dbo.图书资料.借阅次数 DESC";
/// <summary>
/// 动态视图——今日借阅记录
/// </summary>
private static string todayBorrow = @"SELECT dbo.流通.图书条码号, dbo.图书资料.分类号, dbo.图书资料.书名,
dbo.图书资料.ISBN, dbo.图书资料.作者, dbo.图书资料.单价, dbo.图书资料.出版社,
dbo.图书资料.出版日期, dbo.图书资料.图书类型, dbo.图书资料.编码日期,
dbo.图书资料.入库日期, dbo.图书资料.书架名称, dbo.图书资料.借阅次数,
dbo.流通.借书日期, dbo.流通.还书日期, dbo.流通.归还标志
FROM dbo.流通 INNER JOIN
dbo.图书资料 ON dbo.流通.图书条码号 = dbo.图书资料.条形码
WHERE (dbo.流通.归还标志 = 0) and dbo.流通.借书日期='" + DateTime.Now.ToShortDateString() + "'";
/// <summary>
/// 动态视图——今日归还记录
/// </summary>
private static string todayReturn = @"SELECT dbo.流通.图书条码号, dbo.图书资料.分类号, dbo.图书资料.书名,
dbo.图书资料.ISBN, dbo.图书资料.作者, dbo.图书资料.单价, dbo.图书资料.出版社,
dbo.图书资料.出版日期, dbo.图书资料.图书类型, dbo.图书资料.编码日期,
dbo.图书资料.入库日期, dbo.图书资料.书架名称, dbo.图书资料.借阅次数,
dbo.流通.借书日期, dbo.流通.还书日期, dbo.流通.归还标志
FROM dbo.流通 INNER JOIN
dbo.图书资料 ON dbo.流通.图书条码号 = dbo.图书资料.条形码
WHERE (dbo.流通.归还标志 = 1) and dbo.流通.借书日期='" + DateTime.Now.Date.ToShortDateString() + "'";
/// <summary>
/// 动态视图——今日到/超期记录
/// </summary>
private static string todayCD = @"SELECT dbo.流通.图书条码号, dbo.图书资料.分类号, dbo.图书资料.书名,
dbo.图书资料.ISBN, dbo.图书资料.作者, dbo.图书资料.单价, dbo.图书资料.出版社,
dbo.图书资料.出版日期, dbo.图书资料.图书类型, dbo.图书资料.编码日期,
dbo.图书资料.入库日期, dbo.图书资料.书架名称, dbo.图书资料.借阅次数,
dbo.流通.借书日期, dbo.流通.还书日期, dbo.流通.归还标志
FROM dbo.流通 INNER JOIN
dbo.图书资料 ON dbo.流通.图书条码号 = dbo.图书资料.条形码
WHERE (dbo.流通.归还标志 = 0) and dbo.流通.借书日期='" + DateTime.Now.Date.ToShortDateString()
+ "' and dbo.流通.还书日期<='" + DateTime.Now.ToShortDateString() + "'";
/// <summary>
/// 查询模式
/// </summary>
public static string Type = "";
/// <summary>
/// 定义方法GetData(),返回一个数据表
/// </summary>
/// <returns>返回DataTable</returns>
public static System.Data.DataTable GetData(string view)
{
SqlDataAdapter adapter = new SqlDataAdapter("select * from " + view,Global.conn);
DataSet ds= new DataSet();
try
{
adapter.Fill(ds);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
return ds.Tables[0];
}
/// <summary>
/// 定义方法GetData(),返回一个数据表
/// </summary>
/// <returns>返回DataTable</returns>
public static System.Data.DataTable GetData2(string sel)
{
SqlDataAdapter adapter = new SqlDataAdapter(sel,Global.conn);
DataSet ds= new DataSet();
try
{
adapter.Fill(ds);
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
return ds.Tables[0];
}
/// <summary>
/// 图书借阅记录
/// </summary>
public static void initializeScreen(bool reset)
{
ListViewItem item = null;
int colIndex=0;
switch(Type)
{
case "图书借阅记录":
tableTemp = GetData(Type);
break;
case "已借阅图书":
tableTemp = GetData(Type);
break;
case "已归还图书":
tableTemp = GetData(Type);
break;
case "已超期图书":
tableTemp = GetData2(cqBooks);
break;
case "读者信息":
tableTemp = GetData(Type);
break;
case "已挂失借书证":
tableTemp = GetData(Type);
break;
case "已丢失图书":
tableTemp = GetData(Type);
break;
case "今日借阅记录":
tableTemp = GetData2(todayBorrow);
break;
case "今日归还记录":
tableTemp = GetData2(todayReturn);
break;
case "今日到超期记录":
tableTemp = GetData2(todayCD);
break;
}
if(reset)
{
listView1.Items.Clear();
//将所得到的表的列名,赋值给单元格
foreach(DataColumn col in tableTemp.Columns)
{
colIndex++;
comboBox1.Items.Add(col.ColumnName);
}
}
else
{
listView1.Clear();
//将所得到的表的列名,赋值给单元格
foreach(DataColumn col in tableTemp.Columns)
{
colIndex++;
listView1.Columns.Add(col.ColumnName,-2,HorizontalAlignment.Left);
comboBox1.Items.Add(col.ColumnName);
}
}
//同样方法处理数据
foreach(DataRow row in tableTemp.Rows)
{
colIndex=0;
item = new ListViewItem(row[0].ToString());
for(colIndex= 1;colIndex<tableTemp.Columns.Count;colIndex++)
{
item.SubItems.Add(row[colIndex].ToString());
}
listView1.Items.Add(item);
}
}
public LookUp(string type)
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
listView1 = new System.Windows.Forms.ListView();
//
// listView1
//
listView1.FullRowSelect = true;
listView1.GridLines = true;
listView1.Sorting = SortOrder.Descending;
listView1.Location = new System.Drawing.Point(16, 16);
listView1.Name = "listView1";
listView1.Size = new System.Drawing.Size(704, 336);
listView1.TabIndex = 9;
listView1.View = System.Windows.Forms.View.Details;
listView1.ColumnClick+=new ColumnClickEventHandler(listView1_ColumnClick);
comboBox1 = new System.Windows.Forms.ComboBox();
this.Controls.Add(listView1);
//
// comboBox1
//
comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList;
comboBox1.Location = new System.Drawing.Point(88, 22);
comboBox1.Name = "comboBox1";
comboBox1.Size = new System.Drawing.Size(168, 20);
comboBox1.TabIndex = 6;
groupBox1.Controls.Add(comboBox1);
//
//
//
Type = type;
this.Text = "查询——" + Type;
initializeScreen(false);
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(tableTemp!=null)
{
tableTemp.Dispose();
}
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(LookUp));
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.radioButton2 = new System.Windows.Forms.RadioButton();
this.radioButton1 = new System.Windows.Forms.RadioButton();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.button4 = new System.Windows.Forms.Button();
this.textBox1 = new System.Windows.Forms.TextBox();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.button1 = new System.Windows.Forms.Button();
this.btnClose = new System.Windows.Forms.Button();
this.button3 = new System.Windows.Forms.Button();
this.toolTip1 = new System.Windows.Forms.ToolTip(this.components);
this.groupBox1.SuspendLayout();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -