Esempio n. 1
0
        /// <summary>实现 IDTExtensibility2 接口的 OnConnection 方法。接收正在加载外接程序的通知。</summary>
        /// <param term='application'>宿主应用程序的根对象。</param>
        /// <param term='connectMode'>描述外接程序的加载方式。</param>
        /// <param term='addInInst'>表示此外接程序的对象。</param>
        /// <seealso class='IDTExtensibility2' />
        public void OnConnection(object application, ext_ConnectMode connectMode, object addInInst, ref Array custom)
        {
            _applicationObject = (DTE2)application;
            _addInInstance     = (AddIn)addInInst;

            m_serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(_applicationObject as Microsoft.VisualStudio.OLE.Interop.IServiceProvider);
            if (connectMode == ext_ConnectMode.ext_cm_Startup)
            {
                try
                {
                    _commands = (Commands2)_applicationObject.Commands;
                    _commitem.Install(_applicationObject, _addInInstance, _commands);

                    string err = InitBaseCode.InitBaseDll();
                    if (err != null)
                    {
                        FrmCompileResault.ShowCompileResault(null, err, "错误");
                    }
                }
                catch (Exception ex)
                {
                    FrmCompileResault.ShowCompileResault(null, ex.ToString(), "错误");
                }
            }
        }
Esempio n. 2
0
        ///// <summary>
        ///// 选中的文档视图
        ///// </summary>
        //private ClassDesignerDocView _selectDocView;

        ///// <summary>
        ///// 选中的文档视图
        ///// </summary>
        //public ClassDesignerDocView SelectDocView
        //{
        //    get { return _selectDocView; }
        //    set { _selectDocView = value; }
        //}
        private void FrmDBCreate_Load(object sender, EventArgs e)
        {
            if (SelectedClass != null)
            {
                try
                {
                    GetClassSQL();
                }
                catch (Exception ex)
                {
                    FrmCompileResault.ShowCompileResault(null, ex.ToString(), "生成SQL错误");
                }
            }
            this.Text += ToolVersionInfo.ToolVerInfo;
        }
Esempio n. 3
0
        private void btnImp_Click(object sender, EventArgs e)
        {
            ComboBoxItem item = cmbType.SelectedItem as ComboBoxItem;

            if (item == null)
            {
                return;
            }

            ComboBoxItem conn    = item.Tag as ComboBoxItem;
            string       summary = conn.Value as string;

            if (!string.IsNullOrEmpty(summary))
            {
                FrmCompileResault.ShowCompileResault(summary, null, "注意事项");
            }
        }
Esempio n. 4
0
        private void labHelp_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            StringBuilder sbInfo = new StringBuilder();

            sbInfo.AppendLine("数据库生成语句缺少字段一般是由于多个数据项目相互引起的");
            sbInfo.AppendLine("由于本插件不可实现跨项目检测实体和数据库的映射");
            sbInfo.AppendLine("假设:B项目引用了A项目,B项目中的实体派生自A项目的实体基类,则会出现B项目生成数据库时候缺少字段的问题");
            sbInfo.AppendLine("\n");
            sbInfo.AppendLine("可以在程序启动时候执行以下语句获取准确的数据库架构升级语句:");
            StringBuilder sbCode = new StringBuilder();

            sbCode.AppendLine("Buffalo.DB.DataBaseAdapter.DataAccessLoader.AppendModelAssembly(typeof(InfoDB).Assembly);");
            sbCode.AppendLine("MyClass.GetDBinfo().GetUpdateDBText();");
            sbCode.AppendLine("MyClass.InitDB();");
            sbCode.AppendLine("string sql = MyClass.GetDBinfo().GetUpdateDBText();");
            sbCode.AppendLine("\n");
            sbCode.AppendLine("其中InfoDB为A项目的数据库类,MyClass为B项目的数据库");
            FrmCompileResault.ShowCompileResault(sbInfo.ToString(), sbCode.ToString(), "数据库生成语句不准确怎么办?");
        }
Esempio n. 5
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(), "错误");
                }
            }
        }