protected void dlRobots_ItemDataBound(object sender, DataListItemEventArgs e) { try { if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { Wink.Robot robot = ((Wink.Robot)e.Item.DataItem); //BIND INFO BUTTON var props = typeof(Wink.Robot).GetProperties(); var properties = new List <KeyValuePair <string, string> >(); foreach (var prop in props) { if (prop.Name != "json") { TextInfo textInfo = new CultureInfo("en-US", false).TextInfo; string propname = textInfo.ToTitleCase(prop.Name.Replace("_", " ")); var propvalue = prop.GetValue(robot, null); if (propvalue != null) { properties.Add(new KeyValuePair <string, string>(propname, propvalue.ToString())); } } } DataList dlProperties = (DataList)e.Item.FindControl("dlProperties"); if (dlProperties != null) { var displayprops = properties.Where(p => p.Value.ToLower() != "schedules only"); dlProperties.DataSource = displayprops; dlProperties.DataBind(); } TextBox tbPosition = (TextBox)e.Item.FindControl("tbPosition"); tbPosition.Text = robot.position > 1000 ? "" : (robot.position).ToString(); TextBox tbDisplayName = (TextBox)e.Item.FindControl("tbDisplayName"); tbDisplayName.Text = robot.displayName; //Assign Image ImageButton imgIcon = (ImageButton)e.Item.FindControl("imgIcon"); imgIcon.ImageUrl = "~/Images/Robots/" + (robot.isschedule ? "schedule" : "robot") + robot.enabled + ".png"; if (robot.isschedule) { imgIcon.Enabled = false; } //Set Last/Next Trigger Time string tooltip = "Last Triggered: " + robot.last_fired; if (robot.isschedule) { tooltip += Environment.NewLine + "Next Scheduled Run: " + robot.next_run; } TextBox tbName = (TextBox)e.Item.FindControl("tbName"); tbName.ToolTip = tooltip; //Resize for long names int i = tbName.Text.Length; int rowsize = (i / 23) + 2; tbName.Rows = rowsize; //Set Alert icon DateTime lastalert = DateTime.MinValue; if (DateTime.TryParse(robot.last_fired, out lastalert)) { string alertTimeout = SettingMgmt.getSetting("Robot-Alert-Minutes-Since-Last-Trigger"); Int32 timeout = 60; Int32.TryParse(alertTimeout, out timeout); DateTime lastTrigger = lastalert; DateTime dateAlert = DateTime.Now.AddMinutes(timeout * -1); if (lastTrigger > dateAlert) { Image imgAlert = (Image)e.Item.FindControl("imgAlert"); imgAlert.Visible = true; } } } } catch (Exception ex) { throw; //EventLog.WriteEntry("WinkAtHome.Robots.dlRobots_ItemDataBound", ex.Message, EventLogEntryType.Error); } }
protected void btnClose_Click(object sender, EventArgs e) { try { LinkButton ib = (LinkButton)sender; TextBox tbPosition = (TextBox)ib.NamingContainer.FindControl("tbPosition"); TextBox tbDisplayName = (TextBox)ib.NamingContainer.FindControl("tbDisplayName"); Label lblPositionBad = (Label)ib.NamingContainer.FindControl("lblPositionBad"); ModalPopupExtender mpeInfo = (ModalPopupExtender)ib.NamingContainer.FindControl("mpeInfo"); Wink.Robot item = Wink.Robot.getRobotByID(ib.CommandArgument); bool savePosSuccess = false; bool saveNameSuccess = false; if (item != null) { //SAVE POSITION try { Int32 pos = 9999; if (string.IsNullOrWhiteSpace(tbPosition.Text)) { savePosSuccess = true; } else if (Int32.TryParse(tbPosition.Text, out pos) && pos > 0 && pos < 1001) { List <string> existingList = new List <string>(); foreach (DataListItem dli in dlRobots.Items) { HiddenField hfRobotID = (HiddenField)dli.FindControl("hfRobotID"); existingList.Add(hfRobotID.Value); } string newItem = item.id; existingList.RemoveAll(s => s == newItem); existingList.Insert(pos - 1, newItem); foreach (string ID in existingList) { int position = existingList.IndexOf(ID) + 1; Wink.Robot.setRobotPosition(ID, position); } lblPositionBad.Visible = false; savePosSuccess = true; } else { lblPositionBad.Visible = true; } } catch (Exception ex) { lblPositionBad.Visible = true; } //SAVE DISPLAY NAME try { Wink.Robot.setRobotDisplayName(item.id, tbDisplayName.Text); saveNameSuccess = true; } catch (Exception ex) { } } if (saveNameSuccess && savePosSuccess) { Session["modalshowing"] = "false"; mpeInfo.Hide(); BindData(); } else { mpeInfo.Show(); } } catch (Exception ex) { throw; //EventLog.WriteEntry("WinkAtHome.Robots.btnClose_Click", ex.Message, EventLogEntryType.Error); } }