SBarnes wrote:1. In creating a business entity I noticed that all properties implement Notify Property changed, I would assume this is so that the entity can be bound to the the Infragistics controls but is this mandatory on all properties i.e. if something is not going to be bound to a control does it need to do so?
We don't bind (we found it didn't give the flexibility we needed at the time), we just implement the INotifyPropertyChanged interface as a way of our UI to be informed of property changes. It also is used by our business logic to set the ChangeFlag, which is used by both the business logic and forms. You should still invoke the NotifyPropertyChanged method built into our base classes on property setters so that the business logic knows on save it's state, and the UI knows the state to update ribbon tool states.
SBarnes wrote:2. In creating a form that would inherit from JiwaFinancials.Jiwa.JiwaApplication.Forms.Maintenance, can you review the steps I have identified to hook it up to the Jiwa framework, these steps I already have worked out from looking at the Magento Plug in as you suggested previously are:
A. Add the code created by the designer to the bottom on the plugin
B. Make sure the class for the form has a constructor that calls Initializecomponent
C. Override Setup making sure to call base.setup and setupwindow
D. Override SetupBeforeHandlers and set the MDIParent and set the forms BusinessLogic property to an instance of of the new entity
E. Add the plugin under forms maintenance and add a menu item to the form /plugin
Is there anything I've missed?
I don't think you've missed anything - only one way to find out! If you find unexpected behaviour with your form, let us know in another thread and we can pinpoint what's missing.
SBarnes wrote:3. Could you also provide an example or insight into implementing IJiwaCollectionItem as the entity I am creating will have lines as well and for consistency I would like to try and use the Jiwa Collection properly. The related collection code would also help.
Thanks.
A simple example would be the freight items for carriers in the carrier maintenance form - note we always inherit from JiwaCollectionItem, we don't implement the interface separately as that would mean a lot more repetition of code, and we hate that:
- Code: Select all
Option Strict Off
Option Explicit On
Imports JiwaFinancials.Jiwa
Imports System.Data.SqlClient
Public Class FreightDescriptionCollection
Inherits JiwaFinancials.Jiwa.JiwaApplication.JiwaCollection(Of FreightDescription)
Private _Carrier As Carrier
Public ReadOnly Property Carrier() As Carrier
Get
Return _Carrier
End Get
End Property
Sub New(ByVal ownerCarrier As Carrier)
_Carrier = ownerCarrier
RecIDIsGUID = True
End Sub
Public Overrides Sub Read()
Dim Sql As String
Dim SQLReader As SqlDataReader = Nothing
Dim SQLParam As SqlParameter = Nothing
Dim oldReading As Boolean = Reading
Try
Reading = True
Clear()
With JiwaApplication.Manager.Instance.Database
Sql = "SELECT RecID, FreightDescription, DefaultItem, LastSavedDateTime, FreightDescriptionEnabled " &
"FROM FR_CarrierFreightDescriptions " &
"WHERE FR_Carriers_RecID = @FR_Carriers_RecID " &
"ORDER BY FreightDescription "
Using SQLCmd As SqlCommand = New SqlCommand(Sql, .SQLConnection, .SQLTransaction)
SQLParam = New SqlParameter("@FR_Carriers_RecID", System.Data.SqlDbType.Char)
SQLParam.Value = Carrier.RecID
SQLCmd.Parameters.Add(SQLParam)
SQLReader = .ExecuteReader(SQLCmd)
Dim freightDescription As FreightDescription
Do While SQLReader.Read = True
freightDescription = New FreightDescription
freightDescription.RecID = .Sanitise(SQLReader, "RecID")
freightDescription.Description = .Sanitise(SQLReader, "FreightDescription")
freightDescription.DefaultItem = .Sanitise(SQLReader, "DefaultItem")
freightDescription.LastSavedDateTime = .Sanitise(SQLReader, "LastSavedDateTime")
freightDescription.Enabled = .Sanitise(SQLReader, "FreightDescriptionEnabled")
Add(freightDescription)
Loop
SQLReader.Close()
End Using
End With
Finally
Reading = oldReading
If Not SQLReader Is Nothing Then
SQLReader.Close()
End If
End Try
End Sub
Protected Overrides Sub OnRemoving(item As FreightDescription)
If item.DefaultItem And Collection.Count > 1 Then
Throw New Exception("Cannot remove the default freight description - make another freight description the default first.")
End If
MyBase.OnRemoving(item)
End Sub
Protected Overrides Sub OnAdding(item As FreightDescription)
If Carrier.IsReading = False Then
If Collection.Count = 0 Then
item.DefaultItem = True
End If
item.Enabled = True
End If
MyBase.OnAdding(item)
End Sub
End Class
And the class which it is a collection of, FreightDescription:
- Code: Select all
Option Strict Off
Option Explicit On
Imports JiwaFinancials.Jiwa
Imports System.Data.SqlClient
Public Class FreightDescription
Inherits JiwaFinancials.Jiwa.JiwaApplication.JiwaCollectionItem(Of FreightDescription)
#Region "Variables"
Private _Description As String = ""
Private _DefaultItem As Boolean
Private _LastSavedDateTime As Date
Private _Enabled As Boolean
#End Region
#Region "Properties"
Public ReadOnly Property FreightDescriptions() As FreightDescriptionCollection
Get
Return Collection
End Get
End Property
Public Property Description As String
Get
Return _Description
End Get
Set(value As String)
_Description = value
NotifyPropertyChanged("Description")
End Set
End Property
Public Property Enabled As String
Get
Return _Enabled
End Get
Set(value As String)
_Enabled = value
NotifyPropertyChanged("Enabled")
End Set
End Property
Public Property DefaultItem As Boolean
Get
Return _DefaultItem
End Get
Set(ByVal value As Boolean)
_DefaultItem = value
NotifyPropertyChanged("DefaultItem")
If Not FreightDescriptions Is Nothing AndAlso FreightDescriptions.Reading = False Then
If value = True Then
For Each otherFreightDescription As FreightDescription In FreightDescriptions
If Not otherFreightDescription.Equals(Me) Then
If otherFreightDescription.DefaultItem = True Then
otherFreightDescription.SetDefaultItem(False)
End If
End If
Next
Else
' You can't set the DefaultItem to false : you must set another to true.
_DefaultItem = True
NotifyPropertyChanged("DefaultItem")
End If
End If
End Set
End Property
Public Property LastSavedDateTime() As Date
Get
Return _LastSavedDateTime
End Get
Set(ByVal Value As Date)
_LastSavedDateTime = Value
End Set
End Property
#End Region
Friend Sub SetDefaultItem(ByVal newValue As Boolean)
_DefaultItem = newValue
NotifyPropertyChanged("IsDefault")
End Sub
Protected Overrides Sub iSave()
Dim Sql As String
Dim SQLParam As SqlParameter
With JiwaApplication.Manager.Instance.Database
If DeleteFlag = False Then
If InsertFlag Then
Sql = "INSERT INTO FR_CarrierFreightDescriptions(RecID, FR_Carriers_RecID, FreightDescription, DefaultItem, LastSavedDateTime, FreightDescriptionEnabled) " &
"VALUES (@RecID, @FR_Carriers_RecID, @FreightDescription, @DefaultItem, GETDATE(), @FreightDescriptionEnabled)"
Else
Sql = "UPDATE FR_CarrierFreightDescriptions SET " &
"FreightDescription = @FreightDescription" &
", DefaultItem = @DefaultItem" &
", FreightDescriptionEnabled = @FreightDescriptionEnabled" &
", LastSavedDateTime = GETDATE()" &
" WHERE RecID = @RecID AND LastSavedDateTime = @LastSavedDateTime "
End If
Using SQLCmd As SqlCommand = New SqlCommand(Sql, .SQLConnection, .SQLTransaction)
SQLParam = New SqlParameter("@RecID", System.Data.SqlDbType.Char)
SQLParam.Value = RecID
SQLCmd.Parameters.Add(SQLParam)
If InsertFlag Then
SQLParam = New SqlParameter("@FR_Carriers_RecID", System.Data.SqlDbType.Char)
SQLParam.Value = FreightDescriptions.Carrier.RecID
SQLCmd.Parameters.Add(SQLParam)
Else
SQLParam = New SqlParameter("@LastSavedDateTime", System.Data.SqlDbType.DateTime)
SQLParam.Value = LastSavedDateTime
SQLCmd.Parameters.Add(SQLParam)
End If
SQLParam = New SqlParameter("@FreightDescription", System.Data.SqlDbType.VarChar)
SQLParam.Value = Description
SQLCmd.Parameters.Add(SQLParam)
SQLParam = New SqlParameter("@DefaultItem", System.Data.SqlDbType.Bit)
SQLParam.Value = DefaultItem
SQLCmd.Parameters.Add(SQLParam)
SQLParam = New SqlParameter("@FreightDescriptionEnabled", System.Data.SqlDbType.Bit)
SQLParam.Value = Enabled
SQLCmd.Parameters.Add(SQLParam)
If .ExecuteNonQuery(SQLCmd) = 0 Then
Throw New JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ConcurrencyConflictException("unable to " & If(InsertFlag, "insert into", "update") & " FR_CarrierFreightDescriptions")
End If
End Using
End If
If DeleteFlag Then
Sql = "DELETE FROM FR_CarrierFreightDescriptions WHERE RecID = @RecID"
Using SQLCmd As SqlCommand = New SqlCommand(Sql, .SQLConnection, .SQLTransaction)
SQLParam = New SqlParameter("@RecID", System.Data.SqlDbType.Char)
SQLParam.Value = RecID
SQLCmd.Parameters.Add(SQLParam)
If .ExecuteNonQuery(SQLCmd) = 0 Then
Throw New JiwaFinancials.Jiwa.JiwaApplication.Exceptions.ConcurrencyConflictException("unable to delete from FR_CarrierFreightDescriptions")
End If
End Using
End If
End With
End Sub
End Class
The Carrier class itself needs to instantiate the collection and read and save when required:
- Code: Select all
Public Class Carrier
Inherits JiwaApplication.BusinessLogic.Maintenance
...
Private WithEvents _FreightDescriptions As FreightDescriptionCollection
...
Public ReadOnly Property FreightDescriptions As FreightDescriptionCollection
Get
Return _FreightDescriptions
End Get
End Property
...
Public Sub New()
MyBase.New()
ClientClassName = "JiwaFinancials.Jiwa.JiwaCarrierMaintUI.MainForm"
SortOrders.Add(New JiwaApplication.IJiwaNavigable.SortKey With {.Description = "CarrierName", .FieldName = "FR_Carriers.CarrierName"})
_Services = New ServiceCollection(Me)
_FreightDescriptions = New FreightDescriptionCollection(Me)
End Sub
...
Public Overrides Sub Clear()
ChangeFlag = False
InsertFlag = False
DeleteFlag = False
RecID = ""
_CarrierName = ""
_AccountNo = ""
_Enabled = False
_Notes = ""
_Services.Clear()
_FreightDescriptions.clear()
End Sub
Public Overrides Sub Read(RecID As String)
...
_FreightDescriptions.Read()
End Sub
Protected Overrides Sub iSave()
...
_FreightDescriptions.Save()
End Sub


