This is a migrated thread and some comments may be shown as answers.

Custom Columns in a Custom Provider Not Showing in TaskUpdate

2 Answers 38 Views
Gantt
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 06 Dec 2016, 12:17 PM

Hello --

I have a custom task class and a custom provider (non-EM). Both follow the model code, and work perfectly on page load.

When changing values, the server side TaskUpdate event fires, and e.Tasks(0) has the expected values for the task that was just updated.

However...

Problem 1: e.Tasks(0) is a standard Task object, and not my CustomTask object. How can I get my custom field values on TaskUpdate?

Problem 2: Sender, while containing the appropriate RadGantt properties set on the .aspx page, does not have the Provider I gave it on Page Load. Also, Tasks contains zero object and GetAllTasks returns nothing.

I'm not sure what code will help, so I'll just post it all.  Sorry for the length.

Gantt declaration on the .aspx:

            <telerik:RadAjaxManager runat="server" EnableAJAX="true" ></telerik:RadAjaxManager>
            <telerik:RadAjaxPanel runat="server" >
            <telerik:RadGantt runat="server" RenderMode="Auto" ID="RadGantt1" Enabled="true" Visible="true"
                Skin="BlackMetroTouch" Height="600" Width="100%" ListWidth="60%"
                AllowColumnResize="true" AllowSorting="true" ReadOnly="false" ShowTooltip="false"
                EnablePdfExport="true" AutoGenerateColumns="false" DisplayDeleteConfirmation="true"
                AllowPercentCompleteDrag="false" ShowCurrentTimeMarker="true" EnableViewState="true"
                SelectedView="WeekView" WeekView-UserSelectable="true" YearView-UserSelectable="true"
                DayView-UserSelectable="true" MonthView-UserSelectable="true">
                <Columns>
                    <telerik:GanttBoundColumn DataField="Title" DataType="String" Width="180px" />
                    <telerik:GanttBoundColumn DataField="Start" DataType="DateTime" DataFormatString="dd/MM/yy" Width="80px" />
                    <telerik:GanttBoundColumn DataField="End" DataType="DateTime" DataFormatString="dd/MM/yy" Width="80px" />
                    <telerik:GanttBoundColumn DataField="System" HeaderText="System" DataType="String" Width="120px" />
                    <telerik:GanttBoundColumn DataField="ActivityType" HeaderText="Type" DataType="String" Width="120px" />
                    <telerik:GanttBoundColumn DataField="AssignedTo" HeaderText="AssignedTo" DataType="String" Width="120px" />
                    <telerik:GanttBoundColumn DataField="NotificationAddress" HeaderText="Notify" DataType="String" Width="250px" />
                    <telerik:GanttBoundColumn DataField="Description" HeaderText="Description" DataType="String" Width="300px" />
                </Columns>
                <CustomTaskFields>
                    <telerik:GanttCustomField PropertyName="Description" ClientPropertyName="description" Type="String" />
                    <telerik:GanttCustomField PropertyName="AssignedTo" ClientPropertyName="assignedTo" Type="String" />
                    <telerik:GanttCustomField PropertyName="System" ClientPropertyName="system" Type="String" />
                    <telerik:GanttCustomField PropertyName="ActivityType" ClientPropertyName="activityType" Type="String" />
                    <telerik:GanttCustomField PropertyName="NotificationAddress" ClientPropertyName="notificationAddress" Type="String" />
                </CustomTaskFields>
                <DataBindings>
                    <TasksDataBindings IdField="ID" ParentIdField="ParentID" StartField="Start" EndField="End" TitleField="Title" PercentCompleteField="PercentComplete" SummaryField="Summary" ExpandedField="Expanded" OrderIdField="OrderID" />
                    <DependenciesDataBindings TypeField="Type" IdField="ID" PredecessorIdField="PredecessorID" SuccessorIdField="SuccessorID" />
                </DataBindings>
            </telerik:RadGantt>
            </telerik:RadAjaxPanel>

 

The page code-behind:

    Private Sub RadGantt1_TaskUpdate(sender As Object, e As TaskEventArgs) Handles RadGantt1.TaskUpdate

       ' Both sender and RadGantt1 have no tasks here!

       'e.Tasks(0) is a standard Task object. How can I get my custom column data?

   End Sub

 

 

Lastly, sorry for the huge clip, but I don't know what could be significant.

Here's the custom provider. It seems to work fine.

Imports System.Data.SqlClient
Imports Telerik.Web.UI
Imports Telerik.Web.UI.Gantt

Public Class CustomTask
    Inherits Task

    Public Sub New()
        MyBase.New()
    End Sub

    Public Property Description() As String
        Get
            Return DirectCast(If(ViewState("Description"), ""), String)
        End Get
        Set(value As String)
            ViewState("Description") = value
        End Set
    End Property

    Public Property AssignedTo() As String
        Get
            Return DirectCast(If(ViewState("AssignedTo"), ""), String)
        End Get
        Set(value As String)
            ViewState("AssignedTo") = value
        End Set
    End Property

    Public Property System() As String
        Get
            Return DirectCast(If(ViewState("System"), ""), String)
        End Get
        Set(value As String)
            ViewState("System") = value
        End Set
    End Property

    Public Property RunActivityID() As Integer
        Get
            Return DirectCast(If(ViewState("RunActivityID"), ""), Integer)
        End Get
        Set(value As Integer)
            ViewState("RunActivityID") = value
        End Set
    End Property

    Public Property ActivityType() As String
        Get
            Return DirectCast(If(ViewState("ActivityType"), ""), String)
        End Get
        Set(value As String)
            ViewState("ActivityType") = value
        End Set
    End Property

    Public Property NotificationAddress() As String
        Get
            Return DirectCast(If(ViewState("NotificationAddress"), ""), String)
        End Get
        Set(value As String)
            ViewState("NotificationAddress") = value
        End Set
    End Property

    Public Property ScheduleDays() As String
        Get
            Return DirectCast(If(ViewState("ScheduleDays"), ""), String)
        End Get
        Set(value As String)
            ViewState("ScheduleDays") = value
        End Set
    End Property

    Protected Overrides Function GetSerializationData() As IDictionary(Of String, Object)
        Dim dict = MyBase.GetSerializationData()

        dict("Description") = Description
        dict("AssignedTo") = AssignedTo
        dict("System") = System
        dict("RunActivityID") = RunActivityID
        dict("ActivityType") = ActivityType
        dict("NotificationAddress") = NotificationAddress
        dict("ScheduleDays") = ScheduleDays

        Return dict
    End Function

    Public Overrides Sub LoadFromDictionary(values As System.Collections.IDictionary)
        MyBase.LoadFromDictionary(values)

        Description = DirectCast(values("Description"), String)
        AssignedTo = DirectCast(values("AssignedTo"), String)
        System = DirectCast(values("System"), String)
        RunActivityID = DirectCast(values("RunActivityID"), Integer)
        ActivityType = DirectCast(values("ActivityType"), String)
        NotificationAddress = DirectCast(values("NotificationAddress"), String)
        ScheduleDays = DirectCast(values("ScheduleDays"), String)
    End Sub
End Class

Public Class CustomGanttTaskFactory
    Implements ITaskFactory

    Private Function ITaskFactory_CreateTask() As Task Implements ITaskFactory.CreateTask
        Return New CustomTask()
    End Function
End Class

Public Class GanttCustomProvider
    Inherits GanttProviderBase

    Private TemplateName As String
    Private RunID As Integer
    Private ProcString As String  'all three of these are used to help form the SQL queries

    Public Sub New()
        MyBase.New()
    End Sub

    Public Sub New(Template As String)
        MyBase.New()
        TemplateName = Template
        ProcString = "@TemplateName = '" & TemplateName & "'"
    End Sub

    Public Sub New(SandboxRunID As Integer)
        MyBase.New()
        RunID = SandboxRunID
        ProcString = "@RunID = " & SandboxRunID.ToString
    End Sub

    Public Overrides ReadOnly Property TaskFactory() As ITaskFactory
        Get
            Return New CustomGanttTaskFactory()
        End Get
    End Property

    Public Overrides Function GetTasks() As List(Of ITask)
        Dim tasks = New List(Of ITask)()

        Dim strConn As String = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
        Dim conn As New SqlConnection(strConn)
        Dim cmdCommand As SqlCommand = conn.CreateCommand()
        cmdCommand.CommandText = "usp_Telerik_Task_SELECT " & ProcString
        cmdCommand.CommandType = System.Data.CommandType.Text
        conn.Open()
        Dim dr As SqlDataReader = cmdCommand.ExecuteReader()
        If dr.HasRows Then
            While dr.Read()
                Dim newTask As New CustomTask
                newTask.ID = dr("ID")
                newTask.ParentID = dr("ParentID")
                newTask.OrderID = dr("OrderID")
                newTask.Title = dr("Title")
                newTask.Start = dr("Start")
                newTask.End = dr("End")
                newTask.PercentComplete = dr("PercentComplete")
                newTask.Expanded = dr("Expanded")
                newTask.Summary = dr("Summary")
                newTask.Description = dr("Description")
                newTask.AssignedTo = dr("Assigned To")
                newTask.System = dr("StageID").ToString()
                newTask.RunActivityID = dr("RunActivityID")
                newTask.ActivityType = dr("ActivityType")
                newTask.NotificationAddress = dr("Notification Address")
                newTask.ScheduleDays = dr("ScheduleDays")

                tasks.Add(newTask)
            End While
        End If

        tasks(0).ParentID = Nothing
        tasks(0).Summary = True

        Return tasks
    End Function

    Public Overrides Function UpdateTask(task As ITask) As ITask
        Dim strConn As String
        Dim sqlText As String = "usp_Telerik_Task_UPDATE "

        sqlText = sqlText & "@ID = " & task.ID.ToString
        sqlText = sqlText & ", @ParentID = " & task.ParentID.ToString
        sqlText = sqlText & ", @OrderID = " & task.OrderID.ToString
        sqlText = sqlText & ", @Title = '" & task.Title & "'"
        sqlText = sqlText & ", @Start = '" & task.Start.ToString & "'"
        sqlText = sqlText & ", @End = '" & task.End.ToString & "'"
        sqlText = sqlText & ", @PercentComplete = " & task.PercentComplete.ToString
        sqlText = sqlText & ", @Expanded = " & task.Expanded.ToString()
        sqlText = sqlText & ", @Summary = " & task.Summary.ToString()

' comment out these lines because only a standard task is provided by the control and the custom fields are not included.
        'sqlText = sqlText & ", @StageName = '" & task.StageName & "'"
        'sqlText = sqlText & ", @ActivityType = '" & task.ActivityType.ToString & "'"
        'sqlText = sqlText & ", @NotificationAddress = '" & task.NotificationAddress.ToString & "'"
        'sqlText = sqlText & ", @ScheduleDays = '" & task.ScheduleDays.ToString & "'"
        'sqlText = sqlText & ", @Comments = '" & task.Description.ToString & "'"

        strConn = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
        Dim conn As New SqlConnection(strConn)
        Dim cmdCommand As SqlCommand = conn.CreateCommand()
        cmdCommand.CommandText = sqlText
        cmdCommand.CommandType = System.Data.CommandType.Text
        conn.Open()
        cmdCommand.ExecuteNonQuery()

        Return task
    End Function

    Public Overrides Function DeleteTask(task As ITask) As ITask
' not implemented yet

        Return task
    End Function

    Public Overrides Function InsertTask(task As ITask) As ITask
' not implemented yet

        Return task
    End Function

    Public Overrides Function GetDependencies() As List(Of IDependency)
        Dim deps = New List(Of IDependency)()

        Dim strConn As String
        strConn = ConfigurationManager.ConnectionStrings("DefaultConnection").ConnectionString
        Dim conn As New SqlConnection(strConn)
        Dim cmdCommand As SqlCommand = conn.CreateCommand()
        cmdCommand.CommandText = "usp_Telerik_TaskDependencies_SELECT " & ProcString
        cmdCommand.CommandType = System.Data.CommandType.Text
        conn.Open()
        Dim dr As SqlDataReader = cmdCommand.ExecuteReader()
        If dr.HasRows Then
            While dr.Read()
                Dim newDep As New Dependency
                newDep.ID = dr("ID")
                newDep.PredecessorID = dr("PredecessorID")
                newDep.SuccessorID = dr("SuccessorID")
                newDep.Type = dr("Type")
                deps.Add(newDep)
            End While
        End If

        Return deps
    End Function

    Public Overrides Function DeleteDependency(dependency As IDependency) As IDependency
' not implemented yet

        Return dependency
    End Function

    Public Overrides Function InsertDependency(dependency As IDependency) As IDependency
' not implemented yet

        Return dependency
    End Function
End Class

2 Answers, 1 is accepted

Sort by
0
Plamen
Telerik team
answered on 09 Dec 2016, 08:57 AM
Hi,

I have inspected a similar scenario the is implemented here and the custom field is accessible in the update method and is updated correctly. Please review it and let me know if you have further questions.

Regards,
Plamen
Telerik by Progress
Telerik UI for ASP.NET AJAX is ready for Visual Studio 2017 RC! Learn more.
0
David
Top achievements
Rank 1
answered on 11 Dec 2016, 06:57 AM

Thanks.

It seems that most of the answers on these forums are simply to throw unrelated sample code to your customers. I was already aware of this example, but did you notice that my code is not EF, not using web services, and not even C#?

I did find the answer. As expected, it was something stupid, but hard to find. For the benefit of others:

The line in Page_Load that reads RadGantt1.Provider = New GanttProvider(), must be outside any If Not IsPostBack. The line needs to run every time, as the Gantt does not appear to hold onto any server side declared properties between postbacks. This is shown on this example page, but without any explanation:

http://docs.telerik.com/devtools/aspnet-ajax/controls/gantt/data-binding/providers/custom-entityframework-provider

 

 

Tags
Gantt
Asked by
David
Top achievements
Rank 1
Answers by
Plamen
Telerik team
David
Top achievements
Rank 1
Share this question
or