Skip to content

Commit

Permalink
Merge pull request #43 from africanmathsinitiative/master
Browse files Browse the repository at this point in the history
updating master
  • Loading branch information
Vitalis95 authored Apr 4, 2022
2 parents 1245a94 + e4cf3ec commit 0c9dff7
Show file tree
Hide file tree
Showing 23 changed files with 968 additions and 1,771 deletions.
2 changes: 1 addition & 1 deletion instat/dlgDeleteRowsOrColums.Designer.vb

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

6 changes: 3 additions & 3 deletions instat/dlgExportDataset.Designer.vb

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

53 changes: 33 additions & 20 deletions instat/dlgExportDataset.vb
Original file line number Diff line number Diff line change
Expand Up @@ -92,16 +92,13 @@ Public Class dlgExportDataset
Private Sub ucrReceiverMultipleDataFrames_ControlContentsChanged(ucrchangedControl As ucrCore) Handles ucrReceiverMultipleDataFrames.ControlContentsChanged
chkSaveAsSingleFile.Visible = ucrReceiverMultipleDataFrames.GetVariableNamesList().Length > 1
ChangeFileControlsValues()
ucrFilePath.Clear() 'will raise event FilePathChanged
End Sub

Private Sub chkSaveAsSingleFile_CheckedChanged(sender As Object, e As EventArgs) Handles chkSaveAsSingleFile.CheckedChanged
ChangeFileControlsValues()
ucrFilePath.Clear() 'will raise event FilePathChanged
End Sub

Private Sub cboFileExtension_SelectedIndexChanged(sender As Object, e As EventArgs) Handles cboFileType.SelectedIndexChanged
ucrFilePath.Clear() 'will raise event FilePathChanged
ucrFilePath.FilePathDialogFilter = GetFilePathDialogFilterText(cboFileType.SelectedItem)
End Sub

Expand All @@ -113,7 +110,7 @@ Public Class dlgExportDataset
'if no or single data frame selected or save as single checked then just set the base function to the default
If ucrReceiverMultipleDataFrames.GetVariableNamesList().Length <= 1 OrElse chkSaveAsSingleFile.Checked Then
ucrBase.clsRsyntax.SetBaseRFunction(clsDefaultFunction)
lblConfirm.Text = GetTranslation("Click Ok to Confirm the Export.")
lblConfirm.Text = GetTranslation("File with the same name will be overwritten." & Environment.NewLine & "Click Ok to Confirm the Export.")
Else
'else, create a string command for exporting separate files to a directory.
'note, as of 09/09/2020 rio didn't support exporting separate files in 1 command see issue #5590
Expand All @@ -137,14 +134,9 @@ Public Class dlgExportDataset
Private Sub ChangeFileControlsValues()
Dim strPrevSelectedFileType As String = cboFileType.SelectedItem
Dim iSelectedDataFrames As Integer = ucrReceiverMultipleDataFrames.GetVariableNamesList().Length
ucrFilePath.FolderBrowse = False 'set file path control to open default SaveFileDialog prompt
ucrFilePath.DefaultFileSuggestionName = ""
ucrFilePath.FilePathDialogFilter = ""
cboFileType.Items.Clear()


ucrFilePath.FolderBrowse = iSelectedDataFrames > 1 AndAlso Not chkSaveAsSingleFile.Checked
Dim bSaveAsMultipleFiles As Boolean = iSelectedDataFrames > 1 AndAlso Not chkSaveAsSingleFile.Checked

cboFileType.Items.Clear()
If iSelectedDataFrames > 1 AndAlso chkSaveAsSingleFile.Checked Then
'file types currently supported insaving of multiple files into a single file
cboFileType.Items.Add("Excel files (*.xlsx)")
Expand Down Expand Up @@ -175,43 +167,64 @@ Public Class dlgExportDataset
cboFileType.Items.Add("SAS XPORT (*.xpt)")

'set the default suggested name
ucrFilePath.DefaultFileSuggestionName = ucrReceiverMultipleDataFrames.GetVariableNames(bWithQuotes:=False)
If Not ucrReceiverMultipleDataFrames.IsEmpty Then
ucrFilePath.DefaultFileSuggestionName = ucrReceiverMultipleDataFrames.GetVariableNamesList(bWithQuotes:=False)(0)
End If
End If

'previous selected file type may not be there in the current combobox items
cboFileType.SelectedItem = strPrevSelectedFileType
If String.IsNullOrEmpty(cboFileType.SelectedItem) Then
If Not String.IsNullOrEmpty(strPrevSelectedFileType) AndAlso cboFileType.Items.Contains(strPrevSelectedFileType) Then
cboFileType.SelectedItem = strPrevSelectedFileType
Else
cboFileType.SelectedIndex = 0
End If

'If we are saving to multiple files, then path should be set to a folder.
'If we are saving to a single file, then path should be set to a file.
'Therefore `bSaveAsMultipleFiles` and `ucrFilePath.FolderBrowse` should always be equal.
'If not, then we need to make the `ucrFilePath` control consistent with the state of `bSaveAsMultipleFiles`.
If bSaveAsMultipleFiles <> ucrFilePath.FolderBrowse Then
ucrFilePath.FolderBrowse = bSaveAsMultipleFiles
If Not ucrFilePath.IsEmpty Then
If ucrFilePath.FolderBrowse Then
ucrFilePath.FilePath = ucrFilePath.FilePathDirectory
Else
ucrFilePath.FilePath = ucrFilePath.FilePathDirectory & "\" &
ucrFilePath.SuggestionNameWithoutExtension &
GetSelectedExtension(cboFileType.SelectedItem)
End If
End If
End If

ucrFilePath.FilePathDialogFilter = GetFilePathDialogFilterText(cboFileType.SelectedItem)

End Sub

''' <summary>
''' expected string format "filetype (*.ext)"
''' expected string format: "filetype (*.ext)"
''' </summary>
''' <param name="strText"></param>
''' <returns></returns>
Private Function GetFilePathDialogFilterText(strText As String) As String
If String.IsNullOrEmpty(strText) Then
Return ""
End If
'example of required format; Excel files (*.xlsx)|*.xlsx
Dim arrStr() As String = strText.Split({"(", ")"}, StringSplitOptions.RemoveEmptyEntries)
Return arrStr(0) & "(" & arrStr(1) & ")|" & arrStr(1)

'example of filter string format returned: Excel files|*.xlsx
Dim arrStr() As String = strText.Split({"(", ")"}, StringSplitOptions.RemoveEmptyEntries)
Return arrStr(0) & "|" & arrStr(1)
End Function

''' <summary>
''' expected string format "filetype (*.ext)"
''' expected string format: "filetype (*.ext)"
''' </summary>
''' <param name="strText"></param>
''' <returns></returns>
Private Function GetSelectedExtension(strText As String) As String
If String.IsNullOrEmpty(strText) Then
Return ""
End If
'example of required format;.xlsx
'example of string format returned: .xlsx
Return strText.Split({"(", "*", ")"}, StringSplitOptions.RemoveEmptyEntries)(1)
End Function

Expand Down
Loading

0 comments on commit 0c9dff7

Please sign in to comment.