Пример #1
0
        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);
        }
Пример #2
0
        public bool Update(Domain.Attribute entity)
        {
            var result = true;

            using (UnitOfWork.Build(_attributeRepository.DbContext))
            {
                result = _attributeRepository.Update(entity);
                if (entity.OptionSetId.HasValue && entity.OptionSet != null && !entity.OptionSet.IsPublic)
                {
                    var details = _optionSetDetailFinder.Query(n => n.Select(f => f.OptionSetDetailId).Where(f => f.OptionSetId == entity.OptionSetId.Value));
                    foreach (var item in entity.OptionSet.Items)
                    {
                        if (item.OptionSetDetailId.Equals(Guid.Empty))
                        {
                            item.OptionSetDetailId = Guid.NewGuid();
                            result = _optionSetDetailCreater.Create(item);
                        }
                        else
                        {
                            result = _optionSetDetailUpdater.Update(item);
                        }
                    }
                    //delete lost
                    var ids    = entity.OptionSet.Items.Select(n => n.OptionSetDetailId);
                    var lostid = details.Select(n => n.OptionSetDetailId).Except(ids).ToList();
                    if (lostid.NotEmpty())
                    {
                        result = _optionSetDetailDeleter.DeleteById(lostid.ToArray());
                    }
                }
                if (entity.PickLists.NotEmpty())//bit
                {
                    foreach (var item in entity.PickLists)
                    {
                        if (item.StringMapId.Equals(Guid.Empty))
                        {
                            result = _stringMapCreater.Create(item);
                        }
                        else
                        {
                            result = _stringMapUpdater.Update(item);
                        }
                    }
                }
                //localization
                _localizedLabelService.Update(entity.LocalizedName.IfEmpty(""), "LocalizedName", entity.AttributeId, this._appContext.BaseLanguage);
                _localizedLabelService.Update(entity.Description.IfEmpty(""), "Description", entity.AttributeId, this._appContext.BaseLanguage);
                //set to cache
                var optionSetEntity = _optionSetFinder.FindById(entity.OptionSet.OptionSetId);
                _cacheService.SetEntity(entity);
                _cacheServiceOption.RemoveEntity(optionSetEntity);
            }
            return(result);
        }
Пример #3
0
        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());
            }
        }
Пример #4
0
        public IActionResult GetItems(Guid optionsetid)
        {
            var result = _optionSetDetailFinder.Query(n => n.Where(f => f.OptionSetId == optionsetid));

            return(JOk(result));
        }
Пример #5
0
        /// <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();
                        }
                    }
                }
            }
        }