/// <summary>实现 IDTCommandTarget 接口的 QueryStatus 方法。此方法在更新该命令的可用性时调用</summary> /// <param term='commandName'>要确定其状态的命令的名称。</param> /// <param term='neededText'>该命令所需的文本。</param> /// <param term='status'>该命令在用户界面中的状态。</param> /// <param term='commandText'>neededText 参数所要求的文本。</param> /// <seealso class='Exec' /> public void QueryStatus(string commandName, vsCommandStatusTextWanted neededText, ref vsCommandStatus status, ref object commandText) { if (neededText == vsCommandStatusTextWanted.vsCommandStatusTextWantedNone) { if (commandName == "BuffaloEntityConfig.Connect" || commandName == "BuffaloDBCreater.Connect") { SelectedShapesCollection selectedShapes = SelectedShapes; if (selectedShapes == null) { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusUnsupported | vsCommandStatus.vsCommandStatusInvisible; return; } bool findClass = false; 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; } status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; findClass = true; break; } if (findClass == false) { status = (vsCommandStatus)vsCommandStatus.vsCommandStatusUnsupported | vsCommandStatus.vsCommandStatusInvisible; return; } } status = (vsCommandStatus)vsCommandStatus.vsCommandStatusSupported | vsCommandStatus.vsCommandStatusEnabled; } }
/// <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(), "错误"); } } }