コード例 #1
0
ファイル: MainProgram.cs プロジェクト: CHG1731/ATM
 private String biljetSelection(int amount)
 {
     String choice = "00,00,00,*";
     String option1 = "invalid";
     String option2 = "invalid";
     String option3 = "invalid";
     String option4 = "invalid";
     Boolean validInput = false;
     int selection = 0;
     int tens = 0;
     int twenties = 0;
     int fifties = 0;
     BiljetScreen selector = new BiljetScreen();
     tens = amount / 10;
     if (stock.checkIfAvailable(tens, twenties, fifties))
     {
         selector.setLabel1(tens.ToString());
         if (tens > 9) { option1 = tens.ToString() + ",00,00,*"; }
         else { option1 = "0" + tens.ToString() + ",00,00,*"; }
     }
     if (amount % 20 == 0)
     {
         twenties = (amount / 20);
         tens = 0;
         fifties = 0;
         option2 = generateCommand(tens, twenties, fifties);
     }
     else
     {
         twenties = (amount - (amount % 20)) / 20;
         tens = 1;
         fifties = 0;
         option2 = generateCommand(tens, twenties, fifties);
     }
     if (!(option2.Equals("invalid")))
     {
         selector.setLabel2(tens.ToString(), twenties.ToString());
     }
     if (amount >= 50 && amount % 50 == 0)
     {
         tens = 0;
         twenties = 0;
         fifties = amount / 50;
         option3 = generateCommand(tens, twenties, fifties);
         if (!(option3.Equals("invalid")))
         {
             selector.setLabel3(tens.ToString(), fifties.ToString());
         }
     }
     else if (amount >= 60)
     {
         tens = (amount % 50) / 10;
         twenties = 0;
         fifties = (amount - (amount % 50)) / 50;
         option3 = generateCommand(tens, twenties, fifties);
         if (!(option3.Equals("invalid")))
         {
             selector.setLabel3(tens.ToString(), fifties.ToString());
         }
         if (((amount % 50) % 20) == 0)
         {
             twenties = ((amount % 50) % 20) / 20;
             tens = 0;
         }
         else if (amount % 50 == 30)
         {
             twenties = 1;
             tens = 1;
         }
         option4 = generateCommand(tens, twenties, fifties);
         if (!(option4.Equals("invalid")))
         {
             selector.setLabel4(tens.ToString(), twenties.ToString(), fifties.ToString());
         }
     }
     selector.Show();
     if (option1.Equals("invalid") && option2.Equals("invalid") && option3.Equals("invalid") && option4.Equals("invalid"))
     {
         selector.showInsufficient();
     }
     else
     {
         //Error.show(option1 + " " + option2 + " " + option3 + "" + option4);
         while (validInput == false)
         {
             selection = arduino.getChoice();
             if (selection == 1 && !(option1.Equals("invalid"))) { validInput = true; }
             else if (selection == 2 && !(option2.Equals("invalid"))) { validInput = true; }
             else if (selection == 3 && !(option3.Equals("invalid"))) { validInput = true; }
             else if (selection == 5 && !(option4.Equals("invalid"))) { validInput = true; }
             else if (selection == 4)
             {
                 cancelled = true;
                 break;
             }
         }
         switch (selection)
         {
             case 1:
                 choice = option1;
                 break;
             case 2:
                 choice = option2;
                 break;
             case 3:
                 choice = option3;
                 break;
             case 5:
                 choice = option4;
                 break;
         }
     }
     selector.Hide();
     //Error.show(choice);
     return choice;
 }
コード例 #2
0
ファイル: MainProgram.cs プロジェクト: CHG1731/ATM
    private void pin()
    {
        Boolean printTicket = false;
        Boolean goBack = true;
        int amount = 0;
        String input;
        String dispenserCommand = "00,00,00,*";
        cancelled = false;

        while (goBack == true)
        {
            pinsherm.Show();
            while (true)
            {
                input = arduino.getString();
                if (input.Contains("1"))
                {
                    amount = 10;
                    break;
                }
                else if (input.Contains("2"))
                {
                    amount = 20;
                    break;
                }
                else if (input.Contains("3"))
                {
                    amount = 50;
                    break;
                }
                else if (input.Contains("4"))
                {
                    amount = getAlternativeAmount();
                    break;
                }
                else if (input.Contains("#"))
                {
                    cancelled = true;
                    break;
                }
                else if (input.Contains("C"))
                {
                    cancelled = true;
                    endOfSession = false;
                    break;
                }
            }
            pinsherm.Hide();
            if ((amount > saldo && amount != 0) || amount >= 200)
            {
                PinError pinError = new PinError();
                cancelled = true;
            }
            if (cancelled == true)
            {
                break;
            }
            if (amount == 10 && stock.checkIfAvailable(1, 0 , 0) == true)
            {
                dispenserCommand = "01,00,00,*";
            }
            else if(amount == 10)
            {
                BiljetScreen selector = new BiljetScreen();
                selector.showInsufficient();
                cancelled = true;
            }
            if (amount > 10)
            {
                dispenserCommand = biljetSelection(amount);
                if (dispenserCommand.Equals("00,00,00,*"))
                {
                    cancelled = true;
                    break;
                }
            }
            if (cancelled == true) { break; }
            uploadConnection.UpdateBalans(rekeningID, (saldo - amount*100));
            uploadConnection.transaction(pasID, rekeningID, amount);
            asker.Show();
            while (true)
            {
                input = arduino.getString();
                if (input.Contains("*"))
                {
                    printTicket = true;
                    goBack = false;
                    break;
                }
                else if (input.Contains("#"))
                {
                    goBack = false;
                    break;
                }
                else if (input.Contains("A"))
                {
                    Email mailer = new Email(userName, amount, rekeningID,klantID);
                    mailer.sendEmail();
                    goBack = false;
                    break;
                }
            }
            asker.Hide();
            stock.substractBiljets(dispenserCommand);
            arduino.dispenseMoney(dispenserCommand);
            if (printTicket == true)
            {
                Printer bonPrinter = new Printer(userName, amount, rekeningID);
                bonPrinter.printTicket();
            }
            if (goBack == false)
            {
                ByeScreen goAway = new ByeScreen();
            }
        }
    }