/// <summary> /// transaction /// </summary> public TransactionCard (Transaction transaction) { TransactionGuid = transaction.TransactionGuid; Designation = transaction.Designation; TransactionReference ="Ref: " + transaction.TransactionReference; PaymentMethodeString = "Par " + transaction.PaymentMethode; TransactionDateString = transaction.TransactionDate.GetValueOrDefault().ToShortDateString(); Description = transaction.Description; TresorereName = ""; //todo get tresorer Name if (transaction.Amount > 0) { AmountString=transaction.Amount.ToString("0.##", CultureInfo.CurrentCulture)+" dhs"; UpDownImage=Resources.Down.ToByteArray(); } else { AmountString= (-transaction.Amount).ToString("0.##", CultureInfo.CurrentCulture)+" dhs"; UpDownImage=Resources.Up.ToByteArray(); } }
public AddTransaction () { InitializeComponent(); new Task(() => { Dispatcher.BeginInvoke(new Action(() => { _TRANS_TYPE.ItemsSource=EnumsHelper.GetAllValuesAndDescriptions<TransactionType>(); _PAY_METHODE.ItemsSource=EnumsHelper.GetAllValuesAndDescriptions<PaymentMethode>(); _DATE_TRANS.DisplayDateStart = DateTime.Today.AddDays(-1); var newData = new Transaction { Designation = "", PaidToward = "", Amount = 0, PaymentMethode = PaymentMethode.Espece, TransactionDate = DateTime.Today, TransactionReference = App.Store.Economat.Finance.GetNewTransactionReference() }; _GRID.DataContext=newData; })); }).Start(); }
internal static bool TransactionExist (Transaction newTransaction) { using (var db = new StationContext()) { if(db.Transactions.Find(newTransaction.TransactionGuid)!=null) return true; return db.Transactions.Any(t => t.TransactionReference.Equals(newTransaction.TransactionReference, StringComparison.CurrentCultureIgnoreCase)) || db.Transactions.Any(t => t.PaymentMethode == newTransaction.PaymentMethode && t.Designation.Equals(newTransaction.Designation) && t.TransactionDate == newTransaction.TransactionDate && Math.Abs(t.Amount - newTransaction.Amount) < .0000001); } }
internal static bool StaticNewTransaction (Transaction newTransaction) { if(TransactionExist(newTransaction)) throw new InvalidOperationException("TRANSACTION_REFERENCE_ALREADY_EXIST"); if(newTransaction.TransactionDate < DateTime.Today.AddDays(-1)) throw new InvalidOperationException("TRANSACTION_DATE_NOT_VALIDE"); using (var db = new StationContext()) { newTransaction.TransactionGuid =newTransaction.TransactionGuid == Guid.Empty ? Guid.NewGuid() : newTransaction.TransactionGuid; var transDate = newTransaction.TransactionDate.GetValueOrDefault(); newTransaction.TransactionDate = new DateTime(transDate.Year, transDate.Month, transDate.Day, DateTime.Now.Hour, DateTime.Now.Minute, DateTime.Now.Second); if (string.IsNullOrEmpty(newTransaction.Description)) newTransaction.Description =newTransaction.Designation; newTransaction.DateAdded = DateTime.Now; newTransaction.AddUserGuid = Guid.Empty; newTransaction.LastEditDate = DateTime.Now; newTransaction.LastEditUserGuid = Guid.Empty; db.Transactions.Add(newTransaction); return db.SaveChanges()>0; } }
/// <summary> /// /// </summary> /// <param name="newTransaction"></param> /// <returns></returns> public bool NewTransaction(Transaction newTransaction) { //todo security return StaticNewTransaction(newTransaction); }