コード例 #1
0
        protected void changeStatusClick(object sender, EventArgs e)
        {
            Greenhouse oGHouse = new Greenhouse();

            string gHouseID = Request.QueryString["Gid"].ToString();

            gHouse = oGHouse.getGHouse(gHouseID);

            SqlConnection conn = new SqlConnection(constr);
            SqlCommand    cmd  = new SqlCommand("UPDATE GREENHOUSESTABLE SET STATUS = @STATUS WHERE GID = @GID", conn);

            if (gHouse.gHouse_Status == "Active")
            {
                cmd.Parameters.AddWithValue("@STATUS", "Inactive");
                cmd.Parameters.AddWithValue("@GID", gHouse.gHouse_ID);
            }
            else
            {
                cmd.Parameters.AddWithValue("@STATUS", "Active");
                cmd.Parameters.AddWithValue("@GID", gHouse.gHouse_ID);
            }

            conn.Open();
            cmd.ExecuteNonQuery();
            conn.Close();
            Response.Redirect(Request.Url.AbsoluteUri);
        }
コード例 #2
0
        protected void Page_Load(object sender, EventArgs e)
        {
            LoadDataofTempChart();
            LoadTempAnalysis();

            humidityTable.Visible = false;
            tempTable.Visible     = true;
            moistureTable.Visible = false;
            lightTable.Visible    = false;
            heightTable.Visible   = false;
            //LoadDataofHumidityChart();
            //LoadHumAnalysis();
            //LoadDataofMoistureChart();
            //LoadMoistureAnalysis();
            //LoadDataofLightChart();
            //LoadLightAnalysis();
            //LoadDataofHeightChart();
            //LoadHeightAnalysis();

            DataSet user = GetUser();

            Repeater1.DataSource = user;
            Repeater1.DataBind();

            Greenhouse oGHouse = new Greenhouse();

            string gHouseID = Request.QueryString["Gid"].ToString();

            gHouse = oGHouse.getGHouse(gHouseID);

            if (gHouse.gHouse_Status == "Active")
            {
                lblStatus.Text           = gHouse.gHouse_Status;
                lblStatus.ForeColor      = System.Drawing.Color.Green;
                btnChangeStatus.CssClass = "btn btn-warning";
                btnChangeStatus.Text     = "Disable";
            }
            else
            {
                lblStatus.Text           = gHouse.gHouse_Status;
                lblStatus.ForeColor      = System.Drawing.Color.Red;
                btnChangeStatus.CssClass = "btn btn-success";
                btnChangeStatus.Text     = "Enable";
            }

            SqlConnection conn = new SqlConnection(constr);

            conn.Open();

            SqlCommand checkcmd = new SqlCommand("SELECT COUNT(*) FROM TEMPSENSOR", conn);
            int        check    = int.Parse(checkcmd.ExecuteScalar().ToString());

            string tempdate;

            if (check == 0)
            {
                Debug.WriteLine("No temp data");
            }
            SqlCommand tempcmd = new SqlCommand("SELECT MAX(TIMEOCCURED) FROM TEMPSENSOR", conn);

            tempdate = tempcmd.ExecuteScalar().ToString();
            Debug.WriteLine(tempdate);

            checkcmd = new SqlCommand("SELECT COUNT(*) FROM HUMIDITYSENSOR", conn);
            check    = int.Parse(checkcmd.ExecuteScalar().ToString());

            string humdate;

            if (check == 0)
            {
                Debug.WriteLine("No humidity data");
            }
            SqlCommand humcmd = new SqlCommand("SELECT MAX(TIMEOCCURED) FROM HUMIDITYSENSOR", conn);

            humdate = humcmd.ExecuteScalar().ToString();
            Debug.WriteLine(humdate);

            //SqlCommand humcmd = new SqlCommand("SELECT MAX(TIMEOCCURED) FROM HUMIDITYSENSOR", conn);
            //Debug.WriteLine(humcmd.ExecuteScalar().ToString());

            checkcmd = new SqlCommand("SELECT COUNT(*) FROM LIGHTSENSOR", conn);
            check    = int.Parse(checkcmd.ExecuteScalar().ToString());

            string lightdate;

            if (check == 0)
            {
                Debug.WriteLine("no light data");
            }

            SqlCommand lightcmd = new SqlCommand("SELECT MAX(TIMEOCCURED) FROM LIGHTSENSOR", conn);

            lightdate = lightcmd.ExecuteScalar().ToString();
            Debug.WriteLine(lightdate);

            //SqlCommand lightcmd = new SqlCommand("SELECT MAX(TIMEOCCURED) FROM LIGHTSENSOR", conn);
            //Debug.WriteLine(lightcmd.ExecuteScalar().ToString());

            checkcmd = new SqlCommand("SELECT COUNT(*) FROM MOISTURESENSOR", conn);
            check    = int.Parse(checkcmd.ExecuteScalar().ToString());

            string moistdate;

            if (check == 0)
            {
                Debug.WriteLine("no moisture data");
            }
            SqlCommand moistcmd = new SqlCommand("SELECT MAX(TIMEOCCURED) FROM MOISTURESENSOR", conn);

            moistdate = moistcmd.ExecuteScalar().ToString();
            Debug.WriteLine(moistdate);

            //SqlCommand moistcmd = new SqlCommand("SELECT MAX(TIMEOCCURED) FROM MOISTURESENSOR", conn);
            //Debug.WriteLine(moistcmd.ExecuteScalar().ToString());

            checkcmd = new SqlCommand("SELECT COUNT(*) FROM PLANTHEIGHT", conn);
            check    = int.Parse(checkcmd.ExecuteScalar().ToString());

            string sonicdate;

            if (check == 0)
            {
                Debug.WriteLine("no sonic data");
            }
            SqlCommand soniccmd = new SqlCommand("SELECT MAX(TIMEOCCURED) FROM PLANTHEIGHT", conn);

            sonicdate = soniccmd.ExecuteScalar().ToString();
            Debug.WriteLine(sonicdate);

            CultureInfo provider = CultureInfo.InvariantCulture;
            CultureInfo frFR     = new CultureInfo("fr-FR");

            lblActivity.Text = tempdate;

            SqlCommand staffcmd = new SqlCommand("SELECT COUNT(*) FROM USERTABLE", conn);
            string     staffno  = staffcmd.ExecuteScalar().ToString();

            lblStaff.Text = staffno;
            //SqlCommand soniccmd = new SqlCommand("SELECT MAX(TIMEOCCURED) FROM PLANTHEIGHT", conn);
            //Debug.WriteLine(soniccmd.ExecuteScalar().ToString());
            //DateTime latestTemp = Convert.ToDateTime(tempdate.ToUpper());
            //DateTime latestHum = DateTime.ParseExact(humdate, "G", provider);
            //DateTime latestLight = Convert.ToDateTime(lightdate.ToUpper(), frFR);
            //DateTime latestMoist = Convert.ToDateTime(moistdate.ToUpper(), frFR);
            //DateTime latestSonic = Convert.ToDateTime(sonicdate.ToUpper(), frFR);
            //Debug.WriteLine("conversion");
            //DateTime latestDateTime = new[] { latestTemp, latestHum, latestLight, latestMoist, latestSonic }.Max();
            //Debug.WriteLine(latestDateTime.ToString());

            ////int result = DateTime.Compare(latest, Convert.ToDateTime(humdate.ToUpper(), enUS));
            ////Debug.WriteLine(result);

            conn.Close();
        }