コード例 #1
0
        private void addIncomeButton_Click(object sender, EventArgs e)
        {
            if (incomeNameTextBox.Text == "")
            {
                MessageBox.Show("Income name cannot be empty!");
                return;
            }
            if (categoryTextBox.Text == "")
            {
                MessageBox.Show("Category name is empty. Using default category.");
                categoryTextBox.Text = "Default";
            }

            var category = Reusable.CheckCategory(_myContext, categoryTextBox.Text);

            if (category == null)
            {
                _myContext.Categroies.Add(new CategoryModel
                {
                    Name = categoryTextBox.Text
                });
                _myContext.SaveChanges();
            }
            category = Reusable.CheckCategory(_myContext, categoryTextBox.Text);

            var incomeItem = Reusable.CheckIncomeItem(_myContext, incomeNameTextBox.Text);

            if (incomeItem == null)
            {
                _myContext.IncomeItems.Add(new IncomeItemModel
                {
                    CategoryId = category.Id,
                    Name       = incomeNameTextBox.Text,
                    LastValue  = (int)numericUpDown.Value
                });
                _myContext.SaveChanges();
            }
            else
            {
                incomeItem.LastValue = (int)numericUpDown.Value;
                _myContext.SaveChanges();
            }
            incomeItem = Reusable.CheckIncomeItem(_myContext, incomeNameTextBox.Text);

            _myContext.Incomes.Add(new IncomeModel
            {
                CreatedTime  = dateTimePicker.Value,
                IncomeItemId = incomeItem.Id,
                UserId       = _user.Id,
                Value        = (int)numericUpDown.Value
            });
            _myContext.SaveChanges();
            MessageBox.Show("Income successfully saved!");
            incomeNameTextBox.Text = "";
            categoryTextBox.Text   = "";
            numericUpDown.Value    = 0;
            ViewSpendings form = (ViewSpendings)Reusable.GetForm("BudgetRegistry.View.ViewSpendings");

            if (form != null)
            {
                form.refresh();
            }
        }
コード例 #2
0
        private void okButton_Click(object sender, EventArgs e)
        {
            if (spendingNameTextBox.Text == "")
            {
                MessageBox.Show("Spending Name cannot be empty!");
                return;
            }
            if (categoryTextBox.Text == "")
            {
                MessageBox.Show("Category name is empty. Using default category.");
                categoryTextBox.Text = "Default";
            }

            var category = Reusable.CheckCategory(_myContext, categoryTextBox.Text);

            if (category == null)
            {
                _myContext.Categroies.Add(new CategoryModel
                {
                    Name = categoryTextBox.Text
                });
                _myContext.SaveChanges();
            }
            category = Reusable.CheckCategory(_myContext, categoryTextBox.Text);

            var spendingItem = Reusable.CheckSpendingItem(_myContext, spendingNameTextBox.Text);

            if (spendingItem == null)
            {
                _myContext.SpendingItems.Add(new SpendingItemModel
                {
                    CategoryId = category.Id,
                    Name       = spendingNameTextBox.Text,
                    LastValue  = (int)numericUpDown.Value
                });
                _myContext.SaveChanges();
            }
            else
            {
                //var item = _myContext.SpendingItems.Where(s => s.Name == spendingNameTextBox.Text).FirstOrDefault();
                spendingItem.LastValue = (int)numericUpDown.Value;
                _myContext.SaveChanges();
            }
            spendingItem = Reusable.CheckSpendingItem(_myContext, spendingNameTextBox.Text);

            _myContext.Spendings.Add(new SpendingModel
            {
                CreatedTime    = dateTimePicker.Value,
                SpendingItemId = spendingItem.Id,
                UserId         = _user.Id,
                Value          = (int)numericUpDown.Value
            });
            _myContext.SaveChanges();
            MessageBox.Show("Spending successfully saved!");
            spendingNameTextBox.Text = "";
            categoryTextBox.Text     = "";
            numericUpDown.Value      = 0;
            ViewSpendings form = (ViewSpendings)Reusable.GetForm("BudgetRegistry.View.ViewSpendings");

            if (form != null)
            {
                form.refreshList();
            }
            else
            {
                MessageBox.Show("Form was null");
            }
        }