commit 10/10/2025
Broadcast Zones and Sound Channels
This commit is contained in:
@@ -995,7 +995,7 @@ class MariaDB(
|
||||
override fun Add(data: BroadcastZones): Boolean {
|
||||
try {
|
||||
val statement =
|
||||
connection.prepareStatement("INSERT INTO ${super.dbName} (description, SoundChannel, Box, Relay) VALUES (?, ?, ?, ?)")
|
||||
connection.prepareStatement("INSERT INTO ${super.dbName} (description, SoundChannel, id, bp) VALUES (?, ?, ?, ?)")
|
||||
statement?.setString(1, data.description)
|
||||
statement?.setString(2, data.SoundChannel)
|
||||
statement?.setString(3, data.id)
|
||||
@@ -1017,7 +1017,7 @@ class MariaDB(
|
||||
try {
|
||||
connection.autoCommit = false
|
||||
val sql =
|
||||
"INSERT INTO ${super.dbName} (description, SoundChannel, Box, Relay) VALUES (?, ?, ?, ?)"
|
||||
"INSERT INTO ${super.dbName} (description, SoundChannel, id, bp) VALUES (?, ?, ?, ?)"
|
||||
val statement = connection.prepareStatement(sql)
|
||||
for (bz in data) {
|
||||
statement.setString(1, bz.description)
|
||||
@@ -1040,7 +1040,7 @@ class MariaDB(
|
||||
override fun UpdateByIndex(index: Int, data: BroadcastZones): Boolean {
|
||||
try {
|
||||
val statement =
|
||||
connection.prepareStatement("UPDATE ${super.dbName} SET description = ?, SoundChannel = ?, Box = ?, Relay = ? WHERE `index` = ?")
|
||||
connection.prepareStatement("UPDATE ${super.dbName} SET description = ?, SoundChannel = ?, id = ?, bp = ? WHERE `index` = ?")
|
||||
statement?.setString(1, data.description)
|
||||
statement?.setString(2, data.SoundChannel)
|
||||
statement?.setString(3, data.id)
|
||||
@@ -1066,9 +1066,9 @@ class MariaDB(
|
||||
// use a temporary table to reorder the index
|
||||
statement?.executeUpdate("CREATE TABLE IF NOT EXISTS $tempdb_name LIKE ${super.dbName}")
|
||||
statement?.executeUpdate("TRUNCATE TABLE $tempdb_name")
|
||||
statement?.executeUpdate("INSERT INTO $tempdb_name (description, SoundChannel, Box, Relay) SELECT description, SoundChannel, Box, Relay FROM ${super.dbName} ORDER BY description ")
|
||||
statement?.executeUpdate("INSERT INTO $tempdb_name (description, SoundChannel, id, bp) SELECT description, SoundChannel, id, bp FROM ${super.dbName} ORDER BY description ")
|
||||
statement?.executeUpdate("TRUNCATE TABLE ${super.dbName}")
|
||||
statement?.executeUpdate("INSERT INTO ${super.dbName} (description, SoundChannel, Box, Relay) SELECT description, SoundChannel, Box, Relay FROM $tempdb_name")
|
||||
statement?.executeUpdate("INSERT INTO ${super.dbName} (description, SoundChannel, id, bp) SELECT description, SoundChannel, id, bp FROM $tempdb_name")
|
||||
statement?.executeUpdate("DROP TABLE $tempdb_name")
|
||||
Logger.info("${super.dbName} table resorted by description" as Any)
|
||||
// reload the local list
|
||||
@@ -1085,7 +1085,7 @@ class MariaDB(
|
||||
val sheet = workbook.getSheet("BroadcastZones")
|
||||
?: throw Exception("No sheet named 'BroadcastZones' found")
|
||||
val headerRow = sheet.getRow(0) ?: throw Exception("No header row found")
|
||||
val headers = arrayOf("Index", "description", "SoundChannel", "Box", "Relay")
|
||||
val headers = arrayOf("Index", "description", "SoundChannel", "id", "bp")
|
||||
for ((colIndex, header) in headers.withIndex()) {
|
||||
val cell = headerRow.getCell(colIndex) ?: throw Exception("Header '$header' not found")
|
||||
if (cell.stringCellValue != header) throw Exception("Header '$header' not found")
|
||||
@@ -1098,9 +1098,9 @@ class MariaDB(
|
||||
val row = sheet.getRow(rowIndex) ?: continue
|
||||
val description = row.getCell(1)?.stringCellValue ?: continue
|
||||
val soundChannel = row.getCell(2)?.stringCellValue ?: continue
|
||||
val box = row.getCell(3)?.stringCellValue ?: continue
|
||||
val relay = row.getCell(4)?.stringCellValue ?: continue
|
||||
val broadcastZone = BroadcastZones(0u, description, soundChannel, box, relay)
|
||||
val id = row.getCell(3)?.stringCellValue ?: continue
|
||||
val bp = row.getCell(4)?.stringCellValue ?: continue
|
||||
val broadcastZone = BroadcastZones(0u, description, soundChannel, id, bp)
|
||||
_broadcastZonesList.add(broadcastZone)
|
||||
}
|
||||
return AddAll(_broadcastZonesList)
|
||||
@@ -1117,7 +1117,7 @@ class MariaDB(
|
||||
val workbook = XSSFWorkbook()
|
||||
val sheet = workbook.createSheet("BroadcastZones")
|
||||
val headerRow = sheet.createRow(0)
|
||||
val headers = arrayOf("Index", "description", "SoundChannel", "Box", "Relay")
|
||||
val headers = arrayOf("Index", "description", "SoundChannel", "id", "bp")
|
||||
for ((colIndex, header) in headers.withIndex()) {
|
||||
val cell = headerRow.createCell(colIndex)
|
||||
cell.setCellValue(header)
|
||||
@@ -1128,8 +1128,8 @@ class MariaDB(
|
||||
row.createCell(0).setCellValue(resultSet.getString("index"))
|
||||
row.createCell(1).setCellValue(resultSet.getString("description"))
|
||||
row.createCell(2).setCellValue(resultSet.getString("SoundChannel"))
|
||||
row.createCell(3).setCellValue(resultSet.getString("Box"))
|
||||
row.createCell(4).setCellValue(resultSet.getString("Relay"))
|
||||
row.createCell(3).setCellValue(resultSet.getString("id"))
|
||||
row.createCell(4).setCellValue(resultSet.getString("bp"))
|
||||
}
|
||||
for (i in headers.indices) {
|
||||
sheet.autoSizeColumn(i)
|
||||
@@ -2361,6 +2361,17 @@ class MariaDB(
|
||||
.sorted()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all distinct sound channel from soundchannelDB
|
||||
* @return a list of distinct sound channel sorted alphabetically
|
||||
*/
|
||||
fun Get_SoundChannel_List(): List<String> {
|
||||
return soundchannelDB.List
|
||||
.distinctBy { it.channel }
|
||||
.map { it.channel }
|
||||
.sorted()
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if a username already exists in the userDB (case-insensitive)
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user