Page 1 of 1

Iterate Over Iventory And Update Items

PostPosted: Wed Oct 28, 2015 3:01 pm
by SBarnes
Hi Guys

I need to logon to Jiwa from a .net application and Iterate Over the Inventory Items and update certain Properties namely for example AUX2/ Bar code if certain criteria are met, could you provide some sample code as to how to go about this?

It may also be necessary from the data from another SQL Database add an item if its not present if the part number is not present after the initial update above, could you provide a sample also of how to insert a new item from code?

Thanks

Re: Iterate Over Iventory And Update Items  Topic is solved

PostPosted: Fri Oct 30, 2015 9:13 am
by Mike.Sheen
Hi Stuart,

This should do what you want for updating items:

Code: Select all
Imports JiwaFinancials.Jiwa.JiwaApplication
Imports JiwaFinancials.Jiwa.JiwaInventory
Imports System.Data.SqlClient

Public Class Test
    Private Sub BulkUpdate()
        Manager.Instance.Logon("SQLServerName", "DatabaseName", JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", "Password")

        With Manager.Instance.Database
            Dim SQLReader As SqlDataReader = Nothing
            Dim inventory As Inventory = Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of Inventory)(Nothing)
            Try

                Dim sql As String = "SELECT InventoryID FROM IN_Main ORDER BY PartNo"

                Using SQLCmd As SqlCommand = New SqlCommand(sql, .SQLConnection, .SQLTransaction)
                    SQLCmd.CommandTimeout = .DefaultCommandTimeout
                    SQLReader = SQLCmd.ExecuteReader()

                    Do While SQLReader.Read
                        Dim InventoryID As String = .Sanitise(SQLReader, "InventoryID").ToString
                        inventory.Read(InventoryID)
                        inventory.AUX2 = "Some Value"
                        inventory.Save()
                    Loop

                    SQLReader.Close()
                End Using

            Finally
                If Not SQLReader Is Nothing Then
                    SQLReader.Close()
                End If
            End Try
        End With

        Manager.Instance.LogOff()
    End Sub
End Class


And for creating an item:

Code: Select all
 Private Sub CreateItem()
        Manager.Instance.Logon("SQLServerName", "DatabaseName", JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", "Password")

        Dim inventory As Inventory = Manager.Instance.BusinessLogicFactory.CreateBusinessLogic(Of Inventory)(Nothing)

        inventory.CreateNew()
        inventory.PartNo = "ABC"
        inventory.Description = "Test"
        inventory.DefaultPrice = 21
        inventory.Save()

        Manager.Instance.LogOff()
    End Sub

Re: Iterate Over Iventory And Update Items

PostPosted: Mon Nov 02, 2015 12:57 pm
by SBarnes
Hi Mike

Firstly thanks for the code it was enough to get me started, but I have run into a small glitch that I am hoping you can help me overcome, the code works perfectly in either a winforms application or a console application where simply thus far I can get it to iterate over the items and spit out a property for each each either to a list ox or the console respectively but if i use the same code in a web based project it stops at the first line

Manager.Instance.Logon("SERVERNAME", "JiwaDemo", JiwaFinancials.Jiwa.JiwaODBC.database.AuthenticationModes.JiwaAuthentication, "Admin", "password"); and the stack trace

System.NullReferenceException was unhandled by user code
HResult=-2147467261
Message=Object reference not set to an instance of an object.
Source=JiwaApplication
StackTrace:
at JiwaFinancials.Jiwa.JiwaApplication.Manager.HandleApplicationManagerPluginExceptions()
at JiwaFinancials.Jiwa.JiwaApplication.Manager.Logon(String ServerName, String DatabaseName, AuthenticationModes AuthenticationMode, String JiwaUserName, String JiwaPassword)

which leads me to believe it is caused by the plugins trying to load, it there a way to progrmatically tell jiwa not to load the plugins or to do so in such a way that its not going to be a problem in a web project?

Thanks for any help

Re: Iterate Over Iventory And Update Items

PostPosted: Mon Nov 02, 2015 2:03 pm
by Mike.Sheen
Hi Stuart,

I've used the Jiwa assemblies in web (MVC 5) projects before without issue (even published to an Azure web app - support.jiwa.com.au is exactly that - it uses the Jiwa assemblies). make sure the target platform is x86, 32 bit, and the .Net framework version matches your Jiwa version - from memory failure to do so causes the problem you are experiencing.

Mike

Re: Iterate Over Iventory And Update Items

PostPosted: Mon Nov 02, 2015 2:51 pm
by SBarnes
Hi Mike,

Thanks for the advice unfortunately this doesn't fix the problem, the version of Jiwa is 7.0.129.0 and the .net framework is 4.5.1 which I know to be correct as the win forms application would not compile until it was changed to 4.5.1 due to the jiwa dlls, the application is a visual studio 2013 update 5 project using mvc 5 and web api 2, the call is in a web api controller although the same problem happens from within an mvc controller as well, not that that should make a difference at any rate.

Any other suggestions would be appreciated.

Re: Iterate Over Iventory And Update Items

PostPosted: Mon Nov 02, 2015 3:35 pm
by SBarnes
Hi Mike,

Ignore my last post, I just figured out the problem when I thought about it rather than just have the jiwa dlls that I am using i.e. odbc, application and inventory, when I added every dll with jiwa in its name from the program directory to the project the problem fixed itself obviously it is related to .net finding the necessary dlls for what is firing with the plugins at login under aps.net as opposed to a normal windows process.

Thanks for the help.