/// <summary> /// Handles the <see cref="CustomValidator.ServerValidate"/> event of the <c>UniqueNameValidator</c> control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="args">The <see cref="ServerValidateEventArgs"/> instance containing the event data.</param> protected void UniqueNameValidator_ServerValidate(object source, ServerValidateEventArgs args) { var gridItem = Engage.Utility.FindParentControl <GridDataItem>((CustomValidator)source); var categoryId = gridItem.ItemIndex >= 0 ? (int)gridItem.OwnerTableView.DataKeyValues[gridItem.ItemIndex]["Id"] : -1; args.IsValid = !CategoryCollection.Load(this.PortalId).Any(category => category.Id != categoryId && category.Name.Equals(args.Value, StringComparison.CurrentCultureIgnoreCase)); }
/// <summary> /// Raises the <see cref="Control.Init"/> event. /// </summary> /// <param name="e">An <see cref="EventArgs"/> object that contains the event data.</param> protected override void OnInit(EventArgs e) { if (!this.PermissionsService.CanManageCategories) { this.DenyAccess(); } base.OnInit(e); this.Load += this.Page_Load; this.CategoriesGrid.ColumnCreated += this.CategoriesGrid_ColumnCreated; this.CategoriesGrid.DeleteCommand += this.CategoriesGrid_DeleteCommand; this.CategoriesGrid.ItemCreated += this.CategoriesGrid_ItemCreated; this.CategoriesGrid.NeedDataSource += this.CategoriesGrid_NeedDataSource; this.CategoriesGrid.InsertCommand += this.CategoriesGrid_InsertCommand; this.CategoriesGrid.UpdateCommand += this.CategoriesGrid_UpdateCommand; this.CategoriesGrid.ItemDataBound += this.CategoriesGrid_ItemDataBound; this.PreRender += (s, o) => this.HideExpandColumnRecursive(this.CategoriesGrid.MasterTableView); this.parentCategories = CategoryCollection.Load(this.PortalId); foreach (var category in this.parentCategories.Where(c => string.IsNullOrEmpty(c.Name))) { category.Name = this.GetDefaultCategoryName(); } }
/// <summary> /// Loads the category info into the static CategoryList /// </summary> public static void Load() { catList = new CategoryCollection(); IDataReader rdr = Category.FetchAll(OrderBy.Asc("listOrder")); catList.Load(rdr); rdr.Close(); }
/// <summary> /// Returns all categories for a given product /// </summary> /// <param name="productID"></param> /// <returns>CategoryCollection</returns> public static CategoryCollection GetByProductID(int productID) { IDataReader rdr = SPs.StoreCategoryGetByProductID(productID).GetReader(); CategoryCollection list = new CategoryCollection(); list.Load(rdr); rdr.Close(); return(list); }
/// <summary> /// Ensures that there is at least one category in this portal; otherwise, creates the default category. /// </summary> private void EnsureDefaultCategoryExists() { if (CategoryCollection.Load(this.PortalId).Any()) { return; } var defaultCategory = Category.Create(this.PortalId, null, string.Empty, null); defaultCategory.Save(this.UserId); }
/// <summary> /// Handles the <see cref="RadGrid.NeedDataSource"/> event of the <see cref="CategoriesGrid"/> control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="e">The <see cref="GridNeedDataSourceEventArgs"/> instance containing the event data.</param> private void CategoriesGrid_NeedDataSource(object source, GridNeedDataSourceEventArgs e) { IEnumerable <Category> categories = CategoryCollection.Load(this.PortalId); if (this.CategoryIds.Any()) { var categoryIdsWithAncestor = Utility.AddAncestorIds(this.CategoryIds.ToArray(), categories.ToArray(), true).ToArray(); categories = categories.Where(category => categoryIdsWithAncestor.Contains(category.Id)); } this.CategoriesGrid.DataSource = categories.ToList(); }
/// <summary> /// Generate the list of all categories /// </summary> private void GenerateCatList() { pnlCatList.Controls.Clear(); ddlParentCat.Items.Clear(); //Get List of all categories CategoryCollection AllCats = new CategoryCollection().Where("parent", null); AllCats.Load(); // Add the null value in there ddlParentCat.Items.Add(new ListItem("_", "NULL")); for (int i = 0; i < AllCats.Count; i++) { VL.Controls.CommonControl newParentCat = (VL.Controls.CommonControl)LoadControl(VL.Config.GetConfigPath("CatEditItem")); newParentCat.initControl(AllCats[i]); pnlCatList.Controls.Add(newParentCat); //Add to the drop down list of all parent category. //We will use that to add a new category ListItem newLItem = new ListItem(AllCats[i].CatName, AllCats[i].CategoryID.ToString()); ddlParentCat.Items.Add(newLItem); } }
/// <summary> /// Loads the settings. /// </summary> public override void LoadSettings() { base.LoadSettings(); try { if (this.IsPostBack) { return; } Localization.LocalizeGridView(ref this.DetailsDisplayModuleGrid, this.LocalResourceFile); this.DetailsDisplayModuleGrid.DataSource = new ModuleController().GetModulesByDefinition(this.PortalId, Utility.ModuleDefinitionFriendlyName); this.DetailsDisplayModuleGrid.DataBind(); this.CategoriesCheckBoxTreeView.DataTextField = "Name"; this.CategoriesCheckBoxTreeView.DataValueField = "Id"; this.CategoriesCheckBoxTreeView.DataFieldID = "Id"; this.CategoriesCheckBoxTreeView.DataFieldParentID = "ParentId"; var categoryList = (from category in CategoryCollection.Load(this.PortalId) select new { Name = string.IsNullOrEmpty(category.Name) ? this.Localize("DefaultCategory", this.LocalSharedResourceFile) : category.Name, Id = category.Id.ToString(CultureInfo.InvariantCulture), ParentId = category.ParentId.HasValue ? category.ParentId.Value.ToString(CultureInfo.InvariantCulture) : string.Empty }).ToList(); categoryList.Add(new { Name = this.Localize("All Categories.Text"), Id = string.Empty, ParentId = (string)null }); this.CategoriesCheckBoxTreeView.DataSource = categoryList; this.CategoriesCheckBoxTreeView.DataBind(); this.SetOptions(); } catch (Exception exc) { Exceptions.ProcessModuleLoadException(this, exc); } }
/// <summary> /// Performs all necessary operations to display the control's data correctly. /// </summary> protected override void BindData() { this.CategoriesTreeView.DataTextField = "Name"; this.CategoriesTreeView.DataValueField = "Id"; this.CategoriesTreeView.DataFieldID = "Id"; this.CategoriesTreeView.DataFieldParentID = "ParentId"; IEnumerable <Category> categories = CategoryCollection.Load(this.PortalId); if (this.CategoryIds.Any()) { var categoryIdsWithAncestor = Utility.AddAncestorIds(this.CategoryIds.ToArray(), categories.ToArray(), true).ToArray(); categories = categories.Where(category => categoryIdsWithAncestor.Contains(category.Id)); } var categoryNodeItems = categories.Select(category => new { Name = string.IsNullOrEmpty(category.Name) ? this.Localize("DefaultCategory.Text", this.LocalSharedResourceFile) : category.Name, Id = category.Id.ToString(CultureInfo.InvariantCulture), ParentId = category.ParentId.HasValue ? category.ParentId.Value.ToString(CultureInfo.InvariantCulture) : string.Empty, }).ToList(); if (categoryNodeItems.Count > 1) { categoryNodeItems.Add(new { Name = this.Localize("AllListItem.Text"), Id = string.Empty, ParentId = (string)null }); } else { this.Visible = false; } this.CategoriesTreeView.DataSource = categoryNodeItems; this.CategoriesTreeView.DataBind(); }
/// <summary> /// Initialize the control /// </summary> /// <param name="inObj"></param> public override void initControl(params object[] inObj) { //Show information of this category _thisCat = (VL.ORM.Category)inObj[0]; lblCatID.InnerText = _thisCat.CategoryID.ToString(); txtName.Text = _thisCat.CatName; txtURLRewrite.Text = _thisCat.URLRewrite; txtArrange.Text = _thisCat.Arrange.ToString(); lblLinkCount.InnerText = _thisCat.CatLinks().Count.ToString() + " links"; //Find the child cat in the list CategoryCollection childCats = new CategoryCollection().Where("parent", _thisCat.CategoryID); childCats.Load(); //Generate all child categories if (childCats.Count > 0) { foreach (Category item in childCats) { VL.Controls.CommonControl childItem = (VL.Controls.CommonControl)LoadControl(VL.Config.GetConfigPath("CatEditItem")); childItem.initControl(item); pnlChildCats.Controls.Add(childItem); } } }
/// <summary> /// Fills the <see cref="TimeZoneDropDownList"/> and <see cref="CategoryComboBox"/>. /// </summary> private void FillLists() { this.TimeZoneDropDownList.DataSource = TimeZoneInfo.GetSystemTimeZones(); this.TimeZoneDropDownList.DataTextField = "DisplayName"; this.TimeZoneDropDownList.DataValueField = "Id"; this.TimeZoneDropDownList.DataBind(); this.TimeZoneDropDownList.SetSelectedString(Dnn.Utility.GetUserTimeZone(this.UserInfo, this.PortalSettings).Id); var categories = (from category in CategoryCollection.Load(this.PortalId) where !this.CategoryIds.Any() || this.CategoryIds.Contains(category.Id) select category).ToList(); var indentedList = new List <RadComboBoxItem>(); this.ToIndentedList(indentedList, categories, null, 0); this.CategoryComboBox.AllowCustomText = this.PermissionsService.CanManageCategories; this.CategoryComboBox.DataTextField = "Text"; this.CategoryComboBox.DataValueField = "Value"; this.CategoryComboBox.DataSource = indentedList; this.CategoryComboBox.DataBind(); // don't show the categories if there's only one option this.CategoryPanel.Visible = this.CategoryComboBox.AllowCustomText || categories.Count() > 1; }
/// <summary> /// Performs all necessary operations to display the control's data correctly. /// </summary> protected override void BindData() { this.CategoriesList.DataTextField = "Name"; this.CategoriesList.DataValueField = "Id"; this.CategoriesList.DataSource = from category in CategoryCollection.Load(this.PortalId) where !this.CategoryIds.Any() || this.CategoryIds.Contains(category.Id) select new { Name = string.IsNullOrEmpty(category.Name) ? this.Localize("DefaultCategory.Text", this.LocalSharedResourceFile) : category.Name, Id = category.Id.ToString(CultureInfo.InvariantCulture) }; this.DataBind(); if (this.CategoriesList.Items.Count > 1) { this.CategoriesList.Items.Insert(0, new ListItem(this.Localize("AllListItem.Text"), string.Empty)); } else { this.CategoriesList.Enabled = false; } }
/// <summary> /// Gets the value of the property with the given <paramref name="propertyName"/>, or <see cref="string.Empty"/> if a property with that name does not exist on this object or is <c>null</c>. /// </summary> /// <remarks> /// To avoid conflicts with template syntax, avoid using the following symbols in the property name /// <list type="bullet"> /// <item><description>:</description></item> /// <item><description>%</description></item> /// <item><description>$</description></item> /// <item><description>#</description></item> /// <item><description>></description></item> /// <item><description><</description></item> /// <item><description>"</description></item> /// <item><description>'</description></item> /// </list> /// </remarks> /// <param name="propertyName">Name of the property.</param> /// <param name="format"> /// A numeric or DateTime format string, or one of the string formatting options accepted by <see cref="TemplateEngine.FormatString"/>, /// or <c>null</c> or <see cref="string.Empty"/> to apply the default format. /// </param> /// <returns>The string representation of the value of this instance as specified by <paramref name="format"/>.</returns> public override string GetValue(string propertyName, string format) { if (propertyName == null) { throw new ArgumentNullException("propertyName"); } switch (propertyName.ToUpperInvariant()) { case "MULTIPLE CATEGORIES": case "MULTIPLECATEGORIES": IEnumerable <Category> categories = CategoryCollection.Load(this.PortalId); var moduleCategoryIds = ModuleSettings.GetCategoriesFor(new FakeModuleControlBase(Utility.DesktopModuleName, this.ModuleContext.Configuration)); if (moduleCategoryIds.Any()) { var categoryIdsWithAncestor = Utility.AddAncestorIds(moduleCategoryIds.ToArray(), categories.ToArray(), true); categories = categories.Where(category => categoryIdsWithAncestor.Contains(category.Id)); } return((categories.Count() > 1).ToString(CultureInfo.InvariantCulture)); } return(base.GetValue(propertyName, format)); }
/// <summary> /// Handles the <see cref="CustomValidator.ServerValidate"/> event of the <see cref="UniqueCategoryNameValidator"/> control. /// </summary> /// <param name="source">The source of the event.</param> /// <param name="args">The <see cref="ServerValidateEventArgs"/> instance containing the event data.</param> private void UniqueCategoryNameValidator_ServerValidate(object source, ServerValidateEventArgs args) { // they picked an existing category, or the new category name doesn't exist in the list of this portal's categories args.IsValid = this.CategoryComboBox.SelectedItem != null || !CategoryCollection.Load(this.PortalId).Any(category => category.Name.Equals(args.Value, StringComparison.CurrentCultureIgnoreCase)); }