コード例 #1
0
ファイル: BusinessController.cs プロジェクト: ljxu1/DWKit
        public ActionResult GetEntityCaptionAttribute(string metaviewName)
        {
            DynamicEntityRepository repo     = new DynamicEntityRepository();
            EntityMetadata          metadata = repo.GetEntityMetadataByEntityName(metaviewName);

            string caption = metadata != null?OptimaJet.BJet.CommonMethods.GetEntityCaptionAttribute(metadata).PropertyName : String.Empty;

            return(Content(ServiceStack.Text.JsonSerializer.SerializeToString(caption)));
        }
コード例 #2
0
ファイル: Sync.cs プロジェクト: ljxu1/DWKit
        public static void CheckRecords(string viewName, List <dynamic> records, Dictionary <string, object> syncParams, List <string> excludeProperties = null)
        {
            if (records == null || records.Count == 0)
            {
                return;
            }

            var budgetProperties = new List <string>()
            {
                "BudgetVersionId", "BudgetId"
            };

            var d        = new DynamicEntityRepository();
            var metadata = d.GetEntityMetadataByViewName(viewName, VisibilitySettings.Empty);

            var replaceIds = new Dictionary <object, object>();

            foreach (dynamic record in records)
            {
                foreach (PlainAttributeDescription att in metadata.PlainAttributes)
                {
                    if ((excludeProperties != null && excludeProperties.Contains(att.PropertyName)) || budgetProperties.Contains(att.PropertyName))
                    {
                        continue;
                    }

                    if (string.IsNullOrWhiteSpace(att.ViewNameForSelect))
                    {
                        continue;
                    }

                    var joinedMd = d.GetEntityMetadataByViewName(att.ViewNameForSelect, VisibilitySettings.Empty);
                    if (!joinedMd.Attributes.Any(c => budgetProperties.Contains(c.PropertyName)))
                    {
                        continue;
                    }

                    var deRecord = (DynamicEntity)record;
                    var oldId    = deRecord[att.PropertyName];

                    if (oldId == null)
                    {
                        continue;
                    }

                    deRecord[att.PropertyName] = replaceIds.ContainsKey(oldId) ?
                                                 replaceIds[oldId] :
                                                 GetSyncRecordId(oldId, joinedMd, syncParams);

                    if (!replaceIds.ContainsKey(oldId))
                    {
                        replaceIds.Add(oldId, deRecord[att.PropertyName]);
                    }
                }
            }
        }
コード例 #3
0
ファイル: Sync.cs プロジェクト: dmelnikov/DWKit
        public static void CheckRecords(string viewName, List<dynamic> records, Dictionary<string, object> syncParams,List<string> excludeProperties = null)
        {
            if (records == null || records.Count == 0)
                return;

            var budgetProperties = new List<string>() { "BudgetVersionId", "BudgetId" };

            var d = new DynamicEntityRepository();
            var metadata = d.GetEntityMetadataByViewName(viewName, VisibilitySettings.Empty);

            var replaceIds = new Dictionary<object, object>();

            foreach (dynamic record in records)
            {
                foreach (PlainAttributeDescription att in metadata.PlainAttributes)
                {
                    if ((excludeProperties != null && excludeProperties.Contains(att.PropertyName)) || budgetProperties.Contains(att.PropertyName))
                        continue;

                    if (string.IsNullOrWhiteSpace(att.ViewNameForSelect))
                        continue;

                    var joinedMd = d.GetEntityMetadataByViewName(att.ViewNameForSelect, VisibilitySettings.Empty);
                    if (!joinedMd.Attributes.Any(c => budgetProperties.Contains(c.PropertyName)))
                    {
                        continue;
                    }

                    var deRecord = (DynamicEntity)record;
                    var oldId = deRecord[att.PropertyName];

                    if (oldId == null)
                        continue;

                    deRecord[att.PropertyName] = replaceIds.ContainsKey(oldId) ?
                        replaceIds[oldId] :
                        GetSyncRecordId(oldId, joinedMd, syncParams);

                    if (!replaceIds.ContainsKey(oldId))
                        replaceIds.Add(oldId, deRecord[att.PropertyName]);
                }
            }
        }
コード例 #4
0
        public static List <Tuple <Guid, string, List <Tuple <Guid, string> > > > GetDependingEntityAccess(string metaviewName, Guid[] ids, int deep = 1)
        {
            DynamicEntityRepository           repo     = new DynamicEntityRepository();
            EntityMetadata                    metadata = repo.GetEntityMetadataByEntityName(metaviewName);
            List <Guid>                       dependingEntityMetadataIds = MetadataRepositoty.GetDependingEntityIds(new TableDescription(metadata.SchemaName, metadata.TableName));
            Dictionary <Guid, EntityMetadata> dependingMetadata          = dependingEntityMetadataIds.Select(id => new KeyValuePair <Guid, EntityMetadata>(id, repo.GetEntityMetadataByEntityId(id)))
                                                                           .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            var dependingEntities = new List <Tuple <Guid, string, List <Tuple <Guid, string> > > >();

            foreach (var entityMetadata in dependingMetadata)
            {
                FilterCriteriaSet    filters = FilterCriteriaSet.Empty;
                AttributeDescription entityCaptionAttribute = OptimaJet.BJet.CommonMethods.GetEntityCaptionAttribute(entityMetadata.Value);

                List <FilterCriteriaSet> filterSets = entityMetadata.Value.PlainAttributes.Where(a => a.IsReference && a.ReferencedSchemaName == metadata.SchemaName && a.ReferencedTableName == metadata.TableName)
                                                      .Select(a => FilterCriteriaSet.And.In(ids.ToList(), entityMetadata.Value.GetColumn(a))).ToList();

                filterSets.ForEach(f => filters = filters != FilterCriteriaSet.Empty ? filters.Merge(f) : f);

                var entities = repo.GetEntitiesByMetadata(entityMetadata.Value, filters).Entities;
                if (entities == null || entities.Count() == 0)
                {
                    continue;
                }

                var dependingEntity = new Tuple <Guid, string, List <Tuple <Guid, string> > >(
                    entityMetadata.Key,
                    entityMetadata.Value.TableName,
                    new List <Tuple <Guid, string> >(entities.Select(e =>
                                                                     new Tuple <Guid, string>((Guid)e.Id, e.GetProperty(entityCaptionAttribute.PropertyName).ToString())
                                                                     ).ToList()));
                dependingEntities.Add(dependingEntity);

                if (deep > 0)
                {
                    dependingEntities.AddRange(GetDependingEntityAccess(dependingEntity.Item2, dependingEntity.Item3.Select(t => t.Item1).ToArray(), deep - 1));
                }
            }
            return(dependingEntities);
        }
コード例 #5
0
ファイル: EntityAccess.cs プロジェクト: dmelnikov/DWKit
        public static List<Tuple<Guid, string, List<Tuple<Guid, string>>>> GetDependingEntityAccess(string metaviewName, Guid[] ids, int deep = 1)
        {
            DynamicEntityRepository repo = new DynamicEntityRepository();
            EntityMetadata metadata = repo.GetEntityMetadataByEntityName(metaviewName);
            List<Guid> dependingEntityMetadataIds = MetadataRepositoty.GetDependingEntityIds(new TableDescription(metadata.SchemaName, metadata.TableName));
            Dictionary<Guid, EntityMetadata> dependingMetadata = dependingEntityMetadataIds.Select(id => new KeyValuePair<Guid, EntityMetadata>(id, repo.GetEntityMetadataByEntityId(id)))
                .ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

            var dependingEntities = new List<Tuple<Guid, string, List<Tuple<Guid, string>>>>();

            foreach (var entityMetadata in dependingMetadata)
            {
                FilterCriteriaSet filters = FilterCriteriaSet.Empty;
                AttributeDescription entityCaptionAttribute = OptimaJet.BJet.CommonMethods.GetEntityCaptionAttribute(entityMetadata.Value);

                List<FilterCriteriaSet> filterSets = entityMetadata.Value.PlainAttributes.Where(a => a.IsReference && a.ReferencedSchemaName == metadata.SchemaName && a.ReferencedTableName == metadata.TableName)
                    .Select(a => FilterCriteriaSet.And.In(ids.ToList(), entityMetadata.Value.GetColumn(a))).ToList();

                filterSets.ForEach(f => filters = filters != FilterCriteriaSet.Empty ? filters.Merge(f) : f);

                var entities = repo.GetEntitiesByMetadata(entityMetadata.Value, filters).Entities;
                if (entities == null || entities.Count() == 0)
                    continue;

                var dependingEntity = new Tuple<Guid, string, List<Tuple<Guid, string>>>(
                    entityMetadata.Key,
                    entityMetadata.Value.TableName,
                    new List<Tuple<Guid, string>>(entities.Select(e =>
                        new Tuple<Guid, string>((Guid)e.Id, e.GetProperty(entityCaptionAttribute.PropertyName).ToString())
                        ).ToList()));
                dependingEntities.Add(dependingEntity);

                if (deep > 0)
                    dependingEntities.AddRange(GetDependingEntityAccess(dependingEntity.Item2, dependingEntity.Item3.Select(t => t.Item1).ToArray(), deep - 1));
            }
            return dependingEntities;
        }
コード例 #6
0
ファイル: BudgetItem.cs プロジェクト: dmelnikov/DWKit
        public static void CopyToNewBudgetVersion(object newBudgetId, object oldBudgetId, Dictionary<string, Dictionary<object, object>> replacesByTable)
        {
            var replaceIds = new Dictionary<object, object>();
            var changedDate = DateTime.Now;
            var repository = new DynamicEntityRepository();

            var newVersion = DynamicRepository.GetByEntity("BudgetVersion",
                FilterCriteriaSet.And.Equal(newBudgetId, "BudgetId")
                    .Merge(FilterCriteriaSet.And.Equal(true, "IsCurrent"))).FirstOrDefault();

            var oldVersion = DynamicRepository.GetByEntity("BudgetVersion",
                FilterCriteriaSet.And.Equal(oldBudgetId, "BudgetId")
                    .Merge(FilterCriteriaSet.And.Equal(true, "IsCurrent"))).FirstOrDefault();

            var newBudget = DynamicRepository.GetByEntity("Budget",
                FilterCriteriaSet.And.Equal(newBudgetId, "Id")).FirstOrDefault();

            bool internalTransaction = false;

            if (SharedCommunicationObjects.SharedTransaction == null)
            {
                SharedCommunicationObjects.CreateSharedTransaction();
                internalTransaction = true;
            }

            try
            {
                #region BudgetItems

                var biMetadata = repository.GetEntityMetadataByEntityName("BudgetItem");

                List<dynamic> records =
                    biMetadata.Get(
                        FilterCriteriaSet.And.Equal((Guid) oldVersion.Id, "BudgetVersionId")
                            .NotEqual(true, "IsDeleted")
                            .NotEqual("Deleted", "State")
                            .NotEqual(true, "IsPrevPeriod"));

                foreach (dynamic r in records)
                {
                    var oldId = r.Id;
                    r.Id = Guid.NewGuid();
                    r.BudgetVersionId = newVersion.Id;
                    r.WasBack = false;
                    r.State = "Draft";
                    r.StateName = "Draft";
                    r.EntityRouteId = null;
                    r.ChangedDate = changedDate;

                    //Заменяем ссылки на скопированные в новый бюджет справочники

                    ReplaceToNewIds(replacesByTable, biMetadata, r);

                    replaceIds.Add(oldId, r.Id);
                }

                var dynamicEntities = records.ConvertAll(d=> d as DynamicEntity);

                PrimaryKeyGenerator.SPGenerateKey(biMetadata, dynamicEntities,
                    new Dictionary<string, string>
                    {
                        {"StoredProcedure", "data_get_sequence"},
                        {"ColumnName", "NumberId"},
                        {"Value", "Value"},
                        {"Code", "BudgetItem"}
                    });

                //Перерасчет остатков
                //BudgetItemMethods.InitResidual(biMetadata, null, dynamicEntities);
                DWKitHelper.EMExecute("BudgetItem.InitResidual", biMetadata, null, dynamicEntities);

                DynamicRepository.InsertByEntity("BudgetItem", records);

                #endregion

                //Словарь со всеми заменами Id-ов
                var allReplaces = replacesByTable.Select(replaces => replaces.Value).ToList();
                allReplaces.Add(replaceIds);

                #region Depends
                var tableList = new Dictionary<string, string>
                {
                    {"BudgetItemAllocation", "BudgetItemId"}
                };

                var b = new Budget();
                foreach (var t in tableList)
                {
                    var replaceByPropertyName = new Dictionary<string, Dictionary<object, object>> { { t.Value, replaceIds } };

                    var tMetadata = repository.GetEntityMetadataByEntityName(t.Key);

                    foreach (var att in tMetadata.PlainAttributes.Where(a=>a.IsReference))
                    {
                        if (!replacesByTable.ContainsKey(att.ReferencedTableName))
                            continue;

                        var replace = replacesByTable[att.ReferencedTableName];

                        replaceByPropertyName.Add(att.PropertyName, replace);
                    }

                    var tmpFilter = FilterCriteriaSet.And.Custom(string.Format("{0} in (select Id from BudgetItem WHERE BudgetVersionId = '{1}')", t.Value, (Guid)oldVersion.Id));
                    var replaces = b.CopyDependsEntity(t.Key, (t.Value == "Id" ? null : "Id"), tmpFilter,
                        replaceByPropertyName, true);

                    allReplaces.Add(replaces);

                }
                #endregion

                #region UploadedFiles
                CopyUploadedFiles(replaceIds);
                #endregion

                #region EntityAccess

                //Все замены в один словарь
                var allReplacesDictionary = allReplaces.SelectMany(dict => dict)
                         .ToDictionary(pair => pair.Key, pair => pair.Value);

                CopyEntityAccess(oldVersion, newVersion, allReplacesDictionary);
                #endregion

                #region Created PrevPeriod BudgetItems

                var biIdsForReclc = BudgetItem.SyncFutureBudgetItem((int)newBudget.Name, replaceIds);
                VtbRestCalculator.Calc.RecalculateAccount(biIdsForReclc, newBudget.Id);

                #endregion

                if (internalTransaction)
                    SharedCommunicationObjects.CommitSharedTransaction();
            }
            catch (Exception ex)
            {
                if (internalTransaction)
                    SharedCommunicationObjects.RollbackSharedTransaction();
                throw ex;
            }
            finally
            {
                if (internalTransaction)
                    SharedCommunicationObjects.DestroySharedTransaction();
            }
        }
コード例 #7
0
ファイル: BudgetItem.cs プロジェクト: dmelnikov/DWKit
        private static void CopyEntityAccess(dynamic currentBudgetVersion, dynamic newBudgetVersion, Dictionary<object, object> replaceIds)
        {
            var repository = new DynamicEntityRepository();

            var entityAccess = DynamicRepository.GetByEntity("EntityAccess",
                FilterCriteriaSet.And.Equal((Guid) currentBudgetVersion.Id, "BudgetVersionId"));

            foreach (dynamic ea in entityAccess)
            {
                var oldId = ea.Id;
                ea.Id = Guid.NewGuid();
                ea.BudgetVersionId = newBudgetVersion.Id;
                replaceIds.Add(oldId, ea.Id);
                DynamicRepository.InsertByEntity("EntityAccess", new List<dynamic>() {ea});

                CopyEntityAccessChilds("EntityAccessOrganizationalStructure", replaceIds, oldId, ea.Id);
                CopyEntityAccessChilds("EntityAccessEmployee", replaceIds, oldId, ea.Id);
                Dictionary<Guid, dynamic> entityAccessItems = CopyEntityAccessChilds("EntityAccessItem", replaceIds, oldId,
                    ea.Id);
                if (entityAccessItems != null && entityAccessItems.Count > 0)
                {
                    foreach (KeyValuePair<Guid, dynamic> entityAccessItem in entityAccessItems)
                    {
                        List<dynamic> entityAccessItemEntities = DynamicRepository.GetByEntity("EntityAccessItemEntity",
                            FilterCriteriaSet.And.Equal(entityAccessItem.Key, "EntityAccessItemId"));
                        if (entityAccessItemEntities != null && entityAccessItemEntities.Count > 0)
                        {
                            foreach (dynamic entityAccessItemEntity in entityAccessItemEntities)
                            {
                                var old_id = entityAccessItemEntity.Id;
                                entityAccessItemEntity.Id = Guid.NewGuid();
                                entityAccessItemEntity.EntityAccessItemId = entityAccessItem.Value.Id;
                                object newEntityId = null;
                                if (replaceIds.TryGetValue(entityAccessItemEntity.EntityId, out newEntityId))
                                {
                                    EntityMetadata metadata =
                                        repository.GetEntityMetadataByEntityId(entityAccessItem.Value.MetadataEntityId);
                                    var captionProperty = CommonMethods.GetEntityCaptionAttribute(metadata).PropertyName;
                                    var entity = metadata.Get(FilterCriteriaSet.And.Equal(newEntityId,
                                        metadata.PrimaryKeyPropertyName)).FirstOrDefault() as DynamicEntity;
                                    entityAccessItemEntity.EntityId = newEntityId;
                                    if (entity != null)
                                        entityAccessItemEntity.AccessEntityCaption =
                                            entity.GetProperty(captionProperty).ToString();
                                }

                                replaceIds.Add(old_id, entityAccessItemEntity.Id);
                            }
                            DynamicRepository.InsertByEntity("EntityAccessItemEntity", entityAccessItemEntities);
                        }
                    }
                }
            }
        }
コード例 #8
0
ファイル: BusinessController.cs プロジェクト: dmelnikov/DWKit
        public ActionResult GetEntityCaptionAttribute(string metaviewName)
        {
            DynamicEntityRepository repo = new DynamicEntityRepository();
            EntityMetadata metadata = repo.GetEntityMetadataByEntityName(metaviewName);

            string caption = metadata != null ? OptimaJet.BJet.CommonMethods.GetEntityCaptionAttribute(metadata).PropertyName : String.Empty;
            return Content(ServiceStack.Text.JsonSerializer.SerializeToString(caption));
        }
コード例 #9
0
ファイル: FXRateImporter.cs プロジェクト: ljxu1/DWKit
        private static EntityContainer GetCurrencies()
        {
            DynamicEntityRepository rep = new DynamicEntityRepository();

            return(rep.GetEntitiesByMetadata(rep.GetEntityMetadataByEntityName("Currency"), FilterCriteriaSet.Empty));
        }
コード例 #10
0
ファイル: FXRateImporter.cs プロジェクト: dmelnikov/DWKit
 private static EntityContainer GetCurrencies()
 {
     DynamicEntityRepository rep = new DynamicEntityRepository();
     return rep.GetEntitiesByMetadata(rep.GetEntityMetadataByEntityName("Currency"), FilterCriteriaSet.Empty);
 }