Ejemplo n.º 1
0
 public Operation CreateClearOperation(EntityDTO masterEntity, ClearDependenceInfo depend, IList<EntityDTO> dependEntities)
 {
     return new SQLCleanOperation () {
         ItemId = masterEntity.Id,
         TableName = TableName,
         CleanField = depend.ClearField,
         WhereStatment = depend.WhereStatment
     };
 }
Ejemplo n.º 2
0
 public Operation CreateDeleteOperation(EntityDTO masterEntity, DeleteDependenceInfo depend, IList<EntityDTO> dependEntities)
 {
     return new SQLDeleteOperation {
         ItemId = masterEntity.Id,
         TableName = TableName,
         WhereStatment = depend.WhereStatment
     };
 }
Ejemplo n.º 3
0
 public IList<EntityDTO> GetDependEntities(DeleteCore core, ClearDependenceInfo depend, EntityDTO masterEntity)
 {
     return GetEntitiesList(depend.WhereStatment, masterEntity.Id);
 }
Ejemplo n.º 4
0
 public IList<EntityDTO> GetDependEntities(DeleteCore core, RemoveFromDependenceInfo depend, EntityDTO masterEntity)
 {
     throw new NotImplementedException ();
 }
Ejemplo n.º 5
0
 public Operation CreateDeleteOperation(EntityDTO entity)
 {
     return new SQLDeleteOperation {
         ItemId = entity.Id,
         TableName = TableName,
         WhereStatment = "WHERE id = @id"
     };
 }
Ejemplo n.º 6
0
 public Operation CreateRemoveFromOperation(EntityDTO masterEntity, RemoveFromDependenceInfo depend, IList<EntityDTO> dependEntities)
 {
     throw new NotSupportedException ();
 }
Ejemplo n.º 7
0
        private int FillRemoveFromItemsOperation(IDeleteInfo currentDeletion, Operation parentOperation, TreeIter parentIter, EntityDTO masterEntity, ref int totalCount)
        {
            int removeCount = 0;
            foreach (var removeDepend in currentDeletion.RemoveFromItems) {
                int groupCount = 0;
                var childClassInfo = removeDepend.GetClassInfo();
                if (childClassInfo == null)
                    throw new InvalidOperationException (String.Format ("Зависимость удаления класса {0} ссылается на коллекцию {2} в классе {1} для которого нет описания.",
                        currentDeletion.ObjectClass,
                        removeDepend.ObjectClass,
                        removeDepend.CollectionName));

                var childList = childClassInfo.GetDependEntities (this, removeDepend, masterEntity);

                if (childList.Count == 0)
                    continue;

                TreeIter GroupIter = ObjectsTreeStore.AppendNode (parentIter);

                var removeOper = childClassInfo.CreateRemoveFromOperation (masterEntity, removeDepend, childList);
                parentOperation.ChildBeforeOperations.Add (removeOper);

                foreach (var row in childList) {
                    ObjectsTreeStore.AppendValues (GroupIter, row.Title);
                    groupCount++;
                    totalCount++;
                    removeCount++;
                }

                CheckDlg.AddLinksCount(groupCount);
                if (CheckDlg.IsCanceled)
                    return 0;

                var classNames = DomainHelper.GetSubjectNames (childClassInfo.ObjectClass);

                ObjectsTreeStore.SetValues (GroupIter, String.Format ("{2} в {0}({1})",
                    classNames.PrepositionalPlural ?? classNames.NominativePlural,
                    groupCount,
                    DomainHelper.GetPropertyTitle (removeDepend.ObjectClass, removeDepend.CollectionName)
                ));
            }
            return removeCount;
        }
Ejemplo n.º 8
0
        private int FillDeleteItemsOperation(IDeleteInfo currentDeletion, Operation parentOperation, TreeIter parentIter, EntityDTO masterEntity, ref int totalCount)
        {
            int deleteCount = 0;
            foreach (var delDepend in currentDeletion.DeleteItems) {
                int GroupCount = 0;
                var childClassInfo = delDepend.GetClassInfo();
                if (childClassInfo == null)
                    throw new InvalidOperationException (String.Format ("Зависимость удаления у класса(таблицы) {0}({1}) ссылается на класс(таблицу) {2}({3}) для которого нет описания.",
                        currentDeletion.ObjectClass,
                        currentDeletion is DeleteInfo ? (currentDeletion as DeleteInfo).TableName : String.Empty,
                        delDepend.ObjectClass,
                        delDepend.TableName));

                var childList = childClassInfo.GetDependEntities(this, delDepend, masterEntity).ToList();

                if (childList.Count == 0)
                    continue;

                foreach(var chk in DeletedItems.Where(x => x.ItemClass == childClassInfo.ObjectClass))
                {
                    childList.RemoveAll(e => e.Id == chk.ItemId);
                }

                if (childList.Count == 0)
                    continue;

                TreeIter GroupIter = ObjectsTreeStore.AppendNode (parentIter);

                var delOper = childClassInfo.CreateDeleteOperation (masterEntity, delDepend, childList);
                if(delDepend.IsCascade)
                    parentOperation.ChildAfterOperations.Add (delOper);
                else
                    parentOperation.ChildBeforeOperations.Add (delOper);

                foreach (var row in childList) {
                    TreeIter ItemIter = ObjectsTreeStore.AppendValues (GroupIter, row.Title);
                    DeletedItems.Add (new DeletedItem {
                        ItemClass = childClassInfo.ObjectClass,
                        ItemId = row.Id,
                        Title = row.Title
                    });

                    totalCount += FillChildOperation (childClassInfo, delOper, ItemIter, row);

                    if (CheckDlg.IsCanceled)
                        return 0;

                    GroupCount++;
                    totalCount++;
                    deleteCount++;
                }

                CheckDlg.AddLinksCount(GroupCount);

                ObjectsTreeStore.SetValues (GroupIter, String.Format ("{0}({1})", StringWorks.StringToTitleCase (childClassInfo.ObjectsName), GroupCount));
            }
            return deleteCount;
        }
Ejemplo n.º 9
0
        private int FillCleanItemsOperation(IDeleteInfo currentDeletion, Operation parentOperation, TreeIter parentIter, EntityDTO masterEntity, ref int totalCount)
        {
            int clearCount = 0;
            foreach (var cleanDepend in currentDeletion.ClearItems) {
                int groupCount = 0;
                var childClassInfo = cleanDepend.GetClassInfo();
                if (childClassInfo == null)
                    throw new InvalidOperationException (String.Format ("Зависимость очистки у класса {0} ссылается на класс {1} для которого нет описания.", currentDeletion.ObjectClass, cleanDepend.ObjectClass));

                var childList = childClassInfo.GetDependEntities (this, cleanDepend, masterEntity);

                if (childList.Count == 0)
                    continue;

                TreeIter GroupIter = ObjectsTreeStore.AppendNode (parentIter);

                var cleanOper = childClassInfo.CreateClearOperation(masterEntity, cleanDepend, childList);

                parentOperation.ChildBeforeOperations.Add (cleanOper);

                foreach(var item in childList)
                {
                    ObjectsTreeStore.AppendValues (GroupIter, item.Title);
                    groupCount++;
                    totalCount++;
                    clearCount++;
                }

                CheckDlg.AddLinksCount(groupCount);
                if (CheckDlg.IsCanceled)
                    return 0;

                ObjectsTreeStore.SetValues (GroupIter, String.Format ("{0}({1})", StringWorks.StringToTitleCase (childClassInfo.ObjectsName), groupCount));
            }
            return clearCount;
        }
Ejemplo n.º 10
0
        int FillChildOperation(IDeleteInfo currentDeletion, Operation parentOperation, TreeIter parentIter, EntityDTO masterEntity)
        {
            TreeIter DeleteIter, ClearIter, RemoveIter;
            int Totalcount = 0;
            int DelCount = 0;
            int ClearCount = 0;
            int RemoveCount = 0;
            EntityDTO secondEntity = null;

            var secondInfo = CalculateSecondInfo(currentDeletion, masterEntity);
            if (!currentDeletion.HasDependences && !(secondInfo == null || secondInfo.HasDependences))
                return 0;

            CheckDlg.SetOperationName(String.Format("Проверка ссылок на: {0}", masterEntity.Title));
            logger.Debug(String.Format("Проверка ссылок на: {0}", masterEntity.Title));
            if (CheckDlg.IsCanceled)
                return 0;

            if(secondInfo != null)
            {
                secondEntity = new EntityDTO {
                    ClassType = secondInfo.ObjectClass,
                    Entity = masterEntity.Entity,
                    Id = masterEntity.Id,
                    Title = masterEntity.Title
                };
            }

            if (currentDeletion.DeleteItems.Count > 0 || (secondInfo != null && secondInfo.DeleteItems.Count > 0)) {
                if (!ObjectsTreeStore.IterIsValid (parentIter))
                    DeleteIter = ObjectsTreeStore.AppendNode ();
                else
                    DeleteIter = ObjectsTreeStore.AppendNode (parentIter);

                DelCount = FillDeleteItemsOperation(currentDeletion, parentOperation, DeleteIter, masterEntity, ref Totalcount);

                if(secondInfo != null)
                {
                    DelCount += FillDeleteItemsOperation(secondInfo, parentOperation, DeleteIter, secondEntity, ref Totalcount);
                }

                if (DelCount > 0)
                    ObjectsTreeStore.SetValues (DeleteIter, String.Format ("Будет удалено ({0}/{1}) объектов:", DelCount, Totalcount));
                else
                    ObjectsTreeStore.Remove (ref DeleteIter);
            }

            //TODO Сделать возможность журналирования очистки полей у объектов.
            if (currentDeletion.ClearItems.Count > 0 || (secondInfo != null && secondInfo.ClearItems.Count > 0)) {
                if (!ObjectsTreeStore.IterIsValid (parentIter))
                    ClearIter = ObjectsTreeStore.AppendNode ();
                else
                    ClearIter = ObjectsTreeStore.AppendNode (parentIter);

                ClearCount = FillCleanItemsOperation(currentDeletion, parentOperation, ClearIter, masterEntity, ref Totalcount);

                if(secondInfo != null)
                {
                    ClearCount += FillDeleteItemsOperation(secondInfo, parentOperation, ClearIter, secondEntity, ref Totalcount);
                }

                if (ClearCount > 0)
                    ObjectsTreeStore.SetValues (ClearIter, RusNumber.FormatCase (ClearCount,
                        "Будет очищено ссылок у {0} объекта:",
                        "Будет очищено ссылок у {0} объектов:",
                        "Будет очищено ссылок у {0} объектов:"
                    ));
                else
                    ObjectsTreeStore.Remove (ref ClearIter);
            }

            if (currentDeletion.RemoveFromItems.Count > 0 || (secondInfo != null && secondInfo.RemoveFromItems.Count > 0)) {
                if (!ObjectsTreeStore.IterIsValid (parentIter))
                    RemoveIter = ObjectsTreeStore.AppendNode ();
                else
                    RemoveIter = ObjectsTreeStore.AppendNode (parentIter);

                RemoveCount = FillRemoveFromItemsOperation(currentDeletion, parentOperation, RemoveIter, masterEntity, ref Totalcount);

                if(secondInfo != null)
                {
                    RemoveCount += FillRemoveFromItemsOperation(secondInfo, parentOperation, RemoveIter, secondEntity, ref Totalcount);
                }

                if (RemoveCount > 0)
                    ObjectsTreeStore.SetValues (RemoveIter, RusNumber.FormatCase (RemoveCount,
                        "Будут очищены ссылки в коллекциях у {0} объекта:",
                        "Будут очищены ссылки в коллекциях у {0} объектов:",
                        "Будут очищены ссылки в коллекциях у {0} объектов:" ));
                else
                    ObjectsTreeStore.Remove (ref RemoveIter);
            }

            return Totalcount;
        }
Ejemplo n.º 11
0
        private IDeleteInfo CalculateSecondInfo(IDeleteInfo info, EntityDTO entity)
        {
            var hinfo = info as IDeleteInfoHibernate;
            if (hinfo == null)
                return null;

            if(hinfo.IsSubclass)
            {
                var root = hinfo.GetRootDeleteInfo();
                if (root != null)
                    return root;
            }

            if(hinfo.IsRootForSubclasses)
            {
                var subclass = NHibernate.NHibernateUtil.GetClass(entity.Entity);

                if (subclass != null)
                    return DeleteConfig.GetDeleteInfo(subclass);
            }

            return null;
        }