Пример #1
0
        public IActionResult Index()
        {
            SqlServerConnHelp sqlConnManager = new SqlServerConnHelp();
            SqlConnection     sqlConnection  = sqlConnManager.GetConnection(@"DELL-SVR\SQLEXPRESS", "SensorData", "jdw", "asdf");
            //SqlConnection sqlConnection = sqlConnManager.GetConnection(@"LAPTOP-AD2UF7HI\SQLEXPRESS", "SensorData", "jdw", "asdf");
            string     query           = "select a.UniqueID, a.Created_On, (Select Max(SensorValue) From SensorDataDetail b where b.UniqueID = a.UniqueID AND b.SensorNode = 'Temperature'), (Select Max(SensorValue) From SensorDataDetail b where b.UniqueID = a.UniqueID AND b.SensorNode = 'Moisture'), (Select Max(SensorValue) From SensorDataDetail b where b.UniqueID = a.UniqueID AND (b.SensorNode = 'Sunlight' or b.SensorNode = 'Luminosity')) from SensorData a";
            SqlCommand cmd             = new SqlCommand(query, sqlConnection);
            var        reader          = cmd.ExecuteReader();
            List <SensorDataFields> db = new List <SensorDataFields>();

            while (reader.Read())
            {
                SensorDataFields row = new SensorDataFields();
                row.UniqueId    = reader.GetString(0).Trim();
                row.date        = reader.GetDateTime(1);
                row.Temperature = reader.GetString(2).Trim();
                row.Moisture    = reader.GetString(3).Trim();
                row.Luminosity  = reader.GetString(4).Trim();
                db.Add(row);
            }

            reader.Close();
            cmd.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();

            ViewData["SensorDataFields"] = db;
            return(View());
        }
Пример #2
0
        public IActionResult Index()
        {
            SqlServerConnHelp sqlConnManager = new SqlServerConnHelp();
            SqlConnection     sqlConnection  = sqlConnManager.GetConnection(@"DELL-SVR\SQLEXPRESS", "SensorData", "jdw", "asdf");
            //SqlConnection sqlConnection = sqlConnManager.GetConnection(@"LAPTOP-AD2UF7HI\SQLEXPRESS", "SensorData", "jdw", "asdf");
            string     query           = "Select * from SensorData";
            SqlCommand cmd             = new SqlCommand(query, sqlConnection);
            var        reader          = cmd.ExecuteReader();
            List <SensorDataFields> db = new List <SensorDataFields>();

            while (reader.Read())
            {
                SensorDataFields row = new SensorDataFields();
                row.Id             = reader.GetInt32(0);
                row.UniqueId       = reader.GetString(1).Trim();
                row.TransmissionId = reader.GetString(2).Trim();
                row.IpAddress      = reader.GetString(3).Trim();
                row.date           = reader.GetDateTime(4);
                db.Add(row);
            }

            reader.Close();
            cmd.Dispose();
            sqlConnection.Close();
            sqlConnection.Dispose();

            ViewData["SensorDataFields"] = db;
            return(View());
        }