Skip to content

Commit

Permalink
Merge pull request #5 from Patowhiz/ClimaticDataEntryAntoine
Browse files Browse the repository at this point in the history
Climatic data entry changes
  • Loading branch information
N-thony authored Mar 19, 2021
2 parents 45e407a + f5ae33a commit 3ed132f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 88 deletions.
91 changes: 20 additions & 71 deletions instat/dlgClimaticDataEntry.vb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Public Class dlgClimaticDataEntry
Public bFirstLoad As Boolean = True
Private bReset As Boolean = True
Private iBasicWidth As Integer
Public dfTemp As DataFrame
'Public dfTemp As DataFrame
Private Sub dlgClimaticDataEntry_Load(sender As Object, e As EventArgs) Handles MyBase.Load
If bFirstLoad Then
InitialiseDialog()
Expand Down Expand Up @@ -52,7 +52,7 @@ Public Class dlgClimaticDataEntry
ucrInputFactorLevels.SetParameter(New RParameter("", 2))
ucrInputFactorLevels.SetFactorReceiver(ucrReceiverStation)
'ucrInputFactorLevels.AddQuotesIfUnrecognised = False
'ucrInputFactorLevels.strQuotes = "`"
ucrInputFactorLevels.strQuotes = ""

ucrReceiverDate.SetParameter(New RParameter("date_col", 3))
ucrReceiverDate.Selector = ucrSelectorClimaticDataEntry
Expand All @@ -75,17 +75,7 @@ Public Class dlgClimaticDataEntry

End Sub

Public Sub GetDataFrame()
Dim clsGetDataFrame As New RFunction
Dim expTemp As SymbolicExpression

If frmMain.clsRLink.bInstatObjectExists AndAlso frmMain.clsRLink.GetDataFrameCount() > 0 Then
clsGetDataFrame.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_data_frame")
clsGetDataFrame.AddParameter("data_name", Chr(34) & ucrSelectorClimaticDataEntry.strCurrentDataFrame & Chr(34))
expTemp = frmMain.clsRLink.RunInternalScriptGetValue(clsGetDataFrame.ToScript(), bSilent:=True)
dfTemp = expTemp.AsDataFrame()
End If
End Sub
Private Sub SetDefaults()

End Sub
Expand All @@ -106,72 +96,31 @@ Public Class dlgClimaticDataEntry
End Sub

Private Sub cmdEnterData_Click(sender As Object, e As EventArgs) Handles cmdEnterData.Click
sdgClimaticDataEntry.Setup(ucrReceiverStation.GetVariableNames(bWithQuotes:=False),
ucrReceiverDate.GetVariableNames(bWithQuotes:=False),
ucrReceiverElements.GetVariableNamesList(bWithQuotes:=False).ToList,
ucrInputFactorLevels.GetValue(),
ucrDateTimePickerFrom.DateValue,
GetDataFrame())
sdgClimaticDataEntry.ShowDialog()
End Sub

Private Sub ucrSelectorClimaticDataEntry_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrSelectorClimaticDataEntry.ControlValueChanged
GetDataFrame()
End Sub

'Public Function GetFilledDataTable(dataFrame As DataFrame) As DataTable
' Dim dataTable As New DataTable
' Dim dataRow As DataRow
' Dim bAddRow As Boolean
' Dim strStationColumnName As String = ucrInputFactorLevels.GetValue()
' Dim strDateColumnName As String = ucrInputFactorLevels.GetValue()
' Dim lstElementsColumnNames As List(Of String) = ucrReceiverElements.GetVariableNamesAsList
' Dim dateFrom As Date = ucrDateTimePickerFrom.DateValue

' 'create the columns to the data table; station, date and elements
' dataTable.Columns.Add(strStationColumnName)
' dataTable.Columns.Add(strDateColumnName)
' For Each strElement As String In lstElementsColumnNames
' dataTable.Columns.Add(strElement)
' Next

' For i As Integer = 0 To dataFrame.RowCount - 1
' bAddRow = True
' 'create a new data table row
' dataRow = dataTable.NewRow()

' 'fill the row with required values
' 'the data frame column names should be the same as the data table column names in content
' For Each strDataFrameColumnName As String In dataFrame.ColumnNames
' If strDataFrameColumnName = strDateColumnName Then
' 'todo. validate the date and compare, if > starting date then bAddRow = False
' End If
' dataRow.Item(strDataFrameColumnName) = dataFrame.Item(i, strDataFrameColumnName)
' Next

' If bAddRow Then
' 'add the row to the datatable
' dataTable.Rows.Add(dataRow)
' End If

' Next

' Return dataTable
'End Function

'Public Function GetFilledWorkSheet(dataTable As DataTable) As Worksheet
' Dim grdWorkSheet As Worksheet = New ReoGridControl().CreateWorksheet("dateentry")

' 'create the columns and set the header names in the worksheet
' grdWorkSheet.Columns = dataTable.Columns.Count
' For k = 0 To dataTable.Columns.Count - 1
' grdWorkSheet.ColumnHeaders.Item(k).Text = dataTable.Columns.Item(k).ColumnName
' Next

' 'create rows and values for the worksheet
' grdWorkSheet.SetRangeData(New RangePosition(0, 0, dataTable.Rows.Count, dataTable.Columns.Count), dataTable)

' 'todo. these 3 settings not important now. Left here to be done later
' 'grdWorkSheet.SetSettings(WorksheetSettings.Edit_AllowAdjustRowHeight, True)
' 'grdWorkSheet.SetRowsHeight(0, 1, 20)
' 'grdWorkSheet.SetRangeDataFormat(New RangePosition(0, 0, grdWorkSheet.Rows, grdWorkSheet.Columns), DataFormat.CellDataFormatFlag.Text)

' Return grdWorkSheet
'End Function
Private Function GetDataFrame() As DataFrame
Dim dfTemp As DataFrame = Nothing
Dim clsGetDataFrame As New RFunction
Dim expTemp As SymbolicExpression

If frmMain.clsRLink.bInstatObjectExists AndAlso frmMain.clsRLink.GetDataFrameCount() > 0 Then
clsGetDataFrame.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_data_frame")
clsGetDataFrame.AddParameter("data_name", Chr(34) & ucrSelectorClimaticDataEntry.strCurrentDataFrame & Chr(34))
expTemp = frmMain.clsRLink.RunInternalScriptGetValue(clsGetDataFrame.ToScript(), bSilent:=True)
dfTemp = expTemp.AsDataFrame()
End If
Return dfTemp
End Function

End Class
64 changes: 47 additions & 17 deletions instat/sdgClimaticDataEntry.vb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,38 @@ Imports instat.Translations
Imports RDotNet
Imports unvell.ReoGrid
Public Class sdgClimaticDataEntry

Dim strStationColumnName As String
Dim strDateColumnName As String
Dim lstElementsColumnNames As List(Of String)
Dim strStationSelected As String
Dim startDateSelected As Date
Dim dataTable As DataTable

Private Sub sdgClimaticDataEntry_Load(sender As Object, e As EventArgs) Handles MyBase.Load
grdDataEntry.CurrentWorksheet = GetFilledWorkSheet(GetFilledDataTable(dlgClimaticDataEntry.dfTemp))

End Sub
Public Function GetFilledDataTable(dataFrame As DataFrame) As DataTable

Public Sub Setup(strStationColumnName As String, strDateColumnName As String, lstElementsColumnNames As List(Of String), strStationSelected As String, startDateSelected As Date, dataFrameSelected As DataFrame)
Me.strStationColumnName = strStationColumnName
Me.strDateColumnName = strDateColumnName
Me.lstElementsColumnNames = lstElementsColumnNames
Me.strStationSelected = strStationSelected
Me.startDateSelected = startDateSelected
grdDataEntry.Worksheets.Clear()
Me.dataTable = GetFilledDataTable(strStationColumnName, strDateColumnName, lstElementsColumnNames, strStationSelected, startDateSelected, dataFrameSelected)

Dim currentWorkSheet As Worksheet = GetFilledWorkSheet(dataTable)
grdDataEntry.AddWorksheet(currentWorkSheet)

grdDataEntry.CurrentWorksheet = currentWorkSheet
End Sub

Private Function GetFilledDataTable(strStationColumnName As String, strDateColumnName As String, lstElementsColumnNames As List(Of String), strStationSelected As String, startDateSelected As Date, dataFrameSelected As DataFrame) As DataTable
Dim dataTable As New DataTable
Dim dataRow As DataRow
Dim dataTableRow As DataRow
Dim dataFrameCellValue As Object
Dim bAddRow As Boolean
Dim strStationColumnName As String = dlgClimaticDataEntry.ucrReceiverStation.GetVariableNames
' Dim strDateColumnName As String = dlgClimaticDataEntry.ucrInputFactorLevels.GetValue()
Dim strDateColumnName As String = dlgClimaticDataEntry.ucrReceiverDate.GetVariableNames
Dim lstElementsColumnNames As List(Of String) = dlgClimaticDataEntry.ucrReceiverElements.GetVariableNamesAsList
Dim dateFrom As Date = dlgClimaticDataEntry.ucrDateTimePickerFrom.DateValue

'create the columns to the data table; station, date and elements
dataTable.Columns.Add(strStationColumnName)
Expand All @@ -38,31 +58,39 @@ Public Class sdgClimaticDataEntry
dataTable.Columns.Add(strElement)
Next

For i As Integer = 0 To dataFrame.RowCount - 1
For i As Integer = 0 To dataFrameSelected.RowCount - 1
bAddRow = True
'create a new data table row
dataRow = dataTable.NewRow()
dataTableRow = dataTable.NewRow()

'fill the row with required values
'the data frame column names should be the same as the data table column names in content
For Each strDataFrameColumnName As String In dataFrame.ColumnNames
If strDataFrameColumnName = strDateColumnName Then
'todo. validate the date and compare, if > starting date then bAddRow = False
End If
dataRow.Item(strDataFrameColumnName) = dataFrame.Item(i, strDataFrameColumnName)
For Each dataTableColumn As DataColumn In dataTable.Columns
dataFrameCellValue = dataFrameSelected.Item(i, dataTableColumn.ColumnName)
'Only add rows of the station selected and from the starting date
'If strColumnName = strStationColumnName AndAlso dataFrameCellValue.ToString <> strStationSelected Then
' 'bAddRow = False
' 'Exit For
'ElseIf strColumnName = strDateColumnName Then
' 'todo. validate the date and compare, if > starting date then bAddRow = False
' 'bAddRow = False
' 'Exit For
'End If

dataTableRow.Item(dataTableColumn.ColumnName) = dataFrameCellValue
Next

If bAddRow Then
'add the row to the datatable
dataTable.Rows.Add(dataRow)
dataTable.Rows.Add(dataTableRow)
End If

Next
Return dataTable
End Function

Public Function GetFilledWorkSheet(dataTable As DataTable) As Worksheet
Dim grdWorkSheet As Worksheet = New ReoGridControl().CreateWorksheet("dataentry")
Dim grdWorkSheet As Worksheet = grdDataEntry.CreateWorksheet("dataentry")

'create the columns and set the header names in the worksheet
grdWorkSheet.Columns = dataTable.Columns.Count
Expand All @@ -71,13 +99,15 @@ Public Class sdgClimaticDataEntry
Next

'create rows and values for the worksheet
grdWorkSheet.Rows = dataTable.Rows.Count
grdWorkSheet.SetRangeData(New RangePosition(0, 0, dataTable.Rows.Count, dataTable.Columns.Count), dataTable)

'todo. these 3 settings not important now. Left here to be done later
'grdWorkSheet.SetSettings(WorksheetSettings.Edit_AllowAdjustRowHeight, True)
'grdWorkSheet.SetRowsHeight(0, 1, 20)
'grdWorkSheet.SetRangeDataFormat(New RangePosition(0, 0, grdWorkSheet.Rows, grdWorkSheet.Columns), DataFormat.CellDataFormatFlag.Text)

'todo. make the station column be uneditable
Return grdWorkSheet
End Function
End Class

0 comments on commit 3ed132f

Please sign in to comment.