Exemple #1
0
        public void SetDataToTextBoxSredn()
        {
            Connect_to_sql conn = new Connect_to_sql();
            string connect_string = conn.Con_str();
            int kod_razrez;
            if (ras_param.kod_sred != -1)
            {
                Connect_to_sql.AgroDataSredn[] AgroSredn = conn.SelectDataFromDataSredn(ras_param.kod_sred, ras_param.sloj0_5, out kod_razrez, connect_string);
                if (AgroSredn != null)
                {
                    TextBox[] str3 = GetTextBoxStroka3();
                    TextBox[] str4 = GetTextBoxStroka4();
                    TextBox[] str5 = GetTextBoxStroka5();
                    if (ras_param.sloj0_5)
                    {
                        for (int i = 0; i < 11; i++)
                        {
                            str3[i].Text = conn.ConvertFloatToString(AgroSredn[i].stroka3);
                            str4[i].Text = conn.ConvertFloatToString(AgroSredn[i].stroka4);
                            str5[i].Text = conn.ConvertFloatToString(AgroSredn[i].stroka5);
                        }
                    }
                    else
                    {
                        for (int i = 1; i < 11; i++)
                        {
                            str3[i].Text = conn.ConvertFloatToString(AgroSredn[i].stroka3);
                            str4[i].Text = conn.ConvertFloatToString(AgroSredn[i].stroka4);
                            str5[i].Text = conn.ConvertFloatToString(AgroSredn[i].stroka5);
                        }
                    }

                    SqlConnection myConnection = new SqlConnection(connect_string);
                    string myInsertQuery = "SELECT * FROM t_razrez WHERE kod_razrez=" + kod_razrez;
                    SqlCommand myCommand = new SqlCommand(myInsertQuery);
                    myCommand.Connection = myConnection;
                    myConnection.Open();
                    SqlDataReader reader = myCommand.ExecuteReader();
                    TextBox[] TextBoxNum = GetTextBoxOb_massa_pochvi();
                    TextBox[] TextBoxVes = GetTextBoxVl_ustoj_zav();
                    int ii = 0;
                    while (reader.Read())
                    {
                        int ind = listBox1.Items.IndexOf(reader[1].ToString());
                        listBox1.SelectedIndex = ind;
                        textBox133.Text = reader[1].ToString();
                        for (int i = 2; i < 13; i++)
                        {
                            TextBoxNum[ii].Text = reader[i].ToString();
                            ii++;
                        }
                        ii = 0;
                        for (int i = 13; i < 24; i++)
                        {
                            TextBoxVes[ii].Text = reader[i].ToString();
                            ii++;
                        }
                    }
                    myCommand.Connection.Close();
                    TextBox[] stroka5 = GetTextBoxStroka5();
                    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);
                    }

                }
            }
        }
Exemple #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);
            }
        }
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         if (textBox1.Text != "")
         {
             Connect_to_sql conn = new Connect_to_sql();
             string connect_string = conn.Con_str();
             Connect_to_sql.AgroStakan[] agr_st = new Connect_to_sql.AgroStakan[11];
             TextBox[] TextBoxNum = GetTextBoxNumber();
             TextBox[] TextBoxVes = GetTextBoxVes();
             string ves = "";
             for (int i = 0; i < 11; i++)
             {
                 agr_st[i].nomer_stakan = Convert.ToInt32(TextBoxNum[i].Text);
                 ves = TextBoxVes[i].Text;
                 ves = ves.Replace('.', ',');
                 agr_st[i].ves_stakan = conn.ConvertStringToFloat(ves, 1);
             }
             conn.AddRowToStakan(textBox1.Text, agr_st, connect_string);
             listBox1.Items.Add(textBox1.Text);
             MessageBox.Show("Запись успешно добавлена", "Оповещение", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             MessageBox.Show("Не задано название группы стаканчиков!", "Предупреждение!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }