C#无限栏目分级程序代码分享 好东西第2/3页
更新时间:2006年12月28日 00:00:00 作者:
C#无限栏目分级程序代码分享[3] 核心代码放送之清空、排序
using System;
using System.Data;
namespace catalog
{
/// <summary>
/// action 的摘要说明。
/// </summary>
public class action:db
{
private static bool[] ShowLine_={false,false,false,false,false,false,false,false,false,false};
private static System.Collections.ArrayList ShowLine=new System.Collections.ArrayList(ShowLine_);
public action()
{
}
public void deleteAllCatalog(string table)
{
string sql="delete from " + table;
base.exesql(sql);
}
public int downClass(string table,int classid)
{
string sql;
sql="select * from " + table + " where classid=" + classid;
int orderid=0,rootid=0,previd=0,nextid=0,depth=0,parentid=0,child=0;
IDataReader dr=base.getdr(sql);
if (dr.Read() )
{
orderid=(int)dr["orderid"];
rootid=(int)dr["rootid"];
previd=(int)dr["previd"];
nextid=(int)dr["nextid"];
depth=(int)dr["depth"];
parentid=(int)dr["parentid"];
child=(int)dr["child"];
}
else
{
dr.Close();
dr.Dispose();
return 1;//要下降排序的栏目不存在
}
dr.Close();
dr.Dispose();
if (nextid==0)
return 2;//要下降排序的栏目下面没有栏目,无法被下降
if (nextid==0 && previd==0)
return 3;//要下降排序的栏目的这一级别只有它一个,没办法被提升
return upClass(table,nextid);
}
#region 向上移动栏目
public int upClass(string table,int classid)
{
string sql;
//先得到要提升的classid的栏目信息
sql="select * from " + table + " where classid=" + classid;
int orderid=0,rootid=0,previd=0,nextid=0,depth=0,parentid=0,child=0;
IDataReader dr=base.getdr(sql);
if (dr.Read() )
{
orderid=(int)dr["orderid"];
rootid=(int)dr["rootid"];
previd=(int)dr["previd"];
nextid=(int)dr["nextid"];
depth=(int)dr["depth"];
parentid=(int)dr["parentid"];
child=(int)dr["child"];
}
else
{
dr.Close();
dr.Dispose();
return 1;//要提升排序的栏目不存在
}
dr.Close();
dr.Dispose();
if (previd==0)
return 2;//要提升排序的栏目上面没有栏目,无法被提升
if (nextid==0 && previd==0)
return 3;//要提升排序的栏目的这一级别只有它一个,没办法被提升
//得到上面一个栏目的信息
sql="select * from " + table + " where classid=" + previd;
int orderid_=0,rootid_=0,previd_=0,nextid_=0,depth_=0,parentid_=0,child_=0;
dr=base.getdr(sql);
if (dr.Read() )
{
orderid_=(int)dr["orderid"];
rootid_=(int)dr["rootid"];
previd_=(int)dr["previd"];
nextid_=(int)dr["nextid"];
depth_=(int)dr["depth"];
parentid_=(int)dr["parentid"];
child_=(int)dr["child"];
}
else
{
dr.Close();
dr.Dispose();
return 4;//要提升排序的栏目的上面的栏目不存在,被非法删除
}
dr.Close();
dr.Dispose();
//把原来previd=classid的换为previd=previd
sql="update "+ table + " set previd=" + previd + " where previd=" + classid;
base.exesql(sql);
//把原来nextid=previd换为classid
sql="update "+ table + " set nextid=" + classid + " where nextid=" + previd;
base.exesql(sql);
//处理提升的栏目nextid->previd,previd->previd_,orderid->orderid_
sql="update "+ table + " set nextid=" + previd + ",previd=" + previd_ + " where classid=" + classid;
base.exesql(sql);
int child_num=0,child_num_=0;//两个栏目的子栏目数目
string[] temp;
string children,children_;
children="0";
children_="0";
if (child>0)
{
children=getChildren(table,classid);
temp=children.Split('','');
child_num=temp.Length;
}
if (child_>0)
{
children_=getChildren(table,previd);
temp=children_.Split('','');
child_num_=temp.Length;
}
//处理上一个栏目nextid->nextid,previd->classid
sql="update "+ table + " set nextid=" + nextid + ",previd=" + classid + " where classid=" + previd;
base.exesql(sql);
sql="update " + table + " set orderid=orderid - "+ (child_num_+1) + " where classid in ("+ (classid + "," + children) +")";
base.exesql(sql);
sql="update " + table + " set orderid=orderid + "+ (child_num+1) + " where classid in ("+ (previd + "," + children_) +")";
base.exesql(sql);
return 0;
}
#endregion
查看原文:http://ent.omeweb.com/book/content.aspx?id=1804
最新评论