//获取旧数据
DataTable tab = DbHelperSql.Query("select * from [Company] where id=" + model.Id).Tables[0];
string OldPid = tab.Rows[0]["Pid"].ToString();
if (OldPid != model.Pid.ToString())//如果新的Pid与就的Pid不同则修改本条记录和子记录的Path
{
string OldSunPath = tab.Rows[0]["Path"].ToString()==""? model.Id.ToString() : tab.Rows[0]["Path"].ToString()+"," + model.Id.ToString();
object o = DbHelperSql.GetSingle("select case path when '' then '' else path+',' end + cast(id as varchar) from [Company] where id=" + model.Pid);
string Path = o == null ? "" : o.ToString();
model.Path = Path;
string SunPath = Path == "" ? model.Id.ToString() : Path + "," + model.Id.ToString();//获取子节点的
DbHelperSql.ExecuteSql("update [Company] set Path=replace(Path,'" + OldSunPath + "','" + SunPath + "') where Path+',' like '" + OldSunPath + ",%' or Path='"+ OldSunPath + "'");
}
父类,完整路径,Pid,Path 无限级修改完整路径
最新推荐文章于 2022-08-11 10:09:22 发布