protected void btnSave_Click(object sender, EventArgs e) { if (!HasWriteAccess) return; if (txtName.Text.Trim().Length == 0) { MessageBox.Show(Lang.TransA("Please enter category name!"), Misc.MessageType.Error); return; } Category category = null; if (EditedCategory == null) { category = new Category(); } else { category = EditedCategory; } category.Name = txtName.Text.Trim(); category.UsersCanCreateGroups = cbUsersCanCreateGroups.Checked; category.Save(); populateDataGrid(); mvCategories.SetActiveView(viewCategories); }
/// <summary> /// Fetches all categories from DB by group ID. /// If there are no categories in DB for specified group ID it returns an empty array. /// </summary> /// <param name="groupID">The group ID.</param> /// <returns>Category array or an emptry array if there are no categories in DB for specified group ID.</returns> public static Category[] FetchCategoriesByGroup(int groupID) { using (SqlConnection conn = Config.DB.Open()) { SqlDataReader reader = (SqlDataReader) SqlHelper.GetDB().ExecuteReader( "FetchCategoriesByGroup", groupID); List<Category> categories = new List<Category>(); while (reader.Read()) { Category category = new Category(); category.id = (int)reader["ID"]; category.name = (string)reader["Name"]; category.order = (int)reader["Order"]; category.usersCanCreateGroups = (bool)reader["UsersCanCreateGroups"]; categories.Add(category); } return categories.ToArray(); } }
/// <summary> /// Fetches categories by specified id, name or order. /// It returns an empty array if there are no categories in DB by specified arguments. /// If these arguments are null it returns all categories from DB. /// </summary> /// <param name="id">The id.</param> /// <param name="name">The name.</param> /// <param name="order">The order.</param> /// <returns>An array with categories or an empty array if no categories are found in DB.</returns> private static Category[] Fetch(int? id, string name, int? order) { //using (var conn = Config.DB.Open()) { List<Category> categories = new List<Category>(); using (var reader = SqlHelper.GetDB().ExecuteReader("FetchCategories", id, name, order)) { while (reader.Read()) { Category category = new Category(); category.id = (int) reader["ID"]; category.name = (string) reader["Name"]; category.order = (int) reader["Order"]; category.usersCanCreateGroups = (bool) reader["UsersCanCreateGroups"]; categories.Add(category); } reader.Close(); } return categories.ToArray(); } }