public void RefreshCategories() { Gtk.TreeIter iter; SqliteCategory newCategory; bool hasValues = false; string command = "SELECT id FROM Categories"; SqliteCommand cmd = db.Connection.CreateCommand(); cmd.CommandText = command; SqliteDataReader dataReader = cmd.ExecuteReader(); while (dataReader.Read()) { int id = dataReader.GetInt32(0); hasValues = true; newCategory = new SqliteCategory(this, id); if ((defaultCategory == null) || (newCategory.Name.CompareTo("Work") == 0)) { defaultCategory = newCategory; } iter = categoryListStore.Append(); categoryListStore.SetValue(iter, 0, newCategory); } dataReader.Close(); cmd.Dispose(); if (!hasValues) { defaultCategory = newCategory = new SqliteCategory(this, "Work"); iter = categoryListStore.Append(); categoryListStore.SetValue(iter, 0, newCategory); newCategory = new SqliteCategory(this, "Personal"); iter = categoryListStore.Append(); categoryListStore.SetValue(iter, 0, newCategory); newCategory = new SqliteCategory(this, "Family"); iter = categoryListStore.Append(); categoryListStore.SetValue(iter, 0, newCategory); newCategory = new SqliteCategory(this, "Project"); iter = categoryListStore.Append(); categoryListStore.SetValue(iter, 0, newCategory); } }
public void RefreshCategories() { SqliteCategory newCategory; var hasValues = false; var command = "SELECT Name FROM Categories"; var cmd = Database.Connection.CreateCommand (); cmd.CommandText = command; var dataReader = cmd.ExecuteReader (); var isFirstEntry = true; while (dataReader.Read()) { var name = dataReader.GetString (0); hasValues = true; newCategory = new SqliteCategory (name); if (isFirstEntry) { defaultCategory = newCategory; isFirstEntry = false; } Categories.Add (newCategory); } dataReader.Close (); cmd.Dispose (); if (!hasValues) { newCategory = new SqliteCategory (this, Catalog.GetString ("Work")); Categories.Add (newCategory); defaultCategory = newCategory; newCategory = new SqliteCategory (this, Catalog.GetString ("Personal")); Categories.Add (newCategory); newCategory = new SqliteCategory (this, Catalog.GetString ("Family")); Categories.Add (newCategory); newCategory = new SqliteCategory (this, Catalog.GetString ("Project")); Categories.Add (newCategory); } }
public void RefreshCategories() { Gtk.TreeIter iter; SqliteCategory newCategory; bool hasValues = false; string command = "SELECT id FROM Categories"; SqliteCommand cmd = db.Connection.CreateCommand(); cmd.CommandText = command; SqliteDataReader dataReader = cmd.ExecuteReader(); while(dataReader.Read()) { int id = dataReader.GetInt32(0); hasValues = true; newCategory = new SqliteCategory (this, id); if( (defaultCategory == null) || (newCategory.Name.CompareTo("Work") == 0) ) defaultCategory = newCategory; iter = categoryListStore.Append (); categoryListStore.SetValue (iter, 0, newCategory); } dataReader.Close(); cmd.Dispose(); if(!hasValues) { defaultCategory = newCategory = new SqliteCategory (this, "Work"); iter = categoryListStore.Append (); categoryListStore.SetValue (iter, 0, newCategory); newCategory = new SqliteCategory (this, "Personal"); iter = categoryListStore.Append (); categoryListStore.SetValue (iter, 0, newCategory); newCategory = new SqliteCategory (this, "Family"); iter = categoryListStore.Append (); categoryListStore.SetValue (iter, 0, newCategory); newCategory = new SqliteCategory (this, "Project"); iter = categoryListStore.Append (); categoryListStore.SetValue (iter, 0, newCategory); } }