private void DeleteCategoryButton_Click(object sender, EventArgs e) { Form1 main = this.Owner as Form1; if (main != null) { var manager = new CategoriesManager(main.dateForm, main.categoriesFileName); var selectedItem = CategoriesBox.SelectedItem.ToString(); var delCategory = new Categories(selectedItem); manager.DeleteCategory(delCategory); foreach (var category in main.categoriesList) { if (selectedItem == category.categoryName) { main.categoriesList.Remove(category); main.categoriesBox.Items.Remove(category.categoryName); if (main.categoriesBox.Items.Count != 2) { main.categoriesBox.SelectedIndex = 0; } else { main.categoriesBox.SelectedIndex = -1; } break; } } Close(); } }
private void Form1_Load(object sender, EventArgs e) { try { var dateNow = new List <string>() { DateTime.Now.ToString(dateForm) }; var loadSessionsSerialization = new Serializer <Session>(sessions, dateNow); sessions = loadSessionsSerialization.ReadEntities(); } catch (FileNotFoundException) { } try { var categories = new CategoriesManager(dateForm, categoriesFileName); categories.ReadCategories(); foreach (var category in categories.categoriesList) { categoriesList.Add(category); categoriesBox.Items.Add(category.categoryName); } } catch (FileNotFoundException) { } categoriesBox.Items.Add(addCat); categoriesBox.Items.Add(delCat); Task.Factory.StartNew(async() => { while (running) { if (stopwatch.Running) { ResultLabel.Invoke((MethodInvoker) delegate { ResultLabel.Text = stopwatch.Elapsed.ToString("hh':'mm':'ss"); }); await Task.Delay(50); } else { await Task.Delay(500); } } }); aw = new ActiveWindow(ForegroundChanged); StartButton.Enabled = false; PauseButton.Enabled = false; StopWorkButton.Enabled = false; }
public void addCategoryButton_Click(object sender, EventArgs e) { Form1 main = this.Owner as Form1; if (main != null) { var manager = new CategoriesManager(main.dateForm, main.categoriesFileName); var newCategory = new Categories(addCategoryTextBox.Text); manager.AddCategory(newCategory); main.categoriesList.Add(newCategory); main.categoriesBox.Items.Insert(0, newCategory.categoryName); main.categoriesBox.SelectedItem = newCategory.categoryName; Close(); } }