public CategoryDataWindow(Category category) { InitializeComponent(); this.editedCategory = category; this.NameCategory = category.Name; }
/// <summary> /// Add a category to the list /// </summary> /// <param name="id">ID of the category</param> /// <param name="name">Name of the category</param> /// <returns>New category inserted</returns> public Category AddToList(int id, string name) { Category category = new Category(id, name); this.categoryList.Add(category); return category; }
/// <summary> /// Delete a category from the list and database /// </summary> /// <param name="category">Category object to delete</param> public void Delete(Category category) { // Database connexion SQLiteDatabase db = SQLiteDatabase.getInstance(Settings.SQLITE_DATABASE); try { List<SQLiteParameter> parameterList = new List<SQLiteParameter>(); parameterList.Add(new SQLiteParameter("@id_category", category.Id)); db.Delete("subscription", "id_category = @id_category", parameterList); db.Delete("category", "id_category = @id_category", parameterList); } catch (Exception e) { MessageBox.Show(e.Message); } // Remove from the list this.categoryList.Remove(category); }
/// <summary> /// Update a category from database /// </summary> /// <param name="category">Category object already edited</param> public void Update(Category category) { // Database connexion SQLiteDatabase db = SQLiteDatabase.getInstance(Settings.SQLITE_DATABASE); // Dictionary with column->value Dictionary<String, String> data = new Dictionary<String, String>(); data.Add("name_category", category.Name); try { List<SQLiteParameter> parameterList = new List<SQLiteParameter>(); parameterList.Add(new SQLiteParameter("@id_category", category.Id)); db.Update("category", data, "category.id_category = @id_category", parameterList); } catch (Exception e) { MessageBox.Show(e.Message); } }
public SubscriptionManager(Category parentCategory) { this.parentCategory = parentCategory; this.subscriptionList = new List<Subscription>(); }