Imports System
Imports System.ComponentModel
Imports System.Collections.Generic
Imports System.Diagnostics
Imports System.Text

Imports DevExpress.ExpressApp
Imports DevExpress.ExpressApp.Actions
Imports DevExpress.Persistent.Base

Public Class RepairRegistryVC
	Inherits DevExpress.ExpressApp.ViewController
    Public Event InitWork(ByVal _Minimum As Long, ByVal _Step As Long, ByVal _Maximum As Long)
    Public Event DoWork()
    Public Event FinalWork
	Public Sub New()
		MyBase.New()

		'This call is required by the Component Designer.
		InitializeComponent()
		RegisterActions(components) 

	End Sub

    Private Sub aRepairRegistryTask_Execute(sender As System.Object, e As DevExpress.ExpressApp.Actions.SimpleActionExecuteEventArgs) Handles aRepairRegistryTask.Execute
        Dim _ocur As Xpo.XPObjectSpace = TryCast(View.ObjectSpace, Xpo.XPObjectSpace)
        Dim _RegistryTasks As RegistryTasks
        Dim _RegistryHeader As RegistryHeader
        Dim _RegistryTask2 As RegistryTasks
        Dim _RegistryTask_Collection As New ArrayList

        _RegistryTask_Collection.Clear()
        RaiseEvent InitWork(1, 1, View.SelectedObjects.Count)
        For Each _RegistryTasks In View.SelectedObjects
            RaiseEvent DoWork()
            _RegistryHeader = _RegistryTasks.RegistryHeader
            If _RegistryTasks.Status <> General.TaskStatus.Completed Then
                For Each _RegistryTask2 In _RegistryHeader.RegistryTasks
                    If _RegistryTask2 IsNot _RegistryTasks Then
                        If _RegistryTask2.CurrentWorkflowSystemSteps IsNot _RegistryHeader.CurrentWorkflowSystemSteps Then
                            If _RegistryTask2.Status <> General.TaskStatus.Completed Then
                                _RegistryTask_Collection.Add(_RegistryTask2)
                            End If
                        End If
                    End If
                Next
            End If
        Next

        For Each _RegistryTask2 In _RegistryTask_Collection
            _RegistryTask2.Status = General.TaskStatus.Completed
            _RegistryTask2.Save()
        Next

        _ocur.CommitChanges()

        RaiseEvent FinalWork
        View.Refresh()
    End Sub
End Class
