コード例 #1
0
        public void AddActor(IActorUserControl actor)
        {
            if (ActorA == null)
            {
                if (actor.GetUserControlType() == EnumTypes.UserControlTypes.BuyerUserControl)
                {
                    throw new ConnectionException(ConnectionException.ILLEGALCONNECTIONFROMBUYER);
                }
                ActorA = actor;
            }
            else if (ActorA != actor)
            {
                if (actor.GetUserControlType() == EnumTypes.UserControlTypes.SupplierUserControl)
                {
                    throw new ConnectionException(ConnectionException.ILLEGALCONNECTIONTOSUPPLIER);
                }
                if (ActorA.GetUserControlType() == EnumTypes.UserControlTypes.SupplierUserControl && actor.GetUserControlType() == EnumTypes.UserControlTypes.BuyerUserControl)
                {
                    throw new ConnectionException(ConnectionException.ILLEGALCONNECTIONSUPPLIERBUYER);
                }

                ActorB = actor;

                CheckForDuplicate();
            }
        }
コード例 #2
0
 public void CheckForDuplicate()
 {
     if (Model.Connections.Where(c => c.ActorA == this.ActorA.GetActor() && c.ActorB == this.ActorB.GetActor()).Count() != 0)
     {
         ActorB = null;
         throw new ConnectionException(ConnectionException.CONNECTIONALREADYEXISTS);
     }
 }
コード例 #3
0
        public void CreateConnectionIfPossible()
        {
            ConnectionUI connectionUI;
            Connection   conn;

            if (ActorA != null && ActorB != null)
            {
                switch (ActorA.GetUserControlType())
                {
                case EnumTypes.UserControlTypes.ShopUserControl:
                    ShopUserControl ShopA = (ShopUserControl)ActorA;
                    switch (ActorB.GetUserControlType())
                    {
                    case EnumTypes.UserControlTypes.ShopUserControl:
                        ShopUserControl ShopB = (ShopUserControl)ActorB;
                        conn         = new Connection(ShopA.ShopModel, ShopB.ShopModel, EnumTypes.ConnectionTypes.ShopToShop);
                        connectionUI = new ConnectionUI(this.Model, Target, conn, this);
                        ConnectionDictionary.Add(conn, connectionUI);
                        this.Model.Connections.Add(conn);
                        connectionUI.PrintOnTarget();
                        ShopA.Reprint(Target);
                        ShopB.Reprint(Target);
                        break;

                    case EnumTypes.UserControlTypes.BuyerUserControl:
                        BuyerUserControl BuyerB = (BuyerUserControl)ActorB;
                        conn         = new Connection(ShopA.ShopModel, BuyerB.BuyerModel, EnumTypes.ConnectionTypes.ShopToBuyer);
                        connectionUI = new ConnectionUI(this.Model, Target, conn, this);
                        ConnectionDictionary.Add(conn, connectionUI);
                        this.Model.Connections.Add(conn);
                        connectionUI.PrintOnTarget();
                        ShopA.Reprint(Target);
                        BuyerB.Reprint(Target);
                        break;
                    }
                    break;

                case EnumTypes.UserControlTypes.SupplierUserControl:
                    SupplierUserControl SuppA  = (SupplierUserControl)ActorA;
                    ShopUserControl     ShopB2 = (ShopUserControl)ActorB;
                    conn         = new Connection(SuppA.SupplierModel, ShopB2.ShopModel, EnumTypes.ConnectionTypes.SupplierToShop);
                    connectionUI = new ConnectionUI(this.Model, Target, conn, this);
                    ConnectionDictionary.Add(conn, connectionUI);
                    this.Model.Connections.Add(conn);
                    connectionUI.PrintOnTarget();
                    SuppA.Reprint(Target);
                    ShopB2.Reprint(Target);
                    break;
                }
                //RYSUJE - czyli
                this.ActorA = null;
                this.ActorB = null;
            }
        }
コード例 #4
0
        public void ReprintActors()
        {
            List <IActorUserControl> actorsList = new List <IActorUserControl>();

            foreach (UIElement element in target.Children)
            {
                IActorUserControl actor = element as IActorUserControl;
                if (actor != null)
                {
                    actorsList.Add(actor);
                }
            }

            foreach (IActorUserControl actor in actorsList)
            {
                actor.Reprint(this.target);
            }
        }
コード例 #5
0
        private void panel_Drop(object sender, DragEventArgs e)
        {
            // If an element in the panel has already handled the drop,
            // the panel should not also handle it.
            if (e.Handled == false)
            {
                Canvas    _canvas  = (Canvas)sender;
                UIElement _element = (UIElement)e.Data.GetData("Object");

                if (_canvas != null && _element != null)
                {
                    // Get the panel that the element currently belongs to,
                    // then remove it from that panel and add it the Children of
                    // the panel that its been dropped on.
                    Panel _parent = (Panel)VisualTreeHelper.GetParent(_element);
                    if (_parent != null)
                    {
                        //Mouse position
                        System.Windows.Point position = e.GetPosition(_canvas);
                        //Type
                        DataModel.EnumTypes.UserControlTypes _type = (DataModel.EnumTypes.UserControlTypes)e.Data.GetData("UserControlType");

                        if ((e.KeyStates == DragDropKeyStates.ControlKey || _parent.Name == "ToolPanel") &&
                            e.AllowedEffects.HasFlag(DragDropEffects.Copy))
                        {
                            switch (_type)
                            {
                            case EnumTypes.UserControlTypes.ShopUserControl:
                                ShopUserControl _shopUserControl = new ShopUserControl((ShopUserControl)_element, Model, ConnectionCreator);
                                Model.Shops.Add(_shopUserControl.ShopModel);
                                _shopUserControl.printOnTarget(_canvas, position);
                                // set the value to return to the DoDragDrop call
                                e.Effects = DragDropEffects.Copy;
                                break;

                            case EnumTypes.UserControlTypes.BuyerUserControl:
                                BuyerUserControl _buyerUserControl = new BuyerUserControl((BuyerUserControl)_element, Model, ConnectionCreator);
                                Model.Buyers.Add(_buyerUserControl.BuyerModel);
                                _buyerUserControl.printOnTarget(_canvas, position);
                                // set the value to return to the DoDragDrop call
                                e.Effects = DragDropEffects.Copy;
                                break;

                            case EnumTypes.UserControlTypes.SupplierUserControl:
                                SupplierUserControl _supplierUserControl = new SupplierUserControl((SupplierUserControl)_element, Model, ConnectionCreator);
                                Model.Suppliers.Add(_supplierUserControl.SupplierModel);
                                _supplierUserControl.printOnTarget(_canvas, position);
                                // set the value to return to the DoDragDrop call
                                e.Effects = DragDropEffects.Copy;
                                break;

                            default:
                                MessageBox.Show("Not habndled yet");
                                break;
                            }
                        }
                        else if (e.AllowedEffects.HasFlag(DragDropEffects.Move))
                        {
                            IActorUserControl _actorUserControl = (IActorUserControl)_element;
                            List <Connection> connections;
                            switch (_actorUserControl.GetUserControlType())
                            {
                            case EnumTypes.UserControlTypes.ShopUserControl:
                                ShopUserControl _shopUserControl = (ShopUserControl)_element;
                                _parent.Children.Remove(_element);
                                _shopUserControl.printOnTarget(_canvas, position);

                                connections = this.Model.Connections.Where(c => c.ActorA == _shopUserControl.ShopModel || c.ActorB == _shopUserControl.ShopModel).ToList();
                                foreach (Connection conn in connections)
                                {
                                    this.ConnectionCreator.ConnectionDictionary[conn].Reprint();
                                }
                                //TODO:
                                //potem gorzej bo dla kazdej linii musimy nzlaezc aktorow zeby ich przerysowac... nie mam do nich odwolan, po liscie wszystkich narysowanych musze leciec
                                //odowlania nie moge zrobic bo przy odtwarzaniu z bazki nie mam jeszcze aktorow ui i nie ma ich w connections ui
                                //zmiana tego bedzie dluzsza niz warto
                                // set the value to return to the DoDragDrop call
                                e.Effects = DragDropEffects.Move;
                                break;

                            case EnumTypes.UserControlTypes.BuyerUserControl:
                                BuyerUserControl _buyerUserControl = (BuyerUserControl)_element;
                                _parent.Children.Remove(_element);
                                _buyerUserControl.printOnTarget(_canvas, position);

                                connections = this.Model.Connections.Where(c => c.ActorA == _buyerUserControl.BuyerModel || c.ActorB == _buyerUserControl.BuyerModel).ToList();
                                foreach (Connection conn in connections)
                                {
                                    this.ConnectionCreator.ConnectionDictionary[conn].Reprint();
                                }
                                // set the value to return to the DoDragDrop call
                                e.Effects = DragDropEffects.Move;
                                break;

                            case EnumTypes.UserControlTypes.SupplierUserControl:
                                SupplierUserControl _supplierUserControl = (SupplierUserControl)_element;
                                _parent.Children.Remove(_element);
                                _supplierUserControl.printOnTarget(_canvas, position);

                                connections = this.Model.Connections.Where(c => c.ActorA == _supplierUserControl.SupplierModel || c.ActorB == _supplierUserControl.SupplierModel).ToList();
                                foreach (Connection conn in connections)
                                {
                                    this.ConnectionCreator.ConnectionDictionary[conn].Reprint();
                                }
                                // set the value to return to the DoDragDrop call
                                e.Effects = DragDropEffects.Move;
                                break;
                            }

                            this.ReprintActors();
                        }
                    }
                }
            }
        }
コード例 #6
0
 public void CancelConnection()
 {
     ActorA = null;
     ActorB = null;
 }