Exemple #1
0
        /// <summary>
        /// Method to use for clicking enter or add button
        /// </summary>
        private void AddIncomeOrExpense()
        {
            RadioButton selectedExp = flowLayoutExpenses.Controls.OfType <RadioButton>()
                                      .FirstOrDefault(r => r.Checked);

            RadioButton selectedInc = flowLayoutIncomes.Controls.OfType <RadioButton>()
                                      .FirstOrDefault(r => r.Checked);

            if (selectedExp == null && selectedInc == null)
            {
                MessageBox.Show("Please select a type");
                return;
            }

            int recur = (int)numRecur.Value;

            if (recur > 1 && comboBoxRecur.Text == "")
            {
                MessageBox.Show("Please select recurring interval");
                return;
            }


            if (selectedExp != null)
            {
                string eType = selectedExp.Text;

                DBMethods.AddExpense(numAmount.Value, eType, UserID, dateTimeExpInc.Value);

                if (recur > 1)
                {
                    DBMethods.AddRecurringExpense(recur, comboBoxRecur.Text, numAmount.Value, eType, UserID, dateTimeExpInc.Value);
                }

                MessageBox.Show("Expense added!");
            }
            else if (selectedInc != null)
            {
                string iType = selectedInc.Text;

                DBMethods.AddIncome(numAmount.Value, iType, UserID, dateTimeExpInc.Value);

                if (recur > 1)
                {
                    DBMethods.AddRecurringIncome(recur, comboBoxRecur.Text, numAmount.Value, iType, UserID, dateTimeExpInc.Value);
                }

                MessageBox.Show("Income added!");
            }

            UpdateFormHistory();
            UpdateBalance();
            UpdateCharts();
        }
 /// <summary>
 /// Add recurring Expense
 /// </summary>
 /// <param name="recur"></param>
 /// <param name="interval"></param>
 /// <param name="amount"></param>
 /// <param name="eType"></param>
 /// <param name="userID"></param>
 /// <param name="dt"></param>
 internal static void AddRecurringExpense(int recur, string interval, decimal amount, string eType, int userID, DateTime dt)
 {
     if (interval == "Months")
     {
         int toAdd = 1;
         for (int r = recur; r > 1; r--)
         {
             DBMethods.AddExpense(amount, eType, userID, dt.AddMonths(toAdd));
             toAdd++;
         }
     }
     else if (interval == "Weeks")
     {
         int toAdd = 1;
         for (int r = recur; r > 1; r--)
         {
             DBMethods.AddExpense(amount, eType, userID, dt.AddDays(toAdd * 7));
             toAdd++;
         }
     }
 }