diff --git a/WindowsFormsCore/Form1.cs b/WindowsFormsCore/Form1.cs index bef7404..5e7680d 100644 --- a/WindowsFormsCore/Form1.cs +++ b/WindowsFormsCore/Form1.cs @@ -56,27 +56,31 @@ namespace WindowsFormsCore Random rnd = new CryptoRandom(DateTime.Now.DayOfYear); private Lotto lotto; private List clicked; - private byte numClicks = 0; private bool clearing; + private TextBox[] txtBGrp1 = new TextBox[7]; + private TextBox[] txtBGrp2 = new TextBox[7]; public Form1() { InitializeComponent(); lotto = new Lotto(rnd); ClearChks(); + for(int i = 0; i < txtBGrp1.Count(); i++) + { + txtBGrp1[i] = (TextBox)this.Controls["txtNr" + (i + 1).ToString()]; + txtBGrp2[i] = (TextBox)this.Controls["txtNr2" + (i + 1).ToString()]; + } } private void btnGenerate_Click(object sender, EventArgs e) { var ansver = lotto.RandomRad(); - txtNr1.Text = ansver[0]; - txtNr2.Text = ansver[1]; - txtNr3.Text = ansver[2]; - txtNr4.Text = ansver[3]; - txtNr5.Text = ansver[4]; - txtNr6.Text = ansver[5]; - txtNr7.Text = ansver[6]; + for (int i = 0; i < txtBGrp1.Count(); i++) + { + txtBGrp1[i].Text = ansver[i]; + } + } private string randomNum() @@ -89,20 +93,12 @@ namespace WindowsFormsCore lblIndicator.BackColor = SystemColors.Control; lblIndicator.Text = " "; List jmfList = new List(); - txtNr21.Text = string.IsNullOrEmpty(txtNr1.Text) ? "" : lotto.AntiCircularValue(int.Parse(txtNr1.Text)).ToString(); - jmfList.Add(txtNr21.Text); - txtNr22.Text = string.IsNullOrEmpty(txtNr2.Text) ? "" : lotto.AntiCircularValue(int.Parse(txtNr2.Text)).ToString(); - jmfList.Add(txtNr22.Text); - txtNr23.Text = string.IsNullOrEmpty(txtNr3.Text) ? "" : lotto.AntiCircularValue(int.Parse(txtNr3.Text)).ToString(); - jmfList.Add(txtNr23.Text); - txtNr24.Text = string.IsNullOrEmpty(txtNr4.Text) ? "" : lotto.AntiCircularValue(int.Parse(txtNr4.Text)).ToString(); - jmfList.Add(txtNr24.Text); - txtNr25.Text = string.IsNullOrEmpty(txtNr5.Text) ? "" : lotto.AntiCircularValue(int.Parse(txtNr5.Text)).ToString(); - jmfList.Add(txtNr25.Text); - txtNr26.Text = string.IsNullOrEmpty(txtNr6.Text) ? "" : lotto.AntiCircularValue(int.Parse(txtNr6.Text)).ToString(); - jmfList.Add(txtNr26.Text); - txtNr27.Text = string.IsNullOrEmpty(txtNr7.Text) ? "" : lotto.AntiCircularValue(int.Parse(txtNr7.Text)).ToString(); - jmfList.Add(txtNr27.Text); + + for (int i = 0; i < txtBGrp1.Count(); i++) + { + txtBGrp2[i].Text = string.IsNullOrEmpty(txtNr1.Text) ? "" : lotto.AntiCircularValue(int.Parse(txtBGrp1[i].Text)).ToString(); + jmfList.Add(txtBGrp2[i].Text); + } jmfList.Sort(); var prev = string.Empty; @@ -145,48 +141,9 @@ namespace WindowsFormsCore if (clicked.Count() > 6) { - - for (int i = 0; i < 7; i++) { - switch (i + 1) - { - case 1: - { - txtNr1.Text = clicked[i]; - break; - } - case 2: - { - txtNr2.Text = clicked[i]; - break; - } - case 3: - { - txtNr3.Text = clicked[i]; - break; - } - case 4: - { - txtNr4.Text = clicked[i]; - break; - } - case 5: - { - txtNr5.Text = clicked[i]; - break; - } - case 6: - { - txtNr6.Text = clicked[i]; - break; - } - case 7: - { - txtNr7.Text = clicked[i]; - break; - } - } + txtBGrp1[i].Text = clicked[i]; } ClearChks(); } @@ -204,7 +161,6 @@ namespace WindowsFormsCore } } clicked = new List(); - numClicks = 0; clearing = false; }