Skip to content

Commit

Permalink
Add Error Check in GUI
Browse files Browse the repository at this point in the history
  • Loading branch information
randomCharacter committed Jul 14, 2018
1 parent 6f668ec commit 1f10393
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions EnigmaGUI/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ private static int[] BuildPlugboardCipher(string code)

return cipher;
}
protected void SelectPlugboard(object sender, EventArgs e)

private void SelectPlugboard(object sender, EventArgs e)
{

var value = ((ComboBox)sender).Name;
Expand All @@ -174,14 +174,28 @@ protected void SelectPlugboard(object sender, EventArgs e)
}
}

protected string GetPlugboardString()
private string GetPlugboardString()
{
ComboBox[] boxes = { A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z };
return boxes.Aggregate("", (current, box) => current + (box.ActiveText ?? box.Name));
}

protected void ButtonClick(object sender, EventArgs e)
private bool ErrorsFound()
{
return (rotorLeftType.ActiveText == rotorCenterType.ActiveText) ||
(rotorLeftType.ActiveText == rotorRightType.ActiveText) ||
(rotorRightType.ActiveText == rotorCenterType.ActiveText);
}

private void ButtonClick(object sender, EventArgs e)
{
if (ErrorsFound())
{
var errorMessage = new MessageDialog(this, DialogFlags.DestroyWithParent, MessageType.Error, ButtonsType.None,
"Wrong pararameters\nOne rotor can not be used twice");
errorMessage.ShowAll();
return;
}
BuildRotors();
var left = AssignRotor(rotorLeftType.ActiveText);
var center = AssignRotor(rotorCenterType.ActiveText);
Expand Down Expand Up @@ -224,4 +238,4 @@ protected void ButtonClick(object sender, EventArgs e)
var res = messageLetters.Aggregate("", (current, t) => current + (char) (machine.Convert(t - 'A') + 'A'));
outputText.Buffer.Text = res;
}
}
}

0 comments on commit 1f10393

Please sign in to comment.