Android Question RDC Execute Batch

Pantelis Loizou

Member
Licensed User
Longtime User
Hi Everyone

I have created an application for PDA's handheld devices for taking orders from customers in a bar/restaurant etc. All the orders are kept locally at first (on the PDA memory) and a soon as the wifi connection with the server is established the orders are executed. This is done in order to avoid wifi connection losses and for the user/waiter to be able to take orders with no interruption and connection failures.

However one problem i face with this method is that sometimes a pending order (an order that remained in the spooler locally becaue of wifi connection failure) might be executed multiple times when the connection is back on.

below may find my code.
B4X:
Dim commands As List
        commands.Initialize
        Main.CursorLite=Main.SQLite.ExecQuery("SELECT * FROM PDA_Lines WHERE pda_storeid='" & Main.StoreID & "' AND pda_station='" & Main.StationID & "' ORDER BY pda_ref, pda_line")
        For p= 0 To Main.CursorLite.RowCount - 1
            Main.CursorLite.Position=p
            pda_ref = Main.CursorLite.GetInt("pda_ref")
            pda_StoreID = Main.CursorLite.GetString("pda_storeid")
            pda_StationID = Main.CursorLite.GetString("pda_station")
            pda_line = Main.CursorLite.GetInt("pda_line")
            pda_table = Main.CursorLite.GetString("pda_table")
            pda_itemnum = Main.CursorLite.GetString("pda_itemnum")
            pda_quantity = Main.CursorLite.GetString("pda_quan")
            pda_cashierid = Main.CursorLite.GetString("pda_cashierid")
            pda_datetime = Main.CursorLite.GetString("pda_datetime")
            pda_priority = Main.CursorLite.GetString("pda_priority")
            pda_print = Main.CursorLite.GetString("pda_print")
            pda_costper = Main.CursorLite.GetDouble("pda_costper")
            pda_modifier = Main.CursorLite.GetString("pda_modifier")
            pda_priceper = Main.CursorLite.GetDouble("pda_priceper")
            pda_itemname = Main.CursorLite.GetString("pda_itemname")
            pda_taxrate = Main.CursorLite.GetDouble("pda_taxrate")
            pda_partysize = Main.CursorLite.GetInt("pda_partysize")
            pda_linedisc = Main.CursorLite.GetDouble("pda_linedisc")
            pda_origprice = Main.CursorLite.GetDouble("pda_origprice")
            pda_dontsend = Main.CursorLite.GetString("pda_dontsend")
            pda_invnotes1 = Main.CursorLite.GetString("pda_notes1")
            pda_invnotes2 = Main.CursorLite.GetString("pda_notes2")
            pda_invnotes3 = Main.CursorLite.GetString("pda_notes3")
            pda_seat = Main.CursorLite.GetString("pda_seat")
            pda_T_ID = Main.CursorLite.GetString("pda_T_ID")
            pda_itemnotes1 = Main.CursorLite.GetString("pda_itemnotes1")
            pda_itemnotes2 = Main.CursorLite.GetString("pda_itemnotes2")
            pda_itemnotes3 = Main.CursorLite.GetString("pda_itemnotes3")
            pda_PromoItemType = Main.CursorLite.GetString("pda_PromoItemType")
        
            If pda_invnotes1<>"" Or pda_invnotes2<>"" Or pda_invnotes3<>"" Then
                pda_invNotes="1"
            Else
                pda_invNotes="0"
            End If
        
            Dim cmd As DBCommand
            cmd.Initialize
            cmd.Name = "insert_PDA_Lines"
            cmd.Parameters = Array As Object(pda_StationID, 999999999, pda_line, pda_table, pda_itemnum, pda_quantity, pda_cashierid, pda_datetime, pda_priority, _
                                             "0", "0", pda_costper, pda_modifier, pda_priceper, pda_itemname.Replace("'", ""), pda_StoreID, pda_taxrate, pda_partysize, _
                                             pda_linedisc, pda_origprice, pda_dontsend, "0", pda_invNotes, pda_invnotes1.Replace("'", ""), pda_invnotes2.Replace("'", ""), _
                                             pda_invnotes3.Replace("'", ""), pda_seat, pda_T_ID, 2, pda_itemnotes1.Replace("'", ""), pda_itemnotes2.Replace("'", ""), pda_itemnotes3.Replace("'", ""), _
                                             pda_PromoItemType, Starter.serialNumber, 0)
            commands.Add(cmd)
        Next
        reqManager.ExecuteBatch(commands, Null)    
    End If
End Sub
Sub JobDone(Job As HttpJob)
   If Job.Success = False Then
     Log("Error: " & Job.ErrorMessage)
   Else
           Dim TextWriter1 As TextWriter
        If Main.LogOrders="Y" Then
            Main.CursorLite=Main.SQLite.ExecQuery("SELECT * FROM PDA_Lines WHERE pda_storeid='" & Main.StoreID & "' AND pda_station='" & Main.StationID & "' ORDER BY pda_ref, pda_line")
            TextWriter1.Initialize(File.OpenOutput(File.DirInternal, "orders.txt", True))
            previous_pda_T_ID=""
            For p= 0 To Main.CursorLite.RowCount - 1
                Main.CursorLite.Position=p
                pda_ref = Main.CursorLite.GetInt("pda_ref")
                pda_StoreID = Main.CursorLite.GetString("pda_storeid")
                pda_StationID = Main.CursorLite.GetString("pda_station")
                pda_line = Main.CursorLite.GetInt("pda_line")
                pda_table = Main.CursorLite.GetString("pda_table")
                pda_itemnum = Main.CursorLite.GetString("pda_itemnum")
                pda_quantity = Main.CursorLite.GetString("pda_quan")
                pda_cashierid = Main.CursorLite.GetString("pda_cashierid")
                pda_datetime = Main.CursorLite.GetString("pda_datetime")
                pda_priority = Main.CursorLite.GetString("pda_priority")
                pda_print = Main.CursorLite.GetString("pda_print")
                pda_costper = Main.CursorLite.GetDouble("pda_costper")
                pda_modifier = Main.CursorLite.GetString("pda_modifier")
                pda_priceper = Main.CursorLite.GetDouble("pda_priceper")
                pda_itemname = Main.CursorLite.GetString("pda_itemname")
                pda_taxrate = Main.CursorLite.GetDouble("pda_taxrate")
                pda_partysize = Main.CursorLite.GetInt("pda_partysize")
                pda_linedisc = Main.CursorLite.GetDouble("pda_linedisc")
                pda_origprice = Main.CursorLite.GetDouble("pda_origprice")
                pda_dontsend = Main.CursorLite.GetString("pda_dontsend")
                pda_invnotes1 = Main.CursorLite.GetString("pda_notes1")
                pda_invnotes2 = Main.CursorLite.GetString("pda_notes2")
                pda_invnotes3 = Main.CursorLite.GetString("pda_notes3")
                pda_seat = Main.CursorLite.GetString("pda_seat")
                pda_T_ID = Main.CursorLite.GetString("pda_T_ID")
                pda_itemnotes1 = Main.CursorLite.GetString("pda_itemnotes1")
                pda_itemnotes2 = Main.CursorLite.GetString("pda_itemnotes2")
                pda_itemnotes3 = Main.CursorLite.GetString("pda_itemnotes3")
                pda_PromoItemType = Main.CursorLite.GetString("pda_PromoItemType")
            
                If pda_invnotes1<>"" Or pda_invnotes2<>"" Or pda_invnotes3<>"" Then
                    pda_invNotes="1"
                Else
                    pda_invNotes="0"
                End If
            
                If previous_pda_T_ID="" Then
                    previous_pda_T_ID=pda_T_ID
                End If
                If previous_pda_T_ID<>pda_T_ID Then
                    TextWriter1.WriteLine("=================================================================================")        
                    previous_pda_T_ID=pda_T_ID                                
                End If
            
                TextWriter1.WriteLine(pda_table & "|" & pda_line & "|" & pda_itemnum & "|" & pda_itemname.Replace("'", "") & "|" & pda_quantity & "|" & pda_priceper & "|" & pda_priority & "|" & pda_modifier & "|" & _
                                     pda_dontsend & "|" & "0" & "|" & pda_invnotes1.Replace("'", "") & "|" & pda_invnotes2.Replace("'", "") & "|" & pda_invnotes3.Replace("'", "") & "|" & pda_seat & "|" & _
                                     pda_itemnotes1.Replace("'", "") & "|" & pda_itemnotes2.Replace("'", "") & "|" & pda_itemnotes3.Replace("'", "") & "|" & pda_PromoItemType)
            Next
            If Main.CursorLite.RowCount - 1 > 0 Then
                TextWriter1.WriteLine("=================================================================================")                            
                TextWriter1.Close
            End If
        End If
        Main.SQLite.ExecNonQuery("DELETE FROM PDA_Lines WHERE pda_storeid='" & Main.StoreID & "' AND pda_station='" & Main.StationID & "'")
   End If
   Job.Release
End Sub
 
Top