| ' |
| ' DotNetNuke® - http://www.dotnetnuke.com |
| ' |
| |
| Imports DotNetNuke |
| Imports DotNetNuke.Common |
| Imports DotNetNuke.Services.Exceptions |
| Imports DotNetNuke.Services.Localization |
| Imports DotNetNuke.Entities.Users |
| |
| Imports Telerik.Web.UI |
| Imports Telerik.Web.UI.Editor |
| Imports System.Drawing |
| |
| |
| |
| Namespace MyCompany.MyClass |
| |
| ''' ----------------------------------------------------------------------------- |
| ''' <summary> |
| ''' The EditMyClass class is used to manage content |
| ''' </summary> |
| ''' <remarks> |
| ''' </remarks> |
| ''' <history> |
| ''' </history> |
| ''' ----------------------------------------------------------------------------- |
| Partial Class Edit |
| Inherits Entities.Modules.PortalModuleBase |
|
| #Region "Private Members" |
| |
| Private ItemId As Integer = Null.NullInteger ' -1 |
|
| #End Region |
|
| #Region "Event Handlers" |
| |
| ''' ----------------------------------------------------------------------------- |
| ''' <summary> |
| ''' Page_Load runs when the control is loaded |
| ''' </summary> |
| ''' <remarks> |
| ''' </remarks> |
| ''' <history> |
| ''' </history> |
| ''' ----------------------------------------------------------------------------- |
| Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load, Me.Load |
| Try |
| |
| |
| ' Generates false entries |
| 'Dim objA As New MyClassInfo |
| 'Static RandomNumGen As New System.Random |
| 'objA.Titre = "Test " & RandomNumGen.Next |
| 'objA.Description = "Desc " & RandomNumGen.Next |
| 'APCtl.AddEntry(objA) |
| |
| |
| |
| Me.RadGrid1.DataSource = Me.EmployeesData |
| If Not Me.Page.IsPostBack Then |
| ' Define current texts |
| Me.RadGrid1.MasterTableView.NoRecordsTemplate = New NoRecordsTemplate("lblNoEntry.Text", Me.LocalResourceFile) |
| End If |
| |
| |
| Catch exc As Exception 'Module failed to load |
| ProcessModuleLoadException(Me, exc) |
| End Try |
| End Sub |
| |
| Private Sub RadGrid1_UpdateCommand(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand, RadGrid1.InsertCommand |
| |
| Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem) |
| Dim editMan As GridEditManager = editedItem.EditManager |
| |
| Dim ID As String = Null.NullInteger |
| If Not e.Item.ItemIndex = Null.NullInteger Then |
| ID = (CType(e.Item, GridEditFormItem)).OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ItemId").ToString |
| End If |
| |
| Dim column As GridColumn |
| Dim objAP As New MyClassInfo |
| |
| For Each column In e.Item.OwnerTableView.Columns |
| If TypeOf column Is IGridEditableColumn Then |
| Dim editableCol As IGridEditableColumn = CType(column, IGridEditableColumn) |
| If (editableCol.IsEditable) Then |
| Dim editor As IGridColumnEditor = editMan.GetColumnEditor(editableCol) |
| |
| Dim editorType As String = CType(editor, Object).ToString() |
| Dim editorText As String = "unknown" |
| Dim editorValue As Object = Nothing |
| |
| If (TypeOf editor Is GridHTMLEditorColumnEditor) Then ' The RadEditor |
| editorText = CType(editor, GridHTMLEditorColumnEditor).Editor.Text |
| editorValue = CType(editor, GridHTMLEditorColumnEditor).Editor.Text |
| End If |
| |
| If (TypeOf editor Is GridTextColumnEditor) Then |
| editorText = CType(editor, GridTextColumnEditor).Text |
| editorValue = CType(editor, GridTextColumnEditor).Text |
| End If |
| |
| If (TypeOf editor Is GridBoolColumnEditor) Then |
| editorText = CType(editor, GridBoolColumnEditor).Value.ToString() |
| editorValue = CType(editor, GridBoolColumnEditor).Value |
| End If |
| |
| If (TypeOf editor Is GridDropDownColumnEditor) Then |
| editorText = CType(editor, GridDropDownColumnEditor).SelectedText & "; " & CType(editor, GridDropDownColumnEditor).SelectedValue |
| editorValue = CType(editor, GridDropDownColumnEditor).SelectedValue |
| End If |
| |
| Try |
| |
| If Not ID = "-1" Then |
| Dim changedRows As DataRow() = Me.EmployeesData.Tables("Employees").Select("ItemId = " & editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("ItemId")) |
| ' Chaque DropDownList effectuant des transformations devra avoir sa transformation |
| If column.UniqueName = "CategoriesList" Then |
| changedRows(0)("CategoryID") = editorValue |
| Else |
| changedRows(0)(column.UniqueName) = editorValue |
| End If |
| |
| Me.EmployeesData.Tables("Employees").AcceptChanges() |
| |
| End If |
| |
| Select Case column.UniqueName |
| Case "ItemId" |
| objAP.ItemId = CType(editorValue, Integer) |
| Case "Titre" |
| objAP.Titre = editorValue |
| Case "Description" ' The RadEditor |
| objAP.Description = editorValue |
| Case "Adresse" |
| objAP.Adresse = editorValue |
| Case "Telephone" |
| objAP.Telephone = editorValue |
| Case "URL" |
| objAP.URL = editorValue |
| Case "Courriel" |
| objAP.Courriel = editorValue |
| Case "CategoriesList" 'Equivalent unique de CategoryID, soit la liste deroulante |
| objAP.CategoryID = CType(editorValue, Integer) |
| |
| End Select |
| |
| Catch ex As Exception |
| SetMessage("<strong>Unable to set value of column '" & column.UniqueName & "'</strong> - " + ex.Message) |
| e.Canceled = True |
| End Try |
| |
| |
| |
| End If |
| End If |
| Next |
| If Not e.Canceled = True Then |
| Dim objAPCtl As New MyClassController |
| |
| ' TimeStamp actualisation |
| objAP.LastModificationDate = Date.Now |
| objAP.LastModificationUserID = Me.UserId |
| |
| If ID = Null.NullInteger.ToString Then |
| ' New entry |
| objAPCtl.AddEntry(objAP) |
| SetMessage("Entree ajoutee") |
| |
| Dim MyEmployeesData As DataSet = New DataSet |
| |
| Dim APCtl As New MyClassController |
| Dim objAPs As New List(Of MyClassInfo) |
| objAPs = APCtl.GetEntries() |
| Dim objC As New CollectionToDataSet(objAPs) |
| |
| ' I convert the collection to Dataset in order to remain comparable with Telerik samples as found in your intranet |
| MyEmployeesData = objC.CreateDataSet |
| |
| ' Define PK on Dataset for .Find() method |
| Dim pk(1) As DataColumn |
| pk(0) = MyEmployeesData.Tables(0).Columns("ItemId") |
| MyEmployeesData.Tables(0).PrimaryKey() = pk |
| |
| Me.EmployeesData = MyEmployeesData |
| |
| ' GiveDataSource() |
| ' Rebind and close edit window |
| ' TODO : Find a way to rebind and close the edit window |
| ' TODO Note : (Seb) The methods given by Telerik on forums and samples doesn't works here (Version 2008..1314 problem ?) |
| Response.Redirect(NavigateURL(Request.QueryString("ctl"), "mid=" & Request.QueryString("mid"))) |
| |
| Else |
| ' Update |
| Dim objAPorigin As New MyClassInfo |
| objAPorigin = objAPCtl.GetEntryByID(ID) |
| |
| ' Here is a list of the columns not displayed in the Grid |
| objAP.ItemId = objAPorigin.ItemId |
| objAP.SortOrderInfoID = objAPorigin.SortOrderInfoID |
| |
| ' Update LastSortOrder when category changes |
| Dim booClearCache As Boolean = False |
| If objAP.CategoryID <> objAPorigin.CategoryID Then |
| objAPCtl.UpdateSortOrder(objAP.SortOrderInfoID, objAPCtl.GetLastSortOrder(Constantes.ItemType.Entree, objAP.CategoryID).SortOrder + 1, objAP.CategoryID) |
| ' booClearCache = True |
| End If |
| |
| objAPCtl.UpdateEntry(objAP) |
| |
| Me.RadGrid1.MasterTableView.ClearEditItems() |
| |
| ' If booClearCache Then |
| ' Enforce update on the grid |
| ' Refresh cat group if needed |
| ' Refresh timeStamp |
| Me.Session.Remove("EmployeesData") |
| Me.RadGrid1.DataSource = Me.EmployeesData |
| Me.RadGrid1.DataBind() |
| 'End If |
| |
| SetMessage("Entry updated") |
| |
| End If |
| End If |
| End Sub |
| |
| Private Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs) Handles RadGrid1.ItemDataBound |
| If (TypeOf e.Item Is GridEditableItem AndAlso CType(e.Item, GridEditableItem).IsInEditMode) Then |
| Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem) |
| Dim editMan As GridEditManager = editedItem.EditManager |
| |
| Dim editor As GridDropDownColumnEditor = CType(editMan.GetColumnEditor("CategoriesList"), GridDropDownColumnEditor) |
| |
| Dim htmleditor As GridHTMLEditorColumnEditor = CType(editMan.GetColumnEditor("Description"), GridHTMLEditorColumnEditor) |
| Dim objRadE As RadEditor = CType(htmleditor.ContainerControl.Controls(0), RadEditor) |
| |
| objRadE.CssClass = "MyRadEditor" |
| objRadE.AutoResizeHeight = True |
| |
| ' TODO |
| 'objRadE.EditModes = EditModes.All |
| objRadE.EnableResize = False |
| objRadE.ToolbarMode = EditorToolbarMode.ShowOnFocus |
| objRadE.Tools.Clear() |
| Dim main As New EditorToolGroup() |
| objRadE.Tools.Add(main) |
| Dim bold As New EditorTool() |
| bold.Name = "Bold" |
| bold.ShortCut = "CTRL+B" |
| main.Tools.Add(bold) |
| Dim italic As New EditorTool() |
| italic.Name = "Italic" |
| italic.ShortCut = "CTRL+I" |
| main.Tools.Add(italic) |
| Dim underline As New EditorTool() |
| underline.Name = "Underline" |
| underline.ShortCut = "CTRL+U" |
| main.Tools.Add(underline) |
| |
| |
| |
| Dim ID As String = "-1" |
| |
| If Not e.Item.ItemIndex = -1 Then |
| ID = (CType(e.Item, GridEditFormItem)).OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ItemId").ToString |
| End If |
| |
| ' Hides some columns |
| editedItem("CategoryID").Parent.Visible = False |
| editedItem("LastModificationDate").Parent.Visible = False |
| editedItem("LastModificationUserID").Parent.Visible = False |
| |
| ' Modify the list control as per custom conventions |
| Dim objAPCtl As New MyClassController |
| Dim objCats As New List(Of CategoryInfo) |
| |
| Dim objEmptyCat As New CategoryInfo |
| objEmptyCat.CategoryID = 0 |
| objEmptyCat.SortOrderInfoId = -1 |
| objEmptyCat.Titre = "-- Choose --" |
| objCats.Add(objEmptyCat) |
| |
| objCats.AddRange(objAPCtl.GetCategories()) |
| |
| editor.DataTextField = "Titre" |
| editor.DataValueField = "CategoryID" |
| editor.DataSource = objCats |
| Editor.DataBind() |
| |
| If Not ID = -1 Then |
| Dim objPA As New MyClassInfo |
| objPA = objAPCtl.GetEntryByID(ID) |
| 'If Not editedItem("CategoryID") Is Nothing Then |
| ' TODO : (seb) We should be able to get the CategoryId from the context RadGrid but I don't know how asap. |
| editor.SelectedValue = objPA.CategoryID.ToString |
| 'CType(editedItem("CategoryID").Controls(0), TextBox).Text |
| 'End If |
| End If |
| |
| 'And so on |
| ElseIf (TypeOf e.Item Is GridDataItem AndAlso Not e.Item.IsInEditMode) Then |
| Dim item As GridDataItem = e.Item |
| |
| ' Replaces some values of the grid so the user has a better comprehension of the stored data |
| Dim ObjAPCtl As New MyClassController |
| |
| Dim catID As String = item("CategoryID").Text |
| If catID = "-1" Or catID = "0" Or catID = Null.NullString Then |
| ' No category |
| item("CategoryID").Text = "-" |
| Else |
| ' Category given |
| |
| Dim ObjCat As New CategoryInfo |
| ObjCat = ObjAPCtl.GetCategoryByID(CType(catID, Integer)) |
| item("CategoryID").Text = ObjCat.Titre |
| |
| End If |
| |
| ' Crop the Description which could be very long |
| If item("Description").Text.Length >= 100 Then |
| item("Description").Text = item("Description").Text.Substring(0, 100) & "[...]" |
| End If |
| |
| ' Replace the UserID by the display name |
| Dim objUCtl As New UserController |
| item("LastModificationUserID").Text = objUCtl.GetUser(Me.PortalId, CType(item("LastModificationUserID").Text, Integer)).DisplayName |
| |
| ' The date |
| 'item("LastModificationDate").Text = CType(item("LastModificationDate").Text, Date).ToLongDateString & " " & CType(item("LastModificationDate").Text, Date).ToLongTimeString |
| |
| ' The sortOrder |
| CType(item("MoveUp").Controls(0), ImageButton).ImageUrl = ResolveUrl("~/images/action_up.gif") |
| CType(item("MoveDown").Controls(0), ImageButton).ImageUrl = ResolveUrl("~/images/action_down.gif") |
| |
| Dim ID As String = "-1" |
| |
| If Not e.Item.ItemIndex = -1 Then |
| ID = (CType(e.Item, GridDataItem)).OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ItemId").ToString |
| End If |
| |
| ' TODO : Update Telerik.Web.UI and use Drag'n'Drop for Re-ordering |
| |
| Dim LastSortIndex As Integer = ObjAPCtl.GetLastSortOrder(Constantes.ItemType.Entree, catID).SortOrder |
| Dim MySortIndex As Integer = ObjAPCtl.GetSortOrderByID(ObjAPCtl.GetEntryByID(ID).SortOrderInfoID).SortOrder |
| |
| If MySortIndex = LastSortIndex And MySortIndex = 1 Then |
| ' 1 entry only |
| item("MoveUp").Controls(0).Visible = False |
| item("MoveDown").Controls(0).Visible = False |
| ElseIf MySortIndex = LastSortIndex Then |
| ' End of the list |
| item("MoveDown").Controls(0).Visible = False |
| ElseIf MySortIndex = 1 Then |
| ' Start of the list |
| item("MoveUp").Controls(0).Visible = False |
| End If |
| |
| |
| |
| End If |
| End Sub |
| |
| |
| Private Sub RadGrid1_ItemCommand(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.ItemCommand |
| If e.Item.GetType.Equals(GetType(GridDataItem)) Then |
| |
| |
| ' TODO : Update Telerik.Web.UI and use Drag'n'Drop for Re-ordering |
| |
| |
| ' Up/Down for re-ordering |
| Dim item As GridDataItem = CType(e.Item, GridDataItem) |
| |
| Dim ID As String = "-1" |
| If Not e.Item.ItemIndex = -1 Then |
| ID = item.OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ItemId").ToString |
| End If |
| |
| Dim objAPCtl As New MyClassController |
| Dim objAP As MyClassInfo = objAPCtl.GetEntryByID(ID) |
| |
| If e.CommandName = "MoveUp" Then |
| objAPCtl.UpdateSortOrderByMove(objAP.SortOrderInfoID, Constantes.ItemType.Entree, objAP.CategoryID, True) |
| ElseIf e.CommandName = "MoveDown" Then |
| objAPCtl.UpdateSortOrderByMove(objAP.SortOrderInfoID, Constantes.ItemType.Entree, objAP.CategoryID, False) |
| End If |
| |
| Me.Session.Remove("EmployeesData") |
| Me.RadGrid1.DataSource = Me.EmployeesData |
| Me.RadGrid1.DataBind() |
| End If |
| End Sub |
| |
| |
| |
| Private Sub GiveDataSource() |
| RadGrid1.DataSource = Me.EmployeesData |
| Me.EmployeesData.Tables("Employees").PrimaryKey = New DataColumn() {Me.EmployeesData.Tables("Employees").Columns("ItemId")} |
| End Sub |
| |
| Private Sub RadGrid1_NeedDataSource(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource |
| If Not Me.EmployeesData Is Nothing Then |
| GiveDataSource() |
| Else |
| Me.RadGrid1.DataSource = New List(Of MyClassInfo) |
| End If |
| End Sub |
| |
| Private Sub Page_PreRender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.PreRender |
| If Not MyBase.IsPostBack Then |
| ' Me.RadGrid1.MasterTableView.Items(0).Edit = True |
| Me.RadGrid1.MasterTableView.Rebind() |
| End If |
| End Sub |
| |
| Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As GridCommandEventArgs) Handles RadGrid1.DeleteCommand |
| Dim ID As String = (CType(e.Item, GridDataItem)).OwnerTableView.DataKeyValues(e.Item.ItemIndex)("ItemId").ToString |
| |
| Dim MyEmployeesData As DataSet = New DataSet |
| MyEmployeesData = Me.EmployeesData |
| |
| Dim employeeTable As DataTable = MyEmployeesData.Tables("Employees") |
| If Not (employeeTable.Rows.Find(ID) Is Nothing) Then |
| employeeTable.Rows.Find(ID).Delete() |
| employeeTable.AcceptChanges() |
| End If |
| |
| Me.EmployeesData = MyEmployeesData |
| |
| GiveDataSource() |
| |
| Dim APCtl As New MyClassController |
| APCtl.DeleteEntryById(ID) |
| |
| SetMessage("Entree " & ID & " deleted") |
| |
| |
| End Sub |
| |
| Protected Sub SetMessage(ByVal message As String) |
| RadGrid1.Controls.Add(New LiteralControl(message)) |
| End Sub |
| |
| Public Property EmployeesData() As DataSet |
| Get |
| Dim obj As Object = Me.Session("EmployeesData") |
| If Not obj Is Nothing Then |
| Return CType(obj, DataSet) |
| End If |
| |
| Dim MyEmployeesData As DataSet = New DataSet |
| |
| Dim APCtl As New MyClassController |
| Dim objAPs As New List(Of MyClassInfo) |
| objAPs = APCtl.GetEntries() |
| |
| ' No entries ? |
| If objAPs.Count > 0 Then |
| |
| Dim objC As New CollectionToDataSet(objAPs) |
| |
| ' I convert the collection to Dataset in order to remain comparable with Telerik samples as found in your intranet |
| MyEmployeesData = objC.CreateDataSet |
| |
| ' Define PK on Dataset for .Find() method |
| Dim pk(1) As DataColumn |
| pk(0) = MyEmployeesData.Tables(0).Columns("ItemId") |
| MyEmployeesData.Tables(0).PrimaryKey() = pk |
| |
| Me.Session("EmployeesData") = MyEmployeesData |
| |
| Return MyEmployeesData |
| Else |
| ' No entries . |
| Return Nothing |
| End If |
| |
| End Get |
| Set(ByVal value As DataSet) |
| Me.Session("EmployeesData") = value |
| End Set |
| End Property |
| |
| |
| |
| ''' ----------------------------------------------------------------------------- |
| ''' <summary> |
| ''' cmdCancel_Click runs when the cancel button is clicked |
| ''' </summary> |
| ''' <remarks> |
| ''' </remarks> |
| ''' <history> |
| ''' </history> |
| ''' ----------------------------------------------------------------------------- |
| Private Sub cmdCancel_Click(ByVal sender As Object, ByVal e As EventArgs) Handles cmdCancel.Click |
| Try |
| Response.Redirect(NavigateURL(), True) |
| Catch exc As Exception 'Module failed to load |
| ProcessModuleLoadException(Me, exc) |
| End Try |
| End Sub |
|
|
|
| #End Region |
| |
| End Class |
| |
| End Namespace |