Example #1
0
 private void button3_Click(object sender, EventArgs e)
 {
     try
     {
         Connect_to_sql conn = new Connect_to_sql();
         string connect_string = conn.Con_str();
         if (MessageBox.Show("Вы действительно хотите удалить все записи из базы данных,\nсвязанные с этим полем?", "", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
         {
             if (!conn.DeleteFromPolya(textBox1.Text, connect_string))
             {
                 MessageBox.Show("Записей с таким названием поля, в базе данных не найдено!", "Предупреждение!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
             }
             else
             {
                 int ind = listBox1.Items.IndexOf(textBox1.Text);
                 listBox1.Items.RemoveAt(ind);
                 textBox1.Clear();
                 textBox2.Clear();
                 MessageBox.Show("Все записи связанные с этим полем, успешно удалены!", "Информация", MessageBoxButtons.OK, MessageBoxIcon.Information);
             }
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 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);
     }
 }
Example #3
0
 private void button2_Click(object sender, EventArgs e)
 {
     Connect_to_sql conn = new Connect_to_sql();
     string connect_string = "Data Source=" + comboBox1.Text + ";";
     connect_string += "Database=" + comboBox2.Text + ";";
     if (textBox1.Text != "")
     {
         connect_string += "Integrated Security=false;";
         connect_string += "User ID=" + textBox1.Text + ";";
         connect_string += "Password="******";";
     }
     else
     {
         connect_string += "Integrated Security=true;";
     }
     //string connect_string = conn.Con_str();
     if (comboBox1.Text!="" && comboBox2.Text!="")
     {
         if (saveFileDialog1.ShowDialog() == DialogResult.OK)
         {
             string query_backup = "BACKUP DATABASE " + comboBox2.SelectedItem.ToString() + " TO DISK = '" + saveFileDialog1.FileName + "'";
             try
             {
                 conn.ExecQuery(connect_string, query_backup);
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message);
             }
         }
     }
 }
Example #4
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;
 }
 private void Form_new_raschet_Load(object sender, EventArgs e)
 {
     Connect_to_sql conn = new Connect_to_sql();
     string connect_string = conn.Con_str();
     SqlConnection myConnection = new SqlConnection(connect_string);
     string myInsertQuery = "SELECT Ima_Polya FROM t_Naz_Poley ORDER BY kod_polya";
     SqlCommand myCommand = new SqlCommand(myInsertQuery);
     myCommand.Connection = myConnection;
     myConnection.Open();
     SqlDataReader reader = myCommand.ExecuteReader();
     while (reader.Read())
     {
         comboBox1.Items.Add(reader[0].ToString());
     }
     myCommand.Connection.Close();
 }
 private void button1_Click(object sender, EventArgs e)
 {
     Connect_to_sql conn = new Connect_to_sql();
     Connect_to_sql.AgroNewRaschet new_ras = new Connect_to_sql.AgroNewRaschet();
     string connect_string = conn.Con_str();
     new_ras.date = dateTimePicker1.Value;
     new_ras.name_polya = comboBox1.Text;
     new_ras.sloj0_5 = checkBox2.Checked;
     new_ras.marshrut = checkBox1.Checked;
     int kod_polya = conn.AddNewRaschet(new_ras, connect_string);
     string query = "SELECT kod FROM t_Glavnaya WHERE kod_Polya="+kod_polya+" AND Date='"+new_ras.date.Date+"'";
     new_ras.Glav_ID = conn.ExecQueryWithResult(connect_string, query);
     Form1 f_glavn = (Form1)this.Owner;
     f_glavn.StartRaschet(true);
     f_glavn.SetCurPole(comboBox1.Text, dateTimePicker1.Value.ToShortDateString());
     f_glavn.ras_param = new_ras;
     f_glavn.SetSloj0_5(new_ras.sloj0_5);
     f_glavn.comboBox1.Items.Clear();
     f_glavn.comboBox1.Items.Add(1);
     Close();
 }
Example #7
0
 private void button1_Click(object sender, EventArgs e)
 {
     try
     {
         Connect_to_sql conn = new Connect_to_sql();
         string connect_string = conn.Con_str();
         if (textBox1.Text != "")
         {
             conn.AddRowToPolya(textBox1.Text, connect_string);
             listBox1.Items.Add(textBox1.Text);
             textBox1.Clear();
         }
         else
         {
             MessageBox.Show("Не задано название поля!", "Предупреждение!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
     catch(Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #8
0
        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.AgroRazrez[] agr_razr = new Connect_to_sql.AgroRazrez[11];
                    TextBox[] TextBoxMass = GetTextBoxMassPoch();
                    TextBox[] TextBoxVlazh = GetTextBoxVl_ustoj_zav();
                    string ves = "";
                    for (int i = 0; i < 11; i++)
                    {
                        ves = TextBoxMass[i].Text;
                        ves = ves.Replace('.', ',');
                        agr_razr[i].obemnaya_massa_pochvi = (float)Convert.ToDouble(ves);

                        ves = TextBoxVlazh[i].Text;
                        ves = ves.Replace('.', ',');
                        agr_razr[i].vlazhnost_ustojch_zavyad = (float)Convert.ToDouble(ves);
                    }
                    conn.AddRowToRazrez(textBox23.Text, agr_razr, connect_string);
                    listBox1.Items.Add(textBox23.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);
            }
        }
Example #9
0
        public void Form1_Load(object sender, EventArgs e)
        {
            //     SetCurPole("1", "2");
            bool loaded = true;
            listBox1.Items.Clear();
            listBox2.Items.Clear();
            Connect_to_sql conn = new Connect_to_sql();
            string connect_string = conn.Con_str();
            if (connect_string != "error")
            {
                try
                {
                    conn.TestConnectToDB(connect_string);
                }
                catch (Exception ex)
                {
                    DoOff += 1;
                    MessageBox.Show(ex.Message);
                    if (DoOff >= 2)
                    {
                        Application.ExitThread();
                    }

                    loaded = false;
                }
                if (loaded)
                {
                    SqlConnection myConnection = new SqlConnection(connect_string);
                    string myInsertQuery = "SELECT name FROM t_razrez ORDER BY kod_razrez";
                    SqlCommand myCommand = new SqlCommand(myInsertQuery);
                    myCommand.Connection = myConnection;
                    myConnection.Open();
                    SqlDataReader reader = myCommand.ExecuteReader();
                    while (reader.Read())
                    {
                        listBox1.Items.Add(reader[0].ToString());
                    }
                    myCommand.Connection.Close();
                    myInsertQuery = "SELECT name FROM t_stakan_gruppa ORDER BY kod_gr";
                    myCommand = new SqlCommand(myInsertQuery);
                    myCommand.Connection = myConnection;
                    myConnection.Open();
                    reader = myCommand.ExecuteReader();
                    while (reader.Read())
                    {
                        listBox2.Items.Add(reader[0].ToString());
                    }

                    myCommand.Connection.Close();

                    myreg = Registry.CurrentUser.OpenSubKey("SOFTWARE\\AgroMeteo\\ConnectionSetting", true);
                    try
                    {
                        label57.BackColor = Color.FromArgb((int)myreg.GetValue("c1"));
                        label56.BackColor = Color.FromArgb((int)myreg.GetValue("c2"));
                        label55.BackColor = Color.FromArgb((int)myreg.GetValue("c3"));
                        label54.BackColor = Color.FromArgb((int)myreg.GetValue("c4"));
                        label53.BackColor = Color.FromArgb((int)myreg.GetValue("c5"));
                        label52.BackColor = Color.FromArgb((int)myreg.GetValue("c6"));
                        label51.BackColor = Color.FromArgb((int)myreg.GetValue("c7"));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Внимание! Цветовая схема не настроена! Прежде чем приступать \nк работе с программой, настройте цветовую схему.");
                    }
                }
                else
                {
                    Form_Connect_Options f_conn = new Form_Connect_Options();
                 //   f_conn.Owner = this;
                    f_conn.ShowDialog();
                }
            }
            else
            {
                Form_Connect_Options f_conn = new Form_Connect_Options();
             //   f_conn.Owner = this;
                f_conn.ShowDialog();
            }
        }
Example #10
0
        private void listBox1_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            textBox23.Text = (string)listBox1.SelectedItem;
            textBox24.Text = (string)listBox1.SelectedItem;

            Connect_to_sql conn = new Connect_to_sql();
            string connect_string = conn.Con_str();
            SqlConnection myConnection = new SqlConnection(connect_string);
            string myInsertQuery = "SELECT * FROM t_razrez WHERE name='" + (string)listBox1.SelectedItem + "'";
            SqlCommand myCommand = new SqlCommand(myInsertQuery);
            myCommand.Connection = myConnection;
            myConnection.Open();
            SqlDataReader reader = myCommand.ExecuteReader();
            TextBox[] TextBoxNum = GetTextBoxMassPoch();
            TextBox[] TextBoxVes = GetTextBoxVl_ustoj_zav();
            int ii = 0;
            while (reader.Read())
            {
                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();
        }
Example #11
0
 private void button5_Click(object sender, EventArgs e)
 {
     if (textBox24.Text != "")
     {
         Connect_to_sql conn = new Connect_to_sql();
         string connect_string = conn.Con_str();
         string query_kod_razrez = "SELECT kod_razrez FROM t_razrez WHERE name='" + textBox24.Text + "'";
         int kod = conn.ExecQueryWithResult(connect_string, query_kod_razrez);
         Form_step_uvl form_step_uvl = new Form_step_uvl();
         form_step_uvl.Owner = this;
         form_step_uvl.kod_razrez = kod;
         form_step_uvl.ShowDialog();
     }
 }
Example #12
0
 private void Form_razrez_Load(object sender, EventArgs e)
 {
     textBox1.Select();
     Connect_to_sql conn = new Connect_to_sql();
     string connect_string = conn.Con_str();
     SqlConnection myConnection = new SqlConnection(connect_string);
     string myInsertQuery = "SELECT name FROM t_razrez ORDER BY kod_razrez";
     SqlCommand myCommand = new SqlCommand(myInsertQuery);
     myCommand.Connection = myConnection;
     myConnection.Open();
     SqlDataReader reader = myCommand.ExecuteReader();
     while (reader.Read())
     {
         listBox1.Items.Add(reader[0].ToString());
     }
     myCommand.Connection.Close();
 }
 private void button8_Click(object sender, EventArgs e)
 {
     string first = "Data Source=" + comboBox3.Text + ";";
     if (comboBox1.Text == "Да")
     {
         first = first + "AttachDbFilename=" + textBox2.Text + ";";
         if (comboBox2.Text != "Аутентификация Windows")
         {
             first = first + "Integrated Security=false;";
             first = first + "User ID=" + textBox4.Text + ";";
             first = first + "Password="******";";
         }
         else
         {
             first = first + "Integrated Security=true;";
         }
         first += "Connect Timeout=30;User Instance=True;";
     }
     else
     {
         first = first + "Database=" + comboBox4.Text + ";";
         if (comboBox2.Text != "Аутентификация Windows")
         {
             first = first + "Integrated Security=false;";
             first = first + "User ID=" + textBox4.Text + ";";
             first = first + "Password="******";";
         }
         else
         {
             first = first + "Integrated Security=true;";
         }
     }
     Connect_to_sql conn = new Connect_to_sql();
     try
     {
         conn.RunSQLScript(first);
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message);
     }
 }
Example #14
0
 private void button3_Click(object sender, EventArgs e)
 {
     try
     {
         if (textBox1.Text != "")
         {
             Connect_to_sql conn = new Connect_to_sql();
             string connect_string = conn.Con_str();
             TextBox[] TextBoxNum = GetTextBoxMassPoch();
             TextBox[] TextBoxVes = GetTextBoxVl_ustoj_zav();
             conn.DelRowFromRazrez(textBox24.Text, connect_string);
             listBox1.Items.Remove(textBox24.Text);
             for (int i = 0; i < 11; i++)
             {
                 TextBoxNum[i].Clear();
                 TextBoxVes[i].Clear();
             }
             textBox23.Clear();
             textBox24.Clear();
             MessageBox.Show("Запись успешно удалена", "Оповещение", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
         else
         {
             MessageBox.Show("Не выбрано название группы стаканчиков!", "Предупреждение!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
 private void Form_Edit_Raschet_Load(object sender, EventArgs e)
 {
     Connect_to_sql conn = new Connect_to_sql();
     string connect_string = conn.Con_str();
     SqlConnection myConnection = new SqlConnection(connect_string);
     string myInsertQuery = "SELECT   t_Glavnaya.Kod ,t_Glavnaya.Date, t_Naz_poley.Ima_polya, t_Glavnaya.Progress, t_Glavnaya.sloj0_5, t_Glavnaya.marshrut "
     +"FROM t_Glavnaya INNER JOIN t_Naz_poley ON t_Glavnaya.Kod_Polya = t_Naz_poley.kod_polya";
     SqlCommand myCommand = new SqlCommand(myInsertQuery);
     myCommand.Connection = myConnection;
     myConnection.Open();
     SqlDataReader reader = myCommand.ExecuteReader();
     int j=0;
     while (reader.Read())
     {
         dataGridView1.Rows.Add();
         for (int i = 0; i < reader.FieldCount; i++)
         {
             dataGridView1[i, j].Value = reader[i];
         }
         j++;
     }
     myCommand.Connection.Close();
 }
        private void button7_Click(object sender, EventArgs e)
        {
            string first = "Data Source=" + comboBox3.Text + ";";
            if (comboBox1.Text == "Да")
            {
                first = first + "AttachDbFilename=" + textBox2.Text + ";";
            }
            //first = first + "Database=master;";
            if (comboBox2.Text != "Аутентификация Windows")
            {
                first = first + "Integrated Security=false;";
                first = first + "User ID=" + textBox4.Text + ";";
                first = first + "Password="******";";
            }
            else
            {
                first = first + "Integrated Security=true;";
            }

            //f_closed = false;
               // button2_Click(button2, e);
            /*
            Form_save_db f_save = new Form_save_db();
            f_save.Owner = this;
            f_save.con_string = first;
            f_save.ShowDialog();*/
                // If the user has chosen the file from which he wants the database to be restored

            Connect_to_sql conn = new Connect_to_sql();

                if (openFileDialog2.ShowDialog() == DialogResult.OK)
                {
                    string query_log_name = "RESTORE FILELISTONLY FROM DISK = '" + openFileDialog2.FileName + "'";

                    string connect_string = conn.Con_str();
                    SqlConnection myConnection = new SqlConnection(first);
                    string myInsertQuery = query_log_name;
                    SqlCommand myCommand = new SqlCommand(myInsertQuery);
                    myCommand.Connection = myConnection;
                    string[] DB_name = new string[2];
                    string DB_path = "";
                    string query_path = "select filename from sysfiles where name='master'";
                    try
                    {
                        myConnection.Open();
                        SqlDataReader reader = myCommand.ExecuteReader();

                        int kk = 0;
                        int pos=0;
                        while (reader.Read())
                        {
                            DB_name[kk] = Convert.ToString(reader[0]);
                            kk++;
                        }
                        myCommand.Connection.Close();
                        myCommand = new SqlCommand(query_path);
                        myCommand.Connection = myConnection;
                        myConnection.Open();
                        DB_path = Convert.ToString(myCommand.ExecuteScalar());
                            for (int j = DB_path.Length-1; j > 0; j--)
                            {
                                if (DB_path[j] == '\\')
                                {
                                    DB_path = DB_path.Substring(0, j);
                                    break;
                                }
                            }

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }

                    string query_backup = "RESTORE DATABASE " + textBox1.Text + " FROM DISK = '" + openFileDialog2.FileName + "' WITH REPLACE, MOVE '" + DB_name[0] + "' TO '" + DB_path + "\\" + textBox1.Text + ".mdf', MOVE '" + DB_name[1] + "' TO '" + DB_path + "\\" + textBox1.Text + "_Log.ldf'";
                    try
                    {
                        conn.ExecQuery(first, query_backup);
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message);
                    }
                }
        }
 private void Form_ves_stakan_Load(object sender, EventArgs e)
 {
     textBox2.Select();
     Connect_to_sql conn = new Connect_to_sql();
     string connect_string = conn.Con_str();
     SqlConnection myConnection = new SqlConnection(connect_string);
     string myInsertQuery = "SELECT name FROM t_stakan_gruppa ORDER BY kod_gr";
     SqlCommand myCommand = new SqlCommand(myInsertQuery);
     myCommand.Connection = myConnection;
     myConnection.Open();
     SqlDataReader reader =  myCommand.ExecuteReader();
     while (reader.Read())
     {
         listBox1.Items.Add(reader[0].ToString());
     }
     myCommand.Connection.Close();
     textBox1.KeyPress += new KeyPressEventHandler(Key_Press_other);
     textBox2.KeyPress += new KeyPressEventHandler(Key_Press_other);
     textBox3.KeyPress += new KeyPressEventHandler(Key_Press_other);
     textBox4.KeyPress += new KeyPressEventHandler(Key_Press_other);
     textBox5.KeyPress += new KeyPressEventHandler(Key_Press_other);
 }
        private void button1_Click(object sender, EventArgs e)
        {
            int ind_selRow = dataGridView1.CurrentRow.Index;
            Connect_to_sql.AgroNewRaschet edit_ras = new Connect_to_sql.AgroNewRaschet();
            int id_glav = Convert.ToInt32(dataGridView1[0, ind_selRow].Value);
            Connect_to_sql conn = new Connect_to_sql();
            string connect_string = conn.Con_str();
            SqlConnection myConnection = new SqlConnection(connect_string);
            string myInsertQuery = "SELECT     t_Glavnaya.Date, t_Glavnaya.Kod_Polya, t_Naz_poley.Ima_polya, t_Glavnaya.Kod_Sred, t_Glavnaya.Progress, t_Glavnaya.sloj0_5, "
                      + "t_Glavnaya.marshrut "
                      + "FROM         t_Glavnaya INNER JOIN "
                      + "t_Naz_poley ON t_Glavnaya.Kod_Polya = t_Naz_poley.kod_polya "
                      + "WHERE     (t_Glavnaya.Kod =" + id_glav + ")";
            SqlCommand myCommand = new SqlCommand(myInsertQuery);
            myCommand.Connection = myConnection;
            myConnection.Open();
            SqlDataReader reader = myCommand.ExecuteReader();
            while (reader.Read())
            {
                edit_ras.date = Convert.ToDateTime(reader[0]);
                edit_ras.kod_polya = Convert.ToInt32(reader[1]);
                edit_ras.name_polya = Convert.ToString(reader[2]);
                if ((reader[3]).ToString() != "")
                {
                    edit_ras.kod_sred = Convert.ToInt32(reader[3]);
                }
                else
                    edit_ras.kod_sred = -1;
                edit_ras.progress = Convert.ToInt32(reader[4]);
                edit_ras.sloj0_5 = Convert.ToBoolean(reader[5]);
                edit_ras.marshrut = Convert.ToBoolean(reader[6]);
                edit_ras.Glav_ID = id_glav;

            }
            myCommand.Connection.Close();
            Excel.Workbooks excelappworkbooks;
            Excel.Workbook excelappworkbook;
            Excel.Application appl = new Excel.Application();
            appl.Visible = false;
            appl.SheetsInNewWorkbook = edit_ras.progress+1;
            appl.Workbooks.Add(Type.Missing);
            Excel.Sheets excelsheets;
            Excel.Worksheet excelworksheet;
            Excel.Range excelcells;
            excelappworkbooks = appl.Workbooks;
            excelappworkbook = excelappworkbooks[1];
            excelsheets = excelappworkbook.Worksheets;
            string[] polya = {"Слой почвы см", "Масса влажной почвы\n и стаканчика", "Масса сухой почвы\n и стаканчика", "Масса стаканчиков",
                             "Масса испарившейся\n воды", "Масса сухой почвы\n без стаканчика", "Влажность почвы %", "Масса влажной почвы\n без стаканчика"};
            for (int j = 1; j <= edit_ras.progress; j++)
            {
                int sl = 0;

                Connect_to_sql.AgroDataPovt[] agro_data = new Connect_to_sql.AgroDataPovt[11];
                excelworksheet = (Excel.Worksheet)excelsheets.get_Item(j);

                excelcells = excelworksheet.get_Range("A1", "H4");
                excelcells.Merge(Type.Missing);
                excelcells.Font.Bold = true;
                excelcells.Font.Size = 15;
                excelcells.Borders.Weight = 3;
                excelcells.Borders.Value = 1;
                excelcells.HorizontalAlignment = Excel.Constants.xlCenter;
                excelcells.VerticalAlignment = Excel.Constants.xlCenter;
                excelcells.Value2 = "Отчет по " + j.ToString() + "й повторности\n Дата:" + edit_ras.date.ToLongDateString();
                if(edit_ras.sloj0_5)
                    excelcells = excelworksheet.get_Range("A7", "H17");
                else
                    excelcells = excelworksheet.get_Range("A7", "H16");
                excelcells.HorizontalAlignment = Excel.Constants.xlCenter;
                excelcells.VerticalAlignment = Excel.Constants.xlCenter;
                excelcells.Borders.Weight = 2;
                excelcells.Borders.Value = 1;

                for (int i = 1; i < 9; i++)
                {
                    excelcells = (Excel.Range)excelworksheet.Cells[6, i];
                    excelcells.Borders.Weight = 2;
                    excelcells.Orientation = 90;
                    excelcells.HorizontalAlignment = Excel.Constants.xlCenter;
                    excelcells.VerticalAlignment = Excel.Constants.xlCenter;
                    excelcells.Font.Size = 9;
                    excelcells.NumberFormat = "@";
                    excelcells.Borders.Value = 1;
                    excelcells.Value2 = polya[i - 1];
                }
                bool tr = false;
                int col;
                if (edit_ras.sloj0_5)
                    col = 0;
                else
                    col = 1;

                string query_ifex = "SELECT kod_data FROM t_data_povt WHERE kod_Glavn=" + edit_ras.Glav_ID + " AND povtornost=" + j;
                int ifexist = conn.ExecQueryWithResult(connect_string, query_ifex);
                if (ifexist != -1)
                {
                    int kod_st; //неиспользуемае переменная, нужна для работы функции
                    agro_data = conn.SelectFromDataPovt(edit_ras.Glav_ID, j,out kod_st, connect_string);
                    for (int i = col; i < 11; i++)
                    {

                        if (i == 0)
                        {
                            excelcells = (Excel.Range)excelworksheet.Cells[i + 7 - col, 1];
                            excelcells.NumberFormat = "@";
                            excelcells.Value2 = sl.ToString() + " - " + (sl + 5).ToString();
                            sl += 5;
                            tr = true;
                        }
                        else
                        {
                            excelcells = (Excel.Range)excelworksheet.Cells[i + 7 - col, 1];
                            excelcells.NumberFormat = "@";

                            if (tr)
                            {
                                excelcells.Value2 = sl.ToString() + " - " + (sl + 5).ToString();
                                sl += 5;
                                tr = false;
                            }
                            else
                            {
                                excelcells.Value2 = sl.ToString() + " - " + (sl + 10).ToString();
                                sl += 10;
                            }
                        }

                        excelcells = (Excel.Range)excelworksheet.Cells[i + 7 - col, 2];
                        excelcells.Value2 = conn.ConvertFloatToString(agro_data[i].ves_vlazhnoj);
                        excelcells = (Excel.Range)excelworksheet.Cells[i + 7 - col, 3];
                        excelcells.Value2 = conn.ConvertFloatToString(agro_data[i].ves_suhoj);
                        excelcells = (Excel.Range)excelworksheet.Cells[i + 7 - col, 4];
                        excelcells.Value2 = conn.ConvertFloatToString(agro_data[i].ves_stakan);
                        excelcells = (Excel.Range)excelworksheet.Cells[i + 7 - col, 5];
                        excelcells.Value2 = conn.ConvertFloatToString(agro_data[i].vlazhn_suhaya);
                        excelcells = (Excel.Range)excelworksheet.Cells[i + 7 - col, 6];
                        excelcells.Value2 = conn.ConvertFloatToString(agro_data[i].suhaya_stakan);
                        excelcells = (Excel.Range)excelworksheet.Cells[i + 7 - col, 7];
                        excelcells.Value2 = conn.ConvertFloatToString(agro_data[i].procent_isparivsh_vlagi);
                        excelcells = (Excel.Range)excelworksheet.Cells[i + 7 - col, 8];
                        excelcells.Value2 = conn.ConvertFloatToString(agro_data[i].vlazhnaya_stakan);
                    }
                }
            }
            if (edit_ras.kod_sred != -1)
            {
                int kod_sred;
                Connect_to_sql.AgroDataSredn[] agro_sred = conn.SelectDataFromDataSredn(edit_ras.kod_sred,edit_ras.sloj0_5,out kod_sred,connect_string);
                excelworksheet = (Excel.Worksheet)excelsheets.get_Item(edit_ras.progress+1);

                string name_r = "";

                myConnection = new SqlConnection(connect_string);
                myInsertQuery = "SELECT * FROM t_razrez WHERE kod_razrez=" + kod_sred;
               myCommand = new SqlCommand(myInsertQuery);
                myCommand.Connection = myConnection;
                myConnection.Open();
                reader = myCommand.ExecuteReader();
                //Connect_to_sql.AgroRazrez[] raz = new Connect_to_sql.AgroRazrez[11];
                int ii = 0;
                string[,] raz = new string[2,11];
                while (reader.Read())
                {
                    name_r = reader[1].ToString();
                    for (int i = 2; i < 13; i++)
                    {
                        raz[0,ii] = reader[i].ToString();
                        ii++;
                    }
                    ii = 0;
                    for (int i = 13; i < 24; i++)
                    {
                        raz[1, ii] = reader[i].ToString();
                        ii++;
                    }
                }
                myCommand.Connection.Close();

                            string[] polya_2 = {"Слой","Объемная масса почвы", "Влажность устойчивого\nзавядание", "Расчитанная влажность\n%","Запасы влаги\nв мм.", "Запасы влаги\nнарастающим итогом"};
                int sl = 0;
                if(edit_ras.sloj0_5)
                    excelcells = excelworksheet.get_Range("A1", "L3");
                else
                    excelcells = excelworksheet.get_Range("A1", "K3");
                excelcells.Merge(Type.Missing);
                excelcells.Font.Bold = true;
                excelcells.Font.Size = 15;
                excelcells.Borders.Weight = 3;
                excelcells.Borders.Value = 1;
                excelcells.HorizontalAlignment = Excel.Constants.xlCenter;
                excelcells.VerticalAlignment = Excel.Constants.xlCenter;
                excelcells.Value2 = "Отчет по по запасам влаги, на " + edit_ras.date.ToLongDateString();
                if(edit_ras.sloj0_5)
                    excelcells = excelworksheet.get_Range("A4", "L9");
                else
                    excelcells = excelworksheet.get_Range("A4", "K9");
                excelcells.HorizontalAlignment = Excel.Constants.xlCenter;
                excelcells.VerticalAlignment = Excel.Constants.xlCenter;
                excelcells.Borders.Weight = 2;
                excelcells.Borders.Value = 1;

                for (int i = 4; i < 10; i++)
                {
                    excelcells = (Excel.Range)excelworksheet.Cells[i, 1];
                    excelcells.Borders.Weight = 2;
                    //excelcells.Orientation = 90;
                    excelcells.HorizontalAlignment = Excel.Constants.xlLeft;
                    excelcells.VerticalAlignment = Excel.Constants.xlCenter;
                    excelcells.Font.Size = 9;
                    excelcells.NumberFormat = "@";
                    excelcells.Borders.Value = 1;
                    excelcells.Value2 = polya_2[i - 4];
                    excelcells.ColumnWidth = 20;
                }
                bool tr = false;
                int col;
                if (edit_ras.sloj0_5)
                    col = 0;
                else
                    col = 1;

                    for (int i = col; i < 11; i++)
                    {

                        if (i == 0)
                        {
                            excelcells = (Excel.Range)excelworksheet.Cells[4,i + 2 - col];
                            excelcells.NumberFormat = "@";
                            excelcells.Value2 = sl.ToString() + " - " + (sl + 5).ToString();
                            sl += 5;
                            tr = true;
                        }
                        else
                        {
                            excelcells = (Excel.Range)excelworksheet.Cells[4,i + 2 - col];
                            excelcells.NumberFormat = "@";

                            if (tr)
                            {
                                excelcells.Value2 = sl.ToString() + " - " + (sl + 5).ToString();
                                sl += 5;
                                tr = false;
                            }
                            else
                            {
                                excelcells.Value2 = sl.ToString() + " - " + (sl + 10).ToString();
                                sl += 10;
                            }
                        }
                        excelcells = (Excel.Range)excelworksheet.Cells[5, i + 2 - col];
                        excelcells.Value2 = raz[0, i];
                        excelcells = (Excel.Range)excelworksheet.Cells[6, i + 2 - col];
                        excelcells.Value2 = raz[1, i];

                        excelcells = (Excel.Range)excelworksheet.Cells[7, i + 2 - col];
                        excelcells.Value2 = conn.ConvertFloatToString(agro_sred[i].stroka3);
                        excelcells = (Excel.Range)excelworksheet.Cells[8, i + 2 - col];
                        excelcells.Value2 = conn.ConvertFloatToString(agro_sred[i].stroka4);
                        excelcells = (Excel.Range)excelworksheet.Cells[9, i + 2 - col];
                        excelcells.Value2 = conn.ConvertFloatToString(agro_sred[i].stroka5);
                    }
                    float[] val = new float[10];
                    for (int k = 0; k < 10; k++)
                    {
                        val[k] = agro_sred[k+1].stroka5;
                    }
                    Form1 f_owner = (Form1)this.Owner;
                    string[] step_t = new string[7];
                    step_t[0] = "Почвенная засуха сильная";
                    step_t[1] = "Почвенная засуха слабая";
                    step_t[2] = "Недостаточное увлажнение сильное";
                    step_t[3] = "Недостаточное увлажнение слабое";
                    step_t[4] = "Оптимальное увлажнение";
                    step_t[5] = "Избыточное увлажнение";
                    step_t[6] = "Заболачивание";

                    Connect_to_sql.ResultStepUvl[] res_step = conn.GetResultStepUvl(val, name_r, connect_string);
                    for (int k = 12; k < 17; k++)
                    {
                        for (int p = 1; p < 9; p++)
                        {
                            excelcells = (Excel.Range)excelworksheet.Cells[k, p];
                            excelcells.Merge(Type.Missing);
                            excelcells.Font.Bold = true;
                            excelcells.Font.Size = 10;
                            excelcells.Borders.Weight = 2;
                            excelcells.Borders.Value = 1;
                            excelcells.HorizontalAlignment = Excel.Constants.xlLeft;
                            excelcells.VerticalAlignment = Excel.Constants.xlCenter;
                        }
                    }
                    excelcells = excelworksheet.get_Range("A11", "h12");
                    excelcells.Merge(Type.Missing);
                    excelcells.Font.Bold = true;
                    excelcells.Font.Size = 15;
                    excelcells.Borders.Weight = 3;
                    excelcells.Borders.Value = 1;
                    excelcells.HorizontalAlignment = Excel.Constants.xlCenter;
                    excelcells.VerticalAlignment = Excel.Constants.xlCenter;
                    excelcells.Value2 = "Степень увлажнения почвы по слоям";

                    excelcells = excelworksheet.get_Range("a13", "b13");
                    excelcells.Merge(Type.Missing);
                    excelcells.Value2 = "Слой 0-10";
                    excelcells = excelworksheet.get_Range("c13", "h13");
                    excelcells.Merge(Type.Missing);
                    excelcells.Value2 = step_t[res_step[0].znachenie];

                    excelcells = excelworksheet.get_Range("a14", "b14");
                    excelcells.Merge(Type.Missing);
                    excelcells.Value2 = "Слой 0-20";
                    excelcells = excelworksheet.get_Range("c14", "h14");
                    excelcells.Merge(Type.Missing);
                    excelcells.Value2 = step_t[res_step[1].znachenie];

                    excelcells = excelworksheet.get_Range("a15", "b15");
                    excelcells.Merge(Type.Missing);
                    excelcells.Value2 = "Слой 0-50";
                    excelcells = excelworksheet.get_Range("c15", "h15");
                    excelcells.Merge(Type.Missing);
                    excelcells.Value2 = step_t[res_step[4].znachenie];

                    excelcells = excelworksheet.get_Range("a16", "b16");
                    excelcells.Merge(Type.Missing);
                    excelcells.Value2 = "Слой 0-100";
                    excelcells = excelworksheet.get_Range("c16", "h16");
                    excelcells.Merge(Type.Missing);
                    excelcells.Value2 = step_t[res_step[9].znachenie];

            }

            appl.Visible = true;
        }
Example #19
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);
            }
        }
Example #20
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);
                    }

                }
            }
        }
Example #21
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);
            }
        }
Example #22
0
        private void comboBox1_TextChanged(object sender, EventArgs e)
        {
            Connect_to_sql conn = new Connect_to_sql();
            string connect_string = conn.Con_str();
            int sel_povt = (int)((ComboBox)(sender)).SelectedItem;
            string query_ifex = "SELECT kod_data FROM t_data_povt WHERE kod_Glavn=" + ras_param.Glav_ID + " AND povtornost=" + sel_povt;
            int ifexist = conn.ExecQueryWithResult(connect_string, query_ifex);
            if (ifexist != -1)
            {
                TextBox[] stolbec1 = GetTextBoxVesVlazhPochvi();
                TextBox[] stolbec2 = GetTextBoxVesSuhojPochvi();
                TextBox[] stolbec3 = GetTextBoxVesStakan();
                TextBox[] stolbec4 = GetTextBoxPole4();
                TextBox[] stolbec5 = GetTextBoxPole5();
                TextBox[] stolbec6 = GetTextBoxPole6();
                TextBox[] stolbec7 = GetTextBoxPole7();

                Connect_to_sql.AgroDataPovt[] agro_data = new Connect_to_sql.AgroDataPovt[11];
                int kod_st;
                agro_data = conn.SelectFromDataPovt(ras_param.Glav_ID, sel_povt, out kod_st, connect_string);
                for (int i = 0; i < 11; i++)
                {
                    stolbec1[i].Text = conn.ConvertFloatToString(agro_data[i].ves_vlazhnoj);
                    stolbec2[i].Text = conn.ConvertFloatToString(agro_data[i].ves_suhoj);
                    stolbec3[i].Text = conn.ConvertFloatToString(agro_data[i].ves_stakan);
                    stolbec4[i].Text = conn.ConvertFloatToString(agro_data[i].vlazhn_suhaya);
                    stolbec5[i].Text = conn.ConvertFloatToString(agro_data[i].suhaya_stakan);
                    stolbec6[i].Text = conn.ConvertFloatToString(agro_data[i].procent_isparivsh_vlagi);
                    stolbec7[i].Text = conn.ConvertFloatToString(agro_data[i].vlazhnaya_stakan);
                }
                listBox2.SelectedIndex = -1;
                textBox134.Text = "";
                if (kod_st != -1)
                {
                    string[] num_stak = conn.SelectNomerFormStaka(kod_st, connect_string);
                    string name_stak_grup = conn.SelectNameFormStakanGrup(kod_st, connect_string);
                    Label[] num_st = GetLabelNumStakan();
                    for (int i = 0; i < 11; i++)
                    {
                        num_st[i].Text = num_stak[i];
                    }

                    int ii = 0;
                    System.Collections.IEnumerator numerator = listBox2.Items.GetEnumerator();
                    while(numerator.MoveNext())
                    {
                        if (numerator.Current.ToString() == name_stak_grup)
                        {
                            listBox2.SelectedIndex = ii;
                            textBox134.Text = name_stak_grup;
                            break;
                        }
                        else
                        {
                            ii++;
                        }
                    }
                    //int ind = listBox2.Items.GetEnumerator

                }
            }
        }
Example #23
0
        private void listBox2_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (listBox2.SelectedItem != null)
            {
                textBox134.Text = (string)listBox2.SelectedItem;
                // textBox24.Text = (string)listBox1.SelectedItem;

                Connect_to_sql conn = new Connect_to_sql();
                string connect_string = conn.Con_str();
                SqlConnection myConnection = new SqlConnection(connect_string);
                string myInsertQuery = "SELECT kod_gr from t_stakan_gruppa WHERE name='" + textBox134.Text + "'";
                SqlCommand myCommand = new SqlCommand(myInsertQuery);
                myCommand.Connection = myConnection;
                myConnection.Open();
                int grup_id = (int)myCommand.ExecuteScalar();
                myCommand.Connection.Close();

                myInsertQuery = "SELECT nomer,ves FROM t_stakan WHERE gruppa=" + grup_id + " ORDER BY kod_st";
                myCommand = new SqlCommand(myInsertQuery);
                myCommand.Connection = myConnection;
                myConnection.Open();
                SqlDataReader reader = myCommand.ExecuteReader();
                Label[] TextBoxNum = GetLabelNumStakan();
                TextBox[] TextBoxVes = GetTextBoxVesStakan();
                int ii = 0;
                while (reader.Read())
                {
                    TextBoxNum[ii].Text = reader[0].ToString();
                    TextBoxVes[ii].Text = reader[1].ToString();
                    ii++;
                }
                myCommand.Connection.Close();
            }
        }
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         if (MessageBox.Show("Вы действительно хотите удалить выбранную запись?", "Удаление записи", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes)
         {
             Connect_to_sql conn = new Connect_to_sql();
             string connect_string = conn.Con_str();
             int ind_selRow = dataGridView1.CurrentRow.Index;
             int id_glav = Convert.ToInt32(dataGridView1[0, ind_selRow].Value);
             conn.DeleteFromGlavn(id_glav, connect_string);
             dataGridView1.Rows.Clear();
             Form_Edit_Raschet_Load(null, EventArgs.Empty);
             MessageBox.Show("Запись успешно удалена", "Оповещение", MessageBoxButtons.OK, MessageBoxIcon.Information);
         }
     }
     catch (Exception ex)
     {
         MessageBox.Show(ex.Message, "Ошибка!!!", MessageBoxButtons.OK, MessageBoxIcon.Error);
     }
 }
Example #25
0
        private void button3_Click(object sender, EventArgs e)
        {
            Connect_to_sql conn = new Connect_to_sql();
            string connect_string = "Data Source=" + comboBox1.Text + ";";
            connect_string += "Database=" + comboBox2.Text + ";";
            if (textBox1.Text != "")
            {
                connect_string += "Integrated Security=false;";
                connect_string += "User ID=" + textBox1.Text + ";";
                connect_string += "Password="******";";
            }
            else
            {
                connect_string += "Integrated Security=true;";
            }
            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                string query_log_name = "RESTORE FILELISTONLY FROM DISK = '" + openFileDialog1.FileName + "'";
                SqlConnection myConnection = new SqlConnection(connect_string);
                string myInsertQuery = query_log_name;
                SqlCommand myCommand = new SqlCommand(myInsertQuery);
                myCommand.Connection = myConnection;
                string[] DB_name = new string[2];
                string[] DB_path = new string[2];
                string[] DB_new_path = new string[2];
                try
                {
                    myConnection.Open();
                    SqlDataReader reader = myCommand.ExecuteReader();

                    int kk = 0;
                    int pos = 0;
                    while (reader.Read())
                    {
                        DB_name[kk] = Convert.ToString(reader[0]);
                        DB_path[kk] = Convert.ToString(reader[1]);
                        kk++;
                    }
                    for (int i = 0; i < 2; i++)
                    {
                        for (int j = DB_path[i].Length - 1; j > 0; j--)
                        {
                            if (DB_path[i][j] == '\\')
                            {
                                DB_new_path[i] = DB_path[i].Substring(0, j);
                                break;
                            }
                        }
                    }
                    myCommand.Connection.Close();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                string query_backup = "RESTORE DATABASE " + comboBox2.SelectedItem.ToString() + " FROM DISK = '" + openFileDialog1.FileName + "' WITH REPLACE, MOVE '" + DB_name[0] + "' TO '" + DB_new_path[0] + "\\" + comboBox2.SelectedItem.ToString() + ".mdf', MOVE '" + DB_name[1] + "' TO '" + DB_new_path[1] + "\\" + comboBox2.SelectedItem.ToString() + "_Log.ldf'";
                try
                {
                    conn.ExecQuery(connect_string, query_backup);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
        private void button1_Click(object sender, EventArgs e)
        {
            int ind_selRow = dataGridView1.CurrentRow.Index;
            Connect_to_sql.AgroNewRaschet edit_ras = new Connect_to_sql.AgroNewRaschet();
            int id_glav =Convert.ToInt32(dataGridView1[0, ind_selRow].Value);
            Connect_to_sql conn = new Connect_to_sql();
            string connect_string = conn.Con_str();
            SqlConnection myConnection = new SqlConnection(connect_string);
            string myInsertQuery = "SELECT     t_Glavnaya.Date, t_Glavnaya.Kod_Polya, t_Naz_poley.Ima_polya, t_Glavnaya.Kod_Sred, t_Glavnaya.Progress, t_Glavnaya.sloj0_5, "
                      +"t_Glavnaya.marshrut "
                      +"FROM         t_Glavnaya INNER JOIN "
                      +"t_Naz_poley ON t_Glavnaya.Kod_Polya = t_Naz_poley.kod_polya "
                      +"WHERE     (t_Glavnaya.Kod ="+ id_glav +")";
            SqlCommand myCommand = new SqlCommand(myInsertQuery);
            myCommand.Connection = myConnection;
            myConnection.Open();
            SqlDataReader reader = myCommand.ExecuteReader();
            while (reader.Read())
            {
                edit_ras.date =Convert.ToDateTime(reader[0]);
                edit_ras.kod_polya = Convert.ToInt32(reader[1]);
                edit_ras.name_polya = Convert.ToString(reader[2]);
                if  ((reader[3]).ToString()!="")
                {
                    edit_ras.kod_sred = Convert.ToInt32(reader[3]);
                }
                else
                    edit_ras.kod_sred = -1;
                edit_ras.progress = Convert.ToInt32(reader[4]);
                edit_ras.sloj0_5 = Convert.ToBoolean(reader[5]);
                edit_ras.marshrut = Convert.ToBoolean(reader[6]);
                edit_ras.Glav_ID = id_glav;

            }
            myCommand.Connection.Close();
            Form1 glForm = (Form1)this.Owner;
            glForm.ras_param = edit_ras;
            glForm.StartRaschet(true);
            glForm.comboBox1.Items.Clear();
            glForm.button3_Click(null, EventArgs.Empty);
            if (!edit_ras.marshrut)
            {
                if (edit_ras.progress < 4)
                {
                    for (int i = 1; i <= edit_ras.progress + 1; i++)
                    {
                        glForm.comboBox1.Items.Add(i);
                    }
                }
                else
                {
                    for (int i = 1; i <= edit_ras.progress; i++)
                    {
                        glForm.comboBox1.Items.Add(i);
                    }
                }
            }
            else
            {
                if (edit_ras.progress < 2)
                {
                    for (int i = 1; i <= edit_ras.progress + 1; i++)
                    {
                        glForm.comboBox1.Items.Add(i);
                    }
                }
                else
                {
                    for (int i = 1; i <= edit_ras.progress; i++)
                    {
                        glForm.comboBox1.Items.Add(i);
                    }
                }
            }
            glForm.SetCurPole(edit_ras.name_polya, edit_ras.date.ToShortDateString());
            glForm.SetSloj0_5(edit_ras.sloj0_5);
            glForm.SetDataToTextBoxSredn();
            Close();
        }
        private void button6_Click(object sender, EventArgs e)
        {
            string first = "Data Source=" + comboBox3.Text + ";";
            if (comboBox1.Text == "Да")
            {
                first = first + "AttachDbFilename=" + textBox2.Text + ";";
            }
            //first = first + "Database=master;";
            if (comboBox2.Text != "Аутентификация Windows")
            {
                first = first + "Integrated Security=false;";
                first = first + "User ID=" + textBox4.Text + ";";
                first = first + "Password="******";";
            }
            else
            {
                first = first + "Integrated Security=true;";
            }
            string query_createDB = "CREATE DATABASE " + textBox1.Text;
            Connect_to_sql conn = new Connect_to_sql();
            try
            {
                conn.ExecQuery(first, query_createDB);
                button4_Click(button4, e);

            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }