Inheritance: IGreenhouse
        private void Bind()
        {
            var greenhouse = Greenhouse.ByID(_webContext.GreenhouseIdSession);

            LoadData(greenhouse);
            LoadLocation(greenhouse.Address);
            LoadSection(greenhouse.Sections.ToList());
            LoadGreenhouseUsers(greenhouse.GreenhouseUsers);
        }
        protected void butUpdateGreenhouse_Click(object sender, EventArgs e)
        {
            var g = new Greenhouse
            {
                ID      = _webContext.GreenhouseIdSession,
                Address = new Address
                {
                    City            = tbxCity.Text,
                    Country         = tbxCountry.Text,
                    IsDefault       = cboIsDefault.Checked,
                    StateOrProvince = tbxState.Text,
                    StreetLine1     = tbxSteetAddress1.Text,
                    StreetLine2     = tbxSteetAddress2.Text,
                    Zip             = tbxZipCode.Text.ToNullableInt()
                }
            };

            g.Save();
            LoadLocation(g.Address);
            linkEdit.Visible             = true;
            pnlEditGreenhouse.Visible    = false;
            pnlGreenhouseAddress.Visible = true;
        }
        protected void lbNewSection_Click(object sender, EventArgs e)
        {
            lvSections.EditIndex          = -1;
            lvSections.InsertItemPosition = InsertItemPosition.FirstItem;
            ((LinkButton)sender).Visible  = false;
            Bind();

            var ddlPreset = lvSections.InsertItem.FindControl("ddlPreset") as DropDownList;

            if (ddlPreset == null)
            {
                return;
            }
            ddlPreset.DataSource     = Preset.All();
            ddlPreset.DataTextField  = "Name";
            ddlPreset.DataValueField = "ID";
            ddlPreset.DataBind();

            var pnlOwner = lvSections.InsertItem.FindControl("pnlOwner") as Panel;

            if (pnlOwner != null)
            {
                pnlOwner.Visible = User.IsInRole("administrator");
            }

            var ddlOwner = lvSections.InsertItem.FindControl("ddlOwner") as DropDownList;

            if (ddlOwner != null)
            {
                var users = Greenhouse.ByID(_webContext.GreenhouseIdSession).GreenhouseUsers;
                ddlOwner.DataSource     = users;
                ddlOwner.DataTextField  = "Username";
                ddlOwner.DataValueField = "UserID";
                ddlOwner.DataBind();
            }
        }
 public void LoadData(Greenhouse greenhouse)
 {
     Page.Title = string.Format("{0} — Smart Greenhouse Solutions", greenhouse);
     litGreenhouseTitle.Text = greenhouse.ToString();
 }
        public void lvSections_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
            var litPresetID = e.Item.FindControl("litPresetID") as Literal;
            var ddlPreset   = e.Item.FindControl("ddlPreset") as DropDownList;

            if (ddlPreset != null)
            {
                ddlPreset.DataSource     = Preset.All();
                ddlPreset.DataTextField  = "Name";
                ddlPreset.DataValueField = "ID";
                if (litPresetID != null)
                {
                    ddlPreset.SelectedValue = litPresetID.Text;
                }
                ddlPreset.DataBind();
            }

            var pnlOwner = e.Item.FindControl("pnlOwner") as Panel;

            if (pnlOwner != null)
            {
                pnlOwner.Visible = User.IsInRole("administrator");
            }

            var litUserID = e.Item.FindControl("litUserID") as Literal;
            var ddlOwner  = e.Item.FindControl("ddlOwner") as DropDownList;

            if (ddlOwner != null)
            {
                var users = Greenhouse.ByID(_webContext.GreenhouseIdSession).GreenhouseUsers;
                ddlOwner.DataSource     = users;
                ddlOwner.DataTextField  = "Username";
                ddlOwner.DataValueField = "UserID";
                if (litUserID != null)
                {
                    ddlOwner.SelectedValue = litUserID.Text;
                }
                ddlOwner.DataBind();
            }

            var litIsTemperatureActivated = e.Item.FindControl("litIsTemperatureActivated") as Literal;
            var pnlTemperature            = e.Item.FindControl("pnlTemperature") as Panel;

            if (litIsTemperatureActivated != null)
            {
                if (pnlTemperature != null)
                {
                    pnlTemperature.Visible = bool.Parse(litIsTemperatureActivated.Text);
                }
            }

            var litIsLightActivated = e.Item.FindControl("litIsLightActivated") as Literal;
            var pnlLighting         = e.Item.FindControl("pnlLighting") as Panel;

            if (litIsLightActivated != null)
            {
                if (pnlLighting != null)
                {
                    pnlLighting.Visible = bool.Parse(litIsLightActivated.Text);
                }
            }

            var litIsHumidityActivated = e.Item.FindControl("litIsHumidityActivated") as Literal;
            var pnlHumidity            = e.Item.FindControl("pnlHumidity") as Panel;

            if (litIsHumidityActivated != null)
            {
                if (pnlHumidity != null)
                {
                    pnlHumidity.Visible = bool.Parse(litIsHumidityActivated.Text);
                }
            }

            var litIsWaterLevelActivated = e.Item.FindControl("litIsWaterLevelActivated") as Literal;
            var pnlWaterLevel            = e.Item.FindControl("pnlWaterLevel") as Panel;

            if (litIsWaterLevelActivated != null)
            {
                if (pnlWaterLevel != null)
                {
                    pnlWaterLevel.Visible = bool.Parse(litIsWaterLevelActivated.Text);
                }
            }

            var lblNoModules = e.Item.FindControl("lblNoModules") as Label;

            if (litIsTemperatureActivated != null &&
                litIsLightActivated != null &&
                litIsHumidityActivated != null &&
                litIsWaterLevelActivated != null)
            {
                if (!bool.Parse(litIsTemperatureActivated.Text) &&
                    !bool.Parse(litIsLightActivated.Text) &&
                    !bool.Parse(litIsHumidityActivated.Text) &&
                    !bool.Parse(litIsWaterLevelActivated.Text))
                {
                    if (lblNoModules != null)
                    {
                        lblNoModules.Visible = true;
                    }
                }
            }
        }
 public void LoadData(Greenhouse greenhouse)
 {
     Page.Title = string.Format("{0} — Smart Greenhouse Solutions", greenhouse);
     litGreenhouseTitle.Text = greenhouse.ToString();
 }
 protected void butUpdateGreenhouse_Click(object sender, EventArgs e)
 {
     var g = new Greenhouse
         {
             ID = _webContext.GreenhouseIdSession,
             Address = new Address
                           {
                               City = tbxCity.Text,
                               Country = tbxCountry.Text,
                               IsDefault = cboIsDefault.Checked,
                               StateOrProvince = tbxState.Text,
                               StreetLine1 = tbxSteetAddress1.Text,
                               StreetLine2 = tbxSteetAddress2.Text,
                               Zip = tbxZipCode.Text.ToNullableInt()
                           }
         };
     g.Save();
     LoadLocation(g.Address);
     linkEdit.Visible = true;
     pnlEditGreenhouse.Visible = false;
     pnlGreenhouseAddress.Visible = true;
 }