예제 #1
0
        private void CreateTransactionButton_Click(object sender, RoutedEventArgs e)
        {
            Bill payer     = (Bill)PayerList.SelectedItem;
            Bill recipient = (Bill)RecipientList.SelectedItem;

            CreateTransactionLabel.Content = "";

            if (PayerList.SelectedItem is null || RecipientList.SelectedItem is null)
            {
                CreateTransactionLabel.Content = "You have to select \none Payer and one Recipient";
                return;
            }

            if (payer.BillNumber == recipient.BillNumber)
            {
                CreateTransactionLabel.Content = "Unable create Transaction \nbecause Payer = Recipient";
                return;
            }

            Transaction newTransaction = new Transaction
            {
                Id               = TransactionORM.GetNewTransactionId(),
                VariableSymbol   = Int32.Parse(VariableSymbolTextBox.Text),
                Amount           = Int32.Parse(AmountTextBox.Text),
                Valid            = true,
                PayerBillNum     = payer.BillNumber,
                RecipientBillNum = recipient.BillNumber,
                DateTransaction  = DateTime.Now
            };

            DateTime?selectedDate = DateSelectionBox.SelectedDate;

            if (selectedDate.HasValue)
            {
                newTransaction.DateTransaction = (DateTime)DateSelectionBox.SelectedDate;
            }

            TransactionORM.CreateNewTransaction(newTransaction);
            BillORM.UpdateBillBalance(newTransaction);

            UpdatePayerLabelContent();
            UpdateRecipientLabelContent();
            GenerateNewVariableSymbol();
            GenerateNewAmount();

            UpdateLastTransactionsList(newTransaction);
        }
예제 #2
0
        private void GetAllTransactionBySelectedCriterias()
        {
            List <Transaction> transactions = TransactionORM.GetTransactionByBillId(activeBill);

            if (OnlyIncomingRadioButton.IsChecked == true)
            {
                transactions = transactions.Where(X => X.TransactionType == TransactionType.Incoming)
                               .ToList();
            }
            else if (OnlyOutgoingRadioButton.IsChecked == true)
            {
                transactions = transactions.Where(X => X.TransactionType == TransactionType.Outgoing)
                               .ToList();
            }

            if (TransactionDateFrom.SelectedDate != null)
            {
                transactions = transactions.Where(X => X.DateTransaction >= (DateTime)TransactionDateFrom.SelectedDate)
                               .ToList();
            }
            if (TransactionDateTo.SelectedDate != null)
            {
                transactions = transactions.Where(X => X.DateTransaction <= (DateTime)TransactionDateTo.SelectedDate)
                               .ToList();
            }

            if (AmountFromTextBox.Text != "")
            {
                int amountFrom = int.Parse(AmountFromTextBox.Text);
                transactions = transactions.Where(X => X.Amount >= amountFrom)
                               .ToList();
            }
            if (AmountToTextBox.Text != "")
            {
                int amountTo = int.Parse(AmountToTextBox.Text);
                transactions = transactions.Where(X => X.Amount <= amountTo)
                               .ToList();
            }

            if (VariableSymbolTextBox.Text != "")
            {
                transactions = transactions.Where(X => X.VariableSymbol.ToString().Contains(VariableSymbolTextBox.Text))
                               .ToList();
            }

            if (BillNumberTextBox.Text != "")
            {
                List <Transaction> transactions1 = new List <Transaction>();

                transactions1 = transactions.Where(X => X.TransactionType == TransactionType.Incoming)
                                .Where(X => X.PayerBillNum.ToString().Contains(BillNumberTextBox.Text))
                                .ToList();

                transactions = transactions.Where(X => X.TransactionType == TransactionType.Outgoing)
                               .Where(X => X.RecipientBillNum.ToString().Contains(BillNumberTextBox.Text))
                               .ToList();

                transactions.AddRange(transactions1);
            }


            if (NewestToOldest.IsChecked == true)
            {
                transactions = transactions.OrderByDescending(X => X.DateTransaction)
                               .ToList();
            }
            else if (OldestToNewest.IsChecked == true)
            {
                transactions = transactions.OrderBy(X => X.DateTransaction)
                               .ToList();
            }
            else if (HighestToLowest.IsChecked == true)
            {
                List <Transaction> transactions1 = new List <Transaction>();

                transactions1 = transactions.Where(X => X.TransactionType == TransactionType.Outgoing)
                                .OrderBy(X => X.Amount)
                                .ToList();

                transactions = transactions.Where(X => X.TransactionType == TransactionType.Incoming)
                               .OrderByDescending(X => X.Amount)
                               .ToList();

                transactions.AddRange(transactions1);
            }
            else if (LowestToHighest.IsChecked == true)
            {
                List <Transaction> transactions1 = new List <Transaction>();

                transactions1 = transactions.Where(X => X.TransactionType == TransactionType.Incoming)
                                .OrderBy(X => X.Amount)
                                .ToList();

                transactions = transactions.Where(X => X.TransactionType == TransactionType.Outgoing)
                               .OrderByDescending(X => X.Amount)
                               .ToList();

                transactions.AddRange(transactions1);
            }

            TransactionListBox.ItemsSource = transactions;
            TransactionListBox.Items.Refresh();

            int sumOutgoing = 0;
            int sumIncoming = 0;

            if (transactions.Any())
            {
                foreach (Transaction t in transactions)
                {
                    switch (t.TransactionType)
                    {
                    case TransactionType.Incoming:
                        sumIncoming += t.Amount;
                        break;

                    case TransactionType.Outgoing:
                        sumOutgoing += t.Amount;
                        break;

                    default:
                        break;
                    }
                }
            }

            UpdateIncomingOutgoingBalanceLabels(sumOutgoing, sumIncoming, sumIncoming - sumOutgoing);
        }