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();
}
}
}