(A few new demos recently) (right-click the Treeview). It is more useful in subsequent updates.

Source: Internet
Author: User

Front-endCode

Http://www.baidupcs.com/file/043e27183b83917671dfbf5645559cae? FID = 2467423588-250528-2474618939 & time =
1362981939 & Sign = FDTA-DCb740ccc5511e5e8fedcff06b081203-jRy6dVFO4Oj44qlPgo % 2fiwz2ob1i % 3d & expires = 1 h

Background code

Using system;
Using system. Collections. Generic;
Using system. LINQ;
Using system. text;
Using system. Data;
Using system. Data. sqlclient;

Namespace windows_dal
{
Public class treeview_dal
{
Static sqlconnection myconnection = new sqlconnection ("Server =.; database = windows_test; uid = sa; Pwd = 1 ");
Public static datatable getmenutodatatable ()
{
String SQL = "select * From sysmenutree ";
Return dbtools. DB. executedataset (commandtype. Text, SQL). Tables [0];
}
Public static bool update_treeview (string ID, string text)
{
Myconnection. open ();
Sqltransaction mytrans = myconnection. begintransaction ();
Sqlcommand mycommand = new sqlcommand ();
Mycommand. Connection = myconnection;
Mycommand. Transaction = mytrans;
Int COUNT = 0;
Try
{
String SQL = string. Format ("Update sysmenutree set stext = '{0}' Where noteid = '{1}'", text, ID );
Mycommand. commandtext = SQL;
Count = mycommand. executenonquery ();
// Dbtools. DB. executenonquery (commandtype. Text, SQL );
Mytrans. Commit ();
}
Catch (exception)
{
Mytrans. rollback ();
}
Finally
{
Myconnection. Close ();
}
Return count> 0? True: false;
}

Public static bool add_treeview (string ID, string text)
{
Myconnection. open ();
Sqltransaction mytrans = myconnection. begintransaction ();
Sqlcommand mycommand = new sqlcommand ();
Mycommand. Connection = myconnection;
Mycommand. Transaction = mytrans;
Int COUNT = 0;
Try
{
String SQL = string. format ("insert into sysmenutree values ('{0}', '{1}','', '')", ID, text );
Mycommand. commandtext = SQL;
Count = mycommand. executenonquery ();
// Dbtools. DB. executenonquery (commandtype. Text, SQL );
Mytrans. Commit ();
}
Catch (exception)
{
Mytrans. rollback ();
}
Finally
{
Myconnection. Close ();
}
Return count> 0? True: false;
// String SQL = string. format ("insert into sysmenutree values ('{0}', '{1}','', '')", ID, text );
// Return dbtools. DB. executenonquery (commandtype. Text, SQL)> 0? True: false;
}
Public static bool add_treeview (string text)
{
Myconnection. open ();
Sqltransaction mytrans = myconnection. begintransaction ();
Sqlcommand mycommand = new sqlcommand ();
Mycommand. Connection = myconnection;
Mycommand. Transaction = mytrans;
Int COUNT = 0;
Try
{
String SQL = string. format ("insert into sysmenutree values ('0', '{0}','', '')", text );
Mycommand. commandtext = SQL;
Count = mycommand. executenonquery ();
// Dbtools. DB. executenonquery (commandtype. Text, SQL );
Mytrans. Commit ();
}
Catch (exception)
{
Mytrans. rollback ();
}
Finally
{
Myconnection. Close ();
}
Return count> 0? True: false;
// String SQL = string. format ("insert into sysmenutree values ('{0}', '{1}','', '')", ID, text );
// Return dbtools. DB. executenonquery (commandtype. Text, SQL)> 0? True: false;
}

Public static int del_treeview (string ID)
{
String SQL = string. Format ("select count (*) from sysmenutree where parentid = '{0}'", ID );
If (INT) dbtools. DB. executescalar (commandtype. Text, SQL)> 0)
{
Return 3;
}
Else
{
Myconnection. open ();
Sqltransaction mytrans = myconnection. begintransaction ();
Sqlcommand mycommand = new sqlcommand ();
Mycommand. Connection = myconnection;
Mycommand. Transaction = mytrans;
Int COUNT = 0;
Try
{
SQL = string. Format ("delete sysmenutree where noteid = '{0}'", ID );
Mycommand. commandtext = SQL;
Count = mycommand. executenonquery ();
// Dbtools. DB. executenonquery (commandtype. Text, SQL );
Mytrans. Commit ();
}
Catch (exception)
{
Mytrans. rollback ();
}
Finally
{
Myconnection. Close ();
}
Return count> 0? 1: 2;
// SQL = string. Format ("delete sysmenutree where noteid = '{0}'", ID );
// Return dbtools. DB. executenonquery (commandtype. Text, SQL)> 0? True: false;
}
}
}
}

Database Design

Noteid parentid stext

1 0 pharmaceutical experts

2 1 traditional Chinese medicine

You can modify the loading mode and the user experience after completing the operation.

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.