JJ: BAUSTELLE FormDesigner

This commit is contained in:
Jonathan Jenne
2018-03-29 16:06:15 +02:00
parent 0cdca65efe
commit 1237dcad0c
4 changed files with 268 additions and 79 deletions

View File

@@ -14,9 +14,14 @@ Public Class frmFormDesigner
Private CURRENT_CONTROL As Control
' Movement Variables
Private MouseMoving As Boolean
Private BeginLocation As Point
Private EndLocation As Point
Private Mouse_IsPressed As Boolean
Private Mouse_IsMoving As Boolean
Private Mouse_BeginLocation As Point
Private Mouse_EndLocation As Point
' Windream List Data
Private Windream_ChoiceLists As List(Of String)
Private Windream_Indicies As List(Of String)
Private Sub frmFormDesigner_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing
If CURRENT_ProfilGUID > 0 Then
@@ -53,12 +58,18 @@ Public Class frmFormDesigner
'löscht alle Controls
pnldesigner.Controls.Clear()
CURRENT_CONTROL = Nothing
Try
' Windream initialisieren
clsWindream.Create_Session()
'Windream Abfragen, sollten einmal beim Start des Formulars geladen werden
Windream_Indicies = clsWD_GET.GetIndicesByObjecttype(CURRENT_OBJECTTYPE).ToList()
Windream_ChoiceLists = clsWD_GET.GetChoiceLists()
Catch ex As Exception
MsgBox("Fehler bei Initialisieren von windream: " & vbNewLine & ex.Message, MsgBoxStyle.Critical, "Achtung:")
End Try
Try
TBPM_PROFILE_CONTROLSTableAdapter.Connection.ConnectionString = MyConnectionString
TBPM_CONNECTIONTableAdapter.Connection.ConnectionString = MyConnectionString
@@ -256,6 +267,8 @@ Public Class frmFormDesigner
Select r).ToList()
Dim table = ClassControlCreator.CreateExistingTable(row, columns, True)
AddHandler table.ColumnHeaderMouseClick, AddressOf table_ColumnHeaderMouseClick
pnldesigner.Controls.Add(table)
SetMovementHandlers(table)
End Select
@@ -302,50 +315,103 @@ Public Class frmFormDesigner
End If
End Sub
Private Sub btnlabel_MouseMove(sender As Object, e As MouseEventArgs) Handles btnlabel.MouseMove
If MouseIsDown Then
' Initiate dragging.
btnlabel.DoDragDrop("lbl", DragDropEffects.Copy)
End If
MouseIsDown = False
End Sub
Private Sub pnlDesigner_DragDrop(sender As Object, e As DragEventArgs) Handles pnldesigner.DragDrop
Dim cursorPosition As Point = pnldesigner.PointToClient(Cursor.Position)
Private Sub btntextbox_MouseMove(sender As Object, e As MouseEventArgs) Handles btntextbox.MouseMove
If MouseIsDown Then
' Initiate dragging.
btntextbox.DoDragDrop("txt", DragDropEffects.Copy)
End If
MouseIsDown = False
End Sub
Private Sub Panel2_DragDrop(sender As Object, e As System.Windows.Forms.DragEventArgs) Handles pnldesigner.DragDrop
Dim r As New Random()
Dim random As Integer = r.Next(8, 100)
Select Case e.Data.GetData(DataFormats.Text)
Case "lbl"
'idxlbl += 1
AddNewLabel("lbl" & random.ToString)
Dim label = ClassControlCreator.CreateNewLabel(cursorPosition)
SetMovementHandlers(label)
TBPM_PROFILE_CONTROLSTableAdapter.cmdInsertAnlage(CURRENT_ProfilGUID, label.Name, "LBL", label.Text, label.Location.X, label.Location.Y, Environment.UserName, label.Size.Height, label.Size.Width)
CURRENT_CONTROL = label
CURRENT_CONTROL.Tag = GetLastID()
pnldesigner.Controls.Add(label)
'AddNewLabel("lbl" & Random.ToString)
Case "txt"
'idxtxt += 1
AddNewTextbox("txt" & random)
Dim txt = ClassControlCreator.CreateNewTextBox(cursorPosition)
SetMovementHandlers(txt)
TBPM_PROFILE_CONTROLSTableAdapter.cmdInsertAnlage(CURRENT_ProfilGUID, txt.Name, "TXT", txt.Name, txt.Location.X, txt.Location.Y, Environment.UserName, txt.Size.Height, txt.Size.Width)
CURRENT_CONTROL = txt
CURRENT_CONTROL.Tag = GetLastID()
pnldesigner.Controls.Add(txt)
'AddNewTextbox("txt" & Random)
Case "cmb"
'idxcmb += 1
AddNewCombobox("cmb" & random)
Dim cmb = ClassControlCreator.CreateNewCombobox(cursorPosition)
SetMovementHandlers(cmb)
TBPM_PROFILE_CONTROLSTableAdapter.cmdInsertAnlage(CURRENT_ProfilGUID, cmb.Name, "CMB", cmb.Name, cmb.Location.X, cmb.Location.Y, Environment.UserName, cmb.Size.Height, cmb.Size.Width)
CURRENT_CONTROL = cmb
CURRENT_CONTROL.Tag = GetLastID()
pnldesigner.Controls.Add(cmb)
'AddNewCombobox("cmb" & random)
Case "dtp"
'idxdtp += 1
AddNewDatetimepicker("dtp" & random)
Case "dgv"
'idxdgv += 1
AddNewDGV("dgv" & random)
Dim dtp = ClassControlCreator.CreateNewDatetimepicker(cursorPosition)
SetMovementHandlers(dtp)
TBPM_PROFILE_CONTROLSTableAdapter.cmdInsertAnlage(CURRENT_ProfilGUID, dtp.Name, "DTP", dtp.Name, dtp.Location.X, dtp.Location.Y, Environment.UserName, dtp.Size.Height, dtp.Size.Width)
CURRENT_CONTROL = dtp
CURRENT_CONTROL.Tag = GetLastID()
pnldesigner.Controls.Add(dtp)
'AddNewDatetimepicker("dtp" & random)
Case "chk"
' idxchk += 1
AddNewCheckbox("chk" & random)
Dim chk = ClassControlCreator.CreateNewCheckbox(cursorPosition)
SetMovementHandlers(chk)
TBPM_PROFILE_CONTROLSTableAdapter.cmdInsertAnlage(CURRENT_ProfilGUID, chk.Name, "CHK", chk.Text, chk.Location.X, chk.Location.Y, Environment.UserName, chk.Size.Height, chk.Size.Width)
CURRENT_CONTROL = chk
CURRENT_CONTROL.Tag = GetLastID()
pnldesigner.Controls.Add(chk)
'AddNewCheckbox("chk" & random)
Case "dgv"
Dim dgv = ClassControlCreator.CreateNewDatagridview(cursorPosition)
SetMovementHandlers(dgv)
TBPM_PROFILE_CONTROLSTableAdapter.cmdInsertAnlage(CURRENT_ProfilGUID, dgv.Name, "DGV", dgv.Name, dgv.Location.X, dgv.Location.Y, Environment.UserName, dgv.Size.Height, dgv.Size.Width)
CURRENT_CONTROL = dgv
CURRENT_CONTROL.Tag = GetLastID()
pnldesigner.Controls.Add(dgv)
'AddNewDGV("dgv" & random)
Case "tb"
AddNewTable("tb" & random)
Dim tb = ClassControlCreator.CreateNewTable(cursorPosition)
SetMovementHandlers(tb)
AddHandler tb.ColumnHeaderMouseClick, AddressOf table_ColumnHeaderMouseClick
TBPM_PROFILE_CONTROLSTableAdapter.cmdInsertAnlage(CURRENT_ProfilGUID, tb.Name, "TABLE", tb.Name, tb.Location.X, tb.Location.Y, Environment.UserName, tb.Size.Height, tb.Size.Width)
CURRENT_CONTROL = tb
CURRENT_CONTROL.Tag = GetLastID()
TBPM_CONTROL_TABLETableAdapter.Insert(CURRENT_CONTROL.Tag, "column1", "Column1", 95, Environment.UserName)
TBPM_CONTROL_TABLETableAdapter.Insert(CURRENT_CONTROL.Tag, "column2", "Column2", 95, Environment.UserName)
pnldesigner.Controls.Add(tb)
'AddNewTable("tb" & Random)
End Select
End Sub
Private Sub Panel2_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles pnldesigner.DragEnter
Private Sub pnlDesigner_DragEnter(sender As System.Object, e As System.Windows.Forms.DragEventArgs) Handles pnldesigner.DragEnter
' Check the format of the data being dropped.
If (e.Data.GetDataPresent(DataFormats.Text)) Then
' Display the copy cursor.
@@ -364,34 +430,34 @@ Public Class frmFormDesigner
Return 0
End Try
End Function
Function AddNewLabel(lblname As String)
Try
Dim lbl As New Label
lbl.Name = lblname
lbl.Text = "Bez. definieren"
lbl.AutoSize = True
Dim clientPosition As Point = pnldesigner.PointToClient(Cursor.Position)
lbl.Location = New Point(clientPosition)
pnldesigner.Controls.Add(lbl)
CURRENT_CONTROL = lbl
'Function AddNewLabel(lblname As String)
' Try
' Dim lbl As New Label
' lbl.Name = lblname
' lbl.Text = "Bez. definieren"
' lbl.AutoSize = True
' Dim clientPosition As Point = pnldesigner.PointToClient(Cursor.Position)
' lbl.Location = New Point(clientPosition)
' pnldesigner.Controls.Add(lbl)
' CURRENT_CONTROL = lbl
SetMovementHandlers(lbl)
' SetMovementHandlers(lbl)
TBPM_PROFILE_CONTROLSTableAdapter.cmdInsertAnlage(CURRENT_ProfilGUID, lbl.Name, "LBL", lblname, lbl.Location.X, lbl.Location.Y, Environment.UserName, 16, 200)
CURRENT_CONTROL.Tag = GetLastID()
'Load_Control()
btnsave.Visible = True
Catch ex As Exception
MsgBox("Fehler bei Anlegen Label: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
End Try
End Function
Function AddExistingLabel(lbl As Label, text As String)
lbl.Text = text
lbl.AutoSize = True
' TBPM_PROFILE_CONTROLSTableAdapter.cmdInsertAnlage(CURRENT_ProfilGUID, lbl.Name, "LBL", lblname, lbl.Location.X, lbl.Location.Y, Environment.UserName, 16, 200)
' CURRENT_CONTROL.Tag = GetLastID()
' 'Load_Control()
' btnsave.Visible = True
' Catch ex As Exception
' MsgBox("Fehler bei Anlegen Label: " & vbNewLine & ex.Message, MsgBoxStyle.Critical)
' End Try
'End Function
'Function AddExistingLabel(lbl As Label, text As String)
' lbl.Text = text
' lbl.AutoSize = True
pnldesigner.Controls.Add(lbl)
SetMovementHandlers(lbl)
End Function
' pnldesigner.Controls.Add(lbl)
' SetMovementHandlers(lbl)
'End Function
Private Function GetLastID()
Dim sql = String.Format("SELECT MAX(GUID) FROM TBPM_PROFILE_CONTROLS WHERE PROFIL_ID = {0}", CURRENT_ProfilGUID)
@@ -902,6 +968,7 @@ Public Class frmFormDesigner
Private Sub btndelete_Click(sender As System.Object, e As EventArgs) Handles btndelete.Click
If CURRENT_CONTROL Is Nothing = False Then
delete_Control(CURRENT_CONTROL.Name)
TabControlEigenschaften.Enabled = False
End If
End Sub
@@ -1068,22 +1135,25 @@ Public Class frmFormDesigner
Private Sub OnControl_MouseDown(sender As Control, e As MouseEventArgs)
If e.Button = MouseButtons.Left Then
CURRENT_CONTROL = sender
BeginLocation = e.Location
Mouse_BeginLocation = e.Location
sender.BringToFront()
MouseMoving = True
Mouse_IsPressed = True
Console.WriteLine("CURRENT_CONTROL:" & CURRENT_CONTROL.Name)
End If
End Sub
Private Sub OnControl_MouseUp(sender As Control, e As MouseEventArgs)
If MouseMoving Then
MouseMoving = False
EndLocation = e.Location
Mouse_IsPressed = False
Dim CurrentPosition As Point = DirectCast(pgControls.SelectedObject, BaseProperties).Location
If Mouse_IsMoving Then
Mouse_IsMoving = False
If Point.op_Inequality(CurrentPosition, EndLocation) Then
Dim CurrentPosition = CURRENT_CONTROL.Location
Dim OldPosition As Point = DirectCast(pgControls.SelectedObject, BaseProperties).Location
If Point.op_Inequality(CurrentPosition, OldPosition) Then
DirectCast(pgControls.SelectedObject, BaseProperties).Location = CURRENT_CONTROL.Location
UpdateSingleValue("X_LOC", CURRENT_CONTROL.Location.X)
@@ -1100,18 +1170,21 @@ Public Class frmFormDesigner
Exit Sub
End If
If MouseMoving Then
Mouse_IsMoving = True
Console.WriteLine("Mouse Moving!")
If Mouse_IsPressed Then
Cursor = Cursors.Hand
Refresh()
Dim CurrentPosition As Point = GetCursorPosition()
If Point.op_Inequality(CurrentPosition, BeginLocation) Then
CURRENT_CONTROL.Location = New Point(CurrentPosition.X - BeginLocation.X, CurrentPosition.Y - BeginLocation.Y)
If Point.op_Inequality(CurrentPosition, Mouse_BeginLocation) Then
CURRENT_CONTROL.Location = New Point(CurrentPosition.X - Mouse_BeginLocation.X, CurrentPosition.Y - Mouse_BeginLocation.Y)
End If
End If
Catch ex As Exception
MouseMoving = False
Mouse_IsMoving = False
End Try
End Sub
@@ -1165,9 +1238,17 @@ Public Class frmFormDesigner
Private Sub OnControl_Click(sender As Control, e As MouseEventArgs)
Dim props
Dim dt As DataTable = DD_DMSLiteDataSet.TBPM_PROFILE_CONTROLS
Dim row = dt.AsEnumerable().Where(Function(r As DataRow)
Return r.Item("GUID") = sender.Tag
End Function).Single()
Dim row As DataRow
TabControlEigenschaften.Enabled = True
' Beim Laden der Eigenschaften eines Controls muss die ganze Datatable neu geladen werden
' Nicht wirklich, aber gibt gerade keine bessere Möglichkeit, ohne alle SQL Abfragen selbst auszuführen
TBPM_PROFILE_CONTROLSTableAdapter.FillByProfil(DD_DMSLiteDataSet.TBPM_PROFILE_CONTROLS, CURRENT_ProfilGUID)
row = dt.AsEnumerable().Where(Function(r As DataRow)
Return r.Item("GUID") = sender.Tag
End Function).Single()
' Globale Variablen setzen
CURRENT_CONTROL = sender
@@ -1321,12 +1402,12 @@ Public Class frmFormDesigner
End If
Try
ClassDatabase.Execute_non_Query($"UPDATE TBPM_PROFILE_CONTROLS SET {columnName} = {escapedValue} WHERE GUID = {guid}")
ClassDatabase.Execute_non_Query($"UPDATE TBPM_PROFILE_CONTROLS SET {columnName} = {escapedValue}, CHANGED_WHO = '{Environment.UserName}' WHERE GUID = {guid}")
tslblAenderungen.Visible = True
tslblAenderungen.Text = "Änderungen gespeichert - " & Now
Catch ex As Exception
Dim msg = $"Fehler beim Speichern von Control (Id: {guid}): {vbCrLf}{ex.Message}"
Dim msg = $"UpdateSingleValue - Fehler beim Speichern von Control (Id: {guid}): {vbCrLf}{ex.Message}"
MsgBox(msg)
ClassLogger.Add(msg)
End Try