예제 #1
0
        /// <summary>
        /// 生成数据层
        /// </summary>
        /// <param name="entity"></param>
        public void GenerateDataAccess()
        {
            //FileInfo info = new FileInfo(EntityFileName);


            string dicPath = GenerateBasePath + "\\DataAccess";

            if (!Directory.Exists(dicPath))
            {
                Directory.CreateDirectory(dicPath);
            }
            string dal = Models.DataAccess;

            foreach (ComboBoxItem itype in DataAccessTypes)
            {
                if (!this.BbConfig.IsAllDal && !this.BbConfig.DbType.Equals(itype.Value))
                {
                    continue;
                }
                string type    = itype.Value.ToString();
                string dalPath = dicPath + "\\" + type;
                if (!Directory.Exists(dalPath))
                {
                    Directory.CreateDirectory(dalPath);
                }
                string fileName = dalPath + "\\" + ClassName + "DataAccess.cs";
                if (File.Exists(fileName))
                {
                    continue;
                }

                List <string> codes = new List <string>();
                using (StringReader reader = new StringReader(dal))
                {
                    string tmp = null;
                    while ((tmp = reader.ReadLine()) != null)
                    {
                        tmp = tmp.Replace("<%=EntityNamespace%>", EntityNamespace);
                        tmp = tmp.Replace("<%=Summary%>", Table.Description);
                        tmp = tmp.Replace("<%=DataAccessNamespace%>", DataAccessNamespace);
                        tmp = tmp.Replace("<%=DataBaseType%>", type);
                        tmp = tmp.Replace("<%=ClassName%>", ClassName);
                        codes.Add(tmp);
                    }
                }
                dmt.AppendDal(DataAccessNamespace + "." + type + "." + ClassName + "DataAccess", DataAccessNamespace + ".IDataAccess.I" + ClassName + "DataAccess");
                dmt.AppendBo(BusinessNamespace + "." + ClassName + "Business", EntityNamespace + "." + ClassName);
                CodeFileHelper.SaveFile(fileName, codes);
                EnvDTE.ProjectItem newit = DesignerInfo.CurrentProject.ProjectItems.AddFromFile(fileName);
                newit.Properties.Item("BuildAction").Value = (int)BuildAction.Code;
            }
            dmt.SaveXML();
        }
예제 #2
0
        public static void RemoveEntity(EntityConfig entity)
        {
            FileInfo info = new FileInfo(entity.DesignerInfo.SelectDocView.DocData.FileName);

            //业务层
            string fileName = info.DirectoryName + "\\Business\\" + entity.ClassName + "Business.cs";;

            RemoveFromProject(fileName, entity.DesignerInfo);

            //数据层
            string dicPath = info.DirectoryName + "\\DataAccess";

            entity.InitDBConfig();
            DataAccessMappingConfig dalconfig = new DataAccessMappingConfig(entity);

            foreach (ComboBoxItem itype in Generate3Tier.DataAccessTypes)
            {
                string type    = itype.Value.ToString();
                string dalPath = dicPath + "\\" + type;
                fileName = dalPath + "\\" + entity.ClassName + "DataAccess.cs";
                RemoveFromProject(fileName, entity.DesignerInfo);

                dalconfig.DeleteDal(dalconfig.DataAccessNamespace + "." + type + "." + entity.ClassName + "DataAccess");
                dalconfig.DeleteBo(dalconfig.BusinessNamespace + "." + entity.ClassName + "Business");
            }
            dalconfig.SaveXML();
            string idalPath = dicPath + "\\IDataAccess";

            fileName = idalPath + "\\I" + entity.ClassName + "DataAccess.cs";
            RemoveFromProject(fileName, entity.DesignerInfo);
            idalPath = dicPath + "\\Bql";
            fileName = idalPath + "\\" + entity.ClassName + "DataAccess.cs";
            RemoveFromProject(fileName, entity.DesignerInfo);



            //删除BQLEntity
            fileName = info.DirectoryName + "\\BQLEntity\\" + entity.ClassName + ".cs";
            RemoveFromProject(fileName, entity.DesignerInfo);

            //BEM.xml
            fileName = info.DirectoryName + "\\BEM\\" + entity.ClassName + ".BEM.xml";
            RemoveFromProject(fileName, entity.DesignerInfo);

            //移除实体
            fileName = entity.FileName;
            RemoveFromProject(fileName, entity.DesignerInfo);
            fileName = entity.FileName.Replace(".cs", ".extend.cs");
            RemoveFromProject(fileName, entity.DesignerInfo);
        }