Készen van

This commit is contained in:
István Priskin 2023-04-25 18:19:52 +02:00
parent 53f8f61691
commit 6ddb24344c
2 changed files with 64 additions and 12 deletions

View File

@ -30,7 +30,7 @@ namespace LottoGUI
private void InitializeComponent()
{
this.button1 = new System.Windows.Forms.Button();
this.label1 = new System.Windows.Forms.Label();
this.SorsolasCimke = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.button2 = new System.Windows.Forms.Button();
@ -47,14 +47,14 @@ namespace LottoGUI
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// label1
// SorsolasCimke
//
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.label1.Location = new System.Drawing.Point(30, 87);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(416, 53);
this.label1.TabIndex = 1;
this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
this.SorsolasCimke.Font = new System.Drawing.Font("Microsoft Sans Serif", 26.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.SorsolasCimke.Location = new System.Drawing.Point(30, 87);
this.SorsolasCimke.Name = "SorsolasCimke";
this.SorsolasCimke.Size = new System.Drawing.Size(416, 53);
this.SorsolasCimke.TabIndex = 1;
this.SorsolasCimke.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
//
// label2
//
@ -80,6 +80,7 @@ namespace LottoGUI
this.button2.TabIndex = 4;
this.button2.Text = "Ellenőrzés";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
//
// label3
//
@ -99,7 +100,7 @@ namespace LottoGUI
this.Controls.Add(this.button2);
this.Controls.Add(this.textBox1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Controls.Add(this.SorsolasCimke);
this.Controls.Add(this.button1);
this.Name = "Form1";
this.Text = "LottóGUI alkalmazás";
@ -111,7 +112,7 @@ namespace LottoGUI
#endregion
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label SorsolasCimke;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Button button2;

View File

@ -12,6 +12,7 @@ namespace LottoGUI
{
public partial class Form1 : Form
{
int[] sorsoltak = new int[5];
public Form1()
{
InitializeComponent();
@ -19,14 +20,64 @@ namespace LottoGUI
private void button1_Click(object sender, EventArgs e)
{
int[] sorsoltak = new int[5];
Random rd = new Random();
for (int i = 0; i < 5; i++)
{
bool marvan;
do
{
sorsoltak[i] = rd.Next(1,91);
marvan = false;
for (int j = 0; j < i; j++)
{
marvan = marvan || (sorsoltak[j] == sorsoltak[i]);
}
} while (marvan);
}
} while (true);
Array.Sort(sorsoltak);
SorsolasCimke.Text = $"{sorsoltak[0]} {sorsoltak[1]} {sorsoltak[2]} {sorsoltak[3]} {sorsoltak[4]}";
}
private void button2_Click(object sender, EventArgs e)
{
string beirva = textBox1.Text;
string[] szamok = beirva.Split(';');
if( szamok.Length != 5)
{
label3.Text = "Nem öt értéket adott meg vagy nem jó a választókarakter!";
} else
{
int talalat = 0;
for (int i = 0; i < 5; i++)
{
try
{
int lsz = int.Parse(szamok[i]);
if (lsz<1 || lsz>90)
{
label3.Text = $"Az {i + 1}. szám nem 1-90 közötti!";
talalat = -1;
break;
} else
{
foreach (int s in sorsoltak)
{
if (s == lsz) talalat++;
}
}
}
catch (Exception)
{
label3.Text = $"Az {i+1}. érték nem szám!";
talalat = -1;
break;
}
}
if (talalat>-1) label3.Text = "Találatok száma: " + talalat;
}
}
}