public CategoryDialog(Helpers.Data.Objects.Settings AppSettings, TranslationsHelpers translator, Category editCat) { InitializeComponent(); _translator = translator; _AppSettings = AppSettings; this.Text = _translator.GetTranslatedMessage(_AppSettings.Language, 36, "Edit Category"); _translator.TranslateUI(_AppSettings.Language, this.Name, this.Controls); PopulateForm(editCat); }
public Category GetCategory(int categoryID) { Category result = null; if (_Connection.State != System.Data.ConnectionState.Open) //I raise an error as there is no connection to the database throw new Exception("There is no connection to the database"); String sql = string.Format("SELECT id, name, icon, expanded " + "FROM Categories C " + "WHERE id = {0};",categoryID); SQLiteCommand command = new SQLiteCommand(sql, _Connection); SQLiteDataReader reader = command.ExecuteReader(); if (reader.HasRows) { reader.Read(); int itemID = -1; if (reader["id"] != DBNull.Value) itemID = reader.GetInt32(0); string itemName = string.Empty; if (reader["name"] != DBNull.Value) itemName = reader.GetString(1); string itemIcon = string.Empty; if (reader["icon"] != DBNull.Value) itemIcon = reader.GetString(2); bool itemExpanded = false; if (reader["expanded"] != DBNull.Value) itemExpanded = reader.GetBoolean(3); bool itemSelected = (itemExpanded) ? true : false; result = new Category(itemID, itemName, itemIcon, itemExpanded, itemSelected); } return result; }
private void PopulateForm(Category editCat) { txtIcon.Text = editCat.Icon; txtName.Text = editCat.Name; }