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

@ -5,7 +5,7 @@ Public Class ClassControlCreator
''' <summary>
''' Konstanten
''' </summary>
Private Const LABEL_TEXT = "Bezeichnung definieren"
Private Const DEFAULT_TEXT = "Bezeichnung definieren"
Private Const DEFAULT_FONT_SIZE As Integer = 10
Private Const DEFAULT_FONT_FAMILY As String = "Arial"
@ -13,8 +13,15 @@ Public Class ClassControlCreator
Private Const DEFAULT_COLOR As Integer = 0
Private Const DEFAULT_WIDTH As Integer = 170
Private Const DEFAULT_HEIGHT As Integer = 20
Private Const DEFAULT_HEIGHT_TABLE As Integer = 150
Private Const PREFIX_TEXTBOX = "TXT"
Private Const PREFIX_LABEL = "LBL"
Private Const PREFIX_CHECKBOX = "CHK"
Private Const PREFIX_COMBOBOX = "CMB"
Private Const PREFIX_DATETIMEPICKER = "DTP"
Private Const PREFIX_DATAGRIDVIEW = "DGV"
Private Const PREFIX_TABLE = "TB"
''' <summary>
''' Standard Eigenschaften für alle Controls
@ -75,7 +82,96 @@ Public Class ClassControlCreator
}
Return control
End Function
Public Shared Function CreateNewLabel(location As Point) As Label
Dim control As New Label With {
.Name = $"{PREFIX_LABEL}_{clsTools.ShortGUID}",
.Text = DEFAULT_TEXT,
.AutoSize = True,
.Location = location,
.Cursor = Cursors.Hand
}
Return control
End Function
Public Shared Function CreateNewCheckbox(location As Point) As CheckBox
Dim control As New CheckBox With {
.Name = $"{PREFIX_CHECKBOX}_{clsTools.ShortGUID}",
.AutoSize = True,
.Text = DEFAULT_TEXT,
.Cursor = Cursors.Hand,
.Location = location
}
Return control
End Function
Public Shared Function CreateNewCombobox(location As Point) As ComboBox
Dim control As New ComboBox With {
.Name = $"{PREFIX_COMBOBOX}_{clsTools.ShortGUID}",
.Size = New Size(DEFAULT_WIDTH, DEFAULT_HEIGHT),
.Cursor = Cursors.Hand,
.Location = location
}
Return control
End Function
Public Shared Function CreateNewDatetimepicker(location As Point) As DateTimePicker
Dim control As New DateTimePicker With {
.Name = $"{PREFIX_DATETIMEPICKER}_{clsTools.ShortGUID}",
.Size = New Size(DEFAULT_WIDTH, DEFAULT_HEIGHT),
.Cursor = Cursors.Hand,
.Location = location,
.Format = DateTimePickerFormat.Short
}
Return control
End Function
Public Shared Function CreateNewDatagridview(location As Point) As DataGridView
Dim control As New DataGridView With {
.Name = $"{PREFIX_DATAGRIDVIEW}_{clsTools.ShortGUID}",
.Size = New Size(DEFAULT_WIDTH, DEFAULT_HEIGHT_TABLE),
.Cursor = Cursors.Hand,
.AllowUserToAddRows = False,
.AllowUserToDeleteRows = False,
.AllowUserToResizeColumns = False,
.AllowUserToResizeRows = False
}
control.Columns.Add(New DataGridViewTextBoxColumn With {
.HeaderText = "",
.Name = "column1"
})
Return control
End Function
Public Shared Function CreateNewTable(location As Point) As DataGridView
Dim control As New DataGridView With {
.Name = $"{PREFIX_TABLE}_{clsTools.ShortGUID}",
.Size = New Size(DEFAULT_WIDTH, DEFAULT_HEIGHT_TABLE),
.Cursor = Cursors.Hand,
.AllowUserToAddRows = False,
.AllowUserToDeleteRows = False,
.AllowUserToResizeColumns = False,
.AllowUserToResizeRows = False
}
control.Columns.Add(New DataGridViewTextBoxColumn With {
.HeaderText = "Column1",
.Name = "column1"
})
control.Columns.Add(New DataGridViewTextBoxColumn With {
.HeaderText = "Column2",
.Name = "column2"
})
Return control
End Function
' ----------------------- EXISITING CONTROLS -----------------------

View File

@ -313,7 +313,6 @@ Partial Class frmFormDesigner
Me.gbxControl.TabIndex = 4
Me.gbxControl.TabStop = False
Me.gbxControl.Text = "Controleigenschaften:"
Me.gbxControl.Visible = False
'
'TabControlEigenschaften
'
@ -324,6 +323,7 @@ Partial Class frmFormDesigner
Me.TabControlEigenschaften.Controls.Add(Me.pageFormat)
Me.TabControlEigenschaften.Controls.Add(Me.pageSQL)
Me.TabControlEigenschaften.Controls.Add(Me.pagePropertiesOld)
Me.TabControlEigenschaften.Enabled = False
Me.TabControlEigenschaften.Location = New System.Drawing.Point(12, 22)
Me.TabControlEigenschaften.Name = "TabControlEigenschaften"
Me.TabControlEigenschaften.SelectedIndex = 0

View File

@ -137,9 +137,18 @@
<metadata name="TBPM_PROFILE_CONTROLSBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>179, 17</value>
</metadata>
<metadata name="TBPM_PROFILE_CONTROLSBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>179, 17</value>
</metadata>
<metadata name="DD_DMSLiteDataSet.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="DD_DMSLiteDataSet.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
<metadata name="TBPM_CONNECTIONBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>1021, 17</value>
</metadata>
<metadata name="TBPM_CONNECTIONBindingSource.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>1021, 17</value>
</metadata>
@ -149,6 +158,9 @@
<metadata name="StatusStrip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>904, 17</value>
</metadata>
<metadata name="ToolTip1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>898, 56</value>
</metadata>
<metadata name="TBPM_PROFILE_CONTROLSTableAdapter.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>458, 17</value>
</metadata>

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