Ejemplo n.º 1
0
        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());
        }
Ejemplo n.º 2
0
 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";
     }
 }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
 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";
     }
 }