/// <summary> /// Advances the <see cref="T:System.Data.DbDataReader" /> to the next record. /// </summary> /// <returns><c>true</c> if there are more rows; otherwise, <c>false</c>.</returns> public override bool Read() { if (Reader.Read()) { IOrderedDictionary fields = GetDefault(); for (int i = 0; i < Reader.FieldCount; i++) { if (UseOrdinal) { if (fields.Contains(i)) { fields[i] = Reader[i]; } } else { if (IsMatch(Reader.GetName(i))) { if (fields.Contains(Reader.GetName(i))) { fields[Reader.GetName(i)] = Reader[Reader.GetName(i)]; } } } } RowCount++; SetFields(fields); return(true); } return(false); }
public void Querying() { var dic = new OrderedDictionary <int, string>() { { 3, "three" }, { 2, "two" }, { 1, "one" }, { 4, "four" }, }; IDictionary <int, string> dicIntf = dic; IOrderedDictionary dicNonGeneric = dic; IReadOnlyOrderedDictionary <int, string> readOnlyDic = dic; Assert.Equal("one", dic[2]); Assert.Throws <ArgumentOutOfRangeException>(() => dic[-1]); Assert.Throws <ArgumentOutOfRangeException>(() => dic[dic.Count]); Assert.Equal("two", dicIntf[2]); Assert.Throws <KeyNotFoundException>(() => dicIntf[0]); Assert.True(dic.TryGetValue(2, out var value)); Assert.Equal("two", value); Assert.False(dic.TryGetValue(0, out value)); Assert.Equal(null, value); Assert.True(dic.ContainsKey(2)); Assert.False(dic.ContainsKey(0)); Assert.True(dic.Keys.Contains(2)); Assert.False(dic.Keys.Contains(0)); Assert.True(readOnlyDic.Keys.Contains(2)); Assert.False(readOnlyDic.Keys.Contains(0)); Assert.True(dicNonGeneric.Contains(2)); Assert.False(dicNonGeneric.Contains(0)); Assert.True(dic.ContainsValue("two")); Assert.False(dic.ContainsValue("Two")); Assert.True(dic.Values.Contains("two")); Assert.False(dic.Values.Contains("Two")); Assert.True(readOnlyDic.Values.Contains("two")); Assert.False(readOnlyDic.Values.Contains("Two")); Assert.Equal(1, dic.GetKeyAt(2)); Assert.Throws <ArgumentOutOfRangeException>(() => dic.GetKeyAt(-1)); Assert.Throws <ArgumentOutOfRangeException>(() => dic.GetKeyAt(dic.Count)); Assert.Equal(2, dic.IndexOfKey(1)); Assert.Equal(-1, dic.IndexOfKey(0)); var array = new KeyValuePair <int, string> [dic.Count + 2]; dicIntf.CopyTo(array, 1); Assert.Equal(new[] {
/// <devdoc> /// Extracts the value(s) from the given cell and puts the value(s) into a dictionary. Indicate includeReadOnly /// to have readonly fields' values inserted into the dictionary. /// </devdoc> public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control childControl = null; string dataField = DataImageUrlField; object value = null; bool includeNullValue = false; if (((rowState & DataControlRowState.Insert) != 0) && !InsertVisible) { return; } if (cell.Controls.Count == 0) // this should happen only in design mode { Debug.Assert(DesignMode, "Unless you're in designmode, there should be a control in the cell."); return; } childControl = cell.Controls[0]; Image image = childControl as Image; if (image != null) { if (includeReadOnly) { includeNullValue = true; if (image.Visible) { value = image.ImageUrl; } } } else { TextBox editBox = childControl as TextBox; if (editBox != null) { value = editBox.Text; includeNullValue = true; // just in case someone wrote a derived textbox that returns null for Text. } } if (value != null || includeNullValue) { if (ConvertEmptyStringToNull && value is string && ((string)value).Length == 0) { value = null; } if (dictionary.Contains(dataField)) { dictionary[dataField] = value; } else { dictionary.Add(dataField, value); } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { string format = this.DataFormatString; object val = null; try { Decimal d = Decimal.Parse(cell.Text, CultureInfo.CurrentCulture); val = d; } catch (Exception ex) { } string dataField = this.DataField; if (dictionary.Contains(dataField)) { dictionary[dataField] = val; } else { dictionary.Add(dataField, val); } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { string dataField = DataField; object obj2 = null; // object obj3 = null; if (cell.Controls.Count > 0) { // Get column editor of type DropDownList of current cell Control control = cell.Controls[0]; DropDownList dropDownList = control as DropDownList; if ((dropDownList != null) && (includeReadOnly || dropDownList.Enabled)) { obj2 = dropDownList.Text; } } if (obj2 != null) { if (dictionary.Contains(dataField)) { dictionary[dataField] = obj2; } else { //put both text and value into the dictionary dictionary.Add(dataField, obj2); } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { var key = DataField; object value = null; if (cell.Controls.Count > 0) { var control = cell.Controls[0]; var list = control as DropDownList; if ((list != null) && list.Items.Count > 0 && (includeReadOnly || list.Enabled)) { value = list.SelectedValue; } } if (value != null) { if (dictionary.Contains(key)) { dictionary[key] = value; } else { dictionary.Add(key, value); } } }
/// <summary> /// 从单元格取出数值 /// </summary> /// <param name="dictionary"></param> /// <param name="cell"></param> /// <param name="rowState"></param> /// <param name="includeReadOnly"></param> public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control control = null; string dataField = this.DataField; object obj2 = null; if (cell.Controls.Count > 0) { control = cell.Controls[0]; DropDownList box = control as DropDownList; if ((box != null) && (includeReadOnly || box.Enabled)) { obj2 = box.SelectedValue; } } if (obj2 != null) { if (dictionary.Contains(dataField)) { dictionary[dataField] = obj2; } else { dictionary.Add(dataField, obj2); } } }
/// <devdoc> /// Extracts the value(s) from the given cell and puts the value(s) into a dictionary. Indicate includeReadOnly /// to have readonly fields' values inserted into the dictionary. /// </devdoc> public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control childControl = null; string dataField = DataField; object value = null; if (cell.Controls.Count > 0) { childControl = cell.Controls[0]; CheckBox checkBox = childControl as CheckBox; if (checkBox != null) { if (includeReadOnly || checkBox.Enabled) { value = checkBox.Checked; } } } if (value != null) { if (dictionary.Contains(dataField)) { dictionary[dataField] = value; } else { dictionary.Add(dataField, value); } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control control = null; string dataField = this.DataField; object obj2 = null; if (cell.Controls.Count > 0) { control = cell.Controls[0]; CheckBox box = control as CheckBox; if ((box != null) && (includeReadOnly || box.Enabled)) { obj2 = box.Checked; } } if (obj2 != null) { if (dictionary.Contains(dataField)) { dictionary[dataField] = obj2; } else { dictionary.Add(dataField, obj2); } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { if (this.UseCheckBox) { Control control = null; string dataField = this.DataField; object obj2 = null; if (cell.Controls.Count > 0) { control = cell.Controls[0]; CheckBox box = control as CheckBox; if ((box != null) && (includeReadOnly || box.Enabled)) { obj2 = box.Checked; } } if (obj2 != null) { if (dictionary.Contains(dataField)) { dictionary[dataField] = obj2; } else { dictionary.Add(dataField, obj2); } } } else { base.ExtractValuesFromCell(dictionary, cell, rowState, includeReadOnly); } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { string format = this.DataFormatString; if (string.IsNullOrEmpty(format)) { format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern; } object val = null; try { DateTime dt = DateTime.ParseExact(cell.Text, format, CultureInfo.CurrentCulture); val = dt; } catch (Exception ex) { } string dataField = this.DataField; if (dictionary.Contains(dataField)) { dictionary[dataField] = val; } else { dictionary.Add(dataField, val); } }
private string LookupParameter(IOrderedDictionary parameters, string value) { if (!string.IsNullOrEmpty(value) && value.StartsWith("@")) { string name = value.TrimStart('@'); if (parameters.Contains(name)) { value = parameters[name].ToString(); } else if (parameters.Contains("@" + name)) { value = parameters["@" + name].ToString(); } } return(value); }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control control = null; string dataField = this.DataField; object text = null; string nullDisplayText = this.NullDisplayText; if (((rowState & DataControlRowState.Insert) == DataControlRowState.Normal) || this.InsertVisible) { if (cell.Controls.Count > 0) { control = cell.Controls[0]; TextBox box = control as TextBox; if (box != null) { text = box.Text; } } else if (includeReadOnly) { string s = cell.Text; if (s == " ") { text = string.Empty; } else if (this.SupportsHtmlEncode && this.HtmlEncode) { text = HttpUtility.HtmlDecode(s); } else { text = s; } } if (text != null) { if (((text is string) && (((string)text).Length == 0)) && this.ConvertEmptyStringToNull) { text = null; } if (((text is string) && (((string)text) == nullDisplayText)) && (nullDisplayText.Length > 0)) { text = null; } if (dictionary.Contains(dataField)) { dictionary[dataField] = text; } else { dictionary.Add(dataField, text); } } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control control = null; string dataField = this.DataField; object text = null; string nullDisplayText = this.NullDisplayText; if (((rowState & DataControlRowState.Insert) == DataControlRowState.Normal) || this.InsertVisible) { if (cell.Controls.Count > 0) { control = cell.Controls[0]; TextBox box = control as TextBox; if (box != null) { text = box.Text; } } else if (includeReadOnly) { string s = cell.Text; if (s == " ") { text = string.Empty; } else if (this.SupportsHtmlEncode && this.HtmlEncode) { text = HttpUtility.HtmlDecode(s); } else { text = s; } } if (text != null) { if (((text is string) && (((string) text).Length == 0)) && this.ConvertEmptyStringToNull) { text = null; } if (((text is string) && (((string) text) == nullDisplayText)) && (nullDisplayText.Length > 0)) { text = null; } if (dictionary.Contains(dataField)) { dictionary[dataField] = text; } else { dictionary.Add(dataField, text); } } } }
/// <summary> /// Binds a controls value to a property of an entity. /// </summary> /// <param name="control">The control to get the value from.</param> /// <param name="list">The <see cref="IOrderedDictionary"/> containing the values.</param> /// <param name="propertyName">The name of the property to bind the value to.</param> public static void BindControl(Control control, IOrderedDictionary list, String propertyName) { if (control != null) { if (list.Contains(propertyName)) { list.Remove(propertyName); } list.Add(propertyName, GetValue(control)); } }
static void ExceptRange(string range, IOrderedDictionary fastKeys, ref List <string> affectedKeys) { var tmp = range.Split('~'); int start = Convert.ToInt32(Trim(tmp[0])); int end = Convert.ToInt32(Trim(tmp[1])); for (int i = start; i <= end; i++) { string newKey = Convert.ToString(i); if (fastKeys.Contains(newKey)) { affectedKeys.Remove(newKey); } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control editor = null; String field = this.DataField; Boolean valueSet = false; Object currentValue = null; if (cell.Controls.Count > 0) { editor = cell.Controls[0]; CheckBox checkBoxEditor = editor as CheckBox; if ((checkBoxEditor != null) && (includeReadOnly || checkBoxEditor.Enabled)) { valueSet = true; currentValue = checkBoxEditor.Checked; } ListControl listEditor = editor as ListControl; if ((listEditor != null) && (includeReadOnly || listEditor.Enabled)) { valueSet = true; if (listEditor.SelectedValue == Boolean.TrueString) { currentValue = true; } else if (listEditor.SelectedValue == Boolean.FalseString) { currentValue = false; } else { currentValue = DBNull.Value; } } } if (valueSet) { if (dictionary.Contains(field)) { dictionary[field] = currentValue; } else { dictionary.Add(field, currentValue); } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control control = null; string dataImageUrlField = this.DataImageUrlField; object imageUrl = null; bool flag = false; if ((((rowState & DataControlRowState.Insert) == DataControlRowState.Normal) || this.InsertVisible) && (cell.Controls.Count != 0)) { control = cell.Controls[0]; Image image = control as Image; if (image != null) { if (includeReadOnly) { flag = true; if (image.Visible) { imageUrl = image.ImageUrl; } } } else { TextBox box = control as TextBox; if (box != null) { imageUrl = box.Text; flag = true; } } if ((imageUrl != null) || flag) { if ((this.ConvertEmptyStringToNull && (imageUrl is string)) && (((string)imageUrl).Length == 0)) { imageUrl = null; } if (dictionary.Contains(dataImageUrlField)) { dictionary[dataImageUrlField] = imageUrl; } else { dictionary.Add(dataImageUrlField, imageUrl); } } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control control = null; string dataImageUrlField = this.DataImageUrlField; object imageUrl = null; bool flag = false; if ((((rowState & DataControlRowState.Insert) == DataControlRowState.Normal) || this.InsertVisible) && (cell.Controls.Count != 0)) { control = cell.Controls[0]; Image image = control as Image; if (image != null) { if (includeReadOnly) { flag = true; if (image.Visible) { imageUrl = image.ImageUrl; } } } else { TextBox box = control as TextBox; if (box != null) { imageUrl = box.Text; flag = true; } } if ((imageUrl != null) || flag) { if ((this.ConvertEmptyStringToNull && (imageUrl is string)) && (((string) imageUrl).Length == 0)) { imageUrl = null; } if (dictionary.Contains(dataImageUrlField)) { dictionary[dataImageUrlField] = imageUrl; } else { dictionary.Add(dataImageUrlField, imageUrl); } } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { if (cell.Controls.Count > 0) { DropDownList ddl = cell.Controls[0] as DropDownList; if (null == ddl) { throw new InvalidOperationException("DropDownField could not extract control."); } object selectedValue = ddl.SelectedValue; if (dictionary.Contains(this.DataField)) { dictionary[this.DataField] = selectedValue; } else { dictionary.Add(this.DataField, selectedValue); } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { if (cell.Controls.Count > 0) { DropDownList ddl = cell.Controls[0] as DropDownList; if (null == ddl) { throw new InvalidOperationException("DropDownField could not extract control."); } object selectedValue = ddl.SelectedValue; if (dictionary.Contains(this.DataField)) { dictionary[this.DataField] = selectedValue; } else { dictionary.Add(this.DataField, selectedValue); } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { string format = this.DataFormatString; object val = null; try { Decimal d = Decimal.Parse(cell.Text, CultureInfo.CurrentCulture); val = d; } catch (Exception ex) { } string dataField = this.DataField; if (dictionary.Contains(dataField)) dictionary[dataField] = val; else { dictionary.Add(dataField, val); } }
/// <summary> /// This method is called by the ExtractRowValues methods of /// GridView and DetailsView. Retrieve the current value of the /// cell from the Checked state of the Radio button. /// </summary> /// <param name="dictionary"></param> /// <param name="cell"></param> /// <param name="rowState"></param> /// <param name="includeReadOnly"></param> public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { // Determine whether the cell contains a RadioButtonList // in its Controls collection. if (cell.Controls.Count > 0) { object radio = cell.Controls[0]; object checkedValue = null; if (radio is RadioButton || radio is RadioButtonList) { if (radio is RadioButton) { checkedValue = ((RadioButton)radio).Checked; } else if (radio is RadioButtonList) { checkedValue = ((RadioButtonList)radio).SelectedValue; } } else { // A RadioButton is expected, but a null is encountered. throw new InvalidOperationException("BoundRadioButtonField could not extract control."); } // Add the value of the Checked attribute of the // RadioButton to the dictionary. if (dictionary.Contains(DataField)) { dictionary[DataField] = checkedValue; } else { dictionary.Add(DataField, checkedValue); } } }
/// <summary> /// This method is called by the ExtractRowValues methods of /// GridView and DetailsView. Retrieve the current value of the /// cell from the Checked state of the Radio button. /// </summary> /// <param name="dictionary"></param> /// <param name="cell"></param> /// <param name="rowState"></param> /// <param name="includeReadOnly"></param> public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { // Determine whether the cell contains a RadioButtonList // in its Controls collection. if (cell.Controls.Count > 0) { object radio = cell.Controls[0]; object checkedValue = null; if (radio is RadioButton || radio is RadioButtonList) { if (radio is RadioButton) { checkedValue = ((RadioButton)radio).Checked; } else if (radio is RadioButtonList) { checkedValue = ((RadioButtonList)radio).SelectedValue; } } else { // A RadioButton is expected, but a null is encountered. throw new InvalidOperationException("BoundRadioButtonField could not extract control."); } // Add the value of the Checked attribute of the // RadioButton to the dictionary. if (dictionary.Contains(DataField)) { dictionary[DataField] = checkedValue; } else { dictionary.Add(DataField, checkedValue); } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { string format = this.DataFormatString; if (string.IsNullOrEmpty(format)) format = DateTimeFormatInfo.CurrentInfo.ShortDatePattern; object val = null; try { DateTime dt = DateTime.ParseExact(cell.Text, format, CultureInfo.CurrentCulture); val = dt; } catch (Exception ex) { } string dataField = this.DataField; if (dictionary.Contains(dataField)) dictionary[dataField] = val; else { dictionary.Add(dataField, val); } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control control = null; string dataField = this.DataField; object obj2 = null; object obj3 = null; if (cell.Controls.Count > 0) { // Get column editor of type DropDownList of current cell control = cell.Controls[0]; DropDownList box = control as DropDownList; if ((box != null) && (includeReadOnly || box.Enabled)) { obj2 = box.Text; if (obj2 != null) { // extract value from DropDownList ListItem itm = box.Items.FindByValue(obj2.ToString()); obj3 = itm.Text; } } } if (obj2 != null) { if (dictionary.Contains(dataField)) { dictionary[dataField] = obj2; } else { //put both text and value into the dictionary dictionary.Add(dataField, obj3); dictionary.Add(this.IDDataField, obj2); } } }
public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { object value = null; if (cell != null) { if (cell.Controls.Count > 0) { value = this.ExtractControlValue(cell.Controls[0]); } } if (dictionary != null) { if (dictionary.Contains(this.DataField)) { dictionary[this.DataField] = value; } else { dictionary.Add(this.DataField, value); } } }
/// <summary> /// Checks to see if the collection contains the specified parameter name. /// </summary> /// <param name="name">The parameter name.</param> /// <returns><c>true</c> if the specified parameter name is in collection, <c>false</c> if it is not.</returns> public virtual bool Contains(string name) => _parameters.Contains(name);
public static string GetOrDefault(this IOrderedDictionary dict, string key, string def) { return(dict.Contains(key) ? (dict[key] as string) : def); }
/// <devdoc> /// Extracts the value(s) from the given cell and puts the value(s) into a dictionary. Indicate includeReadOnly /// to have readonly fields' values inserted into the dictionary. /// </devdoc> public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control childControl = null; string dataField = DataField; object value = null; string nullDisplayText = NullDisplayText; if (((rowState & DataControlRowState.Insert) != 0) && !InsertVisible) { return; } if (cell.Controls.Count > 0) { childControl = cell.Controls[0]; TextBox editBox = childControl as TextBox; if (editBox != null) { value = editBox.Text; } } else { if (includeReadOnly == true) { string cellText = cell.Text; if (cellText == " ") { // nothing HtmlEncodes to , so we know that this means it was empty. value = String.Empty; } else { if (SupportsHtmlEncode && HtmlEncode) { value = HttpUtility.HtmlDecode(cellText); } else { value = cellText; } } } } if (value != null) { if ((value is string) && (((string)value).Length == 0) && ConvertEmptyStringToNull) { value = null; } if (value is string && (string)value == nullDisplayText && nullDisplayText.Length > 0) { value = null; } if (dictionary.Contains(dataField)) { dictionary[dataField] = value; } else { dictionary.Add(dataField, value); } } }
public bool Contains(object key) { // todo: override return(_dictionary.Contains(key)); }
protected override IEnumerable ExecuteSelect(DataSourceSelectArguments arguments) { Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "Begin"); if (CanSort) { arguments.AddSupportedCapabilities(DataSourceCapabilities.Sort); } if (CanPage) { arguments.AddSupportedCapabilities(DataSourceCapabilities.Page); } if (CanRetrieveTotalRowCount) { arguments.AddSupportedCapabilities(DataSourceCapabilities.RetrieveTotalRowCount); } // merge SelectParameters IOrderedDictionary parameters = SelectParameters.GetValues(Context, Owner); string sortExpression = GetNonNullOrEmpty( arguments.SortExpression, parameters[_sortExpressionParameterName] as string, SortExpression); string entityName = GetNonNullOrEmpty( parameters[_entityNameParameterName] as string, EntityName); string attributeName = GetNonNullOrEmpty( parameters[_attributeNameParameterName] as string, AttributeName); var metadataFlags = MetadataFlags; if (parameters.Contains(_metadataFlagsParameterName)) { metadataFlags = (parameters[_metadataFlagsParameterName] as string).ToEnum <EntityFilters>(); } var entityFlags = EntityFlags; if (parameters.Contains(_entityFlagsParameterName)) { entityFlags = (parameters[_entityFlagsParameterName] as string).ToEnum <EntityFilters>(); } // raise pre-event CrmMetadataDataSourceSelectingEventArgs selectingArgs = new CrmMetadataDataSourceSelectingEventArgs( Owner, arguments, entityName, attributeName, metadataFlags, entityFlags, sortExpression); OnSelecting(selectingArgs); if (selectingArgs.Cancel) { Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "Cancel"); return(null); } // merge event results arguments.RaiseUnsupportedCapabilitiesError(this); sortExpression = selectingArgs.SortExpression; entityName = selectingArgs.EntityName; attributeName = selectingArgs.AttributeName; metadataFlags = selectingArgs.MetadataFlags; entityFlags = selectingArgs.EntityFlags; if (CancelSelectOnNullParameter && string.IsNullOrEmpty(entityName) && string.IsNullOrEmpty(attributeName)) { Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "CancelSelectOnNullParameter"); return(null); } IEnumerable result = null; int rowsAffected = 0; try { if (Owner.CacheParameters.Enabled) { var cacheKey = GetCacheKey(metadataFlags, entityFlags, entityName, attributeName, sortExpression); result = ObjectCacheManager.Get(cacheKey, cache => { var metadata = ExecuteSelect(entityName, attributeName, sortExpression, entityFlags, metadataFlags, out rowsAffected); return(metadata); }, (cache, metadata) => { if (metadata != null) { var dependencies = GetCacheDependencies(metadata); cache.Insert(cacheKey, metadata, dependencies); } }); } else { result = ExecuteSelect(entityName, attributeName, sortExpression, entityFlags, metadataFlags, out rowsAffected); } } catch (System.Web.Services.Protocols.SoapException ex) { Tracing.FrameworkError("CrmMetadataDataSourceView", "ExecuteSelect", "{0}\n\n{1}", ex.Detail.InnerXml, ex); } catch (Exception e) { Tracing.FrameworkError("CrmMetadataDataSourceView", "ExecuteSelect", "Exception: {0}", e); // raise post-event with exception CrmMetadataDataSourceStatusEventArgs selectedExceptionArgs = new CrmMetadataDataSourceStatusEventArgs(0, e); OnSelected(selectedExceptionArgs); if (!selectedExceptionArgs.ExceptionHandled) { throw; } return(result); } // raise post-event CrmMetadataDataSourceStatusEventArgs selectedArgs = new CrmMetadataDataSourceStatusEventArgs(rowsAffected, null); OnSelected(selectedArgs); Tracing.FrameworkInformation("CrmMetadataDataSourceView", "ExecuteSelect", "End"); return(result); }
/// <devdoc> /// Extracts the value(s) from the given cell and puts the value(s) into a dictionary. Indicate includeReadOnly /// to have readonly fields' values inserted into the dictionary. /// </devdoc> public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control childControl = null; string dataField = DataField; object value = null; string nullDisplayText = NullDisplayText; if (((rowState & DataControlRowState.Insert) != 0) && !InsertVisible) { return; } if (cell.Controls.Count > 0) { childControl = cell.Controls[0]; TextBox editBox = childControl as TextBox; if (editBox != null) { value = editBox.Text; } } else { if (includeReadOnly == true) { string cellText = cell.Text; if (cellText == " ") // nothing HtmlEncodes to , so we know that this means it was empty. { value = String.Empty; } else { if (SupportsHtmlEncode && HtmlEncode) { value = HttpUtility.HtmlDecode(cellText); } else { value = cellText; } } } } if (value != null) { if ((value is string) && (((string)value).Length == 0) && ConvertEmptyStringToNull) { value = null; } if (value is string && (string)value == nullDisplayText && nullDisplayText.Length > 0) { value = null; } if (dictionary.Contains(dataField)) { dictionary[dataField] = value; } else { dictionary.Add(dataField, value); } } }
MethodInfo GetObjectMethod (string methodName, IOrderedDictionary parameters, DataObjectMethodType methodType) { MemberInfo[] methods = ObjectType.GetMember (methodName, MemberTypes.Method, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.IgnoreCase | BindingFlags.FlattenHierarchy); if (methods.Length > 1) { // MSDN: The ObjectDataSource resolves method overloads by method name and number // of parameters; the names and types of the parameters are not considered. // LAMESPEC: the tests show otherwise DataObjectMethodAttribute methodAttribute = null; MethodInfo methodInfo = null; bool hasConflict = false; foreach (MethodInfo me in methods) { // we look for methods only ParameterInfo [] pinfos = me.GetParameters (); if (pinfos.Length == parameters.Count) { object [] attrs = me.GetCustomAttributes (typeof (DataObjectMethodAttribute), true); DataObjectMethodAttribute domAttr = (attrs != null && attrs.Length > 0) ? (DataObjectMethodAttribute) attrs [0] : null; if (domAttr != null && domAttr.MethodType != methodType) continue; bool paramsMatch = true; foreach (ParameterInfo pinfo in pinfos) { if (!parameters.Contains (pinfo.Name)) { paramsMatch = false; break; } } if (!paramsMatch) continue; if (domAttr != null) { if (methodAttribute != null) { if (methodAttribute.IsDefault) { if (domAttr.IsDefault) { methodInfo = null; break; //fail due to a conflict } else continue; //existing matches better } else { methodInfo = null; //we override hasConflict = !domAttr.IsDefault; } } else methodInfo = null; //we override } if (methodInfo == null) { methodAttribute = domAttr; methodInfo = me; continue; } hasConflict = true; } } if (!hasConflict && methodInfo != null) return methodInfo; } else if (methods.Length == 1) { MethodInfo me = methods[0] as MethodInfo; if (me != null && me.GetParameters().Length == parameters.Count) return me; } throw CreateMethodException (methodName, parameters); }
object[] GetParameterArray (ParameterInfo[] methodParams, IOrderedDictionary viewParams, out ArrayList outParamInfos) { // FIXME: make this case insensitive outParamInfos = null; object[] values = new object [methodParams.Length]; foreach (ParameterInfo mp in methodParams) { // Parameter names must match if (!viewParams.Contains (mp.Name)) return null; values [mp.Position] = ConvertParameter (mp.ParameterType, viewParams [mp.Name]); if (mp.ParameterType.IsByRef) { if (outParamInfos == null) outParamInfos = new ArrayList (); outParamInfos.Add (mp); } } return values; }
public bool Update(IOrderedDictionary keys, IOrderedDictionary oldValues, IOrderedDictionary newValues) { IDao<Item, string> dao = DaoFactory.GetDao<Item, string>(); Item item = dao.GetById(keys[0].ToString(), true); if (item == null) return false; if (newValues.Contains("Forhtf")) item.Forhtf = Convert.ToBoolean(newValues["Forhtf"].ToString()); if (newValues.Contains("Fordnf")) item.Fordnf = Convert.ToBoolean(newValues["Fordnf"].ToString()); if (newValues.Contains("Colorcode")) item.Colorcode = (newValues["Colorcode"].ToString()); if (newValues.Contains("Colorname")) item.Colorcode = (newValues["Colorname"].ToString()); if (newValues.Contains("Id")) item.Colorcode = (newValues["Id"].ToString()); if (newValues.Contains("Itemname")) item.Itemname = (newValues["Itemname"].ToString()); //if (newValues.Contains("Areacode")) item.Areacode = (newValues["Areacode"].ToString()); try { return (dao.SaveOrUpdate(item) != null); } catch { return false; } }
public bool Equals(DataKey other) { if (other == null) { return(false); } IOrderedDictionary otherKeyTable = other.keyTable; if (keyTable != null && otherKeyTable != null) { if (keyTable.Count != otherKeyTable.Count) { return(false); } object thisValue, otherValue; foreach (object key in keyTable.Keys) { if (!otherKeyTable.Contains(key)) { return(false); } thisValue = keyTable [key]; otherValue = otherKeyTable [key]; if (thisValue == null ^ otherValue == null) { return(false); } if (!thisValue.Equals(otherValue)) { return(false); } } } string[] otherKeyNames = other.keyNames; if (keyNames != null && otherKeyNames != null) { int len = keyNames.Length; if (len != otherKeyNames.Length) { return(false); } for (int i = 0; i < len; i++) { if (String.Compare(keyNames [i], otherKeyNames [i], StringComparison.Ordinal) != 0) { return(false); } } } else if (keyNames == null ^ otherKeyNames == null) { return(false); } return(true); }
/// <devdoc> /// Extracts the value(s) from the given cell and puts the value(s) into a dictionary. Indicate includeReadOnly /// to have readonly fields' values inserted into the dictionary. /// </devdoc> public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control childControl = null; string dataField = DataImageUrlField; object value = null; bool includeNullValue = false; if (((rowState & DataControlRowState.Insert) != 0) && !InsertVisible) { return; } if (cell.Controls.Count == 0) { // this should happen only in design mode Debug.Assert(DesignMode, "Unless you're in designmode, there should be a control in the cell."); return; } childControl = cell.Controls[0]; Image image = childControl as Image; if (image != null) { if (includeReadOnly) { includeNullValue = true; if (image.Visible) { value = image.ImageUrl; } } } else { TextBox editBox = childControl as TextBox; if (editBox != null) { value = editBox.Text; includeNullValue = true; // just in case someone wrote a derived textbox that returns null for Text. } } if (value != null || includeNullValue) { if (ConvertEmptyStringToNull && value is string && ((string)value).Length == 0) { value = null; } if (dictionary.Contains(dataField)) { dictionary[dataField] = value; } else { dictionary.Add(dataField, value); } } }
/// <summary> /// Adds elements to the collection having the specified names and values. /// </summary> /// <param name="list">A collection of name/value pairs.</param> /// <param name="names">The property names.</param> /// <param name="values">The property values.</param> public static void SetValues(IOrderedDictionary list, String[] names, Object[] values) { for ( int i = 0; i < names.Length; i++ ) { if ( list.Contains(names[i]) ) { list.Remove(names[i]); } list.Add(names[i], values[i]); } }
/// <devdoc> /// Extracts the value(s) from the given cell and puts the value(s) into a dictionary. Indicate includeReadOnly /// to have readonly fields' values inserted into the dictionary. /// </devdoc> public override void ExtractValuesFromCell(IOrderedDictionary dictionary, DataControlFieldCell cell, DataControlRowState rowState, bool includeReadOnly) { Control childControl = null; string dataField = DataField; object value = null; if (cell.Controls.Count > 0) { childControl = cell.Controls[0]; CheckBox checkBox = childControl as CheckBox; if (checkBox != null) { if (includeReadOnly || checkBox.Enabled) { value = checkBox.Checked; } } } if (value != null) { if (dictionary.Contains(dataField)) { dictionary[dataField] = value; } else { dictionary.Add(dataField, value); } } }