示例#1
0
        private void deleteTransaction(object sender, EventArgs e)
        {
            int tmpSelectedIndex = getselectedTransactionId();
            int catTransId;

            if (tmpSelectedIndex > 0)
            {
                var query = from Transaction in budgetManager.Transactions
                            where Transaction.Id == tmpSelectedIndex
                            select Transaction;

                Transaction transaction = query.First();
                catTransId = transaction.CatTransId;
                budgetManager.Transactions.Remove(transaction);

                var query2 = from CatTrans in budgetManager.CatTrans
                             where CatTrans.Id == catTransId
                             select CatTrans;

                if (query2.Any())
                {
                    CatTrans catTrans = query2.First();
                    budgetManager.CatTrans.Remove(catTrans);
                }
                budgetManager.SaveChanges();
                setselectedTransactionId(-1);
                MessageBox.Show("Transaction deleted successfully", "Successful", MessageBoxButtons.OK, MessageBoxIcon.Information);
                loadData();
            }
            else
            {
                MessageBox.Show("Select a transaction to delete", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
示例#2
0
        private double GetActualValue(Category category)
        {
            double actualVal = 0.0;
            double income    = 0.0;
            double expense   = 0.0;

            if (category.CatTrans.ToList() == null)
            {
                return(actualVal);
            }
            CatTrans catTrans = category.CatTrans.ToList().Find(f => f.Month == DateTime.Now.Month && f.Year == DateTime.Now.Year);

            if (catTrans != null)
            {
                foreach (Transaction item in catTrans.Transactions.ToList())
                {
                    if (item.TrType == TransactionType.Income)
                    {
                        income += item.Value;
                    }
                    else
                    {
                        expense += item.Value;
                    }
                }
                actualVal = expense - income;
            }
            return(actualVal);
        }
示例#3
0
        private bool createTransactionFromValues(ref Transaction transaction, transactionOperations op)
        {
            Double tempVal = 0;

            if (!ValidateField(txtTitle.Text, "Title"))
            {
                return(false);
            }
            if (!ValidateField(txtValue.Text, "Value"))
            {
                return(false);
            }
            if (!ValidateField(txtDescription.Text, "Description"))
            {
                return(false);
            }
            if (Double.TryParse(txtValue.Text, out tempVal))
            {
                transaction.Value = tempVal;
            }
            else
            {
                MessageBox.Show("Value should be double", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            transaction.Title = txtTitle.Text;

            transaction.Desc = txtDescription.Text;

            if (radioIncome.Checked)
            {
                transaction.TrType = TransactionType.Income;
            }
            else
            {
                transaction.TrType = TransactionType.Expense;
            }

            transaction.RecursionType = (RecursionInterval)comboRecursionType.SelectedItem;
            transaction.Date          = datePickerTransaction.Value.Date;
            transaction.UserId        = this.userId;

            var query = from CatTran in budgetManager.CatTrans
                        where CatTran.Month == (Int16)(datePickerTransaction.Value.Month) &&
                        CatTran.Year == (Int16)(datePickerTransaction.Value.Year) &&
                        CatTran.CategoryId == ((Category)comboCategory.SelectedItem).Id
                        select CatTran;

            if (query.Any())
            {
                transaction.CatTran = query.First();
            }
            else
            {
                CatTrans catTran = new CatTrans();
                catTran.CategoryId  = ((Category)comboCategory.SelectedItem).Id;
                catTran.Month       = (Int16)(datePickerTransaction.Value.Month);
                catTran.Year        = (Int16)(datePickerTransaction.Value.Year);
                transaction.CatTran = catTran;
            }

            return(true);
        }