예제 #1
0
        //Add another expense
        private void AddExpeBtn_Click(object sender, RoutedEventArgs e)
        {
            //Create new employee
            Expenses nextExp = new Expenses()
            {
                Name = "Electricity", Cost = 150m, IncurredDate = DateTime.Now
            };

            incurredExpenses.Add(nextExp);

            //Read Expenses
            totalExpBlk.Text = "Total is " + GetTotalExp().ToString();
        }
예제 #2
0
        private void btnRemove_Click(object sender, RoutedEventArgs e)
        {
            //identify which expense is selected
            Expenses selectedExpense = lbxExp.SelectedItem as Expenses;

            if (selectedExpense != null)
            {
                //remove that expense
                Expenses.TotalExpenses -= selectedExpense.Cost;
                incurredExpenses.Remove(selectedExpense);

                decimal total = Expenses.TotalExpenses;
                totalExpBlk.Text = string.Format("{0:C}", total);
            }
        }
예제 #3
0
        private Expenses GetRandomExpense(Random randomFactory)
        {
            Random rf = new Random();

            int    randNumber     = rf.Next(0, 3);
            string randomCategory = names[randNumber];

            decimal randomAmount = (decimal)randomFactory.Next(1, 10001) / 100;

            DateTime randomDate = DateTime.Now.AddDays(-randomFactory.Next(0, 32));

            Expenses randomExpense = new Expenses(randomCategory, randomAmount, randomDate);

            return(randomExpense);
        }
예제 #4
0
        private void BtnAdd_Click(object sender, RoutedEventArgs e)
        {
            //read data from screen
            string   type = cbxType.SelectedItem as string;
            decimal  amt  = Convert.ToDecimal(tbxAmount.Text);
            DateTime date = dpDate.SelectedDate.Value;

            //create expense object
            Expenses newExp = new Expenses(type, amt, date);

            //get reference to main window
            MainWindow main = Owner as MainWindow;

            //add to collection
            main.incurredExpenses.Add(newExp);

            //Closed the window
            this.Close();
        }
예제 #5
0
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            //Create expense objects

            Random randomFactory = new Random();


            //create 3 expense objects

            Expenses exp1 = GetRandomExpense(randomFactory);
            Expenses exp2 = GetRandomExpense(randomFactory);
            Expenses exp3 = GetRandomExpense(randomFactory);
            Expenses exp4 = GetRandomExpense(randomFactory);


            //add to list collection
            //add to collection
            incurredExpenses.Add(exp1);
            incurredExpenses.Add(exp2);
            incurredExpenses.Add(exp3);
            incurredExpenses.Add(exp4);


            //Populate list items in listbox
            lbxExp.ItemsSource = incurredExpenses;

            //Get total


            decimal total = Expenses.TotalExpenses;

            totalExpBlk.Text = string.Format("{0:C}", total);

            //populate combo box
            cbxFilter.ItemsSource = names;
        }