SoFunction
Updated on 2025-04-13

C# unlimited column hierarchical program code sharing Good stuff


C# unlimited column hierarchical program code sharing [3] Core code broadcast mobile column

#region Mobile column
  public int moveClass(string table,int classid,int target)
  {
   if (!checkExist(table,classid) )
return 1;//The column to be moved does not exist
   if(target!=0)
   {
    if(!checkExist(table,target))
return 2;//The target column does not exist
   }

//All sub-columns of the category to be moved
   string moveclassids;  
   moveclassids=getChildren(table,classid);
   string[] arr=('','');  
   string temp="," + moveclassids;
   if (("," + ())!=-1)
return 3;//The subordinate category of this category cannot be specified as the category to which it belongs

   string sql;

#region//First process the information of the column to be moved
   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 classparentpath"].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"];
   }
   ();
   ();

   if(depth>0)
//Update the number of child columns of parent columns
    ("update "+ table +" set child=child-1 where ClassID=" + parentid);

//Modify the NextID of the previous category and the PrevID of the next category
   if (previd>0)
    ("update "+ table +" set NextID=" + nextid + " where ClassID=" + previd);
   if (nextid>0)
    ("update "+ table +" set PrevID=" + previd + " where ClassID=" + nextid);

//Get the largest orderid in the sub-column of the column to be moved
   if(child>0)
   {
    sql="select max(orderid) from " + table + " where classid in (" + moveclassids + ")";
    last_orderid=(int)(sql);
//Processing the orderid of the column behind the category tree to be moved, all-(+1)
    ("update " + table + " set orderid=orderid-" + (+1) + " where orderid>" + last_orderid);
   }
   else
   {
    last_orderid=orderid;
//Processing the orderid of the column behind the category tree to be moved, all-1
    ("update " + table + " set orderid=orderid-1 where orderid>" + last_orderid);
   }

   

   #endregion

#region//Processing information about target categories
   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//Is it a first-level column?
   if(target>0)
   {
sql="select * from "+ table + " where classparentpath"].ToString()+"," + target;//New Paternal Path
     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"];
    }
    ();
    ();
//Update the number of sub-columns of the target column
    ("update "+ table +" set child=child+1 where ClassID=" + target);

    target_children=(table,target);
    if (target_child>0)
    {
//If there is a sub-column, it will be found in the orderid of the last sub-column
     sql="select max(orderid) from " + table + " where classid in (" + target_children + ")";
     target_last_orderid=(int)(sql);
//Find the last classid of the first-level subcategory of the target category and update its nextid=classid
     sql="select classid from " + table + " where parent order by orderid desc";
     object temp_=(sql);
     target_last_child_classid=(int)temp_;
     ("update " + table + " set next where classupdate " + table + " set orderid=orderid + " + (+1) + " where orderid>" + target_last_orderid);
    else
     ("update " + table + " set orderid=orderid + 1 where orderid>" + target_last_orderid);
   }
else//As a first-level category
   {
//Redefine target_depth
    target_depth=-1;
//Redefine target_last_orderid
    if (child >0)
     sql="select max(orderid) from " + table + " where classid not in (" + (classid + "," + moveclassids) + ")";
//_____________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________________
    else
sql="select max(orderid) from " + table + " where classid<>" + classid;//The category that may be moved is the last one, exclude it here
    object _temp;
    _temp=(sql);
    if(_temp!=null)
     target_last_orderid=(int)_temp;
//Redefine target_rootid
    target_rootid=classid;

//Get previd
    sql="select max(classid) from " + table + " where parentid=0 and classid<>" + classid;
    _temp=(sql);
    if(_temp!=null)
    {
     target_previd=(int)_temp;
//Modify the nextid of the previous first-level column
     ("update " + table + "set next where class," + classid ,orderid
    for(int x=0;x<;x++)
    {
//Note that we need to solve the nesting problem of depth and parentpath, that is, the subcategory and subcategory of the category to be moved
     string path;
     sql="select parentpath from " + table + " where class," + classid),(target_parentpath + "," + classid));
     ("update " + table +" set depth=depth - "+ depth_d +", parentpath=''"+ path + "'',root,order where classupdate " + table +" set nextid=0,depth="+ (target_depth+1) +",parent, parentpath=''"+ target_parentpath +"'',prev ,root,order where classid =" + classid);
else//The difference is previd
    ("update " + table +" set prev,nextid=0,depth="+ (target_depth+1) +",parent, parentpath=''"+ target_parentpath +"'' ,root,order where classid =" + classid);

   #endregion

   return 0;
  }
  #endregion
For details, please see the original text:/book/?id=1802
Demo address:/catalog/