-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewController.swift
More file actions
138 lines (96 loc) · 4.08 KB
/
Copy pathViewController.swift
File metadata and controls
138 lines (96 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
//
// ViewController.swift
// DatabaseTest
//
// Created by Søren on 23/02/15.
// Copyright (c) 2015 Søren. All rights reserved.
//
import UIKit
class ViewController: UIViewController, UISearchBarDelegate, UISearchDisplayDelegate {
var passTest:String!
@IBOutlet weak var shortDefinition: UITextField!
@IBOutlet weak var textRes: UITextField!
@IBOutlet weak var inputField: UITextField!
@IBOutlet weak var labelNowCalled: UITextField!
@IBOutlet weak var nowCalled: UITextField!
@IBOutlet weak var desciption: UITextView!
@IBOutlet weak var alsoCalled: UITextField!
let db = SQLiteDB.sharedInstance();
override func viewDidLoad() {
super.viewDidLoad()
var inputString:String = passTest.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceCharacterSet())
let query = "select * from Forkortelser2 WHERE Begreb like ? "
let query2 = "select * from Forkortelser2 WHERE Fuldbetegnelse like ?"
let query3 = "select * from Forkortelser2 WHERE Beskrivelse like ?"
let data2 = db.query(query2,parameters:[inputString + "%"])
let data3 = db.query(query3,parameters:["%" + inputString + "%"])
let data = db.query(query,parameters:[inputString + "%"] )
// if data contains no result try the other query
if data.count == 0{
let data2 = db.query(query2,parameters:[inputString + "%"])
/* var alert = UIAlertController(title: "Vi fandt desværre ikke noget resultat", message: "Desværre ingen resultater på " + inputString, preferredStyle: UIAlertControllerStyle.Alert)
let defaultAction = UIAlertAction(title: "OK", style: .Default, handler: nil)
alert.addAction(defaultAction)
self.presentViewController(alert, animated: true, completion:nil)*/
self.textRes.text = "Desværre ingen resultater på " + inputString
// if data2 contains a sqlrow
if data2.count != 0{
// get all the values and display in the textfields
self.getValues(data2)
}
else if(data3.count != 0){
self.getValues(data3)
}
}
else{
self.getValues(data)
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func getValues(myObject:[SQLRow]){
let row = myObject[0]
if let name = row["Begreb"]{
self.shortDefinition.text = name.asString()
}
if let name = row["Fuldbetegnelse"]{
self.textRes.text = name.asString()
}
if let called = row["Ogsåkaldet"]{
let result:String = called.asString();
colorBackground(result, myTextField: self.alsoCalled)
//self.alsoCalled.text = called.asString()
}
if let beskrivelse = row["Beskrivelse"]{
self.desciption.text = beskrivelse.asString()
}
if let name = row["Nukaldet"]{
// if name is empty
if name.asString().isEmpty{
// remove present value
self.nowCalled.text = " "
// set the backgroundcolor to red
self.nowCalled.backgroundColor = UIColor.redColor();
}
else{
self.nowCalled.text = name.asString()
}
}
}
func anotherTest(){
}
func colorBackground(myString:String,myTextField:UITextField){
if myString.isEmpty{
myTextField.text = " "
myTextField.backgroundColor = UIColor.redColor()
}
else{
myTextField.text = myString
myTextField.backgroundColor = UIColor.whiteColor();
}
}
func test (){}
var hey:String!
}