vendredi 18 novembre 2016

appy formula depending on sql id

i have a c# winforms app with makes some calculations based on a formula. the formula runs OK but depending on the value of an sql table the formula can change. I was thinking of appying IF´s, but if i do i click the button and the formula does nothing. I removed a large quantity of code to facilitade viewing.

    private void button1_Click(object sender, EventArgs e) //formula
            {
                decimal ValueFromDB;
                con.Open();
                using (SqlCommand cmd = new SqlCommand("select prumos from dbo.modelos where id = '" + prumos + "'", con))
                {
                    cmd.Parameters.AddWithValue("@ID", prumos);
                    ValueFromDB = decimal.Parse(cmd.ExecuteScalar().ToString());
                    con.Close();
                }
                if (larg.Text == string.Empty)
                {
                    MessageBox.Show("Missing Value", "Warning");
                    return;
//SEVERAL OTHER IF´s to prevent empty textboxes
                }        
        else if (prumos == "1")
        {
            return;
        }    
                decimal uw;                    
                decimal ata;                 
                decimal vi1;
...
                decimal wmk4;
                decimal wmk5;
                decimal wmk6;


                vi1 = decimal.Parse(textBox1.Text);
                wmk3 = decimal.Parse(textBox12.Text);
                wmk4 = decimal.Parse(textBox22.Text);
...
                wmk5 = decimal.Parse(textBox17.Text);
                wmk6 = decimal.Parse(textBox15.Text);
...                     
                uw = (adp * ufa + adv * ug + perv * wmk) / ac;
                answ.Text = (Math.Truncate(uw * 100) / 100).ToString();
 {
        **else if (prumos == "2")**
        {
            return;
        }    

ETC...

Any ideas?

Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire