欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#無限欄目分級程序代碼分享 好東西第3/3頁

 更新時間:2006年12月28日 00:00:00   作者:  

C#無限欄目分級程序代碼分享[3] 核心代碼放送之移動欄目

#region 移動欄目
  public int moveClass(string table,int classid,int target)
  {
   if (!checkExist(table,classid) )
    return 1;//要移動的欄目不存在
   if(target!=0)
   {
    if(!checkExist(table,target))
     return 2;//目標欄目不存在
   }

   //要移動的類別的所有的子欄目
   string moveclassids;  
   moveclassids=getChildren(table,classid);
   string[] arr=moveclassids.Split('','');  
   string temp="," + moveclassids;
   if (temp.IndexOf("," + target.ToString())!=-1)
    return 3;//不能指定該類別的下屬類別作為所屬類別

   string sql;

   #region //先處理要移動的欄目的信息
   string parentpath="";
   int orderid=0,rootid=0,previd=0,nextid=0,depth=0,parentid=0,child=0;
   int last_orderid=0;
   sql="select * from "+ table + " where classid=" + classid;
   IDataReader dr=base.getdr(sql);
   if (dr.Read() )
   {
    parentpath=dr["parentpath"].ToString();
    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"];
   }
   dr.Close();
   dr.Dispose();

   if(depth>0)
    //更新父系欄目的子欄目數(shù)目
    base.exesql("update "+ table +" set child=child-1 where ClassID=" + parentid);

   //修改上一類別的NextID和下一類別的PrevID
   if (previd>0)
    base.exesql("update "+ table +" set NextID=" + nextid + " where ClassID=" + previd);
   if (nextid>0)
    base.exesql("update "+ table +" set PrevID=" + previd + " where ClassID=" + nextid);

   //得到要移動的欄目的子欄目里最大的orderid
   if(child>0)
   {
    sql="select max(orderid) from " + table + " where classid in (" + moveclassids + ")";
    last_orderid=(int)base.getvalue(sql);
    //處理要移動的類別樹后面的欄目的orderid,全部-(arr.Length+1)
    base.exesql("update " + table + " set orderid=orderid-" + (arr.Length+1) + " where orderid>" + last_orderid);
   }
   else
   {
    last_orderid=orderid;
    //處理要移動的類別樹后面的欄目的orderid,全部-1
    base.exesql("update " + table + " set orderid=orderid-1 where orderid>" + last_orderid);
   }

   

   #endregion

   #region//處理目標類別的信息
   string target_parentpath="0";
   int target_orderid=0,target_rootid=0,target_previd=0,target_nextid=0,target_depth=0,target_parentid=0,target_child=0;
   int target_last_child_classid=0;
   int target_last_orderid=0;
   string target_children="";

   #region//是不是作為一級欄目
   if(target>0)
   {
    sql="select * from "+ table + " where classid=" + target;
    dr=base.getdr(sql);
    if (dr.Read() )
    {
     target_parentpath=dr["parentpath"].ToString()+"," + target;//新的父系路徑
     target_orderid=(int)dr["orderid"];
     target_rootid=(int)dr["rootid"];
     target_previd=(int)dr["previd"];
     target_nextid=(int)dr["nextid"];
     target_depth=(int)dr["depth"];
     target_parentid=(int)dr["parentid"];
     target_child=(int)dr["child"];
    }
    dr.Close();
    dr.Dispose();
    //更新目標欄目的子欄目數(shù)目
    base.exesql("update "+ table +" set child=child+1 where ClassID=" + target);

    target_children=this.getChildren(table,target);
    if (target_child>0)
    {
     //如果有子欄目找到最后一個子欄目的orderid
     sql="select max(orderid) from " + table + " where classid in (" + target_children + ")";
     target_last_orderid=(int)base.getvalue(sql);
     //找到目標類別的一級子類別最后一個classid,并更新它的nextid=classid
     sql="select classid from " + table + " where parentid=" + target + " order by orderid desc";
     object temp_=base.getvalue(sql);
     target_last_child_classid=(int)temp_;
     base.exesql("update " + table + " set nextid=" + classid + " where classid=" + target_last_child_classid);
    }
    else
    {
     target_last_orderid=target_orderid;
     target_last_child_classid=0;
    }
    if (child>0)
     //處理目標類別樹后面的欄目的orderid,全部加上(arr.Length+1)
     base.exesql("update " + table + " set orderid=orderid + " + (arr.Length+1) + " where orderid>" + target_last_orderid);
    else
     base.exesql("update " + table + " set orderid=orderid + 1 where orderid>" + target_last_orderid);
   }
   else//作為一級類別
   {
    //重新定義target_depth
    target_depth=-1;
    //重新定義target_last_orderid
    if (child >0)
     sql="select max(orderid) from " + table + " where classid not in (" + (classid + "," + moveclassids) + ")";
     //_______________________________________________________________這里解決當要移動的欄目有子欄目的時候,orderid出現(xiàn)的小問題.
    else
     sql="select max(orderid) from " + table + " where classid<>" + classid;//有可能要移動的類別在最后一個,這里把它排除
    object _temp;
    _temp=base.getvalue(sql);
    if(_temp!=null)
     target_last_orderid=(int)_temp;
    //重新定義target_rootid
    target_rootid=classid;

    //得到previd
    sql="select max(classid) from " + table + " where parentid=0 and classid<>" + classid;
    _temp=base.getvalue(sql);
    if(_temp!=null)
    {
     target_previd=(int)_temp;
     //修改上一個一級欄目的nextid
     base.exesql("update " + table + "set nextid="+ classid + " where classid=" + target_previd);
    }
   }
   #endregion

   #endregion

   #region 綜合處理

   if (child>0)//要移動的類別有子欄目
   {
    int depth_d=0;//depth的減量
    if(target==0)
     depth_d=depth;
    else
     depth_d=depth-(target_depth+1);
    //更新字欄目的父系路徑為 target_parentpath + "," + classid ,orderid
    for(int x=0;x<arr.Length;x++)
    {
     //注意這里要解決depth和parentpath的嵌套問題,即要移動的類別的子類別還有子類別
     string path;
     sql="select parentpath from " + table + " where classid=" + arr[x];
     path=base.getvalue(sql).ToString();
     path=path.Replace((parentpath + "," + classid),(target_parentpath + "," + classid));
     base.exesql("update " + table +" set depth=depth - "+ depth_d +", parentpath=''"+ path + "'',rootid="+ target_rootid +",orderid="+ (target_last_orderid + x + 2) +" where classid=" + arr[x]);
     //__________________________________________________________________________________________________________________________________________________________//其父系欄目已經(jīng)加1,這里至少加2
    }
   }

   if (target>0)//更新要移動的類別的parentpath和previd,rootid,orderid,parentid,depth,nextid,target_previd
    base.exesql("update " + table +" set nextid=0,depth="+ (target_depth+1) +",parentid="+ target +", parentpath=''"+ target_parentpath +"'',previd="+ target_last_child_classid +" ,rootid="+ target_rootid +",orderid="+ (target_last_orderid+1) +" where classid =" + classid);
   else//區(qū)別在于previd
    base.exesql("update " + table +" set previd="+ target_previd +",nextid=0,depth="+ (target_depth+1) +",parentid="+ target +", parentpath=''"+ target_parentpath +"'' ,rootid="+ target_rootid +",orderid="+ (target_last_orderid+1) +" where classid =" + classid);

   #endregion

   return 0;
  }
  #endregion
詳細請看原文:http://ent.omeweb.com/book/content.aspx?id=1802
演示地址:http://ent.omeweb.com/catalog/index.html

相關(guān)文章

最新評論