static void Main(string[] args) { Context context = new Context(); StartState start = new StartState(); StopState stop = new StopState(); start.Action(context); Console.WriteLine(context.getState()); stop.Action(context); Console.WriteLine(context.getState()); }
private void bt_Transaction_Click(object sender, EventArgs e) { try { double amount = Convert.ToDouble(tb_Amount.Text); double currentAmount = Convert.ToDouble(tb_Balance.Text); if (ctxt.getState() is StateDeposit) { currentAmount += amount; } else { if (currentAmount - amount >= 0) { currentAmount -= amount; } else { tb_Amount.Text = @"Balance can't be negative"; } } tb_Balance.Text = currentAmount.ToString(); } catch (FormatException exc) { tb_Amount.Text = @"Only numbers are allowed"; } }
static void Main(string[] args) { Context context = new Context(); StartState startState = new StartState(); startState.doAction(context); Console.WriteLine(context.getState().description()); StopState stopState = new StopState(); stopState.doAction(context); Console.WriteLine(context.getState().description()); Console.Read(); }
public void CheckState(Context cxt) { if (cxt.getState() is StateDeposit) { Text = "Bank Transaction - Deposit"; bt_Transaction.Text = "Deposit"; } else { Text = "Bank Transaction - Withdraw"; bt_Transaction.Text = "Withdraw"; } }