/// <summary>
 /// Iterates into paragraph items.
 /// </summary>
 /// <param name="paragraph">The paragraph.</param>
 /// <param name="fieldType">Type of field.</param>
 private void RemoveFieldCodesInParagraph(ParagraphItemCollection paraItems)
 {
     for (int i = 0; i < paraItems.Count; i++)
     {
         if (paraItems[i] is WField)
         {
             WField field = paraItems[i] as WField;
             field.Unlink();
         }
         else if (paraItems[i] is WTextBox)
         {
             //If paragraph item is textbox, iterates into textbody of textbox.
             WTextBox textBox = paraItems[i] as WTextBox;
             RemoveFieldCodesInTextBody(textBox.TextBoxBody);
         }
         else if (paraItems[i] is Shape)
         {
             //If paragraph item is shape, iterates into textbody of shape.
             Shape shape = paraItems[i] as Shape;
             RemoveFieldCodesInTextBody(shape.TextBody);
         }
         else if (paraItems[i] is InlineContentControl)
         {
             //If paragraph item is inline content control, iterates into its item.
             InlineContentControl inlineContentControl = paraItems[i] as InlineContentControl;
             RemoveFieldCodesInParagraph(inlineContentControl.ParagraphItems);
         }
     }
 }
Beispiel #2
0
        //Форма редактирования обьекта
        public ObjectForm(Object Obj, List <Object> ObjectList)
        {
            //список всех полей объекта
            FieldInfo[] fields = Obj.GetType().GetFields();

            //создание пустой формы для редактирования полей
            base.Text = Obj.GetType().ToString();
            base.Size = new System.Drawing.Size(500, 60 + 25 * (fields.Length + 2));

            //создание полей
            for (int i = 0; i < fields.Length; i++)
            {
                //надпись содержащая тип и имя поля
                Label label = new Label
                {
                    Location = new Point(15, 25 * (i + 1)),
                    //Width = string.Concat(fields[i].FieldType.Name, " ", fields[i].Name).Length * 7,
                    Width = base.Width / 2,
                    Text  = string.Concat(fields[i].Name, " - ", fields[i].FieldType.Name, ": ")
                };
                base.Controls.Add(label);

                //Создание чекбоксов
                if (fields[i].FieldType == typeof(bool))
                {
                    CheckBox check = new CheckBox()
                    {
                        Name     = fields[i].Name,
                        Location = new Point(15 + label.Width, 25 * (i + 1)),
                        //Width = base.Width - (label.Location.X + label.Width + 30),
                        //Text = fields[i].GetValue(Obj).ToString()
                        Checked = (bool)fields[i].GetValue(Obj)
                    };
                    base.Controls.Add(check);
                } //Создание для стандартных типов значений текстовых полей ввода, и их заполнение
                else if (((fields[i].FieldType.IsPrimitive) && (!fields[i].FieldType.IsEnum)) ||
                         (fields[i].FieldType == typeof(string)))
                {
                    TextBox text = new TextBox
                    {
                        Name     = fields[i].Name,
                        Location = new Point(15 + label.Width, 25 * (i + 1)),
                        Width    = base.Width - (label.Location.X + label.Width + 30),
                        Text     = fields[i].GetValue(Obj).ToString()
                    };
                    base.Controls.Add(text);
                }//Создание выпадающих списков для перечислимых типов
                else if (fields[i].FieldType.IsEnum)
                {
                    ComboBox combobox = new ComboBox
                    {
                        Name           = fields[i].Name,
                        SelectionStart = 0,
                        DropDownStyle  = ComboBoxStyle.DropDownList,
                        Location       = new Point(15 + label.Width, 25 * (i + 1)),
                        Width          = base.Width - (label.Location.X + label.Width + 30)
                    };
                    combobox.Items.AddRange(fields[i].FieldType.GetEnumNames());
                    combobox.SelectedIndex = (int)(fields[i].GetValue(Obj));
                    base.Controls.Add(combobox);
                }

                //Создание выпадающих списков для вложенных членов
                else
                {
                    ComboBox combobox = new ComboBox
                    {
                        Name           = fields[i].Name,
                        SelectionStart = 0,
                        DropDownStyle  = ComboBoxStyle.DropDownList,
                        Location       = new Point(15 + label.Width, 25 * (i + 1)),
                        Width          = base.Width - (label.Location.X + label.Width + 30)
                    };

                    //список объектов удовлетворяющих типу поля
                    List <object> SuitableItems = ObjectList.Where(WField => (WField.GetType() == fields[i].FieldType)).ToList();

                    //заполнение списка
                    for (int j = 0; j < SuitableItems.Count; j++)
                    {
                        var ObjField = SuitableItems[j].GetType().GetField("Identifer");
                        if (ObjField != null)
                        {
                            combobox.Items.Add(ObjField.GetValue(SuitableItems[j]));
                        }
                    }

                    //Установка связанного обьекта
                    var buf   = fields[i].GetValue(Obj);
                    int index = -1;

                    if (buf != null)
                    {
                        for (int j = 0; j < SuitableItems.Count; j++)
                        {
                            if (buf.Equals(SuitableItems[j]))
                            {
                                index = j; break;
                            }
                        }
                        combobox.SelectedIndex = index;
                    }

                    base.Controls.Add(combobox);
                }
            }

            //кнопка сохранения
            Button SaveBut = new Button
            {
                Name         = "SaveBut",
                Text         = "Save",
                Location     = new Point(base.Width / 2 - (base.Width / 8), (fields.Length + 1) * 25),
                Width        = base.Width / 4,
                DialogResult = DialogResult.OK,
            };

            GObj           = Obj;
            GObjectList    = ObjectList;
            SaveBut.Click += SaveAction;

            base.Controls.Add(SaveBut);

            //return form;
        }