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