?? 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 + -