Skip to content

Commit

Permalink
Merge pull request #91 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
updating branch
  • Loading branch information
maxwellfundi authored May 11, 2017
2 parents 02cf8da + 340b640 commit 4451f9b
Show file tree
Hide file tree
Showing 25 changed files with 1,945 additions and 772 deletions.
4 changes: 2 additions & 2 deletions instat/dlgAddKey.vb
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ Public Class dlgAddKey

Private Sub SetDefaults()
ucrSelectorKeyColumns.Reset()
ucrInputKeyName.SetName("")
ucrInputKeyName.Reset()
ucrInputCheckInput.Reset()
bUniqueChecked = False

bUniqueChecked = False
clsDefaultRFunction = New RFunction
clsDefaultRFunction.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_key")
ucrBase.clsRsyntax.SetBaseRFunction(clsDefaultRFunction)
Expand Down
132 changes: 80 additions & 52 deletions instat/dlgAddLink.Designer.vb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

101 changes: 94 additions & 7 deletions instat/dlgAddLink.vb
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
' along with this program. If not, see <http://www.gnu.org/licenses/>.

Imports instat.Translations
Imports RDotNet
Public Class dlgAddLink
Public bFirstLoad As Boolean = True
Private bFirstLoad As Boolean = True
Private bReset As Boolean = True
Private clsAddLink As RFunction

Private Sub dlgAddLink_Load(sender As Object, e As EventArgs) Handles MyBase.Load
autoTranslate(Me)
Expand All @@ -35,28 +37,113 @@ Public Class dlgAddLink

Private Sub InitialiseDialog()
ucrBase.iHelpTopicID = 506
cmdSpecifyLink.Enabled = False ' temporarily disabled

ucrDataSelectorFrom.SetParameter(New RParameter("from_data_frame", 0))
ucrDataSelectorFrom.SetParameterIsString()

ucrDataSelectorTo.SetParameter(New RParameter("to_data_frame", 0))
ucrDataSelectorTo.SetParameterIsString()

ucrInputLinkName.SetParameter(New RParameter("link_name", 0))
lvwLinkViewBox.Columns.Add("Name", 80, HorizontalAlignment.Left)
lvwLinkViewBox.Columns.Add("Columns", 150, HorizontalAlignment.Left)
ucrInputSelectedKey.IsReadOnly = True
End Sub

Private Sub SetDefaults()
Dim clsDefaultFunction As New RFunction
clsAddLink = New RFunction

'clsDefaultFunction.SetRCommand()
'ucrBase.clsRsyntax.SetBaseRFunction(clsDefaultFunction)
ucrDataSelectorFrom.Reset()
ucrDataSelectorTo.Reset()
UpdateKeys()

clsAddLink.AddParameter("type", Chr(34) & "keyed_link" & Chr(34))
clsAddLink.SetRCommand(frmMain.clsRLink.strInstatDataObject & "$add_link")
ucrBase.clsRsyntax.SetBaseRFunction(clsAddLink)
End Sub

Private Sub SetRCodeForControls(bReset As Boolean)
SetRCode(Me, ucrBase.clsRsyntax.clsBaseFunction, bReset)
End Sub

Private Sub TestOKEnabled()
End Sub

Private Sub ReopenDialog()
If ucrDataSelectorFrom.cboAvailableDataFrames.Text <> "" AndAlso ucrDataSelectorTo.cboAvailableDataFrames.Text <> "" AndAlso Not ucrInputLinkName.IsEmpty AndAlso Not ucrInputSelectedKey.IsEmpty Then
ucrBase.OKEnabled(True)
Else
ucrBase.OKEnabled(False)
End If
End Sub

Private Sub ucrBaseReplace_ClickReset(sender As Object, e As EventArgs) Handles ucrBase.ClickReset
SetDefaults()
SetRCodeForControls(True)
TestOKEnabled()
End Sub

Public Sub UpdateKeys()
Dim clsColumnNames As New RFunction
Dim lstKeys As GenericVector
Dim chrKeyColumns As CharacterVector
Dim lviTemp As ListViewItem
Dim strKeyColumns As String
Dim bCanAutoLink As Boolean
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.ForeColor = Color.Green
Else
lviTemp.ForeColor = Color.Red
End If
lvwLinkViewBox.Items.Add(lviTemp)
End If
Next
End Sub

Private Sub lvwLinkViewBox_SelectedIndexChanged(sender As Object, e As EventArgs) Handles lvwLinkViewBox.SelectedIndexChanged
Dim strColNames As String()
Dim clsPairs As New RFunction

clsPairs.SetRCommand("c")

If lvwLinkViewBox.SelectedIndices.Count = 1 Then
strColNames = lvwLinkViewBox.SelectedItems(0).SubItems(1).Text.Split(",")
For Each strTemp As String In strColNames
clsPairs.AddParameter(strTemp.Trim(" "), Chr(34) & strTemp.Trim(" ") & Chr(34))
Next
clsAddLink.AddParameter("link_pairs", clsRFunctionParameter:=clsPairs, iPosition:=2)
ucrInputSelectedKey.SetName(lvwLinkViewBox.SelectedItems(0).SubItems(0).Text)
Else
clsAddLink.RemoveParameterByName("link_pairs")
ucrInputSelectedKey.SetName("")
End If
End Sub

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

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

0 comments on commit 4451f9b

Please sign in to comment.