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>
        /// 1.后台普通的显示cshtml文件【多个文件】
        ///       如果是大文本列,需生成@Html.Raw(ViewBag.OnlineEditorHtml),默认不生成
        /// [模板文件]:view/view.txt
        /// [生成文件名称]:ClassName
        /// [生成文件后缀名]:.cshtml
        /// </summary>
        private void CreateNormalView()
        {
            string ClassName = "Admin";
            string InstanceName = "admin";
            string Table_Comment = "系统管理员";
            string Template_Name, Content, Content_New, OnlineEditorHtml = "", ComboTreeInitHtml = "";
            string Relation_Table_Name;
            string Column_Name, Column_Type, Column_Length;

            foreach (string Table_Name in TableList)
            {
                //读取原文件内容到内存
                Template_Name     = @"AutoCode/Model/view/view.txt";
                Content           = UtilFile.ReadFile2String(Template_Name);
                ClassName         = Table_Name;
                ComboTreeInitHtml = "";
                OnlineEditorHtml  = "";
                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);

                    Content_New = Content.Replace("{$ClassName}", ClassName);
                    Content_New = Content_New.Replace("{$Table_Comment}", Table_Comment);
                    Content_New = Content_New.Replace("{$InstanceName}", InstanceName);

                    Dictionary <string, Dictionary <string, string> > FieldInfo = FieldInfos[Table_Name];
                    foreach (KeyValuePair <String, Dictionary <string, string> > entry in FieldInfo)
                    {
                        Column_Name         = entry.Key;
                        Column_Type         = entry.Value["Type"];
                        Column_Length       = entry.Value["Length"];
                        Relation_Table_Name = Column_Name.Replace("_ID", "");
                        if (Relation_Table_Name.ToUpper().Equals("PARENT"))
                        {
                            ComboTreeInitHtml = @"
    <script type=""text/javascript"" src=""@Url.Content(""~/Content/common/js/ajax/ext/shared/components/ComboBoxTree.js"")""></script>";
                        }

                        int iLength = UtilNumber.Parse(Column_Length);
                        if (ColumnIsTextArea(Column_Name, Column_Type, iLength))
                        {
                            OnlineEditorHtml = "	@Html.Raw(ViewBag.OnlineEditorHtml)";
                        }
                    }

                    Content_New = Content_New.Replace("{$OnlineEditorHtml}", OnlineEditorHtml);
                    Content_New = Content_New.Replace("{$ComboTreeInitHtml}", ComboTreeInitHtml);

                    //存入目标文件内容
                    UtilFile.WriteString2FileEncodingGbk(Save_Dir + ClassName + ".cshtml", Content_New);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///  1.Core/Service服务层所有的服务业务类|接口【多个文件】
        /// [模板文件]:service/service.txt|service/iservice.txt
        /// [生成文件名称]:"Service"+ClassName|"IService"+ClassName
        /// [生成文件后缀名]:.cs
        /// </summary>
        private void CreateNormalService()
        {
            string ClassName = "Admin";
            string InstanceName = "admin";
            string Table_Comment = "系统管理员";
            string Template_Name, Content, Content_New;
            string ID_Type, ID_Default_Value;

            foreach (string Table_Name in TableList)
            {
                //读取原文件内容到内存
                Template_Name = @"AutoCode/Model/service/iservice.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 = t_c[0];
                    }
                    InstanceName = UtilString.LcFirst(ClassName);

                    Dictionary <string, Dictionary <string, string> > FieldInfo = FieldInfos[Table_Name];
                    Dictionary <string, string> entry = FieldInfo["ID"];
                    if (entry["Type"].Equals("uniqueidentifier"))
                    {
                        ID_Type          = "Guid";
                        ID_Default_Value = "null";
                    }
                    else
                    {
                        ID_Type          = "int";
                        ID_Default_Value = "0";
                    }

                    Content_New = Content.Replace("{$ClassName}", ClassName);
                    Content_New = Content_New.Replace("{$Table_Comment}", Table_Comment);
                    Content_New = Content_New.Replace("{$InstanceName}", InstanceName);
                    Content_New = Content_New.Replace("{$ID_Type}", ID_Type);

                    //存入目标文件内容
                    UtilFile.WriteString2File(Save_Dir + "IService" + ClassName + ".cs", Content_New);

                    //读取原文件内容到内存
                    Template_Name = @"AutoCode/Model/service/service.txt";
                    Content       = UtilFile.ReadFile2String(Template_Name);
                    Content_New   = Content.Replace("{$ClassName}", ClassName);
                    Content_New   = Content_New.Replace("{$Table_Comment}", Table_Comment);
                    InstanceName  = UtilString.LcFirst(ClassName);
                    Content_New   = Content_New.Replace("{$InstanceName}", InstanceName);
                    Content_New   = Content_New.Replace("{$ID_Type}", ID_Type);
                    Content_New   = Content_New.Replace("{$ID_Default_Value}", ID_Default_Value);

                    //存入目标文件内容
                    UtilFile.WriteString2File(Save_Dir + "Service" + ClassName + ".cs", Content_New);
                }
            }
        }
Exemplo n.º 4
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.º 5
0
        /// <summary>
        /// 3.Portal 网站主体的ManageService工具类
        /// </summary>
        /// [模板文件]:service/manageservice.txt
        /// 生成文件名称:ManageService.cs
        private void CreateManageService()
        {
            string Content = "";
            string ClassName, InstanceName, Table_Comment, UnitTemplate;
            string ServiceDefine = "", ServiceMethod = "";
            //读取原文件内容到内存
            string Template_Name = @"AutoCode/Model/service/manageservice.txt";

            Content = UtilFile.ReadFile2String(Template_Name);

            foreach (string Table_Name in TableList)
            {
                ClassName     = Table_Name;
                Table_Comment = "";
                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);
                UnitTemplate   = @"
        /// <summary>
        /// {$Table_Comment}服务
        /// </summary>
        private static IService{$ClassName} {$InstanceName}Service;";
                UnitTemplate   = UnitTemplate.Replace("{$InstanceName}", InstanceName);
                UnitTemplate   = UnitTemplate.Replace("{$ClassName}", ClassName);
                UnitTemplate   = UnitTemplate.Replace("{$Table_Comment}", Table_Comment);
                ServiceDefine += UnitTemplate;
                UnitTemplate   = @"
        /// <summary>
        /// 服务:{$Table_Comment}
        /// </summary>
        public static IService{$ClassName} {$ClassName}Service()
        {
            Init();
            if ({$InstanceName}Service == null) {$InstanceName}Service = new Service{$ClassName}();
            return {$InstanceName}Service;
        }";
                UnitTemplate   = UnitTemplate.Replace("{$InstanceName}", InstanceName);
                UnitTemplate   = UnitTemplate.Replace("{$ClassName}", ClassName);
                UnitTemplate   = UnitTemplate.Replace("{$Table_Comment}", Table_Comment);
                ServiceMethod += UnitTemplate;
            }
            Content = Content.Replace("{$ServiceDefine}", ServiceDefine);
            Content = Content.Replace("{$ServiceMethod}", ServiceMethod);

            //存入目标文件内容
            UtilFile.WriteString2File(Save_Dir + "ManageService.cs", Content);
        }
Exemplo n.º 6
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.º 7
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.º 8
0
        /// <summary>
        /// 运行主程序
        /// 1.生成配置文件:autocode.config.xml
        /// </summary>
        public void Run()
        {
            base.Init();
            //1.生成配置文件:autocode.config.xml
            App_Dir = App_Dir + Path.DirectorySeparatorChar + "AutoCode" + Path.DirectorySeparatorChar + "Model" + Path.DirectorySeparatorChar;
            string Save_Dir = App_Dir + "autocode.config.xml";

            if (File.Exists(Save_Dir))
            {
                return;
            }
            if (!Directory.Exists(Save_Dir))
            {
                UtilFile.CreateDir(Save_Dir);
            }

            XElement xElement = new XElement(new XElement("classes"));

            foreach (string Table_Name in TableList)
            {
                if (TableInfoList.ContainsKey(Table_Name))
                {
                    //添加查询条件配置
                    XElement ConditionsElement = new XElement("conditions");
                    ConditionsToConfig(Table_Name, ConditionsElement);

                    //表关系主键显示配置
                    XElement RelationShowsElement = new XElement("relationShows");
                    RelationShowsToConfig(Table_Name, RelationShowsElement);
                    if (ConditionsElement.Elements().Count() <= 0)
                    {
                        ConditionsElement = null;
                    }
                    if (RelationShowsElement.Elements().Count() <= 0)
                    {
                        RelationShowsElement = null;
                    }
                    xElement.Add(
                        new XElement("class",
                                     ConditionsElement,
                                     RelationShowsElement,
                                     new XAttribute("name", Table_Name)
                                     )
                        );
                }
            }

            //需要指定编码格式,否则在读取时会抛:根级别上的数据无效。 第 1 行 位置 1异常
            XmlWriterSettings settings = new XmlWriterSettings();

            settings.Encoding = new UTF8Encoding(false);
            settings.Indent   = true;
            XmlWriter xw = XmlWriter.Create(Save_Dir, settings);

            xElement.Save(xw);
            //写入文件
            xw.Flush();
            xw.Close();

            //表五种关系映射配置
            XDocument xmlDoc = XDocument.Load(Save_Dir);

            foreach (string Table_Name in TableList)
            {
                RelationFives(Table_Name, xmlDoc);
            }
            xmlDoc.Save(Save_Dir);
            Debug.WriteLine(xElement.ToString());
        }
Exemplo n.º 9
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.º 10
0
        /// <summary>
        /// 4.实体类有外键的实体类需要生成HttpData 文件
        ///   例如Admin有外键Department_ID,会生成Department的HttpData类【多个文件】
        /// [模板文件]:domain/httpdata.txt|domain/httpdatadefine.txt
        /// [生成文件名称]:ClassName|ClassName
        /// [生成文件后缀名]:.ashx.cs|.ashx"
        /// </summary>
        private void CreateHttpData()
        {
            string Relation_ClassName = "Admin";
            string Relation_InstanceName = "admin";
            string Table_Comment = "系统管理员";
            string Relation_Table_Name, Relation_Column_Name = "", Relation_Column_Level;
            string UnitTemplate, Template_Name, Content, Content_New;
            string ClassName;
            string Column_Name, Column_Comment;

            foreach (string Table_Name in TableList)
            {
                ClassName = Table_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"];
                    if (Column_Name.Contains("_ID"))
                    {
                        Relation_ClassName  = Column_Name.Replace("_ID", "");
                        Relation_Table_Name = Relation_ClassName;

                        if (TableList.Contains(Relation_ClassName) || (Relation_Table_Name.ToUpper().Equals("PARENT")))
                        {
                            if (Relation_Table_Name.ToUpper().Equals("PARENT"))
                            {
                                string Save_Dir_Tree = Save_Dir + Path.DirectorySeparatorChar + "Tree" + Path.DirectorySeparatorChar;
                                if (!Directory.Exists(Save_Dir_Tree))
                                {
                                    UtilFile.CreateDir(Save_Dir_Tree);
                                }

                                //读取原文件内容到内存
                                Template_Name         = @"AutoCode/Model/domain/httpdatatree.txt";
                                Content               = UtilFile.ReadFile2String(Template_Name);
                                Relation_InstanceName = UtilString.LcFirst(ClassName);
                                Relation_Column_Name  = "";
                                Relation_Column_Level = "";
                                Dictionary <string, Dictionary <string, string> > Relation_FieldInfo = FieldInfos[ClassName];
                                foreach (KeyValuePair <String, Dictionary <string, string> > relation_entry in Relation_FieldInfo)
                                {
                                    Relation_Column_Name = relation_entry.Key;
                                    if (UtilString.Contains(relation_entry.Key.ToUpper(), "NAME", "TITLE", "URL"))
                                    {
                                        break;
                                    }
                                }

                                foreach (KeyValuePair <String, Dictionary <string, string> > relation_entry in Relation_FieldInfo)
                                {
                                    if (UtilString.Contains(relation_entry.Key.ToUpper(), "LEVEL"))
                                    {
                                        Relation_Column_Level = relation_entry.Key;
                                        break;
                                    }
                                }

                                if (string.IsNullOrEmpty(Relation_Column_Level))
                                {
                                    foreach (KeyValuePair <String, Dictionary <string, string> > relation_entry in Relation_FieldInfo)
                                    {
                                        if (UtilString.Contains(relation_entry.Key.ToUpper(), "TYPE"))
                                        {
                                            Relation_Column_Level = relation_entry.Key;
                                            break;
                                        }
                                    }
                                    bool IsPermitNull = true;
                                    if (entry.Value["Null"].Equals("否"))
                                    {
                                        IsPermitNull = false;
                                    }
                                    if (IsPermitNull)
                                    {
                                        UnitTemplate = @"
                    int? level=Convert.ToInt16({$InstanceName}.{$Relation_Column_Level});";
                                    }
                                    else
                                    {
                                        UnitTemplate = @"
                    int level=Convert.ToInt16({$InstanceName}.{$Relation_Column_Level});";
                                    }
                                }
                                else
                                {
                                    bool IsPermitNull = true;
                                    if (entry.Value["Null"].Equals("否"))
                                    {
                                        IsPermitNull = false;
                                    }
                                    if (IsPermitNull)
                                    {
                                        UnitTemplate = @"
                    int? level={$InstanceName}.{$Relation_Column_Level};";
                                    }
                                    else
                                    {
                                        UnitTemplate = @"
                    int level={$InstanceName}.{$Relation_Column_Level};";
                                    }
                                }
                                UnitTemplate = UnitTemplate.Replace("{$InstanceName}", Relation_InstanceName);
                                UnitTemplate = UnitTemplate.Replace("{$Relation_Column_Level}", Relation_Column_Level);
                                if (TableInfoList.ContainsKey(ClassName) && TableInfoList[ClassName].ContainsKey("Comment"))
                                {
                                    Table_Comment = TableInfoList[ClassName]["Comment"];
                                    string[] t_c = Table_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                                    if (t_c.Length > 1)
                                    {
                                        Table_Comment = t_c[0];
                                    }
                                }

                                Column_Comment = entry.Value["Comment"];
                                string[] c_c = Column_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                                if (c_c.Length >= 1)
                                {
                                    Column_Comment = c_c[0];
                                }
                                Column_Comment = Column_Comment.Replace("标识", "");

                                Content_New = Content.Replace("{$ClassName}", ClassName);
                                Content_New = Content_New.Replace("{$Table_Comment}", Table_Comment);
                                Content_New = Content_New.Replace("{$InstanceName}", Relation_InstanceName);
                                Content_New = Content_New.Replace("{$Relation_Column_Name}", Relation_Column_Name);
                                Content_New = Content_New.Replace("{$Relation_Column_Level_Name}", Relation_Column_Level);
                                Content_New = Content_New.Replace("{$Relation_Column_Level}", UnitTemplate);

                                //存入目标文件内容
                                UtilFile.WriteString2File(Save_Dir_Tree + ClassName + "Tree.ashx.cs", Content_New);

                                //读取原文件内容到内存
                                Template_Name = @"AutoCode/Model/domain/httpdatatreedefine.txt";
                                Content       = UtilFile.ReadFile2String(Template_Name);
                                Content_New   = Content.Replace("{$ClassName}", ClassName);

                                //存入目标文件内容
                                UtilFile.WriteString2File(Save_Dir_Tree + ClassName + "Tree.ashx", Content_New);
                            }
                            else if (TableInfoList.ContainsKey(Relation_Table_Name))
                            {
                                //读取原文件内容到内存
                                Template_Name = @"AutoCode/Model/domain/httpdata.txt";
                                Content       = UtilFile.ReadFile2String(Template_Name);
                                if (TableInfoList.ContainsKey(Relation_ClassName))
                                {
                                    Table_Comment = TableInfoList[Relation_ClassName]["Comment"];
                                    string[] t_c = Table_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                                    if (t_c.Length > 1)
                                    {
                                        Table_Comment = t_c[0];
                                    }
                                    Relation_InstanceName = UtilString.LcFirst(Relation_ClassName);

                                    Dictionary <string, Dictionary <string, string> > Relation_FieldInfo = FieldInfos[Relation_Table_Name];
                                    foreach (KeyValuePair <String, Dictionary <string, string> > relation_entry in Relation_FieldInfo)
                                    {
                                        Relation_Column_Name = relation_entry.Key;
                                        if (UtilString.Contains(relation_entry.Key.ToUpper(), "NAME", "TITLE", "URL"))
                                        {
                                            break;
                                        }
                                    }

                                    Content_New = Content.Replace("{$ClassName}", Relation_ClassName);
                                    Content_New = Content_New.Replace("{$Table_Comment}", Table_Comment);
                                    Content_New = Content_New.Replace("{$InstanceName}", Relation_InstanceName);
                                    Content_New = Content_New.Replace("{$Column_Name}", Column_Name);
                                    Content_New = Content_New.Replace("{$Relation_Column_Name}", Relation_Column_Name);

                                    //存入目标文件内容
                                    UtilFile.WriteString2File(Save_Dir + Relation_ClassName + ".ashx.cs", Content_New);

                                    //读取原文件内容到内存
                                    Template_Name = @"AutoCode/Model/domain/httpdatadefine.txt";
                                    Content       = UtilFile.ReadFile2String(Template_Name);
                                    Content_New   = Content.Replace("{$ClassName}", Relation_ClassName);

                                    //存入目标文件内容
                                    UtilFile.WriteString2File(Save_Dir + Relation_ClassName + ".ashx", Content_New);
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
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);
                }
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// 1a.生成实体类分部类(显示属性)
        /// </summary>
        private void CreateDomainPartial()
        {
            string ClassName = "Admin";
            string InstanceName = "admin";
            string Table_Comment = "系统管理员";
            string Template_Name, UnitTemplate, Content, Content_New;
            string Column_Name, Column_Comment, Column_Type, Column_Length;
            string Relation_ClassName, Relation_Column_Comment, Relation_Table_Name, Relation_Column_Name;
            string 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))
                {
                    Dictionary <string, Dictionary <string, string> > FieldInfo = FieldInfos[Table_Name];
                    UnitColumnDefine = "";
                    foreach (KeyValuePair <String, Dictionary <string, string> > entry in FieldInfo)
                    {
                        Column_Name    = entry.Key;
                        Column_Comment = entry.Value["Comment"];
                        Column_Type    = entry.Value["Type"];
                        Column_Length  = entry.Value["Length"];
                        string[] c_c = Column_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                        if (c_c.Length >= 1)
                        {
                            Column_Comment = c_c[0];
                        }

                        int iLength = UtilNumber.Parse(Column_Length);

                        if (Column_Type.Equals("tinyint"))
                        {
                            Column_Comment = entry.Value["Comment"];
                            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);
                                UnitTemplate      = @"
        /// <summary>
{$Column_Comment}
        /// </summary>
        public String {$Column_Name}Show
        {
            get;
            set;
        }";
                                UnitTemplate      = UnitTemplate.Replace("{$Column_Comment}", Column_Comment);
                                UnitTemplate      = UnitTemplate.Replace("{$Column_Name}", Column_Name);
                                UnitColumnDefine += UnitTemplate;
                            }
                        }
                        else if (Column_Name.Contains("_ID"))
                        {
                            Relation_ClassName = Column_Name.Replace("_ID", "");
                            if (TableList.Contains(Relation_ClassName) || (Relation_ClassName.ToUpper().Equals("PARENT")))
                            {
                                if (Relation_ClassName.ToUpper().Equals("PARENT"))
                                {
                                    Relation_Table_Name  = Relation_ClassName;
                                    Relation_Column_Name = "";
                                    Dictionary <string, Dictionary <string, string> > Relation_FieldInfo = FieldInfos[ClassName];
                                    foreach (KeyValuePair <String, Dictionary <string, string> > relation_entry in Relation_FieldInfo)
                                    {
                                        Relation_Column_Name = relation_entry.Key;
                                        if (UtilString.Contains(relation_entry.Key.ToUpper(), "NAME", "TITLE", "URL"))
                                        {
                                            break;
                                        }
                                    }
                                    Column_Comment    = Column_Comment.Replace("标识", "");
                                    UnitTemplate      = @"

        /// <summary>
        /// 显示{$Column_Comment}
        /// </summary>
        public String {$Relation_Column_Name}_Parent
        {
            get;
            set;
        }
        
        /// <summary>
        /// 显示{$Column_Comment}[全]
        /// </summary>
        public String {$ClassName}ShowAll
        {
            get;
            set;
        }
                                    ";
                                    UnitTemplate      = UnitTemplate.Replace("{$Column_Comment}", Column_Comment);
                                    UnitTemplate      = UnitTemplate.Replace("{$ClassName}", ClassName);
                                    UnitTemplate      = UnitTemplate.Replace("{$Relation_Column_Name}", Relation_Column_Name);
                                    UnitColumnDefine += UnitTemplate;
                                }
                                else if (TableInfoList.ContainsKey(Relation_ClassName))
                                {
                                    Relation_Table_Name = Relation_ClassName;
                                    Dictionary <string, Dictionary <string, string> > Relation_FieldInfo = FieldInfos[Relation_Table_Name];
                                    Relation_Column_Name    = Column_Name;
                                    Relation_Column_Comment = Relation_Column_Name;
                                    foreach (KeyValuePair <String, Dictionary <string, string> > relation_entry in Relation_FieldInfo)
                                    {
                                        Relation_Column_Name = relation_entry.Key;

                                        if (UtilString.Contains(relation_entry.Key.ToUpper(), "NAME", "TITLE", "URL"))
                                        {
                                            Relation_Column_Comment = relation_entry.Value["Comment"];
                                            break;
                                        }
                                    }
                                    UnitTemplate      = @"
        /// <summary>
        /// {$Relation_Column_Comment}
        /// </summary>
        public String {$Relation_Column_Name}
        {
            get;
            set;
        }";
                                    UnitTemplate      = UnitTemplate.Replace("{$Relation_Column_Comment}", Relation_Column_Comment);
                                    UnitTemplate      = UnitTemplate.Replace("{$Relation_Column_Name}", Relation_Column_Name);
                                    UnitColumnDefine += UnitTemplate;
                                }
                            }
                        }
                        else if (ColumnIsTextArea(Column_Name, Column_Type, iLength))
                        {
                            UnitTemplate = @"
        /// <summary>
        /// {$Column_Comment}
        /// </summary>
        public String {$Column_Name}Show
        {
            get;
            set;
        }";

                            Column_Comment = entry.Value["Comment"];
                            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);
                            }
                            UnitTemplate      = UnitTemplate.Replace("{$Column_Comment}", Column_Comment);
                            UnitTemplate      = UnitTemplate.Replace("{$Column_Name}", Column_Name);
                            UnitColumnDefine += UnitTemplate;
                        }
                    }

                    if (OneHasManyDefine.ContainsKey(Table_Name))
                    {
                        UnitTemplate      = @"
        /// <summary>
        /// 辅助主键
        ///【用于ExtJs Combo主键下拉框显示ID以和主表ID名称区别开来】
        /// </summary>
        public String {$Table_Name}_ID
        {
            get;
            set;
        }";
                        UnitTemplate      = UnitTemplate.Replace("{$Table_Name}", Table_Name);
                        UnitColumnDefine += UnitTemplate;
                    }
                    if (!string.IsNullOrEmpty(UnitColumnDefine))
                    {
                        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);
                        Content_New = Content_New.Replace("{$InstanceName}", InstanceName);
                        Content_New = Content_New.Replace("{$ColumnDefines}", UnitColumnDefine);
                        //存入目标文件内容
                        UtilFile.WriteString2File(Save_Dir + ClassName + ".cs", Content_New);
                    }
                }
            }
        }
Exemplo n.º 13
0
        /// <summary>
        ///  2.Business/Admin后台所有ExtService服务类【多个文件】
        /// [模板文件]:service/extservice.txt|service/extservicedefine.txt
        /// [生成文件名称]:"ExtService"+ClassName|"ExtService"+ClassName
        /// [生成文件后缀名]:.ashx.cs|.ashx
        /// </summary>
        private void CreateExtService()
        {
            string ClassName = "Admin";
            string InstanceName = "admin";
            string Table_Comment = "系统管理员";
            string Service_NameSpace = "AdminManage";
            string Template_Name, UnitTemplate, Content, Content_New;
            string ColumnNameComment, ColumnCommentName, EnumColumnName;
            string Column_Name, Column_Table_Name, Column_Comment, Column_Type, Column_Length;
            string ImportConvertDataToShow, ExportConvertShowToData;
            string SpecialResult = "";
            string Relation_ClassName, Relation_InstanceName;
            string Relation_Table_Name, Relation_Column_Name, TreeInstanceDefine, Relation_Column_Level, RelationFieldTreeRecursive;
            string ImgUploadSrc = "", Relation_Parent_Init = "";
            bool   IsImage;

            foreach (string Table_Name in TableList)
            {
                //读取原文件内容到内存
                Template_Name = @"AutoCode/Model/service/extservice.txt";
                Content       = UtilFile.ReadFile2String(Template_Name);
                ClassName     = Table_Name;
                RelationFieldTreeRecursive = "";
                TreeInstanceDefine         = "";
                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);

                    Content_New = Content.Replace("{$ClassName}", ClassName);
                    Content_New = Content_New.Replace("{$Table_Comment}", Table_Comment);
                    Content_New = Content_New.Replace("{$InstanceName}", InstanceName);

                    Dictionary <string, Dictionary <string, string> > FieldInfo = FieldInfos[Table_Name];
                    ColumnNameComment       = ""; ColumnCommentName = ""; EnumColumnName = ""; SpecialResult = "";
                    ImportConvertDataToShow = ""; ExportConvertShowToData = ""; ImgUploadSrc = ""; Relation_Parent_Init = "";
                    foreach (KeyValuePair <String, Dictionary <string, string> > entry in FieldInfo)
                    {
                        IsImage        = false;
                        Column_Name    = entry.Key;
                        Column_Comment = entry.Value["Comment"];
                        Column_Type    = entry.Value["Type"];
                        Column_Length  = entry.Value["Length"];
                        string[] c_c = Column_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                        if (c_c.Length >= 1)
                        {
                            Column_Comment = c_c[0];
                        }
                        if (!((Column_Name.ToUpper().Equals(CommitTime_Str.ToUpper())) || (Column_Name.ToUpper().Equals(UpdateTime_Str.ToUpper()))))
                        {
                            if (!Column_Type.Equals("tinyint"))
                            {
                                ColumnNameComment += "                    {\"" + Column_Name + "\",\"" + Column_Comment + "\"},\r\n";
                                ColumnCommentName += "                    {\"" + Column_Comment + "\",\"" + Column_Name + "\"},\r\n";
                            }
                        }
                        int iLength = UtilNumber.Parse(Column_Length);
                        IsImage = ColumnIsImage(Column_Name, Column_Comment);
                        if (IsImage)
                        {
                            UnitTemplate  = @"
                    Dictionary<string,object> uploadResult=this.UploadImage({$InstanceName}Form.Files,""{$Column_Name}Upload"",""{$Column_Name}"",""{$InstanceName}"");
                    if ((uploadResult!=null)&&((bool)uploadResult[""success""]==true)&&(uploadResult.Keys.Contains(""file_name""))){
                        {$InstanceName}.{$Column_Name}=(string)uploadResult[""file_name""];
                    }";
                            UnitTemplate  = UnitTemplate.Replace("{$InstanceName}", InstanceName);
                            UnitTemplate  = UnitTemplate.Replace("{$Column_Name}", Column_Name);
                            ImgUploadSrc += UnitTemplate;
                        }
                        else if (Column_Type.Equals("tinyint"))
                        {
                            Column_Comment = entry.Value["Comment"];
                            c_c            = Column_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                            if (c_c.Length > 1)
                            {
                                UnitTemplate      = @"
                    {$InstanceName}.{$Column_Name}Show = Enum{$Column_Table_Name}.{$Column_Name}Show(Convert.ToChar({$InstanceName}.{$Column_Name}));";
                                UnitTemplate      = UnitTemplate.Replace("{$InstanceName}", InstanceName);
                                UnitTemplate      = UnitTemplate.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;
                                }
                                UnitTemplate             = UnitTemplate.Replace("{$Column_Table_Name}", Column_Table_Name);
                                SpecialResult           += UnitTemplate;
                                Column_Comment           = c_c[0].Trim();
                                EnumColumnName          += "\"" + Column_Name + "\",";
                                ColumnNameComment       += "                    {\"" + Column_Name + "Show\",\"" + Column_Comment + "\"},\r\n";
                                ColumnCommentName       += "                    {\"" + Column_Comment + "\",\"" + Column_Name + "Show\"},\r\n";
                                ExportConvertShowToData += "                    " + InstanceName + "." + Column_Name + "Show = Enum" + Column_Name + "." + Column_Name + "Show(" + InstanceName + "." + Column_Name + ");\r\n";
                                ImportConvertDataToShow += "                    " + InstanceName + "." + Column_Name + " = Enum" + Column_Name + "." + Column_Name + "ByShow(" + InstanceName + "." + Column_Name + "Show);\r\n";
                            }
                        }
                        else if (Column_Name.Contains("_ID"))
                        {
                            Relation_Table_Name = Column_Name.Replace("_ID", "");
                            Relation_ClassName  = Relation_Table_Name;

                            if (TableList.Contains(Relation_ClassName) || (Relation_ClassName.ToUpper().Equals("PARENT")))
                            {
                                if (Relation_Table_Name.ToUpper().Equals("PARENT"))
                                {
                                    Relation_Table_Name   = Table_Name;
                                    Relation_ClassName    = ClassName;
                                    Relation_Column_Name  = "";
                                    Relation_Column_Level = "";
                                    Relation_InstanceName = UtilString.LcFirst(Relation_ClassName);
                                    Dictionary <string, Dictionary <string, string> > Relation_FieldInfo = FieldInfos[Table_Name];
                                    foreach (KeyValuePair <String, Dictionary <string, string> > relation_entry in Relation_FieldInfo)
                                    {
                                        if (UtilString.Contains(relation_entry.Key.ToUpper(), "NAME", "TITLE", "URL"))
                                        {
                                            Relation_Column_Name = relation_entry.Key;
                                            break;
                                        }
                                    }
                                    bool IsPermitNull = true;
                                    foreach (KeyValuePair <String, Dictionary <string, string> > relation_entry in Relation_FieldInfo)
                                    {
                                        if (UtilString.Contains(relation_entry.Key.ToUpper(), "LEVEL"))
                                        {
                                            Relation_Column_Level = relation_entry.Key;
                                            if (relation_entry.Value["Null"].Equals("否"))
                                            {
                                                IsPermitNull = false;
                                            }
                                            break;
                                        }
                                    }
                                    TreeInstanceDefine = @"
                {$Relation_ClassName} {$Relation_InstanceName}_instance;";
                                    if (string.IsNullOrEmpty(Relation_Column_Level))
                                    {
                                        foreach (KeyValuePair <String, Dictionary <string, string> > relation_entry in Relation_FieldInfo)
                                        {
                                            if (UtilString.Contains(relation_entry.Key.ToUpper(), "TYPE"))
                                            {
                                                Relation_Column_Level = relation_entry.Key;
                                                break;
                                            }
                                        }
                                        UnitTemplate = @"
                    {$Relation_InstanceName}_instance=null;
                    if ({$Relation_InstanceName}.Parent_ID!=null){
                        {$Relation_InstanceName}_instance=db.{$Relation_ClassName}.Find({$Relation_InstanceName}.Parent_ID);
                        {$Relation_InstanceName}.{$Relation_Column_Name}_Parent={$Relation_InstanceName}_instance.{$Relation_Column_Name};
                    }
                    if ({$Relation_InstanceName}_instance!=null){
                        int level = (int){$Relation_InstanceName}_instance.{$Relation_Column_Level};
                        {$Relation_InstanceName}.{$Relation_ClassName}ShowAll=this.{$Relation_ClassName}ShowAll({$Relation_InstanceName}.Parent_ID,level);
                    }";
                                        RelationFieldTreeRecursive = @"
        /// <summary>
        /// 显示{$Column_Comment}[全]
        ///  注:采用了递归写法
        /// </summary>
        /// <param name=""Parent_ID"">{$Column_Comment}标识</param>
        /// <param name=""level"">目录层级</param>
        /// <returns></returns>
        private string {$Relation_ClassName}ShowAll(int? Parent_ID,int level)
        {
            string {$Relation_ClassName}ShowAll="""";
            {$Relation_ClassName} {$Relation_InstanceName}_p=db.{$Relation_ClassName}.Find(Parent_ID);
            if (level<=0){
                {$Relation_ClassName}ShowAll={$Relation_InstanceName}_p.{$Relation_Column_Name};
            }else{
                Parent_ID={$Relation_InstanceName}_p.Parent_ID;
                {$Relation_ClassName}ShowAll=this.{$Relation_ClassName}ShowAll(Parent_ID,level-1)+""->""+{$Relation_InstanceName}_p.{$Relation_Column_Name};
            }
            return {$Relation_ClassName}ShowAll;
        }
";
                                    }
                                    else
                                    {
                                        string ColumnTypeNull = "int";
                                        if (IsPermitNull)
                                        {
                                            ColumnTypeNull += "?";
                                        }
                                        UnitTemplate = @"
                    {$Relation_InstanceName}_instance=null;
                    if ({$Relation_InstanceName}.Parent_ID!=null){
                        {$Relation_InstanceName}_instance=db.{$Relation_ClassName}.Find({$Relation_InstanceName}.Parent_ID);
                        {$Relation_InstanceName}.{$Relation_Column_Name}_Parent={$Relation_InstanceName}_instance.{$Relation_Column_Name};
                    }
                    if ({$Relation_InstanceName}_instance!=null){
                        {$ColumnTypeNull} level = {$Relation_InstanceName}_instance.{$Relation_Column_Level};
                        {$Relation_InstanceName}.{$Relation_ClassName}ShowAll=this.{$Relation_ClassName}ShowAll({$Relation_InstanceName}.Parent_ID,level);
                    }";
                                        UnitTemplate = UnitTemplate.Replace("{$ColumnTypeNull}", ColumnTypeNull);
                                        RelationFieldTreeRecursive = @"
        /// <summary>
        /// 显示{$Column_Comment}[全]
        ///  注:采用了递归写法
        /// </summary>
        /// <param name=""Parent_ID"">{$Column_Comment}标识</param>
        /// <param name=""level"">目录层级</param>
        /// <returns></returns>
        private string {$Relation_ClassName}ShowAll(int? Parent_ID,int level)
        {
            string {$Relation_ClassName}ShowAll="""";
            {$Relation_ClassName} {$Relation_InstanceName}_p=db.{$Relation_ClassName}.Find(Parent_ID);
            if (level<=1){
                {$Relation_ClassName}ShowAll={$Relation_InstanceName}_p.{$Relation_Column_Name};
            }else{
                Parent_ID={$Relation_InstanceName}_p.Parent_ID;
                {$Relation_ClassName}ShowAll=this.{$Relation_ClassName}ShowAll(Parent_ID,level-1)+""->""+{$Relation_InstanceName}_p.{$Relation_Column_Name};
            }
            return {$Relation_ClassName}ShowAll;
        }
";
                                    }
                                    UnitTemplate       = UnitTemplate.Replace("{$Relation_InstanceName}", Relation_InstanceName);
                                    UnitTemplate       = UnitTemplate.Replace("{$Relation_ClassName}", Relation_ClassName);
                                    UnitTemplate       = UnitTemplate.Replace("{$Relation_Column_Name}", Relation_Column_Name);
                                    UnitTemplate       = UnitTemplate.Replace("{$Relation_Column_Level}", Relation_Column_Level);
                                    TreeInstanceDefine = TreeInstanceDefine.Replace("{$Relation_InstanceName}", Relation_InstanceName);
                                    TreeInstanceDefine = TreeInstanceDefine.Replace("{$Relation_ClassName}", Relation_ClassName);
                                    SpecialResult     += UnitTemplate;
                                    Column_Comment     = entry.Value["Comment"];
                                    c_c = Column_Comment.Split(new char[] { '\r', '\n' }, StringSplitOptions.RemoveEmptyEntries);
                                    if (c_c.Length >= 1)
                                    {
                                        Column_Comment = c_c[0];
                                    }
                                    Column_Comment             = Column_Comment.Replace("标识", "");
                                    RelationFieldTreeRecursive = RelationFieldTreeRecursive.Replace("{$Column_Comment}", Column_Comment);
                                    RelationFieldTreeRecursive = RelationFieldTreeRecursive.Replace("{$Relation_InstanceName}", Relation_InstanceName);
                                    RelationFieldTreeRecursive = RelationFieldTreeRecursive.Replace("{$Relation_ClassName}", Relation_ClassName);
                                    RelationFieldTreeRecursive = RelationFieldTreeRecursive.Replace("{$Relation_Column_Name}", Relation_Column_Name);
                                    UnitTemplate          = @"
                    if ({$InstanceName}.{$Column_Name} == 0) {$InstanceName}.{$Column_Name} = null;";
                                    UnitTemplate          = UnitTemplate.Replace("{$InstanceName}", InstanceName);
                                    UnitTemplate          = UnitTemplate.Replace("{$Column_Name}", Column_Name);
                                    Relation_Parent_Init += UnitTemplate;
                                }
                                else if (TableInfoList.ContainsKey(Relation_Table_Name))
                                {
                                    //读取原文件内容到内存
                                    Template_Name         = @"AutoCode/Model/domain/httpdata.txt";
                                    Content               = UtilFile.ReadFile2String(Template_Name);
                                    Relation_InstanceName = UtilString.LcFirst(Relation_ClassName);
                                    Relation_Table_Name   = Relation_ClassName;

                                    Dictionary <string, Dictionary <string, string> > Relation_FieldInfo = FieldInfos[Relation_Table_Name];
                                    Relation_Column_Name = Column_Name;
                                    foreach (KeyValuePair <String, Dictionary <string, string> > relation_entry in Relation_FieldInfo)
                                    {
                                        Relation_Column_Name = relation_entry.Key;
                                        if (UtilString.Contains(relation_entry.Key.ToUpper(), "NAME", "TITLE", "URL"))
                                        {
                                            break;
                                        }
                                    }
                                    UnitTemplate             = @"
                    {$InstanceName}.{$Relation_Column_Name} = {$InstanceName}.{$Relation_ClassName}.{$Relation_Column_Name};";
                                    UnitTemplate             = UnitTemplate.Replace("{$InstanceName}", InstanceName);
                                    UnitTemplate             = UnitTemplate.Replace("{$Relation_ClassName}", Relation_ClassName);
                                    UnitTemplate             = UnitTemplate.Replace("{$Relation_Column_Name}", Relation_Column_Name);
                                    SpecialResult           += UnitTemplate;
                                    UnitTemplate             = @"
                    {$Relation_ClassName} {$Relation_InstanceName} = db.{$Relation_ClassName}.Where(e => e.{$Relation_Column_Name}.Equals({$InstanceName}.{$Relation_Column_Name})).SingleOrDefault();
                    {$InstanceName}.{$Column_Name} = {$Relation_InstanceName}.ID;
                                ";
                                    UnitTemplate             = UnitTemplate.Replace("{$InstanceName}", InstanceName);
                                    UnitTemplate             = UnitTemplate.Replace("{$Relation_InstanceName}", Relation_InstanceName);
                                    UnitTemplate             = UnitTemplate.Replace("{$Column_Name}", Column_Name);
                                    UnitTemplate             = UnitTemplate.Replace("{$Relation_ClassName}", Relation_ClassName);
                                    UnitTemplate             = UnitTemplate.Replace("{$Relation_Column_Name}", Relation_Column_Name);
                                    ImportConvertDataToShow += UnitTemplate;
                                }
                            }
                        }
                        else if (ColumnIsTextArea(Column_Name, Column_Type, iLength))
                        {
                            UnitTemplate   = @"
                    if (!string.IsNullOrEmpty({$InstanceName}.{$Column_Name}))
                    {
                        {$InstanceName}.{$Column_Name}Show = Regex.Replace({$InstanceName}.{$Column_Name}, ""<\\s*img\\s+[^>]*?src\\s*=\\s*(\'|\"")(.*?)\\1[^>]*?\\/?\\s*>"", ""<a href='${2}' target='_blank'>${0}</a>"");
                        {$InstanceName}.{$Column_Name}Show = {$InstanceName}.{$Column_Name}Show.Replace(""\\\"""", """");
                    }";
                            UnitTemplate   = UnitTemplate.Replace("{$InstanceName}", InstanceName);
                            UnitTemplate   = UnitTemplate.Replace("{$Column_Name}", Column_Name);
                            SpecialResult += UnitTemplate;
                        }
                    }
                    ColumnNameComment = ColumnNameComment.Substring(0, ColumnNameComment.Length - 3);
                    ColumnCommentName = ColumnCommentName.Substring(0, ColumnCommentName.Length - 3);

                    Content_New = Content_New.Replace("{$ColumnNameComment}", ColumnNameComment);
                    Content_New = Content_New.Replace("{$ColumnCommentName}", ColumnCommentName);

                    SpecialResult += @"
                    this.Stores.Add((" + ClassName + ")ClearInclude(" + InstanceName + "));";
                    SpecialResult  = SpecialResult.Substring(1, SpecialResult.Length - 1);
                    Content_New    = Content_New.Replace("{$SpecialResult}", SpecialResult);
                    Content_New    = Content_New.Replace("{$Service_NameSpace}", Service_NameSpace);
                    Content_New    = Content_New.Replace("{$CommitTime_Str}", CommitTime_Str);
                    Content_New    = Content_New.Replace("{$UpdateTime_Str}", UpdateTime_Str);

                    Content_New = Content_New.Replace("{$EnumColumnName}", EnumColumnName);
                    Content_New = Content_New.Replace("{$ImportConvertDataToShow}", ImportConvertDataToShow);
                    Content_New = Content_New.Replace("{$ExportConvertShowToData}", ExportConvertShowToData);
                    Content_New = Content_New.Replace("{$RelationFieldTreeRecursive}", RelationFieldTreeRecursive);
                    Content_New = Content_New.Replace("{$TreeInstanceDefine}", TreeInstanceDefine);

                    Content_New = Content_New.Replace("{$ImgUploadSrc}", ImgUploadSrc);
                    Content_New = Content_New.Replace("{$Relation_Parent_Init}", Relation_Parent_Init);

                    //存入目标文件内容
                    UtilFile.WriteString2File(Save_Dir + "ExtService" + ClassName + ".ashx.cs", Content_New);

                    //读取原文件内容到内存
                    Template_Name = @"AutoCode/Model/service/extservicedefine.txt";
                    Content       = UtilFile.ReadFile2String(Template_Name);
                    Content_New   = Content.Replace("{$ClassName}", ClassName);
                    Content_New   = Content_New.Replace("{$Service_NameSpace}", Service_NameSpace);

                    //存入目标文件内容
                    UtilFile.WriteString2File(Save_Dir + "ExtService" + ClassName + ".ashx", Content_New);
                }
            }
        }