📄 lookup.cs
字号:
this.groupBox2.SuspendLayout();
this.SuspendLayout();
//
// groupBox1
//
this.groupBox1.Controls.Add(this.radioButton2);
this.groupBox1.Controls.Add(this.radioButton1);
this.groupBox1.Controls.Add(this.label3);
this.groupBox1.Controls.Add(this.label2);
this.groupBox1.Controls.Add(this.button4);
this.groupBox1.Controls.Add(this.textBox1);
this.groupBox1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox1.Location = new System.Drawing.Point(16, 360);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(440, 100);
this.groupBox1.TabIndex = 10;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "导航-查询信息类型";
//
// radioButton2
//
this.radioButton2.Location = new System.Drawing.Point(360, 20);
this.radioButton2.Name = "radioButton2";
this.radioButton2.Size = new System.Drawing.Size(72, 24);
this.radioButton2.TabIndex = 9;
this.radioButton2.Text = "模糊查询";
//
// radioButton1
//
this.radioButton1.Checked = true;
this.radioButton1.Location = new System.Drawing.Point(288, 20);
this.radioButton1.Name = "radioButton1";
this.radioButton1.Size = new System.Drawing.Size(72, 24);
this.radioButton1.TabIndex = 8;
this.radioButton1.TabStop = true;
this.radioButton1.Text = "精确查询";
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(16, 59);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(60, 17);
this.label3.TabIndex = 7;
this.label3.Text = "查询条件:";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(16, 24);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(60, 17);
this.label2.TabIndex = 5;
this.label2.Text = "查询依据:";
//
// button4
//
this.button4.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button4.Location = new System.Drawing.Point(368, 56);
this.button4.Name = "button4";
this.button4.Size = new System.Drawing.Size(48, 23);
this.button4.TabIndex = 4;
this.button4.Text = "查询";
this.button4.Click += new System.EventHandler(this.button4_Click);
//
// textBox1
//
this.textBox1.Location = new System.Drawing.Point(88, 57);
this.textBox1.Name = "textBox1";
this.textBox1.Size = new System.Drawing.Size(272, 21);
this.textBox1.TabIndex = 3;
this.textBox1.Text = "";
//
// groupBox2
//
this.groupBox2.Controls.Add(this.button1);
this.groupBox2.Controls.Add(this.btnClose);
this.groupBox2.Controls.Add(this.button3);
this.groupBox2.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.groupBox2.Location = new System.Drawing.Point(464, 388);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(248, 72);
this.groupBox2.TabIndex = 11;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "控制栏";
//
// button1
//
this.button1.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button1.Location = new System.Drawing.Point(87, 32);
this.button1.Name = "button1";
this.button1.TabIndex = 4;
this.button1.Text = "重置";
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// btnClose
//
this.btnClose.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.btnClose.Location = new System.Drawing.Point(162, 32);
this.btnClose.Name = "btnClose";
this.btnClose.TabIndex = 3;
this.btnClose.Text = "关闭";
this.btnClose.Click += new System.EventHandler(this.btnClose_Click);
//
// button3
//
this.button3.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.button3.Location = new System.Drawing.Point(12, 32);
this.button3.Name = "button3";
this.button3.TabIndex = 2;
this.button3.Text = "导出Excel";
this.button3.Click += new System.EventHandler(this.button3_Click);
//
// LookUp
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(738, 472);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.groupBox1);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "LookUp";
this.ShowInTaskbar = false;
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "查询";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 关闭
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void btnClose_Click(object sender, System.EventArgs e)
{
this.Close();
}
/// <summary>
/// 导出记录到Excel
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button3_Click(object sender, System.EventArgs e)
{
Microsoft.Office.Interop.Excel.Application excel= new Microsoft.Office.Interop.Excel.Application();
int rowIndex=1;
int colIndex=0;
excel.Application.Workbooks.Add(true);
//tableTemp = GetData(Type);
//将所得到的表的列名,赋值给单元格
foreach(DataColumn col in tableTemp.Columns)
{
colIndex++;
excel.Cells[1,colIndex]=col.ColumnName;
}
//同样方法处理数据
foreach(DataRow row in tableTemp.Rows)
{
rowIndex++;
colIndex=0;
foreach(DataColumn col in tableTemp.Columns)
{
colIndex++;
excel.Cells[rowIndex,colIndex]=row[col.ColumnName].ToString();
}
}
MessageBox.Show("成功导出记录!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
//不可见,即后台处理
excel.Visible=true;
}
/// <summary>
/// 查询
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button4_Click(object sender, System.EventArgs e)
{
string str = "";
if(comboBox1.Text != "")
{
if(radioButton1.Checked)
{
switch(Type)
{
case "今日借阅记录":
str = todayBorrow + " and " + comboBox1.Text + "='" + textBox1.Text + "'";
break;
case "今日归还记录":
str = todayReturn + " and " + comboBox1.Text + "='" + textBox1.Text + "'";
break;
case "今日到超期记录":
str = todayCD + " and " + comboBox1.Text + "='" + textBox1.Text + "'";
break;
default:
str = "select * from " + Type + " where " + comboBox1.Text + "='" + textBox1.Text + "'";
break;
}
ListViewItem item = null;
listView1.Items.Clear();
int colIndex=0;
tableTemp = GetData2(str);
//同样方法处理数据
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);
}
}
else
{
switch(Type)
{
case "今日借阅记录":
str = todayBorrow + " and " + comboBox1.Text + " like '%" + textBox1.Text + "%'";
break;
case "今日归还记录":
str = todayReturn + " and " + comboBox1.Text + " like '%" + textBox1.Text + "%'";
break;
case "今日到超期记录":
str = todayCD + " and " + comboBox1.Text + " like '%" + textBox1.Text + "%'";
break;
default:
str = "select * from " + Type + " where " + comboBox1.Text + " like '%" + textBox1.Text + "%'";
break;
}
ListViewItem item = null;
listView1.Items.Clear();
int colIndex=0;
tableTemp = GetData2(str);
//同样方法处理数据
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);
}
}
}
else
{
MessageBox.Show("查询依据不清楚!请重新设定!","提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
comboBox1.Focus();
}
}
/// <summary>
/// 重置查询窗口列举数据
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void button1_Click(object sender, System.EventArgs e)
{
initializeScreen(true);
}
/// <summary>
/// 单击列表头进行手工排序
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void listView1_ColumnClick(object sender, ColumnClickEventArgs e)
{
listView1.ListViewItemSorter = new Library.Class.ListViewItemComparer(e.Column);
listView1.Sort();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -