哈哈,好的告訴我email我來發給你
解决方案 »
- 为什么COM组件在C#的引用中总显示版本为1.0呢?
- c#实现更新~~~~
- 索引超出范围。必须为非负值并小于集合大小。
- InstallShield 制作安装包问题
- 怎样彻底断开SQL活动链接
- 用C#和System.Net.Mail发送到邮箱里的邮件正常,但用jmail接收回来时标题全是乱码,内容有少部分乱码,如何解决。看样本:
- 关于XmlDocument .CreateElement(string , string) 设置 namespaceURI 问题
- 在线等待,请高手指点,关于C#实现HTTP或是FTP文件下载的问题
- 如何用ado.net获取一个数据库中的所有表名。(数据库不定)
- 调试的时候,断点不能命中
- 怎么用C#制作ActiveX控件,或者是OCX也行啊,只要能在JS中调用就可以!
- 右键菜单中的剪切、复制、粘贴和删除怎么用代码实现?
每個節點有BOM編號和自身的節點編號,以及上級節點編號
我的方法是每拷貝一個節點就將源節點的子節點拷貝並且把上級節點編號修改成剛拷貝生成的那個節點的編號,我在程序裡面處理的,效率不理想
所以想寫個存儲過程
1. COPY的节点允许放在父节点下吗还是处于根的位置?
2. 如果新节点没有父节点,pid如何处理?
3. “傳入一個整形數組”其中數組的的含义是什么?代表多个被复制的ID还是...
4. 传入的参数是什么作用?新节点的父ID还是被复制的ID?
是否只要返回 ID, P_ID的一个集合?
1.本來是在什麼節點下面的就還是按照同樣的結構拷貝
2.=0
3.比如我想拷貝一些節點int[] ids = new int[]{1,5,6};那麼就得把ID為1,5,6的節點和子節點進行拷貝
4. see point above
最后從該臨時表取數據即可。
你直接給我個代碼看看
比如(執行前,節點內容如下)
id=10 的pID = 1
id=11 的pID = 3
id=12 的pID = 5
id=13 的pID = 6
id=14 的pID = 13
id=15 的pID = 10
那麼當傳入"1,3,5,6"後,需要構建一批新節點
摹擬生成的新節點(執行後,源節點ID 這一欄不必要,是我為了對照才寫上去的)
源節點ID ID pID
1 20 0 (因為,1,3,5,6本來的pID=0)
3 21 0
5 22 0
6 23 0
10 24 20
11 25 21
12 26 22
13 27 23
14 28 27
15 29 24
說實話,存儲過程也很麻煩的
畢竟是自動編號
所以就添加了一個字段oid
記錄下源節點編號
然後提取出源節點集和目標節點集(已經生成的新的)
然後對照目標節點OID的值去原來的節點集合中搜對應的節點,找到pid再到目標節點集裡面找
oid=源pid的節點,得到其id存到目標節點的pid裡面去即可
因為所有操作都在內存中操作的,提取數據一次回存數據一次,總共兩次和數據庫通訊
效率鍋的去
--创建数据测试环境
create table #tb(id int identity(1,1),parentid int,name varchar(10))
insert into #tb
select 0,'中国'
union all select 1,'广东'
union all select 1,'广西'
union all select 1,'四川'
union all select 2,'广州'
union all select 2,'佛山'
union all select 2,'东莞'
union all select 5,'越秀区'
union all select 5,'海珠区'
union all select 5,'芳村'
union all select 6,'禅城区'
union all select 6,'南海区'
union all select 11,'石湾'
go--创建复制的存储过程
create proc p_copy
@s_id int, --复制该项下的所有子项
@d_id int --复制到此项下
as
declare @nid int,@oid int,@name varchar(10)
select id,name into #temp from #tb where parentid=@s_id
while exists(select 1 from #temp)
begin
select @oid=id,@name=name from #temp
insert into #tb values(@d_id,@name)
set @nid=@@identity
exec p_copy @oid,@nid
delete from #temp where id=@oid
end
go--测试
exec p_copy 2,3--显示处理结果
select * from #tbgo
--删除数据测试环境
drop proc p_copy
drop table #tb
--创建数据测试环境
create table #tb(id int identity(1,1),parentid int,name varchar(10))
insert into #tb
select 0,'中国'
union all select 1,'广东'
union all select 1,'广西'
union all select 1,'四川'
union all select 2,'广州'
union all select 2,'佛山'
union all select 2,'东莞'
union all select 5,'越秀区'
union all select 5,'海珠区'
union all select 5,'芳村'
union all select 6,'禅城区'
union all select 6,'南海区'
union all select 11,'石湾'go
--创建复制的存储过程
create proc p_copy
@s_id int, --复制该项下的所有子项
@d_id int, --复制到此项下
@new_id int --新增加项的开始编号
as
declare @nid int,@oid int,@name varchar(10)
select id,name into #temp from #tb where parentid=@s_id and id<@new_id
while exists(select 1 from #temp)
begin
select @oid=id,@name=name from #temp
insert into #tb values(@d_id,@name)
set @nid=@@identity
exec p_copy @oid,@nid,@new_id
delete from #temp where id=@oid
end
go--创建批量复制的存储过程
create proc p_copystr
@s_id varchar(8000) --要复制项的列表,用逗号分隔
as
declare @nid int,@oid int,@name varchar(10)
set @s_id=','+@s_id+','
select id,name into #temp from #tb
where charindex(','+cast(id as varchar)+',', @s_id)>0
while exists(select 1 from #temp)
begin
select @oid=id,@name=name from #temp
insert into #tb values(@oid,@name)
set @nid=@@identity
print @oid
print @nid
exec p_copy @oid,@nid,@nid
delete from #temp where id=@oid
end
go--测试
exec p_copystr '5,6'--显示处理结果
select * from #tbgo
--删除数据测试环境
drop proc p_copystr,p_copy
drop table #tb