Ejemplo n.º 1
0
 public float ConvertStringToFloat(string inputText)
 {
     Connect_to_sql conn = new Connect_to_sql();
     if (inputText != "")
     {
         float res = conn.RoundTo(Convert.ToDouble(inputText), 1);
         return res;
     }
     else return 0;
 }
Ejemplo n.º 2
0
        private void button2_Click_1(object sender, EventArgs e)
        {
            Connect_to_sql conn = new Connect_to_sql();
            string connect_string = conn.Con_str();
            float[] SrednVl = conn.GetSrednPovtorn(ras_param.Glav_ID, ras_param.sloj0_5, ras_param.marshrut, connect_string);
            TextBox[] stroka1 = GetTextBoxOb_massa_pochvi();
            TextBox[] stroka2 = GetTextBoxVl_ustoj_zav();
            TextBox[] stroka3 = GetTextBoxStroka3();
            TextBox[] stroka4 = GetTextBoxStroka4();
            TextBox[] stroka5 = GetTextBoxStroka5();
            Connect_to_sql.AgroDataSredn[] DataSred = new Connect_to_sql.AgroDataSredn[11];

            for (int i = 0; i < 11; i++)
            {
                stroka3[i].Text = conn.ConvertFloatToString(SrednVl[i]);
            }
            if (!ras_param.sloj0_5)
            {
                for (int i = 1; i < 11; i++)
                {
                    float str3 = conn.ConvertStringToFloat(stroka3[i].Text,1);
                    float str2 = conn.ConvertStringToFloat(stroka2[i].Text,2);
                    float str1 = conn.ConvertStringToFloat(stroka1[i].Text,2);
                    float srt_rez = (str3 - str2) * str1;
                    stroka4[i].Text = conn.ConvertFloatToString(conn.RoundTo(srt_rez, 1));
                }
                stroka5[1].Text = stroka4[1].Text;
                for (int i = 2; i < 11; i++)
                {
                    stroka5[i].Text = conn.ConvertFloatToString(conn.RoundTo((conn.ConvertStringToFloat(stroka5[i - 1].Text, 1) + conn.ConvertStringToFloat(stroka4[i].Text, 1)), 1));
                }
                for (int i = 1; i < 11; i++)
                {
                    DataSred[i].stroka3 = conn.ConvertStringToFloat(stroka3[i].Text,1);
                    DataSred[i].stroka4 = conn.ConvertStringToFloat(stroka4[i].Text,1);
                    DataSred[i].stroka5 = conn.ConvertStringToFloat(stroka5[i].Text,1);
                }
                conn.AddRowToSredn(DataSred, ras_param.sloj0_5, ras_param.Glav_ID, textBox133.Text, connect_string);

            }
            else
            {
                for (int i = 0; i < 11; i++)
                {
                    float str3 = conn.ConvertStringToFloat(stroka3[i].Text,1);
                    float str2 = conn.ConvertStringToFloat(stroka2[i].Text,2);
                    float str1 = conn.ConvertStringToFloat(stroka1[i].Text,2);
                    float srt_rez = (str3 - str2) * str1;
                    stroka4[i].Text = conn.ConvertFloatToString(conn.RoundTo(srt_rez, 1));
                }
                stroka4[0].Text = conn.ConvertFloatToString(conn.RoundTo((conn.ConvertStringToFloat(stroka4[0].Text, 1) / 2), 1));
                stroka4[1].Text = conn.ConvertFloatToString(conn.RoundTo((conn.ConvertStringToFloat(stroka4[1].Text, 1) / 2), 1));
                stroka5[0].Text = stroka4[0].Text;
                for (int i = 1; i < 11; i++)
                {
                    stroka5[i].Text = conn.ConvertFloatToString(conn.RoundTo((conn.ConvertStringToFloat(stroka5[i - 1].Text, 1) + conn.ConvertStringToFloat(stroka4[i].Text, 1)), 1));
                }
                for (int i = 0; i < 11; i++)
                {
                    DataSred[i].stroka3 = conn.ConvertStringToFloat(stroka3[i].Text, 1);
                    DataSred[i].stroka4 = conn.ConvertStringToFloat(stroka4[i].Text, 1);
                    DataSred[i].stroka5 = conn.ConvertStringToFloat(stroka5[i].Text, 1);
                }
                conn.AddRowToSredn(DataSred, ras_param.sloj0_5, ras_param.Glav_ID, textBox133.Text, connect_string);
            }
            float[] val = new float[10];
            for (int i = 0; i < 10; i++)
            {
                val[i] = conn.ConvertStringToFloat(stroka5[i + 1].Text, 1);
            }
            Connect_to_sql.ResultStepUvl[] res_step = conn.GetResultStepUvl(val, textBox133.Text, connect_string);
               /* for (int i = 0; i < 10; i++)
            {
                if(res_step[i].color!=0)
                stroka5[i + 1].BackColor = Color.FromArgb(res_step[i].color);
            }*/
            if (res_step[0].color != 0)
            {
                textBox137.BackColor = Color.FromArgb(res_step[0].color);
            }
            if (res_step[1].color != 0)
            {
                textBox138.BackColor = Color.FromArgb(res_step[1].color);
            }
            if (res_step[4].color != 0)
            {
                textBox139.BackColor = Color.FromArgb(res_step[4].color);
            }
            if (res_step[9].color != 0)
            {
                textBox140.BackColor = Color.FromArgb(res_step[9].color);
            }
        }
Ejemplo n.º 3
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                Connect_to_sql conn = new Connect_to_sql();
                string connect_string = conn.Con_str();
                TextBox[] stolbec1 = GetTextBoxVesVlazhPochvi();
                TextBox[] stolbec2 = GetTextBoxVesSuhojPochvi();
                TextBox[] stolbec3 = GetTextBoxVesStakan();
                TextBox[] stolbec4 = GetTextBoxPole4();
                TextBox[] stolbec5 = GetTextBoxPole5();
                TextBox[] stolbec6 = GetTextBoxPole6();
                TextBox[] stolbec7 = GetTextBoxPole7();
                for (int i = 0; i < 11; i++)
                {
                    stolbec1[i].Text = stolbec1[i].Text.Replace('.', ',');
                    stolbec2[i].Text = stolbec2[i].Text.Replace('.', ',');
                    stolbec3[i].Text = stolbec3[i].Text.Replace('.', ',');
                }
                if (!ras_param.sloj0_5)
                {
                    for (int i = 1; i < 11; i++)
                    {
                        stolbec4[i].Text = Convert.ToString(conn.RoundTo((Convert.ToDouble(stolbec1[i].Text) - Convert.ToDouble(stolbec2[i].Text)), 1));
                    }
                    for (int i = 1; i < 11; i++)
                    {
                        stolbec5[i].Text = Convert.ToString(conn.RoundTo((Convert.ToDouble(stolbec2[i].Text) - Convert.ToDouble(stolbec3[i].Text)), 1));
                    }
                    for (int i = 1; i < 11; i++)
                    {
                        stolbec6[i].Text = Convert.ToString(conn.RoundTo(((Convert.ToDouble(stolbec4[i].Text) / Convert.ToDouble(stolbec5[i].Text)) * 100), 1));
                    }
                    for (int i = 1; i < 11; i++)
                    {
                        stolbec7[i].Text = Convert.ToString(conn.RoundTo((Convert.ToDouble(stolbec1[i].Text) - Convert.ToDouble(stolbec3[i].Text)), 1));
                    }
                }
                else
                {
                    for (int i = 0; i < 11; i++)
                    {
                        stolbec4[i].Text = Convert.ToString(conn.RoundTo((Convert.ToDouble(stolbec1[i].Text) - Convert.ToDouble(stolbec2[i].Text)), 1));
                    }
                    for (int i = 0; i < 11; i++)
                    {
                        stolbec5[i].Text = Convert.ToString(conn.RoundTo((Convert.ToDouble(stolbec2[i].Text) - Convert.ToDouble(stolbec3[i].Text)), 1));
                    }
                    for (int i = 0; i < 11; i++)
                    {
                        stolbec6[i].Text = Convert.ToString(conn.RoundTo(((Convert.ToDouble(stolbec4[i].Text) / Convert.ToDouble(stolbec5[i].Text)) * 100), 1));
                    }
                    for (int i = 0; i < 11; i++)
                    {
                        stolbec7[i].Text = Convert.ToString(conn.RoundTo((Convert.ToDouble(stolbec1[i].Text) - Convert.ToDouble(stolbec3[i].Text)), 1));
                    }
                }

                Connect_to_sql.AgroDataPovt[] DataPovt = new Connect_to_sql.AgroDataPovt[11];
                for (int i = 0; i < 11; i++)
                {
                    DataPovt[i].ves_vlazhnoj = ConvertStringToFloat(stolbec1[i].Text);
                    DataPovt[i].ves_suhoj = ConvertStringToFloat(stolbec2[i].Text);
                    DataPovt[i].ves_stakan = ConvertStringToFloat(stolbec3[i].Text);
                    DataPovt[i].vlazhn_suhaya = ConvertStringToFloat(stolbec4[i].Text);
                    DataPovt[i].suhaya_stakan = ConvertStringToFloat(stolbec5[i].Text);
                    DataPovt[i].procent_isparivsh_vlagi = ConvertStringToFloat(stolbec6[i].Text);
                    DataPovt[i].vlazhnaya_stakan = ConvertStringToFloat(stolbec7[i].Text);
                }

                string query_progress = "SELECT progress FROM t_Glavnaya WHERE kod=" + ras_param.Glav_ID;
                if (!ras_param.marshrut)
                {
                    if (((int)comboBox1.SelectedItem == comboBox1.Items.Count) && ((int)comboBox1.SelectedItem <= 4))
                    {
                        int progress = conn.ExecQueryWithResult(connect_string, query_progress);
                        if (progress == 4)
                        {
                            string query_delRowFrom = "DELETE FROM t_data_povt WHERE kod_Glavn=" + ras_param.Glav_ID + " AND Povtornost=" + (int)comboBox1.SelectedItem;
                            conn.ExecQuery(connect_string, query_delRowFrom);
                        }
                        conn.InsertRowToDataPovt(ras_param.Glav_ID, (int)comboBox1.SelectedItem, DataPovt, ras_param.sloj0_5, textBox134.Text, connect_string);

                        string query_edit_progress = "UPDATE t_Glavnaya SET progress=" + comboBox1.Items.Count + " WHERE kod=" + ras_param.Glav_ID;
                        conn.ExecQuery(connect_string, query_edit_progress);
                        if (comboBox1.Items.Count < 4)
                        {
                            comboBox1.Items.Add((int)comboBox1.SelectedItem + 1);
                        }
                    }
                    else
                    {
                        string query_delRowFrom = "DELETE FROM t_data_povt WHERE kod_Glavn=" + ras_param.Glav_ID + " AND Povtornost=" + (int)comboBox1.SelectedItem;
                        conn.ExecQuery(connect_string, query_delRowFrom);
                        conn.InsertRowToDataPovt(ras_param.Glav_ID, (int)comboBox1.SelectedItem, DataPovt, ras_param.sloj0_5, textBox134.Text, connect_string);
                    }
                }
                else
                {
                    if (((int)comboBox1.SelectedItem == comboBox1.Items.Count) && ((int)comboBox1.SelectedItem <= 2))
                    {
                        int progress = conn.ExecQueryWithResult(connect_string, query_progress);
                        if (progress == 2)
                        {
                            string query_delRowFrom = "DELETE FROM t_data_povt WHERE kod_Glavn=" + ras_param.Glav_ID + " AND Povtornost=" + (int)comboBox1.SelectedItem;
                            conn.ExecQuery(connect_string, query_delRowFrom);
                        }
                        conn.InsertRowToDataPovt(ras_param.Glav_ID, (int)comboBox1.SelectedItem, DataPovt, ras_param.sloj0_5, textBox134.Text, connect_string);
                        // int progress = conn.ExecQueryWithResult(connect_string, query_progress);
                        string query_edit_progress = "UPDATE t_Glavnaya SET progress=" + comboBox1.Items.Count + " WHERE kod=" + ras_param.Glav_ID;
                        conn.ExecQuery(connect_string, query_edit_progress);
                        if (comboBox1.Items.Count < 2)
                        {
                            comboBox1.Items.Add((int)comboBox1.SelectedItem + 1);
                        }
                    }
                    else
                    {
                        string query_delRowFrom = "DELETE FROM t_data_povt WHERE kod_Glavn=" + ras_param.Glav_ID + " AND Povtornost=" + (int)comboBox1.SelectedItem;
                        conn.ExecQuery(connect_string, query_delRowFrom);
                        conn.InsertRowToDataPovt(ras_param.Glav_ID, (int)comboBox1.SelectedItem, DataPovt, ras_param.sloj0_5, textBox134.Text, connect_string);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }