public static void UpdateSignCategorySigns(int signCategoryId) { using (RockContext rockContext = new RockContext()) { SignCategory signCategory = new SignCategoryService(rockContext).Get(signCategoryId); if (signCategory != null) { var signs = new SignService(rockContext) .Queryable() .Where(s => s.SignCategories.Select(sc => sc.Id).Contains(signCategoryId)) .ToList(); foreach (var sign in signs) { List <string> codes = new List <string>(); var categoriesCodes = sign.SignCategories .Select(sc => sc.Codes) .ToList(); foreach (var code in categoriesCodes) { codes.AddRange((code ?? "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .ToList() ); } MicroframeConnection signConnection = new MicroframeConnection(sign.IPAddress, sign.Port.AsIntegerOrNull() ?? 9107, sign.PIN); signConnection.UpdateMessages(codes); } } } }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var signCategoryService = new SignCategoryService(new RockContext()); var signCategories = signCategoryService.Queryable().Select(s => s).OrderBy(s => s.Name).ToList(); gSignCategories.DataSource = signCategories; gSignCategories.DataBind(); }
protected void mdSignCategories_SaveClick(object sender, EventArgs e) { var signCategoryId = ddlSignCategories.SelectedValue.AsInteger(); var signCategory = new SignCategoryService(new RockContext()).Get(signCategoryId); if (signCategory != null & !SignCategories.ContainsKey(signCategory.Id)) { SignCategories.Add(signCategory.Id, signCategory.Name); } BindSignCategories(); mdSignCategories.Hide(); }
protected void gSignCategories_Delete(object sender, RowEventArgs e) { var rockContext = new RockContext(); SignCategoryService signCategoryService = new SignCategoryService(rockContext); SignCategory signCategory = signCategoryService.Get(e.RowKeyId); if (signCategory != null) { signCategoryService.Delete(signCategory); rockContext.SaveChanges(); } BindGrid(); }
protected void btnSave_Click(object sender, EventArgs e) { SignCategory signCategory = null; var rockContext = new RockContext(); var signCategoryService = new SignCategoryService(rockContext); var attributeService = new AttributeService(rockContext); int signCategoryId = int.Parse(hfSignCategoryId.Value); if (signCategoryId != 0) { signCategory = signCategoryService.Get(signCategoryId); } if (signCategory == null) { // Check for existing var existingDevice = signCategoryService.Queryable() .Where(k => k.Name == tbName.Text) .FirstOrDefault(); if (existingDevice != null) { nbDuplicateSign.Text = string.Format("A sign category already exists with the name '{0}'. Please use a different device name.", existingDevice.Name); nbDuplicateSign.Visible = true; } else { signCategory = new SignCategory(); signCategoryService.Add(signCategory); } } if (signCategory != null) { signCategory.Name = tbName.Text; signCategory.Description = tbDescription.Text; if (!signCategory.IsValid || !Page.IsValid) { // Controls will render the error messages return; } rockContext.SaveChanges(); NavigateToParentPage(); } }
/// <summary> /// Shows the edit. /// </summary> /// <param name="DeviceId">The device identifier.</param> public void ShowDetail(int signCategoryId) { pnlDetails.Visible = true; SignCategory signCategory = null; var rockContext = new RockContext(); if (!signCategoryId.Equals(0)) { signCategory = new SignCategoryService(rockContext).Get(signCategoryId); lActionTitle.Text = ActionTitle.Edit(SignCategory.FriendlyTypeName).FormatAsHtmlTitle(); } if (signCategory == null) { signCategory = new SignCategory { Id = 0 }; lActionTitle.Text = ActionTitle.Add(SignCategory.FriendlyTypeName).FormatAsHtmlTitle(); } hfSignCategoryId.Value = signCategory.Id.ToString(); tbName.Text = signCategory.Name; tbDescription.Text = signCategory.Description; // render UI based on Authorized and IsSystem bool readOnly = false; nbEditModeMessage.Text = string.Empty; if (!IsUserAuthorized(Authorization.EDIT)) { readOnly = true; nbEditModeMessage.Text = EditModeMessage.ReadOnlyEditActionNotAllowed(SignCategory.FriendlyTypeName); } if (readOnly) { lActionTitle.Text = ActionTitle.View(SignCategory.FriendlyTypeName); btnCancel.Text = "Close"; } tbName.ReadOnly = readOnly; tbDescription.ReadOnly = readOnly; btnSave.Visible = !readOnly; }
private void ShowCategory(int signCategoryId) { tbCode.MaxLength = GetAttributeValue("MaxLength").AsIntegerOrNull() ?? 4; phCodes.Controls.Clear(); SignCategory signCategory = new SignCategoryService(new RockContext()).Get(signCategoryId); if (signCategory == null) { return; } ltCategory.Text = signCategory.Name; hfSignCategory.Value = signCategoryId.ToString(); pnlCategory.Visible = true; ltCategory.Text = signCategory.Name; var codes = (signCategory.Codes ?? "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (codes.Any()) { foreach (var code in codes) { Panel pnlCode = new Panel(); pnlCode.CssClass = "codes"; phCodes.Controls.Add(pnlCode); Literal ltCode = new Literal(); ltCode.Text = code + " "; pnlCode.Controls.Add(ltCode); LinkButton lbCode = new LinkButton(); lbCode.ID = code + signCategory.Id.ToString(); lbCode.Text = "<i class='fa fa-close'></i>"; lbCode.Click += (s, e) => RemoveCode(code, signCategoryId); pnlCode.Controls.Add(lbCode); } } else { Literal ltEmpty = new Literal(); ltEmpty.Text = "<i>This category currently contains no codes</i>"; phCodes.Controls.Add(ltEmpty); } }
/// <summary> /// Binds the grid. /// </summary> private void BindGrid() { var signCategoryService = new SignCategoryService(new RockContext()); var signCategories = signCategoryService.Queryable() .Select(sc => sc) .OrderBy(s => s.Name) .ToList() .Select(sc => new { Id = sc.Id, Name = sc.Name, Count = ((sc.Codes ?? "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries)).Count().ToString() } ).ToList(); gSignCategories.DataSource = signCategories; gSignCategories.DataBind(); }
protected void btnAdd_Click(object sender, EventArgs e) { int maxCodeLength = GetAttributeValue("MaxLength").AsIntegerOrNull() ?? 4; var signCategoryId = hfSignCategory.Value.AsInteger(); RockContext rockContext = new RockContext(); SignCategory signCategory = new SignCategoryService(rockContext).Get(signCategoryId); var code = tbCode.Text.Trim().ToUpper(); tbCode.Text = ""; if (string.IsNullOrWhiteSpace(code)) { return; } if (code.Length > maxCodeLength) { code = code.Substring(0, maxCodeLength); } if (signCategory != null) { var codes = (signCategory.Codes ?? "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (!codes.Contains(code)) { codes.Add(code); signCategory.Codes = string.Join(",", codes); rockContext.SaveChanges(); UpdateSigns(signCategoryId); } ShowCategory(signCategoryId); BindGrid(); } else { pnlCategory.Visible = false; return; } }
private void RemoveCode(string code, int signCategoryId) { RockContext rockContext = new RockContext(); SignCategory signCategory = new SignCategoryService(rockContext).Get(signCategoryId); if (signCategory != null) { var codes = (signCategory.Codes ?? "").Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).ToList(); if (codes.Contains(code)) { codes.Remove(code); signCategory.Codes = string.Join(",", codes); rockContext.SaveChanges(); UpdateSigns(signCategoryId); } ShowCategory(signCategoryId); BindGrid(); } else { pnlCategory.Visible = false; return; } }
protected void btnSave_Click(object sender, EventArgs e) { Sign sign = null; var rockContext = new RockContext(); var signService = new SignService(rockContext); var attributeService = new AttributeService(rockContext); int signId = int.Parse(hfSignId.Value); if (signId != 0) { sign = signService.Get(signId); } if (sign == null) { // Check for existing var existingDevice = signService.Queryable() .Where(k => k.Name == tbName.Text) .FirstOrDefault(); if (existingDevice != null) { nbDuplicateSign.Text = string.Format("A sign already exists with the name '{0}'. Please use a different device name.", existingDevice.Name); nbDuplicateSign.Visible = true; } else { sign = new Sign(); signService.Add(sign); } } if (sign != null) { sign.Name = tbName.Text; sign.PIN = tbPIN.Text; sign.Description = tbDescription.Text; sign.IPAddress = tbIPAddress.Text; sign.Port = tbPort.Text; if (!sign.IsValid || !Page.IsValid) { // Controls will render the error messages return; } var keys = SignCategories.Select(sc => sc.Key).ToList(); foreach (var signCategory in sign.SignCategories.ToList()) { if (!keys.Contains(signCategory.Id)) { sign.SignCategories.Remove(signCategory); } } var newSignCategories = new SignCategoryService(rockContext).GetByIds(keys).ToList(); foreach (var newSignCategory in newSignCategories) { if (!sign.SignCategories.Select(sc => sc.Id).Contains(newSignCategory.Id)) { sign.SignCategories.Add(newSignCategory); } } rockContext.SaveChanges(); NavigateToParentPage(); } }