📄 form1.cs
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;
namespace KBSearch
{
/// <summary>
/// Form1 的摘要说明。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Button BT_Search;
private System.Windows.Forms.TextBox TB_Text;
private System.Windows.Forms.GroupBox groupBox1;
private System.Windows.Forms.Splitter splitter1;
private System.Windows.Forms.GroupBox groupBox2;
private System.Windows.Forms.DataGrid dataGrid1;
/// <summary>
/// 必需的设计器变量。
/// </summary>
private System.ComponentModel.Container components = null;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// 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.BT_Search = new System.Windows.Forms.Button();
this.TB_Text = new System.Windows.Forms.TextBox();
this.groupBox1 = new System.Windows.Forms.GroupBox();
this.splitter1 = new System.Windows.Forms.Splitter();
this.groupBox2 = new System.Windows.Forms.GroupBox();
this.dataGrid1 = new System.Windows.Forms.DataGrid();
this.groupBox1.SuspendLayout();
this.groupBox2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).BeginInit();
this.SuspendLayout();
//
// BT_Search
//
this.BT_Search.Location = new System.Drawing.Point(280, 24);
this.BT_Search.Name = "BT_Search";
this.BT_Search.TabIndex = 0;
this.BT_Search.Text = "button1";
this.BT_Search.Click += new System.EventHandler(this.BT_Search_Click);
//
// TB_Text
//
this.TB_Text.Location = new System.Drawing.Point(8, 24);
this.TB_Text.Name = "TB_Text";
this.TB_Text.Size = new System.Drawing.Size(264, 21);
this.TB_Text.TabIndex = 1;
this.TB_Text.Text = "";
//
// groupBox1
//
this.groupBox1.Controls.Add(this.TB_Text);
this.groupBox1.Controls.Add(this.BT_Search);
this.groupBox1.Dock = System.Windows.Forms.DockStyle.Top;
this.groupBox1.Location = new System.Drawing.Point(0, 0);
this.groupBox1.Name = "groupBox1";
this.groupBox1.Size = new System.Drawing.Size(360, 56);
this.groupBox1.TabIndex = 3;
this.groupBox1.TabStop = false;
this.groupBox1.Text = "查询条件";
//
// splitter1
//
this.splitter1.Dock = System.Windows.Forms.DockStyle.Top;
this.splitter1.Location = new System.Drawing.Point(0, 56);
this.splitter1.Name = "splitter1";
this.splitter1.Size = new System.Drawing.Size(360, 8);
this.splitter1.TabIndex = 4;
this.splitter1.TabStop = false;
//
// groupBox2
//
this.groupBox2.Controls.Add(this.dataGrid1);
this.groupBox2.Dock = System.Windows.Forms.DockStyle.Fill;
this.groupBox2.Location = new System.Drawing.Point(0, 64);
this.groupBox2.Name = "groupBox2";
this.groupBox2.Size = new System.Drawing.Size(360, 237);
this.groupBox2.TabIndex = 5;
this.groupBox2.TabStop = false;
this.groupBox2.Text = "结果";
//
// dataGrid1
//
this.dataGrid1.DataMember = "";
this.dataGrid1.Dock = System.Windows.Forms.DockStyle.Fill;
this.dataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText;
this.dataGrid1.Location = new System.Drawing.Point(3, 17);
this.dataGrid1.Name = "dataGrid1";
this.dataGrid1.Size = new System.Drawing.Size(354, 217);
this.dataGrid1.TabIndex = 0;
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(360, 301);
this.Controls.Add(this.groupBox2);
this.Controls.Add(this.splitter1);
this.Controls.Add(this.groupBox1);
this.Name = "Form1";
this.Text = "Form1";
this.groupBox1.ResumeLayout(false);
this.groupBox2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
private void BT_Search_Click(object sender, System.EventArgs e)
{
string constr="PROVIDER=MSIDXS;DATA SOURCE=KB";
OleDbConnection con=new OleDbConnection(constr);
try
{
OleDbCommand cmd=new OleDbCommand();
cmd.Connection=con;
cmd.CommandText="SELECT Rank,FileName, Create, Access, Path FROM SCOPE() where CONTAINS ('\""+TB_Text.Text+"\"')";
OleDbDataAdapter da=new OleDbDataAdapter();
da.SelectCommand=cmd;
con.Open();
DataSet ds=new DataSet();
da.Fill(ds);
//OleDbDataReader reader=cmd.ExecuteReader();
dataGrid1.DataSource=ds;
//reader.Close();
}
catch(Exception E)
{
Console.Write(E.Message);
}
finally
{
con.Close();
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -