예제 #1
0
        private void SaveCurrentItem()
        {
            if (itemName != null)
            {
                if (NameTextBox.Text == "Main")
                {
                    MessageBox.Show("Items cannot be named \"Main\"");
                    NameTextBox.Text = itemName;
                    return;
                }

                BudgetCalcItem currentItem = new BudgetCalcItem(NameTextBox.Text, PercentIncomeBox.Value, false);

                data.SetItem(currentItem);

                if (NameTextBox.Text != itemName)
                {
                    data.RemoveItem(itemName);
                    itemName = currentItem.ItemName;
                    RefreshListBox();
                }
                else
                {
                    itemName = currentItem.ItemName;
                }
            }
        }
예제 #2
0
        private void ItemsBox_SelectedValueChanged(object sender, EventArgs e)
        {
            // Save the current item
            SaveCurrentItem();

            // Get the item from data whose name matches the current selected item in the list box
            BudgetCalcItem currentItem = data.GetItems()[(string)ItemsBox.SelectedItem];

            NameTextBox.Text       = currentItem.ItemName;
            PercentIncomeBox.Value = currentItem.IncomePercent;

            itemName = currentItem.ItemName;
        }
예제 #3
0
        private void UpdateItemsBox()
        {
            for (int i = ItemsBox.Items.Count - 1; i >= 0; i--)
            {
                ItemsBox.Items.RemoveAt(i);
            }

            for (int i = 0; i < data.GetItems().Count(); i++)
            {
                BudgetCalcItem item = data.GetItems().ElementAt(i).Value;
                ItemsBox.Items.Add(item.ItemName);
                ItemsBox.SetItemChecked(ItemsBox.Items.IndexOf(item.ItemName), item.Selected);
            }
        }
예제 #4
0
        private void ItemsBox_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e)
        {
            BudgetCalcItem selectedItem = data.GetItems()[(string)ItemsBox.Items[e.Index]];

            if (e.NewValue == CheckState.Checked)
            {
                selectedItem.Selected = true;
            }
            else if (e.NewValue == CheckState.Unchecked)
            {
                selectedItem.Selected = false;
            }

            data.SetItem(selectedItem);
        }
예제 #5
0
        // TODO: Maybe instead of reading the amount from file every time a new item is selected, I could read it all at once when the file is opened?
        // TODO: Decide on this once I figure out if I am going to save everything in the one file instead of the csv files.
        private void ItemsBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            BudgetCalcItem selectedItem = data.GetItems()[(string)ItemsBox.SelectedItem];
            string         filePath     = Path.GetDirectoryName(dataFilePath) + $"\\{selectedItem.ItemName}.csv";

            PercentIncomeDataLabel.Text = selectedItem.IncomePercent.ToString();
            if (File.Exists(filePath))
            {
                CurrentBalanceDataLabel.Text = File.ReadLines(filePath).Last().Split(',').Last();
            }
            else
            {
                CurrentBalanceDataLabel.Text = "0.00";
            }
        }
예제 #6
0
        public void SetItem(BudgetCalcItem item)
        {
            if (item.ItemName == "Main")
            {
                throw new System.ArgumentException("Items cannot be named \"Main\"");
            }

            if (_Items.ContainsKey(item.ItemName))
            {
                _Items[item.ItemName] = item;
            }
            else
            {
                _Items.Add(item.ItemName, item);
            }
        }