?? frmbasesort.cs
字號:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace EquipmentMS.BaseInfo
{
public partial class frmBaseSort : Form
{
BaseClass.Operation oper = new EquipmentMS.BaseClass.Operation();
int zclbID = 0;
public frmBaseSort()
{
InitializeComponent();
}
private void frmBaseSort_Load(object sender, EventArgs e)
{
this.FillTreeView();
}
private void FillTreeView()
{
trvFile.Nodes.Clear();
//設置TreeView控件的菜單項
DataSet ds = null;
ds = oper.TreeFill();
TreeNode RootNode = null;
DataTable dt = ds.Tables[0].Copy(); //將資產列表另存一份為dt
DataView dv = new DataView(dt);
dv.RowFilter = "firstID = -1";
//將數據集中的所有記錄逐個根據他們之間的關系添加到樹形表中去
if (dv.Count > 0)
{
foreach (DataRowView myRow in dv)
{
//設置根節點,然后該函數會遞歸添加所有子節點。
trvFile.Nodes.Add(RootNode = new TreeNode(myRow["zclb"].ToString()));
childTreeView(myRow["zclb"].ToString(), trvFile.Nodes[0], myRow);
trvFile.SelectedNode = trvFile.Nodes[0]; //選中第一個節點
}
}
trvFile.ExpandAll();
}
private void childTreeView(string childPart, TreeNode childNode, DataRowView childRow)
{
string strdeptName = "";
DataSet ds = null;
ds = oper.TreeFill();
DataTable dt = ds.Tables[0].Copy();
DataView dv = new DataView(dt);
//篩選獲得當前傳遞過來的節點的子項,并將其添加到樹形圖中
//判斷方法是凡parentIndex等于傳遞過來的節點的absIndex的,就是該節點的子項
dv.RowFilter = "firstID = '" + childRow["secondID"].ToString() + "'";
//遞歸的添加每一個節點的所有子節點
foreach (DataRowView myRow in dv)
{
strdeptName = myRow["zclb"].ToString();
TreeNode myNode = new TreeNode(strdeptName);
childNode.Nodes.Add(myNode);
//函數遞歸調用,將所有節點按順序添加完畢
childTreeView(strdeptName, myNode, myRow);
}
}
private void trvFile_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
try
{
DataSet ds = oper.GetDataSetBaseZclb(e.Node.Text);
zclbID = Convert.ToInt16(ds.Tables[0].Rows[0]["ID"].ToString());
}
catch
{ }
}
private void btnUpdate_Click(object sender, EventArgs e)
{
DataSet ds = oper.GetDataSetBaseZclb(trvFile.SelectedNode.Text);
if (ds.Tables[0].Rows[0]["firstID"].ToString() != "-1" && ds.Tables[0].Rows[0]["firstID"].ToString() != "0")
{
trvFile.LabelEdit = true; //開啟標簽編輯
trvFile.SelectedNode.BeginEdit();
}
}
private void btnMain_Click(object sender, EventArgs e)
{
DataSet ds = oper.GetDataSetBaseZclb(trvFile.SelectedNode.Text);
if (ds.Tables[0].Rows[0]["firstID"].ToString() != "-1" && ds.Tables[0].Rows[0]["firstID"].ToString() != "0")
{
string firstID = ds.Tables[0].Rows[0]["firstID"].ToString();
int d = oper.insertBaseZclb(firstID, "新建項目", (Convert.ToInt16(firstID) + 1).ToString());
this.trvFile.SelectedNode.Parent.Nodes.Add("新建項目");
}
}
private void btnExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void btnDelete_Click(object sender, EventArgs e)
{
DataSet ds = oper.GetDataSetBaseZclb(trvFile.SelectedNode.Text);
if (ds.Tables[0].Rows[0]["firstID"].ToString() != "-1" && ds.Tables[0].Rows[0]["firstID"].ToString() != "0")
{
oper.deleteBaseZclb(Convert.ToInt16(ds.Tables[0].Rows[0]["id"].ToString()));
MessageBox.Show("刪除成功!","系統提示",MessageBoxButtons.OK,MessageBoxIcon.Information);
this.FillTreeView();
}
}
private void btnSave_Click(object sender, EventArgs e)
{
oper.UpdateBaseZclb(zclbID, trvFile.SelectedNode.Text);
this.FillTreeView();
trvFile.LabelEdit = false; //關閉標簽編輯
}
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -