public override void okButton_Click(object sender, EventArgs e) { var fullItemList = new List<ZaLedgerItem>(); var originAccount = (ZaAccount) comboOriginalAccount.SelectedItem; var throughAccount = (ZaAccount) comboThroughAccount.SelectedItem; var destinationAccount = (ZaAccount) comboDestinationAccount.SelectedItem; var amount = Decimal.Parse(textBox1.Text); var dateOfTransfer = dateTimeDateOfTransfer.Value; if (originAccount != null && destinationAccount != null && amount > 0) { var originItem = new ZaLedgerItem(); originItem.PurchaseDate = DateTime.Today; originItem.Account = originAccount; originItem.Description = "Transfer from [" + originAccount + "] to [" + (throughAccount ?? destinationAccount) + "]"; originItem.PurchasePrice = amount; originItem.PurchaseDate = dateOfTransfer; fullItemList.Add(originItem); if (throughAccount != null) { var throughItemRecieved = new ZaLedgerItem(); throughItemRecieved.PurchaseDate = DateTime.Today; throughItemRecieved.Account = throughAccount; throughItemRecieved.Description = "Transfer Recieved from [" + originAccount + "]"; throughItemRecieved.PurchasePrice = -amount; throughItemRecieved.PurchaseDate = dateOfTransfer; fullItemList.Add(throughItemRecieved); var throughItemForwarded = new ZaLedgerItem(); throughItemForwarded.PurchaseDate = DateTime.Today; throughItemForwarded.Account = throughAccount; throughItemForwarded.Description = "Forwarding Transfer to [" + destinationAccount + "]"; throughItemForwarded.PurchasePrice = amount; throughItemForwarded.PurchaseDate = dateOfTransfer; fullItemList.Add(throughItemForwarded); } var destinationItem = new ZaLedgerItem(); destinationItem.PurchaseDate = DateTime.Today; destinationItem.Account = destinationAccount; destinationItem.Description = "Transfer Recieved from [" + (throughAccount ?? destinationAccount) + "]"; destinationItem.PurchasePrice = -amount; destinationItem.PurchaseDate = dateOfTransfer; fullItemList.Add(destinationItem); returnValue = fullItemList; base.okButton_Click(sender, e); // clear all the values on the form originAccount = null; } else { MessageBox.Show("An origin account, destination account and amount are required as a minimum.", "Required Fields", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
/// <summary> /// Constructor /// </summary> public ZaLedgerItem(ZaLedgerItem toClone) : this(toClone.PurchaseDate, toClone.Description, toClone.ExpenseType, toClone.SecondaryExpenseType, toClone.Account, toClone.PurchasePrice) { }
private void ZaLedgerItemDialog_Load(object sender, EventArgs e) { if (LedgerItem == null) { LedgerItem = new ZaLedgerItem(); } else { MaxItemValue = LedgerItem.PurchasePrice; } accountCombo.DataSource = MockDb.Database.Accounts.ToList(); accountCombo.DisplayMember = "Label"; accountCombo.ValueMember = "Self"; accountCombo.SelectedItem = LedgerItem.Account; expenseTypeCombo.DataSource = MockDb.Database.ExpenseTypes.ToList(); expenseTypeCombo.DisplayMember = "Label"; expenseTypeCombo.ValueMember = "Self"; expenseTypeCombo.SelectedItem = LedgerItem.ExpenseType; UpdateSecondaryCombo(); secondaryExpenseTypeCombo.DisplayMember = "Label"; secondaryExpenseTypeCombo.ValueMember = "Self"; secondaryExpenseTypeCombo.SelectedItem = LedgerItem.SecondaryExpenseType; descriptionText.Text = LedgerItem.Description; purchaseDatePicker.Value = LedgerItem.PurchaseDate != DateTime.MinValue ? LedgerItem.PurchaseDate : DateTime.Today; purchasePriceNumeric.Text = LedgerItem.PurchasePrice.ToString(); }