Skip to content

Commit

Permalink
Merge pull request IDEMSInternational#6172 from lilyclements/AddLinkFix
Browse files Browse the repository at this point in the history
Fixed bug in dlgAddLink triggered when dialog opened without a data frame loaded into R-Instat
  • Loading branch information
lloyddewit authored Mar 17, 2021
2 parents 0d664c0 + 18eb0cd commit fd5c9cb
Showing 1 changed file with 37 additions and 36 deletions.
73 changes: 37 additions & 36 deletions instat/dlgAddLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -101,34 +101,36 @@ Public Class dlgAddLink
Dim strColumnNames As String()
Dim clsGetKeys As New RFunction

lvwLinkViewBox.Items.Clear()

lblKeys.Text = ucrDataSelectorTo.cboAvailableDataFrames.SelectedItem & " Keys:"
clsGetKeys.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_keys")
clsGetKeys.AddParameter("data_name", Chr(34) & ucrDataSelectorTo.cboAvailableDataFrames.SelectedItem & Chr(34))
lstKeys = frmMain.clsRLink.RunInternalScriptGetValue(clsGetKeys.ToScript).AsList

clsColumnNames.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_column_names")
clsColumnNames.AddParameter("data_name", Chr(34) & ucrDataSelectorFrom.cboAvailableDataFrames.SelectedItem & Chr(34))
strColumnNames = frmMain.clsRLink.RunInternalScriptGetValue(clsColumnNames.ToScript).AsCharacter().ToArray

For i = 0 To lstKeys.Count - 1
chrKeyColumns = lstKeys(i).AsCharacter
strKeyColumns = String.Join(", ", chrKeyColumns.ToArray)
If chrKeyColumns IsNot Nothing Then
lviTemp = New ListViewItem({lstKeys.Names(i), strKeyColumns})
clsColumnNames.AddParameter("to_columns", "c(" & strKeyColumns & ")")
bCanAutoLink = chrKeyColumns.ToArray.All(Function(strCol) strColumnNames.Contains(strCol))
If bCanAutoLink Then
lviTemp.BackColor = Color.LightGreen
ucrBase.OKEnabled(True)
Else
lviTemp.BackColor = Color.LightCoral
ucrBase.OKEnabled(False)
If ucrDataSelectorTo.cboAvailableDataFrames.Text <> "" Then
lvwLinkViewBox.Items.Clear()

lblKeys.Text = ucrDataSelectorTo.cboAvailableDataFrames.SelectedItem & " Keys:"
clsGetKeys.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_keys")
clsGetKeys.AddParameter("data_name", Chr(34) & ucrDataSelectorTo.cboAvailableDataFrames.SelectedItem & Chr(34))
lstKeys = frmMain.clsRLink.RunInternalScriptGetValue(clsGetKeys.ToScript).AsList

clsColumnNames.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$get_column_names")
clsColumnNames.AddParameter("data_name", Chr(34) & ucrDataSelectorFrom.cboAvailableDataFrames.SelectedItem & Chr(34))
strColumnNames = frmMain.clsRLink.RunInternalScriptGetValue(clsColumnNames.ToScript).AsCharacter().ToArray

For i = 0 To lstKeys.Count - 1
chrKeyColumns = lstKeys(i).AsCharacter
strKeyColumns = String.Join(", ", chrKeyColumns.ToArray)
If chrKeyColumns IsNot Nothing Then
lviTemp = New ListViewItem({lstKeys.Names(i), strKeyColumns})
clsColumnNames.AddParameter("to_columns", "c(" & strKeyColumns & ")")
bCanAutoLink = chrKeyColumns.ToArray.All(Function(strCol) strColumnNames.Contains(strCol))
If bCanAutoLink Then
lviTemp.BackColor = Color.LightGreen
ucrBase.OKEnabled(True)
Else
lviTemp.BackColor = Color.LightCoral
ucrBase.OKEnabled(False)
End If
lvwLinkViewBox.Items.Add(lviTemp)
End If
lvwLinkViewBox.Items.Add(lviTemp)
End If
Next
Next
End If
End Sub

Private Sub lvwLinkViewBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lvwLinkViewBox.SelectedIndexChanged
Expand All @@ -151,20 +153,19 @@ Public Class dlgAddLink
TestOKEnabled()
End Sub

Private Sub ucrDataSelectorTo_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrDataSelectorTo.ControlValueChanged
UpdateKeys()
TestOKEnabled()
End Sub

Private Sub ucrDataSelectorFrom_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrDataSelectorFrom.ControlContentsChanged, ucrInputLinkName.ControlContentsChanged, ucrInputSelectedKey.ControlContentsChanged
TestOKEnabled()
End Sub

Private Function IsSelectionValidKey() As Boolean
If lvwLinkViewBox.SelectedItems.Count = 1 Then
Return lvwLinkViewBox.SelectedItems(0).BackColor = Color.LightGreen
Else
Return False
End If
End Function

Private Sub ucrDataSelectorTo_ControlValueChanged(ucrChangedControl As ucrCore) Handles ucrDataSelectorTo.ControlValueChanged
UpdateKeys()
End Sub

Private Sub CoreControls_ControlContentsChanged(ucrChangedControl As ucrCore) Handles ucrDataSelectorFrom.ControlContentsChanged, ucrDataSelectorTo.ControlContentsChanged, ucrInputLinkName.ControlContentsChanged, ucrInputSelectedKey.ControlContentsChanged
TestOKEnabled()
End Sub
End Class

0 comments on commit fd5c9cb

Please sign in to comment.