public string Get(Guid entityId) { var dir = _webHelper.MapPath("~/excel/"); var entity = _entityFinder.FindById(entityId); var attributes = _attributeFinder.Query(n => n.Where(f => f.EntityId == entityId && f.AttributeTypeName != AttributeTypeIds.PRIMARYKEY && f.Name.NotIn("createdon", "createdby", "modifiedon", "modifiedby", "versionnumber", "owneridtype", "owningbusinessunit", "organizationid", "workflowid", "processstate", "stageid")).Sort(s => s.SortAscending(a => a.CreatedOn))); var filePath = dir + entity.Name + "_" + DateTime.Now.ToString("yyyyMMddhhmmss") + ".xls"; HSSFWorkbook book = new HSSFWorkbook(); ISheet sheet = book.CreateSheet(entity.LocalizedName); IRow headerRow = sheet.CreateRow(0); int columnIndex = 0; foreach (var attr in attributes) { ICell cell; ICellStyle style = book.CreateCellStyle(); if (attr.TypeIsPickList() || attr.TypeIsStatus()) { var options = _optionSetDetailServiceFinder.Query(n => n.Where(f => f.OptionSetId == attr.OptionSetId).Sort(s => s.SortAscending(f => f.DisplayOrder))); sheet.AddValidationData(book.CreateListConstraint(columnIndex, options.Select(f => f.Name))); } else if (attr.TypeIsBit() || attr.TypeIsState()) { var options = _stringMapFinder.Query(n => n.Where(f => f.AttributeId == attr.AttributeId).Sort(s => s.SortAscending(f => f.DisplayOrder))); sheet.AddValidationData(book.CreateListConstraint(columnIndex, options.Select(f => f.Name))); } else if (attr.TypeIsDateTime()) { sheet.AddValidationData(book.CreateDateConstraint(columnIndex)); } else if (attr.TypeIsDecimal() || attr.TypeIsMoney()) { sheet.AddValidationData(book.CreateNumericConstraint(columnIndex, attr.MinValue.ToString(), attr.MaxValue.ToString())); } else if (attr.TypeIsInt()) { sheet.AddValidationData(book.CreateNumericConstraint(columnIndex, attr.MinValue.ToString(), attr.MaxValue.ToString(), true)); } cell = headerRow.CreateCell(columnIndex); cell.SetCellValue(attr.LocalizedName); cell.CellStyle = style; columnIndex++; } using (MemoryStream ms = new MemoryStream()) { book.Write(ms); using (FileStream fs = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { byte[] data = ms.ToArray(); fs.Write(data, 0, data.Length); fs.Flush(); } book = null; } return(filePath); }
private void SetAttributeItems(Schema.Domain.Attribute attr) { if ((attr.TypeIsPickList() || attr.TypeIsStatus()))// && attr.OptionSet == null) { var os = _optionSetFinder.FindById(attr.OptionSetId.Value); attr.OptionSet = os; } else if ((attr.TypeIsBit() || attr.TypeIsState() ))// && attr.PickLists.IsEmpty()) { attr.PickLists = _stringMapFinder.Query(n => n.Where(w => w.AttributeId == attr.AttributeId).Sort(s => s.SortAscending(f => f.DisplayOrder))); } }
public IActionResult EditAttribute(Guid id) { if (id.Equals(Guid.Empty)) { return(NotFound()); } EditAttributeModel model = new EditAttributeModel(); var entity = _attributeFinder.FindById(id); if (entity == null) { return(NotFound()); } model.Entity = _entityFinder.FindById(entity.EntityId); if (model.Entity != null) { entity.CopyTo(model); if (entity.OptionSetId.HasValue) { entity.OptionSet = _optionSetFinder.FindById(entity.OptionSetId.Value); entity.OptionSet.Items = _optionSetDetailFinder.Query(n => n.Where(w => w.OptionSetId == entity.OptionSetId.Value).Sort(s => s.SortAscending(f => f.DisplayOrder))); model.IsCommonOptionSet = entity.OptionSet.IsPublic; } if (entity.TypeIsBit() || entity.TypeIsState()) { entity.PickLists = _stringMapFinder.Query(n => n.Where(w => w.AttributeId == entity.AttributeId)); } model.Attribute = entity; if (model.SummaryExpression.IsNotEmpty()) { model.AaExp = new AttributeAggregateExpression().DeserializeFromJson(model.SummaryExpression); } else { model.AaExp = new AttributeAggregateExpression(); } return(View(model)); } else { return(NotFound()); } }
/// <summary> /// 过滤条件对话框 /// </summary> /// <returns></returns> public IActionResult FilterDialog([FromBody] FilterModel model, DialogModel dm) { ViewData["DialogModel"] = dm; if (model.Field.IsNotEmpty()) { //如果是关联表字段 if (model.Field.IndexOf('.') > 0) { var relationshipName = model.Field.Split('.')[0]; var field = model.Field.Split('.')[1]; //根据关系查询目标实体ID var relationship = _relationShipFinder.FindByName(relationshipName); model.AttributeMeta = _attributeFinder.Find(relationship.ReferencedEntityId, field); model.RelationShipMeta = relationship; } else { model.AttributeMeta = _attributeFinder.Find(model.EntityId, model.Field); } if (model.AttributeMeta == null) { return(NotFound()); } if (model.AttributeMeta.AttributeTypeName.IsCaseInsensitiveEqual(AttributeTypeIds.PICKLIST)) { model.AttributeMeta.OptionSet = _optionSetFinder.FindById(model.AttributeMeta.OptionSetId.Value); } if (model.AttributeMeta.AttributeTypeName.IsCaseInsensitiveEqual(AttributeTypeIds.BIT) || model.AttributeMeta.AttributeTypeName.IsCaseInsensitiveEqual(AttributeTypeIds.STATE)) { model.AttributeMeta.PickLists = _stringMapFinder.Query(n => n.Where(w => w.AttributeId == model.AttributeMeta.AttributeId)); } } return(View(model)); }
/// <summary> /// 获取关联的实体及字段元数据 /// </summary> private void GetMetaData(QueryBase query, bool getEntities, bool getAttributes, bool getRelationShips) { //保存主实体 if (getEntities) { _entityList = new List <Schema.Domain.Entity> { _entityFinder.FindByName(query.EntityName) }; } //获取实体所有字段 if (getAttributes) { var entityAttributes = _attributeFinder.FindByEntityName(query.EntityName); _attributeList = new List <Schema.Domain.Attribute>(); if (query is QueryExpression) { var queryExp = query as QueryExpression; if (!queryExp.ColumnSet.AllColumns && queryExp.ColumnSet.Columns.NotEmpty()) { _attributeList.AddRange(entityAttributes.Where(x => queryExp.ColumnSet.Columns.Contains(x.Name, StringComparer.InvariantCultureIgnoreCase) || (x.IsPrimaryField || x.TypeIsPrimaryKey()))); } else { _attributeList = entityAttributes; } } else if (query is QueryByAttribute) { var queryExp = query as QueryByAttribute; if (!queryExp.ColumnSet.AllColumns && queryExp.ColumnSet.Columns.NotEmpty()) { _attributeList.AddRange(entityAttributes.Where(x => queryExp.ColumnSet.Columns.Contains(x.Name, StringComparer.InvariantCultureIgnoreCase) || (x.IsPrimaryField || x.TypeIsPrimaryKey()))); } else { _attributeList = entityAttributes; } } } //link entities if (query is QueryExpression) { var queryExp = query as QueryExpression; foreach (var le in queryExp.LinkEntities) { GetLinkMetaData(le, getEntities, getAttributes, getRelationShips); } } if (getAttributes) { //attribute options foreach (var attr in _attributeList) { if (attr.TypeIsPickList() || attr.TypeIsStatus()) { if (attr.OptionSet == null) { var options = _optionSetDetailFinder.Query(x => x.Where(f => f.OptionSetId == attr.OptionSetId.Value).Sort(s => s.SortAscending(f => f.DisplayOrder))); attr.OptionSet = new OptionSet(); attr.OptionSet.Items = options?.ToList(); } } else if (attr.TypeIsState() || attr.TypeIsBit()) { if (attr.PickLists == null) { attr.PickLists = _stringMapFinder.Query(x => x.Where(f => f.AttributeId == attr.AttributeId).Sort(s => s.SortAscending(f => f.DisplayOrder)))?.ToList(); } } } } }
public IActionResult Get(Guid attributeId) { var result = _stringMapFinder.Query(n => n.Where(f => f.AttributeId == attributeId)); return(JOk(result)); }
private ConditionExpression GetCondition(Schema.Domain.Attribute attr, object keyword, string entityAlias = "") { //数字类型 if (keyword.ToString().IsNumeric() && (attr.TypeIsInt() || attr.TypeIsFloat() || attr.TypeIsDecimal() || attr.TypeIsMoney() || attr.TypeIsSmallMoney() || attr.TypeIsSmallInt() )) { return(new ConditionExpression(GetSearchName(attr, entityAlias), GetConditionOperator(attr), keyword)); } //日期类型 else if ((attr.TypeIsDateTime() || attr.TypeIsSmallDateTime() )) { if (DateTime.TryParse(keyword.ToString(), out DateTime d)) { return(new ConditionExpression(GetSearchName(attr, entityAlias), GetConditionOperator(attr), keyword)); } } //guid类型 else if (attr.TypeIsPrimaryKey() || attr.TypeIsLookUp() || attr.TypeIsOwner() || attr.TypeIsCustomer()) { if (keyword.ToString().IsGuid()) { return(new ConditionExpression(attr.Name, GetConditionOperator(attr), keyword)); } return(new ConditionExpression(GetSearchName(attr, entityAlias), ConditionOperator.Like, keyword)); } //选项类型 else if ((attr.TypeIsState() || attr.TypeIsBit() || attr.TypeIsPickList() || attr.TypeIsStatus())) { if (keyword.ToString().IsInteger())//如果是数值 { return(new ConditionExpression(entityAlias.IsEmpty() ? attr.Name : entityAlias + "." + attr.Name, GetConditionOperator(attr), keyword)); } else { //按名称查找选项值 //... if (attr.TypeIsState() || attr.TypeIsBit()) { if (attr.PickLists.IsEmpty()) { attr.PickLists = _stringMapFinder.Query(n => n.Where(f => f.AttributeId == attr.AttributeId)); } var value = attr.PickLists.Find(n => n.Name.IsCaseInsensitiveEqual(keyword.ToString())); if (null != value) { keyword = value.Value; } } else if (attr.TypeIsPickList() || attr.TypeIsStatus()) { if (attr.OptionSet == null) { attr.OptionSet = new OptionSet();//_optionSetFinder.FindById(attr.OptionSetId.Value); } var value = attr.OptionSet.Items.Find(n => n.Name.IsCaseInsensitiveEqual(keyword.ToString())); if (null != value) { keyword = value.Value; } } } //if (keyword.ToString().IsInteger()) //{ // return new ConditionExpression(attr.Name, ConditionOperator.Equal, keyword); //} } //字符串类型 else if ((attr.TypeIsNvarchar() || attr.TypeIsVarchar() || attr.TypeIsChar())) { return(new ConditionExpression(GetSearchName(attr, entityAlias), GetConditionOperator(attr), keyword)); } return(null); }