📄 frmfindnode.cs
字号:
this.btnLocateNodeInTree.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btnLocateNodeInTree.BackColor = System.Drawing.Color.Transparent;
this.btnLocateNodeInTree.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btnLocateNodeInTree.Location = new System.Drawing.Point(328, 272);
this.btnLocateNodeInTree.Name = "btnLocateNodeInTree";
this.btnLocateNodeInTree.Size = new System.Drawing.Size(88, 24);
this.btnLocateNodeInTree.TabIndex = 5;
this.btnLocateNodeInTree.Text = "在树中定位";
this.btnLocateNodeInTree.Click += new System.EventHandler(this.btnLocateNodeInTree_Click);
//
// frmFindNode
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.BackgroundImage = ((System.Drawing.Image)(resources.GetObject("$this.BackgroundImage")));
this.ClientSize = new System.Drawing.Size(488, 309);
this.Controls.Add(this.btnFind);
this.Controls.Add(this.dataGrid1);
this.Controls.Add(this.label1);
this.Controls.Add(this.txtFind);
this.Controls.Add(this.txtFilter);
this.Controls.Add(this.label2);
this.Controls.Add(this.label3);
this.Controls.Add(this.scboFindCategory);
this.Controls.Add(this.btnClearFilter);
this.Controls.Add(this.btnMovePrev);
this.Controls.Add(this.btnMoveNext);
this.Controls.Add(this.btnMoveLast);
this.Controls.Add(this.btnClose);
this.Controls.Add(this.btnMoveFirst);
this.Controls.Add(this.btnLocateNodeInTree);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "frmFindNode";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "查找数据";
this.TopMost = true;
this.Closing += new System.ComponentModel.CancelEventHandler(this.frmFindNode_Closing);
((System.ComponentModel.ISupportInitialize)(this.dataGrid1)).EndInit();
this.ResumeLayout(false);
}
#endregion
public frmFindNode(OLEDBAccessObj dbobj, SuperTreeView tree)
{
this.InitializeComponent();
this._tree = tree;
this.dbObj = dbobj;
this.Init();
}
/// <summary>
/// 初始化
/// </summary>
private void Init()
{
this.scboFindCategory.Add("全树节点文本", "OnlyText");
this.scboFindCategory.Add("详细信息型节点内容", "DetailText");
this.scboFindCategory.Add("文件型节点内容", "OnlyFile");
this.scboFindCategory.Add("文件夹型节点内容", "Folder");
this.scboFindCategory.Add("图片型节点内容", "PicLib");
this.scboFindCategory.Add("全部数据库中节点内容", "All");
//展示所有的节点记录
if(this._tree == null)
return;
dt = this._tree.dtTreeNodes;
dt.DefaultView.RowFilter = "";
this.dataGrid1.DataSource = dt;
this.dataGridTextBoxColumn1.Width = this.dataGrid1.Width;
//正确设置绑定对象
this.dbh.Container = this;
this.dbh.SetDataSource(dt, null);
this.scboFindCategory.SelectedIndex = -1;
}
#region 变量区
private OLEDBAccessObj dbObj = null;
//树节点记录集
private DataTable dt = null;
//用于显示树的控件
private SuperTreeView _tree = null;
private DataBindingHelper dbh = new DataBindingHelper();
#endregion
#region 查找功能
private void GetAllRecord(string tableName)
{
if(tableName.Trim() == string.Empty)
return;
this.txtFilter.Text = "";
string strSQL = "";
switch(tableName)
{
case "OnlyText" :
dt = this._tree.dtTreeNodes;
this.dataGrid1.DataSource = dt;
this.dbh.SetDataSource(dt, null);
return;
case "DetailText" :
strSQL = "Select BelongTo as NodePath from DetailText ";
break;
case "OnlyFile" :
strSQL = "Select BelongTo as NodePath from OnlyFile ";
break;
case "Folder" :
strSQL = "Select BelongTo as NodePath from Folder ";
break;
case "PicLib" :
strSQL = "Select BelongTo as NodePath from PicLib ";
break;
case "All" :
this.SearchAll();
return;
}
DataSet ds = this.dbObj.GetSQLDataSet(strSQL, "TreeNodes");
dt = ds.Tables["TreeNodes"];
this.dataGrid1.DataSource = dt;
this.dbh.SetDataSource(dt, null);
}
private void Search(string tableName)
{
if(tableName.Trim() == string.Empty)
return;
this.txtFilter.Text = "";
string strSQL = "";
switch(tableName)
{
case "OnlyText" :
//dt = this._tree.dtTreeNodes;
//this.dataGrid1.DataSource = dt;
//this.dbh.SetDataSource(dt, null);
//this.dt.DefaultView.RowFilter = "NodePath Like '%" + this.txtFind.Text + "%'";
return;
case "DetailText" :
strSQL = "Select BelongTo as NodePath from DetailText where [Text] Like '%" + this.txtFind.Text + "%'";
break;
case "OnlyFile" :
strSQL = "Select BelongTo as NodePath from OnlyFile where [Text] Like '%" + this.txtFind.Text + "%'";
break;
case "Folder" :
strSQL = "Select BelongTo as NodePath from Folder where [Text] Like '%" + this.txtFind.Text + "%'";
break;
case "PicLib" :
strSQL = "Select BelongTo as NodePath from PicLib where [Text] Like '%" + this.txtFind.Text + "%'";
break;
case "All" :
this.SearchAll();
return;
}
DataSet ds = this.dbObj.GetSQLDataSet(strSQL, "TreeNodes");
dt = ds.Tables["TreeNodes"];
this.dataGrid1.DataSource = dt;
this.dbh.SetDataSource(dt, null);
}
/// <summary>
/// 查找全部数据
/// </summary>
private void SearchAll()
{
DataSet ds1, ds2, ds3, ds4;
string strSQL;
strSQL = "Select BelongTo as NodePath from DetailText where [Text] Like '%" + this.txtFind.Text + "%'";
ds1 = this.dbObj.GetSQLDataSet(strSQL, "TreeNodes");
strSQL = "Select BelongTo as NodePath from OnlyFile where [Text] Like '%" + this.txtFind.Text + "%'";
ds2 = this.dbObj.GetSQLDataSet(strSQL, "TreeNodes");
strSQL = "Select BelongTo as NodePath from Folder where [Text] Like '%" + this.txtFind.Text + "%'";
ds3 = this.dbObj.GetSQLDataSet(strSQL, "TreeNodes");
strSQL = "Select BelongTo as NodePath from PicLib where [Text] Like '%" + this.txtFind.Text + "%'";
ds4 = this.dbObj.GetSQLDataSet(strSQL, "TreeNodes");
ds1.Merge(ds2);
ds1.Merge(ds3);
ds1.Merge(ds4);
dt = ds1.Tables["TreeNodes"];
this.dataGrid1.DataSource = dt;
this.dbh.SetDataSource(dt, null);
}
/// <summary>
/// 定位树
/// </summary>
private void LocateNodeInTree()
{
string nodePath = this.dbh.GetCurrentDataRow()["NodePath"].ToString();
this._tree.SelectedNode = this._tree.FindNode(nodePath);
}
#endregion
private void btnClose_Click(object sender, System.EventArgs e)
{
this.Visible = false;
}
private void btnFind_Click(object sender, System.EventArgs e)
{
if(this.scboFindCategory.SelectedIndex == -1)
return;
this.Search(this.scboFindCategory.GetItemTag(this.scboFindCategory.SelectedIndex).ToString());
}
private void btnLocateNodeInTree_Click(object sender, System.EventArgs e)
{
this.LocateNodeInTree();
}
private void scboFindCategory_SelectedIndexChanged(object sender, System.EventArgs e)
{
if(this.scboFindCategory.SelectedIndex == 0)
{
this.txtFind.Enabled = false;
}
else
{
this.txtFind.Enabled = true;
this.txtFind.Focus();
}
this.GetAllRecord(this.scboFindCategory.GetItemTag(this.scboFindCategory.SelectedIndex).ToString());
}
private void frmFindNode_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
this.Visible = false;
e.Cancel = true;
}
private void txtFilter_TextChanged(object sender, System.EventArgs e)
{
this.dt.DefaultView.RowFilter = "NodePath Like '%" + this.txtFilter.Text + "%'";
}
private void btnClearFilter_Click(object sender, System.EventArgs e)
{
this.txtFilter.Text = "";
}
private void btnMoveFirst_Click(object sender, System.EventArgs e)
{
this.dbh.MoveFirst();
}
private void btnMovePrev_Click(object sender, System.EventArgs e)
{
this.dbh.MovePrev();
}
private void btnMoveNext_Click(object sender, System.EventArgs e)
{
this.dbh.MoveNext();
}
private void btnMoveLast_Click(object sender, System.EventArgs e)
{
this.dbh.MoveLast();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -