Пример #1
0
        public virtual ActionResult <object> InitializeScreen([FromBody] RequestScreenModel model)
        {
            // Проверка, что такой скрин уже не проинициализирован
            if (screenInfo.Screen == null || screenInfo.Screen.Name != model.NewScreenName)
            {
                // Очистка информации
                viewInfo.Dispose();

                // Инициализация скрина
                screenInfo.Initialize(model.NewScreenName, model.NewViewName, context);
                screenInfo.ActionType = ActionType.InitializeScreen;
                screenInfoUI.Initialize(screenInfo, context);

                // Восстановление контекста при переходе на экран, который присутствует в хлебных крошках
                if (ComponentsRecordsInfo.GetCrumbs().FirstOrDefault(i => i.ViewId == screenInfo.CurrentView?.ViewId) != null)
                {
                    ComponentsRecordsInfo.RestoreContext(new List <View>()
                    {
                        context.Views
                        .Include(bo => bo.BusObject)
                        .ThenInclude(boc => boc.BusObjectComponents)
                        .ThenInclude(bc => bc.BusComp)
                        .FirstOrDefault(i => i.Id == screenInfo.CurrentView.ViewId)
                    });
                }
            }
            else
            {
                screenInfo.ActionType = ActionType.ReloadScreen;
            }
            return(Ok(screenInfoUI.Serialize()));
        }
Пример #2
0
 public virtual ActionResult <object> ScreenInfo(string screenName)
 {
     if (screenInfo.Screen != null && screenInfo.Screen.Name != screenName)
     {
         IScreenInfo newScreenInfo = (IScreenInfo)screenInfo.Clone();
         newScreenInfo.Initialize(screenName, null, context);
         IScreenInfoUI newScreenInfoUI = (IScreenInfoUI)screenInfoUI.Clone();
         newScreenInfoUI.Initialize(newScreenInfo, context);
         return(Ok(newScreenInfoUI.Serialize()));
     }
     else
     {
         return(Ok(screenInfoUI.Serialize()));
     }
 }
Пример #3
0
        public ActionResult Drilldown()
        {
            Applet currentApplet = viewInfo.CurrentPopupApplet ?? viewInfo.CurrentApplet;

            currentApplet = context.Applets
                            .AsNoTracking()
                            .Select(a => new
            {
                id      = a.Id,
                name    = a.Name,
                type    = a.Type,
                busComp = new
                {
                    id      = a.BusComp.Id,
                    name    = a.BusComp.Name,
                    routing = a.BusComp.Routing
                },
                drilldowns = a.Drilldowns.Select(d => new
                {
                    id               = d.Id,
                    name             = d.Name,
                    hyperLinkFieldId = d.HyperLinkFieldId,
                    sourceField      = new
                    {
                        id   = d.SourceField.Id,
                        name = d.SourceField.Name
                    },
                    destinationBusinessComponent = new
                    {
                        id      = d.DestinationBusinessComponent.Id,
                        name    = d.DestinationBusinessComponent.Name,
                        routing = d.DestinationBusinessComponent.Routing
                    },
                    destinationField = new
                    {
                        id   = d.DestinationField.Id,
                        name = d.DestinationField.Name
                    },
                    destinationScreenId     = d.DestinationScreenId,
                    destinationScreenItemId = d.DestinationScreenItemId,
                    destinationScreenItem   = new
                    {
                        id   = d.DestinationScreenItem.Id,
                        view = new
                        {
                            id          = d.DestinationScreenItem.View.Id,
                            busObjectId = d.DestinationScreenItem.View.BusObjectId
                        }
                    }
                })
            })
                            .Select(a => new Applet
            {
                Id      = a.id,
                Name    = a.name,
                Type    = a.type,
                BusComp = new BusinessComponent
                {
                    Id      = a.busComp.id,
                    Name    = a.busComp.name,
                    Routing = a.busComp.routing
                },
                Drilldowns = a.drilldowns.Select(d => new Drilldown
                {
                    Id               = d.id,
                    Name             = d.name,
                    HyperLinkFieldId = d.hyperLinkFieldId,
                    SourceField      = new Field
                    {
                        Id   = d.sourceField.id,
                        Name = d.sourceField.name
                    },
                    DestinationBusinessComponent = new BusinessComponent
                    {
                        Id      = d.destinationBusinessComponent.id,
                        Name    = d.destinationBusinessComponent.name,
                        Routing = d.destinationBusinessComponent.routing
                    },
                    DestinationField = new Field
                    {
                        Id   = d.destinationField.id,
                        Name = d.destinationField.name
                    },
                    DestinationScreenId   = d.destinationScreenId,
                    DestinationScreenItem = new ScreenItem
                    {
                        Id   = d.destinationScreenItem.id,
                        View = new View
                        {
                            Id          = d.destinationScreenItem.view.id,
                            BusObjectId = d.destinationScreenItem.view.busObjectId
                        }
                    }
                }).ToList()
            })
                            .FirstOrDefault(i => i.Id == currentApplet.Id);
            if (currentApplet != null)
            {
                string controlName;
                Field  field;
                switch (currentApplet.Type)
                {
                case "Tile":
                    controlName = viewInfo.CurrentColumn.Name;
                    field       = viewInfo.CurrentColumn.Field;
                    break;

                default:
                    controlName = viewInfo.CurrentPopupControl?.Name ?? viewInfo.CurrentControl?.Name;
                    field       = viewInfo.CurrentPopupControl?.Field ?? viewInfo.CurrentControl?.Field;
                    break;
                }
                if (field != null)
                {
                    TBUSFactory BUSFactory = new TBUSFactory();
                    Drilldown   drilldown  = currentApplet.Drilldowns.FirstOrDefault(i => i.HyperLinkFieldId == field.Id);
                    if (drilldown != null && drilldown.DestinationBusinessComponent?.Name != null && drilldown.DestinationField?.Name != null && drilldown.SourceField?.Name != null)
                    {
                        // Целевой экран
                        Screen destinationScreen = context.Screens.AsNoTracking().FirstOrDefault(i => i.Id == drilldown.DestinationScreenId);
                        if (destinationScreen != null)
                        {
                            applicationInfo.CurrentScreen = destinationScreen;

                            // Целевыое представление
                            View destinationView = context.Views.AsNoTracking().FirstOrDefault(i => i.Id == drilldown.DestinationScreenItem.View.Id);
                            if (destinationView != null)
                            {
                                applicationInfo.CurrentView = destinationView;

                                // Исходное поле
                                dynamic      sourceRecord   = BUSFactory.GetRecord(null, context, viewInfo, currentApplet.BusComp, "Id", viewInfo.CurrentRecord);
                                PropertyInfo sourceProperty = sourceRecord.GetType().GetProperty(drilldown.SourceField.Name);
                                if (sourceProperty != null)
                                {
                                    // Очистка старой информации о выбранных записях
                                    if (screenInfo.Screen.Name != destinationScreen.Name)
                                    {
                                        ComponentsRecordsInfo.Dispose();
                                    }

                                    // Установка текущей выбранной записи на целевой бизнес компоненте
                                    var sourcePropertyValue = sourceProperty.GetValue(sourceRecord);
                                    if (sourcePropertyValue != null)
                                    {
                                        dynamic destinationRecord = BUSFactory.GetRecord(null, context, viewInfo, drilldown.DestinationBusinessComponent, drilldown.DestinationField.Name, sourcePropertyValue.ToString());
                                        if (destinationRecord != null)
                                        {
                                            ComponentsRecordsInfo.SetSelectedRecord(drilldown.DestinationBusinessComponent.Name, destinationRecord.Id.ToString());
                                        }

                                        // Установка текущих выбранных записей на всех родительских бизнес компонентах целевой компоненты
                                        BusinessObject destinationBO = context.BusinessObjects
                                                                       .AsNoTracking()
                                                                       .Include(boc => boc.BusObjectComponents)
                                                                       .ThenInclude(l => l.Link)
                                                                       .ThenInclude(cf => cf.ChildField)
                                                                       .Include(boc => boc.BusObjectComponents)
                                                                       .ThenInclude(l => l.Link)
                                                                       .ThenInclude(pf => pf.ParentField)
                                                                       .FirstOrDefault(i => i.Id == destinationView.BusObjectId);
                                        BusinessObjectComponent destinationComponent = destinationBO.BusObjectComponents.FirstOrDefault(i => i.BusCompId == drilldown.DestinationBusinessComponent.Id);
                                        dynamic childRecord = destinationRecord;
                                        if (destinationComponent.Link != null)
                                        {
                                            BusinessComponent parentBusComp = context.BusinessComponents
                                                                              .AsNoTracking()
                                                                              .Select(bc => new
                                            {
                                                id    = bc.Id,
                                                name  = bc.Name,
                                                table = new
                                                {
                                                    id   = bc.Table.Id,
                                                    name = bc.Table.Name
                                                }
                                            })
                                                                              .Select(bc => new BusinessComponent
                                            {
                                                Id    = bc.id,
                                                Name  = bc.name,
                                                Table = new Table
                                                {
                                                    Id   = bc.table.id,
                                                    Name = bc.table.name
                                                }
                                            })
                                                                              .FirstOrDefault(i => i.Id == destinationComponent.Link.ParentBCId);
                                            BusinessComponent childBusComp = context.BusinessComponents
                                                                             .AsNoTracking()
                                                                             .Select(bc => new { id = bc.Id, name = bc.Name })
                                                                             .Select(bc => new BusinessComponent {
                                                Id = bc.id, Name = bc.name
                                            })
                                                                             .FirstOrDefault(i => i.Id == destinationComponent.Link.ChildBCId);
                                            string childFieldValue = childRecord.GetType().GetProperty(destinationComponent.Link.ChildField.Name).GetValue(childRecord).ToString();
                                            string parentFieldName = destinationComponent.Link.ParentField.Name;
                                            IEnumerable <dynamic> parentRecords = (IEnumerable <dynamic>)(context.GetType().GetProperty(parentBusComp.Table.Name).GetValue(context));
                                            string  searchSpecificationByParent = $"{parentFieldName} = \"{childFieldValue}\"";
                                            dynamic parentRecord = parentRecords.AsQueryable().Where(searchSpecificationByParent).FirstOrDefault();
                                            ComponentsRecordsInfo.SetSearchSpecification(childBusComp.Name, SearchSpecTypes.SearchSpecificationByParent, searchSpecificationByParent);
                                            ComponentsRecordsInfo.SetSelectedRecord(parentBusComp.Name, parentRecord.Id.ToString());
                                            destinationComponent = destinationBO.BusObjectComponents.FirstOrDefault(i => i.BusCompId == destinationComponent.Link.ParentBCId);
                                            childRecord          = parentRecord;
                                        }

                                        // Установка хлебных крошек
                                        ScreenItem crumb = screenInfo.Screen.ScreenItems.FirstOrDefault(n => n.View != null && n.View.Name == screenInfo.CurrentView.Name);
                                        ComponentsRecordsInfo.AppendCrumb(crumb);
                                        if (screenInfo.Screen.Name == destinationScreen.Name)
                                        {
                                            screenInfo.Initialize(screenInfo.Screen.Name, destinationView.Name, context);
                                            screenInfoUI.Initialize(screenInfo, context);
                                            viewInfo.View = destinationView;
                                        }
                                        viewInfo.ActionType = ActionType.Drilldown;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(Ok());
        }