Ejemplo n.º 1
0
        private void fillSqlCritTable()
        {
            try
            {
                string          connStr = Program.connStr;
                MySqlConnection conn    = new MySqlConnection(connStr);
                conn.Open();

                var lastEntry = "SELECT DateTime FROM `machine_stats` WHERE id = (SELECT MAX(id) FROM `machine_stats`)";

                MySqlCommand command      = new MySqlCommand(lastEntry, conn);
                string       returnedDate = command.ExecuteScalar().ToString(); //Получаем правильно
                DateTime     maxDateDT    = DateTime.Parse(returnedDate);
                DateTime     minDateDT    = maxDateDT.AddHours(-24);
                string       minDate      = DatToDB.reverseDate(minDateDT.ToString()); //Считаем правильно
                string       maxDate      = DatToDB.reverseDate(maxDateDT.ToString());

                conn.Close();
                var select = String.Format("SELECT * FROM `machine_stats` WHERE ((`DateTime` >= '{0}') AND (`DateTime` <= '{1}') AND ((`Temp` >= '{2}') OR (`Vibr` >= '{3}') OR " +
                                           "(`Power` >= '{4}') OR (`Load` >= '{5}') OR (`Wtime` >= '{6}')))", minDate, maxDate, Program.critTemp, Program.critVibr, Program.critPow, Program.critLoad, Program.critTime);
                //Запрос обрабатывается
                var dataAdapter = new MySqlDataAdapter(select, conn);
                var ds          = new DataSet();
                dataAdapter.Fill(ds);  //А ds пустой!
                dataGridView1.ReadOnly   = true;
                dataGridView1.DataSource = ds.Tables[0];
            }
            catch
            {
                MessageBox.Show("Проверьте подключение к интернету");
            }
        }
Ejemplo n.º 2
0
        private void fillSqlCritTable()
        {
            try
            {
                string          connStr = "server=baltika.mysql.database.azure.com;user=sailor@baltika;database=smartfactory;password=Baltika123;charset=utf8;";
                MySqlConnection conn    = new MySqlConnection(connStr);
                conn.Open();

                var lastEntry = "SELECT DateTime FROM `machine_stats` WHERE id = (SELECT MAX(id) FROM `machine_stats`)";

                MySqlCommand command      = new MySqlCommand(lastEntry, conn);
                string       returnedDate = command.ExecuteScalar().ToString(); //Получаем правильно
                DateTime     maxDateDT    = DateTime.Parse(returnedDate);
                DateTime     minDateDT    = maxDateDT.AddHours(-24);
                string       minDate      = DatToDB.reverseDate(minDateDT.ToString()); //Считаем правильно
                string       maxDate      = DatToDB.reverseDate(maxDateDT.ToString());

                conn.Close();

                var select = String.Format("SELECT * FROM `machine_stats` WHERE ((`DateTime` >= '{0}') AND (`DateTime` <= '{1}') AND ((`Temp` BETWEEN '{2}' AND '{3}') OR (`Vibr` BETWEEN '{4}' AND '{5}') OR " +
                                           "(`Power` BETWEEN '{6}' AND '{7}') OR (`Load` BETWEEN '{8}' AND '{9}') OR (`Wtime` BETWEEN '{10}' AND '{11}')))", minDate, maxDate, Program.dangTemp, Program.critTemp, Program.dangVibr, Program.critVibr,
                                           Program.dangPow, Program.critPow, Program.dangLoad, Program.critLoad, Program.dangTime, Program.critTime);
                //Запрос обрабатывается
                var dataAdapter = new MySqlDataAdapter(select, conn);
                var ds          = new DataSet();
                dataAdapter.Fill(ds);  //А ds пустой!
                dataGridView1.ReadOnly   = true;
                dataGridView1.DataSource = ds.Tables[0];
            }
            catch
            {
                MessageBox.Show("Проверьте подключение к сети");
            }
        }