Esempio n. 1
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();
            }
        }