国产探花免费观看_亚洲丰满少妇自慰呻吟_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;

namespace com.prm.client.forms
{
/// <summary>
/// sm_addnewfunction 的摘要說明。
/// </summary>
public class sm_addnewfunction: system.windows.forms.form
{
private system.windows.forms.label lbl_name;
private system.windows.forms.textbox txt_name;
private system.windows.forms.label lbl_tag;
private system.windows.forms.textbox txt_tag;
private system.windows.forms.checkbox ckb_isinterface;
private system.windows.forms.label lbl_isinterface;
private system.windows.forms.label lbl_type;
private system.windows.forms.label lbl_funentity;
private system.windows.forms.combobox cbo_type;
private system.windows.forms.textbox txt_funentity;
private system.windows.forms.label lbl_belongto;
private system.windows.forms.textbox txt_belongto;
private system.windows.forms.textbox txt_detail;
private system.windows.forms.label lbl_detail;
private system.windows.forms.button btn_confirm;
private system.windows.forms.button btn_cancel;
private system.windows.forms.button btn_help;


//用來保存數字字典功能類別的數據
clientdictionary[] dic_functype;
//用來保存connection屬性
private oracleconnection functableconn;
//用來保存新增加的記錄的主鍵(功能id)
private long newfuncid;
//只讀屬性,用來讀取新增加的記錄的主鍵(功能id)
//public long newfuncid {get {return newfuncid;}}
//用來保存新增加的功能記錄
private functiontable newfuncitem;
public functiontable newfuncitem {get {return newfuncitem;}}

/// <summary>
/// 必需的設計器變量。
/// </summary>
private system.componentmodel.container components = null;

/// <summary>
/// 構造函數,通過參數dic_functype對窗口進行初始化值,通過參數fatherid得到
/// 新增加的功能的上級功能id
/// </summary>
public sm_addnewfunction(long fatherid,clientdictionary[] dic_functype)
{
//
// windows 窗體設計器支持所必需的
//
initializecomponent();
newfuncitem=new functiontable();
newfuncitem.funcfatherid=fatherid;
//初始化id為-1,如果新增成功則將重新賦值
newfuncitem.funcid=-1;
dic_functype=dic_functype;
const string valuemember="valuemember",displaymember="displaymember",nulltext="";
cbo_type.datasource = dic_functype;
cbo_type.valuemember = valuemember;
cbo_type.displaymember = displaymember;

dataaccessobject functableaccessobject=new dataaccessobject();
functableconn=functableaccessobject.connection;
}

/// <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_addnewfunction));
this.lbl_name = new system.windows.forms.label();
this.lbl_tag = new system.windows.forms.label();
this.lbl_type = new system.windows.forms.label();
this.lbl_funentity = new system.windows.forms.label();
this.lbl_belongto = new system.windows.forms.label();
this.txt_name = new system.windows.forms.textbox();
this.txt_tag = new system.windows.forms.textbox();
this.cbo_type = new system.windows.forms.combobox();
this.txt_belongto = new system.windows.forms.textbox();
this.txt_detail = new system.windows.forms.textbox();
this.lbl_detail = new system.windows.forms.label();
this.ckb_isinterface = new system.windows.forms.checkbox();
this.btn_confirm = new system.windows.forms.button();
this.btn_cancel = new system.windows.forms.button();
this.btn_help = new system.windows.forms.button();
this.lbl_isinterface = new system.windows.forms.label();
this.txt_funentity = new system.windows.forms.textbox();
this.suspendlayout();
//
// lbl_name
//
this.lbl_name.location = new system.drawing.point(56, 24);
this.lbl_name.name = "lbl_name";
this.lbl_name.size = new system.drawing.size(48, 23);
this.lbl_name.tabindex = 0;
this.lbl_name.text = "名稱:";
//
// lbl_tag
//
this.lbl_tag.location = new system.drawing.point(56, 56);
this.lbl_tag.name = "lbl_tag";
this.lbl_tag.size = new system.drawing.size(48, 23);
this.lbl_tag.tabindex = 1;
this.lbl_tag.text = "標識:";
//
// lbl_type
//
this.lbl_type.location = new system.drawing.point(56, 112);
this.lbl_type.name = "lbl_type";
this.lbl_type.size = new system.drawing.size(48, 23);
this.lbl_type.tabindex = 2;
this.lbl_type.text = "類別:";
//
// lbl_funentity
//
this.lbl_funentity.location = new system.drawing.point(32, 144);
this.lbl_funentity.name = "lbl_funentity";
this.lbl_funentity.size = new system.drawing.size(72, 23);
this.lbl_funentity.tabindex = 3;
this.lbl_funentity.text = " 功能體:";
//
// lbl_belongto
//
this.lbl_belongto.location = new system.drawing.point(8, 176);
this.lbl_belongto.name = "lbl_belongto";
this.lbl_belongto.size = new system.drawing.size(96, 23);
this.lbl_belongto.tabindex = 4;
this.lbl_belongto.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, 16);
this.txt_name.name = "txt_name";
this.txt_name.size = new system.drawing.size(152, 21);
this.txt_name.tabindex = 5;
this.txt_name.text = "";
//
// 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, 48);
this.txt_tag.name = "txt_tag";
this.txt_tag.size = new system.drawing.size(152, 21);
this.txt_tag.tabindex = 6;
this.txt_tag.text = "";
//
// cbo_type
//
this.cbo_type.dropdownstyle = system.windows.forms.comboboxstyle.dropdownlist;
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, 104);
this.cbo_type.name = "cbo_type";
this.cbo_type.size = new system.drawing.size(152, 20);
this.cbo_type.tabindex = 7;
//
// 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, 168);
this.txt_belongto.name = "txt_belongto";
this.txt_belongto.size = new system.drawing.size(152, 21);
this.txt_belongto.tabindex = 8;
this.txt_belongto.text = "";
//
// 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, 200);
this.txt_detail.name = "txt_detail";
this.txt_detail.size = new system.drawing.size(152, 21);
this.txt_detail.tabindex = 9;
this.txt_detail.text = "";
//
// lbl_detail
//
this.lbl_detail.location = new system.drawing.point(56, 208);
this.lbl_detail.name = "lbl_detail";
this.lbl_detail.size = new system.drawing.size(48, 23);
this.lbl_detail.tabindex = 10;
this.lbl_detail.text = "描述:";
//
// ckb_isinterface
//
this.ckb_isinterface.location = new system.drawing.point(104, 72);
this.ckb_isinterface.name = "ckb_isinterface";
this.ckb_isinterface.size = new system.drawing.size(24, 24);
this.ckb_isinterface.tabindex = 11;
//
// btn_confirm
//
this.btn_confirm.backgroundimage = ((system.drawing.image)(resources.getobject("btn_confirm.backgroundimage")));
this.btn_confirm.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.btn_confirm.location = new system.drawing.point(40, 240);
this.btn_confirm.name = "btn_confirm";
this.btn_confirm.size = new system.drawing.size(64, 22);
this.btn_confirm.tabindex = 12;
this.btn_confirm.text = "確 定";
this.btn_confirm.click += new system.eventhandler(this.btn_confirm_click);
//
// btn_cancel
//
this.btn_cancel.backgroundimage = ((system.drawing.image)(resources.getobject("btn_cancel.backgroundimage")));
this.btn_cancel.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.btn_cancel.location = new system.drawing.point(128, 240);
this.btn_cancel.name = "btn_cancel";
this.btn_cancel.size = new system.drawing.size(64, 22);
this.btn_cancel.tabindex = 13;
this.btn_cancel.text = "取 消";
this.btn_cancel.click += new system.eventhandler(this.btn_cancel_click);
//
// btn_help
//
this.btn_help.backgroundimage = ((system.drawing.image)(resources.getobject("btn_help.backgroundimage")));
this.btn_help.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.btn_help.location = new system.drawing.point(216, 240);
this.btn_help.name = "btn_help";
this.btn_help.size = new system.drawing.size(64, 22);
this.btn_help.tabindex = 14;
this.btn_help.text = "幫 助";
//
// lbl_isinterface
//
this.lbl_isinterface.location = new system.drawing.point(32, 80);
this.lbl_isinterface.name = "lbl_isinterface";
this.lbl_isinterface.size = new system.drawing.size(72, 23);
this.lbl_isinterface.tabindex = 15;
this.lbl_isinterface.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, 136);
this.txt_funentity.name = "txt_funentity";
this.txt_funentity.size = new system.drawing.size(152, 21);
this.txt_funentity.tabindex = 16;
this.txt_funentity.text = "";
//
// sm_addnewfunction
//
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(320, 273);
this.controls.add(this.txt_funentity);
this.controls.add(this.lbl_isinterface);
this.controls.add(this.btn_help);
this.controls.add(this.btn_cancel);
this.controls.add(this.btn_confirm);
this.controls.add(this.ckb_isinterface);
this.controls.add(this.lbl_detail);
this.controls.add(this.txt_detail);
this.controls.add(this.txt_belongto);
this.controls.add(this.cbo_type);
this.controls.add(this.txt_tag);
this.controls.add(this.txt_name);
this.controls.add(this.lbl_belongto);
this.controls.add(this.lbl_funentity);
this.controls.add(this.lbl_type);
this.controls.add(this.lbl_tag);
this.controls.add(this.lbl_name);
this.forecolor = system.drawing.color.fromargb(((system.byte)(30)), ((system.byte)(66)), ((system.byte)(94)));
this.icon = ((system.drawing.icon)(resources.getobject("$this.icon")));
this.name = "sm_addnewfunction";
this.startposition = system.windows.forms.formstartposition.centerscreen;
this.text = "新增功能";
this.resumelayout(false);

}
#endregion

/// <summary>
/// 按確定按鈕后,先檢查輸入的數據的合法性;
/// 接著根據輸入對變量newfuncitem進行相應的賦值,然后調用insertfuncitem過程在功能表中增加一條記錄
/// </summary>
private void btn_confirm_click(object sender, system.eventargs e)
{
if(txt_name.text=="")
{
messagebox.show("功能名稱不能為空");
return;
}
if(txt_tag.text=="")
{
messagebox.show("功能標識不能為空");
return;
}
if(this.txt_funentity.text=="")
{
messagebox.show("功能體不能為空");
return;
}
newfuncitem.funcname=txt_name.text.trim();
newfuncitem.functag=txt_tag.text.trim();
if(this.ckb_isinterface.checked==true)
{
newfuncitem.funcisinterface="1";
}
else
{
newfuncitem.funcisinterface="0";
}
newfuncitem.funcid=querynextfuncid();
//如果新生成的id為0則表示沒有成功自動生成新id,應該返回,不再執行增加操作。
if(newfuncitem.funcid==0) return;
newfuncitem.functype=this.cbo_type.selectedvalue.tostring().trim();
newfuncitem.funcentity=this.txt_funentity.text.trim();
newfuncitem.funcbelongto=this.txt_belongto.text.trim();
newfuncitem.funcdetail=this.txt_detail.text.trim();
newfuncitem.funcisexpand="";
newfuncitem.funcver="";
insertfuncitem(newfuncitem);
this.close();

}

/// <summary>
///輸出自動生成的id號,如果生成失敗則輸出0
/// </summary>
private long querynextfuncid()
{
functableconn.open ();
oraclecommand myselectcmd= new oraclecommand();
myselectcmd.connection = functableconn;
myselectcmd.commandtext = "select seq_功能.nextval from dual";
myselectcmd.commandtype = commandtype.text ;
long nextid=0;
try
{
oracledatareader myreader = myselectcmd.executereader();
myreader.read();
nextid= myreader.getint64(0);
myreader.close();
}
catch(exception ex)
{
messagebox.show("查詢時出現錯誤:"+ex.tostring());
}
finally
{
functableconn.close ( ) ;
}
return nextid;
}

/// <summary>
/// 在功能表中插入一條新記錄,利用了回滾功能,即如果插入不成功則功能表
/// 恢復為插入前的狀態
/// </summary>
/// <param name="newitem">要插入的新紀錄的信息</param>
private void insertfuncitem(functiontable newitem)
{
functableconn.open();
system.data.oracleclient.oracletransaction mytran = functableconn.begintransaction ();
try
{
oraclecommand cmd = new oraclecommand ();

cmd.commandtext = "insert into 功能 (功能id,功能標識,功能名稱,功能簡述, 所屬窗體,有無界面,功能類別,功能體,上級功能id,可否展顯,版本號) values ('"
+newitem.funcid+"', '"
+newitem.functag+"', '"
+newitem.funcname+"', '"
+newitem.funcdetail+"', '"
+newitem.funcbelongto+"', '"
+newitem.funcisinterface+"', '"
+newitem.functype+"', '"
+newitem.funcentity+"', '"
+newitem.funcfatherid+"', '"
+newitem.funcisexpand+"', '"
+newitem.funcver+"')";
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 btn_cancel_click(object sender, system.eventargs e)
{
//如果點擊取消的話則newfuncitem.funcid賦值為-1
newfuncitem.funcid=-1;
this.close();
}

}
}


發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 团风县| 庆安县| 尼木县| 宣城市| 攀枝花市| 眉山市| 芜湖市| 东辽县| 麻栗坡县| 阜新市| 淳安县| 巴林左旗| 龙海市| 屏边| 麟游县| 合江县| 邵武市| 麻城市| 西贡区| 尉氏县| 仲巴县| 介休市| 京山县| 平度市| 仲巴县| 南川市| 靖州| 西城区| 嘉义市| 邯郸市| 达拉特旗| 曲阳县| 金秀| 宾川县| 苏州市| 江都市| 墨竹工卡县| 正定县| 绥江县| 札达县| 临澧县|