Saqlashdan oldin kiritilgan qiymati avtomatik hisoblash c #

Men Saqlash ni bosishdan oldin BMI natijasini balandlik va vazn qiymatlari matn qutisiga kiritilganidan keyin ko'rsatishga harakat qilaman. Nima qilishim kerak?

protected void btnSave_Click(object sender, EventArgs e)
{     
    Boolean transSuccess = false;      
    String myScript = "";       
    String sqlStmt = "";      

    OracleConnection conOra = new OracleConnection(conOraStr);
    conOra.Open();
    OracleTransaction transOra;
    transOra = conOra.BeginTransaction();

    double weight = Convert.ToDouble(txtWeight.Text);
    double height = Convert.ToDouble(txtHeight.Text);
    double bmi; 

    bmi = Math.Round(( weight/( height * height))* 10000, 1);
    lblbmi.Text = String.Format(bmi.ToString(),"0,0");
}
2
txtWeight va txtHeight matn kutubxonalarida change hodisalarini yaratishga harakat qildingizmi va u erda lblbmi kodini yangilashni xohlaysizmi?
qo'shib qo'ydi muallif MaKCbIMKo, manba
Buni qilishning eng oson usuli.
qo'shib qo'ydi muallif MaKCbIMKo, manba
Buni qilishning eng oson usuli.
qo'shib qo'ydi muallif MaKCbIMKo, manba
Buni qilishning eng oson usuli.
qo'shib qo'ydi muallif MaKCbIMKo, manba
Yaxshi va mas'uliyatli bo'lsa-da, bu juda muhim savol. Men bu savolni fikrga asoslangan holda yopish uchun ovoz beraman.
qo'shib qo'ydi muallif Amit Joshi, manba
Yaxshi va mas'uliyatli bo'lsa-da, bu juda muhim savol. Men bu savolni fikrga asoslangan holda yopish uchun ovoz beraman.
qo'shib qo'ydi muallif Amit Joshi, manba
Yaxshi va mas'uliyatli bo'lsa-da, bu juda muhim savol. Men bu savolni fikrga asoslangan holda yopish uchun ovoz beraman.
qo'shib qo'ydi muallif Amit Joshi, manba

6 javoblar

Bu tez yozish, siz uni kodingizga qo'shishingiz kerak bo'ladi.

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
    double height;
    double weight;
    double bmi;


    public Form1()
    {
        InitializeComponent();
    }


    private void calculate()
    {
        bmi = Math.Round((weight/(height * height)) * 10000, 1);

    }
    private void updateResult()
    {
        calculatedLabel.Text = String.Format(bmi.ToString(), "0,0"); ;
    }
    private void weightTxtbx_TextChanged(object sender, EventArgs e)
    {
        try
        {
            weight = Convert.ToDouble(weightTxtbx.Text);
        }
        catch
        {
           //stop app from crashing if input is not a number
        }
        calculate();
        updateResult();
    }

    private void heightTxtbx_TextChanged(object sender, EventArgs e)
    {
        try
        {
            height = Convert.ToDouble(heightTxtbx.Text);
        }
        catch
        {
           //stop app from crashing if input is not a number
        }
        calculate();
        updateResult();
    }
}
}
0
qo'shib qo'ydi

Bu tez yozish, siz uni kodingizga qo'shishingiz kerak bo'ladi.

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
    double height;
    double weight;
    double bmi;


    public Form1()
    {
        InitializeComponent();
    }


    private void calculate()
    {
        bmi = Math.Round((weight/(height * height)) * 10000, 1);

    }
    private void updateResult()
    {
        calculatedLabel.Text = String.Format(bmi.ToString(), "0,0"); ;
    }
    private void weightTxtbx_TextChanged(object sender, EventArgs e)
    {
        try
        {
            weight = Convert.ToDouble(weightTxtbx.Text);
        }
        catch
        {
           //stop app from crashing if input is not a number
        }
        calculate();
        updateResult();
    }

    private void heightTxtbx_TextChanged(object sender, EventArgs e)
    {
        try
        {
            height = Convert.ToDouble(heightTxtbx.Text);
        }
        catch
        {
           //stop app from crashing if input is not a number
        }
        calculate();
        updateResult();
    }
}
}
0
qo'shib qo'ydi

Bu tez yozish, siz uni kodingizga qo'shishingiz kerak bo'ladi.

using System;
using System.Windows.Forms;

namespace WindowsFormsApp1
{
public partial class Form1 : Form
{
    double height;
    double weight;
    double bmi;


    public Form1()
    {
        InitializeComponent();
    }


    private void calculate()
    {
        bmi = Math.Round((weight/(height * height)) * 10000, 1);

    }
    private void updateResult()
    {
        calculatedLabel.Text = String.Format(bmi.ToString(), "0,0"); ;
    }
    private void weightTxtbx_TextChanged(object sender, EventArgs e)
    {
        try
        {
            weight = Convert.ToDouble(weightTxtbx.Text);
        }
        catch
        {
           //stop app from crashing if input is not a number
        }
        calculate();
        updateResult();
    }

    private void heightTxtbx_TextChanged(object sender, EventArgs e)
    {
        try
        {
            height = Convert.ToDouble(heightTxtbx.Text);
        }
        catch
        {
           //stop app from crashing if input is not a number
        }
        calculate();
        updateResult();
    }
}
}
0
qo'shib qo'ydi

Mana buni qilishingiz mumkin

protected void txtWeight_TextChanged(object sender, EventArgs e)
  {     
    Boolean transSuccess = false;      
    String myScript = "";       
    String sqlStmt = "";      

    OracleConnection conOra = new OracleConnection(conOraStr);
    conOra.Open();
    OracleTransaction transOra;
    transOra = conOra.BeginTransaction();

        double weight = Convert.ToDouble(txtWeight.Text);
        double height = Convert.ToDouble(txtHeight.Text);
        double bmi; 

        bmi=Math.Round(( weight/( height * height))* 10000, 1);

        lblbmi.Text= String.Format(bmi.ToString(),"0,0");
  }
protected void txtHeight_TextChanged(object sender, EventArgs e)
  {     
    Boolean transSuccess = false;      
    String myScript = "";       
    String sqlStmt = "";      

    OracleConnection conOra = new OracleConnection(conOraStr);
    conOra.Open();
    OracleTransaction transOra;
    transOra = conOra.BeginTransaction();

        double weight = Convert.ToDouble(txtWeight.Text);
        double height = Convert.ToDouble(txtHeight.Text);
        double bmi; 

        bmi=Math.Round(( weight/( height * height))* 10000, 1);

        lblbmi.Text= String.Format(bmi.ToString(),"0,0");
  }
0
qo'shib qo'ydi
Bu yomon, qiymat har bir o'zgarganda, u JB ulanish o'rnatadi ...
qo'shib qo'ydi muallif SoyDuck, manba
Ha. Lekin men faqatgina ishlash uchun namuna bo'ldim. Hali ham tahnklar
qo'shib qo'ydi muallif Zahid Mustafa, manba

Mana buni qilishingiz mumkin

protected void txtWeight_TextChanged(object sender, EventArgs e)
  {     
    Boolean transSuccess = false;      
    String myScript = "";       
    String sqlStmt = "";      

    OracleConnection conOra = new OracleConnection(conOraStr);
    conOra.Open();
    OracleTransaction transOra;
    transOra = conOra.BeginTransaction();

        double weight = Convert.ToDouble(txtWeight.Text);
        double height = Convert.ToDouble(txtHeight.Text);
        double bmi; 

        bmi=Math.Round(( weight/( height * height))* 10000, 1);

        lblbmi.Text= String.Format(bmi.ToString(),"0,0");
  }
protected void txtHeight_TextChanged(object sender, EventArgs e)
  {     
    Boolean transSuccess = false;      
    String myScript = "";       
    String sqlStmt = "";      

    OracleConnection conOra = new OracleConnection(conOraStr);
    conOra.Open();
    OracleTransaction transOra;
    transOra = conOra.BeginTransaction();

        double weight = Convert.ToDouble(txtWeight.Text);
        double height = Convert.ToDouble(txtHeight.Text);
        double bmi; 

        bmi=Math.Round(( weight/( height * height))* 10000, 1);

        lblbmi.Text= String.Format(bmi.ToString(),"0,0");
  }
0
qo'shib qo'ydi
Bu yomon, qiymat har bir o'zgarganda, u JB ulanish o'rnatadi ...
qo'shib qo'ydi muallif SoyDuck, manba
Ha. Lekin men faqatgina ishlash uchun namuna bo'ldim. Hali ham tahnklar
qo'shib qo'ydi muallif Zahid Mustafa, manba

Mana buni qilishingiz mumkin

protected void txtWeight_TextChanged(object sender, EventArgs e)
  {     
    Boolean transSuccess = false;      
    String myScript = "";       
    String sqlStmt = "";      

    OracleConnection conOra = new OracleConnection(conOraStr);
    conOra.Open();
    OracleTransaction transOra;
    transOra = conOra.BeginTransaction();

        double weight = Convert.ToDouble(txtWeight.Text);
        double height = Convert.ToDouble(txtHeight.Text);
        double bmi; 

        bmi=Math.Round(( weight/( height * height))* 10000, 1);

        lblbmi.Text= String.Format(bmi.ToString(),"0,0");
  }
protected void txtHeight_TextChanged(object sender, EventArgs e)
  {     
    Boolean transSuccess = false;      
    String myScript = "";       
    String sqlStmt = "";      

    OracleConnection conOra = new OracleConnection(conOraStr);
    conOra.Open();
    OracleTransaction transOra;
    transOra = conOra.BeginTransaction();

        double weight = Convert.ToDouble(txtWeight.Text);
        double height = Convert.ToDouble(txtHeight.Text);
        double bmi; 

        bmi=Math.Round(( weight/( height * height))* 10000, 1);

        lblbmi.Text= String.Format(bmi.ToString(),"0,0");
  }
0
qo'shib qo'ydi
Bu yomon, qiymat har bir o'zgarganda, u JB ulanish o'rnatadi ...
qo'shib qo'ydi muallif SoyDuck, manba
Ha. Lekin men faqatgina ishlash uchun namuna bo'ldim. Hali ham tahnklar
qo'shib qo'ydi muallif Zahid Mustafa, manba