namespace BMI_Calculator.Repository
{
internal interface IRepository
{
string BMI(string Weight, string Height);
}
}using BMI_Calculator.Repository;
namespace BMI_Calculator.Services
{
internal class Myrepository : IRepository
{
public string BMI(string Weight, string Height)
{
decimal dWeight = Convert.ToDecimal(Weight);
decimal dHeight = Convert.ToDecimal(Height);
decimal BMI = dWeight / (dHeight * dHeight);
return BMI.ToString("0.00");
}
}
}
namespace BMI_Calculator
{
public partial class Form1 : Form
{
IRepository repo;
public Form1()
{
InitializeComponent();
repo = new Myrepository();
}
private void btnCalculate_Click(object sender, EventArgs e)
{
if (IsValid())
{
decimal dWeight = Convert.ToDecimal(numWeight.Value);
decimal dHeight = Convert.ToDecimal(numHeight.Value);
dHeight /= 100;
string result = repo.BMI(dWeight.ToString(), dHeight.ToString());
lblDisplayer.Text = result;
}
}
public bool IsValid()
{
if (numHeight.Value > 273 || numHeight.Value < 54)
{
MessageBox.Show("Enter a Real Height in cm", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
else if (numWeight.Value > 635 || numWeight.Value < 2)
{
MessageBox.Show("Enter a Real Weight in kg", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
}
else
{
return true;
}
}
}
}
عالی بود