New Business Logic Entities  Topic is solved

Discussions relating to Jiwa 7 plugin development, and the Jiwa 7 API.

Re: New Business Logic Entities  Topic is solved

Postby Mike.Sheen » Thu Jun 16, 2016 8:23 pm

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
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Re: New Business Logic Entities

Postby SBarnes » Fri Jun 17, 2016 8:39 am

Hi Mike,

Thanks for the update I had been able to get most of it going by having a look at other examples from Jiwa itself through reflection and from the Magento plugin for things such as search, new and save, although I will definitely go through the example you have provided to ensure I haven't missed anything vital on the collection I've setup.

One other area though that I am unsure on is how you could achieve some print functionality, I understand that you need to create a crystal report and then add it to the system as a report, but how do you then hook the toolbar print button to functionality within the form, is this similar to search in that you need to overrride a print function on the form and then have it call into your business logic?
Regards
Stuart Barnes
SBarnes
Shihan
Shihan
 
Posts: 1696
Joined: Fri Aug 15, 2008 3:27 pm
Topics Solved: 191

Re: New Business Logic Entities

Postby Mike.Sheen » Fri Jun 17, 2016 6:24 pm

SBarnes wrote:One other area though that I am unsure on is how you could achieve some print functionality, I understand that you need to create a crystal report and then add it to the system as a report, but how do you then hook the toolbar print button to functionality within the form, is this similar to search in that you need to overrride a print function on the form and then have it call into your business logic?


Yes, override the PrintRecord method in your UI class/form, then you can either print the report from there, or if you want your business logic to keep an audit of printed reports, invoke that.

A simple example is from the BillMaintenance form - it follows a common pattern we prefer to adopt in which the report uses a stored procedure, and has formulas defined for a stored proc based report:

Code: Select all
Public Overrides Sub PrintRecord(ByVal ReportDefinition As JiwaApplication.PrintGroup.FormReports.ReportDefinition)
   OnPrintStarting(ReportDefinition)
   Dim PrintUIObject As JiwaApplication.JiwaPrintReportUI.MainForm
   Dim MyLoop As Integer

   PrintUIObject = JiwaApplication.Manager.Instance.CreateReport(ReportDefinition, 1, True, False, True)
   If Not (PrintUIObject Is Nothing) Then
      For MyLoop = 1 To PrintUIObject.PrintReportObject.JiwaReportRangeCollection.Count
         If UCase(PrintUIObject.PrintReportObject.JiwaPrintFormulaCollection(PrintUIObject.PrintReportObject.JiwaReportRangeCollection(MyLoop).FormulaKey).Name) = UCase("Pass_SP_StartingBillNo") Or UCase(PrintUIObject.PrintReportObject.JiwaPrintFormulaCollection(PrintUIObject.PrintReportObject.JiwaReportRangeCollection(MyLoop).FormulaKey).Name) = UCase("Pass_SP_EndingBillNo") Then
            PrintUIObject.PrintReportObject.JiwaReportRangeCollection(MyLoop).Value = BillMaintenance.BillNo
         End If
      Next MyLoop

      PrintUIObject.UpdateReport()
      PrintUIObject.chkDrill.Checked = True
      PrintUIObject.PrintReportToScreen()
      PrintUIObject.Show()
   End If
   OnPrintEnd(ReportDefinition)
End Sub
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2583
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 807

Previous

Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 0 guests