Ejemplo n.º 1
0
 public BalanceGroupItem(HierarchicalEmcosPointCollection children)
 {
     if (children != null)
     {
         foreach (var child in children)
         {
             Children.Add(child);
         }
     }
 }
Ejemplo n.º 2
0
        public PointsEditor(IEnumerable <IHierarchicalEmcosPoint> balancePoints, IEnumerable <IHierarchicalEmcosPoint> otherPoints, IWindowWithDialogs window)
        {
            _rootEmcosGroup = DEFAULT_ROOT_EMCOS_GROUP;
            _window         = window;

            EmcosPoints = new HierarchicalEmcosPointCollection(null, balancePoints);

            OtherPoints = new HierarchicalEmcosPointCollection(null, otherPoints);

            InitializeComponent();
            DataContext = this;

            NewPoints = new List <IHierarchicalEmcosPoint>();

            // настройка сервиса
            System.ServiceModel.Channels.Binding binding = new System.ServiceModel.BasicHttpBinding()
            {
                MaxBufferSize          = 10240000,
                MaxReceivedMessageSize = 10240000,
                Name = "ServiceSoap"
            };
            _emcosWebServiceClient = new EmcosTestWebService.ServiceSoapClient(binding,
                                                                               new System.ServiceModel.EndpointAddress(String.Format("http://{0}/{1}",
                                                                                                                                     EmcosSettings.Default.ServerAddress,
                                                                                                                                     EmcosSettings.Default.WebServiceName)));

            this.Loaded += (s, e) =>
            {
                //await LoadPointsFromServiceAsync();
            };

            CommandUpdate = new DelegateCommand(async() =>
            {
                await LoadPointsFromServiceAsync();
            });

            CommandDelete = new DelegateCommand(() =>
            {
                var dialog     = _window.DialogQuestion(String.Format("Точка '{0}' будет удалена. Вы уверены, что хотите продолжить?", _emcosPointsSelectedValue.Name));
                dialog.YesText = "Да, удалить";
                dialog.NoText  = "Отменить";
                dialog.Yes     = () =>
                {
                    _emcosPointsSelectedValue.Parent.Children.Remove(_emcosPointsSelectedValue);

                    if (NewPoints.Contains(_emcosPointsSelectedValue))
                    {
                        NewPoints.Remove(_emcosPointsSelectedValue);
                    }

                    if (DeletedPoints.Contains(_emcosPointsSelectedValue) == false)
                    {
                        DeletedPoints.Add(_emcosPointsSelectedValue);
                    }
                };
            }, (o) => _emcosPointsSelectedValue != null && _emcosPointsSelectedValue.Parent != null);

            CommandMoveUp = new DelegateCommand(() =>
            {
                int index = _emcosPointsSelectedValue.Parent.Children.IndexOf(_emcosPointsSelectedValue);
                _emcosPointsSelectedValue.Parent.Children.Move(index, index - 1);
            },
                                                (o) => _emcosPointsSelectedValue != null &&
                                                _emcosPointsSelectedValue.Parent != null &&
                                                _emcosPointsSelectedValue.Parent.Children.IndexOf(_emcosPointsSelectedValue) > 0
                                                );

            CommandMoveDown = new DelegateCommand(() =>
            {
                int index = _emcosPointsSelectedValue.Parent.Children.IndexOf(_emcosPointsSelectedValue);
                _emcosPointsSelectedValue.Parent.Children.Move(index, index + 1);
            },
                                                  (o) => _emcosPointsSelectedValue != null &&
                                                  _emcosPointsSelectedValue.Parent != null &&
                                                  _emcosPointsSelectedValue.Parent.Children.IndexOf(_emcosPointsSelectedValue) < _emcosPointsSelectedValue.Parent.ChildrenCount - 1);

            CommandClear = new DelegateCommand(() =>
            {
                var dialog     = _window.DialogQuestion("Список точек будет очищен. Вы уверены, что хотите продолжить?");
                dialog.YesText = "Да, очистить";
                dialog.NoText  = "Отменить";
                dialog.Yes     = () =>
                {
                    DeletedPoints.Clear();
                    DeletedPoints.AddRange(EmcosPoints.FlatItemsList);
                    EmcosPoints.Clear();
                    NewPoints.Clear();
                };
            }, (o) => EmcosPoints != null && EmcosPoints.Count > 0);

            CommandAdd = new DelegateCommand(() =>
            {
                if (_emcosPointsSelectedValue != null)
                {
                    _emcosPointsSelectedValue.Children.Add(_emcosPointsFromSiteSelectedValue);
                }
                else
                {
                    EmcosPoints.Add(_emcosPointsFromSiteSelectedValue);
                }

                if (NewPoints.Contains(_emcosPointsFromSiteSelectedValue) == false)
                {
                    NewPoints.Add(_emcosPointsFromSiteSelectedValue);
                }
            }, (o) => _emcosPointsFromSiteSelectedValue != null);

            CommandBalanceFormula = new DelegateCommand(() =>
            {
                BalanceFormulaEditor ctrl = new BalanceFormulaEditor();
                ctrl.DataContext          = Repository.Instance.GetGroupBalanceFormula(_emcosPointsSelectedValue.Id);

                var dialog = _window.DialogCustom(ctrl, TMPApplication.WpfDialogs.DialogMode.YesNo);

                dialog.YesText = "Записать";
                dialog.NoText  = "Отменить";
                dialog.Yes     = () =>
                {
                    ;
                };
            }, (o) => _emcosPointsSelectedValue != null && _emcosPointsSelectedValue.IsGroup);
        }
Ejemplo n.º 3
0
        private async Task LoadPointsFromServiceAsync()
        {
            const string ErrorMessage = "Получение списка точек от сервиса - ошибка:\n{0}";
            IDialog      dialog       = null;

            try
            {
                dialog = _window.DialogWaitingScreen("Получение данных ...", indeterminate: true, mode: TMPApplication.WpfDialogs.DialogMode.Cancel);
                dialog.Show();
                var source = await FillPointsTree(_rootEmcosGroup);

                if (source.Count == 0)
                {
                    dialog.Close();
                    _window.ShowDialogWarning("Список пуст!", TITLE);
                    EmcosPointsFromSite = null;
                }
                else
                {
                    dialog.Caption = "Создание модели";
                    EmcosSiteWrapperApp.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new System.Threading.ThreadStart(delegate { }));

                    EmcosPointsFromSite = new HierarchicalEmcosPointCollection(null, source);
                    dialog.Caption      = "Поиск изменений";
                    EmcosSiteWrapperApp.Current.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Background, new System.Threading.ThreadStart(delegate { }));

                    // поиск новых точек
                    void checkNewItems(IEnumerable <IHierarchicalEmcosPoint> sourcePoints, IEnumerable <IHierarchicalEmcosPoint> destinationPoints)
                    {
                        foreach (var point in sourcePoints)
                        {
                            IHierarchicalEmcosPoint p = destinationPoints.Where(i => i.Id == point.Id).FirstOrDefault();
                            if (p == null)
                            {
                                point.Tag = "NEW";
                            }
                            else
                            {
                                point.Tag = null;
                                if (point.HasChildren)
                                {
                                    checkNewItems(point.Children, p.Children);
                                }
                            }
                        }
                    }
                    checkNewItems(EmcosPointsFromSite, EmcosPoints);

                    // поиск удаленных точек
                    void checkDeletedItems(IEnumerable <IHierarchicalEmcosPoint> sourcePoints, IEnumerable <IHierarchicalEmcosPoint> destinationPoints)
                    {
                        foreach (var point in sourcePoints)
                        {
                            IHierarchicalEmcosPoint p = destinationPoints.Where(i => i.Id == point.Id).FirstOrDefault();
                            if (p == null)
                            {
                                point.Tag = "DELETED";
                            }
                            else
                            {
                                point.Tag = null;
                                if (point.HasChildren)
                                {
                                    checkDeletedItems(point.Children, p.Children);
                                }
                            }
                        }
                    }
                    checkDeletedItems(EmcosPoints, EmcosPointsFromSite);

                    dialog.Close();
                }
            }
            catch (Exception ex)
            {
                EmcosSiteWrapperApp.Log("Получение списка точек от сервиса - ошибка");
                if (dialog != null)
                {
                    dialog.Close();
                }
                _window.ShowDialogError(String.Format(ErrorMessage, EmcosSiteWrapperApp.GetExceptionDetails(ex)));
            }
        }