Datatable.DefaultView.RowFilter не работает для определенных пользователей - PullRequest
0 голосов
/ 15 апреля 2020

Так что я в своем уме. Я собираюсь выпустить эту программу, но в настоящее время я единственный пользователь, который может ее открыть. Я переключил базу данных SQL с Windows Аутентификация на SQL Аутентификация сервера, так как думал, что это проблема с сервером SQL, не позволяющим другим пользователям подключаться. Я могу заставить это работать для всех пользователей, когда я только фильтрую основную таблицу (см. DashboardDataFiltersub), но если я использую любой из других фильтров, все, что я получаю, это экран spla sh, то приложение закрывается. Странная часть для меня, если я комментирую или удаляю FixtureDataFilter, ProgramDataFilter и CMMDataFilter, эта программа будет работать без проблем.

Спасибо за помощь, Мэтт

Imports System.Data
Imports SPR.DatabaseLoading
Imports Microsoft.Office.Interop

Public Class OpenScreen
    Public Shared OutlookApp As Outlook.Application
    Dim User As String = Environment.UserName & "@senioraeroct.com"
    Dim Result() As DataRow

    Private Sub MainWindow_Loaded(sender As Object, e As RoutedEventArgs) Handles Me.Loaded

        SPRMainDataAdapt.Fill(SPRMainDataTable)
        ProgramDataAdapt.Fill(ProgramDataTable)
        FixtureDataAdapt.Fill(FixtureDataTable)
        CMMDataAdapt.Fill(CMMDataTable)

        Dim SPRSource As System.Windows.Data.CollectionViewSource = CType(FindResource("SPRSource"), System.Windows.Data.CollectionViewSource)
        SPRSource.View.MoveCurrentToFirst()
        DashBoardDataGrid.ItemsSource = SPRMainDataTable

        Dim ProgSource As System.Windows.Data.CollectionViewSource = CType(FindResource("ProgSource"), System.Windows.Data.CollectionViewSource)
        ProgSource.View.MoveCurrentToFirst()
        ProgramDataGrid.ItemsSource = ProgramDataTable

        Dim FixSource As System.Windows.Data.CollectionViewSource = CType(FindResource("FixSource"), System.Windows.Data.CollectionViewSource)
        FixSource.View.MoveCurrentToFirst()
        FixtureDataGrid.ItemsSource = FixtureDataTable

        Dim CMMSource As System.Windows.Data.CollectionViewSource = CType(FindResource("CMMSource"), System.Windows.Data.CollectionViewSource)
        CMMSource.View.MoveCurrentToFirst()
        CMMDataGrid.ItemsSource = CMMDataTable

        ComboDataAdapt.FillEmail(EmailDataTable)
        Result = EmailDataTable.Select("Email = '" & User & "'")

        If Result.Length <> 0 Then
            User = Result(0)("Name")
        End If

        DashboardDataFilter()
        FixtureDataFilter()
        ProgramDataFilter()
        CMMDataFilter()
        OpenBtn.Focus()
    End Sub

    Private Sub MainWindow_Initialized(sender As Object, e As EventArgs) Handles Me.Initialized
        Try
            OutlookApp = GetObject(, "Outlook.Application")
        Catch
            OutlookApp = New Outlook.Application
        End Try
    End Sub

    Private Sub DashboardDataFilter()
        'Set the filter based on username
        Dim Filter As String = ""

        If Result.Length <> 0 Then
            Dim Type As String = Result(0)("Type")
            If Type.Contains("Engineering") Then
                If Type.Contains("Quality Engineering") Then
                    Filter = Filter & "CompleteSPR is NULL AND QualName LIKE '%" & User & "%'"
                Else
                    Filter = Filter & "CompleteSPR is NULL AND EngName LIKE '%" & User & "%'"
                End If
            End If
        Else
            Filter = Filter & "EngName LIKE '%N/A%'"
        End If

        'Apply Filter
        SPRMainDataTable.DefaultView.RowFilter = Filter
    End Sub

    Private Sub ProgramDataFilter()
        'Set the filter based on username
        Dim Filter As String = ""

        Filter = "Complete is NULL"
        If Result.Length <> 0 Then
            Dim Type As String = Result(0)("Type")
            If Type.Contains("Engineering") Then
                If Type.Contains("Quality Engineering") = False Then
                    Filter = Filter & " AND (SPREng LIKE '%" & User & "%')"
                End If
            End If
            Filter = Filter & " OR (AssignedBy LIKE '%" & User & "%' OR Programmer LIKE '%" & User & "%')"
        Else
            Filter = Filter & " AssignedBy LIKE '%N/A%'"
        End If

        'Apply Filter
        ProgramDataTable.DefaultView.RowFilter = Filter
    End Sub

    Private Sub FixtureDataFilter()
        'Set the filter based on username
        Dim Filter As String = ""

        Filter = "Complete is NULL"
        If Result.Length <> 0 Then
            Dim Type As String = Result(0)("Type")
            If Type.Contains("Engineering") Then
                If Type.Contains("Quality Engineering") = False Then
                    Filter = Filter & " AND (SPREng LIKE '%" & User & "%')"
                End If
            End If
            Filter = Filter & " OR (AssignedBy LIKE '%" & User & "%' OR DesEng LIKE '%" & User & "%')"
        Else
            Filter = Filter & " AssignedBy LIKE '%N/A%'"
        End If

        'Apply Filter
        FixtureDataTable.DefaultView.RowFilter = Filter
    End Sub

    Private Sub CMMDataFilter()
        'Set the filter based on username
        Dim Filter As String = ""

        Filter = "Complete is NULL"
        If Result.Length <> 0 Then
            Dim Type As String = Result(0)("Type")
            If Type.Contains("Engineering") Then
                If Type.Contains("Quality Engineering") = False Then
                    Filter = Filter & " AND (SPREng LIKE '%" & User & "%')"
                End If
            End If
            Filter = Filter & " OR (AssignedBy LIKE '%" & User & "%' OR Programmer LIKE '%" & User & "%')"
        Else
            Filter = Filter & " AssignedBy LIKE '%N/A%'"
        End If

        'Apply Filter
        CMMDataTable.DefaultView.RowFilter = Filter
    End Sub
End Class
...