Esempio n. 1
0
        /// <summary>
        /// 获取所有类
        /// </summary>
        /// <returns></returns>
        public static List <ClrClass> GetAllClass(Diagram selectedDiagram)
        {
            ShapeElementMoveableCollection nestedChildShapes = selectedDiagram.NestedChildShapes;
            List <ClrClass> lstClass = new List <ClrClass>();
            IEnumerable     shapes   = nestedChildShapes as IEnumerable;

            if (shapes == null)
            {
                return(null);
            }
            foreach (ShapeElement element in shapes)
            {
                ClrClass classType = SummaryShape.GetClass(element);
                if (classType != null)
                {
                    lstClass.Add(classType);
                }
            }
            return(lstClass);
        }
        /// <summary>
        /// 显示或隐藏注释
        /// </summary>
        /// <param name="dia">图</param>
        public static void ShowOrHideSummary(Diagram dia, Connect conn)
        {
            ShapeElementMoveableCollection nestedChildShapes = dia.NestedChildShapes;
            ClrClassShape       shape  = null;
            ClrEnumerationShape shape2 = null;
            ClrInterfaceShape   shape3 = null;
            AssociationShape    shape4 = null;
            bool flag = true;

            DBConfigInfo    dbInfo   = DBConfigInfo.LoadInfo(conn.GetDesignerInfo());
            SummaryShowItem showInfo = SummaryShowItem.All;

            if (dbInfo != null)
            {
                showInfo = dbInfo.SummaryShow;
            }



            foreach (ShapeElement element in (IEnumerable)nestedChildShapes)
            {
                if (element is ClrClassShape)
                {
                    shape = element as ClrClassShape;
                    if (element.NestedChildShapes.Count > 0)
                    {
                        break;
                    }
                }
            }
            if (shape != null)
            {
                ShapeFieldCollection shapeFields = shape.ShapeFields;
                int index = -1;
                for (int i = 0; i < shapeFields.Count; i++)
                {
                    if (shapeFields[i] is SummaryShape)
                    {
                        index = i;
                        break;
                    }
                }
                if (index < 0)
                {
                    flag = true;
                    SummaryShape shapeField = new SummaryShape();
                    shapeFields.Add(shapeField);
                }
                else
                {
                    flag = false;
                    shapeFields.RemoveAt(index);
                }

                foreach (ShapeElement element2 in (IEnumerable)shape.NestedChildShapes)
                {
                    if (!(element2 is CDCompartment))
                    {
                        continue;
                    }
                    shapeFields = element2.ShapeFields;
                    index       = -1;
                    for (int j = 0; j < shapeFields.Count; j++)
                    {
                        if (shapeFields[j] is MemberSummary)
                        {
                            index = j;
                            break;
                        }
                    }
                    if (index < 0)
                    {
                        if (flag)
                        {
                            MemberSummary summary = new MemberSummary();

                            summary.FromAddin       = conn;
                            summary.SummaryShowInfo = showInfo;
                            shapeFields.Add(summary);
                        }
                    }
                    else if (!flag)
                    {
                        shapeFields.RemoveAt(index);
                    }
                    break;
                }
            }
            foreach (ShapeElement element3 in (IEnumerable)nestedChildShapes)
            {
                if (element3 is ClrEnumerationShape)
                {
                    shape2 = element3 as ClrEnumerationShape;
                    if (element3.NestedChildShapes.Count > 0)
                    {
                        break;
                    }
                }
            }

            if (shape2 != null)
            {
                ShapeFieldCollection fields2 = shape2.ShapeFields;
                int num4 = -1;
                for (int k = 0; k < fields2.Count; k++)
                {
                    if (fields2[k] is EnumSummary)
                    {
                        num4 = k;
                        break;
                    }
                }
                if (num4 < 0)
                {
                    if (flag)
                    {
                        EnumSummary summary2 = new EnumSummary();
                        fields2.Add(summary2);
                    }
                }
                else if (!flag)
                {
                    fields2.RemoveAt(num4);
                }
                foreach (ShapeElement element4 in (IEnumerable)shape.NestedChildShapes)
                {
                    if (!(element4 is CDCompartment))
                    {
                        continue;
                    }
                    fields2 = element4.ShapeFields;
                    num4    = -1;
                    for (int m = 0; m < fields2.Count; m++)
                    {
                        if (fields2[m] is EnumItemSummary)
                        {
                            num4 = m;
                            break;
                        }
                    }
                    if (num4 < 0)
                    {
                        if (flag)
                        {
                            EnumItemSummary summary3 = new EnumItemSummary();
                            summary3.FromAddin = conn;

                            summary3.SummaryShowInfo = showInfo;
                            fields2.Add(summary3);
                        }
                    }
                    else if (!flag)
                    {
                        fields2.RemoveAt(num4);
                    }
                    break;
                }
            }

            foreach (ShapeElement element5 in (IEnumerable)nestedChildShapes)
            {
                if (element5 is ClrInterfaceShape)
                {
                    shape3 = element5 as ClrInterfaceShape;
                    if (element5.NestedChildShapes.Count > 0)
                    {
                        break;
                    }
                }
            }
            if (shape3 != null)
            {
                ShapeFieldCollection fields3 = shape3.ShapeFields;
                int num7 = -1;
                for (int n = 0; n < fields3.Count; n++)
                {
                    if (fields3[n] is InterSummary)
                    {
                        num7 = n;
                        break;
                    }
                }
                if (num7 < 0)
                {
                    if (flag)
                    {
                        InterSummary summary4 = new InterSummary();
                        fields3.Add(summary4);
                    }
                }
                else if (!flag)
                {
                    fields3.RemoveAt(num7);
                }
                foreach (ShapeElement element6 in (IEnumerable)shape3.NestedChildShapes)
                {
                    if (!(element6 is CDCompartment))
                    {
                        continue;
                    }
                    fields3 = element6.ShapeFields;
                    num7    = -1;
                    for (int num9 = 0; num9 < fields3.Count; num9++)
                    {
                        if (fields3[num9] is MemberSummary)
                        {
                            num7 = num9;
                            break;
                        }
                    }
                    if (num7 < 0)
                    {
                        if (flag)
                        {
                            MemberSummary summary5 = new MemberSummary();

                            summary5.FromAddin       = conn;
                            summary5.SummaryShowInfo = showInfo;
                            fields3.Add(summary5);
                        }
                    }
                    else if (!flag)
                    {
                        fields3.RemoveAt(num7);
                    }
                    break;
                }
            }

            foreach (ShapeElement element7 in (IEnumerable)nestedChildShapes)
            {
                if (element7 is AssociationShape)
                {
                    shape4 = element7 as AssociationShape;
                }
            }
            if (shape4 != null)
            {
                ShapeFieldCollection fields4 = shape4.Label.ShapeFields;
                int num10 = -1;
                for (int num11 = 0; num11 < fields4.Count; num11++)
                {
                    if (fields4[num11] is AssLabelSummary)
                    {
                        num10 = num11;
                        break;
                    }
                }
                if (num10 < 0)
                {
                    if (flag)
                    {
                        AssLabelSummary summary6 = new AssLabelSummary();
                        fields4.Add(summary6);
                    }
                }
                else if (!flag)
                {
                    fields4.RemoveAt(num10);
                }
            }
        }
Esempio n. 3
0
        /// <summary>实现 IDTCommandTarget 接口的 Exec 方法。此方法在调用该命令时调用。</summary>
        /// <param term='commandName'>要执行的命令的名称。</param>
        /// <param term='executeOption'>描述该命令应如何运行。</param>
        /// <param term='varIn'>从调用方传递到命令处理程序的参数。</param>
        /// <param term='varOut'>从命令处理程序传递到调用方的参数。</param>
        /// <param term='handled'>通知调用方此命令是否已被处理。</param>
        /// <seealso class='Exec' />
        public void Exec(string commandName, vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
        {
            handled = false;
            if (executeOption == vsCommandExecOption.vsCommandExecOptionDoDefault)
            {
                try
                {
                    if (IsCommand(commandName, "BuffaloEntityConfig"))
                    {
                        SelectedShapesCollection selectedShapes = SelectedShapes;
                        if (selectedShapes == null)
                        {
                            return;
                        }
                        for (int i = 0; i < selectedShapes.Count; i++)
                        {
                            if (!(selectedShapes.TopLevelItems[i].Shape is ClrTypeShape))
                            {
                                continue;
                            }
                            ClrTypeShape sp = selectedShapes.TopLevelItems[i].Shape as ClrTypeShape;
                            if (!(sp.AssociatedType is ClrClass))
                            {
                                continue;
                            }
                            using (FrmClassDesigner st = new FrmClassDesigner())
                            {
                                Diagram selDiagram = SelectedDiagram;
                                st.SelectedClass = sp;
                                st.DesignerInfo  = GetDesignerInfo();
                                st.ShowDialog();
                            }
                        }
                        handled = true;
                        return;
                    }
                    else if (IsCommand(commandName, "BuffaloDBCreater"))
                    {
                        SelectedShapesCollection selectedShapes = SelectedShapes;
                        if (selectedShapes == null)
                        {
                            return;
                        }
                        List <ClrClass> lstClass = new List <ClrClass>();
                        for (int i = 0; i < selectedShapes.Count; i++)
                        {
                            if (!(selectedShapes.TopLevelItems[i].Shape is ClrTypeShape))
                            {
                                continue;
                            }
                            ClrTypeShape sp        = selectedShapes.TopLevelItems[i].Shape as ClrTypeShape;
                            ClrClass     classType = sp.AssociatedType as ClrClass;
                            if (classType == null)
                            {
                                continue;
                            }
                            lstClass.Add(classType);
                        }
                        using (FrmDBCreate st = new FrmDBCreate())
                        {
                            Diagram selDiagram = SelectedDiagram;
                            st.SelectedClass = lstClass;
                            //st.SelectDocView = SelectDocView;
                            //st.CurrentProject = CurrentProject;
                            //st.SelectedDiagram = selDiagram;
                            st.DesignerInfo = GetDesignerInfo();
                            st.ShowDialog();
                        }
                        handled = true;
                        return;
                    }

                    else if (IsCommand(commandName, "BuffaloDBToEntity"))
                    {
                        Diagram dia = SelectedDiagram;
                        if (!(dia is ShapeElement))
                        {
                            return;
                        }
                        using (FrmAllTables frmTables = new FrmAllTables())
                        {
                            //frmTables.SelectedDiagram = dia;
                            //frmTables.SelectDocView = SelectDocView;
                            //frmTables.CurrentProject = CurrentProject;
                            frmTables.DesignerInfo = GetDesignerInfo();
                            frmTables.ShowDialog();
                        }
                    }

                    else if (IsCommand(commandName, "BuffaloShowHideSummery"))
                    {
                        Diagram dia = this.SelectedDiagram;

                        if (dia != null)
                        {
                            VSConfigManager.InitConfig(_applicationObject.Version);
                            ShapeSummaryDisplayer.ShowOrHideSummary(dia, this);
                            this.SelectDocView.CurrentDesigner.ScrollDown();
                            this.SelectDocView.CurrentDesigner.ScrollUp();

                            handled = true;
                        }
                    }
                    else if (IsCommand(commandName, "BuffaloDBCreateAll"))
                    {
                        List <ClrClass> lstClass = GetAllClass(SelectedDiagram);
                        if (lstClass == null)
                        {
                            return;
                        }
                        using (FrmDBCreate st = new FrmDBCreate())
                        {
                            Diagram selDiagram = SelectedDiagram;
                            st.SelectedClass = lstClass;
                            //st.SelectDocView = SelectDocView;
                            //st.CurrentProject = CurrentProject;
                            //st.SelectedDiagram = selDiagram;
                            st.DesignerInfo = GetDesignerInfo();
                            st.ShowDialog();
                        }
                        handled = true;
                        return;
                    }
                    else if (IsCommand(commandName, "BuffaloDBSet"))
                    {
                        string dalNamespace = GetDesignerInfo().GetNameSpace() + ".DataAccess";
                        ShapeElementMoveableCollection nestedChildShapes = SelectedDiagram.NestedChildShapes;

                        FrmDBSetting.ShowConfig(GetDesignerInfo(), dalNamespace);
                    }
                    else if (IsCommand(commandName, "BuffaloEntityRemove"))
                    {
                        SelectedShapesCollection selectedShapes = SelectedShapes;
                        if (selectedShapes == null)
                        {
                            return;
                        }
                        for (int i = 0; i < selectedShapes.Count; i++)
                        {
                            if (!(selectedShapes.TopLevelItems[i].Shape is ClrTypeShape))
                            {
                                continue;
                            }
                            ClrTypeShape sp = selectedShapes.TopLevelItems[i].Shape as ClrTypeShape;
                            if (!(sp.AssociatedType is ClrClass))
                            {
                                continue;
                            }
                            EntityConfig entity = new EntityConfig(sp.AssociatedType,
                                                                   GetDesignerInfo());
                            //entity.SelectDocView = SelectDocView;
                            if (MessageBox.Show("是否要删除实体:" + entity.ClassName +
                                                " 及其相关的业务类?", "提示", MessageBoxButtons.YesNo,
                                                MessageBoxIcon.Question) == DialogResult.Yes)
                            {
                                EntityRemoveHelper.RemoveEntity(entity);
                            }
                        }
                    }

                    else if (IsCommand(commandName, "BuffaloUpdateEntityByDB"))
                    {
                        SelectedShapesCollection selectedShapes = SelectedShapes;
                        if (selectedShapes == null)
                        {
                            return;
                        }
                        for (int i = 0; i < selectedShapes.Count; i++)
                        {
                            if (!(selectedShapes.TopLevelItems[i].Shape is ClrTypeShape))
                            {
                                continue;
                            }
                            ClrTypeShape sp       = selectedShapes.TopLevelItems[i].Shape as ClrTypeShape;
                            ClrClass     curClass = sp.AssociatedType as ClrClass;
                            if (curClass == null)
                            {
                                continue;
                            }
                            EntityConfig entity = EntityConfig.GetEntityConfigByTable(curClass,
                                                                                      GetDesignerInfo());
                            entity.GenerateCode();
                        }
                        handled = true;
                        return;
                    }
                    if (IsCommand(commandName, "BuffaloUI"))
                    {
                        SelectedShapesCollection selectedShapes = SelectedShapes;
                        if (selectedShapes == null)
                        {
                            return;
                        }
                        for (int i = 0; i < selectedShapes.Count; i++)
                        {
                            if (!(selectedShapes.TopLevelItems[i].Shape is ClrTypeShape))
                            {
                                continue;
                            }
                            ClrTypeShape sp = selectedShapes.TopLevelItems[i].Shape as ClrTypeShape;
                            if (!(sp.AssociatedType is ClrClass))
                            {
                                continue;
                            }
                            using (FrmUIGenerater st = new FrmUIGenerater())
                            {
                                Diagram selDiagram = SelectedDiagram;
                                st.CurEntityInfo = new EntityInfo(sp.AssociatedType, GetDesignerInfo());
                                st.BindTargetProjects(AllProjects);
                                st.ShowDialog();
                            }
                        }
                        handled = true;
                        return;
                    }
                    if (IsCommand(commandName, "commandGenDal"))
                    {
                        GreanDataAccess();
                        return;
                    }
                }
                catch (Exception ex)
                {
                    FrmCompileResault.ShowCompileResault(null, ex.ToString(), "错误");
                }
            }
        }