More Notes:
Repository.ascx.vb Line 219 in my Modded Code
Add a new sort type here:
If CType(Settings("defaultsort"), String) <> "" Then
Select Case CType(Settings("defaultsort"), String)
Case "0"
mSortOrder = "UpdatedDate"
Case "1"
mSortOrder = "Downloads"
Case "2"
mSortOrder = "RatingAverage"
Case "3"
mSortOrder = "Name"
Case "4"
mSortOrder = "Author"
Case "5"
mSortOrder = "CustomOrder" ' Added by Tom Harris
End Select
Else
mSortOrder = "UpdatedDate"
End If
-----------------------------------------------------------------------------------------------------------
Repository.ascx.vb Line 1182 in my Modded Code
Case "SORT"
Dim objDDL As New DropDownList
Dim objItem As ListItem
objDDL.EnableViewState = True
objDDL.ID = "cboSort"
objDDL.AutoPostBack = True
objItem = New ListItem(Localization.GetString("SortByDate", LocalResourceFile), "UpdatedDate")
objDDL.Items.Add(objItem)
objItem = New ListItem(Localization.GetString("SortByDownloads", LocalResourceFile), "Downloads")
objDDL.Items.Add(objItem)
objItem = New ListItem(Localization.GetString("SortByUserRating", LocalResourceFile), "RatingAverage")
objDDL.Items.Add(objItem)
objItem = New ListItem(Localization.GetString("SortByTitle", LocalResourceFile), "Name")
objDDL.Items.Add(objItem)
objItem = New ListItem(Localization.GetString("SortByAuthor", LocalResourceFile), "Author")
objDDL.Items.Add(objItem)
' Added by Tom Harris for the CustomOrder sort
objItem = New ListItem(Localization.GetString("SortByCustom", LocalResourceFile), "CustomOrder")
objDDL.Items.Add(objItem)
If mSortOrder <> "" Then
objDDL.Items.FindByValue(mSortOrder).Selected = True
End If
objDDL.CssClass = oRepositoryBusinessController.GetSkinAttribute(xmlHeaderDoc, "SORT", "CssClass", "normal")
AddHandler objDDL.SelectedIndexChanged, AddressOf cboSortOrder_SelectedIndexChanged
hPlaceHolder.Controls.Add(objDDL)
-----------------------------------------------------------------------------------------------------------
RepositoryDB.vb Line 89
' initialization
Public Sub New()
_ItemID = -1
_ModuleId = -1
_CreatedByUser = ""
_CreatedDate = Date.Now()
_UpdatedByUser = ""
_UpdatedDate = Date.Now()
_Name = ""
_Description = ""
_Author = ""
_AuthorEMail = ""
_FileSize = ""
_Downloads = 0
_PreviewImage = ""
_Image = ""
_FileName = ""
_Clicks = 0
_RatingVotes = 0
_RatingTotal = 0
_RatingAverage = 0
_CommentCount = 0
_Approved = 0
_ShowEMail = -1
_Summary = ""
_OrderNumber = 0 'Added by Tom Harris
End Sub
----------------------------------------------------------------------------------------------------------
RepositoryDB.vb Line 89 Line 299
'Add new property
'Added by Tom Harris
Public Property OrderNumber() As Integer
Get
Return _OrderNumber
End Get
Set(ByVal Value As Integer)
_OrderNumber = Value
End Set
End Property
-------------------------------------------------------------------------------------------------------------------------
Repository Settings.ascx.vb Line 1055
Added by Tom Harris
Sub MoveRecord(ByVal Sender As Object, ByVal E As DataGridCommandEventArgs, ByVal position1 As Integer, ByVal ItemId1 As Integer, ByVal position2 As Integer, ByVal ItemId2 As Integer)
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'ToDo Add to Data Access Provider
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Dim myConnection As New SqlConnection(ConnectionString)
Dim UpdateCommand As SqlCommand = New SqlCommand
UpdateCommand.Connection = myConnection
'Message.Text = "Position1=" & position1 & " Position2=" & position2
UpdateCommand.CommandText = "UPDATE grmRepositoryObjects SET OrderNumber = " & position1 & " WHERE ItemId = " & ItemId2
myConnection.Open()
UpdateCommand.ExecuteNonQuery()
myConnection.Close()
Dim UpdateCommand2 As SqlCommand = New SqlCommand
UpdateCommand2.Connection = myConnection
UpdateCommand2.CommandText = "UPDATE grmRepositoryObjects SET OrderNumber = " & position2 & " WHERE ItemId = " & ItemId1
myConnection.Open()
UpdateCommand2.ExecuteNonQuery()
myConnection.Close()
' Resort the grid for new records
If AddingNew = True Then
MediaSortGrid.CurrentPageIndex = 0
AddingNew = False
End If
' rebind the grid
MediaSortGrid.EditItemIndex = -1
BindGrid()
End Sub
--------------------------------------------------------------------------
Stored Procedure grmAddRepositoryObject
// You don't need to add anything her if you add a new sort.
// you do need this for CustomOrder though
ALTER procedure [dbo].[grmAddRepositoryObject]
@UserName nvarchar(150),
@ModuleID int,
@Name nvarchar(50),
@Description ntext,
@Author nvarchar(150),
@AuthorEMail nvarchar(150),
@FileSize nvarchar(12),
@PreviewImage nvarchar(150),
@Image nvarchar(150),
@FileName nvarchar(150),
@Approved int,
@ShowEMail int,
@Summary ntext
as
DECLARE @OrderNumber int
Set @OrderNumber = IDENT_CURRENT('dbo.grmRepositoryObjects') + 1
insert into dbo.grmRepositoryObjects (
CreatedByUser,
CreatedDate,
UpdatedByUser,
UpdatedDate,
ModuleID,
[Name],
[Description],
Author,
AuthorEMail,
FileSize,
Downloads,
PreviewImage,
[Image],
[FileName],
Clicks,
RatingVotes,
RatingTotal,
RatingAverage,
Approved,
ShowEMail,
Summary,
OrderNumber
)
values (
@UserName,
getdate(),
@UserName,
getdate(),
@ModuleID,
@Name,
@Description,
@Author,
@AuthorEMail,
@FileSize,
0,
@PreviewImage,
@Image,
@FileName,
0,
0,
0,
0,
@Approved,
@ShowEMail,
@Summary,
@OrderNumber
)
select SCOPE_IDENTITY()
------------------------------------------------------------------------------------
Tom Harris changes to Stored Procedure
Stored Procedure Changes grmGetRepositoryObjects add your new sort options here: CASE @sSort
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[grmGetRepositoryObjects]
(
@ModuleID int,
@sFilter nvarchar(256),
@sSort nvarchar(100),
@Approved int,
@CategoryId int,
@Attributes nvarchar(150),
@RowCount int
)
AS
BEGIN
IF @RowCount > 0
SET ROWCOUNT @RowCount
END
BEGIN
IF @CategoryId = -1
SELECT
a.*,
(SELECT COUNT(grmRepositoryComments.ItemID) FROM grmRepositoryComments
WHERE grmRepositoryComments.ObjectID=a.ItemID) AS CommentCount
FROM grmRepositoryObjects a
WHERE a.ModuleID = @ModuleID
AND (a.Approved = @Approved)
AND (@Attributes = '' OR dbo.grmCheckAllAttributes(@Attributes,';',a.ItemID) = 1)
AND
(
@sFilter = ''
OR UPPER(a.Name) LIKE UPPER('%' + @sFilter + '%')
OR UPPER(a.Author) LIKE UPPER('%' + @sFilter + '%')
OR UPPER(a.AuthorEMail) LIKE UPPER('%' + @sFilter + '%')
OR a.Description LIKE '%' + @sFilter + '%'
)
ORDER BY
CASE @sSort
WHEN 'Name' THEN a.Name
WHEN 'Author' THEN a.Author
END ASC,
CASE @sSort
WHEN 'Downloads' THEN a.Downloads
WHEN 'RatingAverage' THEN a.RatingAverage
END DESC,
CASE @sSort
WHEN 'UpdatedDate' THEN a.UpdatedDate
END DESC,
CASE @sSort
WHEN 'CustomOrder' THEN a.OrderNumber
END ASC
ELSE
SELECT
a.*,
(SELECT COUNT(grmRepositoryComments.ItemID) FROM grmRepositoryComments
WHERE grmRepositoryComments.ObjectID=a.ItemID) AS CommentCount
FROM grmRepositoryObjects a, grmRepositoryObjectCategories b
WHERE a.ModuleID = @ModuleID
AND (a.Approved = @Approved)
AND (a.ItemID = b.ObjectID AND b.CategoryId = @CategoryId)
AND (@Attributes = '' OR dbo.grmCheckAllAttributes(@Attributes,';',a.ItemID) = 1)
AND
(
@sFilter = ''
OR UPPER(a.Name) LIKE UPPER('%' + @sFilter + '%')
OR UPPER(a.Author) LIKE UPPER('%' + @sFilter + '%')
OR UPPER(a.AuthorEMail) LIKE UPPER('%' + @sFilter + '%')
OR a.Description LIKE '%' + @sFilter + '%'
)
ORDER BY
CASE @sSort
WHEN 'Name' THEN a.Name
WHEN 'Author' THEN a.Author
END ASC,
CASE @sSort
WHEN 'Downloads' THEN a.Downloads
WHEN 'RatingAverage' THEN a.RatingAverage
END DESC,
CASE @sSort
WHEN 'UpdatedDate' THEN a.UpdatedDate
END DESC,
CASE @sSort
WHEN 'CustomOrder' THEN a.OrderNumber
END ASC
END