代码生成增加预览功能、其他功能优化
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
using ZR.CodeGenerator.CodeGenerator;
|
||||
using System.Text;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
@@ -13,68 +13,63 @@ namespace ZR.CodeGenerator
|
||||
/// <summary>
|
||||
/// 生成vuejs模板,目前只有上传文件方法
|
||||
/// </summary>
|
||||
/// <param name="dbColumnInfo"></param>
|
||||
/// <param name="dbFieldInfo"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetVueJsMethod(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string js = "";
|
||||
var sb = new StringBuilder();
|
||||
|
||||
if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
js += " //文件上传成功方法\r\n";
|
||||
js += $" handleUpload{dbFieldInfo.CsharpField}Success(res, file) {{\r\n";
|
||||
js += $" this.form.{columnName} = URL.createObjectURL(file.raw);\r\n";
|
||||
js += " // this.$refs.upload.clearFiles();\r\n";
|
||||
js += " },\r";
|
||||
sb.AppendLine($" //文件上传成功方法");
|
||||
sb.AppendLine($" handleUpload{dbFieldInfo.CsharpField}Success(res, file) {{");
|
||||
sb.AppendLine($" this.form.{columnName} = URL.createObjectURL(file.raw);");
|
||||
sb.AppendLine($" // this.$refs.upload.clearFiles();");
|
||||
sb.AppendLine($" }},");
|
||||
}
|
||||
//有下拉框选项初列表查询数据
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||
{
|
||||
var sb = new System.Text.StringBuilder(500);
|
||||
sb.AppendLine(@$" // {dbFieldInfo.ColumnComment}字典翻译");
|
||||
sb.AppendLine($" {columnName}Format(row, column) {{");
|
||||
sb.AppendLine(@$" return this.selectDictLabel(this.{columnName}Options, row.{columnName});");
|
||||
sb.AppendLine(@" },");
|
||||
js += sb.ToString();
|
||||
sb.Append(@" },");
|
||||
|
||||
}
|
||||
return js;
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
//rules
|
||||
public static string GetFormRules(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string vueViewEditFromRuleContent = "";
|
||||
StringBuilder sbRule = new StringBuilder();
|
||||
//Rule 规则验证
|
||||
if ((!dbFieldInfo.IsPk && !dbFieldInfo.IsIncrement) && dbFieldInfo.IsRequired)
|
||||
if (!dbFieldInfo.IsPk && !dbFieldInfo.IsIncrement && dbFieldInfo.IsRequired)
|
||||
{
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\r\n";
|
||||
vueViewEditFromRuleContent += $" {{ required: true, message: '请输入{dbFieldInfo.ColumnComment}', trigger: \"blur\"}},\r\n";
|
||||
vueViewEditFromRuleContent += " ],\r\n";
|
||||
sbRule.AppendLine($" {dbFieldInfo.ColumnName}: [{{ required: true, message: '请输入{dbFieldInfo.ColumnComment}', trigger: \"blur\"}}],");
|
||||
}
|
||||
else if (TableMappingHelper.IsNumber(dbFieldInfo.ColumnType) && dbFieldInfo.IsRequired)
|
||||
else if (CodeGeneratorTool.IsNumber(dbFieldInfo.ColumnType) && dbFieldInfo.IsRequired)
|
||||
{
|
||||
vueViewEditFromRuleContent += $" {dbFieldInfo.ColumnName}: [\r\n";
|
||||
vueViewEditFromRuleContent += $" {{ type: 'number', message: '{dbFieldInfo.ColumnName}必须为数字值', trigger: \"blur\"}},\r\n";
|
||||
vueViewEditFromRuleContent += " ],\r\n";
|
||||
sbRule.AppendLine($" {dbFieldInfo.ColumnName}: [{{ type: 'number', message: '{dbFieldInfo.ColumnName}必须为数字值', trigger: \"blur\"}}],");
|
||||
}
|
||||
|
||||
return vueViewEditFromRuleContent;
|
||||
return sbRule.ToString();
|
||||
}
|
||||
|
||||
//model 属性
|
||||
public static string GetModelTemplate(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
var modelcontent = "";
|
||||
modelcontent += " /// <summary>\r\n";
|
||||
modelcontent += $" /// 描述 :{dbFieldInfo.ColumnComment}\r\n";
|
||||
modelcontent += $" /// 空值 :{!dbFieldInfo.IsRequired}\r\n";
|
||||
modelcontent += " /// </summary>\r\n";
|
||||
StringBuilder sbModel = new StringBuilder();
|
||||
sbModel.AppendLine(" /// <summary>");
|
||||
sbModel.AppendLine($" /// 描述 :{dbFieldInfo.ColumnComment}");
|
||||
sbModel.AppendLine($" /// 空值 :{!dbFieldInfo.IsRequired}");
|
||||
sbModel.AppendLine(" /// </summary>");
|
||||
if (dbFieldInfo.IsPk || dbFieldInfo.IsIncrement)
|
||||
{
|
||||
modelcontent += $" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPk.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIncrement.ToString().ToLower()})]\r\n";
|
||||
sbModel.AppendLine($" [SqlSugar.SugarColumn(IsPrimaryKey = {dbFieldInfo.IsPk.ToString().ToLower()}, IsIdentity = {dbFieldInfo.IsIncrement.ToString().ToLower()})]");
|
||||
}
|
||||
modelcontent += $" public {dbFieldInfo.CsharpType}{(GetModelRequired(dbFieldInfo))} {dbFieldInfo.CsharpField} {{ get; set; }}\r\n";
|
||||
return modelcontent;
|
||||
sbModel.AppendLine($" public {dbFieldInfo.CsharpType}{(GetModelRequired(dbFieldInfo))} {dbFieldInfo.CsharpField} {{ get; set; }}");
|
||||
return sbModel.ToString();
|
||||
}
|
||||
public static string GetModelRequired(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
@@ -122,68 +117,68 @@ namespace ZR.CodeGenerator
|
||||
{
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
string vueViewFromContent = "";
|
||||
string labelDisabled = dbFieldInfo.IsPk ? ":disabled=\"true\"" : "";
|
||||
string placeHolder = dbFieldInfo.IsIncrement ? "" : $"请输入{labelName}";
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (GenConstants.inputDtoNoField.Any(f => f.Replace("_", "").ToLower().Contains(dbFieldInfo.CsharpField.ToLower().Replace("_", ""))))
|
||||
{
|
||||
return vueViewFromContent;
|
||||
return sb.ToString();
|
||||
}
|
||||
if (!dbFieldInfo.IsInsert || !dbFieldInfo.IsEdit)
|
||||
{
|
||||
return vueViewFromContent;
|
||||
return sb.ToString();
|
||||
}
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
|
||||
{
|
||||
//时间
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-date-picker v-model=\"form.{columnName}\" type=\"datetime\" placeholder=\"选择日期时间\" default-time=\"12:00:00\"> </el-date-picker>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-date-picker v-model=\"form.{columnName}\" type=\"datetime\" placeholder=\"选择日期时间\" default-time=\"12:00:00\"> </el-date-picker>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_IMAGE_UPLOAD)
|
||||
{
|
||||
//图片
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-upload class=\"avatar-uploader\" name=\"file\" action=\"/api/upload/saveFile/\" :show-file-list=\"false\" :on-success=\"handleUpload{dbFieldInfo.CsharpField}Success\" :before-upload=\"beforeFileUpload\">\r\n";
|
||||
vueViewFromContent += $" <img v-if=\"form.{columnName}\" :src=\"form.{columnName}\" class=\"icon\">\r\n";
|
||||
vueViewFromContent += " <i v-else class=\"el-icon-plus uploader-icon\"></i>\r\n";
|
||||
vueViewFromContent += " </el-upload>\r\n";
|
||||
vueViewFromContent += $" <el-input v-model=\"form.{columnName}\" placeholder=\"请上传文件或手动输入文件地址\"></el-input>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-upload class=\"avatar-uploader\" name=\"file\" action=\"/api/upload/saveFile/\" :show-file-list=\"false\" :on-success=\"handleUpload{dbFieldInfo.CsharpField}Success\" :before-upload=\"beforeFileUpload\">");
|
||||
sb.AppendLine($" <img v-if=\"form.{columnName}\" :src=\"form.{columnName}\" class=\"icon\">");
|
||||
sb.AppendLine(" <i v-else class=\"el-icon-plus uploader-icon\"></i>");
|
||||
sb.AppendLine(" </el-upload>");
|
||||
sb.AppendLine($" <el-input v-model=\"form.{columnName}\" placeholder=\"请上传文件或手动输入文件地址\"></el-input>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_RADIO)
|
||||
{
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-radio-group v-model=\"form.{columnName}\">\r\n";
|
||||
vueViewFromContent += " <el-radio :key=\"1\" :label=\"1\">是</el-radio>\r\n";
|
||||
vueViewFromContent += " <el-radio :key=\"0\" :label=\"0\">否</el-radio>\r\n";
|
||||
vueViewFromContent += " </el-radio-group>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-radio-group v-model=\"form.{columnName}\">");
|
||||
sb.AppendLine(" <el-radio :key=\"1\" :label=\"1\">是</el-radio>");
|
||||
sb.AppendLine(" <el-radio :key=\"0\" :label=\"0\">否</el-radio>");
|
||||
sb.AppendLine(" </el-radio-group>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_TEXTAREA)
|
||||
{
|
||||
vueViewFromContent += $" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-input type=\"textarea\" v-model=\"form.{columnName}\" placeholder=\"请输入内容\"/>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
sb.AppendLine($" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-input type=\"textarea\" v-model=\"form.{columnName}\" placeholder=\"请输入内容\"/>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else if (dbFieldInfo.HtmlType == GenConstants.HTML_SELECT && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||
{
|
||||
string value = TableMappingHelper.IsNumber(dbFieldInfo.CsharpType) ? "parseInt(item.dictValue)" : "item.dictValue";
|
||||
vueViewFromContent += $" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-select v-model=\"form.{columnName}\">\r\n";
|
||||
vueViewFromContent += $" <el-option v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"{value}\"></el-option>\r\n";
|
||||
vueViewFromContent += " </el-select>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
string value = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? "parseInt(item.dictValue)" : "item.dictValue";
|
||||
sb.AppendLine($" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\" prop=\"{columnName}\">");
|
||||
sb.AppendLine($" <el-select v-model=\"form.{columnName}\">");
|
||||
sb.AppendLine($" <el-option v-for=\"item in {columnName}Options\" :key=\"item.dictValue\" :label=\"item.dictLabel\" :value=\"{value}\"></el-option>");
|
||||
sb.AppendLine(" </el-select>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else
|
||||
{
|
||||
string inputNumTxt = TableMappingHelper.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||
vueViewFromContent += $" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\">\r\n";
|
||||
vueViewFromContent += $" <el-input v-model{inputNumTxt}=\"form.{CodeGeneratorTool.FirstLowerCase(columnName)}\" placeholder=\"{placeHolder}\" {labelDisabled}/>\r\n";
|
||||
vueViewFromContent += " </el-form-item>\r\n";
|
||||
string inputNumTxt = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||
sb.AppendLine($" <el-form-item label=\"{labelName}\" :label-width=\"labelWidth\" prop=\"{CodeGeneratorTool.FirstLowerCase(columnName)}\">");
|
||||
sb.AppendLine($" <el-input v-model{inputNumTxt}=\"form.{CodeGeneratorTool.FirstLowerCase(columnName)}\" placeholder=\"{placeHolder}\" {labelDisabled}/>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
|
||||
return vueViewFromContent;
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -193,25 +188,24 @@ namespace ZR.CodeGenerator
|
||||
/// <returns></returns>
|
||||
public static string GetQueryFormHtml(GenTableColumn dbFieldInfo)
|
||||
{
|
||||
string queryFormHtml = "";
|
||||
StringBuilder sb = new();
|
||||
string labelName = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, dbFieldInfo.ColumnName);
|
||||
if (!dbFieldInfo.IsQuery || dbFieldInfo.HtmlType == GenConstants.HTML_FILE_UPLOAD) return queryFormHtml;
|
||||
|
||||
if (!dbFieldInfo.IsQuery || dbFieldInfo.HtmlType == GenConstants.HTML_FILE_UPLOAD) return sb.ToString();
|
||||
if (dbFieldInfo.HtmlType == GenConstants.HTML_DATETIME)
|
||||
{
|
||||
queryFormHtml += "<el-form-item label=\"时间\">\r\n";
|
||||
queryFormHtml += " <el-date-picker v-model=\"dateRange\" size=\"small\" value-format=\"yyyy-MM-dd\" type=\"daterange\" range-separator=\"-\" start-placeholder=\"开始日期\" end-placeholder=\"结束日期\"></el-date-picker>\r\n";
|
||||
queryFormHtml += "</el-form-item>\r\n";
|
||||
sb.AppendLine(" <el-form-item label=\"时间\">");
|
||||
sb.AppendLine(" <el-date-picker v-model=\"dateRange\" size=\"small\" value-format=\"yyyy-MM-dd\" type=\"daterange\" range-separator=\"-\" start-placeholder=\"开始日期\" end-placeholder=\"结束日期\"></el-date-picker>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
else
|
||||
{
|
||||
string inputNumTxt = TableMappingHelper.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||
queryFormHtml += $" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\">\r\n";
|
||||
queryFormHtml += $" <el-input v-model{inputNumTxt}=\"queryParams.{CodeGeneratorTool.FirstLowerCase(dbFieldInfo.CsharpField)}\"/>\r\n";
|
||||
queryFormHtml += " </el-form-item>\r\n";
|
||||
string inputNumTxt = CodeGeneratorTool.IsNumber(dbFieldInfo.CsharpType) ? ".number" : "";
|
||||
sb.AppendLine($" <el-form-item label=\"{ labelName}\" :label-width=\"labelWidth\">");
|
||||
sb.AppendLine($" <el-input v-model{inputNumTxt}=\"queryParams.{CodeGeneratorTool.FirstLowerCase(dbFieldInfo.CsharpField)}\"/>");
|
||||
sb.AppendLine(" </el-form-item>");
|
||||
}
|
||||
|
||||
return queryFormHtml;
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
//table-column
|
||||
@@ -219,17 +213,16 @@ namespace ZR.CodeGenerator
|
||||
{
|
||||
string columnName = dbFieldInfo.ColumnName;
|
||||
string label = CodeGeneratorTool.GetLabelName(dbFieldInfo.ColumnComment, columnName);
|
||||
string vueViewListContent = "";
|
||||
string showToolTip = dbFieldInfo.CsharpType == "string" ? ":show-overflow-tooltip=\"true\"" : "";
|
||||
string formatter = !string.IsNullOrEmpty(dbFieldInfo.DictType) ? $" :formatter=\"{columnName}Format\"" : "";
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (dbFieldInfo.IsList && dbFieldInfo.HtmlType.Equals(GenConstants.HTML_IMAGE_UPLOAD))
|
||||
{
|
||||
vueViewListContent += $" <el-table-column prop=\"{columnName}\" label=\"图片\">\r\n";
|
||||
vueViewListContent += " <template slot-scope=\"scope\">\r\n";
|
||||
vueViewListContent += $" <el-image class=\"table-td-thumb\" :src=\"scope.row.{columnName}\" :preview-src-list=\"[scope.row.{columnName}]\"></el-image>\r\n";
|
||||
vueViewListContent += " </template>\r\n";
|
||||
vueViewListContent += " </el-table-column>\r\n";
|
||||
sb.AppendLine($" <el-table-column prop=\"{columnName}\" label=\"图片\">");
|
||||
sb.AppendLine(" <template slot-scope=\"scope\">");
|
||||
sb.AppendLine($" <el-image class=\"table-td-thumb\" :src=\"scope.row.{columnName}\" :preview-src-list=\"[scope.row.{columnName}]\"></el-image>");
|
||||
sb.AppendLine(" </template>");
|
||||
sb.AppendLine(" </el-table-column>");
|
||||
}
|
||||
//else if (dbFieldInfo.HtmlType.Equals(GenConstants.HTML_RADIO))
|
||||
//{
|
||||
@@ -240,11 +233,11 @@ namespace ZR.CodeGenerator
|
||||
// vueViewListContent += " </template>\r\n";
|
||||
// vueViewListContent += " </el-table-column>\r\n";
|
||||
//}
|
||||
else if(dbFieldInfo.IsList)
|
||||
else if (dbFieldInfo.IsList)
|
||||
{
|
||||
vueViewListContent += $" <el-table-column prop=\"{columnName}\" label=\"{label}\" align=\"center\" {showToolTip}{formatter}/>\r\n";
|
||||
sb.AppendLine($" <el-table-column prop=\"{columnName}\" label=\"{label}\" align=\"center\" {showToolTip}{formatter}/>");
|
||||
}
|
||||
return vueViewListContent;
|
||||
return sb.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,7 @@ using SqlSugar;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using ZR.CodeGenerator.CodeGenerator;
|
||||
using ZR.CodeGenerator.Model;
|
||||
using ZR.Model.System.Generate;
|
||||
|
||||
@@ -15,8 +11,6 @@ namespace ZR.CodeGenerator
|
||||
{
|
||||
/// <summary>
|
||||
/// 代码生成器。
|
||||
/// <remarks>
|
||||
/// 根据指定的实体域名空间生成Repositories和Services层的基础代码文件。
|
||||
/// </remarks>
|
||||
/// </summary>
|
||||
public class CodeGeneratorTool
|
||||
@@ -31,7 +25,7 @@ namespace ZR.CodeGenerator
|
||||
/// </summary>
|
||||
/// <param name="dbTableInfo"></param>
|
||||
/// <param name="dto"></param>
|
||||
public static List<string> Generate(GenTable dbTableInfo, GenerateDto dto)
|
||||
public static void Generate(GenTable dbTableInfo, GenerateDto dto)
|
||||
{
|
||||
_option.BaseNamespace = dbTableInfo.BaseNameSpace;
|
||||
_option.DtosNamespace = _option.BaseNamespace + "Model";
|
||||
@@ -42,9 +36,7 @@ namespace ZR.CodeGenerator
|
||||
_option.ServicesNamespace = _option.BaseNamespace + "Service";
|
||||
_option.ApiControllerNamespace = _option.BaseNamespace + "Admin.WebApi";
|
||||
|
||||
List<string> list = GenerateSingle(dbTableInfo?.Columns, dbTableInfo, dto);
|
||||
|
||||
return list;
|
||||
GenerateSingle(dbTableInfo?.Columns, dbTableInfo, dto);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -53,17 +45,18 @@ namespace ZR.CodeGenerator
|
||||
/// <param name="listField">表字段集合</param>
|
||||
/// <param name="tableInfo">表信息</param>
|
||||
/// <param name="dto"></param>
|
||||
public static List<string> GenerateSingle(List<GenTableColumn> listField, GenTable tableInfo, GenerateDto dto)
|
||||
public static void GenerateSingle(List<GenTableColumn> listField, GenTable tableInfo, GenerateDto dto)
|
||||
{
|
||||
string PKName = "id";
|
||||
string PKType = "int";
|
||||
List<string> genPathList = new();
|
||||
ReplaceDto replaceDto = new();
|
||||
replaceDto.ModelTypeName = tableInfo.ClassName;//表名对应C# 实体类名
|
||||
replaceDto.TableName = tableInfo.TableName;//表名
|
||||
replaceDto.TableDesc = tableInfo.TableComment;//表说明描述
|
||||
replaceDto.Permission = $"{tableInfo.ModuleName}:{tableInfo.ClassName.ToLower()}";//权限
|
||||
replaceDto.ViewsFileName = FirstLowerCase(replaceDto.ModelTypeName);
|
||||
replaceDto.Author = tableInfo.FunctionAuthor;
|
||||
|
||||
//循环表字段信息
|
||||
foreach (GenTableColumn dbFieldInfo in listField)
|
||||
{
|
||||
@@ -96,9 +89,9 @@ namespace ZR.CodeGenerator
|
||||
if ((dbFieldInfo.HtmlType == GenConstants.HTML_SELECT || dbFieldInfo.HtmlType == GenConstants.HTML_RADIO) && !string.IsNullOrEmpty(dbFieldInfo.DictType))
|
||||
{
|
||||
replaceDto.VueDataContent += $" // {dbFieldInfo.ColumnComment}选项列表\n";
|
||||
replaceDto.VueDataContent += $" {FirstLowerCase(dbFieldInfo.CsharpField)}Options: [],";
|
||||
replaceDto.VueDataContent += $" {FirstLowerCase(dbFieldInfo.CsharpField)}Options: [],\n";
|
||||
|
||||
replaceDto.MountedMethod += $" this.getDicts(\"{dbFieldInfo.DictType}\").then((response) => {{\n";
|
||||
replaceDto.MountedMethod += $" this.getDicts(\"{dbFieldInfo.DictType}\").then((response) => {{\n";
|
||||
replaceDto.MountedMethod += $" this.{FirstLowerCase(dbFieldInfo.CsharpField)}Options = response.data;\n";
|
||||
replaceDto.MountedMethod += " })\n";
|
||||
}
|
||||
@@ -115,110 +108,100 @@ namespace ZR.CodeGenerator
|
||||
replaceDto.PKName = PKName;
|
||||
replaceDto.PKType = PKType;
|
||||
|
||||
if (dto.genFiles.Contains(1))
|
||||
if (dto.GenCodeFiles.Contains(1))
|
||||
{
|
||||
Tuple<string, string> tuple = GenerateModels(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
GenerateModels(replaceDto, dto);
|
||||
}
|
||||
if (dto.genFiles.Contains(2))
|
||||
if (dto.GenCodeFiles.Contains(2))
|
||||
{
|
||||
Tuple<string, string> tuple = GenerateInputDto(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
GenerateInputDto(replaceDto, dto);
|
||||
}
|
||||
if (dto.genFiles.Contains(3))
|
||||
if (dto.GenCodeFiles.Contains(3))
|
||||
{
|
||||
Tuple<string, string> tuple = GenerateRepository(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
GenerateRepository(replaceDto, dto);
|
||||
}
|
||||
if (dto.genFiles.Contains(4))
|
||||
if (dto.GenCodeFiles.Contains(4))
|
||||
{
|
||||
Tuple<string, string> tuple = GenerateIService(replaceDto, dto);
|
||||
Tuple<string, string> tuple_1 = GenerateService(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
genPathList.Add(tuple_1.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
WriteAndSave(tuple_1.Item1, tuple_1.Item2);
|
||||
GenerateIService(replaceDto, dto);
|
||||
GenerateService(replaceDto, dto);
|
||||
}
|
||||
if (dto.genFiles.Contains(5))
|
||||
if (dto.GenCodeFiles.Contains(5))
|
||||
{
|
||||
Tuple<string, string> tuple = GenerateControllers(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
GenerateControllers(replaceDto, dto);
|
||||
}
|
||||
if (dto.genFiles.Contains(6))
|
||||
if (dto.GenCodeFiles.Contains(6))
|
||||
{
|
||||
Tuple<string, string> tuple = GenerateVueViews(replaceDto, dto);
|
||||
Tuple<string, string> tuple_1 = GenerateVueJs(replaceDto, dto);
|
||||
genPathList.Add(tuple.Item1);
|
||||
genPathList.Add(tuple_1.Item1);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
WriteAndSave(tuple_1.Item1, tuple_1.Item2);
|
||||
GenerateVueViews(replaceDto, dto);
|
||||
}
|
||||
if (dto.genFiles.Contains(7))
|
||||
if (dto.GenCodeFiles.Contains(7))
|
||||
{
|
||||
Tuple<string, string> tuple = GenerateSql(replaceDto, dto);
|
||||
WriteAndSave(tuple.Item1, tuple.Item2);
|
||||
GenerateVueJs(replaceDto, dto);
|
||||
}
|
||||
if (dto.GenCodeFiles.Contains(8))
|
||||
{
|
||||
GenerateSql(replaceDto, dto);
|
||||
}
|
||||
if (dto.IsPreview == 1)
|
||||
{
|
||||
return;
|
||||
}
|
||||
foreach (var item in dto.GenCodes)
|
||||
{
|
||||
FileHelper.WriteAndSave(item.Path, item.Content);
|
||||
}
|
||||
return genPathList;
|
||||
}
|
||||
|
||||
#region 生成Model
|
||||
|
||||
/// <summary>
|
||||
/// 生成Models文件
|
||||
/// 生成实体类Model
|
||||
/// </summary>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static Tuple<string, string> GenerateModels(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
private static void GenerateModels(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
//../ZR.Model
|
||||
var servicesPath = Path.Combine(generateDto.GenCodePath, _option.ModelsNamespace, "Models");
|
||||
Console.WriteLine("创建文件夹" + servicesPath);
|
||||
CreateDirectory(servicesPath);
|
||||
// ../ZR.Model/Models/User.cs
|
||||
var fullPath = Path.Combine(servicesPath, replaceDto.ModelTypeName + ".cs");
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ModelsNamespace, "Models", replaceDto.ModelTypeName + ".cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var content = ReadTemplate("ModelTemplate.txt")
|
||||
var content = FileHelper.ReadTemplate("ModelTemplate.txt")
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{TableNameDesc}", replaceDto.TableDesc)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{KeyTypeName}", replaceDto.PKName)
|
||||
.Replace("{PropertyName}", replaceDto.ModelProperty)
|
||||
.Replace("{TableName}", replaceDto.TableName);
|
||||
.Replace("{TableName}", replaceDto.TableName)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
generateDto.GenCodes.Add(new GenCode(1, "实体类", fullPath, content));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成InputDto文件
|
||||
/// 生成表单提交输入参数Dto
|
||||
/// </summary>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static Tuple<string, string> GenerateInputDto(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
private static void GenerateInputDto(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var servicesPath = Path.Combine(generateDto.GenCodePath, _option.ModelsNamespace, "Dto");
|
||||
CreateDirectory(servicesPath);
|
||||
// ../ZR.Model/Dto/User.cs
|
||||
var fullPath = Path.Combine(servicesPath, $"{replaceDto.ModelTypeName}Dto.cs");
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ModelsNamespace, "Dto", $"{replaceDto.ModelTypeName}Dto.cs");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var content = ReadTemplate("InputDtoTemplate.txt")
|
||||
var content = FileHelper.ReadTemplate("InputDtoTemplate.txt")
|
||||
.Replace("{DtosNamespace}", _option.DtosNamespace)
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{TableNameDesc}", replaceDto.TableDesc)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{PropertyName}", replaceDto.InputDtoProperty)
|
||||
.Replace("{QueryProperty}", replaceDto.QueryProperty)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName);
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
//generateDto.GenCodes.Add(new GenCode(2, "数据传输实体类", fullPath, content));
|
||||
}
|
||||
#endregion
|
||||
|
||||
@@ -229,24 +212,23 @@ namespace ZR.CodeGenerator
|
||||
/// </summary>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static Tuple<string, string> GenerateRepository(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
private static void GenerateRepository(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var repositoryPath = Path.Combine(generateDto.GenCodePath, _option.RepositoriesNamespace, "Repositories");
|
||||
CreateDirectory(repositoryPath);
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.RepositoriesNamespace, "Repositories", $"{replaceDto.ModelTypeName}Repository.cs");
|
||||
|
||||
var fullPath = Path.Combine(repositoryPath, $"{replaceDto.ModelTypeName}Repository.cs");
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
|
||||
var content = ReadTemplate("RepositoryTemplate.txt")
|
||||
var content = FileHelper.ReadTemplate("RepositoryTemplate.txt")
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{RepositoriesNamespace}", _option.RepositoriesNamespace)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{TableNameDesc}", replaceDto.TableDesc)
|
||||
.Replace("{TableName}", replaceDto.TableName);
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{TableName}", replaceDto.TableName)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
generateDto.GenCodes.Add(new GenCode(3, "仓储层", fullPath, content));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -257,48 +239,47 @@ namespace ZR.CodeGenerator
|
||||
/// </summary>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <param name="replaceDto">替换实体</param>
|
||||
private static Tuple<string, string> GenerateIService(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
private static void GenerateIService(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var iServicesPath = Path.Combine(generateDto.GenCodePath, _option.IServicsNamespace, "Business", "IBusService");
|
||||
CreateDirectory(iServicesPath);
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.IServicsNamespace, "Business", "IBusService", $"I{replaceDto.ModelTypeName}Service.cs");
|
||||
|
||||
var fullPath = Path.Combine(iServicesPath, $"I{replaceDto.ModelTypeName}Service.cs");
|
||||
Console.WriteLine(fullPath);
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
var content = ReadTemplate("IServiceTemplate.txt")
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
var content = FileHelper.ReadTemplate("IServiceTemplate.txt")
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{TableNameDesc}", replaceDto.TableDesc)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{DtosNamespace}", _option.DtosNamespace)
|
||||
.Replace("{IServicsNamespace}", _option.IServicsNamespace)
|
||||
.Replace("{RepositoriesNamespace}", _option.RepositoriesNamespace)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName);
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
//generateDto.GenCodes.Add(new GenCode(4, "接口层", fullPath, content));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 生成Service文件
|
||||
/// </summary>
|
||||
private static Tuple<string, string> GenerateService(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
private static void GenerateService(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var servicesPath = Path.Combine(generateDto.GenCodePath, _option.ServicesNamespace, "Business");
|
||||
CreateDirectory(servicesPath);
|
||||
var fullPath = Path.Combine(servicesPath, $"{replaceDto.ModelTypeName}Service.cs");
|
||||
Console.WriteLine(fullPath);
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ServicesNamespace, "Business", $"{replaceDto.ModelTypeName}Service.cs");
|
||||
|
||||
var content = ReadTemplate("ServiceTemplate.txt")
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var content = FileHelper.ReadTemplate("ServiceTemplate.txt")
|
||||
.Replace("{IRepositoriesNamespace}", _option.IRepositoriesNamespace)
|
||||
.Replace("{DtosNamespace}", _option.DtosNamespace)
|
||||
.Replace("{IServicsNamespace}", _option.IServicsNamespace)
|
||||
.Replace("{TableNameDesc}", replaceDto.TableDesc)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{ServicesNamespace}", _option.ServicesNamespace)
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName);
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
generateDto.GenCodes.Add(new GenCode(4, "服务层", fullPath, content));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -307,47 +288,42 @@ namespace ZR.CodeGenerator
|
||||
/// <summary>
|
||||
/// 生成控制器ApiControllers文件
|
||||
/// </summary>
|
||||
private static Tuple<string, string> GenerateControllers(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
private static void GenerateControllers(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var servicesPath = Path.Combine(generateDto.GenCodePath, _option.ApiControllerNamespace, "Controllers", generateDto.GenTable.ModuleName);
|
||||
CreateDirectory(servicesPath);
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, _option.ApiControllerNamespace, "Controllers", generateDto.GenTable.ModuleName, $"{replaceDto.ModelTypeName}Controller.cs");
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
var fullPath = Path.Combine(servicesPath, $"{replaceDto.ModelTypeName}Controller.cs");
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
|
||||
var content = ReadTemplate("ControllersTemplate.txt")
|
||||
var content = FileHelper.ReadTemplate("ControllersTemplate.txt")
|
||||
.Replace("{ApiControllerNamespace}", _option.ApiControllerNamespace)
|
||||
.Replace("{ServicesNamespace}", _option.ServicesNamespace)
|
||||
.Replace("{ModelsNamespace}", _option.ModelsNamespace)
|
||||
.Replace("{TableDesc}", replaceDto.TableDesc)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{ModelName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Permission}", replaceDto.Permission)
|
||||
.Replace("{PrimaryKey}", replaceDto.PKName)
|
||||
.Replace("{UpdateColumn}", replaceDto.UpdateColumn)
|
||||
.Replace("{InsertColumn}", replaceDto.InsertColumn)
|
||||
.Replace("{ModuleName}", generateDto.GenTable.ModuleName)
|
||||
.Replace("{PKCsharpType}", replaceDto.PKType);
|
||||
.Replace("{PKCsharpType}", replaceDto.PKType)
|
||||
.Replace("{Author}", replaceDto.Author)
|
||||
.Replace("{DateTime}", replaceDto.AddTime);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
generateDto.GenCodes.Add(new GenCode(5, "控制器", fullPath, content));
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 生成Vue页面
|
||||
#region 生成Vue页面 & api
|
||||
/// <summary>
|
||||
/// 生成Vue页面
|
||||
private static Tuple<string, string> GenerateVueViews(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
/// 6、生成Vue页面
|
||||
private static void GenerateVueViews(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
var parentPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src");
|
||||
var servicesPath = Path.Combine(parentPath, "views", generateDto.GenTable.ModuleName, replaceDto.ViewsFileName);
|
||||
CreateDirectory(servicesPath);
|
||||
var fullPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src", "views", generateDto.GenTable.ModuleName, replaceDto.ViewsFileName, "index.vue");
|
||||
|
||||
var fullPath = Path.Combine(servicesPath, "index.vue");
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
|
||||
var content = ReadTemplate("VueTemplate.txt")
|
||||
var content = FileHelper.ReadTemplate("VueTemplate.txt")
|
||||
.Replace("{fileClassName}", replaceDto.ViewsFileName)
|
||||
.Replace("{VueViewListContent}", replaceDto.VueViewListHtml)//查询 table列
|
||||
.Replace("{VueViewFormContent}", replaceDto.VueViewFormHtml)//添加、修改表单
|
||||
@@ -357,42 +333,43 @@ namespace ZR.CodeGenerator
|
||||
.Replace("{vueJsMethod}", replaceDto.VueJsMethod)
|
||||
.Replace("{vueQueryFormHtml}", replaceDto.VueQueryFormHtml)
|
||||
.Replace("{VueDataContent}", replaceDto.VueDataContent)
|
||||
.Replace("{primaryKey}", FirstLowerCase(replaceDto.PKName))
|
||||
.Replace("{PrimaryKey}", FirstLowerCase(replaceDto.PKName))
|
||||
.Replace("{MountedMethod}", replaceDto.MountedMethod)
|
||||
.Replace("{VueViewEditFormRuleContent}", replaceDto.VueViewEditFormRuleContent);//添加、修改表单验证规则
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
generateDto.GenCodes.Add(new GenCode(6, "index.vue", fullPath, content));
|
||||
}
|
||||
public static Tuple<string, string> GenerateVueJs(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
/// <summary>
|
||||
/// 7、生成vue页面api
|
||||
/// </summary>
|
||||
/// <param name="replaceDto"></param>
|
||||
/// <param name="generateDto"></param>
|
||||
/// <returns></returns>
|
||||
public static void GenerateVueJs(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
//api js
|
||||
var parentPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src");
|
||||
string servicesPath = Path.Combine(parentPath, "api");
|
||||
CreateDirectory(servicesPath);
|
||||
string fullPath = Path.Combine(generateDto.GenCodePath, "ZR.Vue", "src", "api", replaceDto.ViewsFileName + ".js");
|
||||
|
||||
string fullPath = Path.Combine(servicesPath, replaceDto.ViewsFileName + ".js");
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
|
||||
var content = ReadTemplate("VueJsTemplate.txt")
|
||||
var content = FileHelper.ReadTemplate("VueJsTemplate.txt")
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{ModelTypeDesc}", replaceDto.TableDesc)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName)
|
||||
.Replace("{ModuleName}", generateDto.GenTable.ModuleName);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
generateDto.GenCodes.Add(new GenCode(7, "api.js", fullPath, content));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region 生成SQL
|
||||
#region 8、生成SQL
|
||||
|
||||
public static Tuple<string, string> GenerateSql(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
public static void GenerateSql(ReplaceDto replaceDto, GenerateDto generateDto)
|
||||
{
|
||||
string fullPath = Path.Combine(generateDto.GenCodePath, replaceDto.ViewsFileName + ".sql");
|
||||
|
||||
if (File.Exists(fullPath) && !generateDto.coverd)
|
||||
return Tuple.Create(fullPath, "");
|
||||
if (File.Exists(fullPath) && !generateDto.Coverd)
|
||||
return;
|
||||
var tempName = "";
|
||||
switch (generateDto.DbType)
|
||||
{
|
||||
@@ -405,7 +382,7 @@ namespace ZR.CodeGenerator
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var content = ReadTemplate($"{tempName}.txt")
|
||||
var content = FileHelper.ReadTemplate($"{tempName}.txt")
|
||||
.Replace("{ModelTypeName}", replaceDto.ModelTypeName)
|
||||
.Replace("{Permission}", replaceDto.Permission)
|
||||
.Replace("{ModelTypeDesc}", replaceDto.TableDesc)
|
||||
@@ -413,7 +390,7 @@ namespace ZR.CodeGenerator
|
||||
.Replace("{ViewsFileName}", replaceDto.ViewsFileName)
|
||||
.Replace("{FunctionName}", generateDto.GenTable.FunctionName);
|
||||
|
||||
return Tuple.Create(fullPath, content);
|
||||
generateDto.GenCodes.Add(new GenCode(8, "sql", fullPath, content));
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -465,94 +442,6 @@ namespace ZR.CodeGenerator
|
||||
{
|
||||
return string.IsNullOrEmpty(columnDescription) ? columnName : columnDescription;
|
||||
}
|
||||
/// <summary>
|
||||
/// 从代码模板中读取内容
|
||||
/// </summary>
|
||||
/// <param name="templateName">模板名称,应包括文件扩展名称。比如:template.txt</param>
|
||||
/// <returns></returns>
|
||||
private static string ReadTemplate(string templateName)
|
||||
{
|
||||
string path = Environment.CurrentDirectory;
|
||||
string fullName = $"{path}/wwwroot/CodeGenTemplate/{templateName}";
|
||||
|
||||
Console.WriteLine("开始读取模板=" + fullName);
|
||||
string temp = fullName;
|
||||
string str = "";
|
||||
if (!File.Exists(temp))
|
||||
{
|
||||
return str;
|
||||
}
|
||||
StreamReader sr = null;
|
||||
try
|
||||
{
|
||||
sr = new StreamReader(temp);
|
||||
str = sr.ReadToEnd(); // 读取文件
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"读取模板出错了{ex.Message}");
|
||||
}
|
||||
sr?.Close();
|
||||
sr?.Dispose();
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 写文件
|
||||
/// </summary>
|
||||
/// <param name="fileName"></param>
|
||||
/// <param name="content"></param>
|
||||
private static void WriteAndSave(string fileName, string content)
|
||||
{
|
||||
fileName = fileName.Replace("\\", "/").Replace("//", "/");
|
||||
Console.WriteLine("写入文件:" + fileName);
|
||||
try
|
||||
{
|
||||
//实例化一个文件流--->与写入文件相关联
|
||||
using var fs = new FileStream(fileName, FileMode.Create, FileAccess.Write);
|
||||
//实例化一个StreamWriter-->与fs相关联
|
||||
using var sw = new StreamWriter(fs);
|
||||
//开始写入
|
||||
sw.Write(content);
|
||||
//清空缓冲区
|
||||
sw.Flush();
|
||||
//关闭流
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("写入文件出错了:" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建文件夹
|
||||
/// </summary>
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static bool CreateDirectory(string path)
|
||||
{
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
path = path.Replace("\\", "/").Replace("//", "/");
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
DirectoryInfo info = Directory.CreateDirectory(path);
|
||||
Console.WriteLine("不存在创建文件夹" + info);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"创建文件夹出错了,{ex.Message}");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
@@ -573,7 +462,7 @@ namespace ZR.CodeGenerator
|
||||
ColumnType = column.DataType,
|
||||
TableId = genTable.TableId,
|
||||
TableName = genTable.TableName,
|
||||
CsharpType = TableMappingHelper.GetCSharpDatatype(column.DataType),
|
||||
CsharpType = GetCSharpDatatype(column.DataType),
|
||||
CsharpField = column.DbColumnName.Substring(0, 1).ToUpper() + column.DbColumnName[1..],
|
||||
IsRequired = !column.IsNullable,
|
||||
IsIncrement = column.IsIdentity,
|
||||
@@ -623,35 +512,32 @@ namespace ZR.CodeGenerator
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 压缩代码
|
||||
/// 获取C# 类型
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <param name="sDatatype"></param>
|
||||
/// <returns></returns>
|
||||
public static string ZipGenCode(GenerateDto dto)
|
||||
public static string GetCSharpDatatype(string sDatatype)
|
||||
{
|
||||
try
|
||||
sDatatype = sDatatype.ToLower();
|
||||
string sTempDatatype = sDatatype switch
|
||||
{
|
||||
//生成压缩包
|
||||
string zipReturnFileName = dto.GenTable.BaseNameSpace + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip";
|
||||
|
||||
CreateDirectory(dto.GenCodePath);
|
||||
string zipFileName = Path.Combine(dto.ZipPath, zipReturnFileName);
|
||||
if (File.Exists(zipFileName))
|
||||
{
|
||||
File.Delete(zipFileName);
|
||||
}
|
||||
|
||||
ZipFile.CreateFromDirectory(dto.GenCodePath, zipFileName);
|
||||
FileHelper.DeleteDirectory(dto.GenCodePath);
|
||||
dto.ZipFileName = zipReturnFileName;
|
||||
return zipReturnFileName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("压缩文件出错。" + ex.Message);
|
||||
return "";
|
||||
}
|
||||
"int" or "number" or "integer" or "smallint" => "int",
|
||||
"bigint" => "long",
|
||||
"tinyint" => "byte",
|
||||
"numeric" or "real" or "float" => "float",
|
||||
"decimal" or "numer(8,2)" => "decimal",
|
||||
"bit" => "bool",
|
||||
"date" or "datetime" or "datetime2" or "smalldatetime" => "DateTime",
|
||||
"money" or "smallmoney" => "double",
|
||||
_ => "string",
|
||||
};
|
||||
return sTempDatatype;
|
||||
}
|
||||
|
||||
public static bool IsNumber(string tableDataType)
|
||||
{
|
||||
string[] arr = new string[] { "int", "long" };
|
||||
return arr.Any(f => f.Contains(GetCSharpDatatype(tableDataType)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+109
-108
@@ -1,141 +1,142 @@
|
||||
using ICSharpCode.SharpZipLib.Checksum;
|
||||
using ICSharpCode.SharpZipLib.Zip;
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
using System.Linq;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using ZR.CodeGenerator.Model;
|
||||
|
||||
namespace ZR.CodeGenerator
|
||||
{
|
||||
public class FileHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// 制作压缩包(多个文件压缩到一个压缩包,支持加密、注释)
|
||||
/// 创建文件夹
|
||||
/// </summary>
|
||||
/// <param name="fileNames">要压缩的文件</param>
|
||||
/// <param name="topDirectoryName">压缩文件目录</param>
|
||||
/// <param name="zipedFileName">压缩包文件名</param>
|
||||
/// <param name="compresssionLevel">压缩级别 1-9</param>
|
||||
/// <param name="password">密码</param>
|
||||
/// <param name="comment">注释</param>
|
||||
public static void ZipFiles(string[] fileNames, string topDirectoryName, string zipedFileName, int? compresssionLevel, string password = "", string comment = "")
|
||||
/// <param name="path"></param>
|
||||
/// <returns></returns>
|
||||
public static bool CreateDirectory(string path)
|
||||
{
|
||||
using (ZipOutputStream zos = new ZipOutputStream(File.Open(zipedFileName, FileMode.OpenOrCreate)))
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
if (compresssionLevel.HasValue)
|
||||
path = path.Replace("\\", "/").Replace("//", "/");
|
||||
}
|
||||
try
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
zos.SetLevel(compresssionLevel.Value);//设置压缩级别
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(password))
|
||||
{
|
||||
zos.Password = password;//设置zip包加密密码
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(comment))
|
||||
{
|
||||
zos.SetComment(comment);//设置zip包的注释
|
||||
}
|
||||
|
||||
foreach (string file in fileNames)
|
||||
{
|
||||
//string fileName = string.Format("{0}/{1}", topDirectoryName, file);
|
||||
string fileName = file;
|
||||
|
||||
if (File.Exists(fileName))
|
||||
{
|
||||
FileInfo item = new FileInfo(fileName);
|
||||
FileStream fs = File.OpenRead(item.FullName);
|
||||
byte[] buffer = new byte[fs.Length];
|
||||
fs.Read(buffer, 0, buffer.Length);
|
||||
|
||||
ZipEntry entry = new ZipEntry(item.Name);
|
||||
zos.PutNextEntry(entry);
|
||||
zos.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
DirectoryInfo info = Directory.CreateDirectory(path);
|
||||
Console.WriteLine("不存在创建文件夹" + info);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"创建文件夹出错了,{ex.Message}");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 压缩多层目录
|
||||
/// 写文件
|
||||
/// </summary>
|
||||
/// <param name="topDirectoryName">压缩文件目录</param>
|
||||
/// <param name="zipedFileName">压缩包文件名</param>
|
||||
/// <param name="compresssionLevel">压缩级别 1-9 </param>
|
||||
/// <param name="password">密码</param>
|
||||
/// <param name="comment">注释</param>
|
||||
/// <param name="filetype">文件类型</param>
|
||||
public static void ZipFileDirectory(string topDirectoryName, string zipedFileName, int compresssionLevel, string password, string comment, string filetype)
|
||||
/// <param name="path">完整路径带扩展名的</param>
|
||||
/// <param name="content"></param>
|
||||
public static void WriteAndSave(string path, string content)
|
||||
{
|
||||
using (System.IO.FileStream ZipFile = File.Open(zipedFileName, FileMode.OpenOrCreate))
|
||||
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
|
||||
{
|
||||
using (ZipOutputStream zos = new ZipOutputStream(ZipFile))
|
||||
{
|
||||
if (compresssionLevel != 0)
|
||||
{
|
||||
zos.SetLevel(compresssionLevel);//设置压缩级别
|
||||
}
|
||||
if (!string.IsNullOrEmpty(password))
|
||||
{
|
||||
zos.Password = password;//设置zip包加密密码
|
||||
}
|
||||
if (!string.IsNullOrEmpty(comment))
|
||||
{
|
||||
zos.SetComment(comment);//设置zip包的注释
|
||||
}
|
||||
ZipSetp(topDirectoryName, zos, "", filetype);
|
||||
}
|
||||
path = path.Replace("\\", "/").Replace("//", "/");
|
||||
}
|
||||
if (!Directory.Exists(Path.GetDirectoryName(path)))
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetDirectoryName(path));
|
||||
}
|
||||
Console.WriteLine("写入文件:" + path);
|
||||
try
|
||||
{
|
||||
//实例化一个文件流--->与写入文件相关联
|
||||
using var fs = new FileStream(path, FileMode.Create, FileAccess.Write);
|
||||
//实例化一个StreamWriter-->与fs相关联
|
||||
using var sw = new StreamWriter(fs);
|
||||
//开始写入
|
||||
sw.Write(content);
|
||||
//清空缓冲区
|
||||
sw.Flush();
|
||||
//关闭流
|
||||
sw.Close();
|
||||
fs.Close();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("写入文件出错了:" + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 递归遍历目录
|
||||
/// </summary>
|
||||
/// <param name="strDirectory">The directory.</param>
|
||||
/// <param name="s">The ZipOutputStream Object.</param>
|
||||
/// <param name="parentPath">The parent path.</param>
|
||||
private static void ZipSetp(string strDirectory, ZipOutputStream s, string parentPath, string filetype)
|
||||
{
|
||||
if (strDirectory[^1] != Path.DirectorySeparatorChar)
|
||||
{
|
||||
strDirectory += Path.DirectorySeparatorChar;
|
||||
}
|
||||
Console.WriteLine("strDirectory=" + strDirectory);
|
||||
Crc32 crc = new Crc32();
|
||||
|
||||
string[] filenames = Directory.GetFileSystemEntries(strDirectory, filetype);
|
||||
foreach (string file in filenames)// 遍历所有的文件和目录
|
||||
/// <summary>
|
||||
/// 从代码模板中读取内容
|
||||
/// </summary>
|
||||
/// <param name="templateName">模板名称,应包括文件扩展名称。比如:template.txt</param>
|
||||
/// <returns></returns>
|
||||
public static string ReadTemplate(string templateName)
|
||||
{
|
||||
string path = Environment.CurrentDirectory;
|
||||
string fullName = $"{path}/wwwroot/CodeGenTemplate/{templateName}";
|
||||
|
||||
Console.WriteLine("开始读取模板=" + fullName);
|
||||
string temp = fullName;
|
||||
string str = "";
|
||||
if (!File.Exists(temp))
|
||||
{
|
||||
if (Directory.Exists(file))// 先当作目录处理如果存在这个目录就递归Copy该目录下面的文件
|
||||
return str;
|
||||
}
|
||||
StreamReader sr = null;
|
||||
try
|
||||
{
|
||||
sr = new StreamReader(temp);
|
||||
str = sr.ReadToEnd(); // 读取文件
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine($"读取模板出错了{ex.Message}");
|
||||
}
|
||||
sr?.Close();
|
||||
sr?.Dispose();
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// 压缩代码
|
||||
/// </summary>
|
||||
/// <param name="dto"></param>
|
||||
/// <returns></returns>
|
||||
public static string ZipGenCode(GenerateDto dto)
|
||||
{
|
||||
try
|
||||
{
|
||||
//生成压缩包
|
||||
string zipReturnFileName = dto.GenTable.BaseNameSpace + DateTime.Now.ToString("yyyyMMddHHmmss") + ".zip";
|
||||
|
||||
CreateDirectory(dto.GenCodePath);
|
||||
string zipFileName = Path.Combine(dto.ZipPath, zipReturnFileName);
|
||||
if (File.Exists(zipFileName))
|
||||
{
|
||||
string pPath = parentPath;
|
||||
pPath += file[(file.LastIndexOf("/") + 1)..];
|
||||
pPath += "/";
|
||||
Console.WriteLine("递归路径" + pPath);
|
||||
ZipSetp(file, s, pPath, filetype);
|
||||
}
|
||||
else // 否则直接压缩文件
|
||||
{
|
||||
//打开压缩文件
|
||||
using (FileStream fs = File.OpenRead(file))
|
||||
{
|
||||
byte[] buffer = new byte[fs.Length];
|
||||
fs.Read(buffer, 0, buffer.Length);
|
||||
string fileName = parentPath + file[(file.LastIndexOf("/") + 1)..];
|
||||
ZipEntry entry = new ZipEntry(fileName);
|
||||
entry.DateTime = DateTime.Now;
|
||||
entry.Size = fs.Length;
|
||||
fs.Close();
|
||||
crc.Reset();
|
||||
crc.Update(buffer);
|
||||
entry.Crc = crc.Value;
|
||||
s.PutNextEntry(entry);
|
||||
s.Write(buffer, 0, buffer.Length);
|
||||
}
|
||||
File.Delete(zipFileName);
|
||||
}
|
||||
|
||||
ZipFile.CreateFromDirectory(dto.GenCodePath, zipFileName);
|
||||
DeleteDirectory(dto.GenCodePath);
|
||||
dto.ZipFileName = zipReturnFileName;
|
||||
return zipReturnFileName;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("压缩文件出错。" + ex.Message);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,30 +10,29 @@ namespace ZR.CodeGenerator.Model
|
||||
public class GenerateDto
|
||||
{
|
||||
public long TableId { get; set; }
|
||||
public string[] QueryColumn { get; set; }
|
||||
|
||||
//public string[] QueryColumn { get; set; }
|
||||
/// <summary>
|
||||
/// 是否预览代码
|
||||
/// </summary>
|
||||
public int IsPreview { get; set; }
|
||||
/// <summary>
|
||||
/// 要生成的文件
|
||||
/// </summary>
|
||||
public int[] genFiles { get; set; }
|
||||
public int[] GenCodeFiles { get; set; }
|
||||
/// <summary>
|
||||
/// 如果目标文件存在,是否覆盖。默认为false
|
||||
/// </summary>
|
||||
public bool coverd { get; set; } = true;
|
||||
public bool Coverd { get; set; } = true;
|
||||
/// <summary>
|
||||
/// 生成代码的数据库类型 0、mysql 1、sqlserver
|
||||
/// </summary>
|
||||
public int DbType { get; set; }
|
||||
public GenTable GenTable { get; set; }
|
||||
#region 存储路径
|
||||
//public string ModelPath { get; set; }
|
||||
//public string ServicePath { get; set; }
|
||||
//public string RepositoryPath { get; set; }
|
||||
//public string ApiPath { get; set; }
|
||||
//public string VuePath { get; set; }
|
||||
//public string VueApiPath { get; set; }
|
||||
|
||||
//public string ParentPath { get; set; } = "..";
|
||||
/// <summary>
|
||||
/// 代码模板预览存储路径存放
|
||||
/// </summary>
|
||||
public List<GenCode> GenCodes { get; set; } = new List<GenCode>();
|
||||
/// <summary>
|
||||
/// 代码生成路径
|
||||
/// </summary>
|
||||
@@ -48,4 +47,20 @@ namespace ZR.CodeGenerator.Model
|
||||
public string ZipFileName { get; set; }
|
||||
#endregion
|
||||
}
|
||||
|
||||
public class GenCode
|
||||
{
|
||||
public int Type { get; set; }
|
||||
public string Title { get; set; }
|
||||
public string Path { get; set; }
|
||||
public string Content { get; set; }
|
||||
|
||||
public GenCode(int type, string title, string path, string content)
|
||||
{
|
||||
Type = type;
|
||||
Title = title;
|
||||
Path = path;
|
||||
Content = content;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,5 +100,7 @@ namespace ZR.CodeGenerator.Model
|
||||
/// views、js文件名
|
||||
/// </summary>
|
||||
public string ViewsFileName { get; set; }
|
||||
public string Author { get; set; }
|
||||
public string AddTime { get; set; } = DateTime.Now.ToString("yyyy-MM-dd");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Infrastructure.Extensions;
|
||||
using ZR.Common.Extension;
|
||||
|
||||
namespace ZR.CodeGenerator.CodeGenerator
|
||||
{
|
||||
public class TableMappingHelper
|
||||
{
|
||||
/// <summary>
|
||||
/// UserService转成userService
|
||||
/// </summary>
|
||||
/// <param name="s"></param>
|
||||
/// <returns></returns>
|
||||
public static string FirstLetterLowercase(string instanceName)
|
||||
{
|
||||
instanceName = instanceName.ParseToString();
|
||||
if (!instanceName.IsEmpty())
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.Append(instanceName[0].ToString().ToLower() + instanceName.Substring(1));
|
||||
return sb.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
return instanceName;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// sys_menu_authorize变成MenuAuthorize
|
||||
/// </summary>
|
||||
public static string GetClassNamePrefix(string tableName)
|
||||
{
|
||||
string[] arr = tableName.Split('_');
|
||||
if (arr.Length <= 0) return tableName;
|
||||
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (int i = 1; i < arr.Length; i++)
|
||||
{
|
||||
sb.Append(arr[i][0].ToString().ToUpper() + arr[i].Substring(1));
|
||||
}
|
||||
return sb.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取C# 类型
|
||||
/// </summary>
|
||||
/// <param name="sDatatype"></param>
|
||||
/// <returns></returns>
|
||||
public static string GetCSharpDatatype(string sDatatype)
|
||||
{
|
||||
sDatatype = sDatatype.ToLower();
|
||||
string sTempDatatype = sDatatype switch
|
||||
{
|
||||
"int" or "number" or "integer" or "smallint" => "int",
|
||||
"bigint" => "long",
|
||||
"tinyint" => "byte",
|
||||
"numeric" or "real" or "float" => "float",
|
||||
"decimal" or "numer(8,2)" => "decimal",
|
||||
"bit" => "bool",
|
||||
"date" or "datetime" or "datetime2" or "smalldatetime" => "DateTime",
|
||||
"money" or "smallmoney" => "double",
|
||||
_ => "string",
|
||||
};
|
||||
return sTempDatatype;
|
||||
}
|
||||
|
||||
public static bool IsNumber(string tableDataType)
|
||||
{
|
||||
string[] arr = new string[] { "int", "long" };
|
||||
return arr.Any(f => f.Contains(GetCSharpDatatype(tableDataType)));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user