DictionaryDAL.cs里的代码
using Microsoft.ApplicationBlocks.Data;
using System.Data.SqlClient;
using System.Data;
using System;
#region DictionaryDAL
/// <summary>
/// This object represents the properties and methods of a Dictionary.
/// </summary>
public class DictionaryDAL
{
public static void AddDictionary(DictionaryInfo DInfo)
{
string Sql = "Insert into Dictionary(ParentId,Title,DirValue)values(@ParentId,@Title,@DirValue)";
SqlParameter[] arParms = new SqlParameter[3];
arParms[0] = new SqlParameter("@ParentId", SqlDbType.Int);
arParms[0].Value = DInfo.ParentId;
arParms[1] = new SqlParameter("@Title", SqlDbType.VarChar, 50);
arParms[1].Value = DInfo.Title;
arParms[2] = new SqlParameter("@DirValue", SqlDbType.VarChar, 10);
arParms[2].Value = DInfo.DirValue;
using (SqlConnection sqlconn = DALUtil.GetConnection())
{
SqlHelper.ExecuteNonQuery(sqlconn, CommandType.Text, Sql, arParms);
}
}
public static void EditDictionary(DictionaryInfo DInfo)
{
string Sql = "Update Dictionary set ParentId = @ParentId,Title = @Title,DirValue = @DirValue Where Id = @Id";
SqlParameter[] arParms = new SqlParameter[5];
arParms[0] = new SqlParameter("@Id", SqlDbType.Int);
arParms[0].Value = DInfo.Id;
arParms[1] = new SqlParameter("@ParentId", SqlDbType.Int);
arParms[1].Value = DInfo.ParentId;
arParms[2] = new SqlParameter("@Title", SqlDbType.VarChar, 50);
arParms[2].Value = DInfo.Title;
arParms[3] = new SqlParameter("@DirValue", SqlDbType.VarChar, 10);
arParms[3].Value = DInfo.DirValue;
using (SqlConnection sqlconn = DALUtil.GetConnection())
{
SqlHelper.ExecuteNonQuery(sqlconn, CommandType.Text, Sql, arParms);
}
}
public static void DelDictionary(int Id)
{
string Sql = "Delete from Dictionary Where Id = @Id";
SqlParameter[] arParms = new SqlParameter[1];
arParms[0] = new SqlParameter("@Id", SqlDbType.Int);
arParms[0].Value = Id;
using (SqlConnection sqlconn = DALUtil.GetConnection())
{
SqlHelper.ExecuteNonQuery(sqlconn, CommandType.Text, Sql, arParms);
}
}
public static DataSet GetDictionaryDataSet()
{
string Sql = "Select * from Dictionary";
DataSet ds = new DataSet();
using (SqlConnection sqlconn = DALUtil.GetConnection())
{
ds = SqlHelper.ExecuteDataset(sqlconn, CommandType.Text, Sql);
return ds;
}
}
private static DictionaryInfo GetDictionaryInfoByReader(SqlDataReader reader)
{
DictionaryInfo DInfo = new DictionaryInfo();
if (reader != null && !reader.IsClosed && reader.Read())
{
if (reader["Id"] != DBNull.Value)
{
DInfo.Id = (int)reader["Id"];
}
if (reader["ParentId"] != DBNull.Value)
{
DInfo.ParentId = (int)reader["ParentId"];
}
if (reader["Title"] != DBNull.Value)
{
DInfo.Title = (string)reader["Title"];
}
if (reader["DirValue"] != DBNull.Value)
{
DInfo.DirValue = (string)reader["DirValue"];
}
public static DictionaryInfo GetDictionaryInfoById(int Id)
{
string Sql = "Select * from Dictionary where Id = @Id";
SqlParameter[] arParms = new SqlParameter[1];
arParms[0] = new SqlParameter("@Id", SqlDbType.Int);
arParms[0].Value = Id;
SqlDataReader sReader = null;
using (SqlConnection sqlconn = DALUtil.GetConnection())
{
sReader = SqlHelper.ExecuteReader(sqlconn, CommandType.Text, Sql, arParms);
return GetDictionaryInfoByReader(sReader);
}
}
}
#endregion
Default.aspx.cs里面的代码
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataSet ds = DictionaryDAL.GetDictionaryDataSet();
TreeBind(ds, "0", TreeView1.Nodes);
}
}
public static void TreeBind(DataSet ds,
string ParentId, TreeNodeCollection nodes)
{
DataView dv = new DataView();
TreeNode tmpNd;
string strId;