private bool CheckFilter(Folder folder, string filterText) { object value = this.data[folder.Group]; if (string.IsNullOrEmpty(filterText)) { return(true); } if (folder.GroupMethod != -1) { switch (folder.Group.FieldType) { case FieldType.Date: DateTime dt = (DateTime)value; switch (folder.GroupMethod) { case 0: DateTime d1 = DateTime.Parse(filterText, DateTimeFormatInfo.CurrentInfo); return(d1 == dt); case 1: DateTime d = DateTime.Parse(filterText, DateTimeFormatInfo.CurrentInfo); return(d.Month == dt.Month && d.Year == dt.Year); case 2: return(int.Parse(filterText, CultureInfo.CurrentCulture) == dt.Year); } break; case FieldType.Text: string text = value as string; if (text == null) { text = string.Empty; } if (folder.GroupMethod == 1) { if (text.Length == 0) { return(false); } else { return(text.Substring(0, 1) == filterText); } } else { return(text == filterText); } } } else { switch (folder.Group.FieldType) { case FieldType.Select: int idx = ((List <string>)folder.Group.Data).IndexOf(filterText); return(idx == (int)value); case FieldType.Number: return(decimal.Parse(filterText, CultureInfo.CurrentCulture) == (decimal)value); case FieldType.Rating: return(decimal.Parse(filterText, CultureInfo.CurrentCulture) == (decimal)value); case FieldType.Reference: if (value is int) { return(false); } else { ObjectData d = (ObjectData)value; return(d[SystemProperty.Name].ToString() == filterText); } case FieldType.List: ListData l = (ListData)value; foreach (ObjectData od in l.Objects) { if (od[SystemProperty.Name].ToString() == filterText) { return(true); } } return(false); case FieldType.Url: return(((string)value).ToLowerInvariant() == filterText.ToLowerInvariant()); } } return(true); }
private bool CheckFilter(Field field, FilterOperation filterOperation, string filterText) { object value = this.data[field]; if (field.IsEmptyData(value)) { return(false); } if (string.IsNullOrEmpty(filterText)) { return(true); } switch (field.FieldType) { case FieldType.Date: DateTime dt = (DateTime)value; return(Utils.CompareText(dt.ToString(), filterText, filterOperation)); case FieldType.Text: string text = value as string; if (text == null) { text = string.Empty; } return(Utils.CompareText(text, filterText, filterOperation)); case FieldType.Select: int val = (int)value; if (val == -1) { return(false); } else { text = ((List <string>)field.Data)[(int)value]; return(Utils.CompareText(text, filterText, filterOperation)); } case FieldType.Reference: if (value is int) { return(false); } else { ObjectData d = (ObjectData)value; return(Utils.CompareText(d[SystemProperty.Name].ToString(), filterText, filterOperation)); } case FieldType.List: ListData l = (ListData)value; foreach (ObjectData od in l.Objects) { if (Utils.CompareText(od[SystemProperty.Name].ToString(), filterText, filterOperation)) { return(true); } } return(false); case FieldType.Boolean: text = (bool)value ? Strings.Yes : Strings.No; return(Utils.CompareText(text, filterText, filterOperation)); case FieldType.Table: TableData td = (TableData)value; foreach (Row row in td.Rows) { foreach (Cell cell in row.Cells) { if (Utils.CompareText(cell.Data.ToString(), filterText, filterOperation)) { return(true); } } } return(false); default: return(Utils.CompareText(value.ToString(), filterText, filterOperation)); } }
public object ConvertFromString(string fieldName, string value, IFormatProvider provider) { Field f = this.GetField(fieldName); if (!string.IsNullOrEmpty(value)) { switch (f.FieldType) { case FieldType.Text: return(value); case FieldType.Memo: return(value); case FieldType.Select: List <string> coll = (List <string>)f.Data; return(coll.IndexOf(value)); case FieldType.Number: return(provider == null?Convert.ToDecimal(value) : Convert.ToDecimal(value, provider)); case FieldType.List: string[] ls = value.Split(new char[] { ';' }); ListData ld = new ListData(); foreach (string s in ls) { bool created = false; ObjectData od = this.GetReferenceData(f, s, ref created); if (od != null) { ld.Objects.Add(od); } } return(ld); case FieldType.Boolean: return(provider == null?Convert.ToBoolean(value) : Convert.ToBoolean(value, provider)); case FieldType.Url: return(value); case FieldType.Date: return(provider == null?Convert.ToDateTime(value) : Convert.ToDateTime(value, provider)); case FieldType.Table: break; case FieldType.Image: break; case FieldType.Rating: return(provider == null?Convert.ToDecimal(value) : Convert.ToDecimal(value, provider)); case FieldType.Reference: if (this.ReferencedObjectData != null) { bool created = false; return(this.GetReferenceData(f, value, ref created)); } break; default: throw new Exception("Invalid value for FieldType"); } } return(f.GetStandardDefaultValue()); }