public void Save(CashBookTransaction cashbookTransaction) { using (var core = new StandardBusinessLayer(this)) { core.Connect(); bool newVerification = cashbookTransaction.No == 0; core.Save(cashbookTransaction); if (newVerification) { CashBookTransactions.Add(cashbookTransaction); } else { for (int i = 0; i < CashBookTransactions.Count(); i++) { if (CashBookTransactions[i].No == cashbookTransaction.No) { CashBookTransactions[i] = cashbookTransaction; break; } } } FillVerification(Verifications.First(v => v.No == cashbookTransaction.VerificationNo)); } }
public CashBookTransaction AddCashBookTransaction(int verificationNo, DateTime verificationDate, DateTime accountingDate, int userNo, int categoryNo, decimal amount, string note) { Verification verification; CashBookTransaction transaction; if (verificationNo > 0) { verification = DataCache.GetVerification(verificationNo); } else { verification = CreateNewVerification(verificationDate.Year); } if (verification.Date.Year != verificationDate.Year) { throw new InvalidOperationException("Datumet på verifikationen stämmer inte överens med dess värde."); } using (var transactionScope = new TransactionScope(TransactionScopeOption.Required, TransactionHelper.Options(System.Transactions.IsolationLevel.ReadCommitted))) { Database.TheConnection.EnlistTransaction(Transaction.Current); verification.Date = DanielEiserman.DateAndTime.Date.FloorDateTime(verificationDate); verification.AccountingDate = DanielEiserman.DateAndTime.Date.FloorDateTime(accountingDate); DataCache.Save(verification); transaction = new CashBookTransaction(userNo, categoryNo, verification.No, verification.Date, verification.AccountingDate, amount, note, CurrentApplication.DateTimeNow); DataCache.Save(transaction); transactionScope.Complete(); } // Alert all listeners that a transaction was created ApplicationEvents.OnCashBookTransactionCreated(transaction.No, transaction.VerificationNo); // Update the new verification CurrentApplication.CurrentVerification = DataCache.GetVerification(verification.No); return(transaction); }
public CashBookTransaction UpdateCashBookTransaction(int cashBookTransactionNo, DateTime verificationDate, DateTime accountingDate, int userNo, int categoryNo, decimal amount, string note) { CashBookTransaction transaction = GetCashBookTransaction(cashBookTransactionNo); transaction.UserNo = userNo; transaction.CategoryNo = categoryNo; transaction.Amount = amount; transaction.Note = note; Verification verification = DataCache.GetVerification(transaction.VerificationNo); //Verification verification = GetVerification(transaction.VerificationNo); verification.Date = DanielEiserman.DateAndTime.Date.FloorDateTime(verificationDate); verification.AccountingDate = DanielEiserman.DateAndTime.Date.FloorDateTime(accountingDate); if (verification.Date.Year != verificationDate.Year || verification.AccountingDate.Year != verificationDate.Year) { throw new InvalidOperationException("Datumet på verifikationen stämmer inte överens med dess värde."); } using (var transactionScope = new TransactionScope(TransactionScopeOption.Required, TransactionHelper.Options(System.Transactions.IsolationLevel.ReadCommitted))) { Database.TheConnection.EnlistTransaction(Transaction.Current); DataCache.Save(verification); DataCache.Save(transaction); transactionScope.Complete(); } // Alert all listeners that a transaction was updated ApplicationEvents.OnCashBookTransactionUpdated(cashBookTransactionNo, verification.No); return(transaction); }
public void ClearCashBookTransaction() { CashBookTransaction = null; }
public Guess(AccountTransaction accountTransaction, CashBookTransaction cashBookTransaction) { AccountTransaction = accountTransaction; CashBookTransaction = cashBookTransaction; }
private void CashBookTransactionForm_Load(object sender, EventArgs e) { using (var core = new StandardBusinessLayer(DataCache)) { core.Connect(); int accountingYear = core.GetCashBoxSettings(CashBoxSettingsNo.CurrentApplicationNo).AccountingYear; var verifications = (from v in DataCache.GetUnbalancedAndEmptyVerifications() orderby v.No descending select new { No = v.No, Name = v.Year.ToString() + "-" + v.SerialNo.ToString() }).ToList(); if (!verifications.Any()) { verifications.Insert(0, new { No = 0, Name = "Ny affärshändelse" }); } if (_initialVerificationNo > 0 && verifications.All(x => x.No != _initialVerificationNo)) { Verification verification = DataCache.GetVerification(_initialVerificationNo); //Verification verification = core.GetVerification(_initialVerificationNo); verifications.Add(new { No = verification.No, Name = verification.Date.Year.ToString() + "-" + verification.SerialNo.ToString() }); } verificationComboBox.ValueMember = "No"; verificationComboBox.DisplayMember = "Name"; verificationComboBox.DataSource = verifications; categoryComboBox.ValueMember = Category.fNo; categoryComboBox.DisplayMember = Category.fName; categoryComboBox.DataSource = core.GetSubCategories(); userComboBox.ValueMember = User.fNo; userComboBox.DisplayMember = User.fName; userComboBox.DataSource = core.GetUsers(); if (_initialCashBookTransactionNo > 0) { //CashBookTransaction transaction = core.GetCashBookTransaction(_initialCashBookTransactionNo); CashBookTransaction transaction = DataCache.GetCashBookTransaction(_initialCashBookTransactionNo); verificationComboBox.SelectedValue = _initialVerificationNo; userComboBox.SelectedValue = transaction.UserNo; categoryComboBox.SelectedValue = transaction.CategoryNo; dateTimePicker.Value = transaction.TransactionTime; accountingDateTimePicker.Value = transaction.AccountingDate; amountTextBox.Text = transaction.Amount.ToString(CurrentApplication.MoneyEditFormat); noteTextBox.Text = transaction.Note; } else { verificationComboBox.SelectedIndex = verifications.Count() - 1; userComboBox.SelectedValue = CurrentApplication.UserNo; if (Guesser.CurrentGuess != null && Guesser.CurrentGuess.CashBookTransaction != null) { categoryComboBox.SelectedValue = Guesser.CurrentGuess.CashBookTransaction.CategoryNo; noteTextBox.Text = Guesser.CurrentGuess.CashBookTransaction.Note; } else { categoryComboBox.SelectedValue = 0; categoryComboBox.DroppedDown = true; } } } EnableDisableControls(); }