ProgaOra/20240327/WindowsFormsApp1/Form1.cs

137 lines
3.9 KiB
C#
Raw Normal View History

2024-03-27 11:03:03 +00:00
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void label1_Click(object sender, EventArgs e)
{
}
private void radioButton1_CheckedChanged(object sender, EventArgs e)
{
MaleCheck();
2024-04-02 11:06:17 +00:00
Category();
2024-03-27 11:03:03 +00:00
}
private void radioButton2_CheckedChanged(object sender, EventArgs e)
{
MaleCheck();
2024-04-02 11:06:17 +00:00
Category();
2024-03-27 11:03:03 +00:00
}
private void textBox1_TextChanged(object sender, EventArgs e)
{
2024-04-02 11:06:17 +00:00
bool noletters = textBox1.Text.Any(x => !char.IsLetter(x));
if (textBox1.Text != "" && noletters)
{
Data.kg = Convert.ToDouble(textBox1.Text);
UpdateIndex();
Category();
}
2024-03-27 11:03:03 +00:00
}
private void textBox2_TextChanged(object sender, EventArgs e)
{
2024-04-02 11:06:17 +00:00
bool noletters = textBox2.Text.Any(x => !char.IsLetter(x));
if (textBox2.Text != "" && noletters)
{
Data.m = Convert.ToDouble(textBox2.Text) / 100;
UpdateIndex();
Category();
}
2024-03-27 11:03:03 +00:00
}
public void UpdateIndex()
{
2024-04-02 11:06:17 +00:00
if (Data.index != null && Data.m != null && Data.m != 0)
2024-03-27 11:03:03 +00:00
{
Data.index = Data.kg / (Data.m * Data.m);
}
}
public void Category()
{
if (Data.male)
{
switch (Data.index)
{
case double n when n < 20.7:
label3.Text = $"BMI:{n}\nSovány";
break;
case double n when n >= 20.7 && n < 27.8:
label3.Text = $"BMI:{n}\nNormális";
break;
case double n when n >= 27.8 && n < 32.3:
label3.Text = $"BMI:{n}\nTúlsúlyos";
break;
case double n when n >= 32.3 && n < 45.4:
label3.Text = $"BMI:{n}\nKomolyan Túlsúlyos";
break;
case double n when n >= 45.4:
label3.Text = $"BMI:{n}\nVeszélyeztetett";
break;
default:
break;
}
}
else
{
switch (Data.index)
{
case double n when n < 19.1:
label3.Text = $"BMI:{n}\nSovány";
break;
2024-04-02 11:06:17 +00:00
case double n when n >= 19.1 && n < 27.3:
2024-03-27 11:03:03 +00:00
label3.Text = $"BMI:{n}\nNormális";
break;
2024-04-02 11:06:17 +00:00
case double n when n >= 27.3 && n < 31.1:
2024-03-27 11:03:03 +00:00
label3.Text = $"BMI:{n}\nTúlsúlyos";
break;
2024-04-02 11:06:17 +00:00
case double n when n >= 31.1 && n < 44.8:
2024-03-27 11:03:03 +00:00
label3.Text = $"BMI:{n}\nKomolyan Túlsúlyos";
break;
2024-04-02 11:06:17 +00:00
case double n when n >= 44.8:
2024-03-27 11:03:03 +00:00
label3.Text = $"BMI:{n}\nVeszélyeztetett";
break;
default:
break;
}
}
}
public void MaleCheck()
{
if (radioButton1.Checked)
{
Data.male = true;
}
else
{
Data.male = false;
}
}
}
public static class Data{
public static double kg;
public static double m;
public static double index;
public static bool male;
}
}