How B4J using JaxaFX 8 helped me out with printing

Peter Simpson

Expert
Licensed User
Longtime User
Hello all,
I've only ever used B4J for personal smaller pet projects for myself, just under two weeks ago thanks to an extremely badly designed MySQL database from another developer, I was left only 4 days to create two remote warehouse printing solution using VB.Net. In VB.Net is was not possible using Crystal Reports (well not in 4 days), so I bit the bullet and turned to B4J. Yes I did manage to create the two apps (app 1 being a delivery note manager, app 2 being a print server for 4 companies at the warehouse 25 files miles away).

I had just about managed to complete the two apps using B4J in 4 days, yes I was burning the candle at both ends :(

So the good news is that I drove the 95 miles to install app 1 at the companies HQ, I then drove an extra 25 miles to install the Dell server and laser printer, App 2 was pre-installed on the dell server which was connected to two printers (not one printer) to print delivery notes for four companies.

Thanks to Steve Laming for sharing his great B4J printing solution, without which the remote printing for this project would have been a hell of a lot more difficult to compete in just four days. Yes there are other solutions on here but none as simple as Steve's when it comes to designing layouts, it's just drag and drop.

Anyway, I've decided to share the very basics of how I created two of the form layouts. I've added screenshots, PDF files and an example project in the B4J tutorial forum.

CLICK HERE to view the B4J post

Have a look, it's sooooooooooooooooo simple to use, that simplicity really is the key in this case.

Enjoy...
 
Last edited:

sorex

Expert
Licensed User
Longtime User
I'm not sure if you can still use Crystal Reports with .NET as their focus is on their own reporting (server) stuff.

I personally prefer CR11 aswell as I find it easier to work with.

Interesting to see how you used that scene builder tool for such task.
How do you tell it what labels are part of the ordered items record set?
(this is usually a split view in CR/RS)
 

Peter Simpson

Expert
Licensed User
Longtime User
How do you tell it what labels are part of the ordered items record set?
(this is usually a split view in CR/RS)

All four databases are MySQL, so it's just a simple task of generating the form members then reading the SQL query results directly onto the views.

Here is an example taken from V1 of my working code (not production code). V2 does all the calculations via the SQL query, V1 doesn't.

The following code reads the database and populates the item list views one row at a time getting it ready to print. I dont dynamically add views I just populate the one long view.

BTW V2 of my code calculates the amount of line there are in the items list. If the list reaches the max bottom line, then it creates a new page using the exact same code again...
B4X:
    Dim Total As Int
    For i = 0 To Items.Length - 1
        Dim ProdId() As String = Regex.Split("~", Items(i))
        Dim SQL As String = $"SELECT * FROM products, del_notes WHERE del_note = ${DelNote} AND products.id = ${ProdId(0)};"$
        Dim SenderFilter As Object = DatabaseCode.MySQL.ExecQueryAsync("MySQL", SQL, Null)
        Wait For (SenderFilter) MySQL_QueryComplete (Success As Boolean, RS As ResultSet)
        If Success Then
            Do While RS.NextRow
                LblProdCode.Text = LblProdCode.Text & RS.GetString("code") & CRLF
                LblDescription.Text = LblDescription.Text & RS.GetString("desc") & CRLF
                LblNoOfUnits.Text = LblNoOfUnits.Text & (RS.GetString("units per carton") * ProdId(1)) & CRLF
                LblUnitsPerCar.Text = LblUnitsPerCar.Text & (RS.GetString("units per carton") * ProdId(1) / ProdId(1)) & CRLF
                LblNoOfCar.Text = LblNoOfCar.Text & ProdId(1) & CRLF
                LblCarPerPal.Text = LblCarPerPal.Text & RS.GetString("cartons of pallets") & CRLF
                LblNoOfPal.Text = LblNoOfPal.Text & ProdId(2) & CRLF
                Total = Total + ProdId(2)
            Loop
            RS.Close
        End If
    Next
 
    LblTotal.Text = Total

There's probably another way to do this, but this works great for me so I will not be changing the code. The print server app has already printed well over 750 delivery notes since last Wednesday with no issues whatsoever.
 
Last edited:

sorex

Expert
Licensed User
Longtime User
hmm... how does it add lines? I just see setting values in that loop.
 

Peter Simpson

Expert
Licensed User
Longtime User
hmm... how does it add lines? I just see setting values in that loop.
Remember that each label is actually a long column and not just a single row label, after reading each result from the database and amending each label via the code above, I then add the following to the end of each append ready for the next item/line.
B4X:
 & CRLF

It simply reads the results and then amends the correct columns until the list is complete.

First the description column is empty.

Read and add the 1st result then add a CRLF
Description column (LblDescription) now looks like
Toshiba Laptop

Read and add the 2nd result then add a CRLF
Description column (LblDescription) now looks like
Toshiba Laptop
Microsoft Mouse


Read and add the 3rd result then add a CRLF
Description column (LblDescription) now looks like
Toshiba Laptop
Microsoft Mouse
Mouse Mat


Read and add the 4th result then add a CRLF
Description column (LblDescription) now looks like
Toshiba Laptop
Microsoft Mouse
Mouse Mat
Laptop case


Etc etc etc.

Basically all the loop is doing is amending each column with the item details (the shortest routine I can currently think of). There's no need to dynamically add lots of labels, I just keep amending the correct column followed by a CRLF.

Yes that's all the code that is needed for populating the 7 columns for the items, the SQL query is also there, the database is already open, I close the connection after the last item is read.

The code above generates the list blow in the redacted screenshot below.
Untitled-2.png
 
Last edited:

sorex

Expert
Licensed User
Longtime User
ok now I get it, Peter.

the only problem you might run at is when text is too long and wraps to another line then the lines will get "out of line" horizontally due to missing linefeeds.

unless you go for that "..." option on single lined fixed sized labels.

good job.
 

Peter Simpson

Expert
Licensed User
Longtime User
the only problem you might run at is when text is too long and wraps to another line then the lines will get "out of line" horizontally due to missing linefeeds
.

I've thought about that already.
I tested their longest item description text and it easily fits within the description field with plenty of free space. Luckily they keep their item descriptions nice and short. If they ever had that problem I would just drop the font size down from 10 to 9 on all 4 layouts.

Cheers...
 
Last edited:

mangojack

Well-Known Member
Licensed User
Longtime User
Top