<?xml version="1.0" encoding="utf-16" standalone="yes"?>
<!--Created: 18.05.2017 12:12:20-->
<!--ACTOptimumVersion: 6.0.6282.19592-->
<ACTOptimumItems ACTOptimumVersion="6.0.6282.19592" Created="18.05.2017 12:12:20">
    <AutoDataMenu Created="18.05.2017 12:12:20" ClassName="Melville_Schellmann.ACTOptimum6.Plugin.MenuItemAutoData" PrefClassVersion="1.0" ACTOptimumVersion="6.0.6282.19592">
        <GlobalPref>True</GlobalPref>
        <NeededRole>2</NeededRole>
        <Name>Firmen verschieben...</Name>
        <Tooltip>Verschiebt auswahl an Firmen als Unterfirmen zu einer einer Mutterfirma</Tooltip>
        <Description>Verschiebt auswahl an Firmen als Unterfirmen zu einer einer Mutterfirma</Description>
        <CommandBar>Connected Menus</CommandBar>
        <Menu>act-ui://com.act/application/menu/group/company</Menu>
        <Index>10</Index>
        <Separator>False</Separator>
        <Shortcut>None</Shortcut>
        <SourceCode>' #ScriptName: MoveCompanies
    ' #Description: Verschiebt markierte Firmen in der Firmenlistenauswahl unter eine Firma.
    ' #Copyright: © 2017 by Melville-Schellmann
    ' #Author: Robert Schellmann, rs@melville-schellmann.de
    ' #Version: 1.0 (11.05.2017) s.o.

    m_oACTApp = ACTApp
    m_oACTOptimum = ACTOptimum
    m_sScriptName = "MoveCompanies"
    
    Dim oMotherCompany As Act.Framework.Companies.Company
    Dim oCompanies As  Act.Framework.Companies.CompanyList
    Dim oCompanyListView As Act.UI.ICompanyListView
    Dim lIndex As Integer
    Dim lMoved As Integer
    
    If Not TypeOf(m_oACTApp.CurrentView) Is Act.UI.ICompanyListView Then
      Msgbox("Bitte rufen Sie diese Funktion nur in der Firmenlistenansicht auf, wo Sie zuvor die zu verschiebenen Firmen markieren.", MsgBoxStyle.Information, m_sScriptName)
      GoTo Abbruch
    End If
    oCompanyListView = CType(m_oACTApp.CurrentView, Act.UI.ICompanyListView)        
    oCompanies = oCompanyListView.GetSelectedCompanies
    If oCompanies Is Nothing Or oCompanies.Count = 0 Then
      Msgbox("Bitte markieren Sie die Firmen, die einer Firma untergeordnet werden sollen.")
    End If
    If TrySelectGroup(oMotherCompany) = False Then
      GoTo Abbruch
    End If
    If oCompanies.Contains(oMotherCompany) Then
      Msgbox(String.Format("Die ausgewählte Firma '{0}' befindet sich unter den markierten Firman.", oMotherCompany.Name) &amp; vbcrlf &amp; _
        "Der Vorgang wird abgebrochen.", MsgBoxStyle.Exclamation, m_sScriptName) 
      GoTo Abbruch
    End If    
    
    lMoved = 0 
    For lIndex = 0 To oCompanies.Count - 1
      m_oACTApp.Cursor = Cursors.WaitCursor
      If Not TryPrintStatus(String.Format("Verschiebe Firma '{0}' ... ({1}/{2})", oCompanies.Item(lIndex).Name, lIndex, oCompanies.Count)) Then
        GoTo Abbruch
      End If
      Application.DoEvents
      Threading.thread.sleep(100)
      If  oCompanies.Item(lIndex).ParentID &lt;&gt; oMotherCompany.ID Then
        Try
          oCompanies.Item(lIndex).SetParent(oMotherCompany)  
          oCompanies.item(lindex).Update
          lMoved += 1
        Catch ex As Exception
          MsgBox(String.Format("Es ist ein Fehler beim Verschieben der Firma '{0}' unter die Firma '{1}' aufgetreten.", oCompanies.Item(lIndex).Name, oMotherCompany.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} Firma/en der Firma '{1}' untergeordnet.", lMoved, oMotherCompany.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 oCompany As Act.Framework.Companies.Company) As Boolean
    
    ' AddReference("ACT.UI.GroupCompanyPicker")
    ' AddReference("Act.UI.Widgets")
    ' AddReference("Infralution.Controls.VirtualTree")
    ' AddReference("Infralution.Controls")

    Dim bIsCompanieselected As Boolean = False
    
    Dim oDialog As Act.UI.GroupCompanyPicker.SelectGroupCompanyDialog
    oDialog = New Act.UI.GroupCompanyPicker.SelectGroupCompanyDialog(m_oACTApp.ActFramework, Act.UI.GroupCompanyPicker.ViewType.Companies)
    oDialog.Text = "Firmanauswahl"
    oDialog.Icon = Melville_Schellmann.ACTOptimum6.Plugin.Icons.IconManager.GetIcon("ACT_Company")

    Do
      If oDialog.ShowDialog(m_oACTApp) = DialogResult.Cancel Then
        GoTo Abbruch
      End If
      If oDialog.SelectedCompanies Is Nothing OrElse oDialog.SelectedCompanies.Count = 0 Then
        Msgbox("Bitte wählen Sie eine Firma aus.", MsgBoxStyle.Information, m_sScriptName)
      End If
      If oDialog.SelectedCompanies.Count &gt; 1 Then
        Msgbox("Bitte wählen Sie nur eine Firma aus.", MsgBoxStyle.Information, m_sScriptName)
      End If
    Loop Until oDialog.SelectedCompanies.Count = 1
    oCompany = oDialog.SelectedCompanies.Item(0)
    bIsCompanieselected = True
    
    Abbruch:
    Return bIsCompanieselected
    
  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_Company</IconName>
    </AutoDataMenu>
</ACTOptimumItems>