22
schangxiang@126.com
2025-05-20 6768c18458bed22ae0ef1d611afd80bdeea31dda
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
 
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
 
namespace GenerateCode_GEBrilliantFactory
{
    public class Model_Generate : BaseGenerate
    {
 
        /// <summary>
        /// 创建实体类
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="columnNameList"></param>
        /// <param name="filePrefixName">文件前缀名</param>
        /// <param name="nameSpacePath">类命名空间</param>
        /// <param name="createPerson">创建人</param>
        /// <param name="chinaComment">中文注释</param>
        /// <param name="entityName">实体类名</param>
        /// <returns></returns>
        public static string GenerateModel(string tableName, List<ColumnModel> columnNameList, string filePrefixName, string nameSpacePath,
            string createPerson, string chinaComment, string entityName
            )
        {
            string header = "using System;\n"
                         + "using System.Runtime.Serialization; \n"
                         + "                   \n"
                         + "namespace WIP_Models \n"
                         + "{\n"
                         + "    /// <summary>\n"
                         + "    /// " + chinaComment + "实体类\n"
                         + "    /// </summary>\n"
                         + "    [DataContract]\n"
                         + "    public class $entityName$ \n"
                         + "    {\n\n";
            int columnCount = columnNameList.Count;
            string attrString = "";
            for (int i = 0; i < columnCount; ++i)
            {
                attrString += StructStrHelper.GenerateAttribute(i, columnNameList[i]);
            }
            string footer = "    }\n"
                + "}";
 
            string modelContent = header + attrString + footer;
            modelContent = modelContent.Replace(
                            "$NowTimeStr$", DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day
                            + " "
                            + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second);//创建时间
            modelContent = modelContent.Replace("$CreatePerson$", createPerson);//创建人
            modelContent = modelContent.Replace("$nameSpacePath$", nameSpacePath);//命名空间
            modelContent = modelContent.Replace("$entityName$", entityName);//实体类名
 
            CommonReplace(ref modelContent);
 
            return modelContent;
 
        }
 
 
        /// <summary>
        /// 创建实体类
        /// </summary>
        /// <param name="tableName">表名</param>
        /// <param name="columnNameList"></param>
        /// <param name="filePrefixName">文件前缀名</param>
        /// <param name="nameSpacePath">类命名空间</param>
        /// <param name="createPerson">创建人</param>
        /// <param name="chinaComment">中文注释</param>
        /// <param name="entityName">实体类名</param>
        /// <returns></returns>
        public static string GenerateModelParam(string tableName, List<ColumnModel> columnNameList, string filePrefixName, string nameSpacePath,
            string createPerson, string chinaComment, string entityName
            )
        {
            string header = "using System;\n"
                         + "using System.Runtime.Serialization; \n"
                         + "                   \n"
                         + "namespace " + MainForm.projectNamePrefix + ".Core.Model.ParamModels \n"
                         + "{\n"
                         + "    /// <summary>\n"
                         + "    /// " + chinaComment + "实体类\n"
                         + "    /// </summary>\n"
                         + "    public class $entityName$Param : PageParam \n"
                         + "    {\n\n";
            int columnCount = columnNameList.Count;
            string attrString = "";
            for (int i = 0; i < columnCount; ++i)
            {
                attrString += StructStrHelper.GenerateAttribute(i, columnNameList[i]);
            }
            string footer = "    }\n"
                + "}";
 
            string modelContent = header + attrString + footer;
            modelContent = modelContent.Replace(
                            "$NowTimeStr$", DateTime.Now.Year + "-" + DateTime.Now.Month + "-" + DateTime.Now.Day
                            + " "
                            + DateTime.Now.Hour + ":" + DateTime.Now.Minute + ":" + DateTime.Now.Second);//创建时间
            modelContent = modelContent.Replace("$CreatePerson$", createPerson);//创建人
            modelContent = modelContent.Replace("$nameSpacePath$", nameSpacePath);//命名空间
            modelContent = modelContent.Replace("$entityName$", entityName);//实体类名
 
            CommonReplace(ref modelContent);
 
            return modelContent;
 
        }
 
 
    }
}