Пример #1
0
        private void SetComponent(Component component)
        {
            if (InvokeRequired)
            {
                Invoke(new MethodInvoker(() => SetComponent(component)));
                return;
            }

            comboBoxComponents.SetSelectedItem(component);
        }
Пример #2
0
        private Component GetComponent()
        {
            if (InvokeRequired)
            {
                Component comp = null;
                Invoke(new MethodInvoker(() => comp = GetComponent()));
                return(comp);
            }

            return(comboBoxComponents.GetSelectedItem <Component>());
        }
Пример #3
0
        private void buttonOk_Click(object sender, EventArgs e)
        {
            if (Entity != null &&
                (textBoxNewComponentName.Text == NewComponentText ||
                 string.IsNullOrEmpty(textBoxNewComponentName.Text)))
            {
                MessageBox.Show(this, "Please enter a valid name for the new component.", "Invalid name", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            if (Entity != null)
            {
                NewComponent.Name = textBoxNewComponentName.Text;

                for (int i = 0; i < NewComponent.Properties.Count; i++)
                {
                    int nameIndex = 2 * i;
                    int typeIndex = nameIndex + 1;
                    NewComponent.Properties[i].Name = ((TextBox)ComponentControls[nameIndex]).Text;
                    NewComponent.Properties[i].Type = ((ComboBox)ComponentControls[typeIndex]).Text;
                }
                Entity.EntitySet.AddComponentSpecification(NewComponent);

                NewComponent.CreateImplementedComponentFor(Entity, textBoxComponentEntityName.Text);
                ArchAngel.Providers.EntityModel.Model.EntityLayer.Component component = NewComponent.GetImplementationFor(Entity);
                component.Name = textBoxComponentEntityName.Text;

                for (int i = 0; i < component.Properties.Count; i++)
                {
                    IColumn col = Properties[i].MappedColumn();
                    component.Properties[i].SetMappedColumn(col);
                }
            }
            else
            {
                ComponentToEdit.Name = textBoxComponentEntityName.Text;

                for (int i = 0; i < ComponentToEdit.Properties.Count; i++)
                {
                    int nameIndex = 2 * i;
                    int typeIndex = nameIndex + 1;
                    //ComponentToEdit.Properties[i].PropertyName = ((TextBox)ComponentControls[nameIndex]).Text;
                    //ComponentToEdit.Properties[i].Type = ((ComboBox)ComponentControls[typeIndex]).Text;
                }
            }
            Close();
        }
Пример #4
0
        public static string ProcessComponentTemplate(Entity entity, ArchAngel.Providers.EntityModel.Model.EntityLayer.Component component)
        {
            System.Text.StringBuilder sb = new StringBuilder(((SourceCodeMultiLineType)SharedData.CurrentProject.GetUserOption("ComponentTemplate")).Value);

            string specName      = component.Specification.Name;
            string componentName = component.Name;

            sb.Replace("#entity.Name#", entity.Name);
            sb.Replace("#component.Name#", component.Name);
            sb.Replace("#component.Type#", specName);

            bool usePrivateSetter = (bool)SharedData.CurrentProject.GetUserOption("UsePrivateSettersOnProperties") ||
                                    (bool)component.GetUserOptionValue("Component_UsePrivateSetter");

            ProcessIfStatement(sb, "component.SetterIsPrivate", usePrivateSetter);

            return(RemoveTrailingLineBreaks(sb.ToString()));
        }
Пример #5
0
        public FormRefactorToComponent(ArchAngel.Providers.EntityModel.Model.EntityLayer.Component component)
        {
            InitializeComponent();

            SetStyle(
                ControlStyles.UserPaint |
                ControlStyles.AllPaintingInWmPaint |
                ControlStyles.OptimizedDoubleBuffer, true);

            FontItem = new Font(Font.FontFamily.Name, 8F, FontStyle.Regular);
            FontType = new Font(Font.FontFamily.Name, 7F, FontStyle.Regular);

            FocusHelper     = new Slyce.Common.TextBoxFocusHelper(new TextBox[] { textBoxComponentEntityName, textBoxNewComponentName });
            ComponentToEdit = component;

            //Entity = entity;
            //Properties = properties;
            int maxHeight = Populate();

            ResizeForm(maxHeight);
        }
Пример #6
0
        private void SetComponent(Component component)
        {
            if(InvokeRequired)
            {
                Invoke(new MethodInvoker(() => SetComponent(component)));
                return;
            }

            comboBoxComponents.SetSelectedItem(component);
        }
Пример #7
0
 public ComponentMapping GetMappingFor(Component component)
 {
     return(componentMappings.FirstOrDefault(c => ReferenceEquals(c.ToComponent, component)));
 }
Пример #8
0
 public ITable GetMappedTableFor(Component component)
 {
     return(componentMappings.Where(c => ReferenceEquals(c.ToComponent, component)).Select(c => c.FromTable).FirstOrDefault());
 }
Пример #9
0
        private void Component_Click(object sender, MouseEventArgs e)
        {
            SelectedComponent = (ArchAngel.Providers.EntityModel.Model.EntityLayer.Component)((RawProperty)sender).Tag;

            if (e.Button == MouseButtons.Right)
            {
                foreach (ToolStripItem item in contextMenuStrip1.Items)
                    item.Visible = false;

                mnuRemoveComponent.Visible = true;
                mnuEditComponent.Visible = true;
                contextMenuStrip1.Show(Cursor.Position);
            }
        }
        private bool Save()
        {
            if (Entity == null)
                return false;

            if (ComponentSpecification == null)
            {
                MessageBox.Show(this, "No component selected.", "Component missing", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return false;
            }
            ArchAngel.Providers.EntityModel.Model.EntityLayer.Component component = ComponentSpecification.GetImplementationFor(Entity);

            if (component == null)
            {
                // Create a new mapping
                component = ComponentSpecification.CreateImplementedComponentFor(Entity, textBoxComponentName.Text);
            }
            component.Name = textBoxComponentName.Text;
            List<Column> columns = GetColumnsOfType(Entity, "xxx");
            int numTables = Entity.MappedTables().Count();

            for (int i = 0; i < ComponentSpecification.Properties.Count; i++)
            {
                if (ComboBoxes[i].SelectedItem != null)
                {
                    Column col = null;
                    string selectedName = ComboBoxes[i].SelectedItem.ToString();

                    if (numTables > 1)
                    {
                        foreach (Column c in columns)
                        {
                            if (string.Format("{0}.{1}  [{2}]", c.Parent.Name, c.Name, c.OriginalDataType) == selectedName)
                            {
                                col = c;
                                break;
                            }
                        }
                    }
                    else
                    {
                        foreach (Column c in columns)
                        {
                            if (string.Format("{0}  [{1}]", c.Name, c.OriginalDataType) == selectedName)
                            {
                                col = c;
                                break;
                            }
                        }
                    }
                    if (col == null)
                        throw new Exception("Column shouldn't be null");

                    component.Properties[i].SetMappedColumn(col);
                }
                else
                {
                    component.Properties[i].SetMappedColumn(null);
                }
            }
            return true;
        }
        private void Populate()
        {
            foreach (LabelX label in Labels)
                panelEx1.Controls.Remove(label);

            foreach (ComboBoxEx combo in ComboBoxes)
                panelEx1.Controls.Remove(combo);

            Labels.Clear();
            ComboBoxes.Clear();
            textBoxComponentName.Text = "";

            //labelComponentName.Text = string.Format("{0} fields", ComponentSpecification.Name);
            labelComponentName.Text = "Component fields";

            if (Entity == null)
            {
                pictureComponent.Visible = false;
                labelComponentName.Visible = false;
                pictureEntity.Visible = false;
                //labelColumns.Visible = false;
                labelColumns.Left = Gap;
                labelColumns.Text = "Select entity:";
                comboBoxExEntities.Left = labelColumns.Right + Gap;
                comboBoxExEntities.Visible = true;
                comboBoxExEntities.DisplayMember = "Name";
                comboBoxExEntities.Items.Clear();
                comboBoxExEntities.Items.AddRange(ComponentSpecification.EntitySet.Entities.ToArray());
                comboBoxExEntities.Top = Gap;// pictureBox1.Bottom + Gap;// labelColumns.Top;
                labelColumns.Top = comboBoxExEntities.Top;
                textBoxComponentName.Text = "";
                textBoxComponentName.Visible = false;
                labelComponentNameInput.Visible = false;
                int newWidth = comboBoxExEntities.Right + Gap;

                if (this.Width != newWidth)
                    this.Left = this.Left - (this.Width - newWidth);

                this.Width = newWidth;
            }
            else
            {
                textBoxComponentName.Visible = true;
                labelComponentNameInput.Visible = true;
                pictureComponent.Visible = true;
                labelComponentName.Visible = true;
                pictureEntity.Visible = true;
                labelColumns.Top = pictureEntity.Top;
                labelColumns.Visible = true;
                comboBoxExEntities.Visible = false;
                labelColumns.Text = "Mapped columns";

                //if (string.IsNullOrEmpty(textBoxComponentName.Text))
                //    textBoxComponentName.Text = "Not set";
            }
            if (ComponentSpecification != null)
            {
                comboBoxComponents.Visible = false;
                labelSelect.Visible = false;
                textBoxComponentName.Top = Gap;
                labelComponentNameInput.Top = Gap;

                ArchAngel.Providers.EntityModel.Model.EntityLayer.Component component = ComponentSpecification.GetImplementationFor(Entity);

                if (component != null)
                    textBoxComponentName.Text = component.Name;
            }
            else
            {
                comboBoxComponents.DisplayMember = "Name";

                foreach (var comp in Entity.EntitySet.ComponentSpecifications)
                    comboBoxComponents.Items.Add(comp);

                //if (comboBoxComponents.Items.Count > 0)
                //    comboBoxComponents.SelectedIndex = 0;

                comboBoxComponents.Top = Gap;
                labelSelect.Top = Gap;
                textBoxComponentName.Top = comboBoxComponents.Bottom + Gap * 3;
                labelComponentNameInput.Top = textBoxComponentName.Top;
            }

            int top = labelComponentName.Bottom + Gap * 2;

            if (Entity != null)
            {
                if (ComponentSpecification != null)
                {
                    foreach (var prop in ComponentSpecification.Properties)
                        Labels.Add(new LabelX() { Text = string.Format("{0}  [{1}]", prop.Name, prop.Type) });

                    ArchAngel.Providers.EntityModel.Model.EntityLayer.Component component = ComponentSpecification.GetImplementationFor(Entity);
                    int numTables = Entity.MappedTables().Count();

                    if (component != null)
                    {
                        foreach (var prop in component.Properties)
                        {
                            List<Column> columns = GetColumnsOfType(Entity, prop.RepresentedProperty.Type);
                            ComboBoxEx combo = new ComboBoxEx();
                            combo.Width = 200;

                            foreach (Column column in columns)
                            {
                                if (numTables > 1)
                                    combo.Items.Add(string.Format("{0}.{1}  [{2}]", column.Parent.Name, column.Name, column.OriginalDataType));
                                else
                                    combo.Items.Add(string.Format("{0}  [{1}]", column.Name, column.OriginalDataType));
                            }
                            combo.DropDownStyle = ComboBoxStyle.DropDownList;
                            IColumn col = prop.MappedColumn();

                            if (col != null)
                            {
                                if (numTables > 1)
                                    combo.SelectedItem = string.Format("{0}.{1}  [{2}]", col.Parent.Name, col.Name, col.OriginalDataType);
                                else
                                    combo.SelectedItem = string.Format("{0}  [{1}]", col.Name, col.OriginalDataType);
                            }
                            ComboBoxes.Add(combo);
                        }
                    }
                    else
                    {
                        // Get the properties of the component specification
                        foreach (var prop in ComponentSpecification.Properties)
                        {
                            List<Column> columns = GetColumnsOfType(Entity, prop.Type);
                            ComboBoxEx combo = new ComboBoxEx();
                            combo.Width = 200;

                            foreach (Column column in columns)
                            {
                                if (numTables > 1)
                                    combo.Items.Add(string.Format("{0}.{1}  [{2}]", column.Parent.Name, column.Name, column.OriginalDataType));
                                else
                                    combo.Items.Add(string.Format("{0}  [{1}]", column.Name, column.OriginalDataType));
                            }
                            combo.DropDownStyle = ComboBoxStyle.DropDownList;
                            ComboBoxes.Add(combo);
                        }
                    }
                }

                int maxLeftColumnWidth = Math.Max(GetWidestLabel(Labels), Gap + pictureComponent.Width + labelComponentName.Width);
                int maxRightColumnWidth = Math.Max(GetWidestComboBox(ComboBoxes), pictureEntity.Width + labelColumns.Width + Gap);
                Graphics labelGraphics = null;

                if (ComponentSpecification != null)
                {
                    for (int i = 0; i < ComponentSpecification.Properties.Count; i++)
                    {
                        LabelX label = Labels[i];
                        panelEx1.Controls.Add(label);
                        //label.BackColor = Color.Transparent;
                        //label.ForeColor = Color.White;
                        if (labelGraphics == null)
                            labelGraphics = Graphics.FromHwnd(label.Handle);

                        SizeF size = Graphics.FromHwnd(label.Handle).MeasureString(label.Text, label.Font);
                        label.Height = Convert.ToInt32(size.Height) + 1;
                        label.Width = Convert.ToInt32(size.Width) + 1;
                        label.Top = top;
                        label.Left = Math.Max(Gap, Gap + maxLeftColumnWidth - label.Width);
                        label.BringToFront();

                        if (Entity != null)
                        {
                            ComboBoxEx comboBox = ComboBoxes[i];
                            panelEx1.Controls.Add(comboBox);
                            comboBox.Top = top;
                            comboBox.Left = Gap * 10 + maxLeftColumnWidth + 60;
                            comboBox.Width = maxRightColumnWidth;
                            comboBox.BringToFront();

                            label.Top = top + comboBox.Height / 2 - label.Height / 2;
                            top += comboBox.Height + 2;
                        }
                        else
                            top += label.Height + 2;
                    }
                }

                pictureComponent.Left = Gap;
                labelComponentName.Left = pictureComponent.Right;
                pictureEntity.Left = Gap * 10 + maxLeftColumnWidth + 60;
                labelColumns.Left = pictureEntity.Right;
                comboBoxExEntities.Left = pictureEntity.Right;
                comboBoxExEntities.Top = labelColumns.Top;
                int newWidth = Gap * 10 + maxLeftColumnWidth + 60 + maxRightColumnWidth + Gap * 3;

                if (this.Width != newWidth)
                    this.Left = this.Left - (this.Width - newWidth);

                this.Width = newWidth;
            }
            this.Height = top + Gap * 15 + buttonOk.Height;
        }
Пример #12
0
 public ComponentMapping GetMappingFor(Component component)
 {
     return componentMappings.FirstOrDefault(c => ReferenceEquals(c.ToComponent, component));
 }
Пример #13
0
 public ITable GetMappedTableFor(Component component)
 {
     return componentMappings.Where(c => ReferenceEquals(c.ToComponent, component)).Select(c => c.FromTable).FirstOrDefault();
 }