using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace GenerateCode_GEBrilliantFactory
{
public class Model_Generate : BaseGenerate
{
///
/// 创建实体类
///
/// 表名
///
/// 文件前缀名
/// 类命名空间
/// 创建人
/// 中文注释
/// 实体类名
///
public static string GenerateModel(string tableName, List 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"
+ " /// \n"
+ " /// " + chinaComment + "实体类\n"
+ " /// \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;
}
///
/// 创建实体类
///
/// 表名
///
/// 文件前缀名
/// 类命名空间
/// 创建人
/// 中文注释
/// 实体类名
///
public static string GenerateModelParam(string tableName, List 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"
+ " /// \n"
+ " /// " + chinaComment + "实体类\n"
+ " /// \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;
}
}
}