Example #1
0
        /// <summary>
        /// 显示配置框
        /// </summary>
        /// <param name="curProject"></param>
        /// <param name="docView"></param>
        /// <param name="dalNamespace"></param>
        public static void ShowConfig(ClassDesignerInfo desinfo, string dalNamespace)
        {
            DBConfigInfo dbinfo = DBConfigInfo.LoadInfo(desinfo);

            using (FrmDBSetting frmSetting = new FrmDBSetting())
            {
                frmSetting._selectedClassDesigner = desinfo;
                if (dbinfo == null)
                {
                    dbinfo             = new DBConfigInfo();
                    dbinfo.DbName      = DBConfigInfo.GetDbName(desinfo);
                    dbinfo.SummaryShow = SummaryShowItem.All;
                    dbinfo.FileName    = DBConfigInfo.GetFileName(desinfo);
                }
                frmSetting.Info        = dbinfo;
                frmSetting.SummaryItem = dbinfo.SummaryShow;
                if (frmSetting.ShowDialog() != DialogResult.OK)
                {
                    return;
                }
                if (string.IsNullOrEmpty(dbinfo.AppNamespace))
                {
                    dbinfo.AppNamespace = dalNamespace + "." + dbinfo.DbType;
                }

                dbinfo.SaveConfig(dbinfo.FileName);
                StaticConnection.ClearCacheOperate(dbinfo.DbName);
            }
        }
Example #2
0
        /// <summary>
        /// 获取类的创建语句
        /// </summary>
        /// <param name="type"></param>
        private void GetClassSQL()
        {
            _lstSql = new List <string>();
            List <KeyWordTableParamItem> lstTable = new List <KeyWordTableParamItem>();
            DBConfigInfo dbcinfo = FrmDBSetting.GetDBConfigInfo(DesignerInfo, "DataAccess.");
            DBInfo       dbInfo  = dbcinfo.CreateDBInfo();

            foreach (ClrClass curType in SelectedClass)
            {
                EntityConfig entity = new EntityConfig(curType, DesignerInfo);

                if (string.IsNullOrEmpty(entity.TableName) || !entity.IsTable)
                {
                    continue;
                }
                string typeName = null;
                Stack <EntityConfig>          stkConfig   = EntityConfig.GetEntity(entity, DesignerInfo);
                List <EntityParam>            lstParam    = new List <EntityParam>();
                List <TableRelationAttribute> lstRelation = new List <TableRelationAttribute>();
                string lastTableName = null;
                string lastSummary   = null;
                while (stkConfig.Count > 0)
                {
                    EntityConfig centity = stkConfig.Pop();
                    FillParams(centity, lstParam, lstRelation);
                    lastTableName = centity.TableName;
                    lastSummary   = centity.Summary;
                }
                KeyWordTableParamItem table = new KeyWordTableParamItem(lstParam, lstRelation, lastTableName, null);
                table.Description = lastSummary;
                lstTable.Add(table);
            }
            try
            {
                using (BatchAction ba = dbInfo.DefaultOperate.StarBatchAction())
                {
                    _lstSql = TableChecker.CheckTable(dbInfo, lstTable);
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("生成语句失败:" + ex.Message);
            }
            ShowSql();
        }
Example #3
0
        private void btnSubmit_Click(object sender, EventArgs e)
        {
            DBConfigInfo dbcinfo = FrmDBSetting.GetDBConfigInfo(DesignerInfo, "");
            DBInfo       dbInfo  = dbcinfo.CreateDBInfo();

            rtbOutput.Text = "";
            if (_lstSql == null || _lstSql.Count == 0)
            {
                return;
            }
            List <string> resault = DBChecker.ExecuteSQL(dbInfo.DefaultOperate, _lstSql);
            StringBuilder sbRet   = new StringBuilder();

            foreach (string res in resault)
            {
                sbRet.AppendLine(res);
            }
            rtbOutput.Text = sbRet.ToString();
        }
Example #4
0
        public static DBConfigInfo GetDBConfigInfo(ClassDesignerInfo info, string dalNamespace)
        {
            DBConfigInfo dbinfo = DBConfigInfo.LoadInfo(info);

            if (dbinfo == null)
            {
                using (FrmDBSetting frmSetting = new FrmDBSetting())
                {
                    frmSetting.Info.DbName = DBConfigInfo.GetDbName(info);
                    if (frmSetting.ShowDialog() != DialogResult.OK)
                    {
                        return(null);
                    }
                    dbinfo = frmSetting.Info;

                    dbinfo.AppNamespace = dalNamespace + "." + dbinfo.DbType;
                    dbinfo.FileName     = DBConfigInfo.GetFileName(info);
                    dbinfo.SaveConfig(dbinfo.FileName);
                    StaticConnection.ClearCacheOperate(dbinfo.DbName);
                }
            }
            return(dbinfo);
        }
Example #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(), "错误");
                }
            }
        }