private void BarManager1_ItemClick(object sender, ItemClickEventArgs e) { if (debitIDSelected != -1) { try { if (e.Item.Caption.Equals("Insert Row Above")) { using (var context = new LorikeetAppEntities()) { var checkDateTime = (from c in context.DebitSystems where c.DebitID == debitIDSelected select c).FirstOrDefault(); if (checkDateTime != null) { DateTime date = checkDateTime.Date.AddSeconds(-1); var addDebitCreditRow = new DebitSystem(); addDebitCreditRow.Credit = 0; addDebitCreditRow.Date = date; addDebitCreditRow.Debit = 0; addDebitCreditRow.Details = ""; addDebitCreditRow.MemberID = this.memberID; addDebitCreditRow.RunningTotal = 0; addDebitCreditRow.StaffID = this.staffID; context.DebitSystems.Add(addDebitCreditRow); context.SaveChanges(); UpdateRunningTotal(); } } } else if (e.Item.Caption.Equals("Insert Row Below")) { using (var context = new LorikeetAppEntities()) { var checkDateTime = (from c in context.DebitSystems where c.DebitID == debitIDSelected select c).FirstOrDefault(); if (checkDateTime != null) { DateTime date = checkDateTime.Date.AddSeconds(1); var addDebitCreditRow = new DebitSystem(); addDebitCreditRow.Credit = 0; addDebitCreditRow.Date = date; addDebitCreditRow.Debit = 0; addDebitCreditRow.Details = ""; addDebitCreditRow.MemberID = this.memberID; addDebitCreditRow.RunningTotal = 0; addDebitCreditRow.StaffID = this.staffID; context.DebitSystems.Add(addDebitCreditRow); context.SaveChanges(); UpdateRunningTotal(); } } } else if (e.Item.Caption.Equals("Delete Row")) { DialogResult dr = new DialogResult(); dr = MessageBox.Show("Are you sure you want to remove row?", "Warning", MessageBoxButtons.YesNo); if (dr == DialogResult.Yes) { using (var context = new LorikeetAppEntities()) { var debitCreditToRemove = (from d in context.DebitSystems where d.DebitID == debitIDSelected select d).FirstOrDefault(); if (debitCreditToRemove != null) { context.DebitSystems.Remove(debitCreditToRemove); context.SaveChanges(); UpdateRunningTotal(); } } } } else if (e.Item.Caption.Equals("Fix Mistake")) { if (fixable) { FixMistake(); } } } catch (Exception ex) { MessageBox.Show(MiscStuff.GetAllMessages(ex)); } } }
static void Main(string[] args) { EmailNotificationSender emailNotificationSender = new EmailNotificationSender(); SMSNotificationSender smsNotificationSender = new SMSNotificationSender(); UINotificationSender uiNotificationSender = new UINotificationSender(); CreditSystem creditSystem = new CreditSystem(); DebitSystem debitSystem = new DebitSystem(); PromotionSystem promotionSystem = new PromotionSystem(); Account account = new Account() { AccountName = "Dumpi", Balance = 0 }; //////////////////////////////////////////////////////////////////////////////////////////// creditSystem._notificationSender = emailNotificationSender; creditSystem.Credit(account, 100); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); creditSystem._notificationSender = smsNotificationSender; creditSystem.Credit(account, 100); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); creditSystem._notificationSender = uiNotificationSender; creditSystem.Credit(account, 100); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// debitSystem._notificationSender = emailNotificationSender; debitSystem.Debit(account, 100); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); debitSystem._notificationSender = smsNotificationSender; debitSystem.Debit(account, 100); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); debitSystem._notificationSender = uiNotificationSender; debitSystem.Debit(account, 200); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); //////////////////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////////////////// string offer = "$1 million loan approved"; promotionSystem._notificationSender = emailNotificationSender; promotionSystem.Promote(account, offer); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); promotionSystem._notificationSender = smsNotificationSender; promotionSystem.Promote(account, offer); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); promotionSystem._notificationSender = uiNotificationSender; promotionSystem.Promote(account, offer); Console.WriteLine("//////////////////////////////////////////////////////////////////////"); //////////////////////////////////////////////////////////////////////////////////////////// //Just to stop the console Console.ReadLine(); }
private void buttonAdd_Click(object sender, EventArgs e) { try { using (var context = new LorikeetAppEntities()) { decimal number; if (textBoxDebit.Text == "" && decimal.TryParse(textBoxCredit.Text, out number)) { var creditToAdd = new DebitSystem(); creditToAdd.StaffID = this.staffID; creditToAdd.MemberID = this.memberID; creditToAdd.Credit = number; creditToAdd.Debit = 0; creditToAdd.Details = textBoxDetails.Text; creditToAdd.Date = DateTime.Now; decimal?runTotal = 0m; var runningTotal = (from dc in context.DebitSystems where dc.MemberID == this.memberID select dc).ToList(); if (runningTotal.Any()) { runTotal = runningTotal.Last().RunningTotal + number; } else { runTotal = number; } creditToAdd.RunningTotal = runTotal; context.DebitSystems.Add(creditToAdd); context.SaveChanges(); Logging.AddLogEntry(staffID, Logging.ErrorCodes.Broadcast, Logging.RefreshCodes.DebitCredit, "Credit for member - " + MiscStuff.GetMemberName(memberID) + " of $" + number + " Added", false); } else if (textBoxCredit.Text == "" && decimal.TryParse(textBoxDebit.Text, out number)) { var debitToAdd = new DebitSystem(); debitToAdd.StaffID = this.staffID; debitToAdd.MemberID = this.memberID; debitToAdd.Credit = 0; debitToAdd.Debit = number; debitToAdd.Details = textBoxDetails.Text; debitToAdd.Date = DateTime.Now; decimal?runTotal = 0m; var runningTotal = (from dc in context.DebitSystems where dc.MemberID == this.memberID select dc).ToList(); if (runningTotal.Any()) { runTotal = runningTotal.Last().RunningTotal - number; } else { runTotal = 0 - number; } debitToAdd.RunningTotal = runTotal; context.DebitSystems.Add(debitToAdd); context.SaveChanges(); Logging.AddLogEntry(staffID, Logging.ErrorCodes.Broadcast, Logging.RefreshCodes.DebitCredit, "Debit for member - " + MiscStuff.GetMemberName(memberID) + " of $" + number + " Added", false); } } } catch (Exception ex) { Logging.AddLogEntry(staffID, Logging.ErrorCodes.Error, Logging.RefreshCodes.None, "Debit / Credit not added - " + ex.Message, false); MessageBox.Show(MiscStuff.GetAllMessages(ex)); } textBoxCredit.Text = ""; textBoxDebit.Text = ""; textBoxDetails.Text = ""; this.debitSystemTableAdapter.FillByMemberID(this.lorikeetAppDataSet.DebitSystem, memberID); }