private void setValue(PropertyInfo prop, object value, ColumnBindingAttribute attribute) { if (value != null) { prop.SetValue(this, value, null); if (OnSettingProperty != null) OnSettingProperty(this, new SetPropertyArgs(prop, value, attribute)); runRecusion(value); } }
private void setProperty(PropertyInfo prop, ColumnBindingAttribute attribute, int index) { var propertyType = prop.PropertyType; object value = null; var singleData = prop.GetCustomAttributes(typeof(SingleSampleDataAttribute), true).Cast<SingleSampleDataAttribute>().Where(d => d.Group == index).FirstOrDefault(); if (singleData != null) { value = getConvertValue(attribute, singleData.Value, propertyType); } else { var datas = prop.GetCustomAttributes(typeof(ComplexSampleDataAttribute), true).Cast<ComplexSampleDataAttribute>(); if (datas.Count() > 0) { var header = datas.Where(c => c.DataType == SampleDataType.Header && c.Group == index).FirstOrDefault(); if (header != null) { DataTable dt = new DataTable(); foreach (var s in header.Content) { dt.Columns.Add(new DataColumn(s)); } var body = datas.Where(c => c.DataType == SampleDataType.Body && c.Group == index); foreach (var r in body) { var row = dt.NewRow(); for (int i = 0; i < r.Content.Count(); i++) { row[i] = r.Content[i]; } dt.Rows.Add(row); } var rows = dt.Select(); value = getConvertValue(attribute, rows, propertyType); } } } setValue(prop, value, attribute); }
private void setSingleProperty(PropertyInfo prop, ColumnBindingAttribute attribute, DataRow[] rows, int index) { object value = null; if (rows != null && rows.Count() > 0) { string colName = attribute.ColNames.First(); //May Throw Error DataRow dr = rows[index]; if (dr[colName] != null && dr[colName].ToString() != "") { value = getConvertValue(attribute, dr[colName], prop.PropertyType); } } setValue(prop, value, attribute); }
private void resetColumnName(MemberInfo prop, ColumnBindingAttribute attr) { if (attr.ColNames == null || attr.ColNames.Count() == 0) { attr.ColNames = new string[] { prop.Name }; } }
private void setComplexProperty(PropertyInfo prop, ColumnBindingAttribute attribute, DataRow[] rows, int index) { object value = null; value = getConvertValue(attribute, rows, prop.PropertyType); setValue(prop, value, attribute); }
private string getTableFilter(ColumnBindingAttribute attribute) { string filter = null; if (attribute != null) { filter = dba.IdColumnName + "=" + CurrentId; } return filter; }
private bool isColumnsInclude(DataTable dt, ColumnBindingAttribute attribute) { bool isAllContain = true; foreach (var s in attribute.ColNames) { if (dt.Columns.Cast<DataColumn>().Where(c => c.ColumnName.ToLower().Contains(s.ToLower())).FirstOrDefault() == null) { isAllContain = false; break; } } return isAllContain; }
private void getSingleProperty(PropertyInfo prop, ColumnBindingAttribute attribute, DataRow[] rows, int index) { string colName = attribute.ColNames.First(); DataRow dr = rows[index]; dr[colName] = prop.GetValue(this, null); }
private DataRow[] getSharedData(ColumnBindingAttribute attribute, bool isSimpleCondition) { DataTable dt = null; string tableName = ""; string columnName = attribute.ColNames.Last(); if (_tableMapping.ContainsKey(columnName.ToLower())) { tableName = _tableMapping[columnName.ToLower()]; } if (tableName != "" && Data.Tables.Contains(tableName)) { dt = Data.Tables[tableName]; } if (dt != null) { string filter = null; filter = getTableFilter(attribute); if (filter != null && isColumnsInclude(dt, attribute)) { return dt.Select(filter); } } return null; }
private DataRow[] getPrivateData(ColumnBindingAttribute attribute, bool isSimpleCondition) { DataTable dt = null; if (Data.Tables.Contains(dba.TableName)) { dt = Data.Tables[dba.TableName]; } if (dt != null) { string filter = null; filter = getTableFilter(attribute); if (filter != null && isColumnsInclude(dt, attribute)) { return dt.Select(filter); } } return null; }
private object getConvertValue(ColumnBindingAttribute colAttr, object SourceValue, Type targetType) { object value = null; value = Convert.ChangeType(SourceValue, targetType); //if (colAttr.MethodName != null && colAttr.Target != null) //{ // var customDelegate = Delegate.CreateDelegate(typeof(ColumnBindingConvert), colAttr.Target, colAttr.MethodName) as ColumnBindingConvert; // value = customDelegate.Invoke(SourceValue); //} //else //{ // value = Convert.ChangeType(SourceValue, targetType); //} return value; }
public SetPropertyArgs(MemberInfo Member, object value, ColumnBindingAttribute Attribute) { this.Member = Member; this.Value = value; this.Attribute = Attribute; }