CategoryCC.swift 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // CategoryCC.swift
  3. // NexilisLite
  4. //
  5. // Created by Qindi on 20/06/22.
  6. //
  7. import Foundation
  8. public class CategoryCC: Model {
  9. public var id: String
  10. public var service_id: String
  11. public var service_name: String
  12. public var parent: String
  13. public var description: String
  14. public var is_tablet: String
  15. public var isActive: Bool
  16. public static var default_parent = "-99"
  17. public init(id: String, service_id: String, service_name: String,parent: String, description: String, is_tablet: String, isActive:Bool = false) {
  18. self.id = id
  19. self.service_id = service_id
  20. self.service_name = service_name
  21. self.parent = parent
  22. self.description = description
  23. self.is_tablet = is_tablet
  24. self.isActive = isActive
  25. }
  26. public static func == (lhs: CategoryCC, rhs: CategoryCC) -> Bool {
  27. return lhs.service_id == rhs.service_id
  28. }
  29. public static func getDatafromParent(parent: String) -> [CategoryCC] {
  30. var data: [CategoryCC] = []
  31. Database.shared.database?.inTransaction({ fmdb, rollback in
  32. do {
  33. if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select id, service_id, service_name, description, parent, is_tablet from SERVICE_BANK where parent = '\(parent)'") {
  34. while cursor.next() {
  35. data.append(CategoryCC(id: cursor.string(forColumnIndex: 0) ?? "",
  36. service_id: cursor.string(forColumnIndex: 1) ?? "",
  37. service_name: cursor.string(forColumnIndex: 2) ?? "",
  38. parent: cursor.string(forColumnIndex: 4) ?? "",
  39. description: cursor.string(forColumnIndex: 3) ?? "",
  40. is_tablet: cursor.string(forColumnIndex: 5) ?? ""))
  41. }
  42. cursor.close()
  43. }
  44. } catch {
  45. rollback.pointee = true
  46. print("Access database error: \(error.localizedDescription)")
  47. }
  48. })
  49. return data
  50. }
  51. public static func getDataFromServiceId(service_id: String) -> CategoryCC? {
  52. var data: CategoryCC?
  53. Database.shared.database?.inTransaction({ fmdb, rollback in
  54. do {
  55. if let cursor = Database.shared.getRecords(fmdb: fmdb, query: "select id, service_id, service_name, description, parent, is_tablet from SERVICE_BANK where service_id = '\(service_id)'"), cursor.next() {
  56. data = CategoryCC(id: cursor.string(forColumnIndex: 0) ?? "",
  57. service_id: cursor.string(forColumnIndex: 1) ?? "",
  58. service_name: cursor.string(forColumnIndex: 2) ?? "",
  59. parent: cursor.string(forColumnIndex: 4) ?? "",
  60. description: cursor.string(forColumnIndex: 3) ?? "",
  61. is_tablet: cursor.string(forColumnIndex: 5) ?? "")
  62. cursor.close()
  63. }
  64. } catch {
  65. rollback.pointee = true
  66. print("Access database error: \(error.localizedDescription)")
  67. }
  68. })
  69. return data
  70. }
  71. }