<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<!--Created: 10.07.2015 16:00:22-->
<!--ACTOptimumVersion: 6.0.5581.26549-->
<ACTOptimumItems ACTOptimumVersion="6.0.5581.26549" Created="10.07.2015 16:00:22">
    <AutoDataMenu Created="10.07.2015 16:00:22" ClassName="Melville_Schellmann.ACTOptimum6.Plugin.MenuItemAutoData" PrefClassVersion="1.0" ACTOptimumVersion="6.0.5581.26549">
        <GlobalPref>True</GlobalPref>
        <NeededRole>2</NeededRole>
        <Name>Gruppen verschieben...</Name>
        <Tooltip>Verschiebt auswahl an Gruppen als Untergruppen zu einer einer Muttergruppe</Tooltip>
        <Description>Verschiebt auswahl an Gruppen als Untergruppen zu einer einer Muttergruppe</Description>
        <CommandBar>Connected Menus</CommandBar>
        <Menu>act-ui://com.act/application/menu/group</Menu>
        <Index>10</Index>
        <Separator>False</Separator>
        <Shortcut>None</Shortcut>
        <SourceCode>' #ScriptName: MoveGroups
    ' #Description: DEUTSCH:
    '               Verschiebt markierte Gruppen in der Gruppenlistenauswahl unter eine Gruppe.
    '               
    '               ENGLISH:
    '               Moves selected groups in the group list selection among a main group .
    '               
    ' #Copyright: © 2013 by Melville-Schellmann
    ' #Author: Robert Schellmann, rs@melville-schellmann.de
    ' #Version: 1.0 (10.06.2013) s.o.

    m_oACTApp = ACTApp
    m_oACTOptimum = ACTOptimum
    m_sScriptName = "MoveGroups"
    
    Dim oMotherGroup As Act.Framework.Groups.Group
    Dim oGroups As  act.Framework.Groups.GroupList
    Dim oGroupListView As Act.UI.IGroupListView
    Dim lIndex As Integer
    Dim lMoved As Integer
    
    If Not TypeOf(m_oACTApp.CurrentView) Is Act.UI.IGroupListView Then
      Msgbox("Bitte rufen Sie diese Funktion nur in der Gruppenlistenansicht auf.", MsgBoxStyle.Information, m_sScriptName)
      GoTo Abbruch
    End If
    oGroupListView = CType(m_oACTApp.CurrentView, Act.UI.IGroupListView)        
    oGroups = oGroupListView.GetSelectedGroups
    If oGroups Is Nothing Or oGroups.Count = 0 Then
      Msgbox("Bitte markieren Sie die Gruppen, die einer Gruppe untergeordnet werden sollen.")
    End If
    If TrySelectGroup(oMotherGroup) = False Then
      GoTo Abbruch
    End If
    If oGroups.Contains(oMotherGroup) Then
      Msgbox(String.Format("Die ausgewählte Gruppe '{0}' befindet sich unter den markierten Gruppen.", oMotherGroup.Name) &amp; vbcrlf &amp; _
        "Der Vorgang wird abgebrochen.", MsgBoxStyle.Exclamation, m_sScriptName) 
      GoTo Abbruch
    End If    
    
    lMoved = 0 
    For lIndex = 0 To oGroups.Count - 1
      m_oACTApp.Cursor = Cursors.WaitCursor
      If Not TryPrintStatus(String.Format("Verschiebe Gruppe '{0}' ... ({1}/{2})", oGroups.Item(lIndex).Name, lIndex, oGroups.Count)) Then
        GoTo Abbruch
      End If
      Application.DoEvents
      Threading.thread.sleep(100)
      If  oGroups.Item(lIndex).ParentID &lt;&gt; oMotherGroup.ID Then
        Try
          oGroups.Item(lIndex).SetParent(oMotherGroup)  
          oGroups.item(lindex).Update
          lMoved += 1
        Catch ex As Exception
          MsgBox(String.Format("Es ist ein Fehler beim Verschieben der Gruppe '{0}' unter die Gruppe '{1}' aufgetreten.", oGroups.Item(lIndex).Name, oMotherGroup.Name) &amp; vbcrlf &amp; _
            ex.Message, MsgBoxStyle.Exclamation, m_sScriptName)
        End Try
        Application.DoEvents
        Threading.thread.sleep(100)
      End If 
    Next
    Msgbox(String.Format("Es wurden {0} Gruppen der Gruppe '{1}' untergeordnet.", lMoved, oMotherGroup.Name), MsgBoxStyle.Information, m_sScriptName)
    If lMoved &gt; 0 Then
      m_oACTOptimum.refreshView
    End If
    Abbruch:
    TryPrintStatus(String.Empty)
    m_oACTApp.Cursor = Cursors.Default
    
  End Sub
  
  Private Shared m_oACTApp As Act.UI.ActApplication
  Private Shared m_oACTOptimum As Melville_Schellmann.ACTOptimum6.Plugin.ACTOptimumManager
  Private Shared m_sScriptName As String
  
  Private Shared Function TrySelectGroup(ByRef oGroup As Act.Framework.Groups.Group) As Boolean
    
    ' AddReference("ACT.UI.GroupCompanyPicker")
    ' AddReference("Act.UI.Widgets")
    ' AddReference("Infralution.Controls.VirtualTree")
    ' AddReference("Infralution.Controls")

    Dim bIsGroupSelected As Boolean = False
    
    Dim oDialog As Act.UI.GroupCompanyPicker.SelectGroupCompanyDialog
    oDialog = New Act.UI.GroupCompanyPicker.SelectGroupCompanyDialog(m_oACTApp.ActFramework, Act.UI.GroupCompanyPicker.ViewType.Groups)
    oDialog.Text = "Gruppenauswahl"
    oDialog.Icon = Melville_Schellmann.ACTOptimum6.Plugin.Icons.IconManager.GetIcon("ACT_Group")

    Do
      If oDialog.ShowDialog(m_oACTApp) = DialogResult.Cancel Then
        GoTo Abbruch
      End If
      If oDialog.SelectedGroups Is Nothing OrElse oDialog.SelectedGroups.Count = 0 Then
        Msgbox("Bitte wählen Sie eine Gruppe aus.", MsgBoxStyle.Information, m_sScriptName)
      End If
      If oDialog.SelectedGroups.Count &gt; 1 Then
        Msgbox("Bitte wählen Sie nur eine Gruppe aus.", MsgBoxStyle.Information, m_sScriptName)
      End If
    Loop Until oDialog.SelectedGroups.Count = 1
    oGroup = oDialog.SelectedGroups.Item(0)
    bIsGroupSelected = True
    
    Abbruch:
    Return bIsGroupSelected
    
  End Function
  
  Private Shared Function TryPrintStatus(sMessage As String) As Boolean
    Dim plStatus  As System.Windows.Forms.StatusBarPanel
    Dim sCancelMesssage As String = "Drücken Sie die ESC-Taste um den Vorgang zu unterbrechen."
    
    TryPrintStatus = False
    
    If m_oACTApp Is Nothing Then
      Msgbox("m_oACTApp is missing.") 
      GoTo Abbruch
    End If
    If m_oACTApp.StatusBar Is Nothing Then
      Msgbox("Statusbar is missing.") 
      GoTo Abbruch
    End If
    plStatus = m_oACTApp.StatusBar.Panels.Item(1)
    
    If plStatus.ToolTipText.IndexOf(sCancelMesssage) &lt; 0 Then
      plStatus.ToolTipText = sCancelMesssage
      plStatus.Tag = Nothing
      AddHandler m_oACTApp.StatusBar.KeyUp, AddressOf Application_KeyUp
    Else
      If plStatus.Tag = "Cancel"  Then
        sMessage = String.Empty
      End If
    End If
    
    If  System.String.IsNullOrEmpty(sMessage) Then
      plStatus.Text = sMessage
      plStatus.ToolTipText = String.Empty
      plStatus.Tag = Nothing
      RemoveHandler m_oACTApp.StatusBar.KeyUp, AddressOf Application_KeyUp
    Else
      plStatus.Text = sMessage &amp; " " &amp; sCancelMesssage
      If m_oACTApp.StatusBar.Focused = False Then
        m_oACTApp.StatusBar.Focus
      End If
      TryPrintStatus = True
    End If
    
    Abbruch:
  End Function
  Private Shared Sub Application_KeyUp(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs)
    If CType(e.KeyCode, Integer) = Keys.Escape Then
      If Msgbox("Wollen Sie den Vorgang abbrechen?", MsgBoxStyle.YesNo Or MsgBoxStyle.Question, "Vorgangsunterbrechung") = MsgBoxResult.Yes Then
        CType(sender, System.Windows.Forms.statusbar).Panels.Item(1).Tag = "Cancel"
      End If 
    End If
  End Sub
  Private Sub Dummy</SourceCode>
        <IconName>ACT_Group</IconName>
    </AutoDataMenu>
</ACTOptimumItems>