/// <summary>
        /// 生成实体类代码
        /// </summary>
        public string CreatControllers()
        {
            string strclass = BuilderTools.LoadTemplate("code/Controllers.txt");

            strclass = this.ReplaceAll(strclass, eControllersCode);
            return(strclass.ToString());
        }
        /// <summary>
        /// 生成实体类代码
        /// </summary>
        public string CreatDAL()
        {
            string strclass = BuilderTools.LoadTemplate("code/DAL.txt");

            eDALCode.strwhere       = this.GetWhereCode();
            eDALCode.insertsql      = this.GetInsertSql();
            eDALCode.updatesql      = this.GetUpdateSql();
            eDALCode.primarykeyname = this.GetPrimaryKeyName();
            strclass = this.ReplaceAll(strclass, eDALCode);
            return(strclass.ToString());
        }
        /// <summary>
        /// 获取查询条件代码
        /// </summary>
        /// <returns></returns>
        private string GetWhereCode()
        {
            StringBuilder strcode = new StringBuilder();

            foreach (ColumnInfo field in eDALCode.Fieldlist)
            {
                if (field.Description.IndexOf("search") > -1)
                {
                    string columnType = CodeCommon.DbTypeToCS(field.TypeName);
                    string AttrType   = BuilderTools.GetAttrType(columnType); //属性数据类型
                    string where = $"" + '"' + $"{field.ColumnName} = @{field.ColumnName}" + '"';
                    string description = field.Description.Replace(":search", "");
                    switch (AttrType)
                    {
                    case "int":
                        strcode.Append(@"
            if (model." + field.ColumnName + " > 0) //" + description + @"
            {
                strWhere.AddWhere(" + where + @");
            }");
                        break;

                    case "string":
                        strcode.Append(@"
            if (!string.IsNullOrEmpty(model." + field.ColumnName + ")) //" + description + @"
            {
                strWhere.AddWhere(" + where + @");
            }");
                        break;

                    case "DateTime":
                        strcode.Append(@"
            if (model." + field.ColumnName + " != null) //" + description + @"
            {
                strWhere.AddWhere(" + where + @");
            }");
                        break;
                    }
                }
            }
            return(strcode.ToString());
        }
Пример #4
0
        /// <summary>
        /// 生成属性集合
        /// </summary>
        public string CreatModelMethod()
        {
            StringBuilder strclass = new StringBuilder();

            foreach (ColumnInfo field in eModelCode.Fieldlist)
            {
                string columnName   = field.ColumnName;                     //列名
                string columnTypedb = field.TypeName;                       //类型
                bool   IsIdentity   = field.IsIdentity;                     //是否自增标识
                bool   ispk         = field.IsPrimaryKey;                   //是否主键
                bool   cisnull      = field.Nullable;                       //
                string deText       = field.Description;                    //属性说明
                string columnType   = CodeCommon.DbTypeToCS(columnTypedb);
                string AttrType     = BuilderTools.GetAttrType(columnType); //属性数据类型

                strclass.Append($@"
        /// <summary>
        /// {deText}
        /// </summary>
        public {AttrType} {columnName} ");
                strclass.AppendLine("{ get; set; }");
            }
            return(strclass.ToString());
        }