国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 開發 > 綜合 > 正文

C#中TreeView類操作全攻略(一)

2024-07-21 02:19:40
字體:
來源:轉載
供稿:網友
using system;
using system.drawing;
using system.collections;
using system.componentmodel;
using system.windows.forms;
using system.data;
using com.prm.client.tools;
using system.data.oracleclient;
using com.prm.client.common;
using com.prm.client.sysmanager.popedom;

namespace com.prm.client.forms
{
/// <summary>
/// form1 的摘要說明。
/// </summary>
public class sm_functionmaintenance : system.windows.forms.form
{
private system.windows.forms.groupbox groupbox1;
private system.windows.forms.groupbox groupbox2;
private system.windows.forms.treeview trv_function;
private system.windows.forms.label lbl_detail;
private system.windows.forms.label lbl_belongto;
private system.windows.forms.label lbl_funentity;
private system.windows.forms.label lbl_type;
private system.windows.forms.label lbl_isinterface;
private system.windows.forms.label lbl_tag;
private system.windows.forms.label lbl_name;
private system.windows.forms.checkbox ckb_isinterface;
private system.windows.forms.combobox cbo_type;
private system.windows.forms.textbox txt_detail;
private system.windows.forms.textbox txt_belongto;
private system.windows.forms.textbox txt_funentity;
private system.windows.forms.textbox txt_tag;
private system.windows.forms.textbox txt_name;
private system.data.dataset dataset1;
private system.data.datacolumn datacolumn1;
private system.data.datacolumn datacolumn2;
private system.data.datacolumn datacolumn3;
private system.data.datacolumn datacolumn4;
private system.data.datacolumn datacolumn5;
private system.data.datacolumn datacolumn6;
private system.data.datacolumn datacolumn7;
private system.data.datacolumn datacolumn8;
private system.data.datacolumn datacolumn9;
private system.data.datacolumn datacolumn10;
private system.data.datacolumn datacolumn11;
//用來保存功能表中所有的數據
private system.data.datatable funcdatatable;

//用來保存connection屬性
private oracleconnection functableconn;
//用來保存數字字典功能類別的數據
clientdictionary[] dic_functype;
//用來保存樹總的虛擬根節點的id,默認為0
public const string root_node_value = "0";
private system.windows.forms.button btn_help;
private system.windows.forms.button btn_remove;
private system.windows.forms.button btn_modify;
private system.windows.forms.button btn_addson;
private system.windows.forms.button btn_addroot;
private system.windows.forms.button btn_close;



//樹結點的臨時信息
/// <summary>
/// 必需的設計器變量。
/// </summary>
private system.componentmodel.container components = null;

public sm_functionmaintenance(sm_popedom popedom)
{
//
// windows 窗體設計器支持所必需的
//
initializecomponent();

//生成類dataaccessobject的實例,并保存連接屬性
dataaccessobject functableaccessobject=new dataaccessobject();
functableconn=functableaccessobject.connection;
//調用queryallfuncinfo過程來對變量funcdatatable進行賦值
queryallfuncinfo();
const string valuemember="valuemember",displaymember="displaymember",nulltext="";
//調用queryfunctypedictionary過程來對變量dic_functype進行賦值
queryfunctypedictionary();
cbo_type.datasource = dic_functype;
cbo_type.valuemember = valuemember;
cbo_type.displaymember = displaymember;
}

/// <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()
{
system.resources.resourcemanager resources = new system.resources.resourcemanager(typeof(sm_functionmaintenance));
this.groupbox1 = new system.windows.forms.groupbox();
this.trv_function = new system.windows.forms.treeview();
this.groupbox2 = new system.windows.forms.groupbox();
this.lbl_detail = new system.windows.forms.label();
this.lbl_belongto = new system.windows.forms.label();
this.lbl_funentity = new system.windows.forms.label();
this.lbl_type = new system.windows.forms.label();
this.lbl_isinterface = new system.windows.forms.label();
this.lbl_tag = new system.windows.forms.label();
this.lbl_name = new system.windows.forms.label();
this.cbo_type = new system.windows.forms.combobox();
this.txt_detail = new system.windows.forms.textbox();
this.txt_belongto = new system.windows.forms.textbox();
this.txt_funentity = new system.windows.forms.textbox();
this.ckb_isinterface = new system.windows.forms.checkbox();
this.txt_tag = new system.windows.forms.textbox();
this.txt_name = new system.windows.forms.textbox();
this.dataset1 = new system.data.dataset();
this.funcdatatable = new system.data.datatable();
this.datacolumn1 = new system.data.datacolumn();
this.datacolumn2 = new system.data.datacolumn();
this.datacolumn3 = new system.data.datacolumn();
this.datacolumn4 = new system.data.datacolumn();
this.datacolumn5 = new system.data.datacolumn();
this.datacolumn6 = new system.data.datacolumn();
this.datacolumn7 = new system.data.datacolumn();
this.datacolumn8 = new system.data.datacolumn();
this.datacolumn9 = new system.data.datacolumn();
this.datacolumn10 = new system.data.datacolumn();
this.datacolumn11 = new system.data.datacolumn();
this.btn_help = new system.windows.forms.button();
this.btn_remove = new system.windows.forms.button();
this.btn_modify = new system.windows.forms.button();
this.btn_addson = new system.windows.forms.button();
this.btn_addroot = new system.windows.forms.button();
this.btn_close = new system.windows.forms.button();
this.groupbox1.suspendlayout();
this.groupbox2.suspendlayout();
((system.componentmodel.isupportinitialize)(this.dataset1)).begininit();
((system.componentmodel.isupportinitialize)(this.funcdatatable)).begininit();
this.suspendlayout();
//
// groupbox1
//
this.groupbox1.controls.add(this.trv_function);
this.groupbox1.location = new system.drawing.point(24, 24);
this.groupbox1.name = "groupbox1";
this.groupbox1.size = new system.drawing.size(440, 496);
this.groupbox1.tabindex = 0;
this.groupbox1.tabstop = false;
this.groupbox1.text = "功能列表:";
//
// trv_function
//
this.trv_function.allowdrop = true;
this.trv_function.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.trv_function.imageindex = -1;
this.trv_function.indent = 40;
this.trv_function.location = new system.drawing.point(8, 16);
this.trv_function.name = "trv_function";
this.trv_function.selectedimageindex = -1;
this.trv_function.size = new system.drawing.size(424, 472);
this.trv_function.tabindex = 0;
this.trv_function.dragover += new system.windows.forms.drageventhandler(this.trv_function_dragover);
this.trv_function.afterselect += new system.windows.forms.treevieweventhandler(this.trv_function_afterselect);
this.trv_function.dragenter += new system.windows.forms.drageventhandler(this.trv_function_dragenter);
this.trv_function.itemdrag += new system.windows.forms.itemdrageventhandler(this.trv_function_itemdrag);
this.trv_function.dragdrop += new system.windows.forms.drageventhandler(this.trv_function_dragdrop);
//
// groupbox2
//
this.groupbox2.controls.add(this.lbl_detail);
this.groupbox2.controls.add(this.lbl_belongto);
this.groupbox2.controls.add(this.lbl_funentity);
this.groupbox2.controls.add(this.lbl_type);
this.groupbox2.controls.add(this.lbl_isinterface);
this.groupbox2.controls.add(this.lbl_tag);
this.groupbox2.controls.add(this.lbl_name);
this.groupbox2.controls.add(this.cbo_type);
this.groupbox2.controls.add(this.txt_detail);
this.groupbox2.controls.add(this.txt_belongto);
this.groupbox2.controls.add(this.txt_funentity);
this.groupbox2.controls.add(this.ckb_isinterface);
this.groupbox2.controls.add(this.txt_tag);
this.groupbox2.controls.add(this.txt_name);
this.groupbox2.location = new system.drawing.point(472, 24);
this.groupbox2.name = "groupbox2";
this.groupbox2.size = new system.drawing.size(296, 496);
this.groupbox2.tabindex = 1;
this.groupbox2.tabstop = false;
this.groupbox2.text = "功能詳細信息:";
//
// lbl_detail
//
this.lbl_detail.location = new system.drawing.point(56, 320);
this.lbl_detail.name = "lbl_detail";
this.lbl_detail.size = new system.drawing.size(48, 23);
this.lbl_detail.tabindex = 13;
this.lbl_detail.text = "描述:";
//
// lbl_belongto
//
this.lbl_belongto.location = new system.drawing.point(8, 272);
this.lbl_belongto.name = "lbl_belongto";
this.lbl_belongto.size = new system.drawing.size(94, 23);
this.lbl_belongto.tabindex = 12;
this.lbl_belongto.text = "所屬窗口標識:";
//
// lbl_funentity
//
this.lbl_funentity.location = new system.drawing.point(40, 224);
this.lbl_funentity.name = "lbl_funentity";
this.lbl_funentity.size = new system.drawing.size(64, 23);
this.lbl_funentity.tabindex = 11;
this.lbl_funentity.text = " 功能體:";
//
// lbl_type
//
this.lbl_type.location = new system.drawing.point(56, 176);
this.lbl_type.name = "lbl_type";
this.lbl_type.size = new system.drawing.size(48, 23);
this.lbl_type.tabindex = 10;
this.lbl_type.text = "類別:";
//
// lbl_isinterface
//
this.lbl_isinterface.location = new system.drawing.point(32, 128);
this.lbl_isinterface.name = "lbl_isinterface";
this.lbl_isinterface.size = new system.drawing.size(72, 23);
this.lbl_isinterface.tabindex = 9;
this.lbl_isinterface.text = "有無界面:";
//
// lbl_tag
//
this.lbl_tag.location = new system.drawing.point(56, 88);
this.lbl_tag.name = "lbl_tag";
this.lbl_tag.size = new system.drawing.size(48, 23);
this.lbl_tag.tabindex = 8;
this.lbl_tag.text = "標識:";
//
// lbl_name
//
this.lbl_name.location = new system.drawing.point(56, 40);
this.lbl_name.name = "lbl_name";
this.lbl_name.size = new system.drawing.size(48, 23);
this.lbl_name.tabindex = 7;
this.lbl_name.text = "名稱:";
//
// cbo_type
//
this.cbo_type.enabled = false;
this.cbo_type.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.cbo_type.location = new system.drawing.point(104, 168);
this.cbo_type.name = "cbo_type";
this.cbo_type.size = new system.drawing.size(176, 20);
this.cbo_type.tabindex = 6;
//
// txt_detail
//
this.txt_detail.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.txt_detail.location = new system.drawing.point(104, 312);
this.txt_detail.name = "txt_detail";
this.txt_detail.readonly = true;
this.txt_detail.size = new system.drawing.size(176, 21);
this.txt_detail.tabindex = 5;
this.txt_detail.text = "";
//
// txt_belongto
//
this.txt_belongto.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.txt_belongto.location = new system.drawing.point(104, 264);
this.txt_belongto.name = "txt_belongto";
this.txt_belongto.readonly = true;
this.txt_belongto.size = new system.drawing.size(176, 21);
this.txt_belongto.tabindex = 4;
this.txt_belongto.text = "";
//
// txt_funentity
//
this.txt_funentity.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.txt_funentity.location = new system.drawing.point(104, 216);
this.txt_funentity.name = "txt_funentity";
this.txt_funentity.readonly = true;
this.txt_funentity.size = new system.drawing.size(176, 21);
this.txt_funentity.tabindex = 3;
this.txt_funentity.text = "";
//
// ckb_isinterface
//
this.ckb_isinterface.enabled = false;
this.ckb_isinterface.location = new system.drawing.point(104, 120);
this.ckb_isinterface.name = "ckb_isinterface";
this.ckb_isinterface.size = new system.drawing.size(24, 24);
this.ckb_isinterface.tabindex = 2;
//
// txt_tag
//
this.txt_tag.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.txt_tag.location = new system.drawing.point(104, 80);
this.txt_tag.name = "txt_tag";
this.txt_tag.readonly = true;
this.txt_tag.size = new system.drawing.size(176, 21);
this.txt_tag.tabindex = 1;
this.txt_tag.text = "";
//
// txt_name
//
this.txt_name.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.txt_name.location = new system.drawing.point(104, 32);
this.txt_name.name = "txt_name";
this.txt_name.readonly = true;
this.txt_name.size = new system.drawing.size(176, 21);
this.txt_name.tabindex = 0;
this.txt_name.text = "";
//
// dataset1
//
this.dataset1.datasetname = "newdataset";
this.dataset1.locale = new system.globalization.cultureinfo("zh-cn");
this.dataset1.tables.addrange(new system.data.datatable[] {
this.funcdatatable});
//
// funcdatatable
//
this.funcdatatable.columns.addrange(new system.data.datacolumn[] {
this.datacolumn1,
this.datacolumn2,
this.datacolumn3,
this.datacolumn4,
this.datacolumn5,
this.datacolumn6,
this.datacolumn7,
this.datacolumn8,
this.datacolumn9,
this.datacolumn10,
this.datacolumn11});
this.funcdatatable.tablename = "funcdatatable";
//
// datacolumn1
//
this.datacolumn1.columnname = "功能id";
//
// datacolumn2
//
this.datacolumn2.columnname = "功能標識";
//
// datacolumn3
//
this.datacolumn3.columnname = "功能名稱";
//
// datacolumn4
//
this.datacolumn4.columnname = "功能簡述";
//
// datacolumn5
//
this.datacolumn5.columnname = "所屬窗體";
//
// datacolumn6
//
this.datacolumn6.columnname = "有無界面";
//
// datacolumn7
//
this.datacolumn7.columnname = "功能類別";
//
// datacolumn8
//
this.datacolumn8.columnname = "功能體";
//
// datacolumn9
//
this.datacolumn9.columnname = "上級功能id";
//
// datacolumn10
//
this.datacolumn10.columnname = "可否展顯";
//
// datacolumn11
//
this.datacolumn11.columnname = "版本號";
//
// btn_help
//
this.btn_help.backgroundimage = ((system.drawing.image)(resources.getobject("btn_help.backgroundimage")));
this.btn_help.location = new system.drawing.point(536, 536);
this.btn_help.name = "btn_help";
this.btn_help.size = new system.drawing.size(75, 22);
this.btn_help.tabindex = 10;
this.btn_help.text = "幫 助";
this.btn_help.click += new system.eventhandler(this.btn_help_click);
//
// btn_remove
//
this.btn_remove.backgroundimage = ((system.drawing.image)(resources.getobject("btn_remove.backgroundimage")));
this.btn_remove.location = new system.drawing.point(344, 536);
this.btn_remove.name = "btn_remove";
this.btn_remove.size = new system.drawing.size(75, 22);
this.btn_remove.tabindex = 9;
this.btn_remove.text = "刪 除";
this.btn_remove.click += new system.eventhandler(this.btn_remove_click);
//
// btn_modify
//
this.btn_modify.backgroundimage = ((system.drawing.image)(resources.getobject("btn_modify.backgroundimage")));
this.btn_modify.location = new system.drawing.point(248, 536);
this.btn_modify.name = "btn_modify";
this.btn_modify.size = new system.drawing.size(75, 22);
this.btn_modify.tabindex = 8;
this.btn_modify.text = "修 改";
this.btn_modify.click += new system.eventhandler(this.btn_modify_click);
//
// btn_addson
//
this.btn_addson.backgroundimage = ((system.drawing.image)(resources.getobject("btn_addson.backgroundimage")));
this.btn_addson.location = new system.drawing.point(152, 536);
this.btn_addson.name = "btn_addson";
this.btn_addson.size = new system.drawing.size(80, 22);
this.btn_addson.tabindex = 7;
this.btn_addson.text = "新增子節點";
this.btn_addson.click += new system.eventhandler(this.btn_addson_click);
//
// btn_addroot
//
this.btn_addroot.backgroundimage = ((system.drawing.image)(resources.getobject("btn_addroot.backgroundimage")));
this.btn_addroot.location = new system.drawing.point(56, 536);
this.btn_addroot.name = "btn_addroot";
this.btn_addroot.size = new system.drawing.size(80, 22);
this.btn_addroot.tabindex = 6;
this.btn_addroot.text = "新增根節點";
this.btn_addroot.click += new system.eventhandler(this.btn_addroot_click);
//
// btn_close
//
this.btn_close.backgroundimage = ((system.drawing.image)(resources.getobject("btn_close.backgroundimage")));
this.btn_close.location = new system.drawing.point(632, 536);
this.btn_close.name = "btn_close";
this.btn_close.size = new system.drawing.size(75, 22);
this.btn_close.tabindex = 11;
this.btn_close.text = "關 閉";
this.btn_close.click += new system.eventhandler(this.btn_close_click);
//
// sm_functionmaintenance
//
this.autoscalebasesize = new system.drawing.size(6, 14);
this.backcolor = system.drawing.color.fromargb(((system.byte)(242)), ((system.byte)(247)), ((system.byte)(250)));
this.clientsize = new system.drawing.size(800, 600);
this.controlbox = false;
this.controls.add(this.btn_close);
this.controls.add(this.btn_help);
this.controls.add(this.btn_remove);
this.controls.add(this.btn_modify);
this.controls.add(this.btn_addson);
this.controls.add(this.btn_addroot);
this.controls.add(this.groupbox2);
this.controls.add(this.groupbox1);
this.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.formborderstyle = system.windows.forms.formborderstyle.none;
this.icon = ((system.drawing.icon)(resources.getobject("$this.icon")));
this.maximizebox = false;
this.minimizebox = false;
this.name = "sm_functionmaintenance";
this.startposition = system.windows.forms.formstartposition.manual;
this.load += new system.eventhandler(this.sm_functionmaintenance_load);
this.groupbox1.resumelayout(false);
this.groupbox2.resumelayout(false);
((system.componentmodel.isupportinitialize)(this.dataset1)).endinit();
((system.componentmodel.isupportinitialize)(this.funcdatatable)).endinit();
this.resumelayout(false);

}
#endregion

/// <summary>
/// 應用程序的主入口點。
/// </summary>
[stathread]
static void main()
{
application.run(new sm_functionmaintenance(null));
}

/// <summary>
/// 查詢功能表的全部內容,并初始化所有的樹節點信息;把查詢結果保存在funcdatatable這個datatable對象中
/// 該過程對變量funcdatatable和treenodes進行賦值
/// </summary>
/// <param name=""></param>
/// <returns></returns>
private void queryallfuncinfo()
{
functableconn.open ();
oraclecommand myselectcmd= new oraclecommand();
myselectcmd.connection = functableconn;
myselectcmd.commandtext = "select * from 功能 order by 功能id" ;
myselectcmd.commandtype = commandtype.text ;
oracledataadapter myoracledataadapter = new oracledataadapter();
myoracledataadapter.selectcommand=myselectcmd;
myoracledataadapter.missingschemaaction = missingschemaaction.addwithkey;
try
{
myoracledataadapter.fill(funcdatatable);
}
catch(exception ex)
{
errorhandle.show("查詢功能表時發生異常錯誤。", ex, "功能維護");
//messagebox.show("查詢功能表時出現錯誤:"+ex.tostring());
}
finally
{
functableconn.close ( ) ;
}

}

/// <summary>
/// 查詢功能id為funcid的記錄內容;把查詢結構保存在funcitem這個functiontable對象中并且返回該結果;
/// </summary>
/// <param name="funcid"></param>
/// <returns>funcitem</returns>
private functiontable queryfuncitem(long funcid)
{
int funcentitynum=funcdatatable.rows.count;
int findindex=-1;
functiontable funcitem=new functiontable();
for(int i=0;i<funcentitynum;i++)
{
if (funcid ==long.parse((funcdatatable.rows[i].itemarray[0].tostring())))
{
findindex=i;
break;
}
}
if(findindex==-1)
{
clientmessagebox.showwarn("沒有查到相關的數據!", "功能維護");
//messagebox.show("沒有查到相關的數據!");
}
else
{
funcitem.funcid=long.parse((funcdatatable.rows[findindex].itemarray[0].tostring()));
funcitem.functag=(funcdatatable.rows[findindex].itemarray[1].tostring());
funcitem.funcname=(funcdatatable.rows[findindex].itemarray[2].tostring());
funcitem.funcdetail=(funcdatatable.rows[findindex].itemarray[3].tostring());
funcitem.funcbelongto=(funcdatatable.rows[findindex].itemarray[4].tostring());
funcitem.funcisinterface=(funcdatatable.rows[findindex].itemarray[5].tostring());
funcitem.functype=(funcdatatable.rows[findindex].itemarray[6].tostring());
funcitem.funcentity=(funcdatatable.rows[findindex].itemarray[7].tostring());
funcitem.funcfatherid=long.parse((funcdatatable.rows[findindex].itemarray[8].tostring()));
funcitem.funcisexpand=(funcdatatable.rows[findindex].itemarray[9].tostring());
funcitem.funcver=(funcdatatable.rows[findindex].itemarray[10].tostring());
}
return funcitem;

}

/// <summary>
/// 查詢數字字典中功能類別的內容;并把查詢結構保存在clientdictionary對象dic_functype中;
/// </summary>
/// <param name=""></param>
/// <returns></returns>
private void queryfunctypedictionary()
{
functableconn.open ();
oraclecommand myselectcmd= new oraclecommand();
myselectcmd.connection = functableconn;
myselectcmd.commandtext = "select * from 數據字典,屬性 where 數據字典.屬性id = 屬性.屬性id and 屬性.屬性名稱 = '功能類別'";
myselectcmd.commandtype = commandtype.text ;
try
{
oracledatareader myreader = myselectcmd.executereader();
int diccount=0;
if (myreader.hasrows)
{
while (myreader.read())
{
diccount++;
}
}
myreader.close();
myreader = myselectcmd.executereader();
dic_functype=new clientdictionary[diccount];
for(int i=0;i<diccount;i++)
{
myreader.read();
dic_functype[i]=new clientdictionary(myreader.getstring(4),myreader.getstring(3));
}
myreader.close();
}
catch(exception ex)
{
messagebox.show("查詢數據字典時出現錯誤:"+ex.tostring());
}
finally
{
functableconn.close ( ) ;
}
}


/// <summary>
/// 將數據添加到treeview控件中
/// </summary>
/// <param name="nds">當前層的所有結點</param>
/// <param name="parentid">當前層的父親結點</param>
private void inittreeview(treenodecollection nds,string parentid)
{
//建立視圖,為以后設立查詢條件作準備
dataview mydataview=new dataview();
//新節點
treenode newnode;
//新節點的父親節點id
string newnodefatherid;
//dataview的數據源
mydataview.table=funcdatatable;
//過濾條件
mydataview.rowfilter="上級功能id="+parentid;

foreach(datarowview drv in mydataview)
{
newnode=new treenode();
newnode.tag=drv["功能id"].tostring();
newnode.text=drv["功能名稱"].tostring();
nds.add(newnode);
newnodefatherid=drv["上級功能id"].tostring();
//遞歸調用遍歷當前節點的子節點
inittreeview(newnode.nodes,newnode.tag.tostring ());
}
}


/// <summary>
/// 取得treeview某一節點所有的子結點編號和子結點顯示名稱
/// </summary>
/// <param name="enumnodes"></param>
/// <returns></returns>
private hashtable getnodesvalue(ienumerator enumnodes)
{
//存儲樹結點信息的哈希表
hashtable result =new hashtable();

//當前結點
treenode node = null;
//當前節點的父親結點
treenode father = null;

//取得所有結點的編號和顯示名稱
while(enumnodes.movenext())
{
//取得一個結點和它的父親結點
node = (treenode)enumnodes.current;
father = node.parent;

//取得當前結點的所有兒子
treenodecollection sonnodes = node.nodes;

ienumerator sonenumnodes = sonnodes.getenumerator();
//遞歸取得所有兒子結點的編號和顯示名稱
hashtable sonresult = getnodesvalue(sonenumnodes);

if (sonresult.count !=0)
{
//取得所有兒子結點信息的列舉
idictionaryenumerator enumdic = sonresult.getenumerator();
while(enumdic.movenext())
{
//將所有兒子信息添加到存儲節點信息的哈希表中
result.add(enumdic.key, enumdic.value);
}
}
result.add(node.tag, node.text);
}

//將保存結點信息的結果返回
return result;
}



/// <summary>
/// 選中某個節點后取得該節點的id,并顯示該id對應的信息;
/// </summary>
private void trv_function_afterselect(object sender, system.windows.forms.treevieweventargs e)
{
dataview mydataview = new dataview ();
mydataview.table= funcdatatable;
mydataview.rowfilter= "功能id="+ e.node.tag.tostring();
foreach ( datarowview editrow in mydataview)
{
this.txt_tag.text=editrow["功能標識"].tostring();
this.txt_name.text=editrow["功能名稱"].tostring();
this.txt_detail.text=editrow["功能簡述"].tostring();
this.txt_belongto.text=editrow["所屬窗體"].tostring();
;
this.cbo_type.selectedvalue=editrow["功能類別"].tostring();
this.txt_funentity.text=editrow["功能體"].tostring();
if (editrow["有無界面"].tostring() =="0")
{
this.ckb_isinterface.checked=false;
}
else
{
this.ckb_isinterface.checked=true;
}
}
}

/// <summary>
/// 初始化樹,并把焦點定位在第一個根節點上;
/// </summary>
private void sm_functionmaintenance_load(object sender, system.eventargs e)
{
inittreeview(trv_function.nodes,root_node_value);
//聚焦到樹的第一個節點上
trv_function.selectednode=trv_function.nodes[0];
trv_function.focus();
//折疊所有的樹的節點
trv_function.collapseall();
}

private void btn_addroot_click(object sender, system.eventargs e)
{
sm_addnewfunction addrootform=new sm_addnewfunction(0,dic_functype);
//addrootform窗口關閉時將會對addrootform.newfuncitem這個屬性進行賦值
addrootform.showdialog();
//如果返回的功能id不為-1表示增加成功,則
//更新funcdatatable,把新增的節點加到funcdatatable中
if(addrootform.newfuncitem.funcid !=-1)
{
datarow myrow=funcdatatable.newrow();
myrow["功能id"] = addrootform.newfuncitem.funcid;
myrow["功能標識"] = addrootform.newfuncitem.functag;
myrow["功能名稱"] = addrootform.newfuncitem.funcname;
myrow["功能簡述"] = addrootform.newfuncitem.funcdetail;
myrow["所屬窗體"] = addrootform.newfuncitem.funcbelongto;
myrow["有無界面"] = addrootform.newfuncitem.funcisinterface;
myrow["功能類別"] = addrootform.newfuncitem.functype;
myrow["功能體"] = addrootform.newfuncitem.funcentity;
myrow["上級功能id"] = addrootform.newfuncitem.funcfatherid;
myrow["可否展顯"] = addrootform.newfuncitem.funcisexpand;
myrow["版本號"] = addrootform.newfuncitem.funcver;

funcdatatable.rows.add(myrow);

//在樹的根部添加新增加的節點
treenode newrootnode=new treenode(addrootform.newfuncitem.funcname);
newrootnode.tag=addrootform.newfuncitem.funcid.tostring();
trv_function.nodes.add(newrootnode);
//聚焦到新增的節點上
trv_function.selectednode=newrootnode;
}
trv_function.focus();
}

private void btn_addson_click(object sender, system.eventargs e)
{
if(trv_function.selectednode!= null)
{
long newfuncitemfatherid=long.parse(trv_function.selectednode.tag.tostring());
sm_addnewfunction addsonform=new sm_addnewfunction(newfuncitemfatherid,dic_functype);
//addsonform窗口關閉時將會對addsonform.newfuncitem這個屬性進行賦值
addsonform.showdialog();
//如果返回的功能id不為-1表示增加成功,則
//更新funcdatatable,把新增的節點加到funcdatatable中
if(addsonform.newfuncitem.funcid !=-1)
{
datarow myrow=funcdatatable.newrow();
myrow["功能id"] = addsonform.newfuncitem.funcid;
myrow["功能標識"] = addsonform.newfuncitem.functag;
myrow["功能名稱"] = addsonform.newfuncitem.funcname;
myrow["功能簡述"] = addsonform.newfuncitem.funcdetail;
myrow["所屬窗體"] = addsonform.newfuncitem.funcbelongto;
myrow["有無界面"] = addsonform.newfuncitem.funcisinterface;
myrow["功能類別"] = addsonform.newfuncitem.functype;
myrow["功能體"] = addsonform.newfuncitem.funcentity;
myrow["上級功能id"] = addsonform.newfuncitem.funcfatherid;
myrow["可否展顯"] = addsonform.newfuncitem.funcisexpand;
myrow["版本號"] = addsonform.newfuncitem.funcver;

funcdatatable.rows.add(myrow);

//在樹的選定的節點添加新的子節點
treenode newsonnode=new treenode(addsonform.newfuncitem.funcname);
newsonnode.tag=addsonform.newfuncitem.funcid.tostring();
trv_function.selectednode.nodes.add(newsonnode);
//聚焦到新增的節點上
trv_function.selectednode=newsonnode;
}
trv_function.focus();
}
else
{
messagebox.show("沒有選中節點!","警告",messageboxbuttons.ok,messageboxicon.warning);
}

}

private void btn_modify_click(object sender, system.eventargs e)
{
if(trv_function.selectednode!= null)
{
long editfuncitemfatherid=long.parse(trv_function.selectednode.tag.tostring());
functiontable editfuncitem =queryfuncitem(editfuncitemfatherid);

sm_editfunction editform=new sm_editfunction(editfuncitem,dic_functype);
//editform窗口關閉時將會對editform.newfuncitem和editform.isedit這兩個屬性進行賦值
editform.showdialog();
//如果用戶進行了修改,則更新funcdatatable;
if(editform.isedit==true)
{
dataview mydataview = new dataview ();
mydataview.table= funcdatatable;
mydataview.rowfilter= "功能id="+ editfuncitemfatherid.tostring();
foreach ( datarowview editrow in mydataview)
{
editrow["功能標識"] = editform.newfuncitem.functag;
editrow["功能名稱"] = editform.newfuncitem.funcname;
editrow["功能簡述"] = editform.newfuncitem.funcdetail;
editrow["所屬窗體"] = editform.newfuncitem.funcbelongto;
editrow["有無界面"] = editform.newfuncitem.funcisinterface;
editrow["功能類別"] = editform.newfuncitem.functype;
editrow["功能體"] = editform.newfuncitem.funcentity;
editrow["上級功能id"] = editform.newfuncitem.funcfatherid;
editrow["可否展顯"] = editform.newfuncitem.funcisexpand;
editrow["版本號"] = editform.newfuncitem.funcver;
}
//修改對應的樹的節點名稱
trv_function.selectednode.text=editform.newfuncitem.funcname;

//更改顯示區域的相應的內容
this.txt_tag.text=editform.newfuncitem.functag;
this.txt_name.text=editform.newfuncitem.funcname;
this.txt_detail.text=editform.newfuncitem.funcdetail;
this.txt_belongto.text=editform.newfuncitem.funcbelongto;
;
this.cbo_type.selectedvalue=editform.newfuncitem.functype;
this.txt_funentity.text=editform.newfuncitem.funcentity;
if (editform.newfuncitem.funcisinterface =="0")
{
this.ckb_isinterface.checked=false;
}
else
{
this.ckb_isinterface.checked=true;
}
}

trv_function.focus();
}
else
{
messagebox.show("沒有選中要修改的節點!","警告",messageboxbuttons.ok,messageboxicon.warning);
}

}


private void btn_remove_click(object sender, system.eventargs e)
{
if(trv_function.selectednode!= null)
{
if (clientmessagebox.showconfirm("你確定要刪除這些數據嗎?", "功能維護")== dialogresult.yes)
//if (messagebox.show ("你確定要刪除這些數據嗎?", "刪除數據",
//messageboxbuttons.yesno, messageboxicon.question)== dialogresult.yes)
{
treenode nextfocusnode=new treenode();
//如果選中的是根節點(根據路徑名是否等于節點名判斷,兩者相等的話則表示是根節點
if(trv_function.selectednode.fullpath==trv_function.selectednode.text)
{
//取得第一層的節點數目
int nodescount=trv_function.nodes.count;

//如果不是同一層中的最后一個節點,則取下一個節點為聚焦節點
//根據index判斷節點的位置,index等于節點數減一表示是最后一個節點
if(trv_function.selectednode.index !=nodescount-1)
{
nextfocusnode=trv_function.selectednode.nextvisiblenode;
}
//否則取該層第一節點為聚焦節點
else
{
nextfocusnode=trv_function.nodes[0];
}
}
//如果選中的不是根節點
else
{
//取得第該層的節點數目
int nodescount=trv_function.selectednode.parent.nodes.count;

//如果選中的節點的父節點只有一個子節點,則刪除后聚焦的節點為父節點
if(nodescount==1)
{
nextfocusnode=trv_function.selectednode.parent;
}
//根據index判斷節點的位置,index等于節點數減一表示是最后一個節點
//如果不是同一層中的最后一個節點,則取下一個節點為聚焦節點
else if(trv_function.selectednode.index !=nodescount-1)
{
nextfocusnode=trv_function.selectednode.nextvisiblenode;
}
//否則取該層第一節點為聚焦節點
else
{
nextfocusnode=trv_function.selectednode.parent.nodes[0];
}
}
long deletefuncitemid=long.parse(trv_function.selectednode.tag.tostring());
//
treenodecollection deletenodes = trv_function.selectednode.nodes;
ienumerator enumnodes = deletenodes.getenumerator();

//調用getnodesvalue取得要刪除的節點及其子節點的節點數目
hashtable hashnodes =getnodesvalue(enumnodes);

//arrdeleteid數組保存要刪除的節點及其子節點的id;
long[] arrdeleteid=new long[hashnodes.count+1];

//arrdeletename數組保存要刪除的節點及其子節點的名稱;
string[] arrdeletename=new string[hashnodes.count+1];

//把要刪除的節點的id和名稱作為數組的第一個元素
arrdeleteid[0]=deletefuncitemid;
arrdeletename[0]=trv_function.selectednode.text;

idictionaryenumerator enumhashnodes = hashnodes.getenumerator();
int index=0;
//把要刪除的節點的所有子節點作為數組的其他元素
while(enumhashnodes.movenext())
{
arrdeleteid[index+1]=long.parse(enumhashnodes.key.tostring());
arrdeletename[index+1]=enumhashnodes.value.tostring();
index++;
}
//

for(int i=0;i<arrdeleteid.length;i++)
{
deletefuncitem(arrdeleteid[i],arrdeletename[i]);
}
console.writeline();

//更新funcdatatable
for(int h=0;h<arrdeleteid.length;h++)
{
for(int i=0;i<funcdatatable.rows.count;i++)
{
if (funcdatatable.rows[i].itemarray[0].tostring()==arrdeleteid[h].tostring())
{
funcdatatable.rows[i].delete();
break;
}
}
funcdatatable.acceptchanges();
}

//刪除樹上的相關節點
trv_function.nodes.remove(trv_function.selectednode);

//聚焦到下一個所要聚焦的節點
trv_function.selectednode=nextfocusnode;
trv_function.focus();
}
else
{
trv_function.focus();
return;
}
}
else
{
messagebox.show("沒有選中要刪除的節點!","警告",messageboxbuttons.ok,messageboxicon.warning);
}

}


/// <summary>
/// 刪除某個功能,并且刪除角色功能表和操作員授權表中相應的功能的記錄;
/// 且把界面定制表中相應的功能名稱后面加上“(該功能已收回)”字樣,并對改表中
/// 相應的功能id置為null
/// </summary>
private void deletefuncitem(long funcid,string funcname)
{
functableconn.open();
system.data.oracleclient.oracletransaction mytran = functableconn.begintransaction ();
try
{
oraclecommand cmd = new oraclecommand ();
cmd.transaction = mytran;
cmd.connection =functableconn;
cmd.commandtext = "delete from 功能 where 功能id = '"+funcid+"'";
cmd.executenonquery ();
cmd.commandtext = "delete from 角色功能 where 功能id = '"+funcid+"'";
cmd.executenonquery ();
cmd.commandtext = "delete from 操作員授權 where 功能id = '"+funcid+"'";
cmd.executenonquery ();
string newfuncname=funcname+"(該功能已收回!)";
cmd.commandtext = "update 界面定制 set 功能id=null,節點名稱='" + newfuncname+"'"+ " where 功能id ="+funcid;
cmd.executenonquery ();
mytran.commit ();
}
catch(exception ee)
{
try
{
mytran.rollback();
messagebox.show ("rollback over");
}
catch (oracleexception ex)
{
if (mytran.connection != null)
{
messagebox.show ("在回滾時發生 " + ex.gettype() +" 異常!",
"警告",system.windows.forms.messageboxbuttons.ok,
system.windows.forms.messageboxicon.warning);
}
}

messagebox.show ("發生" + ee.gettype() +
"異常/n" +"刪除功能出錯!","警告",system.windows.forms.messageboxbuttons.ok,
system.windows.forms.messageboxicon.warning);
}
finally
{
functableconn.close();
}
}

private void btn_help_click(object sender, system.eventargs e)
{
trv_function.nodes.clear();
inittreeview(trv_function.nodes,root_node_value);
trv_function.expandall();

}
private void btn_close_click(object sender, system.eventargs e)
{
this.close();
}


private void trv_function_itemdrag(object sender, system.windows.forms.itemdrageventargs e)
{
if(e.button == mousebuttons.left)
{
//開始進行"drag"操作
dodragdrop ((treenode)e.item,dragdropeffects.move);
}
}

private void trv_function_dragdrop(object sender, system.windows.forms.drageventargs e)
{


treenode temp = new treenode ();
//得到要移動的節點
treenode movenode = (treenode)e.data.getdata (temp.gettype());
//轉換坐標為控件treeview的坐標
point position=new point(0,0);
position.x = e.x ;
position.y = e.y ;
position = trv_function.pointtoclient(position);

//得到移動的目的地的節點
treenode aimnode =trv_function.getnodeat(position) ;

if (isdragenable(aimnode,movenode)==true)
{
if (aimnode!=movenode)
{
treenode tempnode= new treenode ();
trv_function.nodes.remove(movenode);
if (aimnode ==null)
{
trv_function.nodes.insert(trv_function.nodes.count,movenode);
}
else
{
aimnode.nodes.add(movenode);
}

//更新funcdatatable
dataview mydataview = new dataview ();
mydataview.table= funcdatatable;
mydataview.rowfilter= "功能id="+ movenode.tag.tostring()+"";
//保存要移動的節點的新的父節點id;
string movenodefatherid="0";
foreach ( datarowview editrow in mydataview)
{
if (aimnode==null)
{
//如果是根節點
movenodefatherid="0";
}
else
{
movenodefatherid=aimnode.tag.tostring();
}
editrow["上級功能id"]=movenodefatherid;
}
//聚焦到要移動的節點上
trv_function.selectednode=movenode;

//更新數據庫中的功能表:改變移動節點的父節點字段為新的父節點
functableconn.open();
system.data.oracleclient.oracletransaction mytran = functableconn.begintransaction ();
try
{
oraclecommand cmd = new oraclecommand ();
cmd.commandtext ="update 功能 set 上級功能id='"+movenodefatherid +"' where 功能id = '"+movenode.tag.tostring()+"'";
cmd.transaction = mytran;
cmd.connection =functableconn;
cmd.executenonquery ();
mytran.commit ();
}
catch(exception ee)
{
try
{
mytran.rollback();
}
catch (oracleexception ex)
{
if (mytran.connection != null)
{
messagebox.show ("在回滾時發生 " + ex.gettype() +" 異常!",
"警告",system.windows.forms.messageboxbuttons.ok,
system.windows.forms.messageboxicon.warning);
}
}

messagebox.show ("發生" + ee.gettype() +
"異常/n" +"修改記錄失敗!","警告",system.windows.forms.messageboxbuttons.ok,
system.windows.forms.messageboxicon.warning);
}
finally
{
functableconn.close();
}
//數據庫更新完畢!
}
}

}

private void trv_function_dragenter(object sender, system.windows.forms.drageventargs e)
{
e.effect = dragdropeffects.move;
}

private void trv_function_dragover(object sender, system.windows.forms.drageventargs e)
{
point position=new point(0,0);
position.x = e.x ;
position.y = e.y ;
position = trv_function.pointtoclient ( position ) ;
treenode dropnode = trv_function.getnodeat ( position ) ;
trv_function.selectednode=dropnode ;
trv_function.focus();
}

/// <summary>
/// 判斷是否可以拖動動目標節點,如果可以則返回true,否則為false;
/// 判斷根據是:目標節點不能是被拖動的節點的父親節點!
/// </summary>
private bool isdragenable( treenode aimnode,treenode orinode)
{
while (aimnode!=null)
{
if (aimnode.parent !=orinode)
{
aimnode = aimnode.parent;
isdragenable( aimnode,orinode);
}
else
{
return false;
}
}
return true;
}


}
}




發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 平乡县| 南涧| 麦盖提县| 舞钢市| 洛南县| 乃东县| 长汀县| 玉林市| 安岳县| 澄迈县| 兴国县| 湖南省| 蕲春县| 介休市| 修文县| 建湖县| 广南县| 曲阳县| 柘城县| 开阳县| 巫溪县| 青海省| 玉环县| 湖州市| 兰溪市| 裕民县| 周至县| 林口县| 白城市| 兴山县| 桐庐县| 延长县| 广东省| 三门县| 临湘市| 云安县| 萨嘎县| 石渠县| 临湘市| 贡山| 临泉县|