예제 #1
0
        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();
            }
        }
예제 #2
0
파일: Form1.cs 프로젝트: Rizhiy825/Timer
        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;
        }
예제 #3
0
        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();
            }
        }