#Description: Example Function to update an Account's Monitor Category.
#Author: Intersoft Systems Limited
#Version: 1.00
#Last Updated: 20/04/2020

''' <summary>
'''  Updates an Account's Monitor Category.
''' </summary>
''' <param name="accountPk">
'''  The Primary Key of the Account. If you already have the Account object loaded, set to Account.Pk.
''' </param>
''' <param name="monitorCategory">
'''  The Monitor Catgeory, A, B or C, to update.
''' </param>
''' <param name="monitorCategoryId">
'''  The Id of the Monitor Category to update to, or blank to clear.
''' </param>
''' <param name="dateEffective">
'''  The date to update the Monitor Category on.
''' </param>
''' <param name="reference">
'''  Your Reference for the Monitor Category change. Maximum of 20 characters.
''' </param>
''' <param name="notes">
'''  Any Notes regarding the Monitor Category change. Maximum of 255 characters.
''' </param>
''' <returns>
'''  A Boolean value indicating success.
''' </returns>
Private Function Account_MonitorCategoryChange(accountPk As Integer,
                                               dateEffective As Date,
                                               monitorCategory As isefinAccountMonitorCategory,
                                               monitorCategoryId As String,
                                               reference As String,
                                               notes As String) As Boolean

  Dim AccountMonitorCategoryChange As finAccountMonitorCategoryChange
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Create Objects
  AccountMonitorCategoryChange = finBL.CreateAccountMonitorCategoryChange()
	
  With AccountMonitorCategoryChange
    ' Load Account
    Success = .AccountLoadPk(accountPk)

    If Success Then
      ' Firstly, set Date Effective to ensure existing Monitor Categories are loaded on this date
      .DateEffective = dateEffective 

      ' Update Monitor Category
      Select Case monitorCategory
        Case isefinAccountMonitorCategory.CategoryA
          .MonitorCategoryAUpdate = True
          .MonitorCategoryAId = monitorCategoryId
          
        Case isefinAccountMonitorCategory.CategoryB
          .MonitorCategoryBUpdate = True
          .MonitorCategoryBId = monitorCategoryId
          
        Case isefinAccountMonitorCategory.CategoryC
          .MonitorCategoryCUpdate = True
          .MonitorCategoryCId = monitorCategoryId
      End Select

      ' Update Other Properties
      .Notes = notes
      .Reference = reference

      ' Commit (if there are changes)
      If .HasChanges() Then
        Success = .ExecuteCommit()
			End If
    End If
  End With

  ' Return Success
  Return Success

End Function