public bool IsEmpty() { lock (TransactionsLock) { return(!Transactions.Any()); } }
private void CreateExecute(object obj) { Transaction hint = null; if (SelectedTransaction != null) { hint = m_transactionService.Get(SelectedTransaction.TransactionId); } else if (Transactions.Any()) { hint = m_transactionService.Get( Transactions.OrderByDescending(t => t.At).First().TransactionId); } else { AccountLink thisAccountLink = m_accountService.GetAsLink(m_accountId); hint = new Transaction { CreditAccount = thisAccountLink, DebitAccount = thisAccountLink, Amount = 0, At = DateTime.Now }; } Transaction newTransaction; if (m_transactionCreateViewService.Show(hint, out newTransaction)) { IAccountTransactionItemViewModel newTransactionViewModel = m_accountTransactionItemViewModelFactory.Create(newTransaction); Transactions.Add(newTransactionViewModel); PopulateTransactionBalances(); } }
/// <summary> /// Refresh the datasource of transactions. /// </summary> /// <param name="transactions"></param> private void RefreshTransactions(IList <Transaction> transactions) { foreach (var newTransaction in transactions .Where(tr => !Transactions.Any(knownTransaction => knownTransaction.TransactionId == tr.TransactionId))) { Transactions.Add(newTransaction); } }
protected override void POOrder_OrderDate_FieldVerifying(PXCache cache, PXFieldVerifyingEventArgs args) { if (Transactions.Any()) { Document.Ask(PoMessages.Warning, ScMessages.SubcontractDateChangeConfirmation, MessageButtons.YesNo, MessageIcon.Question); } }
private async void Import() { AllowInput = false; try { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "JSON|*.json"; ofd.DefaultExt = "json"; if (ofd.ShowDialog() == true && ofd.CheckFileExists && ofd.CheckPathExists) { var imported = FileExporter.FileExporter.ImportTransaction(ofd.FileName); IDatabaseService dbconn = new DatabaseService(); dbconn.ConnectionString = ConnectionStringsProvider.Get(); foreach (var entry in imported) { if (!Transactions.Any(c => c.Name == entry.Name)) { entry.Id = 0; await dbconn.TransactionService.SaveAsync(entry); } } var transactionsRaw = await dbconn.TransactionService.GetTransactionsAsync(); Transactions = new ObservableCollection <ITransaction>(transactionsRaw); Transaction = null; ReloadEditor(); } } catch (FileFormatException e) { MessageBox.Show("Invalid file format loaded. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (IOException e) { MessageBox.Show("Unexpected error occurred while loading JSON file. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (SqlException e) { MessageBox.Show("Unexpected SQL error occurred while saving imported entry in database. Details:/n" + e.ToString(), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception) { MessageBox.Show("Unexpected error occurred while importing", "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { AllowInput = true; } }
private void ClearTransactions() { if (Transactions.Any()) { Adapter.DeleteTransactions(Id); Transactions.Clear(); } _databaseProvider = null; Database = null; }
private void AssertNoDetachedReferences() { foreach (var payee in Payees) { if (payee.DefaultCategory != null) { if (!Categories.Any(c => ReferenceEquals(c, payee.DefaultCategory))) { throw new MoneizException($"Database is not valid: category of payee '{payee}' is not valid"); } } } foreach (var transaction in Transactions) { if (transaction.Account != null) { if (!Accounts.Any(c => ReferenceEquals(c, transaction.Account))) { throw new MoneizException($"Database is not valid: account of transaction '{transaction.Id}' is not valid"); } } if (transaction.Category != null) { if (!Categories.Any(c => ReferenceEquals(c, transaction.Category))) { throw new MoneizException($"Database is not valid: category of transaction '{transaction.Id}' is not valid"); } } if (transaction.Payee != null) { if (!Payees.Any(c => ReferenceEquals(c, transaction.Payee))) { throw new MoneizException($"Database is not valid: payee of transaction '{transaction.Id}' is not valid"); } } if (transaction.LinkedTransaction != null) { if (!ReferenceEquals(transaction.LinkedTransaction.LinkedTransaction, transaction)) { throw new MoneizException($"Database is not valid: linked transaction of transaction '{transaction.Id}' is not valid"); } if (!Transactions.Any(c => ReferenceEquals(c, transaction.LinkedTransaction))) { throw new MoneizException($"Database is not valid: linked transaction of transaction '{transaction.Id}' is not valid"); } } } }
public override string ToString() { var numCredit = Transactions != null?Transactions.Count(t => t.IsCredit) : 0; var numDebit = Transactions != null?Transactions.Count(t => !t.IsCredit) : 0; var firstTran = Transactions != null && Transactions.Any() ? Transactions[0].ToString() : ""; return(string.Format("Name: {0} From: {1} To: {2} {3} {4} # Transactions: {5} #credit: {7} #debit: {8}\n First Transaction: {6}", Name, DateFrom, DateTo, Balance.HasValue ? "Balance: " : "", Balance.HasValue ? Balance.Value.ToString(CultureInfo.InvariantCulture) : "", NumOfTransactions, firstTran, numCredit, numDebit)); }
/// <summary> /// Deletes the transaction marked. /// If no transaction id marked, the selected transaction is deleted. /// </summary> private void DeleteTransactions() { if (Transactions.Any()) { var markedTrans = Transactions.Where(t => t.IsMarked); if (markedTrans.Any()) { var markedArray = markedTrans.Select(t => t.Entity).ToArray(); _messagingService.ShowProgressMessage(UIText.WAIT_SCREEN_HEADER, UIText.DELETING_TRANS_WAIT_MSG); _transactionRepository.DeleteTransactionsAsync(markedArray); return; } } _messagingService.ShowMessage(InfoMessages.INF_MARK_FOR_DEL); }
public long GetTotalFees() { if (Transactions == null || !Transactions.Any()) { return(0); } long result = 0; foreach (var tx in Transactions) { var cbTx = tx as NoneCoinbaseTransaction; if (cbTx == null) { continue; } result += ((TransactionOut)cbTx.TransactionOut.First()).Value; } return(result); }
private async Task LoadItem(InvType type) { _eventAggregator.PublishOnUIThread(new StatusEvent(this, "Processing trade details...")); if (type == null) { return; } setActualViewperiod(); Transactions = await _transactionDetailsService.GetTransactions(type, ActualViewStart, ActualViewEnd); if (Transactions.Any()) { Order order = await _transactionDetailsService.GetOrder(type).ConfigureAwait(false); TransactionAggregate = new TransactionAggregate(Transactions.GroupBy(t => t.TransactionDate.Date), type, order); } else { TransactionAggregate = new TransactionAggregate(); } _eventAggregator.PublishOnUIThread(new StatusEvent(this, "Trade details loaded")); }
private void UpdateTransactionList(IEnumerable <TransactionEntity> newTxs) { if (newTxs == null) { TransactionViewHeaderText = "No Transactions Found"; return; } else if (newTxs.Any()) { TransactionViewHeaderText = string.Empty; } var newTxAdded = false; foreach (var tx in newTxs) { if (!Transactions.Any(oldTx => string.Equals(oldTx.TxId, tx.TxId, StringComparison.Ordinal))) { Transactions.Add(tx); newTxAdded = true; } else { var existingTxs = Transactions.Where(oldTx => string.Equals(oldTx.TxId, tx.TxId, StringComparison.Ordinal)); foreach (var existingTx in existingTxs) { existingTx.Confirmations = tx.Confirmations; } } } if (newTxAdded) { Transactions = Transactions.OrderByDescending(tx => tx.TimeReceived).ToList(); } RaisePropertyChanged("Transactions"); }
public void Seed(bool isDevelopment) { if (!TransactionCategories.Any()) { TransactionCategories.AddRange(new[] { new TransactionCategory { TransactionType = (int)TransactionTypes.Income, Title = "Salary" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Income, Title = "Refund" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Income, Title = "Investment" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Income, Title = "Allowance" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Income, Title = "Bonus" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Income, Title = "Other" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Food" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Bill" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Transportation" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Car" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Shopping" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Clothing" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Smoking" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Electronics" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Travel" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Education" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Gifts" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Sports" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Entertainment" }, new TransactionCategory { TransactionType = (int)TransactionTypes.Expense, Title = "Other" }, }); SaveChanges(); } if (isDevelopment) { if (!Transactions.Any()) { Transactions.AddRange(new[] { new Transaction { Id = Guid.NewGuid(), AccountId = 1, AccountTitle = "Default cash", Amount = 200, Date = DateTime.UtcNow, Notes = "Default transaction", TransactionCategoryId = 1, Type = "Income", TypeId = (int)TransactionTypes.Income, TransactionTags = new List <TransactionTag> { new TransactionTag { Tag = "Default" } }, UserId = 1, CurrencyTitle = "US Dollar", CurrencyId = 1, CurrencyCode = "USD", }, new Transaction { Id = Guid.NewGuid(), AccountId = 1, AccountTitle = "Default cash", Amount = 75, Date = DateTime.UtcNow, Notes = "Default transaction", TransactionCategoryId = 2, Type = "Expense", TypeId = (int)TransactionTypes.Expense, TransactionTags = new List <TransactionTag> { new TransactionTag { Tag = "Default" } }, UserId = 1, CurrencyTitle = "US Dollar", CurrencyId = 1, CurrencyCode = "USD", } }); SaveChanges(); } if (!Accounts.Any()) { Accounts.AddRange(new Account[] { new Account { Title = "Cash default", AccountId = 1, UserId = 1 } }); SaveChanges(); } } }
/// <summary> /// Creates a <see cref="Block{T}"/> instance by manually filling all field values. /// For a more automated way, see also <see cref="Mine"/> method. /// </summary> /// <param name="index">The height of the block to create. Goes to the <see cref="Index"/>. /// </param> /// <param name="difficulty">The mining difficulty that <paramref name="nonce"/> has to /// satisfy. Goes to the <see cref="Difficulty"/>.</param> /// <param name="nonce">The nonce which satisfy the given <paramref name="difficulty"/> with /// any other field values. Goes to the <see cref="Nonce"/>.</param> /// <param name="miner">An optional address refers to who mines this block. /// Goes to the <see cref="Miner"/>.</param> /// <param name="previousHash">The previous block's <see cref="Hash"/>. If it's a genesis /// block (i.e., <paramref name="index"/> is 0) this should be <c>null</c>. /// Goes to the <see cref="PreviousHash"/>.</param> /// <param name="timestamp">The time this block is created. Goes to /// the <see cref="Timestamp"/>.</param> /// <param name="transactions">The transactions to be mined together with this block. /// Transactions become sorted in an unpredicted-before-mined order and then go to /// the <see cref="Transactions"/> property. /// </param> /// <seealso cref="Mine"/> public Block( long index, long difficulty, Nonce nonce, Address?miner, HashDigest <SHA256>?previousHash, DateTimeOffset timestamp, IEnumerable <Transaction <T> > transactions) { Index = index; Difficulty = difficulty; Nonce = nonce; Miner = miner; PreviousHash = previousHash; Timestamp = timestamp; Transactions = transactions.OrderBy(tx => tx.Id).ToArray(); var codec = new Codec(); TxHash = Transactions.Any() ? Hashcash.Hash( codec.Encode( new Bencodex.Types.List(Transactions.Select(tx => (IValue)tx.ToBencodex(true))))) : (HashDigest <SHA256>?)null; // FIXME: This does not need to be computed every time? Hash = Hashcash.Hash(SerializeForHash()); // As the order of transactions should be unpredictable until a block is mined, // the sorter key should be derived from both a block hash and a txid. var hashInteger = new BigInteger(Hash.ToByteArray()); // If there are multiple transactions for the same signer these should be ordered by // their tx nonces. So transactions of the same signer should have the same sort key. // The following logic "flattens" multiple tx ids having the same signer into a single // txid by applying XOR between them. IImmutableDictionary <Address, IImmutableSet <Transaction <T> > > signerTxs = Transactions .GroupBy(tx => tx.Signer) .ToImmutableDictionary( g => g.Key, g => (IImmutableSet <Transaction <T> >)g.ToImmutableHashSet() ); IImmutableDictionary <Address, BigInteger> signerTxIds = signerTxs .ToImmutableDictionary( pair => pair.Key, pair => pair.Value .Select(tx => new BigInteger(tx.Id.ToByteArray())) .OrderBy(txid => txid) .Aggregate((a, b) => a ^ b) ); // Order signers by values derivied from both block hash and their "flatten" txid: IImmutableList <Address> signers = signerTxIds .OrderBy(pair => pair.Value ^ hashInteger) .Select(pair => pair.Key) .ToImmutableArray(); // Order transactions for each signer by their tx nonces: Transactions = signers .SelectMany(signer => signerTxs[signer].OrderBy(tx => tx.Nonce)) .ToImmutableArray(); }
public ApplicationContext(DbContextOptions <ApplicationContext> options) : base(options) { Database.EnsureCreated(); IsEmpty = !(Users.Any() || Assets.Any() || Transactions.Any() || Categories.Any()); }
public bool IsInBlock(string userToken, Guid poll) => Transactions.Any(transaction => transaction.Sender == userToken && transaction.Poll == poll);