日期:2014-05-18  浏览次数:20547 次

无限级分类的问题
我正在做一个电子商城的网站!~需要做一个无限级分类的功能!~最好是存储过程版!~谁有做好的源码能分享个吗?需要有cs文件和数据库文件!~谢谢!~期待中!我的QQ是:200831856               E_mail:   daichao911@163.com           /             200831856@qq.com

------解决方案--------------------
这是我以前写的一个无限级单位管理代码,你可以参考一下,数据库可以参照实体类设置
/// <summary>
/// 实体类Department
/// </summary>
public class Department
{
public Department()
{}
#region Model
private int _id;
private string _departmentname;
private string _treecode;
private int _sequence;
private int _pid;
/// <summary>
///
/// </summary>
public int ID
{
set{ _id=value;}
get{return _id;}
}
/// <summary>
/// 单位名称
/// </summary>
public string DepartmentName
{
set{ _departmentname=value;}
get{return _departmentname;}
}
/// <summary>
/// 树形代码
/// </summary>
public string TreeCode
{
set{ _treecode=value;}
get{return _treecode;}
}
/// <summary>
/// 排序
/// </summary>
public int Sequence
{
set{ _sequence=value;}
get{return _sequence;}
}
/// <summary>
/// 上级单位ID
/// </summary>
public int PID
{
set { _pid = value; }
get { return _pid; }
}
#endregion Model

}
------解决方案--------------------
/// <summary>
/// 增加一条数据
/// </summary>
public int Add(FZC_Exam.Model.Department model)
{
StringBuilder strSql = new StringBuilder();
strSql.Append( "insert into Department( ");
strSql.Append( "DepartmentName,DepartmentCode,TreeCode,Sequence,PID) ");
strSql.Append( " values ( ");
strSql.Append( "@DepartmentName,@DepartmentCode,@TreeCode,@Sequence,@PID) ");
strSql.Append( ";select @@IDENTITY ");
SqlParameter[] parameters = {
new SqlParameter( "@DepartmentName ", SqlDbType.VarChar,100),
new SqlParameter( "@DepartmentCode ", SqlDbType.VarChar,100),
new SqlParameter( "@TreeCode ", SqlDbType.VarChar,100),
new SqlParameter( "@Sequence ", SqlDbType.Int,4),
new SqlParameter( "@PID ", SqlDbType.BigInt,8)};
//model.TreeCode;
DataTable mytable =DbHelperSQL.FillData( "Department ", "TreeCode ", 1, 1, true, "PID= ' " + model.PID + " ' ");
if (mytable.Rows.Count ==0)
{
mytable = DbHelperSQL.FillData( "Department ", "TreeCode ", 1, 1, true, "ID= ' " + model.PID + " ' ");
model.TreeCode = mytable.Rows[0][ "TreeCode "].ToString() + "001 ";
}
else
{
string strTreeCode = mytable.Rows[0][ "TreeCode "].ToString();
model.TreeCode = strTreeCode.Substring(0, strTreeCode.Length - 3);
int intTreeCode =1001+ int.Parse(strTreeCode.Substring(strTreeCode.Length - 3, 3));
model.TreeCode = model.TreeC