1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
Dim saveFileDialog As New Microsoft.Win32.SaveFileDialog saveFileDialog.DefaultExt = "txt" Dim reportFileName As String = "ClientGroupExport_" & System.DateTime.Now.ToString("yyyyMMdd") Dim currExt = IO.Path.GetExtension(reportFileName) saveFileDialog.FileName = reportFileName Try If saveFileDialog.ShowDialog() Then 'SavedFileName = saveFileDialog.FileName Using fileStream As System.IO.Stream = saveFileDialog.OpenFile() Using sw As New System.IO.StreamWriter(fileStream) 'Me.FilteredClientGroups.CopyTo(fileStream) Dim str As String = String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\newLN", "ClientType", "SimpleName", "SingleLineAddress", "Phone", "Fax", "Email", "Mobile", "Owner", "ClientSourceType").Replace("\t", vbTab).Replace("\newLN", vbNewLine) str = str & String.Join(Environment.NewLine, FilteredClientGroupMembers.Select(Of String)(Function(x) String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", x.ClientType, x.SimpleName, x.SingleLineAddress, x.Phone, x.Fax, x.Email, x.Mobile, x.Owner, x.ClientSourceType))).Replace("\t", vbTab) sw.WriteLine(str) sw.Flush() sw.Close() End Using End Using If IO.File.Exists(saveFileDialog.FileName) Then If Windows.MessageBox.Show("Do you wish to open the saved file now?", "Open File?", Windows.MessageBoxButton.YesNo, Windows.MessageBoxImage.Question, Windows.MessageBoxResult.No) = Windows.MessageBoxResult.Yes Then 'Open the file in the default viewer Try System.Diagnostics.Process.Start(saveFileDialog.FileName) Catch ex As Exception Windows.MessageBox.Show(String.Format("An error occurred trying to open the file '{0}'", saveFileDialog.FileName), "File Error", Windows.MessageBoxButton.OK, Windows.MessageBoxImage.Error) RollbarClientSync.SendExceptionAsync(ex, Controller.CurrentIdentity) End Try End If End If End If Catch ioEx As System.IO.IOException Windows.MessageBox.Show(String.Format("There was a problem saving the file to '{0}'. The error was: {1}{2}Check to see if the file is already in use, and that you have permissions to write to the requested file path.", saveFileDialog.FileName, ioEx.GetBaseException.Message, Environment.NewLine), "Failed To Save Report", Windows.MessageBoxButton.OK, Windows.MessageBoxImage.Error) Catch fileEx As Exception Windows.MessageBox.Show(String.Format("There was a problem saving the file to '{0}'. The error was: {1}", saveFileDialog.FileName, fileEx.GetBaseException.Message), "Failed To Save Client Group report", Windows.MessageBoxButton.OK, Windows.MessageBoxImage.Error) RollbarClientSync.SendExceptionAsync(fileEx, Controller.CurrentIdentity) End Try ''OR Dim saveFileDialog As New Microsoft.Win32.SaveFileDialog saveFileDialog.DefaultExt = "tab" Dim reportFileName As String = "ClientGroupExport_" & System.DateTime.Now.ToString("yyyyMMdd") Dim currExt = IO.Path.GetExtension(reportFileName) saveFileDialog.FileName = reportFileName Try If saveFileDialog.ShowDialog() Then 'SavedFileName = saveFileDialog.FileName Using fileStream As System.IO.Stream = saveFileDialog.OpenFile() Using sw As New System.IO.StreamWriter(fileStream) 'Me.FilteredClientGroups.CopyTo(fileStream) Dim lines As New List(Of String) Dim headers As New List(Of String) headers.Add("ClientType") headers.Add("SimpleName") headers.Add("SingleLineAddress") headers.Add("Phone") headers.Add("Fax") headers.Add("Email") headers.Add("Mobile") headers.Add("ContactName") headers.Add("ContactEmail") headers.Add("ContactPhone") headers.Add("Owner") headers.Add("ClientSourceType") lines.Add(String.Join(vbTab, headers.ToArray)) For Each row In FilteredClientGroupMembers Dim elements As New List(Of String) elements.Add(row.ClientType) elements.Add(row.SimpleName) elements.Add(row.SingleLineAddress) elements.Add(row.Phone) elements.Add(row.Fax) elements.Add(row.Email) elements.Add(row.Mobile) elements.Add(row.ContactName) elements.Add(row.ContactEmail) elements.Add(row.ContactPhone) elements.Add(row.Owner) elements.Add(row.ClientSourceType) lines.Add(String.Join(vbTab, elements.ToArray)) Next ''Dim str As String = String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}\newLN", "ClientType", "SimpleName", "SingleLineAddress", "Phone", "Fax", "Email", "Mobile", "Owner", "ClientSourceType").Replace("\t", vbTab).Replace("\newLN", vbNewLine) 'Str = str & String.Join(Environment.NewLine, FilteredClientGroupMembers.Select(Of String)(Function(x) String.Format("{0}\t{1}\t{2}\t{3}\t{4}\t{5}\t{6}\t{7}\t{8}", x.ClientType, x.SimpleName, x.SingleLineAddress, x.Phone, x.Fax, x.Email, x.Mobile, x.Owner, x.ClientSourceType))).Replace("\t", vbTab) Dim contents = String.Join(Environment.NewLine, lines.ToArray) sw.WriteLine(contents) sw.Flush() sw.Close() End Using End Using If IO.File.Exists(saveFileDialog.FileName) Then If Windows.MessageBox.Show("Do you wish to open the saved file now?", "Open File?", Windows.MessageBoxButton.YesNo, Windows.MessageBoxImage.Question, Windows.MessageBoxResult.No) = Windows.MessageBoxResult.Yes Then 'Open the file in the default viewer Try System.Diagnostics.Process.Start(saveFileDialog.FileName) Catch ex As Exception Windows.MessageBox.Show(String.Format("An error occurred trying to open the file '{0}'", saveFileDialog.FileName), "File Error", Windows.MessageBoxButton.OK, Windows.MessageBoxImage.Error) RollbarClientSync.SendExceptionAsync(ex, Controller.CurrentIdentity) End Try End If End If End If Catch ioEx As System.IO.IOException Windows.MessageBox.Show(String.Format("There was a problem saving the file to '{0}'. The error was: {1}{2}Check to see if the file is already in use, and that you have permissions to write to the requested file path.", saveFileDialog.FileName, ioEx.GetBaseException.Message, Environment.NewLine), "Failed To Save Report", Windows.MessageBoxButton.OK, Windows.MessageBoxImage.Error) Catch fileEx As Exception Windows.MessageBox.Show(String.Format("There was a problem saving the file to '{0}'. The error was: {1}", saveFileDialog.FileName, fileEx.GetBaseException.Message), "Failed To Save Client Group report", Windows.MessageBoxButton.OK, Windows.MessageBoxImage.Error) RollbarClientSync.SendExceptionAsync(fileEx, Controller.CurrentIdentity) End Try |