public static AbstractTransaction Create() { AbstractTransaction instantTransaction = new InstantTransaction(); instantTransaction.StartDate = DateTime.Now; instantTransaction.EndDate = DateTime.Now; return(instantTransaction); }
public static List <AbstractTransaction> GetTransactionFromDB(string sql) { SqlCommand cmd = new SqlCommand(); cmd.Connection = GetConnexion; cmd.CommandText = sql; List <AbstractTransaction> currentTransactionList = new List <AbstractTransaction>(); using (DbDataReader reader = cmd.ExecuteReader()) { if (reader.HasRows) { while (reader.Read()) { AbstractTransaction newTransaction; string TransactionType = reader.GetString(reader.GetOrdinal("transactionType")); if (TransactionType == "Instant") { newTransaction = new InstantTransaction(); } else if (TransactionType == "Deffered") { newTransaction = new DeferredTransaction(); } else { newTransaction = new PermanentTransaction(); PermanentTransaction newPermanentTransaction = (PermanentTransaction)newTransaction; newPermanentTransaction.StartDate = reader.GetDateTime(reader.GetOrdinal("beginDate")); newPermanentTransaction.EndDate = reader.GetDateTime(reader.GetOrdinal("endDate")); newPermanentTransaction.Periodicity = reader.GetInt32(reader.GetOrdinal("periodicity")); } newTransaction.IdTransaction = reader.GetInt32(reader.GetOrdinal("idTransaction")); newTransaction.TransactionDate = reader.GetDateTime(reader.GetOrdinal("transactionDate")); newTransaction.Amount = reader.GetDecimal(reader.GetOrdinal("amount")); newTransaction.AccountOrigin = reader.GetInt32(reader.GetOrdinal("idOriginAccount")); newTransaction.AccountDestination = reader.GetInt32(reader.GetOrdinal("idDestinationAccount")); currentTransactionList.Add(newTransaction); } } } return(currentTransactionList); }
public static AbstractTransaction Create(String transactionType) { AbstractTransaction transaction; if (typeof(InstantTransaction).Name == transactionType) { transaction = InstantTransaction.Create(); } else if (typeof(DeferredTransaction).Name == transactionType) { transaction = DeferredTransaction.Create(); } else if (typeof(PermanentTransaction).Name == transactionType) { transaction = PermanentTransaction.Create(); } else { throw new ArgumentException($"No transaction type corresponding to {transactionType}"); } return(transaction); }
public static AbstractTransaction Create(DateTime?startDate = null, DateTime?endDate = null) { AbstractTransaction transaction = null; if (startDate == null) { transaction = InstantTransaction.Create(); } else if (startDate > DateTime.Now && endDate == null) { transaction = DeferredTransaction.CreateDeferred(startDate); } else if (startDate < endDate && startDate > DateTime.Now) { transaction = PermanentTransaction.CreatePermanent(startDate, endDate); } else { IO.DisplayWarning("There is something wrong with the date."); throw new ArgumentException("No transaction can be executed from date " + startDate + " to " + endDate); } return(transaction); }