/// <summary> /// 添加栏目 /// </summary> public static int Insert(QuestionType channel) { if (channel.ParentID == 0) { channel.Depth = 0; channel.ParentID = 0; channel.Path = "0~"; channel.NamePath = "所有栏目~"; channel.AddInsert("RootID", "IDENT_CURRENT('QuestionType')"); } else { QuestionType condition = new QuestionType(); condition.ID = channel.ParentID; QuestionType parentChannel = TableOperate <QuestionType> .GetRowData(condition); string path = Convert.ToString(parentChannel.Path) + channel.ParentID + "~"; string namePath = Convert.ToString(parentChannel.NamePath) + Convert.ToString(parentChannel.Name) + "~"; channel.Depth = parentChannel.Depth + 1; channel.Path = path; channel.RootID = parentChannel.RootID; channel.NamePath = namePath; } return(TableOperate <QuestionType> .InsertReturnID(channel)); }
/// <summary> /// 修改栏目 /// </summary> public static int Update(QuestionType channel) { //修改信息 QuestionType condition = new QuestionType(); condition.ID = channel.ID; QuestionType oldChannel = TableOperate <QuestionType> .GetRowData(condition); if (channel.ParentID != oldChannel.ParentID) { if (channel.ParentID == 0) { channel.Depth = 0; channel.ParentID = 0; channel.Path = "0~"; channel.NamePath = "所有栏目~"; channel.AddInsert("RootID", "IDENT_CURRENT('QuestionType')"); } else { condition = new QuestionType(); condition.ID = channel.ParentID; QuestionType parentChannel = TableOperate <QuestionType> .GetRowData(condition); string path = Convert.ToString(parentChannel.Path) + channel.ParentID + "~"; string namePath = Convert.ToString(parentChannel.NamePath) + Convert.ToString(parentChannel.Name) + "~"; channel.Depth = parentChannel.Depth + 1; channel.Path = path; channel.RootID = parentChannel.RootID; channel.NamePath = namePath; } } else { channel.Depth = oldChannel.Depth; channel.Path = oldChannel.Path; channel.NamePath = oldChannel.NamePath; channel.RootID = oldChannel.RootID; } //修改下面是有的子项的Depth, Path, RootID, NamePath UpdateChild(channel, oldChannel); return(TableOperate <QuestionType> .Update(channel)); }