diff --git a/app/DD-Record-Organiser/frmGeodataNavigation.vb b/app/DD-Record-Organiser/frmGeodataNavigation.vb index e36f9e3..ce234d2 100644 --- a/app/DD-Record-Organiser/frmGeodataNavigation.vb +++ b/app/DD-Record-Organiser/frmGeodataNavigation.vb @@ -10,9 +10,11 @@ Public Class frmGeodataNavigation Private BING_KEY As String = "hQUTlqLLK70bETnonpfi~0jx1pIAq1yQ7gXqbIyzKrg~Au-Tewbty8afAxdbNilSv4JlU7qwU-fQKu0ouH9e1uJmpIyVdA3jugVEWMdy1Rbt" Private EntityId As Integer = Nothing Private EntitySql As String = Nothing - Private Grid As GridControl = Nothing + Private EntityDataTable As DataTable = Nothing + Private ConstructorMain_Grid As GridControl = Nothing Private CurrentPoint As GeoPoint = Nothing + #Region "MAP CONTROL" Private ReadOnly Property ImageLayer() As ImageTilesLayer Get @@ -32,10 +34,10 @@ Public Class frmGeodataNavigation Dim items As New List(Of MapCustomElementEx) ' Datensätze mit Lat,Lon Werten laden - Dim dt As DataTable = ClassDatabase.Return_Datatable(Me.EntitySql) + Dim rows As DataRow() = EntityDataTable.Select("LATITUDE IS NOT NULL AND LONGITUDE IS NOT NULL") ' PushPins - For Each row As DataRow In dt.Rows + For Each row As DataRow In rows Dim lat As Double = row.Item("LATITUDE") Dim lon As Double = row.Item("LONGITUDE") @@ -63,34 +65,21 @@ Public Class frmGeodataNavigation storage.Items.AddRange(items.ToArray()) VectorLayer.Data = storage - tsLabelRecordCount.Text = String.Format("{0} Elemente gefunden", items.Count) + tsLabelRecordCount.Text = String.Format("{0} Elemente mit Koordinaten gefunden", items.Count) MapControl1.ZoomToFitLayerItems() End Sub #End Region - + Public Sub New(ByRef gridControl As GridControl, ByVal EntityId As Integer) ' Dieser Aufruf ist für den Designer erforderlich. InitializeComponent() ' Fügen Sie Initialisierungen nach dem InitializeComponent()-Aufruf hinzu. - Me.Grid = gridControl - Me.EntityId = EntityId - Me.EntitySql = String.Format("SELECT T.*, T1.LATITUDE, T1.LONGITUDE from VWTEMP_PMO_FORM{0} T,TBPMO_RECORD_GEODATA T1 WHERE T.[Record-ID] = T1.RECORD_ID", Me.EntityId) - End Sub - - Private Sub frmGeodataNavigation_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing - Try - Dim gridView As Views.Grid.GridView = Me.Grid.FocusedView - gridView.ActiveFilterString = Nothing - Catch ex As Exception - MsgBox("Error in frmGeodataNavigation_FormClosing: " & vbNewLine & ex.Message) - End Try - End Sub - - Private Sub LoadGridData() - + Me.ConstructorMain_Grid = gridControl + 'Me.EntityId = EntityId + 'Me.EntitySql = String.Format("SELECT T.*, T1.LATITUDE, T1.LONGITUDE from VWTEMP_PMO_FORM{0} T,TBPMO_RECORD_GEODATA T1 WHERE T.[Record-ID] = T1.RECORD_ID", Me.EntityId) End Sub Private Sub frmGeodataNavigation_Load(sender As Object, e As EventArgs) Handles MyBase.Load @@ -99,66 +88,86 @@ Public Class frmGeodataNavigation dataProvider.BingKey = BING_KEY ImageLayer.DataProvider = dataProvider - LoadItemList() + EntitySql = Get_Grid_Sql(CURRENT_CONSTRUCTOR_ID, CURRENT_FORM_ID, CURRENT_CONSTRUCTOR_DETAIL_ID, frmConstructor_Main.GridType.Grid, USER_GUID, String.Empty, False, 1, 0, GridControlGeo, grvwMain, True) + LoadData() - Dim sql = Get_Grid_Sql(CURRENT_CONSTRUCTOR_ID, CURRENT_FORM_ID, CURRENT_CONSTRUCTOR_DETAIL_ID, frmConstructor_Main.GridType.Grid, USER_GUID, String.Empty, False, 1, 0, GridControlGeo, grvwMain, True) - If Not IsNothing(sql) Then - Dim DT_GEO As DataTable = ClassDatabase.Return_Datatable(sql) - GridControlGeo.DataSource = DT_GEO - End If - - Dim listcheck As List(Of String) = ClassHelper.Return_listcheck(CURRENT_FORM_ID) - Dim listdate As List(Of String) = ClassHelper.Return_listdate(CURRENT_FORM_ID) - - Dim CheckBoxEditorForDisplay = New RepositoryItemCheckEdit() - CheckBoxEditorForDisplay.ValueChecked = 1 - CheckBoxEditorForDisplay.ValueUnchecked = 0 - GridControlGeo.RepositoryItems.Add(CheckBoxEditorForDisplay) - - ' Alle Checkbox Spalten durchgehen und CheckBoxEditor zuweisen - For Each col As String In listcheck - If Not IsNothing(grvwMain.Columns(col)) Then - grvwMain.Columns(col).ColumnEdit = CheckBoxEditorForDisplay - End If - Next - - For Each col As String In listdate - Dim date_edit As New DevExpress.XtraEditors.Repository.RepositoryItemTimeEdit - Dim date_column As GridColumn = grvwMain.Columns(col) - date_column.DisplayFormat.FormatType = FormatType.DateTime - date_column.DisplayFormat.FormatString = CURRENT_DATE_FORMAT - date_column.OptionsFilter.FilterPopupMode = FilterPopupMode.Date - date_column.ColumnEdit = date_edit - date_column.FilterMode = ColumnFilterMode.Value ' was DisplayText - - date_edit.DisplayFormat.FormatType = FormatType.DateTime - date_edit.DisplayFormat.FormatString = CURRENT_DATE_FORMAT - date_edit.Mask.MaskType = Mask.MaskType.DateTime - date_edit.Mask.EditMask = CURRENT_DATE_FORMAT - date_edit.Mask.UseMaskAsDisplayFormat = True - - Next - - ' Styles for GridControl - grvwMain.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.None - grvwMain.OptionsBehavior.Editable = False - grvwMain.OptionsSelection.EnableAppearanceFocusedCell = False - grvwMain.OptionsSelection.EnableAppearanceFocusedRow = False - grvwMain.OptionsSelection.EnableAppearanceHideSelection = False - - grvwMain.Columns("AddedWhen").DisplayFormat.FormatType = FormatType.DateTime - grvwMain.Columns("AddedWhen").DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss" - grvwMain.Columns("ChangedWhen").DisplayFormat.FormatType = FormatType.DateTime - grvwMain.Columns("ChangedWhen").DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss" - - grvwMain.Columns("Record-ID").Visible = False - grvwMain.Columns("Form-ID").Visible = False - grvwMain.Columns("ROW_COLOR").Visible = False Catch ex As Exception MsgBox("Error while loading GeoData: " & vbNewLine & ex.Message) End Try End Sub + Private Sub frmGeodataNavigation_FormClosing(sender As Object, e As FormClosingEventArgs) Handles Me.FormClosing + Try + Dim gridView As Views.Grid.GridView = Me.ConstructorMain_Grid.FocusedView + gridView.ActiveFilterString = Nothing + Catch ex As Exception + MsgBox("Error in frmGeodataNavigation_FormClosing: " & vbNewLine & ex.Message) + End Try + End Sub + + Private Sub LoadData() + EntityDataTable = ClassDatabase.Return_Datatable(EntitySql) + LoadItemList() + LoadGridData() + End Sub + + + Private Sub LoadGridData() + If Not IsNothing(EntityDataTable) Then + GridControlGeo.DataSource = EntityDataTable + End If + + Dim listcheck As List(Of String) = ClassHelper.Return_listcheck(CURRENT_FORM_ID) + Dim listdate As List(Of String) = ClassHelper.Return_listdate(CURRENT_FORM_ID) + + Dim CheckBoxEditorForDisplay = New RepositoryItemCheckEdit() + CheckBoxEditorForDisplay.ValueChecked = 1 + CheckBoxEditorForDisplay.ValueUnchecked = 0 + GridControlGeo.RepositoryItems.Add(CheckBoxEditorForDisplay) + + ' Alle Checkbox Spalten durchgehen und CheckBoxEditor zuweisen + For Each col As String In listcheck + If Not IsNothing(grvwMain.Columns(col)) Then + grvwMain.Columns(col).ColumnEdit = CheckBoxEditorForDisplay + End If + Next + + For Each col As String In listdate + Dim date_edit As New DevExpress.XtraEditors.Repository.RepositoryItemTimeEdit + Dim date_column As GridColumn = grvwMain.Columns(col) + date_column.DisplayFormat.FormatType = FormatType.DateTime + date_column.DisplayFormat.FormatString = CURRENT_DATE_FORMAT + date_column.OptionsFilter.FilterPopupMode = FilterPopupMode.Date + date_column.ColumnEdit = date_edit + date_column.FilterMode = ColumnFilterMode.Value ' was DisplayText + + date_edit.DisplayFormat.FormatType = FormatType.DateTime + date_edit.DisplayFormat.FormatString = CURRENT_DATE_FORMAT + date_edit.Mask.MaskType = Mask.MaskType.DateTime + date_edit.Mask.EditMask = CURRENT_DATE_FORMAT + date_edit.Mask.UseMaskAsDisplayFormat = True + + Next + + ' Styles for GridControl + grvwMain.FocusRectStyle = DevExpress.XtraGrid.Views.Grid.DrawFocusRectStyle.None + grvwMain.OptionsBehavior.Editable = False + grvwMain.OptionsSelection.EnableAppearanceFocusedCell = False + grvwMain.OptionsSelection.EnableAppearanceFocusedRow = False + grvwMain.OptionsSelection.EnableAppearanceHideSelection = False + + grvwMain.Columns("AddedWhen").DisplayFormat.FormatType = FormatType.DateTime + grvwMain.Columns("AddedWhen").DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss" + grvwMain.Columns("ChangedWhen").DisplayFormat.FormatType = FormatType.DateTime + grvwMain.Columns("ChangedWhen").DisplayFormat.FormatString = CURRENT_DATE_FORMAT & " HH:MM:ss" + + grvwMain.Columns("Record-ID").Visible = False + grvwMain.Columns("Form-ID").Visible = False + grvwMain.Columns("ROW_COLOR").Visible = False + End Sub + + + Private Sub SetGridFilter(records As List(Of Integer)) Try Dim filter As New List(Of String) @@ -167,7 +176,7 @@ Public Class frmGeodataNavigation filter.Add(String.Format("[Record-Id] = {0}", id)) Next - Dim gridView As Views.Grid.GridView = Me.Grid.FocusedView + Dim gridView As Views.Grid.GridView = Me.ConstructorMain_Grid.FocusedView gridView.ActiveFilterString = String.Join(" OR ", filter.ToArray()) Catch ex As Exception MsgBox("Error in SetGridFilter: " & vbNewLine & ex.Message) @@ -204,6 +213,10 @@ Public Class frmGeodataNavigation End Sub Private Sub grvwMain_RowStyle(sender As Object, e As Views.Grid.RowStyleEventArgs) Handles grvwMain.RowStyle + If e.RowHandle = DevExpress.XtraGrid.GridControl.AutoFilterRowHandle Then + e.Appearance.BackColor = Color.Orange 'LemonChiffon + End If + If e.RowHandle > 0 Then Dim row As DataRowView = grvwMain.GetRow(e.RowHandle) Dim LATITUDE = row.Item("LATITUDE") @@ -251,10 +264,17 @@ Public Class frmGeodataNavigation txtLat.Text = SelectedPoint.Latitude txtLon.Text = SelectedPoint.Longitude + + SaveCurrentPoint() End If End Sub Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click + SaveCurrentPoint() + End Sub + + + Private Sub SaveCurrentPoint() Dim point As GeoPoint = GetCurrentPoint() If point Is Nothing Then @@ -266,20 +286,40 @@ Public Class frmGeodataNavigation Dim currentRow As DataRowView = grvwMain.GetFocusedRow() Dim RecordId As Integer = currentRow.Item("Record-ID") - Dim SQL As String = "UPDATE TBPMO_RECORD_GEODATA SET LATITUDE = @lat, LONGITUDE = @lon, CHANGED_WHO = @who WHERE RECORD_ID = @recordid" - Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection(MyConnectionString) - Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(SQL, conn) + Dim geoDataExists As Boolean = ClassDatabase.Execute_Scalar("SELECT RECORD_ID FROM TBPMO_RECORD_GEODATA WHERE RECORD_ID = " & RecordId) - cmd.Parameters.Add("@lat", SqlDbType.Decimal).Value = point.Latitude - cmd.Parameters.Add("@lon", SqlDbType.Decimal).Value = point.Longitude - cmd.Parameters.Add("@who", SqlDbType.VarChar).Value = Environment.UserName - cmd.Parameters.Add("@recordid", SqlDbType.Int).Value = RecordId + If geoDataExists Then + Dim SQL As String = "UPDATE TBPMO_RECORD_GEODATA SET LATITUDE = @lat, LONGITUDE = @lon, CHANGED_WHO = @who WHERE RECORD_ID = @recordid" + Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection(MyConnectionString) + Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(SQL, conn) - conn.Open() - cmd.ExecuteNonQuery() - conn.Close() + cmd.Parameters.Add("@lat", SqlDbType.Decimal).Value = point.Latitude + cmd.Parameters.Add("@lon", SqlDbType.Decimal).Value = point.Longitude + cmd.Parameters.Add("@who", SqlDbType.VarChar).Value = Environment.UserName + cmd.Parameters.Add("@recordid", SqlDbType.Int).Value = RecordId + conn.Open() + cmd.ExecuteNonQuery() + conn.Close() + Else + Dim SQL As String = "INSERT INTO TBPMO_RECORD_GEODATA (LATITUDE,LONGITUDE,ADDED_WHO,RECORD_ID) VALUES (@lat,@lon,'@who',@recordid)" + Dim conn As SqlClient.SqlConnection = New SqlClient.SqlConnection(MyConnectionString) + Dim cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(SQL, conn) + cmd.Parameters.Add("@lat", SqlDbType.Decimal).Value = point.Latitude + cmd.Parameters.Add("@lon", SqlDbType.Decimal).Value = point.Longitude + cmd.Parameters.Add("@who", SqlDbType.VarChar).Value = Environment.UserName + cmd.Parameters.Add("@recordid", SqlDbType.Int).Value = RecordId + + conn.Open() + cmd.ExecuteNonQuery() + conn.Close() + End If + + ' Markierte Zeile speichern, um diese beim neu laden wieder zu setzen + Dim rowhandle As Integer = grvwMain.FocusedRowHandle + LoadData() + grvwMain.FocusedRowHandle = rowhandle Catch ex As Exception MsgBox("Error while saving Coordinates: " & vbNewLine & ex.Message)