Made a few fixes to the Text Search Function

Created a Stored Procedure to move Procedures, Sections and Steps
Added set files to READ/WRITE if they are READ ONLY.
This commit is contained in:
Rich 2013-03-12 14:59:13 +00:00
parent 661bf3887d
commit 23ad3d8d7b
2 changed files with 389 additions and 1 deletions

View File

@ -6011,4 +6011,385 @@ IF (@@Error = 0) PRINT 'Procedure Creation: vesp_SortProcedures Succeeded'
ELSE PRINT 'Procedure Creation: vesp_SortProcedures Error on Creation'
GO
/****** Object: StoredProcedure [vefn_RemoveExtraText] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_RemoveExtraText]') AND OBJECTPROPERTY(id,N'IsScalarFunction') = 1)
DROP FUNCTION [vefn_RemoveExtraText];
GO
/*
select text, .dbo.vefn_RemoveExtraText(text,2,0,0) StrippedText from Contents where ContentID=373
select text, .dbo.vefn_RemoveExtraText(text,1,0,0) StrippedText from Contents where ContentID=373
select text, .dbo.vefn_RemoveExtraText(text,0,0,0) StrippedText ,.dbo.vefn_FirstLink(text,0), PATINDEX('%[' + nchar(9516) + nchar(9574) + char(21) + ']%' , text) from Contents where ContentID=373
select .dbo.vefn_RemoveExtraText('\b Bold\b0',0,0,0)
select .dbo.vefn_RemoveExtraText('\b Bold\b0',0,1,0)
select .dbo.vefn_RemoveExtraText('A\u1?B\u12?C\u123?D\u1234?E',0,0,0)
select .dbo.vefn_RemoveExtraText('A\u1?B\u12?C\u123?D\u1234?E',0,0,1)
*/
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE FUNCTION [dbo].[vefn_RemoveExtraText](@text nvarchar(MAX),@includeLink int, @includeRtfFormatting int , @includeSpecialCharacters int)
RETURNS varchar(MAX)
WITH EXECUTE AS OWNER
AS
BEGIN
DECLARE @index int
DECLARE @index2 int
-- Replace Hard Hyphen with Hyphen
SET @text = replace(@text,'\u8209?','-')
-- Replace Hard Space with Space
SET @text = replace(@text,'\u160?',' ')
set @text = replace(@text,nchar(160),' ')
-- Strip Links
IF @includeLink = 0 -- Remove Links
SET @text = [dbo].[vefn_RemoveRange](@text,'<START]' ,'[END>')
IF @includeLink < 2 -- Remove Comments
SET @text = [dbo].[vefn_RemoveRange](@text,'\v' ,'\v0')
if(@includeRtfFormatting=0)
-- Remove Rtf Formatting
BEGIN
SET @text = Replace(@text, '\b0 ', '');
SET @text = Replace(@text, '\b ', '');
SET @text = Replace(@text, '\ulnone ', '');
SET @text = Replace(@text, '\ul0 ', '');
SET @text = Replace(@text, '\ul ', '');
SET @text = Replace(@text, '\i0 ', '');
SET @text = Replace(@text, '\i ', '');
SET @text = Replace(@text, '\super ', '');
SET @text = Replace(@text, '\sub ', '');
SET @text = Replace(@text, '\nosupersub ', '');
SET @text = Replace(@text, '\b0', '');
SET @text = Replace(@text, '\b', '');
SET @text = Replace(@text, '\ul0', '');
SET @text = Replace(@text, '\ul', '');
SET @text = Replace(@text, '\i0', '');
SET @text = Replace(@text, '\i', '');
SET @text = Replace(@text, '\super', '');
SET @text = Replace(@text, '\sub', '');
SET @text = Replace(@text, '\nosupersub', '');
END
if(@includeSpecialCharacters=0)
-- Remove Special Characters
BEGIN
SET @index = PATINDEX('%\u[0-9]?%',@text)
while(@index != 0)
BEGIN
SET @text = substring(@text,1,@index-1) + substring(@text,@index+4,len(@text))
SET @index = PATINDEX('%\u[0-9]?%',@text)
END
SET @index = PATINDEX('%\u[0-9][0-9]?%',@text)
while(@index != 0)
BEGIN
SET @text = substring(@text,1,@index-1) + substring(@text,@index+5,len(@text))
SET @index = PATINDEX('%\u[0-9][0-9]?%',@text)
END
SET @index = PATINDEX('%\u[0-9][0-9][0-9]?%',@text)
while(@index != 0)
BEGIN
SET @text = substring(@text,1,@index-1) + substring(@text,@index+6,len(@text))
SET @index = PATINDEX('%\u[0-9][0-9][0-9]?%',@text)
END
SET @index = PATINDEX('%\u[0-9][0-9][0-9][0-9]?%',@text)
while(@index != 0)
BEGIN
SET @text = substring(@text,1,@index-1) + substring(@text,@index+7,len(@text))
SET @index = PATINDEX('%\u[0-9][0-9][0-9][0-9]?%',@text)
END
SET @index = PATINDEX('%\''[0-9A-Fa-f][0-9A-Fa-f]%',@text)
while(@index != 0)
BEGIN
SET @text = substring(@text,1,@index-1) + substring(@text,@index+4,len(@text))
SET @index = PATINDEX('%\''[0-9A-Fa-f][0-9A-Fa-f]%',@text)
END
END
-- Replace Hyphen with Hard Hyphen
SET @text = replace(@text,'-','\u8209?')
RETURN @text
END
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'ScalarFunction Creation: vefn_RemoveExtraText Succeeded'
ELSE PRINT 'ScalarFunction Creation: vefn_RemoveExtraText Error on Creation'
GO
/****** Object: Table Function [vefn_FindSpecialChars] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FindSpecialChars]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1)
DROP FUNCTION [vefn_FindSpecialChars];
GO
/*
select * from vefn_FindSpecialChars('\u160?\ulnone \u8209?')
select MIN(ContentID) MinContentID,Count(*) HowMany,UChar SpecialChar from Contents
cross apply vefn_FindSpecialChars(text) SC
where text like '%\u[0-9]%'
group by UChar
*/
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2013 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE FUNCTION [dbo].[vefn_FindSpecialChars](@text varchar(MAX))
RETURNS @SpecialChars TABLE
(
uchar varchar(10)
)
WITH EXECUTE AS OWNER
AS
BEGIN
DECLARE @index1 int
DECLARE @index2 int
SET @index1 = -1
SET @index1 = PATINDEX('%\u[0-9]%' , @text)
WHILE (@index1 > 0)
BEGIN
SET @index2 = CHARINDEX('?' , @text, @index1 + 3)
if @index2 > 0
BEGIN
INSERT INTO @SpecialChars VALUES (substring(@text,@index1,1 + @index2-@index1))
SET @Text = substring(@text,@index2 + 1,len(@text))
END
SET @index1 = PATINDEX('%\u[0-9]%' , @text)
END
RETURN
END
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'TableFunction Creation: vefn_FindSpecialChars Succeeded'
ELSE PRINT 'TableFunction Creation: vefn_FindSpecialChars Error on Creation'
GO
/****** Object: Table Function [vefn_FindSpecialChars2] ******/
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_FindSpecialChars2]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1)
DROP FUNCTION [vefn_FindSpecialChars2];
GO
/*
select * from vefn_FindSpecialChars2(nchar(255) + nchar(8209) + nchar(160))
select MIN(ContentID) MinContentID,Count(*) HowMany,UChar SpecialChar from Contents
cross apply vefn_FindSpecialChars2(text) SC
group by UChar
*/
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE FUNCTION [dbo].[vefn_FindSpecialChars2](@text nvarchar(MAX))
RETURNS @SpecialChars TABLE
(
uchar int
)
WITH EXECUTE AS OWNER
AS
BEGIN
WHILE (len(@text) > 0)
BEGIN
if(unicode(@text) > 127)
INSERT INTO @SpecialChars VALUES (unicode(@text))
SET @Text = substring(@text,2,len(@text))
END
RETURN
END
GO
-- Display the status of Proc creation
IF (@@Error = 0) PRINT 'TableFunction Creation: vefn_FindSpecialChars2 Succeeded'
ELSE PRINT 'TableFunction Creation: vefn_FindSpecialChars2 Error on Creation'
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[MoveItem]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [MoveItem];
GO
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2013 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE PROCEDURE [dbo].[MoveItem](@ItemID int, @Index int)
WITH EXECUTE AS OWNER
AS
BEGIN TRY -- Try Block
BEGIN TRANSACTION
DECLARE @ItemsChanged TABLE
(
ItemID int Primary Key
)
DECLARE @Siblings TABLE
(
ItemID int PRIMARY KEY,
Ordinal int
)
DECLARE @OldPreviousID int
SELECT @OldPreviousID = PreviousID FROM [Items] where ItemID = @ItemID
DECLARE @OldNextID int
SELECT @OldNextID = ItemID FROM [Items] where PreviousID = @ItemID
insert into @Siblings select * from vefn_AllSiblingItems(@ItemID)
DECLARE @NewNextID int
SELECT @NewNextID = ItemID from @Siblings where Ordinal = @index
DECLARE @NewPreviousID int
SELECT @NewPreviousID = ItemID from @Siblings where Ordinal = @index -1
--PRINT '****************************************************************'
--PRINT '@ItemID = ' + isnull(Cast( @ItemID as varchar(20)),'{null}')
--PRINT '@OldPreviousID = ' + isnull(Cast( @OldPreviousID as varchar(20)),'{null}')
--PRINT '@OldNextID = ' + isnull(Cast( @OldNextID as varchar(20)),'{null}')
--PRINT '@NewPreviousID = ' + isnull(Cast( @NewPreviousID as varchar(20)),'{null}')
--PRINT '@NewNextID = ' + isnull(Cast( @NewNextID as varchar(20)),'{null}')
Update Items set PreviousID = @NewPreviousID where ItemID = @ItemID
Insert INTO @ItemsChanged Select @ItemID
IF @OldNextID is not Null
BEGIN
Update Items set PreviousID = @OldPreviousID where ItemID = @OldNextID
Insert INTO @ItemsChanged Select @OldNextID
END
IF @NewNextID is not Null
BEGIN
Update Items set PreviousID = @ItemID where ItemID = @NewNextID
Insert INTO @ItemsChanged Select @NewNextID
END
IF @OldPreviousID is null
BEGIN
Update Parts set ItemID = @OldNextID where ItemID = @ItemID
Update DocVersions set ItemID = @OldNextID where ItemID = @ItemID
END
IF @NewPreviousID is null
BEGIN
Update Parts set ItemID = @ItemID where ItemID = @NewNextID
Update DocVersions set ItemID = @ItemID where ItemID = @NewNextID
END
SELECT
ii.[ItemID],
[PreviousID],
ii.[ContentID],
ii.[DTS],
ii.[UserID],
ii.[LastChanged],
(SELECT COUNT(*) FROM [Annotations] WHERE [Annotations].[ItemID]=ii.[ItemID]) [AnnotationCount],
(SELECT COUNT(*) FROM [DocVersions] WHERE [DocVersions].[ItemID]=ii.[ItemID]) [DocVersionCount],
(SELECT COUNT(*) FROM [Items] [Next] WHERE [Next].[PreviousID]=ii.[ItemID]) [NextCount],
(SELECT COUNT(*) FROM [Parts] WHERE [Parts].[ItemID]=ii.[ItemID]) [PartCount],
(SELECT COUNT(*) FROM [Transitions] WHERE [Transitions].[RangeID]=ii.[ItemID]) [Transition_RangeIDCount],
(SELECT COUNT(*) FROM [Transitions] WHERE [Transitions].[ToID]=ii.[ItemID]) [Transition_ToIDCount]
FROM [Items] ii
WHERE ItemID in (Select ItemID from @ItemsChanged)
IF( @@TRANCOUNT > 0 )
BEGIN
PRINT 'COMMIT'
COMMIT
END
END TRY
BEGIN CATCH -- Catch Block
IF( @@TRANCOUNT = 1 )
BEGIN
PRINT 'ROLLBACK'
ROLLBACK -- Only rollback if top level
END
ELSE IF( @@TRANCOUNT > 1 )
BEGIN
PRINT 'COMMIT'
COMMIT -- Otherwise commit. Top level will rollback
END
EXEC vlnErrorHandler
END CATCH
GO
IF (@@Error = 0) PRINT 'Procedure Creation: MoveItem Succeeded'
ELSE PRINT 'Procedure Creation: MoveItem Error on Creation'
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_AllSiblingItems]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1)
DROP FUNCTION [vefn_AllSiblingItems];
GO
/*
DECLARE @ItemID int
select @ItemID = ItemID from DocVersions where VersionID = 1
Select * from vefn_AllSiblingItems(@ItemID) order by Ordinal
*/
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2013 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE FUNCTION [dbo].[vefn_AllSiblingItems](@ItemID int)
RETURNS @Siblings TABLE
(
ItemID int,
Ordinal int
)
WITH EXECUTE AS OWNER
AS
BEGIN
with Itemz([ItemID], [PreviousID], [Ordinal]) as (
Select [ItemID], [PreviousID], case when [PreviousID] is null then 0 else -1 end
FROM [Items]
where [ItemID]=@ItemID
-- Previous Siblings
Union All
select I.[ItemID], I.[PreviousID] ,case when I.[PreviousID] is null then 0 else Z.[Ordinal] -1 end
from Itemz Z
join Items I on I.ItemID = Z.PreviousID
where Z.Ordinal < 0
-- Next Siblings
Union All
select I.[ItemID], I.[PreviousID] ,Z.[Ordinal] +1
from Itemz Z
join Items I on I.PreviousID = Z.ItemID
where Z.Ordinal >= 0
)
insert into @Siblings select ItemID, Ordinal from Itemz Where Ordinal >= 0
OPTION (MAXRECURSION 10000)
RETURN
END
GO
IF (@@Error = 0) PRINT 'TableFunction Creation: vefn_AllSiblingItems Succeeded'
ELSE PRINT 'TableFunction Creation: vefn_AllSiblingItems Error on Creation'
GO
IF EXISTS (SELECT * FROM dbo.sysobjects WHERE id = OBJECT_ID(N'[vefn_JustSiblingItems]') AND OBJECTPROPERTY(id,N'IsTableFunction') = 1)
DROP FUNCTION [vefn_JustSiblingItems];
GO
/*
DECLARE @ItemID int
select @ItemID = ItemID from DocVersions where VersionID = 1
Select * from vefn_JustSiblingItems(@ItemID) order by Ordinal
*/
/*****************************************************************************
Volian Enterprises - Proprietary Information - DO NOT COPY OR DISTRIBUTE
Copyright 2012 - Volian Enterprises, Inc. All rights reserved.
*****************************************************************************/
CREATE FUNCTION [dbo].[vefn_JustSiblingItems](@FirstItemID int)
RETURNS @Siblings TABLE
(
ItemID int PRIMARY KEY,
Ordinal int
)
WITH EXECUTE AS OWNER
AS
BEGIN
with Itemz([ItemID],[Ordinal]) as (
Select [ItemID],0
FROM [Items]
where [ItemID]=@FirstItemID
-- Siblings
Union All
select I.[ItemID],Z.[Ordinal] +1
from Itemz Z
join Items I on I.PreviousID = Z.ItemID
)
insert into @Siblings select ItemID, Ordinal from Itemz
OPTION (MAXRECURSION 10000)
RETURN
END
GO
IF (@@Error = 0) PRINT 'TableFunction Creation: vefn_JustSiblingItems Succeeded'
ELSE PRINT 'TableFunction Creation: vefn_JustSiblingItems Error on Creation'
GO

View File

@ -522,7 +522,10 @@ namespace fmtxml
di = di.GetDirectories("fmtall")[0];
FileInfo[] fis = di.GetFiles("*.xml");
foreach (FileInfo fi in fis)
{
if (fi.IsReadOnly) fi.IsReadOnly = false;
fi.Delete();
}
}
private void btnBrowseFmt_Click(object sender, EventArgs e)
{
@ -559,7 +562,11 @@ namespace fmtxml
// delete current svg's
DirectoryInfo disvg = new DirectoryInfo(tbResultPath.Text + @"\genmacall"); //(@"C:\development\proms.net\genmac.xml");
FileInfo[] fissvg = disvg.GetFiles("*.svg");
foreach (FileInfo fi in fissvg) fi.Delete();
foreach (FileInfo fi in fissvg)
{
if (fi.IsReadOnly) fi.IsReadOnly = false;
fi.Delete();
}
DirectoryInfo di = new DirectoryInfo(tbFmtPath.Text);
FileInfo[] fis = di.GetFiles("*.rtf");