redesign wip

This commit is contained in:
Jonathan Jenne
2020-03-02 13:59:59 +01:00
parent 40e80d0804
commit 5139d51c8d
30 changed files with 8041 additions and 18628 deletions

View File

@@ -1,135 +1,93 @@
Imports System.IO
Imports Microsoft.Office.Interop
Imports DevExpress.XtraGrid
Imports DevExpress.XtraGrid.Views.Grid
Imports DevExpress.XtraGrid.Views.Grid.ViewInfo
Public Class ClassDragDrop
Public Shared files_dropped As String()
Public Shared Function Drop_File(e As DragEventArgs)
Private downHitInfo As GridHitInfo = Nothing
Public Sub New()
End Sub
Public Sub AddGridView(view As GridView)
AddHandler view.MouseDown, AddressOf view_MouseDown
AddHandler view.MouseMove, AddressOf view_MouseMove
AddHandler view.GridControl.DragOver, AddressOf grid_DragOver
End Sub
Private Sub view_MouseDown(sender As Object, e As MouseEventArgs)
Dim view As GridView = sender
downHitInfo = Nothing
Dim hitInfo As GridHitInfo = view.CalcHitInfo(New Point(e.X, e.Y))
If Control.ModifierKeys <> Keys.None Then
Return
End If
If e.Button = MouseButtons.Left And hitInfo.RowHandle >= 0 Then
downHitInfo = hitInfo
End If
End Sub
Private Sub view_MouseMove(sender As Object, e As MouseEventArgs)
Try
ClassLogger.Add(">> Drop_File", False)
files_dropped = Nothing
If e.Data.GetDataPresent(DataFormats.FileDrop) Then
Dim MyFiles() As String
Dim i As Integer
' Assign the files to an array.
MyFiles = e.Data.GetData(DataFormats.FileDrop)
' Loop through the array and add the files to the list.
For i = 0 To MyFiles.Length - 1
ClassLogger.Add(">> Simple FileDrop - File: " & MyFiles(i), False)
ReDim Preserve files_dropped(i)
files_dropped(i) = "|DROPFROMFSYSTEM|" & MyFiles(i)
' ListBox1.Items.Add(MyFiles(i))
Next
Return True
ElseIf (e.Data.GetDataPresent("FileGroupDescriptor")) AndAlso (e.Data.GetDataPresent("FileContents")) Then
'// the first step here is to get the stbFileName
'// of the attachment and
'// build a full-path name so we can store it
'// in the temporary folder
'//
'// set up to obtain the aryFileGroupDescriptor
'// and extract the file name
Dim stmInput As IO.Stream = CType(e.Data.GetData("FileGroupDescriptor"), IO.Stream)
Dim aryFileGroupDescriptor(512) As Byte ' = new byte[512]
stmInput.Read(aryFileGroupDescriptor, 0, 512)
'// used to build the stbFileName from the aryFileGroupDescriptor block
Dim stbFileName As System.Text.StringBuilder = New System.Text.StringBuilder("")
'// this trick gets the stbFileName of the passed attached file
Dim intCnt As Integer = 76
Do While aryFileGroupDescriptor(intCnt) <> 0
stbFileName.Append(Convert.ToChar(aryFileGroupDescriptor(intCnt), System.Globalization.CultureInfo.CreateSpecificCulture("de-DE")))
intCnt += 1
Loop
stmInput.Close()
'Sonderzeichen entfernen
Dim Tempfilename = ClassFilehandle.InvalidCharacters(stbFileName.ToString)
Dim anhaenge = e.Data.GetDataPresent("FileContents")
'Dim path As String = "C:\VBProjekte\Dateien"
'// put the zip file into the temp directory
Dim strOutFile As String = Path.GetTempPath() & Tempfilename
'// create the full-path name
'//
'// Second step: we have the file name.
'// Now we need to get the actual raw
'// data for the attached file and copy it to disk so we work on it.
'//
'// get the actual raw file into memory
Dim msInput As IO.MemoryStream = CType(e.Data.GetData("FileContents", True), IO.MemoryStream) 'This returns nothing for an Email
If msInput Is Nothing = False Then
'// allocate enough bytes to hold the raw date
Dim aryFileBytes(CType(msInput.Length, Int32)) As Byte
'// set starting position at first byte and read in the raw data
msInput.Position = 0
msInput.Read(aryFileBytes, 0, CType(msInput.Length, Int32))
'// create a file and save the raw zip file to it
Dim fsOutput As IO.FileStream = New IO.FileStream(strOutFile, IO.FileMode.Create) ';
fsOutput.Write(aryFileBytes, 0, aryFileBytes.Length)
fsOutput.Close() ' // close the file
Dim resultVersion = ClassFilehandle.Versionierung_Datei(strOutFile)
If resultVersion <> "" Then
strOutFile = resultVersion
Dim view As GridView = sender
Dim hitInfo As GridHitInfo = view.CalcHitInfo(New Point(e.X, e.Y))
If e.Button = MouseButtons.Left And Not IsNothing(downHitInfo) Then
Dim dragSize As Size = SystemInformation.DragSize
Dim dragRect As New Rectangle(New Point(downHitInfo.HitPoint.X - dragSize.Width / 2, downHitInfo.HitPoint.Y - dragSize.Height / 2), dragSize)
' DragRect ist ein kleines Rechteck, dessen Mitte der Punkt ist, wo die Maus geklickt wurde.
' Es soll verhindern, dass durch schnelles Klicken unbeabsichtigt Drag'n'Drop Operationen initiiert werden
' Siehe: https://msdn.microsoft.com/en-us/library/system.windows.forms.systeminformation.dragsize(v=vs.110).aspx
If Not dragRect.Contains(New Point(e.X, e.Y)) Then
' dragDropData enhält eine einzelne Row oder den kompletten View,
' jenachdem, wie die Drag'n'Drop Operation gestartet wurde.
Dim dragDropData As String
' Wenn keine Zeile markiert ist
If downHitInfo.RowHandle < 0 Then
Exit Sub
End If
Dim finTemp As IO.FileInfo = New IO.FileInfo(strOutFile)
'// always good to make sure we actually created the file
If (finTemp.Exists = True) Then
ReDim Preserve files_dropped(0)
files_dropped(0) = "|OUTLOOK_ATTACHMENT|" & strOutFile
If LogErrorsOnly = False Then ClassLogger.Add(">> Drop an Attachment - File: " & strOutFile, False)
Return True
Else
ClassLogger.Add(">> Attachment File from Outlook could not be created", False)
' Wenn zwar eine Zeile markiert ist, aber keine über die Checkbox angehakt wurde,
' wird die markierte Zeile übergeben.
' Wenn 1 oder n Zeilen über die Checkbox angehakt wurde, werden diese übergeben
Dim row As DataRow = view.GetDataRow(downHitInfo.RowHandle)
Dim source As String = view.GridControl.Name
If Not IsNothing(row) Then
Try
dragDropData = row.Item("GUID") & "|" & source
view.GridControl.DoDragDrop(dragDropData, DragDropEffects.Move)
downHitInfo = Nothing
DevExpress.Utils.DXMouseEventArgs.GetMouseArgs(e).Handled = True
Catch ex As Exception
LOGGER.Error(ex)
End Try
End If
End If
End If
If e.Data.GetDataPresent("FileGroupDescriptor") Then
Dim oApp
Try
oApp = New Outlook.Application()
Catch ex As Exception
MsgBox("Unexpected error in Initialisieren von Outlook-API:" & vbNewLine & ex.Message & vbNewLine & vbNewLine & "Evtl ist Outlook nicht in der dafür vorgesehenen For")
End Try
ClassLogger.Add(">> Drop of msg", False)
'supports a drop of a Outlook message
Dim myobj As Object
For i As Integer = 1 To oApp.ActiveExplorer.Selection.Count
myobj = oApp.ActiveExplorer.Selection.Item(i)
Dim subj As String = myobj.Subject
If subj = "" Then
subj = "NO_SUBJECT"
End If
If subj.Contains("\") Then
subj = subj.Replace("\", "-")
End If
If subj.Contains("/") Then
subj = subj.Replace("/", "-")
End If
'Sonderzeichen entfernen
subj = ClassFilehandle.InvalidCharacters(subj)
'hardcode a destination path for testing
Dim strFile As String = IO.Path.Combine(Path.GetTempPath, subj + ".msg")
strFile = strFile.Replace("?", "")
strFile = strFile.Replace("!", "")
strFile = strFile.Replace("%", "")
strFile = strFile.Replace("$", "")
ClassLogger.Add(">> Drop of msg - File:" & strFile, False)
Try
myobj.SaveAs(strFile)
Catch ex As Exception
MsgBox("Error in Save Email2Tempfile" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return False
End Try
ReDim Preserve files_dropped(i)
files_dropped(i) = "|OUTLOOK_MESSAGE|" & strFile
Next
Return True
'Drop eines Outlook Attachments
End If
Catch ex As Exception
MsgBox("Error in Drop-File" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
Return False
LOGGER.Error(ex)
MsgBox("Error in view_MouseMove: " & ex.Message, MsgBoxStyle.Critical)
End Try
End Sub
End Function
Private Sub grid_DragOver(sender As Object, e As DragEventArgs)
If e.Data.GetDataPresent(DataFormats.Text) Then
Dim data As String = e.Data.GetData(DataFormats.Text)
Dim source = data.Split("|")(1)
Dim grid As GridControl = sender
If grid.Name <> source Then
e.Effect = DragDropEffects.Move
End If
Else
e.Effect = DragDropEffects.None
End If
End Sub
End Class