public static ExtendedFieldSearchInfo Parse(StringTable values) { ExtendedFieldSearchInfo result = new ExtendedFieldSearchInfo(); ExtendedField[] fileds = AllSettings.Current.ExtendedFieldSettings.FieldsWithPassport.ToArray(); foreach (DictionaryEntry item in values) { if (item.Value == null || (string)item.Value == string.Empty) continue; ExtendedField field = Array.Find<ExtendedField>(fileds, match => match.Key == (string)item.Key); if (field != null) { ExtendedFieldType type = UserBO.Instance.GetExtendedFieldType(field.FieldTypeName); if (type != null) { if (result.Items == null) result.Items = new List<ExtendedFieldSearchInfoItem>(); result.Items.Add(new ExtendedFieldSearchInfoItem((string)item.Key, (string)item.Value, type.NeedExactMatch)); } } } return result; }
public static ExtendedFieldSearchInfo Parse(StringTable values) { ExtendedFieldSearchInfo result = new ExtendedFieldSearchInfo(); ExtendedField[] fileds = AllSettings.Current.ExtendedFieldSettings.FieldsWithPassport.ToArray(); foreach (DictionaryEntry item in values) { if (item.Value == null || (string)item.Value == string.Empty) { continue; } ExtendedField field = Array.Find <ExtendedField>(fileds, match => match.Key == (string)item.Key); if (field != null) { ExtendedFieldType type = UserBO.Instance.GetExtendedFieldType(field.FieldTypeName); if (type != null) { if (result.Items == null) { result.Items = new List <ExtendedFieldSearchInfoItem>(); } result.Items.Add(new ExtendedFieldSearchInfoItem((string)item.Key, (string)item.Value, type.NeedExactMatch)); } } } return(result); }
public UserFilterBase() { this.Pagesize = Consts.DefaultPageSize; ExtendedFields = new ExtendedFieldSearchInfo(); this.Order = UserOrderBy.UserID; this.IsDesc = true; }
protected override void DoGetFromForm() { StringTable temp = new StringTable(); UserExtendedValueCollection values = UserBO.Instance.LoadExtendedFieldValues(); foreach (UserExtendedValue value in values) { temp.Add(value.ExtendedFieldID, value.Value); } ExtendedFields = ExtendedFieldSearchInfo.Parse(temp); base.DoGetFromForm(); }
protected virtual void DoGetFromForm() { foreach (PropertyInfo propertyInfo in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy)) { if (!propertyInfo.IsDefined(typeof(FilterItemAttribute), true)) { continue; } FilterItemAttribute attribute = (FilterItemAttribute)(propertyInfo.GetCustomAttributes(typeof(FilterItemAttribute), true)[0]); string formName = attribute.FormName; if (string.IsNullOrEmpty(formName)) { formName = propertyInfo.Name; } string text = HttpContext.Current.Request.Form[formName]; if (text != null) { //此时可以认为Filter不为空 if (IsNull) { this.IsNull = false; } switch (Type.GetTypeCode(propertyInfo.PropertyType)) { case TypeCode.String: text = HttpUtility.HtmlEncode(text); propertyInfo.SetValue(this, text, null); break; default: //暂时先这么写了,以后要改善这部分的设计 if (attribute.FormType == FilterItemFormType.BeginDate || attribute.FormType == FilterItemFormType.EndDate) { DateTime?date = null; if (!string.IsNullOrEmpty(text)) { using (ErrorScope es = new ErrorScope()) { if (attribute.FormType == FilterItemFormType.EndDate) { date = DateTimeUtil.ParseEndDateTime(text); } else if (attribute.FormType == FilterItemFormType.BeginDate) { date = DateTimeUtil.ParseBeginDateTime(text); } es.IgnoreError <ErrorInfo>(); } propertyInfo.SetValue(this, date, null); } break; } if (propertyInfo.PropertyType == typeof(ExtendedFieldSearchInfo)) { propertyInfo.SetValue(this, ExtendedFieldSearchInfo.Parse(text), null); } else { object objValue; using (ErrorScope es = new ErrorScope()) { if (StringUtil.TryParse(propertyInfo.PropertyType, text, out objValue)) { propertyInfo.SetValue(this, objValue, null); } es.IgnoreError <ErrorInfo>(); } } break; } } } }
protected virtual void DoParse(string value) { if (string.IsNullOrEmpty(value)) { return; } try { value = SecurityUtil.DesDecode(value); } catch { return; } int index = value.IndexOf('|'); if (index < 1) { return; } int[] valueLengths = StringUtil.Split <int>(value.Substring(0, index), ','); if (valueLengths.Length == 0) { return; } //此时可以认为Filter不为空 this.IsNull = false; index++; int i = 0; foreach (PropertyInfo propertyInfo in GetType().GetProperties(BindingFlags.Public | BindingFlags.Instance | BindingFlags.FlattenHierarchy)) { if (!propertyInfo.IsDefined(typeof(FilterItemAttribute), true)) { continue; } if (valueLengths.Length <= i) { break; } int valueLength = valueLengths[i]; FilterItemAttribute attribute = (FilterItemAttribute)(propertyInfo.GetCustomAttributes(typeof(FilterItemAttribute), true)[0]); string text = value.Substring(index, valueLength); switch (Type.GetTypeCode(propertyInfo.PropertyType)) { case TypeCode.Boolean: if (text == "1") { propertyInfo.SetValue(this, true, null); } else { propertyInfo.SetValue(this, false, null); } break; case TypeCode.String: propertyInfo.SetValue(this, text, null); break; default: //暂时先这么写了,以后要改善这部分的设计 if (attribute.FormType == FilterItemFormType.BeginDate || attribute.FormType == FilterItemFormType.EndDate) { DateTime?date = null; if (!string.IsNullOrEmpty(text)) { using (ErrorScope es = new ErrorScope()) { if (attribute.FormType == FilterItemFormType.EndDate) { date = DateTimeUtil.ParseEndDateTime(text); } else if (attribute.FormType == FilterItemFormType.BeginDate) { date = DateTimeUtil.ParseBeginDateTime(text); } es.IgnoreError <ErrorInfo>(); } propertyInfo.SetValue(this, date, null); } break; } if (propertyInfo.PropertyType == typeof(ExtendedFieldSearchInfo)) { propertyInfo.SetValue(this, ExtendedFieldSearchInfo.Parse(text), null); } else { object objValue; using (ErrorScope es = new ErrorScope()) { if (StringUtil.TryParse(propertyInfo.PropertyType, text, out objValue)) { propertyInfo.SetValue(this, objValue, null); } es.IgnoreError <ErrorInfo>(); } } break; } index += valueLength; i++; } }