cs_LinkCategory_UpdateSortOrder
ALTER procedure [dbo].cs_LinkCategory_UpdateSortOrder
(
@LinkCategoryID int,
@SettingsID int,
@MoveUp bit
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
BEGIN
set nocount on
/**//*当 SET NOCOUNT 为 ON 时,不返回计数(表示受 Transact-SQL 语句影响的行数)。
当 SET NOCOUNT 为 OFF 时,返回计数。即使当 SET NOCOUNT 为 ON 时,也更新
@@ROWCOUNT 函数。*/
DECLARE @currentSortValue int
DECLARE @replaceSortValue int
DECLARE @replaceLinkCategoryID int
DECLARE @SectionID int
-- Get the current sort order
-- 获取当前排序类型
SELECT @currentSortValue = SortOrder, @SectionID = SectionID FROM cs_LinkCategories WHERE LinkCategoryID = @LinkCategoryID and SettingsID = @SettingsID
-- Move the item up or down?
IF (@MoveUp = 1)
BEGIN
SELECT @replaceSortValue = coalesce(f.SortOrder, -1), @replaceLinkCategoryID = coalesce(f.LinkCategoryID, -1)
FROM cs_LinkCategories f
inner join (
select top 1 *
from cs_LinkCategories
WHERE SectionID = @SectionID and SortOrder < @currentSortValue and SettingsID = @SettingsID order by SortOrder DESC
) as pf on
pf.LinkCategoryID = f.LinkCategoryID and f.SettingsID = @SettingsID
if( @replaceSortValue != -1 And @replaceSortValue is Not Null )
begin
UPDATE cs_LinkCategories SET SortOrder = @currentSortValue WHERE LinkCategoryID = @replaceLinkCategoryID and SettingsID = @SettingsID
UPDATE cs_LinkCategories SET SortOrder = @replaceSortValue WHERE LinkCategoryID = @LinkCategoryID and SettingsID = @SettingsID
END
END
ELSE
BEGIN
SELECT @replaceSortValue = coalesce(f.SortOrder, -1), @replaceLinkCategoryID = coalesce(f.LinkCategoryID, -1)
FROM cs_LinkCategories f
inner join (
select top 1 *
FROM cs_LinkCategories
WHERE SectionID = @SectionID and SortOrder > @currentSortValue and SettingsID = @SettingsID order by SortOrder ASC
) as pf on
pf.LinkCategoryID = f.LinkCategoryID and f.SettingsID = @SettingsID
if( @replaceSortValue != -1 And @replaceSortValue is Not Null )
begin
UPDATE cs_LinkCategories SET SortOrder = @currentSortValue WHERE LinkCategoryID = @replaceLinkCategoryID and SettingsID = @SettingsID
UPDATE cs_LinkCategories SET SortOrder = @replaceSortValue WHERE LinkCategoryID = @LinkCategoryID and SettingsID = @SettingsID
end
END
END
ALTER procedure [dbo].cs_LinkCategory_UpdateSortOrder
(
@LinkCategoryID int,
@SettingsID int,
@MoveUp bit
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
BEGIN
set nocount on
/**//*当 SET NOCOUNT 为 ON 时,不返回计数(表示受 Transact-SQL 语句影响的行数)。
当 SET NOCOUNT 为 OFF 时,返回计数。即使当 SET NOCOUNT 为 ON 时,也更新
@@ROWCOUNT 函数。*/
DECLARE @currentSortValue int
DECLARE @replaceSortValue int
DECLARE @replaceLinkCategoryID int
DECLARE @SectionID int
-- Get the current sort order
-- 获取当前排序类型
SELECT @currentSortValue = SortOrder, @SectionID = SectionID FROM cs_LinkCategories WHERE LinkCategoryID = @LinkCategoryID and SettingsID = @SettingsID
-- Move the item up or down?
IF (@MoveUp = 1)
BEGIN
SELECT @replaceSortValue = coalesce(f.SortOrder, -1), @replaceLinkCategoryID = coalesce(f.LinkCategoryID, -1)
FROM cs_LinkCategories f
inner join (
select top 1 *
from cs_LinkCategories
WHERE SectionID = @SectionID and SortOrder < @currentSortValue and SettingsID = @SettingsID order by SortOrder DESC
) as pf on
pf.LinkCategoryID = f.LinkCategoryID and f.SettingsID = @SettingsID
if( @replaceSortValue != -1 And @replaceSortValue is Not Null )
begin
UPDATE cs_LinkCategories SET SortOrder = @currentSortValue WHERE LinkCategoryID = @replaceLinkCategoryID and SettingsID = @SettingsID
UPDATE cs_LinkCategories SET SortOrder = @replaceSortValue WHERE LinkCategoryID = @LinkCategoryID and SettingsID = @SettingsID
END
END
ELSE
BEGIN
SELECT @replaceSortValue = coalesce(f.SortOrder, -1), @replaceLinkCategoryID = coalesce(f.LinkCategoryID, -1)
FROM cs_LinkCategories f
inner join (
select top 1 *
FROM cs_LinkCategories
WHERE SectionID = @SectionID and SortOrder > @currentSortValue and SettingsID = @SettingsID order by SortOrder ASC
) as pf on
pf.LinkCategoryID = f.LinkCategoryID and f.SettingsID = @SettingsID
if( @replaceSortValue != -1 And @replaceSortValue is Not Null )
begin
UPDATE cs_LinkCategories SET SortOrder = @currentSortValue WHERE LinkCategoryID = @replaceLinkCategoryID and SettingsID = @SettingsID
UPDATE cs_LinkCategories SET SortOrder = @replaceSortValue WHERE LinkCategoryID = @LinkCategoryID and SettingsID = @SettingsID
end
END
END
cs_LinkCategory_CreateUpdateDelete
ALTER PROCEDURE dbo.cs_LinkCategory_CreateUpdateDelete
@DeleteLinkCategory bit=0,
@SectionID int,
@Name nvarchar(256)='',
@Description nvarchar(2000)=null,
@IsEnabled bit=1,
@SortOrder int=0,
@SettingsID int,
@LinkCategoryID int=0 out
AS
SET Transaction Isolation Level Read UNCOMMITTED
-- Are we deleting?
-- 判断删除
if @DeleteLinkCategory = 1
begin
DELETE FROM cs_Links WHERE LinkCategoryID = @LinkCategoryID and SettingsID = @SettingsID
DELETE FROM cs_LinkCategories WHERE LinkCategoryID = @LinkCategoryID and SectionID = @SectionID and SettingsID = @SettingsID
RETURN
end
-- Are we updating?
-- 判断更新
if @LinkCategoryID > 0
begin
UPDATE cs_LinkCategories SET
[Name] = @Name,
[Description] = @Description,
IsEnabled = @IsEnabled,
SortOrder = @SortOrder
WHERE LinkCategoryID = @LinkCategoryID and SectionID = @SectionID and SettingsID = @SettingsID
end
else
begin -- 下面是添加
If( @SortOrder = 0 )
Begin
Select @SortOrder = max(SortOrder) + 1 from cs_LinkCategories where SectionID = @SectionID and SettingsID = @SettingsID
if(@SortOrder is null)
Select @SortOrder = 0
End
INSERT INTO cs_LinkCategories (SectionID, [Name], [Description], IsEnabled, SortOrder, SettingsID)
VALUES (@SectionID, @Name, @Description, @IsEnabled, @SortOrder, @SettingsID)
set @LinkCategoryID = @@IDENTITY
end
ALTER PROCEDURE dbo.cs_LinkCategory_CreateUpdateDelete
@DeleteLinkCategory bit=0,
@SectionID int,
@Name nvarchar(256)='',
@Description nvarchar(2000)=null,
@IsEnabled bit=1,
@SortOrder int=0,
@SettingsID int,
@LinkCategoryID int=0 out
AS
SET Transaction Isolation Level Read UNCOMMITTED
-- Are we deleting?
-- 判断删除
if @DeleteLinkCategory = 1
begin
DELETE FROM cs_Links WHERE LinkCategoryID = @LinkCategoryID and SettingsID = @SettingsID
DELETE FROM cs_LinkCategories WHERE LinkCategoryID = @LinkCategoryID and SectionID = @SectionID and SettingsID = @SettingsID
RETURN
end
-- Are we updating?
-- 判断更新
if @LinkCategoryID > 0
begin
UPDATE cs_LinkCategories SET
[Name] = @Name,
[Description] = @Description,
IsEnabled = @IsEnabled,
SortOrder = @SortOrder
WHERE LinkCategoryID = @LinkCategoryID and SectionID = @SectionID and SettingsID = @SettingsID
end
else
begin -- 下面是添加
If( @SortOrder = 0 )
Begin
Select @SortOrder = max(SortOrder) + 1 from cs_LinkCategories where SectionID = @SectionID and SettingsID = @SettingsID
if(@SortOrder is null)
Select @SortOrder = 0
End
INSERT INTO cs_LinkCategories (SectionID, [Name], [Description], IsEnabled, SortOrder, SettingsID)
VALUES (@SectionID, @Name, @Description, @IsEnabled, @SortOrder, @SettingsID)
set @LinkCategoryID = @@IDENTITY
end
cs_LinkCategories_Get
ALTER PROCEDURE dbo.cs_LinkCategories_Get
(
@SectionID int,
@SettingsID int,
@PreLoadLinks bit
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
-- Categories 查询种类的信息
SELECT [LinkCategoryID], [SectionID], [Name], [Description], [IsEnabled], [SortOrder], [SettingsID]
FROM cs_LinkCategories
WHERE SectionID = @SectionID and SettingsID = @SettingsID
Order By SortOrder
-- Do we need to return links as well?
-- 是否也要返回连接?
IF (@PreLoadLinks = 1)
BEGIN
SELECT [LinkID], l.[LinkCategoryID], [Title], [Url], l.[IsEnabled], l.[SortOrder], l.[SettingsID], [Rel], l.[Description], [DateCreated]
FROM cs_Links l inner join cs_LinkCategories c on l.LinkCategoryID = c.LinkCategoryID
WHERE c.SectionID = @SectionID and c.SettingsID = @SettingsID
Order By c.SortOrder, l.SortOrder
END
ALTER PROCEDURE dbo.cs_LinkCategories_Get
(
@SectionID int,
@SettingsID int,
@PreLoadLinks bit
)
AS
SET Transaction Isolation Level Read UNCOMMITTED
/**//*设置事务隔离级别,Read UNCOMMITTED 执行脏读或 0 级隔离锁定,这表示不发出共享锁,
也不接受排它锁。当设置该选项时,可以对数据执行未提交读或脏读;在事务结束前可以更
改数据内的数值,行也可以出现在数据集中或从数据集消失。该选项的作用与在事务内所有
语句中的所有表上设置 NOLOCK 相同。这是四个隔离级别中限制最小的级别。*/
-- Categories 查询种类的信息
SELECT [LinkCategoryID], [SectionID], [Name], [Description], [IsEnabled], [SortOrder], [SettingsID]
FROM cs_LinkCategories
WHERE SectionID = @SectionID and SettingsID = @SettingsID
Order By SortOrder
-- Do we need to return links as well?
-- 是否也要返回连接?
IF (@PreLoadLinks = 1)
BEGIN
SELECT [LinkID], l.[LinkCategoryID], [Title], [Url], l.[IsEnabled], l.[SortOrder], l.[SettingsID], [Rel], l.[Description], [DateCreated]
FROM cs_Links l inner join cs_LinkCategories c on l.LinkCategoryID = c.LinkCategoryID
WHERE c.SectionID = @SectionID and c.SettingsID = @SettingsID
Order By c.SortOrder, l.SortOrder
END