[Solved] Saving & Recalling A GridView from a file

Post

Posted
Rating:
#1 (In Topic #1318)
Enthusiast
AndyGable is in the usergroup ‘Enthusiast’
Hi Everyone,

I was just wondering if anyone know a smarter way to store a gridview to a text file and then recall it again

Basically what I need to do is sometimes I have to store a transaction on my Point of sale and I am using the following code

Code (gambas)

  1.                 For i As Integer = 1 To frmSalescreen.GridCurrentSale.rows.Count
  2.                                Dim ItemType As String = frmSalescreen.GridCurrentSale[i - 1, 7].Text
  3.                                 Dim Barcode As String = frmSalescreen.GridCurrentSale[i - 1, 4].Text
  4.                                Dim SaleMode As String = global.SaleMode
  5.                                Dim QtySold As Integer = frmSalescreen.GridCurrentSale[i - 1, 6].Text
  6.                          Dim PriceOverride As Integer = frmSalescreen.GridCurrentSale[i - 1, 8].Text
  7.                     Dim PriceOverridePrice As Integer = frmSalescreen.GridCurrentSale[i - 1, 9].Text
  8.                                Dim ToWorkOn As String = Replace(frmSalescreen.GridCurrentSale[i - 1, 1].Text, "£", "")
  9.                              Dim UnitPrice As Integer = (Val(ToWorkOn) * 100)
  10.                     CreateDataFiles.StoreSaleToNetwork(ItemType, Barcode, SaleMode, QtySold, PriceOverride, PriceOverridePrice, UnitPrice)
  11.                 Next

And this works great BUT if I have a discount on the item example

DVD SALES  £10.00
10% Disc       -£1.00


That is all stored inside the same row and when the above code read it is it errors out at Dim UnitPrice As Integer = (Val(ToWorkOn) * 100)

This is the code I am using to Create the GridView when my systems loads up

Code (gambas)

  1.     With frmSalescreen.GridCurrentSale
  2.             .Columns.Count = 11
  3.             .Columns[0].Width = 550     'Description
  4.             .Columns[1].Width = 125     'Price
  5.             .Columns[2].Width = 25      'Discount Exampt
  6.             .Columns[3].Width = 30      'VAT Code
  7.             .Columns[4].Width = 0       'Barcode Number
  8.             .Columns[5].Width = 0       'Healthy Start Voucher Ok
  9.             .Columns[6].Width = 0       'Qty Sold
  10.             .Columns[7].Width = 0       'Item Type
  11.             .Columns[8].Width = 0       'PriceOverride
  12.             .Columns[9].Width = 0       'PriceOverridePrice
  13.            .Columns[10].Width = 0       'GT Message Needs to be printed (this is the GT number)
  14.            
  15.  
  16.             .Columns[0].Alignment = Align.BottomLeft    'Desciption
  17.             .Columns[1].Alignment = Align.Right             'Price
  18.             .Columns[2].Alignment = Align.BottomLeft    'Discout exempt
  19.             .Columns[3].Alignment = Align.BottomRight   'VAT
  20.  
  21.             .Columns[4].Alignment = Align.BottomLeft    'Barcode Number
  22.             .Columns[5].Alignment = Align.BottomLeft    'Healthy Start Voucher
  23.             .Columns[6].Alignment = Align.BottomLeft    'Item Qty
  24.             .Rows.Count = 0
  25.         End With

The columns that are 0 width are used by my system in other areas when the sale is completed so i would need to store the completed grid (and ideal if I update the grid in the future to hold other triggers to have them store as well)

The way I am loading the files back into the system at the moment is as below

Code (gambas)

  1. Private Sub LoadStoredSale(FileName As String)
  2. 'used on the Weston Uniton recall
  3.     Dim SendAmt As String = Null
  4.     Dim SentFee As String = Null
  5.  
  6.     Dim ItemType As String = Null
  7.     Dim BarcodeNumber As String = Null
  8.     Dim ItemMode As String = Null
  9.     Dim ItemCount As Integer = 0
  10.     Dim SalePrice As Integer = 0
  11.     Dim PriceOverride As Integer = 0
  12.     Dim PriceOverRideValue As Integer = 0
  13.     Dim UnitPrice As Integer = 0
  14.  
  15.     'item type
  16.     'IT For item
  17.     'DE For department
  18.     'ES For Electric service
  19.     'WE For Weston Union
  20.     'HE For Health Lottery
  21.     'PO For Payout (Description would be used for the payout)
  22.     'LO For Lottery
  23.    
  24.  
  25.     '1,I,50201600,Sale,1,65,0,0042
  26.  
  27.       Dim LineData As String = Null
  28.  
  29.     If Exist(FileName) = True Then
  30.         Global.RecalledSaleFile = Open FileName For Input
  31.             While Not Eof(Global.RecalledSaleFile)
  32.                 Line Input #Global.RecalledSaleFile, LineData
  33.  
  34.                       Global.LineMessages = Split(Linedata, "|")
  35.                           ItemType = Global.LineMessages[0]
  36.                      BarcodeNumber = Global.LineMessages[1]
  37.                           ItemMode = Global.LineMessages[2]
  38.                          ItemCount = Global.LineMessages[3]
  39.                      PriceOverride = Global.LineMessages[4]
  40.                 PriceOverRideValue = Global.LineMessages[5]
  41.                          UnitPrice = Global.LineMessages[6]
  42.  
  43.                 Select Case ItemType
  44.                     Case "Job"
  45.                         Global.JobNumber = BarcodeNumber
  46.                         frmbackground.btnEnterJobNumber.Caption = "Job Number " & global.JobNumber
  47.  
  48.                     Case "Item" 'I For item
  49.                         global.SaleMode = ItemMode
  50.                         global.ItemQty = ItemCount
  51.                         If PriceOverride = 1 Then global.PriceOverRideValue = PriceOverRideValue
  52.                         Global.AgeValueLastUsed = 1
  53.                         DatabaseModule.SellProduct(BarcodeNumber, "Recall")
  54.                    
  55.                     Case "ManualDept" 'D For department
  56.                         global.SaleMode = ItemMode
  57.                         global.ItemQty = ItemCount
  58.                         BarcodeNumber = Replace(BarcodeNumber, "Department_", "")
  59.  
  60.                         If ItemCount = 1 Then
  61.                             SalePrice = UnitPrice
  62.                         Else
  63.                             SalePrice = (UnitPrice / ItemCount)
  64.                         End If
  65.                         DepartmentModule.ProcessManualSale(BarcodeNumber, DepartmentModule.GetDeptName(Format(Val(BarcodeNumber), "0000")), SalePrice, DepartmentModule.GetDeptVAT(Format(Val(BarcodeNumber), "0000")))
  66.  
  67.                     Case "ES" 'E For Electric service
  68.                         Select Case BarcodeNumber
  69.                             Case "ELEC"
  70.                                 ElectronicServices.ElectricKeyProcess(SalePrice, "Recall", Global.AddOnServericeVAT)
  71.                                
  72.                             Case "GASP"
  73.                                 ElectronicServices.GasKeyProcess(SalePrice, "Recall", Global.AddOnServericeVAT)
  74.                                    
  75.                             Case "MTUP"
  76.                                 ElectronicServices.MobileTopUpProcess(SalePrice, "Recall", Global.AddOnServericeVAT)
  77.                                        
  78.                             Case "Bill"
  79.                                 ElectronicServices.BillPaymentProcess(SalePrice, "Recall", Global.AddOnServericeVAT)
  80.                         End Select
  81.                    
  82.                     Case "WE" 'W For Weston Union
  83.                         Select Case BarcodeNumber
  84.                             Case "SEND_AMT", "SEND_Amt"
  85.                                 SendAmt = SalePrice
  86.                            
  87.                             Case "SEND_FEE", "SEND_fee"
  88.                                 SentFee = SalePrice
  89.                         End Select
  90.                        
  91.                         If SendAmt <> "" And SentFee <> "" Then
  92.                             WestonUnionModule.SendVaulesToSalescreen(SendAmt, SentFee, "Recall", global.WestonUnionVAT)
  93.                         End If
  94.                        
  95.                     Case "HE" 'H For Health Lottery
  96.                         ElectronicServices.HealthLotteryProcess(ItemCount, "Recall", Global.AddOnServericeVAT)
  97.                    
  98.                     Case "PO" 'P For Payout (Description would be used for the payout)
  99.                        
  100.                     Case "LO" 'L For Lottery                    
  101.                         DatabaseModule.SellProduct(BarcodeNumber, "Recall")
  102.                 End Select
  103.             Wend
  104.         Global.RecalledSaleFile.Close
  105.         Kill FileName
  106.  
  107.         frmRecallFromNetwork.Close
  108.         Menu_Salescreen.SaleScreenMenu
  109.         frmSalescreen.Enabled = True
  110.         frmSalescreen.SetFocus
  111.     End If

I am sure someone smarter them me would have a idea how I could streamline this process or even a way I can just store the discount so it would work as well when recalled (as that is the major problem as I can not tell a customer they can not store a sale if it is any discount applied to any items)

I am 100% open to ideas and way to store this data as the best I have come up with still is not working 100%

Kind regards to everyone
Andy
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Guru
cogier is in the usergroup ‘Guru’
I'm a fan of CSV files for storing data. I have created a basic program that will load a CSV file with shop type details in it and display the items in a GridView.
Hopefully it will give you some ideas.

<IMG src="https://www.cogier.com/gambas/Shopdata.png"> </IMG>

Attachment
Online now: Yes Back to the top
1 guest and 0 members have just viewed this.