VB замена объекта в списке - PullRequest
0 голосов
/ 23 апреля 2019

У меня есть 2 списка утвержденных Поставщиков и originalSupplierData

Когда заполненные утвержденные поставщики будут заполнены, мы клонируем запись в originalSupplierData.Если они изменили запись, но не сохранили, мы спрашиваем пользователя, хотят ли они отменить изменения.Если они хотят вернуться, я пытаюсь заменить запись в утвержденных поставщиках клоном исходных данных.Мой текущий код для возврата:

    Public Sub RevertChanges(SupplierID As Integer)

    Dim orignalSupplier As Approved_Supplier = originalSupplierlist.Where(Function(x) x.ID = SupplierID).Single()
    Dim modifiedSupplier As Approved_Supplier = ApprovedSuppliers.Where(Function(x) x.ID = SupplierID).Single()

    modifiedSupplier = orignalSupplier.Clone


End Sub

Измененный поставщик будет обновлен с исходными значениями, однако фактический элемент в списке не обновляется со значениями.Если я изменю одно из свойств, список получит обновление.Я не уверен, что я делаю не так, может кто-нибудь направить меня в правильном направлении, пожалуйста?

Редактировать Код для заполнения списка из базы данных:

        supplierTableAdapter.Fill(supplierTable)

    _approvedSuppliers = New List(Of Approved_Supplier)
    originalSupplierlist = New List(Of Approved_Supplier)()

    For Each row As ApprovedSuppliersDataset.ApprovedSupplierRow In supplierTable
        supplier = New Approved_Supplier()

        supplier.supplierID = row.PLSupplierAccountID
        supplier.AccountNumber = row.SupplierAccountNumber
        supplier.SupplierName = row.SupplierAccountName
        supplier.SupplierAddress = CompileAddress(row)
        supplier.Phone = CompilePhoneNumber(row)

        If row.IsIDNull = False Then

            supplier.ID = row.ID

            If row.IsAdded_ByNull = False Then
                supplier.AddedBy = row.Added_By
            End If

            If row.IsApprovedNull = False Then
                supplier.Approved = row.Approved
            End If

            If row.IsAuditorNull = False Then
                supplier.Auditor = row.Auditor
            End If

            If row.IsAudit_CommentsNull = False Then
                supplier.AuditComments = row.Audit_Comments
            End If

            If row.IsAudit_DateNull = False Then
                supplier.AuditDate = row.Audit_Date
            End If

            If row.IsDate_AddedNull = False Then
                supplier.DateAdded = row.Date_Added
            End If

            If row.IsNotesNull = False Then
                supplier.Notes = row.Notes
            End If

            If row.IsQuestionnaire_Return_DateNull = False Then
                supplier.QuestionnaireReturnDate = row.Questionnaire_Return_Date
            End If

            If row.IsQuestionnaire_Sent_DateNull = False Then
                supplier.QuestionnaireSentDate = row.Questionnaire_Sent_Date
            End If

            If row.IsQuestionnaire_StatusNull = False Then
                supplier.QuestionnaireStatus = row.Questionnaire_Status
            End If

            If row.IsReplinNull = False Then
                supplier.Replin = row.Replin
            End If

            If row.IsReview_CommentsNull = False Then
                supplier.ReviewComment = row.Review_Comments
            End If

            If row.IsReview_DateNull = False Then
                supplier.ReviewDate = row.Review_Date
            End If

            If row.IsReviewerNull = False Then
                supplier.Reviewers = row.Reviewer
            End If

            If row.IsStakeholder_ContactNull = False Then
                supplier.StakeholderContact = row.Stakeholder_Contact
            End If

            If row.IsStandardsNull = False Then
                supplier.Standards = row.Standards
            End If

            If row.IsStandard_ExpiryNull = False Then
                supplier.StandardExpiry = row.Standard_Expiry
            End If

            If row.IsStatusNull = False Then
                supplier.Status = row.Status
            End If

            If row.IsSupplier_Expiry_DateNull = False Then
                supplier.SupplierExpiryDate = row.Supplier_Expiry_Date
            End If

            If row.IsSupplier_ScopeNull = False Then
                supplier.SupplierScope = row.Supplier_Scope
            End If

            If row.Is_T_CsNull = False Then
                supplier.TC = row._T_Cs
            End If
        End If

        supplier.ClearISDirty()
        _approvedSuppliers.Add(supplier)
        originalSupplierlist.Add(supplier.Clone)
    Next

и для клона мыиметь

  Public Function Clone() As Object Implements ICloneable.Clone
    Dim cloned As New Approved_Supplier()

    cloned.ID = Me.ID
    cloned.DateAdded = Me.DateAdded
    cloned.Status = Me.Status
    cloned.AddedBy = Me.AddedBy
    cloned.Approved = Me.Approved
    cloned.AuditDate = Me.AuditDate
    cloned.Auditor = Me.Auditor
    cloned.AuditComments = Me.AuditComments
    cloned.QuestionnaireStatus = Me.QuestionnaireStatus
    cloned.QuestionnaireSentDate = Me.QuestionnaireSentDate
    cloned.QuestionnaireReturnDate = Me.QuestionnaireReturnDate
    cloned.ReviewDate = Me.ReviewDate
    cloned.Reviewers = Me.Reviewers
    cloned.ReviewComment = Me.ReviewComment
    cloned.Standards = Me.Standards
    cloned.StandardExpiry = Me.StandardExpiry
    cloned.SupplierScope = Me.SupplierScope
    cloned.Replin = Me.Replin
    cloned.TC = Me.TC
    cloned.Notes = Me.Notes
    cloned.StakeholderContact = Me.StakeholderContact
    cloned.SupplierExpiryDate = Me.SupplierExpiryDate

    cloned.supplierID = Me.supplierID 
    cloned.AccountNumber = Me.AccountNumber
    cloned.SupplierName = Me.SupplierName
    cloned.SupplierAddress = Me.SupplierAddress
    cloned.Phone = Me.Phone
    cloned.Email = Me.Email
    cloned.ClearISDirty()
    Return cloned

End Function

1 Ответ

1 голос
/ 23 апреля 2019

Вы не заменяете в списке, воздействуя на updatedSupplier.

Попробуйте получить индекс модифицированногоSupplier и затем заменить элемент в найденном индексе своим клоном.

Public Sub RevertChanges(SupplierID As Integer)

    Dim orignalSupplier As Approved_Supplier = originalSupplierlist.Where(Function(x) x.ID = SupplierID).Single()
    Dim modifiedIndex As Integer = ApprovedSuppliers.FindIndex(Function(x) x.ID = SupplierID)

    ApprovedSuppliers(modifiedIndex) = orignalSupplier.Clone()


End Sub
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...