protected virtual void OnDelete() { this.Operation = OperationType.Deleting; string deletedone = "delete done"; ITranslationResult trares = this.Translator.Translate(null, deletedone, null); if (trares.IsSuccessful()) { deletedone = trares.Translation; } List <ITemplatingItem> itemsToRemove = new List <ITemplatingItem>(); try { ITemplatingItem[] arr = new ITemplatingItem[this._items.Count]; this._items.CopyTo(arr, 0); ITemplatingItem[] array = arr; for (int i = 0; i < array.Length; i++) { ITemplatingItem item = array[i]; if (item.IsCurrent) { this.OnMilestone("save-delete"); bool deleted = false; if (!item.IsNew) { if (null != this.Delete) { Delete(this, new DeleteEventArgs((IDictionary)item.Data)); } deleted = true; } this.OnValidationSucceed(null); if (deleted && !this._monitor.HasErrors()) { itemsToRemove.Add(item); this._monitor.Register(this.Reporter, this._monitor.NewEventInstance(deletedone, EVENT_TYPE.Info)); } this.NeedsDelete = false; this.Operation = OperationType.Viewing; } } if (!this._monitor.HasErrors()) { this.OnMilestone("deleted"); } } catch (Exception ex) { this._monitor.Register(this.Reporter, this._monitor.NewEventInstance("delete error", null, ex, EVENT_TYPE.Error)); } foreach (ITemplatingItem item in itemsToRemove) { this._items.Remove(item); } _paginater.IsFrozen = false; _paginater.OnBackward(); _paginater.OnForward(); }
protected void InitiateRunningTotals() { if (!string.IsNullOrEmpty(this._totalsByMembers)) { this.runningTotalsItem = this._template.NewTemplatingItemInstance(); this.runningTotalsItem.Data = new Dictionary <string, decimal>(); this.runningTotalsItem.IsTotals = true; } }
protected virtual void OnInsert() { ITemplatingItem newItem = this._items.Add(false, true, true, true); this._template.PopulateItem(this._templateConfig, newItem, null); newItem.HasChanges = true; this.Operation = OperationType.Inserting; this.OnMilestone("item"); }
protected virtual void OnInstantiateTotals(ITemplatingItem item) { if (this.IsRecovered || !this.Page.IsPostBack) { this._template.InstantiateTotalsIn(this._templateConfig, this.Binder, this._items.IndexOf(item), item, this.Templatable); } else { this._template.InstantiateTotalsIn(this._templateConfig, null, this._items.IndexOf(item), item, this.Templatable); } }
protected bool IsNewGroupItem(ITemplatingItem item) { bool isNew = this.CheckGroupingLevel(item); if (isNew) { if (this.previousGroupItem != null && !string.IsNullOrEmpty(this._totalsByMembers)) { this._items.Insert(this._items.IndexOf(item), this.runningTotalsItem); } this.previousGroupItem = item; if (!string.IsNullOrEmpty(this._totalsByMembers)) { this.InitiateRunningTotals(); } } this.ComputeRunningTotals(item); return(isNew); }
protected virtual void OnValidate(ITemplatingItem item) { IResult result = this.ValidationManager.Validate(item.Data); if (null != result) { item.IsValid = result.IsSuccessful(); } if (item.IsValid) { item.InvalidMember = null; this.OnValidationSucceed(result); } else { item.InvalidMember = this.ValidationManager.LastFail().Member; this.OnValidationFail(result); } }
protected virtual void OnRebuild() { char[] groupingMap = null; if (!string.IsNullOrEmpty(this.Page.Request[this.UniqueID + "-itemsCount"])) { int.TryParse(this.Page.Request[this.UniqueID + "-itemsCount"], out this._itemsCount); } if (!string.IsNullOrEmpty(this.Page.Request[this.UniqueID + "-groupingMap"])) { groupingMap = this.Page.Request[this.UniqueID + "-groupingMap"].ToCharArray(); } for (int i = 0; i < this._itemsCount; i++) { ITemplatingItem item = this._items.Add(false, false, false, true); if (groupingMap != null && i < groupingMap.Length && '1' == groupingMap[i]) { item.IsGrouping = true; } } this.OnBuild(); this.NeedsBuild = true; }
public override void Create(Control container, IConfigurationType config, ITemplatable templatable, IBinder binder, ITemplatingItem item, int itemIndex, WebPartManager manager) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } if ((config as IConfigurationSection).Elements.ContainsKey("totals")) { Table table; if (container is Table) { table = (container as Table); } else { table = new Table(); table.ApplyStyle(templatable.TotalsStyle); } IConfigurationElement element = (config as IConfigurationSection).GetElementReference("totals"); foreach (IConfigurationElement rowElement in element.Elements.Values) { this.DisplayItem(table, rowElement, "totals" + itemIndex.ToString(), binder, item, templatable.TotalsRowStyle, templatable.InvalidItemStyle, manager); } if (!(container is Table)) { container.Controls.Add(table); } } }
protected bool CheckGroupingLevel(ITemplatingItem item) { bool result = false; if (string.IsNullOrEmpty(this._groupByMember)) { result = false; } else { if (null == this.previousGroupItem) { result = true; } else { Dictionary <string, object> oldValues = new Dictionary <string, object>(); Dictionary <string, object> newValues = new Dictionary <string, object>(); foreach (string member in _groupByMember.Split(',')) { oldValues.Add(member, ReflectionServices.ExtractValue(this.previousGroupItem.Data, member)); newValues.Add(member, ReflectionServices.ExtractValue(item.Data, member)); } foreach (KeyValuePair <string, object> entry in oldValues) { string oldstr = entry.Value == null ? null : entry.Value.ToString(); string newstr = newValues[entry.Key] == null ? null : newValues[entry.Key].ToString(); if (oldstr != newstr) { result = true; break; } } } } return(result); }
protected virtual void OnDelete() { this.Operation = OperationType.Deleting; string deletedone = "delete done"; ITranslationResult trares = this.Translator.Translate(null, deletedone, null); if (trares.IsSuccessful()) { deletedone = trares.Translation; } List<ITemplatingItem> itemsToRemove = new List<ITemplatingItem>(); try { ITemplatingItem[] arr = new ITemplatingItem[this._items.Count]; this._items.CopyTo(arr, 0); ITemplatingItem[] array = arr; for (int i = 0; i < array.Length; i++) { ITemplatingItem item = array[i]; if (item.IsCurrent) { this.OnMilestone("save-delete"); bool deleted = false; if (!item.IsNew) { if (null != this.Delete) Delete(this, new DeleteEventArgs((IDictionary)item.Data)); deleted = true; } this.OnValidationSucceed(null); if (deleted && !this._monitor.HasErrors()) { itemsToRemove.Add(item); this._monitor.Register(this.Reporter, this._monitor.NewEventInstance(deletedone, EVENT_TYPE.Info)); } this.NeedsDelete = false; this.Operation = OperationType.Viewing; } } if (!this._monitor.HasErrors()) this.OnMilestone("deleted"); } catch (Exception ex) { this._monitor.Register(this.Reporter, this._monitor.NewEventInstance("delete error", null, ex, EVENT_TYPE.Error)); } foreach (ITemplatingItem item in itemsToRemove) { this._items.Remove(item); } _paginater.IsFrozen = false; _paginater.OnBackward(); _paginater.OnForward(); }
protected void InitiateRunningTotals() { if (!string.IsNullOrEmpty(this._totalsByMembers)) { this.runningTotalsItem = this._template.NewTemplatingItemInstance(); this.runningTotalsItem.Data = new Dictionary<string, decimal>(); this.runningTotalsItem.IsTotals = true; } }
protected bool IsNewGroupItem(ITemplatingItem item) { bool isNew = this.CheckGroupingLevel(item); if (isNew) { if (this.previousGroupItem != null && !string.IsNullOrEmpty(this._totalsByMembers)) { this._items.Insert(this._items.IndexOf(item), this.runningTotalsItem); } this.previousGroupItem = item; if (!string.IsNullOrEmpty(this._totalsByMembers)) { this.InitiateRunningTotals(); } } this.ComputeRunningTotals(item); return isNew; }
public virtual void DisplayItem(Table table, IConfigurationElement element, string index, IBinder binder, ITemplatingItem item, TableItemStyle style, TableItemStyle invalidStyle, WebPartManager manager) { this.DisplayItem(table, element, index, binder, item, style, invalidStyle, null, manager); }
public void PopulateItem(IConfigurationType config, ITemplatingItem item, string prefix) { ItemTemplate.Instance.PopulateItem(_container, config, item, prefix); }
public virtual void Create(Control container, IConfigurationType config, ITemplatable templatable, IBinder binder, ITemplatingItem item, int itemIndex, WebPartManager manager, bool keepTable) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } Table containerTable; if (container is Table) { containerTable = (container as Table); } else { containerTable = new Table(); containerTable.ID = container.ID + "grouping"; } IConfigurationElement element = (config as IConfigurationSection).GetElementReference("grouping"); Table table; if (keepTable) { table = containerTable; } else { TableRow tr = new TableRow(); TableCell tc = new TableCell(); table = new Table(); tr.ID = "groupingTable" + itemIndex.ToString() + "row"; tc.ID = "groupingTable" + itemIndex.ToString() + "cell"; table.ID = "groupingTable" + itemIndex.ToString(); tc.Controls.Add(table); tr.Cells.Add(tc); containerTable.Rows.Add(tr); if (element.Attributes.ContainsKey("span")) { int columnSpan = 1; int.TryParse(element.GetAttributeReference("span").Value.ToString(), out columnSpan); tc.ColumnSpan = columnSpan; } if (element.Attributes.ContainsKey("rowspan")) { int rowSpan = 1; int.TryParse(element.GetAttributeReference("rowspan").Value.ToString(), out rowSpan); tc.RowSpan = rowSpan; } } table.ApplyStyle(templatable.GroupingStyle); foreach (IConfigurationElement rowElement in element.Elements.Values) { this.DisplayItem(table, rowElement, "grouping" + itemIndex.ToString(), binder, item, templatable.GroupRowStyle, templatable.InvalidItemStyle, manager); } if (!(container is Table)) { container.Controls.Add(containerTable); } }
public Control CreateControl(IConfigurationElement controlElement, string index, IBinder binder, ITemplatingItem item, WebControl container, TableItemStyle invalidStyle, Dictionary <string, Control> registry, WebPartManager manager) { if (null == this._monitor) { throw new ApplicationException("Monitor not set"); } Control result; if (!controlElement.Attributes.ContainsKey("proxy") && !controlElement.Attributes.ContainsKey("type")) { result = null; } else { Control cellControl = null; string cellControlName = null; if (controlElement.Attributes.ContainsKey("proxy")) { object proxyIDValue = controlElement.GetAttributeReference("proxy").Value; string proxyID = null; if (null != proxyIDValue) { proxyID = proxyIDValue.ToString(); } if (string.IsNullOrEmpty(proxyID)) { result = null; return(result); } Control proxy = ReflectionServices.FindControlEx(proxyID, manager); if (null == proxy) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, new ApplicationException("can't find proxy " + proxyID), EVENT_TYPE.Error)); } string proxyMember = null; if (!controlElement.Attributes.ContainsKey("proxyMember")) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, new ApplicationException("proxyMember not found for proxy " + proxyID), EVENT_TYPE.Error)); } else { proxyMember = controlElement.GetAttributeReference("proxyMember").Value.ToString(); } try { cellControl = (ReflectionServices.ExtractValue(proxy, proxyMember) as Control); cellControlName = proxy + "." + proxyMember; } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, ex, EVENT_TYPE.Error)); } if (cellControl == null && null != proxy) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, new ApplicationException(string.Format("member {0} of proxy type {1} is not a Control", proxyMember, proxy.GetType().FullName)), EVENT_TYPE.Error)); } } else { Control scope = container; if (container is TableCell) { scope = container.Parent.Parent; } try { cellControl = this.CreateControl(controlElement.GetAttributeReference("type").Value.ToString(), new bool?(item == null || item.IsReadOnly), scope); cellControlName = controlElement.GetAttributeReference("type").Value.ToString(); } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance("create control error", null, ex, EVENT_TYPE.Error)); } } if (null == cellControl) { result = null; } else { string type = null; if (controlElement.Attributes.ContainsKey("type")) { type = controlElement.GetAttributeReference("type").Value.ToString(); if (cellControl is IButtonControl) { IButtonControl btn = cellControl as IButtonControl; if (("Commander" == type || "LinkCommander" == type) && !controlElement.Attributes.ContainsKey("command")) { this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("create {0} error", type), null, new ApplicationException("command not found"), EVENT_TYPE.Error)); } else { if (controlElement.Attributes.ContainsKey("command")) { btn.CommandName = controlElement.GetAttributeReference("command").Value.ToString(); } } btn.CommandArgument = index; } if (cellControl is StatelessDropDownList) { ((StatelessDropDownList)cellControl).CommandArgument = index; } } if (null != registry) { registry.Add(controlElement.ConfigKey, cellControl); } var properties = controlElement.Elements.Values; foreach (IConfigurationElement controlPropertyElement in properties) { if (!controlPropertyElement.Attributes.ContainsKey("for") || !("cell" == controlPropertyElement.GetAttributeReference("for").Value.ToString())) { string propertyName = null; if (!controlPropertyElement.Attributes.ContainsKey("member")) { this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("'{0}' property set error", cellControlName), null, new ApplicationException(string.Format("member not found for '{0}'", controlPropertyElement.ConfigKey)), EVENT_TYPE.Error)); } else { propertyName = controlPropertyElement.GetAttributeReference("member").Value.ToString(); } IExpression expression = null; LWAS.Extensible.Interfaces.IResult expressionResult = null; if (controlPropertyElement.Elements.ContainsKey("expression")) { IConfigurationElement expressionElement = controlPropertyElement.GetElementReference("expression"); Manager sysmanager = manager as Manager; if (null != sysmanager && null != sysmanager.ExpressionsManager && expressionElement.Attributes.ContainsKey("type")) { expression = sysmanager.ExpressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression; if (null != expression) { try { expression.Make(expressionElement, sysmanager.ExpressionsManager); expressionResult = expression.Evaluate(); } catch (ArgumentException ax) { } } } } object defaultValue = null; if (!string.IsNullOrEmpty(propertyName) && controlPropertyElement.Attributes.ContainsKey("value")) { defaultValue = controlPropertyElement.GetAttributeReference("value").Value; if (null == expression || null == binder) { try { if (string.IsNullOrEmpty(cellControlName) || propertyName != this.KnownTypes[cellControlName].ReadOnlyProperty || (propertyName == this.KnownTypes[cellControlName].ReadOnlyProperty && defaultValue != null && !string.IsNullOrEmpty(defaultValue.ToString()))) { if (propertyName == "Watermark") { if (null != defaultValue && !String.IsNullOrEmpty(defaultValue.ToString())) { ReflectionServices.SetValue(cellControl, propertyName, defaultValue); } } else { ReflectionServices.SetValue(cellControl, propertyName, defaultValue); } } } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("'{0}'.'{1}'='{2}' error", cellControlName, propertyName, controlPropertyElement.GetAttributeReference("value").Value), null, ex, EVENT_TYPE.Error)); } } else { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = new Dictionary <string, object>() { { "0", defaultValue } }; bindingItem.SourceProperty = "0"; bindingItem.Target = cellControl; bindingItem.TargetProperty = propertyName; bindingItem.Expression = expression; bindingItem.ExpressionEvaluationResult = expressionResult; binder.BindingItems.Add(bindingItem); } } if (controlPropertyElement.Attributes.ContainsKey("isList") && (bool)controlPropertyElement.GetAttributeReference("isList").Value) { object list = null; try { list = ReflectionServices.ExtractValue(cellControl, propertyName); if (null == list) { throw new InvalidOperationException(string.Format("Member '{0}' is empty", propertyName)); } if (!(list is ListItemCollection) && !(list is IDictionary <string, object>)) { throw new InvalidOperationException(String.Format("Unsupported list type '{0}'", list.GetType().Name)); } } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance("failed to retrive the list", null, ex, EVENT_TYPE.Error)); } if (null != list) { if (controlPropertyElement.Attributes.ContainsKey("hasEmpty") && (bool)controlPropertyElement.GetAttributeReference("hasEmpty").Value) { if (list is ListItemCollection) { ((ListItemCollection)list).Add(""); } else if (list is Dictionary <string, object> ) { ((Dictionary <string, object>)list).Add("", ""); } } foreach (IConfigurationElement listItemElement in controlPropertyElement.Elements.Values) { string value = null; string text = null; string pull = null; if (listItemElement.Attributes.ContainsKey("value") && null != listItemElement.GetAttributeReference("value").Value) { value = listItemElement.GetAttributeReference("value").Value.ToString(); } if (listItemElement.Attributes.ContainsKey("text") && null != listItemElement.GetAttributeReference("text").Value) { text = listItemElement.GetAttributeReference("text").Value.ToString(); } if (listItemElement.Attributes.ContainsKey("pull") && null != listItemElement.GetAttributeReference("pull").Value) { pull = listItemElement.GetAttributeReference("pull").Value.ToString(); } if (list is ListItemCollection) { ListItem li = new ListItem(text, value); ((ListItemCollection)list).Add(li); if (null != binder && !String.IsNullOrEmpty(pull)) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = item.Data; bindingItem.SourceProperty = pull; bindingItem.Target = li; bindingItem.TargetProperty = "Text"; bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); } } else if (list is Dictionary <string, object> ) { ((Dictionary <string, object>)list).Add(value, text); if (null != binder && !String.IsNullOrEmpty(pull)) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = item.Data; bindingItem.SourceProperty = pull; bindingItem.Target = list; bindingItem.TargetProperty = value; bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); } } } } } if (controlPropertyElement.Attributes.ContainsKey("property")) { if (container.Page != null && null != binder) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = WebPartManager.GetCurrentWebPartManager(container.Page); bindingItem.SourceProperty = "WebParts." + controlPropertyElement.GetAttributeReference("property").Value.ToString(); bindingItem.Target = cellControl; bindingItem.TargetProperty = propertyName; if (string.IsNullOrEmpty(cellControlName) || propertyName != this.KnownTypes[cellControlName].ReadOnlyProperty) { bindingItem.DefaultValue = defaultValue; } bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); } } if (controlPropertyElement.Attributes.ContainsKey("pull")) { string pull = controlPropertyElement.GetAttributeReference("pull").Value.ToString(); if (binder != null && null != item) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = item.Data; bindingItem.SourceProperty = pull; bindingItem.Target = cellControl; bindingItem.TargetProperty = propertyName; if (string.IsNullOrEmpty(cellControlName) || propertyName != this.KnownTypes[cellControlName].ReadOnlyProperty) { bindingItem.DefaultValue = defaultValue; } bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); if (item.InvalidMember == bindingItem.SourceProperty) { container.ApplyStyle(invalidStyle); } } if (this.IsDesignEnabled && propertyName == this.KnownTypes[cellControlName].WatermarkProperty) { // StyleTextBox has its own Watermark feature if (typeof(StyledTextBox).IsInstanceOfType(cellControl)) { ReflectionServices.SetValue(cellControl, "Watermark", pull); } else { container.Attributes.Add("watermark", pull); } } } } } result = cellControl; } } return(result); }
public override void Create(Control container, IConfigurationType config, ITemplatable templatable, IBinder binder, ITemplatingItem item, int itemIndex, WebPartManager manager) { this.Create(container, config, templatable, binder, item, itemIndex, manager, false); }
public override void Extract(Control container, IConfigurationType config, ITemplatable templatable, IBinder binder, IEnumerable registry, ITemplatingItem item, int itemIndex, int itemsCount, WebPartManager manager) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } if (!(registry is ITemplatingItemsCollection)) { throw new ArgumentException("registry must be ITemplatingItemsCollection"); } ITemplatingItemsCollection items = registry as ITemplatingItemsCollection; items.Clear(); IDictionary<string, IConfigurationElement> itemElements = (config as IConfigurationSection).Elements; for (int i = 0; i < itemsCount; i++) { item = new TemplatingItem(); Control hiddenReadOnly = ReflectionServices.FindControlEx(i.ToString() + "-readOnly", container); if (null != hiddenReadOnly) { bool isReadOnly = false; bool.TryParse(((HiddenField)hiddenReadOnly).Value, out isReadOnly); item.IsReadOnly = isReadOnly; } Control hiddenNew = ReflectionServices.FindControlEx(i.ToString() + "-new", container); if (null != hiddenNew) { bool isNew = false; bool.TryParse(((HiddenField)hiddenNew).Value, out isNew); item.IsNew = isNew; } Control hiddenCurrent = ReflectionServices.FindControlEx(i.ToString() + "-current", container); if (null != hiddenCurrent) { bool isCurrent = false; bool.TryParse(((HiddenField)hiddenCurrent).Value, out isCurrent); item.IsCurrent = isCurrent; } Control hiddenHasChanges = ReflectionServices.FindControlEx(i.ToString() + "-hasChanges", container); if (null != hiddenHasChanges) { bool hasChanges = false; bool.TryParse(((HiddenField)hiddenHasChanges).Value, out hasChanges); item.HasChanges = hasChanges; } Control hiddenIsValid = ReflectionServices.FindControlEx(i.ToString() + "-isValid", container); if (null != hiddenIsValid) { bool isValid = false; bool.TryParse(((HiddenField)hiddenIsValid).Value, out isValid); item.IsValid = isValid; } Control hiddenInvalidMember = ReflectionServices.FindControlEx(i.ToString() + "-invalidMember", container); if (null != hiddenInvalidMember) { item.InvalidMember = ((HiddenField)hiddenInvalidMember).Value; } this.PopulateItem(container, config, item, i.ToString()); items.Add(item); } }
public virtual void PopulateItem(Control container, IConfigurationType config, ITemplatingItem item, string index) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } item.Data = new Dictionary<string, object>(); Dictionary<string, object> data = item.Data as Dictionary<string, object>; IDictionary<string, IConfigurationElement> itemElements = (config as IConfigurationSection).Elements; foreach (IConfigurationElement element in itemElements.Values) { if (!("selectors" == element.ConfigKey) && !("commanders" == element.ConfigKey) && !("filter" == element.ConfigKey) && !("header" == element.ConfigKey) && !("footer" == element.ConfigKey)) { foreach (IConfigurationElement fieldElement in element.Elements.Values) { foreach (IConfigurationElement propertyElement in fieldElement.Elements.Values) { if (propertyElement.Attributes.ContainsKey("push")) { string propertyName = propertyElement.GetAttributeReference("member").Value.ToString(); string sourcePropertyName = propertyElement.GetAttributeReference("push").Value.ToString(); if (!data.ContainsKey(sourcePropertyName)) { data.Add(sourcePropertyName, null); } if (!string.IsNullOrEmpty(index)) { string id = string.Concat(new string[] { container.ID, "-", element.ConfigKey, "-", index, "-", fieldElement.ConfigKey, "-ctrl" }); Control fieldControl = ReflectionServices.FindControlEx(id, container); if (null != fieldControl) { object val = ReflectionServices.ExtractValue(fieldControl, propertyName); if (fieldControl is DateTextBox && val == null && propertyName == "Date") { val = ((DateTextBox)fieldControl).Text; } data[sourcePropertyName] = val; } } } } } } } }
public override void Create(Control container, IConfigurationType config, ITemplatable templatable, IBinder binder, ITemplatingItem item, int itemIndex, WebPartManager manager) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } IDictionary <string, IConfigurationElement> itemElements = (config as IConfigurationSection).Elements; Table table; if (container is Table) { table = (container as Table); } else { table = new Table(); } table.ApplyStyle(templatable.DetailsStyle); Panel statusPanel = new Panel(); HiddenField hiddenReadOnly = new HiddenField(); hiddenReadOnly.ID = itemIndex.ToString() + "-readOnly"; hiddenReadOnly.Value = item.IsReadOnly.ToString(); statusPanel.Controls.Add(hiddenReadOnly); HiddenField hiddenNew = new HiddenField(); hiddenNew.ID = itemIndex.ToString() + "-new"; hiddenNew.Value = item.IsNew.ToString(); statusPanel.Controls.Add(hiddenNew); HiddenField hiddenCurrent = new HiddenField(); hiddenCurrent.ID = itemIndex.ToString() + "-current"; hiddenCurrent.Value = item.IsCurrent.ToString(); statusPanel.Controls.Add(hiddenCurrent); HiddenField hiddenHasChanges = new HiddenField(); hiddenHasChanges.ID = itemIndex.ToString() + "-hasChanges"; hiddenHasChanges.Value = item.HasChanges.ToString(); statusPanel.Controls.Add(hiddenHasChanges); HiddenField hiddenIsValid = new HiddenField(); hiddenIsValid.ID = itemIndex.ToString() + "-isValid"; hiddenIsValid.Value = item.IsValid.ToString(); statusPanel.Controls.Add(hiddenIsValid); HiddenField hiddenInvalidMember = new HiddenField(); hiddenInvalidMember.ID = itemIndex.ToString() + "-invalidMember"; hiddenInvalidMember.Value = item.InvalidMember; statusPanel.Controls.Add(hiddenInvalidMember); if (null != item) { item.BoundControls.Clear(); } foreach (IConfigurationElement element in itemElements.Values) { if (!("selectors" == element.ConfigKey) && !("commanders" == element.ConfigKey) && !("filter" == element.ConfigKey) && !("header" == element.ConfigKey) && !("footer" == element.ConfigKey) && !("grouping" == element.ConfigKey) && !("totals" == element.ConfigKey)) { if (item.IsCurrent && !item.IsReadOnly) { this.DisplayItem(table, element, itemIndex.ToString(), binder, item, templatable.EditRowStyle, templatable.InvalidItemStyle, manager); } else { if (item.IsCurrent) { this.DisplayItem(table, element, itemIndex.ToString(), binder, item, templatable.SelectedRowStyle, templatable.InvalidItemStyle, manager); } else { if (itemIndex % 2 == 0) { this.DisplayItem(table, element, itemIndex.ToString(), binder, item, templatable.RowStyle, templatable.InvalidItemStyle, manager); } else { this.DisplayItem(table, element, itemIndex.ToString(), binder, item, templatable.AlternatingRowStyle, templatable.InvalidItemStyle, manager); } } } } } if (table.Rows.Count > 0) { if (!(table.Rows[0].Cells.Count > 0)) { TableCell firstcell = new TableCell(); firstcell.ID = table.Rows[0].ID + "firstcell"; table.Rows[0].Cells.Add(firstcell); } table.Rows[0].Cells[0].Controls.Add(statusPanel); } }
public virtual void PopulateItem(Control container, IConfigurationType config, ITemplatingItem item, string index) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } item.Data = new Dictionary <string, object>(); Dictionary <string, object> data = item.Data as Dictionary <string, object>; IDictionary <string, IConfigurationElement> itemElements = (config as IConfigurationSection).Elements; foreach (IConfigurationElement element in itemElements.Values) { if (!("selectors" == element.ConfigKey) && !("commanders" == element.ConfigKey) && !("filter" == element.ConfigKey) && !("header" == element.ConfigKey) && !("footer" == element.ConfigKey)) { foreach (IConfigurationElement fieldElement in element.Elements.Values) { foreach (IConfigurationElement propertyElement in fieldElement.Elements.Values) { if (propertyElement.Attributes.ContainsKey("push")) { string propertyName = propertyElement.GetAttributeReference("member").Value.ToString(); string sourcePropertyName = propertyElement.GetAttributeReference("push").Value.ToString(); if (!data.ContainsKey(sourcePropertyName)) { data.Add(sourcePropertyName, null); } if (!string.IsNullOrEmpty(index)) { string id = string.Concat(new string[] { container.ID, "-", element.ConfigKey, "-", index, "-", fieldElement.ConfigKey, "-ctrl" }); Control fieldControl = ReflectionServices.FindControlEx(id, container); if (null != fieldControl) { object val = ReflectionServices.ExtractValue(fieldControl, propertyName); if (fieldControl is DateTextBox && val == null && propertyName == "Date") { val = ((DateTextBox)fieldControl).Text; } data[sourcePropertyName] = val; } } } } } } } }
public override void Extract(Control container, IConfigurationType config, ITemplatable templatable, IBinder binder, IEnumerable registry, ITemplatingItem item, int itemIndex, int itemsCount, WebPartManager manager) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } if (!(registry is ITemplatingItemsCollection)) { throw new ArgumentException("registry must be ITemplatingItemsCollection"); } ITemplatingItemsCollection items = registry as ITemplatingItemsCollection; items.Clear(); IDictionary <string, IConfigurationElement> itemElements = (config as IConfigurationSection).Elements; for (int i = 0; i < itemsCount; i++) { item = new TemplatingItem(); Control hiddenReadOnly = ReflectionServices.FindControlEx(i.ToString() + "-readOnly", container); if (null != hiddenReadOnly) { bool isReadOnly = false; bool.TryParse(((HiddenField)hiddenReadOnly).Value, out isReadOnly); item.IsReadOnly = isReadOnly; } Control hiddenNew = ReflectionServices.FindControlEx(i.ToString() + "-new", container); if (null != hiddenNew) { bool isNew = false; bool.TryParse(((HiddenField)hiddenNew).Value, out isNew); item.IsNew = isNew; } Control hiddenCurrent = ReflectionServices.FindControlEx(i.ToString() + "-current", container); if (null != hiddenCurrent) { bool isCurrent = false; bool.TryParse(((HiddenField)hiddenCurrent).Value, out isCurrent); item.IsCurrent = isCurrent; } Control hiddenHasChanges = ReflectionServices.FindControlEx(i.ToString() + "-hasChanges", container); if (null != hiddenHasChanges) { bool hasChanges = false; bool.TryParse(((HiddenField)hiddenHasChanges).Value, out hasChanges); item.HasChanges = hasChanges; } Control hiddenIsValid = ReflectionServices.FindControlEx(i.ToString() + "-isValid", container); if (null != hiddenIsValid) { bool isValid = false; bool.TryParse(((HiddenField)hiddenIsValid).Value, out isValid); item.IsValid = isValid; } Control hiddenInvalidMember = ReflectionServices.FindControlEx(i.ToString() + "-invalidMember", container); if (null != hiddenInvalidMember) { item.InvalidMember = ((HiddenField)hiddenInvalidMember).Value; } this.PopulateItem(container, config, item, i.ToString()); items.Add(item); } }
protected virtual void OnSave() { string savedone = "save done"; ITranslationResult trares = this.Translator.Translate(null, savedone, null); if (trares.IsSuccessful()) { savedone = trares.Translation; } try { ITemplatingItem[] arr = new ITemplatingItem[this._items.Count]; this._items.CopyTo(arr, 0); ITemplatingItem[] array = arr; for (int i = 0; i < array.Length; i++) { ITemplatingItem item = array[i]; if (item.HasChanges) { this.OnValidate(item); if (!item.IsValid) { break; } if (item.IsNew) { if (null != this.CurrentItem) { this.CurrentItem.IsCurrent = false; } item.IsCurrent = true; this.OnMilestone("save-insert"); } else { if (null != this.CurrentItem) { this.CurrentItem.IsCurrent = false; } item.IsCurrent = true; this.OnMilestone("save-update"); } if (item.IsNew) { if (null != this.Insert) { Insert(this, new InsertEventArgs((IDictionary)item.Data)); } } else { if (null != this.Update) { Update(this, new UpdateEventArgs((IDictionary)item.Data)); } } if (!this._monitor.HasErrors()) { item.IsReadOnly = true; item.IsNew = false; item.HasChanges = false; this._monitor.Register(this.Reporter, this._monitor.NewEventInstance(savedone, EVENT_TYPE.Info)); } this.NeedsSave = false; this.Operation = OperationType.Viewing; } } if (!this._monitor.HasErrors()) { this.OnMilestone("saved"); } } catch (Exception ex) { this._monitor.Register(this.Reporter, this._monitor.NewEventInstance("save error", null, ex, EVENT_TYPE.Error)); } }
public virtual void DisplayItem(Table table, IConfigurationElement element, string index, IBinder binder, ITemplatingItem item, TableItemStyle style, TableItemStyle invalidStyle, Dictionary<string, Control> registry, WebPartManager manager) { string[] span = null; if (element.Attributes.ContainsKey("span") && null != element.GetAttributeReference("span").Value) span = element.GetAttributeReference("span").Value.ToString().Split(new char[] { ',' }); string[] rowspan = null; if (element.Attributes.ContainsKey("rowspan") && null != element.GetAttributeReference("rowspan").Value) rowspan = element.GetAttributeReference("rowspan").Value.ToString().Split(new char[] { ',' }); TableRow tr = new TableRow(); tr.ID = string.Concat(new string[] { table.ID, "-", element.ConfigKey, "-", index }); tr.Attributes["key"] = element.ConfigKey; tr.ApplyStyle(style); foreach (IConfigurationElementAttribute attribute in element.Attributes.Values) { if ("span" != attribute.ConfigKey && "rowspan" != attribute.ConfigKey) { tr.Style.Add(attribute.ConfigKey, attribute.Value.ToString()); } } table.Rows.Add(tr); int count = 0; foreach (IConfigurationElement controlElement in element.Elements.Values) { TableCell tc = new TableCell(); tc.ID = tr.ID + "-" + controlElement.ConfigKey; tc.Attributes["key"] = controlElement.ConfigKey; if (span != null && span.Length > count) { int columnSpan = 1; int.TryParse(span[count], out columnSpan); tc.ColumnSpan = columnSpan; if (rowspan != null && rowspan.Length > count) { int rowSpan = 1; int.TryParse(rowspan[count], out rowSpan); tc.RowSpan = rowSpan; } count++; } tr.Cells.Add(tc); string pullpush = null; foreach (IConfigurationElement propertyElement in controlElement.Elements.Values) { if (propertyElement.Attributes.ContainsKey("for") && "cell" == propertyElement.GetAttributeReference("for").Value.ToString() && propertyElement.Attributes.ContainsKey("member") && propertyElement.Attributes.ContainsKey("value")) { try { ReflectionServices.SetValue(tc, propertyElement.GetAttributeReference("member").Value.ToString(), propertyElement.GetAttributeReference("value").Value); } catch (Exception ex) { ControlFactory.Instance.Monitor.Register(ControlFactory.Instance, ControlFactory.Instance.Monitor.NewEventInstance("set cell attributes error", null, ex, EVENT_TYPE.Error)); } } if (propertyElement.Attributes.ContainsKey("pull")) { pullpush = propertyElement.GetAttributeReference("pull").Value.ToString(); } else { if (propertyElement.Attributes.ContainsKey("push")) { pullpush = propertyElement.GetAttributeReference("push").Value.ToString(); } } } Control cellControl = ControlFactory.Instance.CreateControl(controlElement, index, binder, item, tc, invalidStyle, registry, manager); if (null != cellControl) { cellControl.ID = string.Concat(new string[] { table.ID, "-", element.ConfigKey, "-", index, "-", controlElement.ConfigKey, "-ctrl" }); tc.Controls.Add(cellControl); if (cellControl is BaseDataBoundControl && !string.IsNullOrEmpty(pullpush)) { if (!item.BoundControls.ContainsKey(pullpush)) { item.BoundControls.Add(pullpush, new List<BaseDataBoundControl>()); } item.BoundControls[pullpush].Add((BaseDataBoundControl)cellControl); } } } }
public virtual void Create(Control container, IConfigurationType config, ITemplatable templatable, IBinder binder, ITemplatingItem item, int itemIndex, WebPartManager manager) { throw new NotImplementedException(); }
protected virtual void OnReceiveData(IEnumerable data) { this._items.Clear(); if (null == data) { _paginater.Reset(); } else if (null != data) { this.InitiateRunningTotals(); if (this._disablePaginater) { IEnumerator enumerator = data.GetEnumerator(); while (enumerator.MoveNext()) { if (this.IsFilterMatch(enumerator.Current)) { ITemplatingItem item = this._items.Add(true, false, false, true, enumerator.Current); item.IsGrouping = this.IsNewGroupItem(item); } } } else { int index = 0; IEnumerator enumerator = data.GetEnumerator(); bool hasMoreData = enumerator.MoveNext(); bool isEmpty = !hasMoreData; if (hasMoreData && this.IsReset) { this.Paginater.CurrentPage = 1; } while (index < this._paginater.StartIndex && hasMoreData) { hasMoreData = enumerator.MoveNext(); if (this.IsFilterMatch(enumerator.Current)) { index++; } } while (index < this._paginater.StartIndex + this._paginater.PageSize && hasMoreData) { if (this.IsFilterMatch(enumerator.Current)) { ITemplatingItem item = this._items.Add(true, false, false, true, enumerator.Current); item.IsGrouping = this.IsNewGroupItem(item); index++; } hasMoreData = enumerator.MoveNext(); } if (hasMoreData) { do { if (this.IsFilterMatch(enumerator.Current)) { index++; } }while (enumerator.MoveNext()); } this._paginater.ResultsCount = (isEmpty ? 0 : index); } this.FinishRunningTotals(); } }
public virtual void InstantiateTotalsIn(IConfigurationType config, IBinder binder, int itemIndex, ITemplatingItem item, ITemplatable templatable) { TotalsTemplate.Instance.Create(_container, config, templatable, binder, item, itemIndex, this.manager); }
public override void Create(Control container, IConfigurationType config, ITemplatable templatable, IBinder binder, ITemplatingItem item, int itemIndex, WebPartManager manager) { if (null == container) { throw new ArgumentNullException("container"); } if (null == config) { throw new ArgumentNullException("config"); } if (!(config is IConfigurationSection)) { throw new ArgumentException("config must be an IConfigurationSection"); } IDictionary<string, IConfigurationElement> itemElements = (config as IConfigurationSection).Elements; Table table; if (container is Table) { table = (container as Table); } else { table = new Table(); } table.ApplyStyle(templatable.DetailsStyle); Panel statusPanel = new Panel(); HiddenField hiddenReadOnly = new HiddenField(); hiddenReadOnly.ID = itemIndex.ToString() + "-readOnly"; hiddenReadOnly.Value = item.IsReadOnly.ToString(); statusPanel.Controls.Add(hiddenReadOnly); HiddenField hiddenNew = new HiddenField(); hiddenNew.ID = itemIndex.ToString() + "-new"; hiddenNew.Value = item.IsNew.ToString(); statusPanel.Controls.Add(hiddenNew); HiddenField hiddenCurrent = new HiddenField(); hiddenCurrent.ID = itemIndex.ToString() + "-current"; hiddenCurrent.Value = item.IsCurrent.ToString(); statusPanel.Controls.Add(hiddenCurrent); HiddenField hiddenHasChanges = new HiddenField(); hiddenHasChanges.ID = itemIndex.ToString() + "-hasChanges"; hiddenHasChanges.Value = item.HasChanges.ToString(); statusPanel.Controls.Add(hiddenHasChanges); HiddenField hiddenIsValid = new HiddenField(); hiddenIsValid.ID = itemIndex.ToString() + "-isValid"; hiddenIsValid.Value = item.IsValid.ToString(); statusPanel.Controls.Add(hiddenIsValid); HiddenField hiddenInvalidMember = new HiddenField(); hiddenInvalidMember.ID = itemIndex.ToString() + "-invalidMember"; hiddenInvalidMember.Value = item.InvalidMember; statusPanel.Controls.Add(hiddenInvalidMember); if (null != item) { item.BoundControls.Clear(); } foreach (IConfigurationElement element in itemElements.Values) { if (!("selectors" == element.ConfigKey) && !("commanders" == element.ConfigKey) && !("filter" == element.ConfigKey) && !("header" == element.ConfigKey) && !("footer" == element.ConfigKey) && !("grouping" == element.ConfigKey) && !("totals" == element.ConfigKey)) { if (item.IsCurrent && !item.IsReadOnly) { this.DisplayItem(table, element, itemIndex.ToString(), binder, item, templatable.EditRowStyle, templatable.InvalidItemStyle, manager); } else { if (item.IsCurrent) { this.DisplayItem(table, element, itemIndex.ToString(), binder, item, templatable.SelectedRowStyle, templatable.InvalidItemStyle, manager); } else { if (itemIndex % 2 == 0) { this.DisplayItem(table, element, itemIndex.ToString(), binder, item, templatable.RowStyle, templatable.InvalidItemStyle, manager); } else { this.DisplayItem(table, element, itemIndex.ToString(), binder, item, templatable.AlternatingRowStyle, templatable.InvalidItemStyle, manager); } } } } } if (table.Rows.Count > 0) { if (!(table.Rows[0].Cells.Count > 0)) { TableCell firstcell = new TableCell(); firstcell.ID = table.Rows[0].ID + "firstcell"; table.Rows[0].Cells.Add(firstcell); } table.Rows[0].Cells[0].Controls.Add(statusPanel); } }
public virtual void Create(Control container, IConfigurationType config, ITemplatable templatable, IEnumerable registry, IBinder binder, ITemplatingItem item, int itemIndex, WebPartManager manager) { throw new NotImplementedException(); }
protected virtual void OnSave() { string savedone = "save done"; ITranslationResult trares = this.Translator.Translate(null, savedone, null); if (trares.IsSuccessful()) { savedone = trares.Translation; } try { ITemplatingItem[] arr = new ITemplatingItem[this._items.Count]; this._items.CopyTo(arr, 0); ITemplatingItem[] array = arr; for (int i = 0; i < array.Length; i++) { ITemplatingItem item = array[i]; if (item.HasChanges) { this.OnValidate(item); if (!item.IsValid) { break; } if (item.IsNew) { if (null != this.CurrentItem) this.CurrentItem.IsCurrent = false; item.IsCurrent = true; this.OnMilestone("save-insert"); } else { if (null != this.CurrentItem) this.CurrentItem.IsCurrent = false; item.IsCurrent = true; this.OnMilestone("save-update"); } if (item.IsNew) { if (null != this.Insert) Insert(this, new InsertEventArgs((IDictionary)item.Data)); } else { if (null != this.Update) Update(this, new UpdateEventArgs((IDictionary)item.Data)); } if (!this._monitor.HasErrors()) { item.IsReadOnly = true; item.IsNew = false; item.HasChanges = false; this._monitor.Register(this.Reporter, this._monitor.NewEventInstance(savedone, EVENT_TYPE.Info)); } this.NeedsSave = false; this.Operation = OperationType.Viewing; } } if (!this._monitor.HasErrors()) this.OnMilestone("saved"); } catch (Exception ex) { this._monitor.Register(this.Reporter, this._monitor.NewEventInstance("save error", null, ex, EVENT_TYPE.Error)); } }
public Control CreateControl(IConfigurationElement controlElement, string index, IBinder binder, ITemplatingItem item, WebControl container, TableItemStyle invalidStyle, Dictionary<string, Control> registry, WebPartManager manager) { if (null == this._monitor) { throw new ApplicationException("Monitor not set"); } Control result; if (!controlElement.Attributes.ContainsKey("proxy") && !controlElement.Attributes.ContainsKey("type")) { result = null; } else { Control cellControl = null; string cellControlName = null; if (controlElement.Attributes.ContainsKey("proxy")) { object proxyIDValue = controlElement.GetAttributeReference("proxy").Value; string proxyID = null; if (null != proxyIDValue) { proxyID = proxyIDValue.ToString(); } if (string.IsNullOrEmpty(proxyID)) { result = null; return result; } Control proxy = ReflectionServices.FindControlEx(proxyID, manager); if (null == proxy) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, new ApplicationException("can't find proxy " + proxyID), EVENT_TYPE.Error)); } string proxyMember = null; if (!controlElement.Attributes.ContainsKey("proxyMember")) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, new ApplicationException("proxyMember not found for proxy " + proxyID), EVENT_TYPE.Error)); } else { proxyMember = controlElement.GetAttributeReference("proxyMember").Value.ToString(); } try { cellControl = (ReflectionServices.ExtractValue(proxy, proxyMember) as Control); cellControlName = proxy + "." + proxyMember; } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, ex, EVENT_TYPE.Error)); } if (cellControl == null && null != proxy) { this._monitor.Register(this, this._monitor.NewEventInstance("create proxy error", null, new ApplicationException(string.Format("member {0} of proxy type {1} is not a Control", proxyMember, proxy.GetType().FullName)), EVENT_TYPE.Error)); } } else { Control scope = container; if (container is TableCell) { scope = container.Parent.Parent; } try { cellControl = this.CreateControl(controlElement.GetAttributeReference("type").Value.ToString(), new bool?(item == null || item.IsReadOnly), scope); cellControlName = controlElement.GetAttributeReference("type").Value.ToString(); } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance("create control error", null, ex, EVENT_TYPE.Error)); } } if (null == cellControl) { result = null; } else { string type = null; if (controlElement.Attributes.ContainsKey("type")) { type = controlElement.GetAttributeReference("type").Value.ToString(); if (cellControl is IButtonControl) { IButtonControl btn = cellControl as IButtonControl; if (("Commander" == type || "LinkCommander" == type) && !controlElement.Attributes.ContainsKey("command")) { this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("create {0} error", type), null, new ApplicationException("command not found"), EVENT_TYPE.Error)); } else { if (controlElement.Attributes.ContainsKey("command")) { btn.CommandName = controlElement.GetAttributeReference("command").Value.ToString(); } } btn.CommandArgument = index; } if (cellControl is StatelessDropDownList) ((StatelessDropDownList)cellControl).CommandArgument = index; } if (null != registry) { registry.Add(controlElement.ConfigKey, cellControl); } var properties = controlElement.Elements.Values; foreach (IConfigurationElement controlPropertyElement in properties) { if (!controlPropertyElement.Attributes.ContainsKey("for") || !("cell" == controlPropertyElement.GetAttributeReference("for").Value.ToString())) { string propertyName = null; if (!controlPropertyElement.Attributes.ContainsKey("member")) { this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("'{0}' property set error", cellControlName), null, new ApplicationException(string.Format("member not found for '{0}'", controlPropertyElement.ConfigKey)), EVENT_TYPE.Error)); } else { propertyName = controlPropertyElement.GetAttributeReference("member").Value.ToString(); } IExpression expression = null; LWAS.Extensible.Interfaces.IResult expressionResult = null; if (controlPropertyElement.Elements.ContainsKey("expression")) { IConfigurationElement expressionElement = controlPropertyElement.GetElementReference("expression"); Manager sysmanager = manager as Manager; if (null != sysmanager && null != sysmanager.ExpressionsManager && expressionElement.Attributes.ContainsKey("type")) { expression = sysmanager.ExpressionsManager.Token(expressionElement.GetAttributeReference("type").Value.ToString()) as IExpression; if (null != expression) { try { expression.Make(expressionElement, sysmanager.ExpressionsManager); expressionResult = expression.Evaluate(); } catch (ArgumentException ax) { } } } } object defaultValue = null; if (!string.IsNullOrEmpty(propertyName) && controlPropertyElement.Attributes.ContainsKey("value")) { defaultValue = controlPropertyElement.GetAttributeReference("value").Value; if (null == expression || null == binder) { try { if (string.IsNullOrEmpty(cellControlName) || propertyName != this.KnownTypes[cellControlName].ReadOnlyProperty || (propertyName == this.KnownTypes[cellControlName].ReadOnlyProperty && defaultValue != null && !string.IsNullOrEmpty(defaultValue.ToString()))) { if (propertyName == "Watermark") { if (null != defaultValue && !String.IsNullOrEmpty(defaultValue.ToString())) ReflectionServices.SetValue(cellControl, propertyName, defaultValue); } else ReflectionServices.SetValue(cellControl, propertyName, defaultValue); } } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance(string.Format("'{0}'.'{1}'='{2}' error", cellControlName, propertyName, controlPropertyElement.GetAttributeReference("value").Value), null, ex, EVENT_TYPE.Error)); } } else { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = new Dictionary<string, object>() { { "0", defaultValue} }; bindingItem.SourceProperty = "0"; bindingItem.Target = cellControl; bindingItem.TargetProperty = propertyName; bindingItem.Expression = expression; bindingItem.ExpressionEvaluationResult = expressionResult; binder.BindingItems.Add(bindingItem); } } if (controlPropertyElement.Attributes.ContainsKey("isList") && (bool)controlPropertyElement.GetAttributeReference("isList").Value) { object list = null; try { list = ReflectionServices.ExtractValue(cellControl, propertyName); if (null == list) throw new InvalidOperationException(string.Format("Member '{0}' is empty", propertyName)); if (!(list is ListItemCollection) && !(list is IDictionary<string, object>)) throw new InvalidOperationException(String.Format("Unsupported list type '{0}'", list.GetType().Name)); } catch (Exception ex) { this._monitor.Register(this, this._monitor.NewEventInstance("failed to retrive the list", null, ex, EVENT_TYPE.Error)); } if (null != list) { if (controlPropertyElement.Attributes.ContainsKey("hasEmpty") && (bool)controlPropertyElement.GetAttributeReference("hasEmpty").Value) { if (list is ListItemCollection) ((ListItemCollection)list).Add(""); else if (list is Dictionary<string, object>) ((Dictionary<string, object>)list).Add("", ""); } foreach (IConfigurationElement listItemElement in controlPropertyElement.Elements.Values) { string value = null; string text = null; string pull = null; if (listItemElement.Attributes.ContainsKey("value") && null != listItemElement.GetAttributeReference("value").Value) value = listItemElement.GetAttributeReference("value").Value.ToString(); if (listItemElement.Attributes.ContainsKey("text") && null != listItemElement.GetAttributeReference("text").Value) text = listItemElement.GetAttributeReference("text").Value.ToString(); if (listItemElement.Attributes.ContainsKey("pull") && null != listItemElement.GetAttributeReference("pull").Value) pull = listItemElement.GetAttributeReference("pull").Value.ToString(); if (list is ListItemCollection) { ListItem li = new ListItem(text, value); ((ListItemCollection)list).Add(li); if (null != binder && !String.IsNullOrEmpty(pull)) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = item.Data; bindingItem.SourceProperty = pull; bindingItem.Target = li; bindingItem.TargetProperty = "Text"; bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); } } else if (list is Dictionary<string, object>) { ((Dictionary<string, object>)list).Add(value, text); if (null != binder && !String.IsNullOrEmpty(pull)) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = item.Data; bindingItem.SourceProperty = pull; bindingItem.Target = list; bindingItem.TargetProperty = value; bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); } } } } } if (controlPropertyElement.Attributes.ContainsKey("property")) { if (container.Page != null && null != binder) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = WebPartManager.GetCurrentWebPartManager(container.Page); bindingItem.SourceProperty = "WebParts." + controlPropertyElement.GetAttributeReference("property").Value.ToString(); bindingItem.Target = cellControl; bindingItem.TargetProperty = propertyName; if (string.IsNullOrEmpty(cellControlName) || propertyName != this.KnownTypes[cellControlName].ReadOnlyProperty) bindingItem.DefaultValue = defaultValue; bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); } } if (controlPropertyElement.Attributes.ContainsKey("pull")) { string pull = controlPropertyElement.GetAttributeReference("pull").Value.ToString(); if (binder != null && null != item) { IBindingItem bindingItem = binder.NewBindingItemInstance(); bindingItem.Source = item.Data; bindingItem.SourceProperty = pull; bindingItem.Target = cellControl; bindingItem.TargetProperty = propertyName; if (string.IsNullOrEmpty(cellControlName) || propertyName != this.KnownTypes[cellControlName].ReadOnlyProperty) bindingItem.DefaultValue = defaultValue; bindingItem.Expression = expression; binder.BindingItems.Add(bindingItem); if (item.InvalidMember == bindingItem.SourceProperty) container.ApplyStyle(invalidStyle); } if (this.IsDesignEnabled && propertyName == this.KnownTypes[cellControlName].WatermarkProperty) { // StyleTextBox has its own Watermark feature if (typeof(StyledTextBox).IsInstanceOfType(cellControl)) { ReflectionServices.SetValue(cellControl, "Watermark", pull); } else container.Attributes.Add("watermark", pull); } } } } result = cellControl; } } return result; }
protected bool CheckGroupingLevel(ITemplatingItem item) { bool result = false; if (string.IsNullOrEmpty(this._groupByMember)) { result = false; } else { if (null == this.previousGroupItem) { result = true; } else { Dictionary<string, object> oldValues = new Dictionary<string, object>(); Dictionary<string, object> newValues = new Dictionary<string, object>(); foreach (string member in _groupByMember.Split(',')) { oldValues.Add(member, ReflectionServices.ExtractValue(this.previousGroupItem.Data, member)); newValues.Add(member, ReflectionServices.ExtractValue(item.Data, member)); } foreach (KeyValuePair<string, object> entry in oldValues) { string oldstr = entry.Value == null ? null : entry.Value.ToString(); string newstr = newValues[entry.Key] == null ? null : newValues[entry.Key].ToString(); if (oldstr != newstr) { result = true; break; } } } } return result; }
public virtual void Extract(Control container, IConfigurationType config, ITemplatable templatable, IBinder binder, IEnumerable registry, ITemplatingItem item, int itemIndex, int itemsCount, WebPartManager manager) { throw new NotImplementedException(); }
protected void ComputeRunningTotals(ITemplatingItem item) { if (!string.IsNullOrEmpty(this._totalsByMembers)) { Dictionary<string, decimal> data = this.runningTotalsItem.Data as Dictionary<string, decimal>; string[] totals = this._totalsByMembers.Split(new char[] { ',' }); string[] array = totals; for (int i = 0; i < array.Length; i++) { string member = array[i]; object objectval = ReflectionServices.ExtractValue(item.Data, member); decimal val = 0m; if (objectval != DBNull.Value) { val = (decimal)ReflectionServices.StrongTypeValue(objectval, typeof(decimal)); } if (data.ContainsKey(member)) { Dictionary<string, decimal> dictionary; string key; (dictionary = data)[key = member] = dictionary[key] + val; } else { data.Add(member, val); } } } }
public virtual void DisplayItem(Table table, IConfigurationElement element, string index, IBinder binder, ITemplatingItem item, TableItemStyle style, TableItemStyle invalidStyle, Dictionary <string, Control> registry, WebPartManager manager) { string[] span = null; if (element.Attributes.ContainsKey("span") && null != element.GetAttributeReference("span").Value) { span = element.GetAttributeReference("span").Value.ToString().Split(new char[] { ',' }); } string[] rowspan = null; if (element.Attributes.ContainsKey("rowspan") && null != element.GetAttributeReference("rowspan").Value) { rowspan = element.GetAttributeReference("rowspan").Value.ToString().Split(new char[] { ',' }); } TableRow tr = new TableRow(); tr.ID = string.Concat(new string[] { table.ID, "-", element.ConfigKey, "-", index }); tr.Attributes["key"] = element.ConfigKey; tr.ApplyStyle(style); foreach (IConfigurationElementAttribute attribute in element.Attributes.Values) { if ("span" != attribute.ConfigKey && "rowspan" != attribute.ConfigKey) { tr.Style.Add(attribute.ConfigKey, attribute.Value.ToString()); } } table.Rows.Add(tr); int count = 0; foreach (IConfigurationElement controlElement in element.Elements.Values) { TableCell tc = new TableCell(); tc.ID = tr.ID + "-" + controlElement.ConfigKey; tc.Attributes["key"] = controlElement.ConfigKey; if (span != null && span.Length > count) { int columnSpan = 1; int.TryParse(span[count], out columnSpan); tc.ColumnSpan = columnSpan; if (rowspan != null && rowspan.Length > count) { int rowSpan = 1; int.TryParse(rowspan[count], out rowSpan); tc.RowSpan = rowSpan; } count++; } tr.Cells.Add(tc); string pullpush = null; foreach (IConfigurationElement propertyElement in controlElement.Elements.Values) { if (propertyElement.Attributes.ContainsKey("for") && "cell" == propertyElement.GetAttributeReference("for").Value.ToString() && propertyElement.Attributes.ContainsKey("member") && propertyElement.Attributes.ContainsKey("value")) { try { ReflectionServices.SetValue(tc, propertyElement.GetAttributeReference("member").Value.ToString(), propertyElement.GetAttributeReference("value").Value); } catch (Exception ex) { ControlFactory.Instance.Monitor.Register(ControlFactory.Instance, ControlFactory.Instance.Monitor.NewEventInstance("set cell attributes error", null, ex, EVENT_TYPE.Error)); } } if (propertyElement.Attributes.ContainsKey("pull")) { pullpush = propertyElement.GetAttributeReference("pull").Value.ToString(); } else { if (propertyElement.Attributes.ContainsKey("push")) { pullpush = propertyElement.GetAttributeReference("push").Value.ToString(); } } } Control cellControl = ControlFactory.Instance.CreateControl(controlElement, index, binder, item, tc, invalidStyle, registry, manager); if (null != cellControl) { cellControl.ID = string.Concat(new string[] { table.ID, "-", element.ConfigKey, "-", index, "-", controlElement.ConfigKey, "-ctrl" }); tc.Controls.Add(cellControl); if (cellControl is BaseDataBoundControl && !string.IsNullOrEmpty(pullpush)) { if (!item.BoundControls.ContainsKey(pullpush)) { item.BoundControls.Add(pullpush, new List <BaseDataBoundControl>()); } item.BoundControls[pullpush].Add((BaseDataBoundControl)cellControl); } } } }