/// <summary> /// Handles the Click event of the IsRequired control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void IsRequired_Click(object sender, EventArgs e) { try { CheckBox checkbox = sender as CheckBox; if (checkbox != null) { DataGridItem row = checkbox.NamingContainer as DataGridItem; int attributeId = 0; if (row != null) { int.TryParse(dgAssociatedAttributes.DataKeys[row.ItemIndex].ToString(), out attributeId); } Query query = new Query(ProductAttributeMap.Schema).AddWhere(ProductAttributeMap.Columns.AttributeId, Comparison.Equals, attributeId).AddWhere(ProductAttributeMap.Columns.ProductId, Comparison.Equals, productId); ProductAttributeMapCollection productAttributeMapCollection = new ProductAttributeMapController().FetchByQuery(query); if (productAttributeMapCollection.Count > 0) { if (checkbox.Checked) { productAttributeMapCollection[0].IsRequired = true; } else { productAttributeMapCollection[0].IsRequired = false; } productAttributeMapCollection[0].Save(WebUtility.GetUserName()); Store.Caching.ProductCache.RemoveAssociatedAttributeCollectionFromCache(productId); } LoadAssociatedAttributes(); } } catch (Exception ex) { Logger.Error(typeof(attributes).Name + ".IsRequired_Click", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }
/// <summary> /// Handles the ItemReorder event of the Items control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="T:System.EventArgs"/> instance containing the event data.</param> protected void Items_ItemReorder(object sender, EventArgs e) { try { ImageButton theButton = sender as ImageButton; Query query = new Query(ProductAttributeMap.Schema). WHERE(ProductAttributeMap.Columns.ProductId, Comparison.Equals, productId). ORDER_BY(ProductAttributeMap.Columns.SortOrder); ProductAttributeMapCollection productAttributeMapCollection = new ProductAttributeMapController().FetchByQuery(query); if (productAttributeMapCollection != null) { int attributeId = 0; int.TryParse(theButton.CommandArgument.ToString(), out attributeId); if (attributeId > 0) { ProductAttributeMap productAttributeMapMoved = productAttributeMapCollection.Find(delegate(ProductAttributeMap productAttributeMap) { return(productAttributeMap.AttributeId == attributeId); }); int index = productAttributeMapCollection.IndexOf(productAttributeMapMoved); productAttributeMapCollection.RemoveAt(index); if (theButton.CommandName.ToLower() == "up") { productAttributeMapCollection.Insert(index - 1, productAttributeMapMoved); } else if (theButton.CommandName.ToLower() == "down") { productAttributeMapCollection.Insert(index + 1, productAttributeMapMoved); } int i = 1; foreach (ProductAttributeMap productAttributeMap in productAttributeMapCollection) { productAttributeMap.SortOrder = i++; } productAttributeMapCollection.SaveAll(WebUtility.GetUserName()); LoadAssociatedAttributes(); } } } catch (Exception ex) { Logger.Error(typeof(attributes).Name + ".Items_ItemReorder", ex); base.MasterPage.MessageCenter.DisplayCriticalMessage(ex.Message); } }