Initial commit
This commit is contained in:
172
EDOKA_Erweiterungen/Form1.vb
Normal file
172
EDOKA_Erweiterungen/Form1.vb
Normal file
@@ -0,0 +1,172 @@
|
||||
Imports System.IO
|
||||
Imports System.Reflection
|
||||
Imports PluginContracts
|
||||
Public Class Form1
|
||||
Dim db As New DB_Connection
|
||||
Dim plugins As ICollection(Of IPlugin) = New List(Of IPlugin)
|
||||
Private _Plugins As Dictionary(Of String, IPlugin)
|
||||
Dim f As Form
|
||||
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
|
||||
|
||||
Dim splitter() As String
|
||||
Dim Pluginname As String
|
||||
Dim s As String
|
||||
For i As Integer = 1 To Environment.GetCommandLineArgs.Count - 1
|
||||
s = Environment.GetCommandLineArgs(i)
|
||||
splitter = s.Split("=")
|
||||
Select Case splitter(0)
|
||||
Case "/Plugin"
|
||||
Pluginname = splitter(1)
|
||||
Case ("/MA")
|
||||
Globals.Mitarbeiternr = splitter(1)
|
||||
End Select
|
||||
Next
|
||||
splitter = s.Split("")
|
||||
Load_Plugins()
|
||||
|
||||
Try
|
||||
If _Plugins.ContainsKey(Pluginname) Then
|
||||
Dim plugin As IPlugin = _Plugins(Pluginname)
|
||||
plugin.Show(Globals.Mitarbeiternr, "", Me)
|
||||
End If
|
||||
Catch ex As Exception
|
||||
|
||||
End Try
|
||||
Try
|
||||
Dim mdichild As Form = Me.ActiveMdiChild
|
||||
Me.Width = mdichild.Width + 50
|
||||
Me.Height = mdichild.Height + 50 + Me.MainMenuStrip.Height
|
||||
'mdichild.FormBorderStyle = FormBorderStyle.None
|
||||
Me.BackColor = Color.Coral
|
||||
Dim C As Control
|
||||
|
||||
|
||||
|
||||
For Each C In Me.Controls
|
||||
|
||||
If TypeOf C Is MdiClient Then
|
||||
|
||||
C.BackColor = Color.White
|
||||
|
||||
Exit For
|
||||
|
||||
End If
|
||||
|
||||
Next
|
||||
|
||||
|
||||
|
||||
C = Nothing
|
||||
|
||||
Catch ex As Exception
|
||||
MsgBox("Beim Aufrunf der Erweiterung ist ein Fehler aufgetreten (" + ex.Message + ")" + vbCrLf + "Die Funktion wird beendet.", vbExclamation)
|
||||
Me.Close()
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Public Shared Function GetForm(ByVal handle As IntPtr) As Form
|
||||
Return If(handle = IntPtr.Zero, Nothing, TryCast(Control.FromHandle(handle), Form))
|
||||
End Function
|
||||
|
||||
|
||||
Sub Load_Plugins()
|
||||
Dim clsp As New clsPlugin
|
||||
If clsp.get_pluginrechte = "" Then
|
||||
Exit Sub
|
||||
End If
|
||||
Dim path As String
|
||||
path = clsp.get_path
|
||||
plugins = LoadPlugins(path)
|
||||
Populate_Plugins()
|
||||
End Sub
|
||||
|
||||
Public Function LoadPlugins(path As String) As ICollection(Of IPlugin)
|
||||
Dim dllFileNames As String()
|
||||
|
||||
If Directory.Exists(path) Then
|
||||
|
||||
dllFileNames = Directory.GetFiles(path, "*.dll")
|
||||
|
||||
Dim assemblies As ICollection(Of Assembly) = New List(Of Assembly)(dllFileNames.Length)
|
||||
For Each dllFile As String In dllFileNames
|
||||
Dim an As AssemblyName = AssemblyName.GetAssemblyName(dllFile)
|
||||
Dim assembly As Assembly = Assembly.Load(an)
|
||||
assemblies.Add(assembly)
|
||||
Next
|
||||
|
||||
Dim pluginType As Type = GetType(IPlugin)
|
||||
Dim pluginTypes As ICollection(Of Type) = New List(Of Type)
|
||||
For Each assembly As Assembly In assemblies
|
||||
If assembly <> Nothing Then
|
||||
Dim types As Type() = assembly.GetTypes()
|
||||
|
||||
For Each type As Type In types
|
||||
If type.IsInterface Or type.IsAbstract Then
|
||||
Continue For
|
||||
Else
|
||||
If type.GetInterface(pluginType.FullName) <> Nothing Then
|
||||
pluginTypes.Add(type)
|
||||
End If
|
||||
End If
|
||||
Next
|
||||
End If
|
||||
Next
|
||||
|
||||
Dim plugins As ICollection(Of IPlugin) = New List(Of IPlugin)(pluginTypes.Count)
|
||||
For Each type As Type In pluginTypes
|
||||
Dim plugin As IPlugin = Activator.CreateInstance(type)
|
||||
plugins.Add(plugin)
|
||||
Next
|
||||
|
||||
Return plugins
|
||||
End If
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
|
||||
Private Sub Populate_Plugins()
|
||||
Dim clsp As New clsPlugin
|
||||
|
||||
_Plugins = New Dictionary(Of String, IPlugin)
|
||||
|
||||
Dim mi As New MenuItem
|
||||
|
||||
Dim item As Object
|
||||
|
||||
|
||||
Dim i As Integer = 0
|
||||
For Each item In plugins
|
||||
|
||||
'Dim pluginmenuiteam As New MenuItem(item.name)
|
||||
'Me.MenuitemErweiterungen.MenuItems.Add(pluginmenuiteam)
|
||||
|
||||
_Plugins.Add(item.Name, item)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
''lstPlugins.Items.Add(item.Name)
|
||||
'Dim tmisub As New ToolStripMenuItem
|
||||
'tmisub = Me.ToolstipdropdownErweiterungen.DropDownItems.Add(item.name)
|
||||
'AddHandler tmisub.Click, AddressOf Erweiterungen_Click
|
||||
Next
|
||||
|
||||
|
||||
'lstPlugins.SelectedIndex = 0
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub MnuItemPlugin1_Click(sender As Object, e As EventArgs)
|
||||
If _Plugins.ContainsKey(sender.text) Then
|
||||
Dim plugin As IPlugin = _Plugins(sender.text)
|
||||
plugin.Show(Globals.Mitarbeiternr, "", Me)
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Private Sub SchliessenToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles SchliessenToolStripMenuItem.Click
|
||||
Me.Close()
|
||||
End Sub
|
||||
End Class
|
||||
Reference in New Issue
Block a user