Ejemplo n.º 1
0
        public void MoveDown(bool assignNewLocation)
        {
            if (belowCard != null)
            {
                FormFieldCard oldBelowCard = belowCard;
                BelowCard = belowCard.BelowCard;

                if (aboveCard != null)
                {
                    aboveCard.BelowCard = oldBelowCard;
                }
                else
                {
                    oldBelowCard.AboveCard = null;
                }

                AboveCard = oldBelowCard;
                oldBelowCard.BelowCard = this;

                aboveCard.Location = new Point(Location.X, !assignNewLocation ? OriginalY : Location.Y);
                newLocation        = new Point(Location.X, aboveCard.Location.Y + aboveCard.Height + aboveCard.PaddingBottom);
                OriginalY          = newLocation.Value.Y;
                if (assignNewLocation)
                {
                    Location = newLocation.Value;
                }
            }
        }
Ejemplo n.º 2
0
        private void AddField(FieldForm fieldForm)
        {
            FormFieldCard lastCard = FindLastCard();
            FormFieldCard card     = new FormFieldCard()
            {
                //Question = fieldForm.Question.Value,
                CardWidth       = mainPanel.Width - diffX,
                EditorMainPanel = mainPanel,
                MainControl     = this,
            };

            card.CardMouseMove     += card_MouseMove;
            card.CardMouseUp       += card_MouseUp;
            card.RemoveButtonClick += card_RemoveButtonClick;
            card.ChangeTopPanelVisibility(showTools);
            card.SetField(fieldForm.Field);

            if (lastCard != null)
            {
                lastCard.BelowCard = card;
            }

            mainPanel.Controls.Add(card);
            RedrawFormular();
            card.Focus();
            mainPanel.ScrollControlIntoView(card);
        }
Ejemplo n.º 3
0
        public void MoveUp(bool assignNewLocation)
        {
            if (aboveCard != null)
            {
                FormFieldCard oldAboveCard = aboveCard;

                if (aboveCard.AboveCard != null)
                {
                    aboveCard.AboveCard.BelowCard = this;
                }
                else
                {
                    AboveCard = null;
                }

                FormFieldCard oldBelowCard = BelowCard;
                BelowCard = oldAboveCard;

                belowCard.BelowCard = oldBelowCard;

                newLocation = belowCard.Location;
                OriginalY   = newLocation.Value.Y;
                if (assignNewLocation)
                {
                    Location = newLocation.Value;
                }
                belowCard.Location = new Point(Location.X, newLocation.Value.Y + Height + PaddingBottom);
            }
        }
Ejemplo n.º 4
0
        private void card_MouseUp(object sender, MouseEventArgs e)
        {
            FormFieldCard card = ((sender as Control)?.Parent?.Parent as FormFieldCard);

            if (card != null)
            {
                card.AssignNewLocation();
            }
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Add or update in FormEditorControl
        /// </summary>
        /// <param name="field">Field to add</param>
        /// <param name="updateField">Specifies if the field has to be updated in the editor if was founded</param>
        /// /// <param name="addField">Specifies if the field has to be added into editor if was not founded</param>
        /// <returns></returns>
        public bool AddOrUpdateField(Field field, bool updateField, bool addField)
        {
            bool containsField = false;

            foreach (var item in mainPanel.Controls)
            {
                if (item is FormFieldCard cardItem && cardItem.Field.ID == field.ID)
                {
                    if (cardItem.IsRemoved)
                    {
                        cardItem.RemoveCard(true);
                    }
                    else
                    {
                        if (updateField)
                        {
                            cardItem.SetField(field);
                        }

                        cardItem.Focus();
                        containsField = true;
                        mainPanel.ScrollControlIntoView(cardItem);
                        break;
                    }
                }
            }

            if (!containsField && addField)
            {
                FormFieldCard lastCard = FindLastCard();
                FormFieldCard card     = new FormFieldCard()
                {
                    CardWidth = mainPanel.Width - diffX, EditorMainPanel = mainPanel, MainControl = this, Question = field.Question
                };
                card.CardMouseMove     += card_MouseMove;
                card.CardMouseMove     += card_MouseMove;
                card.CardMouseUp       += card_MouseUp;
                card.RemoveButtonClick += card_RemoveButtonClick;
                card.ChangeTopPanelVisibility(showTools);
                card.SetField(field);

                if (lastCard != null)
                {
                    lastCard.BelowCard = card;
                }

                mainPanel.Controls.Add(card);
                RedrawFormular();

                mainPanel.ScrollControlIntoView(card);
                card.Focus();
                AddCommand(new CardCommand(card, Enums.CardCommandEnum.Add));
            }

            return(containsField);
        }
Ejemplo n.º 6
0
        private FormFieldCard FindLastCard()
        {
            FormFieldCard result = null;

            foreach (var item in mainPanel.Controls)
            {
                if (item is FormFieldCard card && card.BelowCard == null)
                {
                    result = card;
                    break;
                }
            }

            return(result);
        }
Ejemplo n.º 7
0
        private void RedrawFormular()
        {
            mainPanel.AutoScroll = false;
            FormFieldCard actualCard          = FindFirstCard();
            Point         actualLocation      = new Point(startX, startY);
            int           actualHeight        = 0;
            int           actualPaddingBottom = 0;

            if (actualCard != null)
            {
                if (!actualCard.IsRemoved)
                {
                    actualCard.Location = actualLocation;
                    actualHeight        = actualCard.Height;
                    actualPaddingBottom = actualCard.PaddingBottom;
                }
                else
                {
                    actualCard.Visible = !actualCard.IsRemoved;
                }

                while (actualCard.BelowCard != null)
                {
                    //if(!actualCard.BelowCard.IsRemoved)
                    //{
                    //    actualLocation = new Point(startX, actualCard.Location.Y + actualCard.Height + actualCard.PaddingBottom); ;
                    //    actualCard.BelowCard.Location = actualLocation;
                    //}

                    if (!actualCard.BelowCard.IsRemoved)
                    {
                        actualLocation = new Point(startX, actualLocation.Y + actualHeight + actualPaddingBottom);
                        actualCard.BelowCard.Location = actualLocation;
                        actualHeight        = actualCard.BelowCard.Height;
                        actualPaddingBottom = actualCard.BelowCard.PaddingBottom;
                    }
                    else
                    {
                        actualCard.BelowCard.Visible = !actualCard.BelowCard.IsRemoved;
                    }

                    actualCard = actualCard.BelowCard;
                }
            }
            mainPanel.AutoScroll = true;
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads EZKO formular into mainPanel of the FormEditorControl
        /// </summary>
        /// <param name="formular">Formular which has to be loaded</param>
        public void LoadFormular(DatabaseCommunicator.Model.Form formular)
        {
            if (formular == null)
            {
                return;
            }

            if (Commands == null)
            {
                Commands = new List <CardCommand>();
            }

            mainPanel.Controls.Clear();

            formNameLabel.Text = formular.Name;

            FormFieldCard lastAddedCard = null;

            foreach (var item in formular.FieldForms.Where(x => !x.Field.IsDeleted).OrderBy(x => x.Question.Index))
            {
                FormFieldCard card = new FormFieldCard()
                {
                    //Question = item.Question.Value,
                    Question        = item.Field.Question,
                    CardWidth       = mainPanel.Width - diffX,
                    EditorMainPanel = mainPanel,
                    MainControl     = this,
                };
                card.CardMouseMove     += card_MouseMove;
                card.CardMouseUp       += card_MouseUp;
                card.RemoveButtonClick += card_RemoveButtonClick;
                card.SetField(item.Field);

                if (lastAddedCard != null)
                {
                    lastAddedCard.BelowCard = card;
                }

                lastAddedCard = card;
                mainPanel.Controls.Add(card);

                AddCommand(new CardCommand(card, Enums.CardCommandEnum.Add));
            }

            RedrawFormular();
        }
Ejemplo n.º 9
0
        private void card_MouseMove(object sender, MouseEventArgs e)
        {
            FormFieldCard card = ((sender as Control)?.Parent?.Parent as FormFieldCard);

            if (card != null)
            {
                if (card.Up && card.AboveCard != null)
                {
                    FormFieldCard aboveCard = card.AboveCard;
                    if (card.Location.Y < aboveCard.CenterY)
                    {
                        card.MoveUp(false);
                    }
                }
                else if (!card.Up && card.BelowCard != null)
                {
                    FormFieldCard belowCard = card.BelowCard;
                    if ((card.Location.Y + card.Height) > belowCard.CenterY)
                    {
                        card.MoveDown(false);
                    }
                }
            }
        }
Ejemplo n.º 10
0
 public void RemoveCommands(FormFieldCard card)
 {
     Commands.RemoveAll(x => x.Card == card);
     UpdateBackButtonVisibility();
 }