Click here to Skip to main content
15,896,421 members
Articles / Web Development / IIS

Scheduled Tasks Web Service

Rate me:
Please Sign up or sign in to vote.
4.00/5 (9 votes)
23 Nov 2007CPOL6 min read 127.6K   2.5K   65  
A web service that acts as a scheduler for tasks.
Public Class TaskEditView


    ''' <summary>
    ''' controller for this form
    ''' </summary>
    Dim controller As TaskEditViewController

    ''' <summary>
    ''' Fires when data is added or updated in this form
    ''' </summary>
    Public Event TaskEditViewUpdated()


    ''' <summary>
    ''' Initialize form
    ''' </summary>
    Private Sub TaskEditView_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Bind the data
        Me.BindData()
    End Sub


    ''' <summary>
    ''' constructor in Add mode
    ''' </summary>
    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        'Set he form name
        Me.Text = "Add a new Task"

        'Initialize the controller
        Me.controller = New TaskEditViewController
        Me.chbxEnableEnd.Checked = False
        Me.chbxEnableDaily.Checked = False
    End Sub


    ''' <summary>
    ''' Constructor in Edit Mode
    ''' </summary>
    ''' <param name="TaskID">ID of the task to edit</param>
    Public Sub New(ByVal TaskID As Integer)
        ' This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call
        Me.Text = "Edit Task"

        'Initialize the controller
        Me.controller = New TaskEditViewController(TaskID)
    End Sub


    ''' <summary>
    ''' Binds the data and set the actual position
    ''' </summary>
    Private Sub BindData()
        Me.sourceTask.DataSource = controller.TaskData
        Me.sourceTask.Position = controller.Position
        'Fill the Assembly List
        Me.cmbxAssembly.Items.Clear()
        For Each Assembly As String In controller.AvailableTasks
            Me.cmbxAssembly.Items.Add(Assembly)
        Next
        'Set the Run only once Check box
        If Me.txtRepeat.Value = 0 Then
            Me.chbxOnlyOnce.Checked = True
        End If
        If Me.txtAbortTaskAfter.Value > 0 Then
            Me.chbxAbortTask.Checked = True
        End If
        'Disbale the end time values 
        If Not controller.EndTimeIsEnabled Then
            Me.chbxEnableEnd.Checked = False
        End If
        'Disable the Daily scheduler values
        If Not controller.DailyScheduleIsEnabled Then
            Me.chbxEnableDaily.Checked = False
        End If

    End Sub


    ''' <summary>
    ''' Save the Task
    ''' </summary>
    Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click
        Me.Cursor = Cursors.WaitCursor
        Me.sourceTask.EndEdit()
        'Fix the End Date/Tome Perform time
        controller.FixDailySchedule(Me.chbxEnableDaily.Checked)
        controller.FixEndTime(Me.chbxEnableEnd.Checked)
        Dim success As Boolean = controller.SaveData()
        Me.Cursor = Cursors.Default
        If success Then
            'Raise the event
            RaiseEvent TaskEditViewUpdated()
            'close the form
            Me.Close()
        Else
            MessageBox.Show(controller.errorString, "", MessageBoxButtons.OK, MessageBoxIcon.Stop)
        End If
    End Sub


    ''' <summary>
    ''' Delete current Task
    ''' </summary>
    Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click
        Me.Cursor = Cursors.WaitCursor
        'Remove all bindings
        RemoveAllBindings()
        controller.DeleteTask()
        Me.Cursor = Cursors.Default
        'Raise the event
        RaiseEvent TaskEditViewUpdated()
        'close the form
        Me.Close()
    End Sub


    ''' <summary>
    ''' Remove all bindings
    ''' </summary>
    Private Sub RemoveAllBindings()
        Me.txtTaskName.DataBindings.Clear()
        Me.chbxEnabled.DataBindings.Clear()
        Me.txtStartDate.DataBindings.Clear()
        Me.txtStartTime.DataBindings.Clear()
        Me.txtEndDate.DataBindings.Clear()
        Me.txtEndTime.DataBindings.Clear()
        Me.txtRepeat.DataBindings.Clear()
        Me.chbxOnlyOnce.DataBindings.Clear()
        Me.txtPerformFrom.DataBindings.Clear()
        Me.txtPerformTo.DataBindings.Clear()
        Me.txtAbortTaskAfter.DataBindings.Clear()
        Me.chbxAbortTask.DataBindings.Clear()
        Me.cmbxAssembly.DataBindings.Clear()
        Me.txtDescription.DataBindings.Clear()
    End Sub


    ''' <summary>
    ''' Set repeat every minutes as 0 if its checked
    ''' </summary>
    Private Sub chbxOnlyOnce_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbxOnlyOnce.CheckedChanged
        If Me.chbxOnlyOnce.Checked Then
            Me.txtRepeat.Value = 0
        End If
    End Sub


    ''' <summary>
    ''' Set run only once, do not allow negative numbers
    ''' </summary>
    Private Sub txtRepeat_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtRepeat.ValueChanged
        If Me.txtRepeat.Value < 0 Then
            Me.txtRepeat.Value = 0
        End If
        If Me.txtRepeat.Value = 0 Then
            Me.chbxOnlyOnce.Checked = True
        Else
            Me.chbxOnlyOnce.Checked = False
        End If
    End Sub


    ''' <summary>
    ''' set as 0 the Abort value if is unchecked
    ''' </summary>
    Private Sub chbxAbortTask_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbxAbortTask.CheckedChanged
        If Not Me.chbxAbortTask.Checked Then
            Me.txtAbortTaskAfter.Value = 0
        End If
    End Sub


    ''' <summary>
    ''' Do not allow negative numbers, also clear the proper checkbox if the value is 0
    ''' </summary>
    Private Sub txtAbortTaskAfter_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtAbortTaskAfter.ValueChanged
        If Me.txtAbortTaskAfter.Value < 0 Then
            Me.txtAbortTaskAfter.Value = 0
        End If
        If Me.txtAbortTaskAfter.Value = 0 Then
            Me.chbxAbortTask.Checked = False
        Else
            Me.chbxAbortTask.Checked = True
        End If
    End Sub


    ''' <summary>
    ''' Enable/Disable End Time for a task
    ''' </summary>
    Private Sub chbxEnableEnd_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbxEnableEnd.CheckedChanged
        If Me.chbxEnableEnd.Checked Then
            'Enable the end controls
            Me.txtEndDate.Enabled = True
            Me.txtEndTime.Enabled = True
        Else
            'Disable the end controls
            Me.txtEndDate.Enabled = False
            Me.txtEndTime.Enabled = False
        End If
    End Sub


    ''' <summary>
    ''' Enable/Disable End Time for dayli valid schedule
    ''' </summary>
    Private Sub chbxEnableDaily_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chbxEnableDaily.CheckedChanged
        If Me.chbxEnableDaily.Checked Then
            Me.txtPerformFrom.Enabled = True
            Me.txtPerformTo.Enabled = True
        Else
            Me.txtPerformFrom.Enabled = False
            Me.txtPerformTo.Enabled = False
        End If
    End Sub


    ''' <summary>
    ''' Set the date for the Time control also
    ''' </summary>
    Private Sub txtStartDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtStartDate.ValueChanged
        Me.txtStartTime.Value = CType(Me.txtStartDate.Value, Date).Date + CType(Me.txtStartTime.Value, Date).TimeOfDay
    End Sub


    ''' <summary>
    ''' Set the date for the Time control also
    ''' </summary>
    Private Sub txtEndDate_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtEndDate.ValueChanged
        Me.txtEndTime.Value = CType(Me.txtEndDate.Value, Date).Date + CType(Me.txtEndTime.Value, Date).TimeOfDay
    End Sub


    ''' <summary>
    ''' Set the perform From  value if has not been set
    ''' </summary>
    Private Sub txtPerformTo_ValueChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtPerformTo.ValueChanged, txtPerformFrom.ValueChanged
        Me.sourceTask.EndEdit()
        'Initialize Values for Perform from and to fields
        controller.InitializePerformTimeValues()
    End Sub
End Class

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Web Developer
Mexico Mexico
I am Pedro Ramirez from mexico, work for www.sciodev.com, the company is located in Mexico, we do outsourcing and nearshore development, we are focused on SaaS nearshore development, I started with VB.Net, but now I am ambidextrous using VB.Net or C#.

Comments and Discussions