forked from arlm/StoryboardTables
/
cryptViewList.cs
205 lines (162 loc) · 5.96 KB
/
cryptViewList.cs
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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
using System;
using System.Drawing;
using System.Collections.Generic;
using MonoTouch.Foundation;
using MonoTouch.UIKit;
using System.Net;
using System.Linq;
using System.Xml.Linq;
using System.IO;
using Mono.Data.Sqlcipher;
namespace StoryboardTables
{
public partial class cryptViewList : UITableViewController
{
List<TaskX> tasks;
public string namex;
public string notesx;
public string SubeVerisi { get; set;}
public async void Yukle()
{
tasks = new List<TaskX>
{
new TaskX() {Name= namex, Notes=notesx, Done=false},
new TaskX() {Name="Devices", Notes="Buy Nexus, Galaxy, Droid", Done=false}
};
TableView.Source = new RootTableSource(tasks.ToArray ());
}
public cryptViewList (IntPtr handle) : base (handle)
{
}
public override void PrepareForSegue (UIStoryboardSegue segue, NSObject sender)
{
if (segue.Identifier == "subeVerileriGonder") { // set in Storyboard
var navctlr = segue.DestinationViewController as SubeVerileriTaskControllerList;
if (navctlr != null) {
var row = TableView.IndexPathForSelectedRow;
var source = TableView.Source as RootTableSource;
var item = source.GetItem(row.Row);
navctlr.CryptedSetTask(this, item);
}
}
}
public void CreateTask () {
var newId = tasks[tasks.Count - 1].Id + 1;
var newTask = new TaskX(){Id=newId};
tasks.Add (newTask);
var detail = Storyboard.InstantiateViewController("subedetail") as SubeVerileriTaskControllerList;
detail.CryptedSetTask (this, newTask);
NavigationController.PushViewController (detail, true);
}
public void SaveTask (TaskX task) {
Console.WriteLine("Save "+task.Name);
var oldTask = tasks.Find(t => t.Id == task.Id);
oldTask = task;
NavigationController.PopViewControllerAnimated(true);
}
public void DeleteTask (TaskX task) {
Console.WriteLine("Delete "+task.Name);
var oldTask = tasks.Find(t => t.Id == task.Id);
tasks.Remove (oldTask);
NavigationController.PopViewControllerAnimated(true);
}
public override bool ShouldAutorotateToInterfaceOrientation (UIInterfaceOrientation toInterfaceOrientation)
{
// Return true for supported orientations
return (toInterfaceOrientation != UIInterfaceOrientation.PortraitUpsideDown);
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Yukle();
if (SubeVerisi != null)
this.Title = SubeVerisi;
else
this.Title = "Crypted";
AddButton.Clicked += (sender, e) => {
CreateTask ();
};
//Non Crypted Data
// string SQLitePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "MyDBXS.db3"); // "IDBDBXZ.db3");
// Crypted Data
string SQLitePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "cryptedDb.db3");
SqList(SQLitePath,SubeVerisi);
}
public override void ViewDidUnload ()
{
base.ViewDidUnload ();
}
public void SqList(string databaseFile,string opinion)
{
try
{
if (!File.Exists (databaseFile))
{
return;
}
//end if
// Connect to database
using (SqliteConnection sqlCon = new SqliteConnection (String.Format ("Data Source = {0}", databaseFile)))
{
sqlCon.SetPassword("haluk");
sqlCon.Open ();
using (SqliteCommand sqlCom = new SqliteCommand (sqlCon))
{
sqlCom.CommandText="SELECT * FROM Personel";
// if(opinion=="Z")
// sqlCom.CommandText = "SELECT * FROM ZSUBE";
//
// else if(opinion=="Y")
// sqlCom.CommandText = "SELECT * FROM YSUBE";
//
// Execute the SELECT statement and retrieve the data
using (SqliteDataReader dbReader = sqlCom.ExecuteReader ())
{
if (dbReader.HasRows)
{
int i;
// Advance through each row
tasks = new List<TaskX> ();
while (dbReader.Read ())
{
TaskX dtask= new TaskX() {Id = Convert.ToInt16( dbReader["ID"]),
Name = String.Format (Convert.ToString (dbReader["UserName"])),
Notes=String.Format ( Convert.ToString (dbReader["Password"])),
Done=false};
tasks.Add(dtask);
};
}
};
TableView.Source = new RootTableSource(tasks.ToArray ());
}
sqlCon.Close ();
}
} catch (Exception ex)
{ }
}
public override void ViewWillAppear (bool animated)
{
base.ViewWillAppear (animated);
if(tasks!=null)
TableView.Source = new RootTableSource(tasks.ToArray ());
}
public override void ViewDidAppear (bool animated)
{
base.ViewDidAppear (animated);
}
public override void ViewWillDisappear (bool animated)
{
base.ViewWillDisappear (animated);
}
public override void ViewDidDisappear (bool animated)
{
base.ViewDidDisappear (animated);
}
}
}