/// <summary>
        /// 生成代码
        /// </summary>
        /// <param name="code">代码行</param>
        /// <param name="tiers">层数</param>
        public void GreanCode(XmlDocument doc)
        {
            string model = Buffalo.DBTools.Models.Entity;

            string baseType = BaseType;



            List <string> codes = new List <string>();

            using (StringReader reader = new StringReader(model))
            {
                string tmp = null;
                while ((tmp = reader.ReadLine()) != null)
                {
                    tmp = tmp.Replace("<%=EntityNamespace%>", EntityNamespace);
                    tmp = tmp.Replace("<%=Summary%>", _belongTable.Description);
                    tmp = tmp.Replace("<%=EntityBaseType%>", baseType);
                    tmp = tmp.Replace("<%=ClassName%>", ClassName);
                    tmp = tmp.Replace("<%=EntityFields%>", BildFields());
                    tmp = tmp.Replace("<%=EntityRelations%>", BildRelations());
                    tmp = tmp.Replace("<%=EntityContext%>", BuildContext());
                    codes.Add(tmp);
                }
            }
            string eFile = GetEntityFileName(FileName);

            CodeFileHelper.SaveFile(eFile, codes);
            EnvDTE.ProjectItem newit = DesignerInfo.CurrentProject.ProjectItems.AddFromFile(eFile);
            newit.Properties.Item("BuildAction").Value = (int)BuildAction.Code;

            GenerateExtendCode();

            BQLEntityGenerater bqlEntity = new BQLEntityGenerater(this, DesignerInfo);

            GenerateExtendCode();
            if (_currentDBConfigInfo.Tier == 3)
            {
                Generate3Tier g3t = new Generate3Tier(this, DesignerInfo);
                g3t.GenerateBusiness();
                if (!string.IsNullOrEmpty(this._belongTable.Name))
                {
                    g3t.GenerateIDataAccess();
                    g3t.GenerateDataAccess();
                    g3t.GenerateBQLDataAccess();
                }
            }
            bqlEntity.GenerateBQLEntityDB();
            bqlEntity.GenerateBQLEntity();
            EntityMappingConfig.SaveXML(this);
            SetToDiagram(doc);
        }
Exemple #2
0
        /// <summary>
        /// 生成数据层
        /// </summary>
        private void GreanDataAccess()
        {
            ClassDesignerInfo cinfo    = GetDesignerInfo();
            List <ClrClass>   lstClass = Connect.GetAllClass(cinfo.SelectedDiagram);

            using (FrmProcess frmLoading = FrmProcess.ShowProcess())
            {
                frmLoading.UpdateProgress(0, 0, "正在生成类");

                for (int i = 0; i < lstClass.Count; i++)
                {
                    ClrClass      cls    = lstClass[i];
                    EntityConfig  entity = new EntityConfig(cls, cinfo);
                    Generate3Tier g3t    = new Generate3Tier(entity);
                    if (!string.IsNullOrEmpty(entity.TableName))
                    {
                        g3t.GenerateIDataAccess();
                        g3t.GenerateDataAccess();
                        g3t.GenerateBQLDataAccess();
                    }
                    frmLoading.UpdateProgress(i + 1, lstClass.Count, "正在生成");
                }
            }
        }