Exemplo n.º 1
0
        /// <summary>
        /// 1.生成核心业务控制器
        /// [如果是在线编辑器需生成:this.ViewBag.OnlineEditorHtml],默认不生成[1个文件]
        /// [模板文件]:action/homecontroller.txt
        /// 生成文件名称:HomeController.cs
        /// </summary>
        private void CreateHomeController()
        {
            string ClassName = "Admin";
            string Table_Comment = "系统管理员";
            string Template_Name, Unit_Template, Content, MainContent, Textarea_Text;
            string Column_Name, Column_Type, Column_Length;

            //读取原文件内容到内存
            Template_Name = @"AutoCode/Model/action/homecontroller.txt";
            Content       = UtilFile.ReadFile2String(Template_Name);
            MainContent   = "";
            foreach (string Table_Name in TableList)
            {
                ClassName = Table_Name;
                if (TableInfoList.ContainsKey(Table_Name))
                {
                    Table_Comment = TableInfoList[Table_Name]["Comment"];
                    string[] t_c = Table_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    if (t_c.Length > 1)
                    {
                        Table_Comment = t_c[0];
                    }

                    Unit_Template = @"
        // 控制器:{$Table_Comment}
        // GET: /Home/{$ClassName}
        public ActionResult {$ClassName}()
        {{$Textarea_Text}
            return View();
        }
                ";
                    Dictionary <string, Dictionary <string, string> > FieldInfo = FieldInfos[Table_Name];
                    Textarea_Text = "";
                    foreach (KeyValuePair <String, Dictionary <string, string> > entry in FieldInfo)
                    {
                        Column_Name   = entry.Key;
                        Column_Type   = entry.Value["Type"];
                        Column_Length = entry.Value["Length"];
                        int iLength = UtilNumber.Parse(Column_Length);
                        if (ColumnIsTextArea(Column_Name, Column_Type, iLength))
                        {
                            Textarea_Text += "\"" + Column_Name + "\",";
                        }
                    }
                    if (!string.IsNullOrEmpty(Textarea_Text))
                    {
                        Textarea_Text = Textarea_Text.Substring(0, Textarea_Text.Length - 1);
                        Textarea_Text = @"
            this.ViewBag.OnlineEditorHtml = this.Load_Onlineditor(" + Textarea_Text + ");";
                    }
                    Unit_Template = Unit_Template.Replace("{$ClassName}", ClassName);
                    Unit_Template = Unit_Template.Replace("{$Textarea_Text}", Textarea_Text);

                    MainContent += Unit_Template.Replace("{$Table_Comment}", Table_Comment);
                }
            }
            Content = Content.Replace("{$MainContent}", MainContent);
            //存入目标文件内容
            UtilFile.WriteString2File(Save_Dir + "HomeController.cs", Content);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 2.生成上传文件控制器
        /// [模板文件]:action/uploadcontroller.txt
        /// 生成文件名称:UploadController.cs
        /// </summary>
        private void CreateUploadController()
        {
            string ClassName = "Admin";
            string InstanceName = "admin";
            string Table_Comment = "系统管理员";
            string Template_Name, Unit_Template, Content, MainContent;

            //读取原文件内容到内存
            Template_Name = @"AutoCode/Model/action/uploadcontroller.txt";
            Content       = UtilFile.ReadFile2String(Template_Name);
            MainContent   = "";
            foreach (string Table_Name in TableList)
            {
                ClassName = Table_Name;
                if (TableInfoList.ContainsKey(Table_Name))
                {
                    Table_Comment = TableInfoList[Table_Name]["Comment"];
                    string[] t_c = Table_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    if (t_c.Length > 1)
                    {
                        Table_Comment = t_c[0];
                    }
                    InstanceName  = UtilString.LcFirst(ClassName);
                    Unit_Template = @"
        /// <summary>
        /// 上传Excel文件:{$Table_Comment}
        /// </summary>
        /// <returns></returns>
        // POST: /Upload/Upload{$ClassName}/
        [HttpPost]
        public ActionResult Upload{$ClassName}(FormCollection form)
        {
            if (Request.Files.Count > 0){
                HttpPostedFileBase file = Request.Files[0];
                string fileName = Path.Combine(Gc.UploadPath, ""attachment"", ""{$InstanceName}"", ""{$InstanceName}"" + UtilDateTime.NowS() + "".xls"");
                file.SaveAs(fileName);

                JObject resultJ = ExtService{$ClassName}.import{$ClassName}(fileName);
                string result = JsonConvert.SerializeObject(resultJ);
                Response.Write(result);
            }else{
                Response.Write(""{'success':false,'data':'上传文件不能为空'}"");
            }
            return null;
        }
                ";
                    Unit_Template = Unit_Template.Replace("{$ClassName}", ClassName);
                    Unit_Template = Unit_Template.Replace("{$InstanceName}", InstanceName);
                    MainContent  += Unit_Template.Replace("{$Table_Comment}", Table_Comment);
                }
            }
            Content = Content.Replace("{$MainContent}", MainContent);
            //存入目标文件内容
            UtilFile.WriteString2File(Save_Dir + "UploadController.cs", Content);
        }
Exemplo n.º 3
0
        /// <summary>
        /// 2.后台首页功能列表显示【1个文件】
        /// [模板文件]:view/index.txt
        /// 生成文件名称:Index.cshtml
        /// </summary>
        private void CreateIndexView()
        {
            string Site_SEO = "Betterlife.Net网站框架";
            string ClassName = "Admin";
            string InstanceName = "admin";
            string Table_Comment = "系统管理员";
            string Template_Name, Unit_Template, Content;

            //读取原文件内容到内存
            Template_Name = @"AutoCode/Model/view/index.txt";
            Content       = UtilFile.ReadFile2String(Template_Name);
            string MainContent = "";

            foreach (string Table_Name in TableList)
            {
                ClassName = Table_Name;
                if (TableInfoList.ContainsKey(Table_Name))
                {
                    Table_Comment = TableInfoList[Table_Name]["Comment"];
                    string[] t_c = Table_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    if (t_c.Length > 1)
                    {
                        Table_Comment = t_c[0];
                    }
                    InstanceName  = UtilString.LcFirst(ClassName);
                    Unit_Template = @"
        <p>@Html.ActionLink(""{$Table_Comment}"", ""{$ClassName}"", ""Home"",null,new { id = ""{$InstanceName}"",title = ""{$Table_Comment}"",@class=""menuIcon""})</p>";
                    Unit_Template = Unit_Template.Replace("{$ClassName}", ClassName);
                    Unit_Template = Unit_Template.Replace("{$Table_Comment}", Table_Comment);
                    Unit_Template = Unit_Template.Replace("{$InstanceName}", InstanceName);
                    MainContent  += Unit_Template;
                }
            }
            MainContent = MainContent.Substring(2);
            Content     = Content.Replace("{$MainContent}", MainContent);
            Content     = Content.Replace("{$Site_SEO}", Site_SEO);


            //存入目标文件内容
            UtilFile.WriteString2File(Save_Dir + "Index.cshtml", Content);
        }
Exemplo n.º 4
0
        /// <summary>
        /// 2.生成上下文环境类【1个文件】
        /// [模板文件]:domain/context.txt
        /// 生成文件名称:BetterlifeNetEntities.Context.cs[EntitiesName+".Context.cs"]
        /// </summary>
        private void CreateContext()
        {
            string EntitiesName = AutoCodeBase.EntitiesName;
            string ClassName = "Admin";
            string Table_Comment = "系统管理员";
            string Template_Name, Unit_Template, Content, MainContent;

            //读取原文件内容到内存
            Template_Name = @"AutoCode/Model/domain/context.txt";
            Content       = UtilFile.ReadFile2String(Template_Name);
            MainContent   = "";
            foreach (string Table_Name in TableList)
            {
                ClassName = Table_Name;
                if (TableInfoList.ContainsKey(Table_Name))
                {
                    Table_Comment = TableInfoList[Table_Name]["Comment"];
                    string[] t_c = Table_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    if (t_c.Length > 1)
                    {
                        Table_Comment = t_c[0];
                    }

                    Unit_Template = @"
        /// <summary>
        /// {$Table_Comment}
        /// </summary>
        public DbSet<{$ClassName}> {$ClassName} { get; set; }
                ";

                    Unit_Template = Unit_Template.Replace("{$ClassName}", ClassName);
                    MainContent  += Unit_Template.Replace("{$Table_Comment}", Table_Comment);
                }
            }

            Content = Content.Replace("{$EntitiesName}", EntitiesName);
            Content = Content.Replace("{$MainContent}", MainContent);
            //存入目标文件内容
            UtilFile.WriteString2File(Save_Dir + EntitiesName + ".Context.cs", Content);
        }
Exemplo n.º 5
0
        /// <summary>
        /// 1.生成实体类【多个文件】
        /// [模板文件]:domain/domain.txt
        /// [生成文件名]:ClassName
        /// [生成文件后缀名]:.cs
        /// </summary>
        private void CreateDomain()
        {
            string ClassName = "Admin";
            string Table_Comment = "系统管理员";
            string Template_Name, Unit_Template, Content, Content_New;

            string UnitColumnDefine;
            string Column_Name, Column_Type, Column_Comment, Column_Null;
            string Relation_ClassName, Relation_InstanceName, Relation_Table_Name;
            string Relation_Unit_Template = "", Relation_Table_Comment = "", Relation_UnitColumnDefine = "";//相关列数据对象定义
            string OneHasMany_Table_Comment = "", OneHasMany_Unit_Template = "", OneHasMany_UnitColumnDefine = "";

            foreach (string Table_Name in TableList)
            {
                //读取原文件内容到内存
                Template_Name = @"AutoCode/Model/domain/domain.txt";
                Content       = UtilFile.ReadFile2String(Template_Name);
                ClassName     = Table_Name;
                if (TableInfoList.ContainsKey(Table_Name))
                {
                    Table_Comment = TableInfoList[Table_Name]["Comment"];
                    string[] t_c = Table_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                    if (t_c.Length > 1)
                    {
                        Table_Comment = "";
                        foreach (string Comment_Single_Line in t_c)
                        {
                            Table_Comment += "    /// " + Comment_Single_Line + "\r\n";
                        }
                    }
                    else
                    {
                        Table_Comment = "    /// " + Table_Comment;
                    }
                    Content_New = Content.Replace("{$ClassName}", ClassName);
                    Content_New = Content_New.Replace("{$Table_Comment}", Table_Comment);

                    Dictionary <string, Dictionary <string, string> > FieldInfo = FieldInfos[Table_Name];
                    UnitColumnDefine          = "";
                    Relation_UnitColumnDefine = ""; OneHasMany_UnitColumnDefine = "";
                    foreach (KeyValuePair <String, Dictionary <string, string> > entry in FieldInfo)
                    {
                        Column_Name    = entry.Key;
                        Column_Comment = entry.Value["Comment"];
                        Column_Type    = entry.Value["Type"];
                        string[] c_c = Column_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                        if (c_c.Length > 1)
                        {
                            Column_Comment = "";
                            foreach (string Comment_Single_Line in c_c)
                            {
                                Column_Comment += "        /// " + Comment_Single_Line + "\r\n";
                            }
                            Column_Comment = Column_Comment.Substring(0, Column_Comment.Length - 2);
                        }
                        else
                        {
                            Column_Comment = "        /// " + Column_Comment;
                        }
                        Unit_Template =
                            @"        /// <summary>
{$Column_Comment}
        /// </summary>
        public {$Column_Type} {$Column_Name} { get; set; }
";
                        bool IsNull = true;
                        Column_Null = entry.Value["Null"];
                        if (Column_Null.Equals("否"))
                        {
                            IsNull = false;
                        }
                        Column_Type       = ColumnTypeByDbDefine(Column_Type, Column_Name, IsNull);
                        Unit_Template     = Unit_Template.Replace("{$Column_Comment}", Column_Comment);
                        Unit_Template     = Unit_Template.Replace("{$Column_Type}", Column_Type);
                        Unit_Template     = Unit_Template.Replace("{$Column_Name}", Column_Name);
                        UnitColumnDefine += Unit_Template;
                        if (Column_Name.Contains("_ID"))
                        {
                            Relation_ClassName = Column_Name.Replace("_ID", "");
                            if (TableList.Contains(Relation_ClassName))
                            {
                                //读取原文件内容到内存
                                Template_Name         = @"AutoCode/Model/domain/httpdata.txt";
                                Content               = UtilFile.ReadFile2String(Template_Name);
                                Relation_InstanceName = UtilString.LcFirst(Relation_ClassName);
                                Relation_Table_Name   = Relation_ClassName;
                                if (TableInfoList.ContainsKey(Relation_Table_Name))
                                {
                                    Relation_Table_Comment = TableInfoList[Relation_Table_Name]["Comment"];
                                    t_c = Relation_Table_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                                    if (c_c.Length > 1)
                                    {
                                        Relation_Table_Comment = "";
                                        foreach (string Comment_Single_Line in c_c)
                                        {
                                            Relation_Table_Comment += "        /// " + Comment_Single_Line + "\r\n";
                                        }
                                        Relation_Table_Comment = Relation_Table_Comment.Substring(0, Column_Comment.Length - 2);
                                    }
                                    else
                                    {
                                        Relation_Table_Comment = "        /// " + Relation_Table_Comment;
                                    }
                                    //多对一关系需定义
                                    Relation_Unit_Template     = @"
        /// <summary>
{$Relation_Table_Comment}
        /// </summary>
        public virtual {$Relation_ClassName} {$Relation_ClassName} { get; set; }";
                                    Relation_Unit_Template     = Relation_Unit_Template.Replace("{$Relation_ClassName}", Relation_ClassName);
                                    Relation_Unit_Template     = Relation_Unit_Template.Replace("{$Relation_Table_Comment}", Relation_Table_Comment);
                                    Relation_UnitColumnDefine += Relation_Unit_Template;
                                }
                            }
                        }
                    }
                    if (OneHasManyDefine.ContainsKey(Table_Name))
                    {
                        List <string> lOneHasMany = OneHasManyDefine[Table_Name];
                        foreach (string OneHasMany_TableName in lOneHasMany)
                        {
                            OneHasMany_Table_Comment = TableInfoList[OneHasMany_TableName]["Comment"];
                            t_c = OneHasMany_Table_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                            if (t_c.Length > 1)
                            {
                                OneHasMany_Table_Comment = "";
                                foreach (string Comment_Single_Line in t_c)
                                {
                                    OneHasMany_Table_Comment += "        /// " + Comment_Single_Line + "\r\n";
                                }
                                OneHasMany_Table_Comment = OneHasMany_Table_Comment.Substring(0, OneHasMany_Table_Comment.Length - 2);
                            }
                            else
                            {
                                OneHasMany_Table_Comment = "        /// " + OneHasMany_Table_Comment;
                            }
                            OneHasMany_Unit_Template     = @"
        /// <summary>
{$OneHasMany_Table_Comment}
        /// </summary>
        public virtual ICollection<{$OneHasMany_TableName}> {$OneHasMany_TableName} { get; set; }
                        ";
                            OneHasMany_Unit_Template     = OneHasMany_Unit_Template.Replace("{$OneHasMany_Table_Comment}", OneHasMany_Table_Comment);
                            OneHasMany_Unit_Template     = OneHasMany_Unit_Template.Replace("{$OneHasMany_TableName}", OneHasMany_TableName);
                            OneHasMany_UnitColumnDefine += OneHasMany_Unit_Template;
                        }
                    }
                    UnitColumnDefine += Relation_UnitColumnDefine;
                    UnitColumnDefine += OneHasMany_UnitColumnDefine;

                    Content_New = Content_New.Replace("{$ColumnDefines}", UnitColumnDefine);

                    //存入目标文件内容
                    UtilFile.WriteString2File(Save_Dir + ClassName + ".cs", Content_New);
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// 3.生成枚举类【一个文件】
        /// [模板文件]:domain/enum.txt
        /// 生成文件名称:Enum.cs
        /// </summary>
        private void CreateEnum()
        {
            string ClassName = "Admin";
            string Table_Comment = "系统管理员";
            string Template_Name, Content;

            string Unit_Template;
            string EnumDefineBlock, EnumD2VBlock, EnumV2DBlock;
            string Column_Name, Column_Table_Name, Column_Type, Column_Comment, MainContent;
            List <Dictionary <string, string> > Enum_ColumnDefine;
            List <string> enumL = new List <string>();//如果重名只放一个

            MainContent = "";
            foreach (string Table_Name in TableList)
            {
                //读取原文件内容到内存
                ClassName = Table_Name;
                if (TableInfoList.ContainsKey(Table_Name))
                {
                    Table_Comment = TableInfoList[Table_Name]["Comment"];

                    Template_Name = @"AutoCode/Model/domain/enum.txt";
                    Content       = UtilFile.ReadFile2String(Template_Name);

                    Dictionary <string, Dictionary <string, string> > FieldInfo = FieldInfos[Table_Name];
                    foreach (KeyValuePair <String, Dictionary <string, string> > entry in FieldInfo)
                    {
                        Column_Name    = entry.Key;
                        Column_Comment = entry.Value["Comment"];
                        Column_Type    = entry.Value["Type"];

                        if (Column_Type.Equals("tinyint"))
                        {
                            string[] c_c = Column_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                            if (c_c.Length > 1)
                            {
                                if (!enumL.Contains(Column_Name))
                                {
                                    enumL.Add(Column_Name);
                                    Enum_ColumnDefine = EnumDefines(Column_Comment);
                                    if ((Enum_ColumnDefine != null) && (Enum_ColumnDefine.Count > 0))
                                    {
                                        EnumDefineBlock = ""; EnumD2VBlock = ""; EnumV2DBlock = "";
                                        foreach (Dictionary <string, string> ColumnDefine in Enum_ColumnDefine)
                                        {
                                            ColumnDefine["Name"] = UtilString.UcFirst(ColumnDefine["Name"]);
                                            EnumDefineBlock     += "        /// <summary>\r\n" +
                                                                   "        /// " + ColumnDefine["Comment"] + "\r\n" +
                                                                   "        /// </summary>\r\n" +
                                                                   "        public const byte " + ColumnDefine["Name"] + " = " + ColumnDefine["Value"] + ";\r\n";
                                            EnumD2VBlock += "                case " + ColumnDefine["Name"] + ":\r\n" +
                                                            "                    return \"" + ColumnDefine["Comment"] + "\";\r\n";
                                            EnumV2DBlock += "                case \"" + ColumnDefine["Comment"] + "\":\r\n" +
                                                            "                    result= " + ColumnDefine["Name"] + ";\r\n" +
                                                            "                    break;\r\n";
                                        }

                                        Unit_Template     = @"
    /// <summary>
    /// {$Column_Comment}
    /// </summary>
    public class Enum{$Column_Table_Name}
    {
{$EnumDefineBlock}
        /// <summary>
        /// 显示{$Column_Comment}
        /// </summary>
        public static String {$Column_Name}Show(byte? {$Column_Name})
        {
            switch ({$Column_Name})
            {
{$EnumD2VBlock}
            }
            return ""未知"";
        }

        /// <summary>
        /// 根据{$Column_Comment}显示文字获取{$Column_Comment}
        /// </summary>
        public static byte? {$Column_Name}ByShow(string Content)
        {
            byte result=byte.MinValue;
            switch (Content)
            {
{$EnumV2DBlock}
            }
            return result;
        }
    }
";
                                        Unit_Template     = Unit_Template.Replace("{$EnumDefineBlock}", EnumDefineBlock);
                                        Unit_Template     = Unit_Template.Replace("{$EnumD2VBlock}", EnumD2VBlock);
                                        Unit_Template     = Unit_Template.Replace("{$EnumV2DBlock}", EnumV2DBlock);
                                        Unit_Template     = Unit_Template.Replace("{$Column_Name}", Column_Name);
                                        Column_Table_Name = Column_Name;
                                        if (Array.IndexOf(Same_Column_Names, Column_Name) > -1)
                                        {
                                            Column_Table_Name = ClassName + "_" + Column_Name;
                                        }
                                        Unit_Template = Unit_Template.Replace("{$Column_Table_Name}", Column_Table_Name);

                                        Column_Comment = c_c[0];
                                        Unit_Template  = Unit_Template.Replace("{$Column_Comment}", Column_Comment);
                                        MainContent   += Unit_Template;
                                    }
                                }
                            }
                        }
                    }
                    Content = Content.Replace("{$MainContent}", MainContent);

                    //存入目标文件内容
                    UtilFile.WriteString2File(Save_Dir + "Enum.cs", Content);
                }
            }
        }