private static void Connection_VersionUpgraded(AndroidDatabaseConnection connection, int oldVersion, int newVersion) { List<string> queries = new List<string>(); queries.Add("CREATE TABLE tasks (id INTEGER NOT NULL, name TEXT NOT NULL, description TEXT, date TEXT, PRIMARY KEY (id))"); queries.Add("CREATE TABLE tasks_relations (parent_id INTEGER NOT NULL, child_id INTEGER NOT NULL, PRIMARY KEY (parent_id, child_id))"); queries.Add("CREATE TABLE tags (id INTEGER NOT NULL, name TEXT NOT NULL, color TEXT, PRIMARY KEY (id))"); queries.Add("CREATE TABLE tasks_tags (task_id INTEGER NOT NULL, tag_id INTEGER NOT NULL, PRIMARY KEY (task_id, tag_id))"); queries.Add("CREATE TABLE attachements (task_id INTEGER NOT NULL, name TEXT NOT NULL, type_id TEXT NOT NULL, data BLOB, PRIMARY KEY (task_id, name))"); queries.Add("CREATE TABLE attachement_types (name TEXT NOT NULL, PRIMARY KEY (name))"); queries.Add("CREATE TABLE metadata (task_id INTEGER NOT NULL, key TEXT NOT NULL, value TEXT, PRIMARY KEY (task_id, key))"); foreach (string query in queries) { using (DbCommand command = connection.CreateCommand()) { command.CommandText = query; command.ExecuteNonQuery(); } } #if DEBUG TaskDatabase database = new TaskDatabase(connection); database.InsertDebugData(); #endif }
public static void Initialize(Context context) { if (initialized) return; initialized = true; // Connect to local database AndroidDatabaseConnection connection = new AndroidDatabaseConnection(context, "Tasks.db"); connection.VersionUpgraded += Connection_VersionUpgraded; connection.Open(); // Setup tasks database Database = new TaskDatabase(connection); }
public override bool OnOptionsItemSelected(IMenuItem item) { if (item.ItemId == Resource.Id.AddTaskMenuItem) { Intent intent = new Intent(this, typeof(TaskEditionActivity)); if (task != null) intent.PutExtra("Task.ParentId", task.Id); StartActivity(intent); } else if (item.ItemId == Resource.Id.EditTaskMenuItem) { Intent intent = new Intent(this, typeof(TaskEditionActivity)); intent.PutExtra("Task.Id", task.Id); StartActivity(intent); } else if (item.ItemId == Resource.Id.UploadMenuItem) { try { MySqlConnection connection = new MySqlConnection("Server=127.0.0.1;Database=julien_taskmanager;Uid=julien_taskmanag;Pwd=taskmanager"); connection.Open(); TaskDatabase database = new TaskDatabase(connection); database.Tasks.Clear(); database.Tasks.AddRange(App.Database.Tasks); database.Save(); Toast.MakeText(this, "Upload succeeded", ToastLength.Short).Show(); } catch { Toast.MakeText(this, "Upload failed", ToastLength.Short).Show(); } } else if (item.ItemId == Resource.Id.DownloadMenuItem) { try { MySqlConnection connection = new MySqlConnection("Server=127.0.0.1;Database=julien_taskmanager;Uid=julien_taskmanag;Pwd=taskmanager"); connection.Open(); TaskDatabase database = new TaskDatabase(connection); App.Database.Tasks.Clear(); App.Database.Tasks.AddRange(database.Tasks); App.Database.Save(); RefreshTasks(); Toast.MakeText(this, "Download succeeded", ToastLength.Short).Show(); } catch { Toast.MakeText(this, "Download failed", ToastLength.Short).Show(); } } return true; }