private string GetOrderField(MemberExpression expression) { EntityMemberPath entityMemberPath = DataReflection.GetEntityMemberPath(expression); //object property3; if (expression.Member is FieldInfo) { var fieldInfo = (FieldInfo)(expression.Member); return(GetWhere(expression.Expression)); } else { var property = (PropertyInfo)(expression.Member); var field = DataReflection.GetEntityFieldInfo(property); if (field != null) { return($" `{entityMemberPath.GetPath()}`.`{field.Attribute.FieldName}` "); } else { bool isMemeberExpression = expression.Expression is MemberExpression; bool isParameterExpression = expression.Expression is ParameterExpression; bool isUnaryExpression = expression.Expression is UnaryExpression; if (expression.Expression is MemberExpression) { var memberExpression = expression.Expression as MemberExpression; return(GetWhereField(memberExpression)); } else if (expression.Expression is ParameterExpression) { if (property.Name == "Id") { var parameterExpression = expression.Expression as ParameterExpression; Type entityType = parameterExpression.Type; var entityInfo = DataReflection.GetEntityInfo(entityType); return($" `{entityMemberPath.GetPath()}`.{entityInfo.Attribute.FieldPrimaryKey} "); } else { var joinEntityInfo = DataReflection.GetEntityInfo(property.PropertyType); return($" `{entityMemberPath.GetPath()}`.{joinEntityInfo.Attribute.FieldPrimaryKey} "); } } else if (expression.Expression is UnaryExpression) { return(GetWhereValue(expression.Expression as UnaryExpression)); } else { return(" "); } } } }
public ReportField(EntityMemberPath fields) { if (fields == null) { throw new ArgumentNullException(nameof(fields)); } Fields = fields; }
private void AddReportField(EntityMemberPath path) { var item = new ListViewItem(HumanText.GetMemberName(path.Tail)) { Tag = path }; InsertSorted(_reportFields, item, true); }
public static ReportDefinition Load(Api api, string fileName) { if (api == null) { throw new ArgumentNullException(nameof(api)); } if (fileName == null) { throw new ArgumentNullException(nameof(fileName)); } var doc = XDocument.Load(fileName); if (doc.Root.Name != Ns + "report") { throw new ArgumentException("Invalid report"); } var root = doc.Root; var result = new ReportDefinition(); result.Entity = api.GetEntitySchema(root.Attribute("entity").Value); var filters = root.Element(Ns + "filters"); if (filters != null) { result.Filters.AddRange(FormatUtil.DeserializeFilters(result.Entity, filters)); } var fields = root.Element(Ns + "fields"); if (fields != null) { foreach (var field in fields.Elements(Ns + "field")) { var fieldPath = EntityMemberPath.Parse(api, result.Entity, field.Attribute("path").Value); if (fieldPath == null) { continue; } var reportField = new ReportField(fieldPath); reportField.Type = (ReportFieldType)Enum.Parse(typeof(ReportFieldType), field.Attribute("type").Value, true); reportField.Transform = (ReportFieldTransform)Enum.Parse(typeof(ReportFieldTransform), field.Attribute("transform").Value, true); result.Fields.Add(reportField); } } return(result); }
private object GetValue(EntityMemberPath field, JToken entity) { JToken result = entity; for (int i = 0; i < field.Count; i++) { result = ((JObject)result)[field[i].Name]; if (result.Type == JTokenType.Null) { return(null); } } return(((JValue)result).Value); }
private void SetSelectedEntity(EntityMemberPath path) { if (path.Count == 0) { _selectedEntity = _entity; _path.Text = HumanText.GetEntityName(_selectedEntity); } else { _selectedEntity = _api.GetEntitySchema(((EntityForeign)path.Tail).LinkTable); _path.Text = HumanText.GetEntityMemberPath(path); } _availableFields.BeginUpdate(); _availableFields.Items.Clear(); foreach (var member in _selectedEntity.Members.OrderBy(HumanText.GetMemberName)) { var memberPath = new EntityMemberPath(path, member); if ( (member is EntityField || member is EntityCalculatedField) && _reportFields.Items.Cast <ListViewItem>().All(p => !p.Tag.Equals(memberPath)) ) { _availableFields.Items.Add(new ListViewItem(HumanText.GetMemberName(member)) { Tag = memberPath }); } } _availableFields.EndUpdate(); UpdateEnabled(); if (_autoCompleteForm != null) { _autoCompleteForm.Dispose(); _autoCompleteForm = null; } }
private string BuildExpand() { var expands = new HashSet <string>(); foreach (var field in BuildExport().Fields) { string path = new EntityMemberPath(field.Take(field.Count - 1)).ToString(); if (path.Length > 0) { expands.Add(path); } } if (expands.Count == 0) { return(null); } return(String.Join(",", expands)); }
public static string GetEntityMemberPath(EntityMemberPath path) { if (path == null) { throw new ArgumentNullException(nameof(path)); } var sb = new StringBuilder(); for (int i = 0; i < path.Count; i++) { if (i > 0) { sb.Append(" » "); } sb.Append(GetMemberName(path[i])); } return(sb.ToString()); }