' declaration
Private colChkBox As B4XTableColumn
Private tblDogodki as B4XTable
Private Sub InitGrid
tblDogodki.Clear
tblDogodki.AddColumn("ID", tblDogodki.COLUMN_TYPE_TEXT)
colChkBox = tblDogodki.AddColumn("Prip", tblDogodki.COLUMN_TYPE_NUMBERS)
tblDogodki.AddColumn("Datum", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.AddColumn("StrojID", tblDogodki.COLUMN_TYPE_NUMBERS)
tblDogodki.AddColumn("Stroj", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.AddColumn("OddelekID", tblDogodki.COLUMN_TYPE_NUMBERS)
tblDogodki.AddColumn("Oddelek", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.AddColumn("DobaviteljID", tblDogodki.COLUMN_TYPE_NUMBERS)
tblDogodki.AddColumn("Dobavitelj", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.AddColumn("Vzdrževalec", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.AddColumn("Telefon", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.AddColumn("Email", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.AddColumn("DogodekID", tblDogodki.COLUMN_TYPE_NUMBERS)
tblDogodki.AddColumn("Dogodek", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.AddColumn("Opis", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.AddColumn("Datum spremembe", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.AddColumn("Uporabnik", tblDogodki.COLUMN_TYPE_TEXT)
tblDogodki.RowHeight = 40dip
tblDogodki.EvenRowColor = xui.Color_RGB(169,192,201)
tblDogodki.OddRowColor = xui.Color_RGB(226,243,247)
tblDogodki.SearchVisible = True
tblDogodki.MaximumRowsPerPage = 10
tblDogodki.BuildLayoutsCache(tblDogodki.MaximumRowsPerPage)
tblDogodki.Refresh
' enable checkbox
For i = 1 To colChkBox.CellsLayouts.Size - 1
Dim parent As B4XView = colChkBox.CellsLayouts.Get(i)
Dim panel As B4XView = xui.CreatePanel("")
parent.AddView(panel, 0, 0, parent.Width, parent.Height)
panel.LoadLayout("CheckBox")
Next
End Sub
' FullfillGrid
Private Sub RefreshGrid(BaseStatus As Int)
' main query za prikaz
Query = $"select dDogIdent, (select case when count(*) > 0 then cast(1 as bit) else cast(0 as bit) end from dokLinkedObjects where dokLinkType = 'pgdogodki' and doklinkCode = dDogIdent) as priponke,
dDogDatum, dDogDobavitelj, sifSupplierName, dDogVzdrzevalec, dDogVzdrEmail, dDogVzdrTelefon, dDogStroj, SifMachineDescription,
dDogOddelek, SifOddelekDescription, dDogDogodek, sifVrDogDescription,
dDogOpis, dDogLinkDokument, dDogLinkPicture, dDogDatSpr, dDogLastUser, dDogIsDeleted
from dokDogodki inner join SifMachine on SifMachineID = dDogStroj
inner join SifOddelki on SifOddelekID = dDogOddelek
inner join sifVrsteDogodkov on sifVrDogID = dDogDogodek
inner join sifSuppliers on sifSupplierID = dDogDobavitelj
where isnull(dDogIsDeleted,0) = ${BaseStatus}
Order by dDogIdent desc"$
Dim rs As ResultSet = Main.MsSql.ExecQuery(Query)
Dim row As List
row.Initialize
Do While rs.NextRow
row.Add(Array(rs.GetInt("dDogIdent"),[B] rs.GetInt("priponke")[/B], rs.GetString("dDogDatum"), rs.GetInt("dDogStroj"), rs.GetString("SifMachineDescription"), rs.GetInt("dDogOddelek"), rs.GetString("SifOddelekDescription"), _
rs.GetInt("dDogDobavitelj"), rs.GetString("sifSupplierName"), rs.GetString("dDogVzdrzevalec"), rs.GetString("dDogVzdrTelefon"), rs.GetString("dDogVzdrEmail"), _
rs.GetInt("dDogDogodek"), rs.GetString("sifVrDogDescription"), rs.GetString("dDogOpis"), rs.GetString("dDogDatSpr"), rs.GetString("dDogLastUser") ))
Loop
rs.Close
tblDogodki.SetData(row)
tblDogodki.Refresh
End Sub
' Insert CHECKBOX for all records which has status = 1
' this is column1 (first column is col0)
Private Sub tblDogodki_DataUpdated
For i = 0 To tblDogodki.VisibleRowIds.Size - 1
Dim rowid As Long = tblDogodki.VisibleRowIds.Get(i)
Dim Item As Map = tblDogodki.GetRow(rowid)
Dim p As B4XView = colPriponke.CellsLayouts.Get(i + 1)
Dim p1 As B4XView = p.GetView(1)
Dim chk As B4XView = p1.GetView(0) 'first view is the label
chk.Visible = rowid > 0
chk.Tag = rowid
If Item.Size > 0 Then
If Item.Get("Prip").As(Int) = 1 Then chk.Checked = True Else chk.Checked = False
End If
Next
End Sub