diff --git a/instat/dlgInfill.vb b/instat/dlgInfill.vb index c2fa50583e..02d4a44ac1 100644 --- a/instat/dlgInfill.vb +++ b/instat/dlgInfill.vb @@ -15,6 +15,7 @@ ' along with this program. If not, see . Imports instat.Translations +Imports System.Text.RegularExpressions Public Class dlgInfill Public enumFilldateMode As String = FilldateMode.Prepare Public Enum FilldateMode @@ -22,9 +23,13 @@ Public Class dlgInfill Climatic End Enum + Private isFilling As Boolean = False Private bFirstLoad As Boolean = True Private bReset As Boolean = True Private clsDefaultFunction As New RFunction + Private lstStationReceivers As New List(Of ucrReceiverMultiple) + Dim lstRecognisedTypes As New List(Of KeyValuePair(Of String, List(Of String))) + Private Sub dlgInfill_Load(sender As Object, e As EventArgs) Handles MyBase.Load If bFirstLoad Then InitialiseDialog() @@ -43,6 +48,12 @@ Public Class dlgInfill ucrBase.iHelpTopicID = 497 ucrBase.clsRsyntax.iCallType = 2 + + Dim kvpStation As KeyValuePair(Of String, List(Of String)) = New KeyValuePair(Of String, List(Of String))("station", {"station", "station.", "id", "name"}.ToList()) + + lstStationReceivers.AddRange({ucrReceiverFactors}) + + lstRecognisedTypes.AddRange({kvpStation}) 'Set receiver ucrReceiverDate.Selector = ucrInfillSelector ucrReceiverDate.SetDataType("Date") @@ -55,6 +66,7 @@ Public Class dlgInfill ucrReceiverFactors.SetIncludedDataTypes({"factor"}) ucrReceiverFactors.Selector = ucrInfillSelector ucrReceiverFactors.strSelectorHeading = "Factors" + ucrReceiverFactors.Tag = "station" ucrReceiverFactors.SetParameter(New RParameter("factors", 5)) ucrReceiverFactors.SetParameterIsString() @@ -118,6 +130,7 @@ Public Class dlgInfill If bReset Then SetRCode(Me, ucrBase.clsRsyntax.clsBaseFunction, bReset) End If + AutoFillStation() End Sub Private Sub TestOkEnabled() @@ -151,17 +164,68 @@ Public Class dlgInfill End Sub Private Sub AutoFillStation() - If ucrInfillSelector.CurrentReceiver IsNot Nothing Then - ucrInfillSelector.CurrentReceiver.SetMeAsReceiver() + If isFilling Then + Exit Sub End If - ucrReceiverFactors.AddItemsWithMetadataProperty(ucrInfillSelector.ucrAvailableDataFrames.cboAvailableDataFrames.Text, "Climatic_Type", {"station_label"}) + isFilling = True + + ' Temporarily remove the event handler + RemoveHandler ucrInfillSelector.ControlValueChanged, AddressOf AutoFillStation + + Dim lstRecognisedValues As List(Of String) + Dim ucrCurrentReceiver As ucrReceiver + Dim bFound As Boolean = False + + ucrCurrentReceiver = ucrInfillSelector.CurrentReceiver + + For Each ucrTempReceiver As ucrReceiver In lstStationReceivers + ucrTempReceiver.SetMeAsReceiver() + lstRecognisedValues = GetRecognisedValues(ucrTempReceiver.Tag) + + If lstRecognisedValues.Count > 0 Then + For Each lviTempVariable As ListViewItem In ucrInfillSelector.lstAvailableVariable.Items + For Each strValue As String In lstRecognisedValues + If Regex.Replace(lviTempVariable.Text.ToLower(), "[^\w]", String.Empty).Equals(strValue) Then + ucrTempReceiver.Add(lviTempVariable.Text, ucrInfillSelector.ucrAvailableDataFrames.cboAvailableDataFrames.Text) + bFound = True + Exit For + End If + Next + If bFound Then + bFound = False + Exit For + End If + Next + End If + Next + + If ucrCurrentReceiver IsNot Nothing Then + ucrCurrentReceiver.SetMeAsReceiver() + End If + + ' Re-enable the event handler + AddHandler ucrInfillSelector.ControlValueChanged, AddressOf AutoFillStation + + isFilling = False End Sub + Private Function GetRecognisedValues(strVariable As String) As List(Of String) + Dim lstValues As New List(Of String) + + For Each kvpTemp As KeyValuePair(Of String, List(Of String)) In lstRecognisedTypes + If kvpTemp.Key = strVariable Then + lstValues = kvpTemp.Value + Exit For + End If + Next + Return lstValues + End Function + Private Sub Controls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrReceiverDate.ControlContentsChanged TestOkEnabled() End Sub - Private Sub ucrInfillSelector_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInfillSelector.ControlValueChanged + Private Sub ucrInfillSelector_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrInfillSelector.ControlValueChanged, ucrReceiverFactors.ControlValueChanged AutoFillStation() End Sub End Class