示例#1
0
        protected void RemoveDeviceButton_Click(object sender, EventArgs e)
        {
            string path       = HttpContext.Current.Request.Url.AbsolutePath;
            string devicename = path.Remove(0, path.LastIndexOf('/') + 1);

            //TODO Check if that Name exists
            //TODO Validate they are sure

            DatabaseCalls.RemoveDeviceFromDatabase(devicename, User.Identity.Name);

            Response.Redirect(path.Remove(path.LastIndexOf('/'))); //refresh page
        }
示例#2
0
        protected void AddNewDeviceButton_Click(object sender, EventArgs e)
        {
            string uid  = UIDTextbox.Text;
            string name = NameTextbox.Text;

            //TODO Check if that UID exists
            //TODO Check if that Name exists
            //TODO Check if UID is already taken

            DatabaseCalls.AddNewDeviceToDatabase(User.Identity.Name, uid, name);

            Response.RedirectToRoute("DeviceRoute", new { device = name });
        }
示例#3
0
        protected void SetNewScheduleButton_Click(object sender, EventArgs e)
        {
            string path       = HttpContext.Current.Request.Url.AbsolutePath;
            string devicename = path.Remove(0, path.LastIndexOf('/') + 1);

            int timezoneoffset = ExtraCommands.GetTimeZoneOffsetMinutes(Request);

            ChangeScheduleButton.CssClass = "btn btn-sm inline-blocks pull-right";
            SetNewScheduleButton.Visible  = false;

            newSchedule.Visible = false;

            string offtime = Request.Form[newofftime.UniqueID];
            string ontime  = Request.Form[newontime.UniqueID];

            DatabaseCalls.SetOffTimeValue(offtime, devicename, timezoneoffset);
            DatabaseCalls.SetOnTimeValue(ontime, devicename, timezoneoffset);
        }
示例#4
0
        protected void ChangeControllerStateOn_Click(object sender, EventArgs e)
        {
            string path       = HttpContext.Current.Request.Url.AbsolutePath;
            string devicename = path.Remove(0, path.LastIndexOf('/') + 1);

            OnChangeControllerStateButton.CssClass  = "btn btn-lg btn-on";
            OffChangeControllerStateButton.CssClass = "btn btn-lg";
            if (DatabaseCalls.GetNewestDeviceState(devicename) == "ON")
            {
                NewPowerStateHolder.Visible = false;
                DatabaseCalls.SetNewestDeviceState(devicename, 1);
            }
            else
            {
                NewPowerStateHolder.Visible     = true;
                ChangeControllerStateLabel.Text = devicename + " will turn on after its next connection.";
                DatabaseCalls.SetNewestDeviceState(devicename, 1);
            }
        }
示例#5
0
        protected void UpdateDeviceView(object sender, EventArgs e)
        {
            //add device name
            string path       = HttpContext.Current.Request.Url.AbsolutePath;
            string devicename = path.Remove(0, path.LastIndexOf('/') + 1);

            DeviceNameLabel.Text = devicename;

            //timezone offset
            int timezoneoffset = ExtraCommands.GetTimeZoneOffsetMinutes(Request);

            //TODO Validate if data exists

            try
            {
                //Last Update Time
                DateTime lastupdatetimeutc = DatabaseCalls.GetNewestConnectionDate(devicename);
                LastUpdatedTime.Text = "Last connected at " + lastupdatetimeutc.AddMinutes(timezoneoffset).ToShortTimeString() + " on " + lastupdatetimeutc.AddMinutes(timezoneoffset).ToShortDateString();

                //State
                if (!Page.IsPostBack)
                {
                    if (DatabaseCalls.GetNewestDeviceState(devicename) == "ON")
                    {
                        OnChangeControllerStateButton.CssClass  = "btn btn-lg btn-on";
                        OffChangeControllerStateButton.CssClass = "btn btn-lg";
                    }
                    else
                    {
                        OnChangeControllerStateButton.CssClass  = "btn btn-lg";
                        OffChangeControllerStateButton.CssClass = "btn btn-lg btn-off";
                    }
                }

                //Times
                try
                {
                    DateTime offtime = DatabaseCalls.GetOffTimeValue(devicename, timezoneoffset);
                    DateTime ontime  = DatabaseCalls.GetOnTimeValue(devicename, timezoneoffset);

                    NextTime.Text = "Off from: " + offtime.ToShortTimeString() + " - " + ontime.ToShortTimeString();

                    newofftime.Text = offtime.ToString("HH:mm");
                    newontime.Text  = ontime.ToString("HH:mm");
                }
                catch
                {
                    NextTime.Text = "- None";
                }


                //Power
                CurrentPower.Text = DatabaseCalls.GetNewestPowerValue(devicename).ToString() + " W";

                //Temperature
                CurrentTemperature.Text = DatabaseCalls.GetNewestTemperatureValue(devicename).ToString() + " °C";
            }
            catch
            {
                LastUpdatedTime.CssClass = "alert alert-warning";
                LastUpdatedTime.Text     = "This device with UID: " + DatabaseCalls.GetUIDFromDeviceName(devicename) + " has not connected to our servers yet";
            }
        }