C # in the TreeView class operation of the full introduction (ii)

Source: Internet
Author: User
Tags empty insert new features rollback tostring trim
treeview| Raiders 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>
Summary description of the 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;


Data used to hold the functional category of a digital dictionary
Clientdictionary[] Dic_functype;
Used to save the connection property
Private OracleConnection Functableconn;
The primary key (feature ID) that is used to save the newly added record
Private long newfuncid;
Read-only property, which is used to read the primary key (feature ID) of the newly added record
Public long Newfuncid {get {return newfuncid;}}
Used to save the newly added feature records
Private Functiontable Newfuncitem;
Public functiontable Newfuncitem {get {return Newfuncitem}}

<summary>
The required designer variable.
</summary>
Private System.ComponentModel.Container components = null;

<summary>
constructor, initializes the window with the parameter Dic_functype, and obtains the Fatherid by the parameter
The superior function ID of the newly added feature
</summary>
Public sm_addnewfunction (Long fatherid,clientdictionary[] dic_functype)
{
//
Required for Windows Forms Designer support
//
InitializeComponent ();
Newfuncitem=new functiontable ();
Newfuncitem.funcfatherid=fatherid;
Initialize ID to-1, and will be assigned if new success
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>
Clean up all resources that are in use.
</summary>
protected override void Dispose (bool disposing)
{
if (disposing)
{
if (Components!= null)
{
Components. Dispose ();
}
}
Base. Dispose (disposing);
}

Code generated #region the Windows forms Designer
<summary>
Designer supports required methods-do not use the Code editor to modify
The contents of this method.
</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 = "Name:";
//
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 = "Logo:";
//
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 = "Category:";
//
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 = "Functional Body:";
//
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 = "belongs to the window ID:";
//
Txt_name
//
This.txt_Name.ForeColor = System.Drawing.Color.FromArgb ((System.Byte)), ((System.Byte) ()), ((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)), ((System.Byte) ($)), ((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)), ((System.Byte) ()), ((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)), ((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) ((System.Byte) ()), ((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 = "description:";
//
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)), ((System.Byte) ()), ((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 = "OK";
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) ((System.Byte) ()), ((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 = "Cancel";
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)), ((System.Byte) ()), ((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 = "Help";
//
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 = "There is no interface:";
//
Txt_funentity
//
This.txt_FunEntity.ForeColor = System.Drawing.Color.FromArgb ((System.Byte)), ((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) ((System.Byte) ()), ((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 = "new Features";
This. ResumeLayout (FALSE);

}
#endregion

<summary>
After pressing the OK button, first check the legality of the input data;
Then assign the variable Newfuncitem according to the input, and then call the Insertfuncitem procedure to add a record to the function table
</summary>
private void Btn_confirm_click (object sender, System.EventArgs e)
{
if (txt_name.text== "")
{
MessageBox.Show ("feature name cannot be empty");
Return
}
if (txt_tag.text== "")
{
MessageBox.Show ("Feature ID cannot be empty");
Return
}
if (this.txt_funentity.text== "")
{
MessageBox.Show ("Function cannot be empty");
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 ();
If the newly generated ID of 0 means that the new ID is not successfully generated automatically, it should be returned and no more operations will be performed.
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>
Output automatically generated ID number, output 0 if build fails
</summary>
Private Long Querynextfuncid ()
{
Functableconn.open ();
OracleCommand myselectcmd= New OracleCommand ();
Myselectcmd.connection = Functableconn;
Myselectcmd.commandtext = "Select Seq_ function. 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 ("Error in Query:" +ex.) ToString ());
}
Finally
{
Functableconn.close ();
}
return NextID;
}

<summary>
Inserts a new record in the menu, taking advantage of the rollback feature, that is, if the insertion is unsuccessful, the function table
Revert to the state before insertion
</summary>
<param name= "NewItem" > Information for the new record to insert </param>
private void Insertfuncitem (Functiontable newitem)
{
Functableconn.open ();
System.Data.OracleClient.OracleTransaction Mytran = Functableconn.begintransaction ();
Try
{
OracleCommand cmd = new OracleCommand ();

Cmd.commandtext = "INSERT into function (function ID, function identification, function name, function description, form, there is no interface, functional category, function, superior function ID, can show, version number) 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 (occurs on rollback) + ex. GetType () + "Exception!" ",
"Warning," System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Warning);
}
}

MessageBox.Show ("occurrence" + EE.) GetType () +
"Exception \ n" + "did not add any records!" "," warned the System.Windows.Forms.MessageBoxButtons.OK,
System.Windows.Forms.MessageBoxIcon.Warning);
}
Finally
{
Functableconn.close ();
}
}

private void Btn_cancel_click (object sender, System.EventArgs e)
{
If you click Cancel, the Newfuncitem.funcid assignment is 1.
Newfuncitem.funcid=-1;
This. Close ();
}

}
}




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.