private void EnterNoOfCounters() { int countersNumberParsed = 0; if (checkboxInputAsWords.Checked == false) { countersNumberParsed = converter.ReadDataAsNumbers(textboxInputNumber.Text); } else { countersNumberParsed = converter.ReadDataAsWords(textboxInputNumber.Text.ToLower()); } if (countersNumberParsed != 0) { this.numberOfCounters = countersNumberParsed; consoleBox.AppendText($"\r\nNumber of counters: {countersNumberParsed}"); buttonSubmitNumberOf.Enabled = false; textboxInputNumber.Enabled = false; checkboxInputAsWords.Enabled = false; labelEnterNumberLabel.Enabled = false; labelSetupCounter.Enabled = true; labelCurrentCounter.Enabled = true; buttonSubmitSetup.Enabled = true; labelDelay.Enabled = true; textboxDelay.Enabled = true; labelEndValue.Enabled = true; textboxEndValue.Enabled = true; labelCurrentCounter.Visible = true; labelCurrentCounter.Text = $"1 of {countersNumberParsed}"; } }
private int EnterNumberOfCounters() //this method does 2 things, doesnt it? (select type & enter number) { MyConverter.Operation converter = new MyConverter.Operation(); //create new Converter to convert user input (numeric or word) to integer converter.alertFromConverter += OnAlertFromConverter; //subscribe to converter's alert msgs bool useNumbers = false; Console.Write("Press a key to select input type:\r\n" + "1. Numeric\r\n" + "2. Words\r\n" + ">"); ConsoleKeyInfo choice; do { choice = Console.ReadKey(); switch (choice.KeyChar) { case '1': useNumbers = true; break; case '2': useNumbers = false; break; case (char)27: //"esc" key return(0); //so here you exit the loop by 'ESC' key... but below you need to type 'exit'? default: Console.Write("\r\nError. There is no such option. Try again or press \"Esc\" to exit program.\r\n>"); break; } } while ((choice.KeyChar != '1') && (choice.KeyChar != '2')); Console.Write("\r\n\r\nInput number of counters:\r\n>"); int countersNumberParsed = 0; do { string countersNumberGivenByUser = Console.ReadLine(); if (countersNumberGivenByUser.ToLower() == "exit") //see above for the 'escape loop' logic { return(0); } //how about change it a bit to a 'if - else' logic? if (useNumbers) { countersNumberParsed = converter.ReadDataAsNumbers(countersNumberGivenByUser); } else { countersNumberParsed = converter.ReadDataAsWords(countersNumberGivenByUser.ToLower()); } } while (countersNumberParsed == 0); //it's cool that you allow retry rather than kill the app if user makes a mistake:) return(countersNumberParsed); }
private void EnterNoOfCounters() { int countersNumberParsed = 0; if (checkboxInputAsWords.Checked == checkboxInputAsRomanNumber.Checked) { countersNumberParsed = converter.ReadDataAsNumbers(textboxInputNumber.Text); } else if (checkboxInputAsWords.Checked == true) { countersNumberParsed = converter.ReadDataAsWords(textboxInputNumber.Text.ToLower()); } else { countersNumberParsed = converter.RomanToInteger(textboxInputNumber.Text.ToLower()); } if (countersNumberParsed != 0) { this.numberOfCounters = countersNumberParsed; consoleBox.AppendText($"\r\nNumber of counters: {countersNumberParsed}"); //what if your UI becomes bigger? //this set true/false becomes unmanageable... buttonSubmitNumberOf.Enabled = false; textboxInputNumber.Enabled = false; checkboxInputAsWords.Enabled = false; labelEnterNumberLabel.Enabled = false; labelSetupCounter.Enabled = true; labelCurrentCounter.Enabled = true; buttonSubmitSetup.Enabled = true; labelDelay.Enabled = true; textboxDelay.Enabled = true; labelEndValue.Enabled = true; textboxEndValue.Enabled = true; labelCurrentCounter.Visible = true; labelCurrentCounter.Text = $"1 of {countersNumberParsed}"; } }