Advertisement
Guest User

Untitled

a guest
Jul 18th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.15 KB | None | 0 0
  1. //
  2. // AllgemeinViewController.swift
  3. // PCMobile
  4. //
  5. // Created by SITF Pr on 7/3/18.
  6. // Copyright © 2018 SITF Pr. All rights reserved.
  7. //
  8.  
  9. import UIKit
  10. import Eureka
  11. import Alamofire
  12. import SwiftyJSON
  13.  
  14. class AllgemeinViewController: FormViewController {
  15.  
  16.  
  17. var bukrsString = "110"
  18.  
  19. var btnBUKRS:UIButton = UIButton(type: UIButtonType.infoLight)
  20. var btnPRCTR:UIButton = UIButton(type: UIButtonType.infoLight)
  21.  
  22. var currentCell: UITableViewCell!
  23.  
  24. var fieldType:PCOFieldType!
  25.  
  26. let localTablesURL = "http://212.4.68.34:50002/sitf/values/?url=http://sitfsed.sitf.local:8000/mobile/pco/loctables"
  27.  
  28. var prctrArray:[PRCTR] = [PRCTR]()
  29. var bukrsArray:[BUKRS] = [BUKRS]()
  30.  
  31. override func viewDidLoad() {
  32. super.viewDidLoad()
  33.  
  34. login(withUsername: "SHAXHIJA", andPassword: "sitfsw1ss")
  35.  
  36. form +++ Section("PROJEKT COCKPIT - PROJEKTDATEN BEARBEITEN")
  37.  
  38.  
  39. <<< TextRow() {
  40. $0.title = "Projekt ID"
  41. $0.tag = "txtProjectID"
  42. $0.placeholder = "SITF-Projekt Einz"
  43. var ruleSet = RuleSet<String>()
  44. ruleSet.add(rule: RuleRequired())
  45. $0.add(ruleSet: ruleSet)
  46. $0.validationOptions = .validatesOnChangeAfterBlurred
  47.  
  48. }
  49. <<< TextRow() {
  50. $0.title = "Projektbescheibung"
  51.  
  52. }
  53.  
  54. <<< TextAreaRow() {
  55. $0.placeholder = "Morbi leo risus, porta ac consectetur ac, vestibulum at eros. Fusce diapibus,tellus ac cursus commodo,tortor mauris condimentum"
  56. var ruleSet = RuleSet<String>()
  57. ruleSet.add(rule: RuleRequired())
  58. $0.add(ruleSet: ruleSet)
  59. $0.validationOptions = .validatesOnChangeAfterBlurred
  60. $0.tag = "notes"
  61. }
  62.  
  63. <<< TextRow() {
  64. $0.title = "PSP-Element"
  65. $0.placeholder = "2839599"
  66. $0.tag = "txtPSPElement"
  67. $0.baseCell.accessoryView = UIButton(type: UIButtonType.infoLight)
  68. var ruleSet = RuleSet<String>()
  69. ruleSet.add(rule: RuleRequired())
  70. $0.add(ruleSet: ruleSet)
  71. $0.validationOptions = .validatesOnChangeAfterBlurred
  72.  
  73. }
  74.  
  75. <<< TextRow() {
  76. $0.title = "Statusnr. Projekt"
  77. $0.placeholder = "00095948333"
  78. $0.tag = "txtStatusNr"
  79. $0.baseCell.accessoryView = UIButton(type: UIButtonType.infoLight)
  80.  
  81.  
  82. }
  83.  
  84.  
  85. +++ Section(){ section in
  86. section.footer =
  87. {
  88. var footer = HeaderFooterView<UIView>(.callback({
  89. let view = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 40))
  90. let label = UILabel(frame: CGRect(x: view.frame.minX, y: 0, width: view.frame.width-16, height: view.frame.height))
  91. label.text = "Giancarlo Bernardini"
  92. label.font = label.font.withSize(14)
  93. label.textColor = .gray
  94. label.textAlignment = .right
  95. view.addSubview(label)
  96. return view
  97. }))
  98. footer.height = { 45 }
  99. return footer
  100. }()
  101.  
  102. section.header = HeaderFooterView(title: "")
  103. }
  104.  
  105.  
  106.  
  107. <<< TextRow() {
  108. $0.title = "Verantwortlich Nr"
  109. $0.placeholder = "343882"
  110. $0.tag = "txtResponsibleNr"
  111. $0.baseCell.accessoryView = UIButton(type: UIButtonType.infoLight)
  112.  
  113. }
  114.  
  115. +++ Section(){ section in
  116. section.footer =
  117. {
  118. var footer = HeaderFooterView<UIView>(.callback({
  119. let view = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 40))
  120. let label = UILabel(frame: CGRect(x: view.frame.minX, y: 0, width: view.frame.width-16, height: view.frame.height))
  121. label.text = "Guisepe Panati"
  122. label.font = label.font.withSize(14)
  123. label.textColor = .gray
  124. label.textAlignment = .right
  125. view.addSubview(label)
  126. return view
  127. }))
  128. footer.height = { 55 }
  129. return footer
  130. }()
  131.  
  132. section.header = HeaderFooterView(title: "")
  133. }
  134.  
  135.  
  136.  
  137. <<< TextRow() {
  138. $0.title = "Kalkulator Nr"
  139. $0.placeholder = "767584"
  140. $0.tag = "txtCalculatorNr"
  141. // let btnSearch = UIButton(type: UIButtonType.infoLight)
  142. $0.baseCell.accessoryView = UIButton(type: UIButtonType.infoLight)
  143. }
  144.  
  145.  
  146. +++ Section("PROJEKT ADRESSE")
  147.  
  148. <<< TextRow() {
  149. $0.title = "Strasse"
  150.  
  151. }
  152.  
  153. <<< TextAreaRow("notes2") {
  154. $0.placeholder = "Lorzenparkstrasse 9"
  155. $0.tag = "txtStrasse"
  156. $0.textAreaHeight = .dynamic(initialTextViewHeight: 25)
  157.  
  158. }
  159.  
  160. <<< TextRow() {
  161. $0.title = "Postleitzahl"
  162. $0.placeholder = "8700"
  163. $0.tag = "txtPLZ"
  164.  
  165. }
  166. <<< TextRow() {
  167. $0.title = "Ort"
  168. $0.placeholder = "Cham"
  169. $0.tag = "txtOrt"
  170.  
  171. }
  172.  
  173. <<< TextRow() {
  174. $0.title = "Land"
  175. $0.placeholder = "Switzerland"
  176. $0.tag = "txtLand"
  177.  
  178. }
  179.  
  180.  
  181. <<< TextRow() {
  182. $0.title = "Region"
  183. $0.placeholder = "Zug"
  184. $0.tag = "txtRegion"
  185. }
  186.  
  187.  
  188.  
  189. +++ Section(){ section in
  190. section.footer =
  191. {
  192. var footer = HeaderFooterView<UIView>(.callback({
  193. let view = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 40))
  194. let label = UILabel(frame: CGRect(x: view.frame.minX, y: 0, width: view.frame.width-16, height: view.frame.height))
  195. label.text = "swiss IT-Factory CH AG"
  196. label.font = label.font.withSize(14)
  197. label.textColor = .gray
  198. label.textAlignment = .right
  199. view.addSubview(label)
  200. // view.backgroundColor = .red
  201. return view
  202. }))
  203. footer.height = { 40 }
  204. return footer
  205. }()
  206.  
  207. section.header = HeaderFooterView(title: "ORGANISATION")
  208. }
  209.  
  210.  
  211.  
  212. <<< LabelRow ("bukrsRow") {
  213.  
  214. LabelRow.defaultCellUpdate = { cell, row in cell.detailTextLabel?.textColor = .lightGray }
  215. currentCell = $0.cell
  216. $0.title = "Buchungskreiss"
  217.  
  218. $0.value = bukrsString
  219. $0.cell.accessoryView = btnBUKRS
  220. btnBUKRS.addTarget(self, action: #selector(bukrsPressed), for: .touchUpInside)
  221. }
  222.  
  223.  
  224.  
  225.  
  226. +++ Section() { section in
  227. section.footer =
  228. {
  229. var footer = HeaderFooterView<UIView>(.callback({
  230. let view = UIView(frame: CGRect(x: 0, y: 0, width: self.tableView.frame.width, height: 40))
  231. let label = UILabel(frame: CGRect(x: view.frame.minX, y: 0, width: view.frame.width-16, height: view.frame.height))
  232. label.text = "IBU ST.Gallen"
  233. label.font = label.font.withSize(14)
  234. label.textColor = .gray
  235. label.textAlignment = .right
  236. view.addSubview(label)
  237. return view
  238. }))
  239. footer.height = { 70 }
  240. return footer
  241. }()
  242.  
  243. section.header = HeaderFooterView(title: "")
  244. }
  245.  
  246.  
  247. <<< LabelRow ("prctrRow") {
  248.  
  249. LabelRow.defaultCellUpdate = { cell, row in cell.detailTextLabel?.textColor = .lightGray }
  250.  
  251. $0.title = "Profitcenter"
  252. $0.value = "1020"
  253. $0.cell.accessoryView = btnPRCTR
  254. btnPRCTR.addTarget(self, action: #selector(profitCenterPressed), for: .touchUpInside)
  255. }
  256.  
  257. }
  258.  
  259.  
  260. @objc func bukrsPressed() {
  261.  
  262. fieldType = .bukrs
  263. self.performSegue(withIdentifier: "segue", sender: nil)
  264. }
  265.  
  266.  
  267.  
  268.  
  269. @objc func profitCenterPressed() {
  270.  
  271. fieldType = .prctr
  272. self.performSegue(withIdentifier: "segue", sender: nil)
  273.  
  274.  
  275. //printoma vleren qe e ka bukrs-ja ne cell print(vleraBUKRS)
  276.  
  277. //
  278. // let textRow: TextAreaRow? = form.rowBy(tag: "notes")
  279. // let value = textRow?.value
  280. // print(value!)
  281.  
  282. // fieldType = .prctr
  283. // self.performSegue(withIdentifier: "segue", sender: nil)
  284. }
  285.  
  286.  
  287.  
  288. //MARK: Login
  289. func login(withUsername username: String, andPassword password: String) {
  290. // startLoading()
  291. let credentials: String! = "Basic \("\(username):\(password)".data(using: String.Encoding.utf8)?.base64EncodedString(options: Data.Base64EncodingOptions(rawValue: 0)) ?? "")"
  292.  
  293. //basic parameteres
  294. // let params = [
  295. // "email": username,
  296. // "password": password
  297. // ] as [String: Any]
  298.  
  299.  
  300. //prepare for sending in SAP
  301. // let project:PRCTR = PRCTR(object: Any.self)
  302. // project.pRCTR = "Gzim"
  303. // project.kTEXT = "21.02.2018"
  304. // project.kOKRS = "42"
  305. //
  306. // convert it to dictionary to be able to send in parameters (ALAMOFIRE)
  307. // let dictionary = project.dictionaryRepresentation()
  308.  
  309. //Base64 Authorization Header
  310. let loginHeaders = [
  311. "Authorization": "\(credentials!)"
  312. ]
  313.  
  314. Alamofire.request(localTablesURL, method: .get, parameters: [:], headers: loginHeaders).responseJSON { response in
  315. if response.response?.statusCode == 200 {
  316. do {
  317. let json = try JSON(data: response.data!) //SwiftJSON
  318. let localTablesBase = LOCALTABLESBase(json: json)
  319. // let localTables = localTablesBase.lOCALTABLES
  320.  
  321. if let arrayPRCTR = localTablesBase.lOCALTABLES?.pRCTR {
  322. self.prctrArray = arrayPRCTR
  323. }
  324.  
  325. if let arrayBUKRS = localTablesBase.lOCALTABLES?.bUKRS {
  326. self.bukrsArray = arrayBUKRS
  327. }
  328.  
  329. //here you reload table, stop loading or whatever you want to do with the data after received them
  330. self.tableView.reloadData()
  331. //stopLoading
  332.  
  333. } catch {
  334. print("diqka nuk o n'rregëll")
  335. }
  336. } else {
  337. print("error with code \(response.response?.statusCode ?? 0)")
  338. }
  339.  
  340. }
  341.  
  342. }
  343.  
  344. //MARK: - Prepare For Segue
  345.  
  346.  
  347. override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
  348.  
  349. if segue.identifier == "segue" {
  350. let vc:AllgemeinTblViewController = segue.destination as! AllgemeinTblViewController
  351. vc.delegate = self
  352. vc.fieldType = fieldType
  353. vc.prctrArray = prctrArray
  354. vc.bukrsArray = bukrsArray
  355. }
  356. }
  357.  
  358.  
  359. }
  360.  
  361.  
  362. //MARK: - Allgemein Table Delegate
  363. extension AllgemeinViewController: AllgemeinTableDelegate {
  364.  
  365. func getValue(value: String,description: String, forType type: PCOFieldType) {
  366. if type == .bukrs {
  367. if let myRow: LabelRow = form.rowBy(tag: "bukrsRow") {
  368. myRow.value = value
  369. myRow.reload()
  370.  
  371. }
  372. } else if type == .prctr {
  373. if let myRow: LabelRow = form.rowBy(tag: "prctrRow") {
  374. myRow.value = value.removeLeadingZeros()
  375. myRow.reload()
  376.  
  377. }
  378. } else {
  379. //status nr
  380. }
  381. }
  382. }
  383.  
  384. extension String {
  385. func removeLeadingZeros() -> String {
  386. var newString = self
  387. let prefix = "0"
  388. while newString.hasPrefix(prefix) {
  389. newString.remove(at: newString.startIndex)
  390. }
  391.  
  392. return newString
  393. }
  394. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement