public string GetStr_CreateMap(string str_nameSpace, DataTable dt_tables, string tableName) { string temp = tableName; string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); StringBuilder sb_body = new StringBuilder(); StringBuilder sb = new StringBuilder(); //sb_body.AppendLine("using " + str_nameSpace + ".Entity." + tablePrefix + ";"); //sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Model;"); //sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Query;"); //sb_body.AppendLine("using " + str_nameSpace + ".ViewModel." + tablePrefix + ".Filter;"); //sb_body.AppendLine("using " + str_nameSpace + ".ViewModel." + tablePrefix + ";"); //sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Cmd;"); //sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Query.Filter;"); //sb_body.AppendLine(""); //sb_body.AppendLine(""); //sb_body.AppendLine(""); sb_body.AppendLine(" #region " + tableName + ""); sb_body.AppendLine(""); sb_body.AppendLine(" cfg.CreateMap<" + tableName + "Entity, " + tableName + ">();"); sb_body.AppendLine(" cfg.CreateMap<" + tableName + ", " + tableName + "Entity>();"); sb_body.AppendLine(""); sb_body.AppendLine(" cfg.CreateMap<" + tableName + ", " + tableName + "Dto>();"); sb_body.AppendLine(" cfg.CreateMap<" + tableName + "Dto, " + tableName + ">();"); sb_body.AppendLine(""); SetData(tableName, sb); sb_body.AppendLine(sb.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" cfg.CreateMap<" + tableName + "FilterViewModel, " + tableName + "FilterDto>();"); sb_body.AppendLine(""); sb_body.AppendLine(" cfg.CreateMap<" + tableName + "CmdDto, " + tableName + ">();"); sb_body.AppendLine(" cfg.CreateMap<" + tableName + "ViewModel, " + tableName + "CmdDto>();"); sb_body.AppendLine(""); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); return(sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using System.Linq;"); sb_body.AppendLine("using System.Text;"); sb_body.AppendLine("using System.Threading.Tasks;"); sb_body.AppendLine("using Lee.Command;"); sb_body.AppendLine("using " + str_nameSpace + ".Entity;"); sb_body.AppendLine("using " + str_nameSpace + ".Entity." + tablePrefix + ";"); sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".DataAccessInterface." + tablePrefix + ""); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 数据访问接口:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public interface I" + tableName + "DataAccess : IDataAccess<" + tableName + "Entity>"); sb_body.AppendLine(" {"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 数据库接口:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public interface I" + tableName + "DbAccess : I" + tableName + "DataAccess"); sb_body.AppendLine(" {"); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); string file_Model = "C:\\Code\\" + str_nameSpace + ".DataAccessInterface\\" + tablePrefix + ""; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/I" + tableName + "DataAccess.cs", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); StringBuilder sb_body = new StringBuilder(); SetData(tableName, tablePrefix, tableDesc, sb_body); string filePath = "C:\\Code\\Sql"; if (!Directory.Exists(filePath)) { Directory.CreateDirectory(filePath); } CommonCode.Save(filePath + "/" + tableName + ".txt", sb_body.ToString()); CommonCode.Save(filePath + "/" + tableName + "_Delete.txt", GetSql_Delete(tableDesc)); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using System.Linq;"); sb_body.AppendLine("using System.Text;"); sb_body.AppendLine("using System.Threading.Tasks;"); sb_body.AppendLine("using Lee.Command;"); sb_body.AppendLine("using Lee.CQuery;"); sb_body.AppendLine("using Lee.CQuery.Paging;"); sb_body.AppendLine("using Lee.Domain.Repository;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Model;"); sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".Domain." + tablePrefix + ".Repository"); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 存储:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public interface I" + tableName + "Repository : IRepository<" + tableName + ">"); sb_body.AppendLine(" {"); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); string file_Model = "C:\\Code\\" + str_nameSpace + ".Domain\\" + tablePrefix + "\\Repository"; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/I" + tableName + "Repository.cs", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using Lee.Domain.Repository;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Model;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Repository;"); sb_body.AppendLine("using " + str_nameSpace + ".Entity." + tablePrefix + ";"); sb_body.AppendLine("using " + str_nameSpace + ".DataAccessInterface." + tablePrefix + ";"); sb_body.AppendLine(""); sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".Repository." + tablePrefix + ""); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 存储:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public class " + tableName + "Repository : DefaultRepository<" + tableName + ", " + tableName + "Entity, I" + tableName + "DataAccess>, I" + tableName + "Repository"); sb_body.AppendLine(" {"); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); string file_Model = "C:\\Code\\" + str_nameSpace + ".Repository\\" + tablePrefix + ""; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + "Repository.cs", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName, string type) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); string src = CommonCode.projSrc + "/" + str_nameSpace + "." + type + "/" + str_nameSpace + "." + type + ".csproj"; var str = JsonHelper.GetFile(src); var suffix = type; string[] arr = JsonHelper.SplitString(str, "\r\n"); StringBuilder sb2 = new StringBuilder(); foreach (var item in arr) { sb2.AppendLine(item); if (item.Contains("SystemConfig") && !item.Contains(tableName)) { string pref = ""; if (type.Contains("Interface")) { pref = "I"; suffix = suffix.Replace("Interface", ""); } if (type == "Domain") { if (item.Contains("Model\\")) { pref = "Model\\"; suffix = ""; } else if (item.Contains("Repository\\")) { pref = "Repository\\I"; suffix = "Repository"; } else if (item.Contains("Service\\")) { pref = "Service\\"; suffix = "Service"; } } else if (type == "ViewModel") { if (item.Contains("Filter\\")) { pref = "Filter\\"; suffix = "FilterViewModel"; } else { suffix = "ViewModel"; } } else if (type == "Dto") { if (item.Contains("Cmd\\")) { pref = "Cmd\\"; suffix = "CmdDto"; } else if (item.Contains("Query\\Filter\\")) { pref = "Query\\Filter\\"; suffix = "FilterDto"; } else if (item.Contains("Query\\")) { pref = "Query\\"; suffix = "Dto"; } } suffix += ".cs"; if (type == "Web") { tablePrefix = "Views\\" + tablePrefix; suffix = ".cshtml"; } SaveData(tablePrefix, pref, tableName, suffix, sb2); } } string file_Model = "C:\\Code\\" + str_nameSpace + "." + type + ""; CommonCode.Save2(file_Model + "/" + str_nameSpace + "." + type + ".csproj", sb2.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); bool isPrimeKey = false; string primaryKey = ""; StringBuilder sb_GetEditData = new StringBuilder(); StringBuilder sb_SetEditData = new StringBuilder(); StringBuilder sb_Table_Th = new StringBuilder(); StringBuilder sb_EditDiv = new StringBuilder(); StringBuilder sb_Formatter = new StringBuilder(); var listModel = CommonCode.GetTableModel(tableName); #region Model //遍历每个字段 foreach (DataRow dr in dt_tables.Rows) { string columnName = dr["columnName"].ToString().Trim(); //字段名 string columnType = dr["columnType"].ToString().Trim(); //字段类型 string columnComment = dr["columnComment"].ToString().Trim(); //字段注释 string nullable = dr["nullable"].ToString().Trim(); //是否可空(Y是不为空,N是为空) string data_default = dr["data_default"].ToString().Trim(); //默認值 string data_maxLength = dr["char_col_decl_length"].ToString().Trim(); //最大長度 string bool_primaryKey = dr["primaryKey"].ToString().Trim(); //主键 值为Y或N if (bool_primaryKey.ToUpper() == "Y") //存在主键 { isPrimeKey = true; primaryKey = columnName.ToUpper(); } if (string.IsNullOrEmpty(columnComment)) { columnComment = columnName; } CommonCode.GetColumnType(ref columnType, ref data_default); nullable = CommonCode.GetNullable(columnType, nullable); string required = "true"; if (columnName == "Remark" || columnName == "SortIndex") { required = "false"; } var arr = new List <string> { "SysNo", "CreateDate", "UpdateDate", "Status", "Enable", "IsDeleted", "CreateUserID", "UpdateUserID", "IsDelete", }; if (!arr.Contains(columnName)) { if (columnType == "bool") { sb_GetEditData.AppendLine(" " + columnName + ": $(\"." + columnName + "\").combobox(\"getValue\"),"); sb_SetEditData.AppendLine(" $(\"." + columnName + "\").combobox(\"select\", row." + columnName + ");"); sb_Formatter.AppendLine(" function formatter" + columnName + "(value, row, index) {"); sb_Formatter.AppendLine(" if (value == true) {"); sb_Formatter.AppendLine(" return \"是\";"); sb_Formatter.AppendLine(" } else {"); sb_Formatter.AppendLine(" return \"否\";"); sb_Formatter.AppendLine(" }"); sb_Formatter.AppendLine(" return value;"); sb_Formatter.AppendLine(" }"); sb_Table_Th.AppendLine(" <th data-options=\"field:'" + columnName + "',width:100,align:'center',formatter:formatter" + columnName + "\">" + columnComment + "</th>"); sb_EditDiv.AppendLine(" <div class=\"layer_form_div\">"); sb_EditDiv.AppendLine(" <input class=\"easyui-combobox " + columnName + "\" name=\"" + columnName + "\" style=\"width: 300px;\" data-options=\"label:'" + columnComment + "',required:" + required + ",editable:false,valueField:'value',textField:'label',data:[{'value':true,label:'是',selected:true},{'value':false,label:'否'}],panelHeight:true\" />"); sb_EditDiv.AppendLine(" </div>"); sb_EditDiv.AppendLine(""); } else if (columnType == "DateTime") { sb_Table_Th.AppendLine(" <th data-options=\"field:'" + columnName + "',width:120,align:'center',formatter:fmDate\">" + columnComment + "</th>"); sb_GetEditData.AppendLine(" " + columnName + ": $(\"." + columnName + "\").textbox(\"getText\"),"); sb_SetEditData.AppendLine(" $(\"." + columnName + "\").textbox(\"setText\", fmDate(row." + columnName + "));"); sb_EditDiv.AppendLine(" <div class=\"layer_form_div\">"); sb_EditDiv.AppendLine(" <input class=\"easyui-datebox " + columnName + "\" name=\"" + columnName + "\" data-options=\"label:'" + columnComment + "',prompt:'请输入" + columnComment + "',required:" + required + ",validType:['length[1," + data_maxLength + "]'],missingMessage:'请输入" + columnComment + "'\" style=\"width: 300px;\" />"); sb_EditDiv.AppendLine(" </div>"); sb_EditDiv.AppendLine(""); } else { if (columnName.Length > 3 && columnName.Substring(columnName.Length - 2, 2) == "ID") { sb_Table_Th.AppendLine(" <th data-options=\"field:'" + columnName.Replace("ID", "Name") + "',width:100,align:'center'\">" + columnComment.Replace("ID", "") + "</th>"); string textField = GetTextField(listModel, columnName); sb_GetEditData.AppendLine(" " + columnName + ": $(\"." + columnName + "\").combobox(\"getValue\"),"); sb_SetEditData.AppendLine(" $(\"." + columnName + "\").combobox(\"select\", row." + columnName + ");"); sb_EditDiv.AppendLine(" <div class=\"layer_form_div\">"); sb_EditDiv.AppendLine(" <input class=\"easyui-combobox " + columnName + "\" name=\"" + columnName + "\" data-options=\"label:'" + columnComment.Replace("ID", "") + "',editable:false,valueField:'SysNo',textField:'" + textField + "',method:'get',url:'/Data/Get" + columnName.Replace("ID", "") + "List',panelHeight:200\" style=\"width: 300px;\" />"); sb_EditDiv.AppendLine(" </div>"); sb_EditDiv.AppendLine(""); } else { sb_Table_Th.AppendLine(" <th data-options=\"field:'" + columnName + "',width:100,align:'center'\">" + columnComment + "</th>"); sb_GetEditData.AppendLine(" " + columnName + ": $(\"." + columnName + "\").textbox(\"getText\"),"); sb_SetEditData.AppendLine(" $(\"." + columnName + "\").textbox(\"setText\", row." + columnName + ");"); if (columnName == "Remark") { sb_EditDiv.AppendLine(" <div class=\"layer_form_div\">"); sb_EditDiv.AppendLine(" <input class=\"easyui-textbox " + columnName + "\" name=\"" + columnName + "\" data-options=\"label:'" + columnComment + "',prompt:'请输入" + columnComment + "',required:" + required + ",validType:['length[1," + data_maxLength + "]'],missingMessage:'请输入" + columnComment + "',multiline:true\" style=\"width: 300px;height:100px;\" />"); sb_EditDiv.AppendLine(" </div>"); sb_EditDiv.AppendLine(""); } else { sb_EditDiv.AppendLine(" <div class=\"layer_form_div\">"); sb_EditDiv.AppendLine(" <input class=\"easyui-textbox " + columnName + "\" name=\"" + columnName + "\" data-options=\"label:'" + columnComment + "',prompt:'请输入" + columnComment + "',required:" + required + ",validType:['length[1," + data_maxLength + "]'],missingMessage:'请输入" + columnComment + "'\" style=\"width: 300px;\" />"); sb_EditDiv.AppendLine(" </div>"); sb_EditDiv.AppendLine(""); } } } } } #endregion Model StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("@{"); sb_body.AppendLine(" ViewBag.Title = \"" + tableDesc + "详情\";"); sb_body.AppendLine(" Layout = \"~/Views/Shared/_Layout.cshtml\";"); sb_body.AppendLine("}"); sb_body.AppendLine(""); sb_body.AppendLine("<script>"); sb_body.AppendLine(""); sb_body.AppendLine(" $(function () {"); sb_body.AppendLine(""); sb_body.AppendLine(" //加载表格"); sb_body.AppendLine(" grid(\"#dtGrid\", \"#dtGridToolber\");"); sb_body.AppendLine(""); sb_body.AppendLine(" //添加"); sb_body.AppendLine(" $(\"#add\").on(\"click\", function () {"); sb_body.AppendLine(" content(\"添加" + tableDesc + "\", \"insertRow\", true);"); sb_body.AppendLine(" });"); sb_body.AppendLine(""); sb_body.AppendLine(" //搜索"); sb_body.AppendLine(" $(\"#searchList\").on(\"click\", function () {"); sb_body.AppendLine(" $('#dtGrid').datagrid('load', GetQueryParams());"); sb_body.AppendLine(" });"); sb_body.AppendLine(""); sb_body.AppendLine(" //删除选中"); sb_body.AppendLine(" $('#remove').linkbutton({"); sb_body.AppendLine(" onClick: function () {"); sb_body.AppendLine(" var gridID = \"#dtGrid\";"); sb_body.AppendLine(" var rows = $(gridID).datagrid('getSelections');"); sb_body.AppendLine(""); sb_body.AppendLine(" if (rows.length > 0) {"); sb_body.AppendLine(" layer.alert(\"确定删除选中的" + tableDesc + "吗?\", {"); sb_body.AppendLine(" icon: 3,"); sb_body.AppendLine(" btn: ['确定', '取消'],"); sb_body.AppendLine(" yes: function (closeIndex) {"); sb_body.AppendLine(" deleSelected(gridID, rows, closeIndex);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" })"); sb_body.AppendLine(""); sb_body.AppendLine(" } else {"); sb_body.AppendLine(" layer.alert('请选择要删除的" + tableDesc + "', { icon: 0, time: 2000 });"); sb_body.AppendLine(" }"); sb_body.AppendLine(" }"); sb_body.AppendLine(" })"); sb_body.AppendLine(" });"); sb_body.AppendLine(""); sb_body.AppendLine(" //删除选中"); sb_body.AppendLine(" function deleSelected(gridID, rows, closeIndex) {"); sb_body.AppendLine(" var " + tableName + "Ids = new Array();"); sb_body.AppendLine(" for (var i = 0; i < rows.length; i++) {"); sb_body.AppendLine(" " + tableName + "Ids.push(rows[i].SysNo);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" var parm = {"); sb_body.AppendLine(" " + tableName + "Ids: " + tableName + "Ids,"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" var loadLayer = null;"); sb_body.AppendLine(" $.ajax({"); sb_body.AppendLine(" type: \"Post\","); sb_body.AppendLine(" url: \"Delete" + tableName + "\","); sb_body.AppendLine(" dataType: \"json\","); sb_body.AppendLine(" data: JSON.stringify(parm),"); sb_body.AppendLine(" contentType: \"application/json\","); sb_body.AppendLine(" beforeSend: function () {"); sb_body.AppendLine(" loadLayer = layer.load(2);"); sb_body.AppendLine(" },"); sb_body.AppendLine(" success: function (data) {"); sb_body.AppendLine(" layer.close(loadLayer);"); sb_body.AppendLine(" if (data.Success) {"); sb_body.AppendLine(" layer.close(closeIndex);"); sb_body.AppendLine(" //layer.msg(data.Message, { time: 1000, btn: ['关闭'] });"); sb_body.AppendLine(" $('#dtGrid').datagrid('reload');"); sb_body.AppendLine(" } else {"); sb_body.AppendLine(" layer.alert(data.Message);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" }"); sb_body.AppendLine(" });"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" //实例化表格"); sb_body.AppendLine(" function grid(id, toolbar) {"); sb_body.AppendLine(" $(id).datagrid({"); sb_body.AppendLine(" url: 'Get" + tableName + "Paging',"); sb_body.AppendLine(" method: 'get',"); sb_body.AppendLine(" height: \"100%\","); sb_body.AppendLine(" width: \"100%\","); sb_body.AppendLine(" autoRowHeight: true,"); sb_body.AppendLine(" fitColumns: true,"); sb_body.AppendLine(" collapsible: true,"); sb_body.AppendLine(" pagination: true,"); sb_body.AppendLine(" pageList: [10, 50, 100, 200, 500, 1000],"); sb_body.AppendLine(" pageSize: 100,"); sb_body.AppendLine(" queryParams: GetQueryParams(),"); sb_body.AppendLine(" striped: true,"); sb_body.AppendLine(" loading: true,"); sb_body.AppendLine(" singleSelect: false,"); sb_body.AppendLine(" //nowrap:true,"); sb_body.AppendLine(" //rownumbers: true,"); sb_body.AppendLine(" scrollbarSize: 0,"); sb_body.AppendLine(" toolbar: toolbar,"); sb_body.AppendLine(" onLoadSuccess: function (data) {"); sb_body.AppendLine(" if (data.total > 0) {"); sb_body.AppendLine(" //加载完成 实例化按钮"); sb_body.AppendLine(" handle_edit(id);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" }"); sb_body.AppendLine(" })"); sb_body.AppendLine(" };"); sb_body.AppendLine(""); sb_body.AppendLine(" //弹框"); sb_body.AppendLine(" function content(title, type, check, _index) {"); sb_body.AppendLine(" layer.open({"); sb_body.AppendLine(" type: 1,"); sb_body.AppendLine(" area: [],"); sb_body.AppendLine(" title: title,"); sb_body.AppendLine(" zIndex: 100,"); sb_body.AppendLine(" content: $(\"#Layer_" + tableName + "\"),"); sb_body.AppendLine(" btn: ['保存', '取消'],"); sb_body.AppendLine(" btn1: function (closeIndex) {"); sb_body.AppendLine(" submit(type, closeIndex);"); sb_body.AppendLine(" },"); sb_body.AppendLine(" btn2: function (closeIndex) {"); sb_body.AppendLine(" layer.close(closeIndex);"); sb_body.AppendLine(" },"); sb_body.AppendLine(" success: function () {"); sb_body.AppendLine(" if (check) {"); sb_body.AppendLine(" $(\"#Layer_Form_" + tableName + "\").form(\"reset\");"); sb_body.AppendLine(" } else {"); sb_body.AppendLine(" var rows = $('#dtGrid').datagrid('getRows');"); sb_body.AppendLine(" var row = rows[_index];"); sb_body.AppendLine(" SetEditData(row);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" }"); sb_body.AppendLine(" });"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" //弹框 提交表单"); sb_body.AppendLine(" function submit(type, closeIndex) {"); sb_body.AppendLine(""); sb_body.AppendLine(" $(\"#Layer_Form_" + tableName + "\").form(\"submit\", {"); sb_body.AppendLine(" onSubmit: function () {"); sb_body.AppendLine(" if ($(this).form(\"validate\")) {"); sb_body.AppendLine(" var loadLayer = null;"); sb_body.AppendLine(" $.ajax({"); sb_body.AppendLine(" url: \"Edit" + tableName + "\","); sb_body.AppendLine(" type: 'post',"); sb_body.AppendLine(" contentType: \"application/json\","); sb_body.AppendLine(" data: JSON.stringify(GetEditData(type)),"); sb_body.AppendLine(" beforeSend: function () {"); sb_body.AppendLine(" loadLayer = layer.load(2);"); sb_body.AppendLine(" },"); sb_body.AppendLine(" success: function (data) {"); sb_body.AppendLine(" layer.close(loadLayer);"); //sb_body.AppendLine(" data = $.parseJSON(data);"); sb_body.AppendLine(" if (!data.Success) {"); sb_body.AppendLine(" layer.alert(data.Message, { icon: 0, tiem: 1500 });"); sb_body.AppendLine(" return;"); sb_body.AppendLine(" }"); sb_body.AppendLine(" var rows = $(\"#dtGrid\").datagrid(\"getRows\");"); sb_body.AppendLine(" $(\"#dtGrid\").datagrid('loadData', rows);"); sb_body.AppendLine(" layer.close(closeIndex);//关闭面板"); sb_body.AppendLine(" $('#dtGrid').datagrid('reload');"); sb_body.AppendLine(" },"); sb_body.AppendLine(" error: function (s) {"); sb_body.AppendLine(""); sb_body.AppendLine(" }"); sb_body.AppendLine(" });"); sb_body.AppendLine(" } else {"); sb_body.AppendLine(" layer.alert(\"信息填写不完整\", { icon: 0, tiem: 1500 });"); sb_body.AppendLine(" }"); sb_body.AppendLine(" }"); sb_body.AppendLine(" });"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" //查询条件"); sb_body.AppendLine(" function GetQueryParams() {"); sb_body.AppendLine(" var parm = {"); sb_body.AppendLine(" " + tableName + "Name_Search: $('#" + tableName + "Name').val(),"); sb_body.AppendLine(" };"); sb_body.AppendLine(" return parm;"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" //提交数据"); sb_body.AppendLine(" function GetEditData(type) {"); sb_body.AppendLine(" var parm = {"); sb_body.AppendLine(" SysNo: type == \"updateRow\" ? $(\".SysNo\").textbox(\"getText\") : \"00000000-0000-0000-0000-000000000000\","); sb_body.AppendLine(sb_GetEditData.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" };"); sb_body.AppendLine(" return parm;"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" //编辑页面赋值"); sb_body.AppendLine(" function SetEditData(row) {"); sb_body.AppendLine(" $(\".SysNo\").textbox(\"setText\", row.SysNo);"); sb_body.AppendLine(sb_SetEditData.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" //格式化操作栏"); sb_body.AppendLine(" function formatterHandle(val, row, index) {"); sb_body.AppendLine(" var ops = \"\";"); sb_body.AppendLine(" ops += \"<a class='easyui-linkbutton style-primary edit'>编辑</a>\";"); sb_body.AppendLine(" return ops;"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" //编辑"); sb_body.AppendLine(" function handle_edit(id) {"); sb_body.AppendLine(" $(id).datagrid(\"getPanel\").find(\"tr .edit\").linkbutton({"); sb_body.AppendLine(" iconCls: 'icon iconfont icon-edit',"); sb_body.AppendLine(" onClick: function (item) {"); sb_body.AppendLine(" var EditIndex = $(this).parents(\"tr\").index();"); sb_body.AppendLine(" $(id).datagrid(\"selectRow\", EditIndex);"); sb_body.AppendLine(""); sb_body.AppendLine(" //var rows = $(id).datagrid('getRows');"); sb_body.AppendLine(" //var row = rows[EditIndex];"); sb_body.AppendLine(""); sb_body.AppendLine(" content(\"编辑" + tableDesc + "\", \"updateRow\", false, EditIndex);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" });"); sb_body.AppendLine(" }"); sb_body.AppendLine("</script>"); sb_body.AppendLine(""); sb_body.AppendLine("<body class=\"easyui-layout\">"); sb_body.AppendLine(" <div style=\"padding: 10px;\" id=\"dtGridToolber\">"); sb_body.AppendLine(" <input class=\"easyui-textbox\" style=\"width: 300px;\" id=\"" + tableName + "Name\" data-options=\"label:'" + tableDesc + "名称',prompt:'请输入" + tableDesc + "名称'\" />"); sb_body.AppendLine(""); sb_body.AppendLine(" <a id=\"searchList\" class=\"easyui-linkbutton style-primary\" style=\"margin: 0\" data-options=\"iconCls:'icon iconfont icon-sousuo'\">搜索</a>"); sb_body.AppendLine(" <a id=\"remove\" class=\"easyui-linkbutton style-red\" style=\"float: right;margin: 0 5px 0 0;\" data-options=\"iconCls:'icon iconfont icon-delete2'\">删除选中</a>"); sb_body.AppendLine(" <a id=\"add\" class=\"easyui-linkbutton style-blue\" style=\"float: right;margin: 0 5px 0 0;\" data-options=\"iconCls:'icon iconfont icon-tianjia1'\">添加" + tableDesc + "</a>"); sb_body.AppendLine(""); sb_body.AppendLine(" </div>"); sb_body.AppendLine(" <table id=\"dtGrid\" scroll=\"on\">"); sb_body.AppendLine(" <thead>"); sb_body.AppendLine(" <tr>"); sb_body.AppendLine(" <th data-options=\"field:'ck',checkbox:true,fixed:true\"></th>"); sb_body.AppendLine(" <th data-options=\"field:'SysNo',width:100,align:'center',hidden:true\">编号</th>"); sb_body.AppendLine(sb_Table_Th.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" <th data-options=\"field:'CreateDate',width:120,align:'center',formatter:fmDate\">添加时间</th>"); sb_body.AppendLine(" <th data-options=\"field:'UpdateDate',width:120,align:'center',formatter:fmDate\">更新时间</th>"); sb_body.AppendLine(" <th data-options=\"field:'handle',width:100,align:'center',fixed:true,formatter:formatterHandle\">操作</th>"); sb_body.AppendLine(" </tr>"); sb_body.AppendLine(" </thead>"); sb_body.AppendLine(" </table>"); sb_body.AppendLine(""); sb_body.AppendLine(" <div id=\"Layer_" + tableName + "\" style=\"width: 600px;height: 400px;display: none;\">"); sb_body.AppendLine(" <form class=\"easyui-form\" id=\"Layer_Form_" + tableName + "\" style=\"width: 80%;margin: 20px auto;\">"); sb_body.AppendLine(" <div class=\"layer_form_div\" style=\"display:none\">"); sb_body.AppendLine(" <input class=\"easyui-textbox SysNo\" name=\"SysNo\" data-options=\"label:'编号'\" />"); sb_body.AppendLine(" </div>"); sb_body.AppendLine(sb_EditDiv.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" </form>"); sb_body.AppendLine(""); sb_body.AppendLine(" </div>"); sb_body.AppendLine(""); sb_body.AppendLine("</body>"); sb_body.AppendLine(""); string file_Model = "C:\\Code\\" + str_nameSpace + ".Web\\Views\\" + tablePrefix + "\\"; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + ".cshtml", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); bool isPrimeKey = false; string primaryKey = ""; bool isSortIndex = false; StringBuilder sb = new StringBuilder(); StringBuilder sb_search = new StringBuilder(); #region Model //遍历每个字段 foreach (DataRow dr in dt_tables.Rows) { string columnName = dr["columnName"].ToString().Trim(); //字段名 string columnType = dr["columnType"].ToString().Trim(); //字段类型 string columnComment = dr["columnComment"].ToString().Trim(); //字段注释 string nullable = dr["nullable"].ToString().Trim(); //是否可空(Y是不为空,N是为空) string data_default = dr["data_default"].ToString().Trim(); //默認值 string data_maxLength = dr["char_col_decl_length"].ToString().Trim(); //最大長度 string bool_primaryKey = dr["primaryKey"].ToString().Trim(); //主键 值为Y或N if (bool_primaryKey.ToUpper() == "Y") //存在主键 { isPrimeKey = true; primaryKey = columnName.ToUpper(); } if (string.IsNullOrEmpty(columnComment)) { columnComment = columnName; } CommonCode.GetColumnType(ref columnType, ref data_default); nullable = CommonCode.GetNullable(columnType, nullable); if (columnType == "string") { sb.AppendLine(" if (!filter." + columnName + ".IsNullOrEmpty())"); sb.AppendLine(" {"); sb.AppendLine(" query.Equal<" + tableName + "Query>(c => c." + columnName + ", filter." + columnName + ");"); sb.AppendLine(" }"); sb_search.AppendLine(" if (!filter." + columnName + "_Search.IsNullOrEmpty())"); sb_search.AppendLine(" {"); sb_search.AppendLine(" query.Like<" + tableName + "Query>(c => c." + columnName + ", filter." + columnName + "_Search);"); sb_search.AppendLine(" }"); } else if (columnName == "IsDelete") { sb_search.AppendLine(""); sb_search.AppendLine(" query.Equal<" + tableName + "Query>(c => c." + columnName + ", false);"); sb_search.AppendLine(""); } else { sb.AppendLine(" if (filter." + columnName + ".HasValue)"); sb.AppendLine(" {"); sb.AppendLine(" query.Equal<" + tableName + "Query>(c => c." + columnName + ", filter." + columnName + ");"); sb.AppendLine(" }"); } if (columnName == "SortIndex") { isSortIndex = true; } } #endregion Model bool IsSetFilter = false; bool IsSaveHistory = true; StringBuilder sb2 = new StringBuilder(); var listModel = CommonCode.GetTableModel(tableName); if (listModel != null) { foreach (var item in listModel) { SetSB(sb2, item, tableName); if (item.IsSetFilter.HasValue) { IsSetFilter = item.IsSetFilter.Value; } if (item.IsSaveHistory.HasValue) { IsSaveHistory = item.IsSaveHistory.Value; } } } var tableModels = CommonCode.GetTableModel(tableName); foreach (var item in tableModels) { } StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using System.Linq;"); sb_body.AppendLine("using System.Data.SqlClient;"); sb_body.AppendLine("using System.Transactions;"); sb_body.AppendLine("using Lee.Command.UnitOfWork;"); sb_body.AppendLine("using Lee.CQuery;"); sb_body.AppendLine("using Lee.CQuery.Paging;"); sb_body.AppendLine("using Lee.Utility;"); sb_body.AppendLine("using Lee.Utility.Extension;"); sb_body.AppendLine("using " + str_nameSpace + ".BusinessInterface." + tablePrefix + ";"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Model;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Service;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Query.Filter;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Cmd;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Query;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO.Query;"); sb_body.AppendLine("using " + str_nameSpace + ".Query." + tablePrefix + ";"); sb_body.AppendLine("using " + str_nameSpace + ".DTO.Bcl.Cmd;"); sb_body.AppendLine("using " + str_nameSpace + ".Enum;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain.Bcl.Service;"); sb_body.AppendLine("using " + str_nameSpace + ".Tools;"); sb_body.AppendLine("using " + str_nameSpace + ".Tools.Helper;"); sb_body.AppendLine("using " + str_nameSpace + ".Business.Common;"); sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".Business." + tablePrefix + ""); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 业务:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public class " + tableName + "Business : I" + tableName + "Business"); sb_body.AppendLine(" {"); sb_body.AppendLine(" public " + tableName + "Business()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 保存"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 保存" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"saveInfo\">保存信息</param>"); sb_body.AppendLine(" /// <returns>执行结果</returns>"); sb_body.AppendLine(" public Result<" + tableName + "Dto> Save" + tableName + "(Save" + tableName + "CmdDto saveInfo)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (saveInfo == null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Result<" + tableName + "Dto>.ErrorResult(\"没有指定任何要保存的信息\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(" using (var businessWork = UnitOfWork.Create())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var saveResult = " + tableName + "Service.Save" + tableName + "(saveInfo." + tableName + ".MapTo<" + tableName + ">());"); sb_body.AppendLine(" if (!saveResult.Success)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Result<" + tableName + "Dto>.ErrorResult(saveResult.Message);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" SaveHistory(saveInfo." + tableName + ", saveResult.Data.SysNo);"); sb_body.AppendLine(""); sb_body.AppendLine(" var commitResult = businessWork.Commit();"); sb_body.AppendLine(" Result<" + tableName + "Dto> result = null;"); sb_body.AppendLine(" if (commitResult.ExecutedSuccess)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" result = Result<" + tableName + "Dto>.SuccessResult(\"保存成功!\");"); sb_body.AppendLine(" result.Data = saveResult.Data.MapTo<" + tableName + "Dto>();"); sb_body.AppendLine(" }"); sb_body.AppendLine(" else"); sb_body.AppendLine(" {"); sb_body.AppendLine(" result = Result<" + tableName + "Dto>.ErrorResult(\"保存失败!\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(" return result;"); sb_body.AppendLine(" }"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 批量保存" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"saveInfo\">保存信息</param>"); sb_body.AppendLine(" /// <returns>执行结果</returns>"); sb_body.AppendLine(" public Result SaveList" + tableName + "(Save" + tableName + "CmdDto saveInfo)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (saveInfo == null || saveInfo.List" + tableName + ".IsNullOrEmpty())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Result.ErrorResult(\"没有指定任何要保存的信息\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" try"); sb_body.AppendLine(" {"); sb_body.AppendLine(" saveInfo.List" + tableName + ".Where(d => d.SysNo == Guid.Empty).ToList().ForEach(d => d.SysNo = Guid.NewGuid());"); sb_body.AppendLine(" var bulk = new SqlBulkTools.BulkOperations();"); sb_body.AppendLine(""); sb_body.AppendLine(" using (TransactionScope trans = new TransactionScope())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" using (SqlConnection conn = new SqlConnection(Keys.connectionString))"); sb_body.AppendLine(" {"); sb_body.AppendLine(" bulk.Setup<" + tableName + "CmdDto>()"); sb_body.AppendLine(" .ForCollection(saveInfo.List" + tableName + ")"); sb_body.AppendLine(" .WithTable(\"" + tablePrefix + "_" + tableName + "\")"); sb_body.AppendLine(" .AddAllColumns()"); sb_body.AppendLine(" .BulkInsertOrUpdate()"); sb_body.AppendLine(" .SetIdentityColumn(x => x.SysNo)"); sb_body.AppendLine(" .MatchTargetOn(x => x.SysNo)"); sb_body.AppendLine(" .Commit(conn);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" trans.Complete();"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); if (IsSaveHistory) { sb_body.AppendLine(" using (var businessWork = UnitOfWork.Create())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" foreach (var item in saveInfo.List" + tableName + ")"); sb_body.AppendLine(" {"); sb_body.AppendLine(" SaveHistory(item, item.SysNo);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" var commitResult = businessWork.Commit();"); sb_body.AppendLine(" }"); } sb_body.AppendLine(" return Result.SuccessResult(\"修改成功!\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(" catch (Exception ex)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" LogHelper.WriteError(ex);"); sb_body.AppendLine(" return Result.ErrorResult(\"修改失败!\" + ex.Message);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); //sb_body.AppendLine(" /// <summary>"); //sb_body.AppendLine(" /// 批量保存" + tableDesc); //sb_body.AppendLine(" /// </summary>"); //sb_body.AppendLine(" /// <param name=\"saveInfo\">保存信息</param>"); //sb_body.AppendLine(" /// <returns>执行结果</returns>"); //sb_body.AppendLine(" public Result SaveList" + tableName + "(Save" + tableName + "CmdDto saveInfo)"); //sb_body.AppendLine(" {"); //sb_body.AppendLine(" if (saveInfo == null || saveInfo.List" + tableName + ".IsNullOrEmpty())"); //sb_body.AppendLine(" {"); //sb_body.AppendLine(" return Result.ErrorResult(\"没有指定任何要保存的信息\");"); //sb_body.AppendLine(" }"); //sb_body.AppendLine(" using (var businessWork = UnitOfWork.Create())"); //sb_body.AppendLine(" {"); //sb_body.AppendLine(" var saveResult = " + tableName + "Service.SaveList" + tableName + "(saveInfo.List" + tableName + ".Select(c => c.MapTo<" + tableName + ">()));"); //sb_body.AppendLine(" if (!saveResult.Success)"); //sb_body.AppendLine(" {"); //sb_body.AppendLine(" return saveResult;"); //sb_body.AppendLine(" }"); //sb_body.AppendLine(""); //sb_body.AppendLine(" foreach (var item in saveInfo.List" + tableName + ")"); //sb_body.AppendLine(" {"); //sb_body.AppendLine(" SaveHistory(item, item.SysNo);"); //sb_body.AppendLine(" }"); //sb_body.AppendLine(""); //sb_body.AppendLine(" var commitResult = businessWork.Commit();"); //sb_body.AppendLine(" return commitResult.ExecutedSuccess ? Result.SuccessResult(\"修改成功\") : Result.ErrorResult(\"修改失败\");"); //sb_body.AppendLine(""); //sb_body.AppendLine(" }"); //sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion 保存"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"filter\">查询条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public " + tableName + "Dto Get" + tableName + "(" + tableName + "FilterDto filter)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var " + tableName + " = " + tableName + "Service.Get" + tableName + "(CreateQueryObject(filter));"); sb_body.AppendLine(" return " + tableName + ".MapTo<" + tableName + "Dto>();"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion 获取"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取列表"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc + "列表"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"filter\">查询条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public List<" + tableName + "Dto> Get" + tableName + "List(" + tableName + "FilterDto filter)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var " + tableName + "List = " + tableName + "Service.Get" + tableName + "List(CreateQueryObject(filter));"); sb_body.AppendLine(" return " + tableName + "List.Select(c => c.MapTo<" + tableName + "Dto>()).ToList();"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion 获取列表"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取分页"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc + "分页"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"filter\">查询条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public IPaging<" + tableName + "Dto> Get" + tableName + "Paging(" + tableName + "FilterDto filter)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var " + tableName + "Paging = " + tableName + "Service.Get" + tableName + "Paging(CreateQueryObject(filter));"); sb_body.AppendLine(" return " + tableName + "Paging.Convert<" + tableName + ", " + tableName + "Dto>();"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion 获取分页"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 删除"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 删除" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"deleteInfo\">删除信息</param>"); sb_body.AppendLine(" /// <returns>执行结果</returns>"); sb_body.AppendLine(" public Result Delete" + tableName + "(Delete" + tableName + "CmdDto deleteInfo)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (!deleteInfo.IsRealDeleted)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Delete" + tableName + "2(deleteInfo);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 参数判断"); sb_body.AppendLine(""); sb_body.AppendLine(" if (deleteInfo == null || deleteInfo." + tableName + "Ids.IsNullOrEmpty())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Result.ErrorResult(\"没有指定要删除的\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion 参数判断"); sb_body.AppendLine(""); sb_body.AppendLine(" using (var businessWork = UnitOfWork.Create())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var " + tableName + "s = deleteInfo." + tableName + "Ids.Select(c => " + tableName + ".Create" + tableName + "(c));"); sb_body.AppendLine(" var deleteResult = " + tableName + "Service.Delete" + tableName + "(" + tableName + "s);"); sb_body.AppendLine(" if (!deleteResult.Success)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return deleteResult;"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" SaveDeleteHistory(deleteInfo);"); sb_body.AppendLine(""); sb_body.AppendLine(" var commitResult = businessWork.Commit();"); sb_body.AppendLine(" return commitResult.ExecutedSuccess ? Result.SuccessResult(\"删除成功\") : Result.ErrorResult(\"删除失败\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 删除客户(假删除)"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"deleteInfo\"></param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public Result Delete" + tableName + "2(Delete" + tableName + "CmdDto deleteInfo)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" #region 参数判断"); sb_body.AppendLine(""); sb_body.AppendLine(" if (deleteInfo == null || deleteInfo." + tableName + "Ids.IsNullOrEmpty())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Result.ErrorResult(\"没有指定要删除的\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion 参数判断"); sb_body.AppendLine(""); sb_body.AppendLine(" try"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var List" + tableName + " = deleteInfo." + tableName + "Ids.Select(c => " + tableName + ".Create" + tableName + "(c)).MapTo<List<" + tableName + "CmdDto>>();"); sb_body.AppendLine(" List" + tableName + ".ForEach(d => d.UpdateDate = DateTime.Now);"); sb_body.AppendLine(" List" + tableName + ".ForEach(d => d.UpdateUserID = deleteInfo.UpdateUserID);"); sb_body.AppendLine(" List" + tableName + ".ForEach(d => d.IsDelete = true);"); sb_body.AppendLine(""); sb_body.AppendLine(" var bulk = new SqlBulkTools.BulkOperations();"); sb_body.AppendLine(""); sb_body.AppendLine(" using (TransactionScope trans = new TransactionScope())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" using (SqlConnection conn = new SqlConnection(Keys.connectionString))"); sb_body.AppendLine(" {"); sb_body.AppendLine(" bulk.Setup<" + tableName + "CmdDto>()"); sb_body.AppendLine(" .ForCollection(List" + tableName + ")"); sb_body.AppendLine(" .WithTable(\"" + tablePrefix + "_" + tableName + "\")"); sb_body.AppendLine(" .AddColumn(d => d.UpdateDate)"); sb_body.AppendLine(" .AddColumn(d => d.UpdateUserID)"); sb_body.AppendLine(" .AddColumn(d => d.IsDelete)"); sb_body.AppendLine(" .BulkUpdate()"); sb_body.AppendLine(" .SetIdentityColumn(x => x.SysNo)"); sb_body.AppendLine(" .MatchTargetOn(x => x.SysNo)"); sb_body.AppendLine(" .Commit(conn);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" trans.Complete();"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); if (IsSaveHistory) { sb_body.AppendLine(" using (var businessWork = UnitOfWork.Create())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" SaveDeleteHistory(deleteInfo);"); sb_body.AppendLine(" var commitResult = businessWork.Commit();"); sb_body.AppendLine(" }"); } sb_body.AppendLine(""); sb_body.AppendLine(" return Result.SuccessResult(\"删除成功!\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(" catch (Exception ex)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" LogHelper.WriteError(ex);"); sb_body.AppendLine(" return Result.ErrorResult(\"删除失败!\" + ex.Message);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" }"); sb_body.AppendLine(" #endregion 删除"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 历史记录"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 保存时,记录历史记录"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"saveInfo\"></param>"); sb_body.AppendLine(" /// <param name=\"SysNo\"></param>"); sb_body.AppendLine(" private static void SaveHistory(" + tableName + "CmdDto saveInfo, Guid SysNo)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" SaveHistoryCmdDto saveHistoryCmdDto = new SaveHistoryCmdDto()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" History = new HistoryCmdDto()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" OperationID = SysNo,"); sb_body.AppendLine(" OperationType = OperationTypeEnum." + tableName + ".ToString(),"); sb_body.AppendLine(" OperationName = saveInfo.SysNo == Guid.Empty ? OperationNameEnum.Add.ToString() : OperationNameEnum.Edit.ToString(),"); sb_body.AppendLine(" CreateUserID = saveInfo.UpdateUserID ?? Guid.Empty,"); sb_body.AppendLine(" }"); sb_body.AppendLine(" };"); sb_body.AppendLine(" HistoryService.SaveHistory(saveHistoryCmdDto.History.MapTo<Domain.Bcl.Model.History>());"); sb_body.AppendLine(""); sb_body.AppendLine(" LogHelper.WriteHistory(\"Save" + tableName + "\", JsonConvertHelper.SerializeObject(saveInfo), saveInfo.UpdateUserID);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 删除时,记录历史记录"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"deleteInfo\"></param>"); sb_body.AppendLine(" private void SaveDeleteHistory(Delete" + tableName + "CmdDto deleteInfo)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" foreach (var item in deleteInfo." + tableName + "Ids)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" SaveHistoryCmdDto saveHistoryCmdDto = new SaveHistoryCmdDto()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" History = new HistoryCmdDto()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" OperationID = item,"); sb_body.AppendLine(" OperationType = OperationTypeEnum." + tableName + ".ToString(),"); sb_body.AppendLine(" OperationName = OperationNameEnum.Delete.ToString(),"); sb_body.AppendLine(" CreateUserID = deleteInfo.UpdateUserID,"); sb_body.AppendLine(" }"); sb_body.AppendLine(" };"); sb_body.AppendLine(" HistoryService.SaveHistory(saveHistoryCmdDto.History.MapTo<Domain.Bcl.Model.History>());"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" LogHelper.WriteHistory(\"Delete" + tableName + "\", JsonConvertHelper.SerializeObject(deleteInfo), deleteInfo.UpdateUserID);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion 历史记录"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 根据查询条件生成查询对象"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 根据查询条件生成查询对象"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"filter\">查询条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" private IQuery CreateQueryObject(" + tableName + "FilterDto filter)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (filter == null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return null;"); sb_body.AppendLine(" }"); sb_body.AppendLine(" IQuery query = QueryFactory.Create<" + tableName + "Query>(filter);"); sb_body.AppendLine(" if (!filter.SysNos.IsNullOrEmpty())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" query.In<" + tableName + "Query>(c => c.SysNo, filter.SysNos);"); sb_body.AppendLine(" }"); sb_body.AppendLine(sb.ToString()); sb_body.AppendLine(""); if (IsSetFilter) { sb_body.AppendLine(" CommonSetFilter.SetFilter_" + tableName + "(filter, query);"); } sb_body.AppendLine(""); sb_body.AppendLine(" #region Search"); sb_body.AppendLine(""); sb_body.AppendLine(sb_search.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 数据加载"); sb_body.AppendLine(sb2.ToString()); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); if (isSortIndex) { sb_body.AppendLine(" query.Desc<" + tableName + "Query>(c => c.SortIndex);"); } sb_body.AppendLine(" query.Desc<" + tableName + "Query>(c => c.CreateDate);"); sb_body.AppendLine(" return query;"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion 根据查询条件生成查询对象"); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); sb_body.AppendLine(""); string file_Model = "C:\\Code\\" + str_nameSpace + ".Business\\" + tablePrefix + ""; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + "Business.cs", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); bool isPrimeKey = false; string primaryKey = ""; StringBuilder sb = new StringBuilder(); #region Model sb.AppendLine(" #region Model"); //遍历每个字段 foreach (DataRow dr in dt_tables.Rows) { string columnName = dr["columnName"].ToString().Trim(); //字段名 string columnType = dr["columnType"].ToString().Trim(); //字段类型 string columnComment = dr["columnComment"].ToString().Trim(); //字段注释 string nullable = dr["nullable"].ToString().Trim(); //是否可空(Y是不为空,N是为空) string data_default = dr["data_default"].ToString().Trim(); //默認值 string data_maxLength = dr["char_col_decl_length"].ToString().Trim(); //最大長度 string bool_primaryKey = dr["primaryKey"].ToString().Trim(); //主键 值为Y或N if (bool_primaryKey.ToUpper() == "Y") //存在主键 { isPrimeKey = true; primaryKey = columnName.ToUpper(); } if (string.IsNullOrEmpty(columnComment)) { columnComment = columnName; } CommonCode.GetColumnType(ref columnType, ref data_default); nullable = CommonCode.GetNullable(columnType, nullable); sb.AppendLine(""); sb.AppendLine(@" /// <summary>"); sb.AppendLine(@" /// " + columnComment); sb.AppendLine(@" /// </summary>"); //if (dr["nullable"].ToString().ToUpper().Trim() == "Y")//不為空 //{ // sb.AppendLine(@" [Required]"); //} //if (!string.IsNullOrEmpty(data_maxLength))//最大長度 //{ // sb.AppendLine(@" [StringLength(" + data_maxLength + ")]"); //} sb.AppendLine(" public " + columnType + nullable + " " + columnName); sb.AppendLine(" {"); sb.AppendLine(" get { return valueDic.GetValue<" + columnType + nullable + ">(\"" + columnName + "\"); }"); sb.AppendLine(" set { valueDic.SetValue(\"" + columnName + "\", value); }"); sb.AppendLine(" }"); } sb.AppendLine(""); sb.AppendLine(" #endregion Model"); #endregion Model StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using Lee.Command;"); sb_body.AppendLine("using Lee.Utility.Extension;"); sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".Entity." + tablePrefix + ""); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// Entity:"+ tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" [Serializable]"); sb_body.AppendLine(" public class "+ tableName + "Entity:CommandEntity<" + tableName + "Entity>"); sb_body.AppendLine(" {"); sb_body.AppendLine(""); sb_body.Append(sb.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); string file_Model = "C:\\Code\\" + str_nameSpace + ".Entity\\" + tablePrefix + ""; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + "Entity.cs", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using System.Linq;"); sb_body.AppendLine("using System.Text;"); sb_body.AppendLine("using System.Threading.Tasks;"); sb_body.AppendLine("using Lee.CQuery;"); sb_body.AppendLine("using Lee.CQuery.Paging;"); sb_body.AppendLine("using Lee.Utility;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Cmd;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Query;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Query.Filter;"); sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".ServiceInterface." + tablePrefix + ""); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 服务接口:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public interface I" + tableName + "Service"); sb_body.AppendLine(" {"); sb_body.AppendLine(" #region 保存"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 保存" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"saveInfo\">保存信息</param>"); sb_body.AppendLine(" /// <returns>执行结果</returns>"); sb_body.AppendLine(" Result<" + tableName + "Dto> Save" + tableName + "(Save" + tableName + "CmdDto saveInfo);"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 批量保存" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"saveInfo\">保存信息</param>"); sb_body.AppendLine(" /// <returns>执行结果</returns>"); sb_body.AppendLine(" Result SaveList" + tableName + "(Save" + tableName + "CmdDto saveInfo);"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"filter\">查询条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" " + tableName + "Dto Get" + tableName + "(" + tableName + "FilterDto filter);"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取列表"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc + "列表"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"filter\">查询条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" List<" + tableName + "Dto> Get" + tableName + "List(" + tableName + "FilterDto filter);"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取分页"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc + "分页"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"filter\">查询条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" IPaging<" + tableName + "Dto> Get" + tableName + "Paging(" + tableName + "FilterDto filter);"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 删除"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 删除" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"deleteInfo\">删除信息</param>"); sb_body.AppendLine(" /// <returns>执行结果</returns>"); sb_body.AppendLine(" Result Delete" + tableName + "(Delete" + tableName + "CmdDto deleteInfo);"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); string file_Model = "C:\\Code\\" + str_nameSpace + ".ServiceInterface\\" + tablePrefix + ""; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/I" + tableName + "Service.cs", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); bool isPrimeKey = false; string primaryKey = ""; StringBuilder sb = new StringBuilder(); StringBuilder sb_ext = new StringBuilder(); StringBuilder sb_search = new StringBuilder(); SetData(tableName, sb_ext); StringBuilder sb_load = new StringBuilder(); var listModel = CommonCode.GetTableModel(tableName); if (listModel != null) { foreach (var item in listModel) { SetLoad(sb_load, item); } } #region Model sb.AppendLine(" #region Model"); //遍历每个字段 foreach (DataRow dr in dt_tables.Rows) { string columnName = dr["columnName"].ToString().Trim(); //字段名 string columnType = dr["columnType"].ToString().Trim(); //字段类型 string columnComment = dr["columnComment"].ToString().Trim(); //字段注释 string nullable = dr["nullable"].ToString().Trim(); //是否可空(Y是不为空,N是为空) string data_default = dr["data_default"].ToString().Trim(); //默認值 string data_maxLength = dr["char_col_decl_length"].ToString().Trim(); //最大長度 string bool_primaryKey = dr["primaryKey"].ToString().Trim(); //主键 值为Y或N if (bool_primaryKey.ToUpper() == "Y") //存在主键 { isPrimeKey = true; primaryKey = columnName.ToUpper(); } if (string.IsNullOrEmpty(columnComment)) { columnComment = columnName; } CommonCode.GetColumnType(ref columnType, ref data_default); nullable = CommonCode.GetNullable(columnType, nullable); nullable = columnType == "string" ? "" : "?"; sb.AppendLine(""); sb.AppendLine(@" /// <summary>"); sb.AppendLine(@" /// " + columnComment); sb.AppendLine(@" /// </summary>"); sb.AppendLine(" public " + columnType + nullable + " " + columnName + " { get; set; }"); if (columnType == "string") { sb_search.AppendLine(""); sb_search.AppendLine(@" /// <summary>"); sb_search.AppendLine(@" /// " + columnComment); sb_search.AppendLine(@" /// </summary>"); sb_search.AppendLine(" public " + columnType + nullable + " " + columnName + "_Search { get; set; }"); } } sb.AppendLine(""); sb.AppendLine(" #endregion Model"); #endregion Model StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using Lee.CQuery.Paging;"); sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".ViewModel." + tablePrefix + ".Filter"); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// FilterViewModel:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public class " + tableName + "FilterViewModel: PagingFilter"); sb_body.AppendLine(" {"); sb_body.AppendLine(""); sb_body.Append(sb.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" #region Search"); sb_body.Append(sb_search.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion Search"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 数据加载"); sb_body.AppendLine(""); sb_body.AppendLine(sb_load.ToString()); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 扩展"); sb_body.AppendLine(""); sb_body.AppendLine(sb_ext.ToString()); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); string file_Model = "C:\\Code\\" + str_nameSpace + ".ViewModel\\" + tablePrefix + "\\Filter"; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + "FilterViewModel" + ".cs", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); bool isPrimeKey = false; string primaryKey = ""; int index = 0; StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); StringBuilder sb3 = new StringBuilder(); StringBuilder sb4 = new StringBuilder(); StringBuilder sb5 = new StringBuilder(); #region Model //遍历每个字段 foreach (DataRow dr in dt_tables.Rows) { string columnName = dr["columnName"].ToString().Trim(); //字段名 string columnType = dr["columnType"].ToString().Trim(); //字段类型 string columnComment = dr["columnComment"].ToString().Trim(); //字段注释 string nullable = dr["nullable"].ToString().Trim(); //是否可空(Y是不为空,N是为空) string data_default = dr["data_default"].ToString().Trim(); //默認值 string data_maxLength = dr["char_col_decl_length"].ToString().Trim(); //最大長度 string bool_primaryKey = dr["primaryKey"].ToString().Trim(); //主键 值为Y或N if (bool_primaryKey.ToUpper() == "Y") //存在主键 { isPrimeKey = true; primaryKey = columnName.ToUpper(); } if (string.IsNullOrEmpty(columnComment)) { columnComment = columnName; } CommonCode.GetColumnType(ref columnType, ref data_default); nullable = CommonCode.GetNullable(columnType, nullable); var arr = new List <string> { "SysNo", "OutsideCode", "ShopID", "StatisticalDate", "Remark", "CreateDate", "UpdateDate", "CreateUserID", "UpdateUserID", }; if (!arr.Contains(columnName)) { if (columnType == "string") { sb2.AppendLine("model." + columnName + " = GetColumnValue(listColumn, listDesc, row, \"" + columnName + "\");"); sb4.AppendLine(" model." + columnName + " = GetColumnValue(listColumn, dr, \"" + columnName + "\");"); } else if (columnType == "DateTime") { string col = columnType[0].ToString().ToUpper(); col += columnType.Substring(1, columnType.Length - 1); sb2.AppendLine("model." + columnName + " = GetColumnValue(listColumn, listDesc, row, \"" + columnName + "\").StrTo" + col + "();"); sb4.AppendLine(" model." + columnName + " = GetColumnValue(listColumn, dr, \"" + columnName + "\").StrTo" + col + "();"); } else { string col = columnType[0].ToString().ToUpper(); col += columnType.Substring(1, columnType.Length - 1); sb2.AppendLine("model." + columnName + " = GetColumnValue(listColumn, listDesc, row, \"" + columnName + "\").StrTo" + col + "(-1);"); sb4.AppendLine(" model." + columnName + " = GetColumnValue(listColumn, dr, \"" + columnName + "\").StrTo" + col + "(-1);"); } sb3.AppendLine(" Map(m => m." + columnName + ").Name(\"" + columnComment + "\");"); sb5.AppendLine(" ExcelHelper.SetCellValue(sheet, thisRow, " + index + ", item." + columnName + ", cellStyle);"); ++index; } sb.AppendLine(" {"); sb.AppendLine(" \"ColumnName\": \""+ columnName + "\","); sb.AppendLine(" \"ColumnDesc\": \""+ columnComment + "\""); sb.AppendLine(" },"); } #endregion Model StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("["); sb_body.AppendLine(" {"); sb_body.AppendLine(" \"TableName\": \""+ tableName + "\","); sb_body.AppendLine(" \"List\": ["); sb_body.Append(sb.ToString()); sb_body.AppendLine(" ]"); sb_body.AppendLine(" }"); sb_body.AppendLine("]"); StringBuilder sb_body3 = new StringBuilder(); sb_body3.AppendLine("using BigDataAnalysis.DTO.Original.Cmd;"); sb_body3.AppendLine("using System;"); sb_body3.AppendLine("using System.Collections.Generic;"); sb_body3.AppendLine("using System.Linq;"); sb_body3.AppendLine("using System.Text;"); sb_body3.AppendLine("using System.Threading.Tasks;"); sb_body3.AppendLine(""); sb_body3.AppendLine("namespace BigDataAnalysis.DTO.CSVMap"); sb_body3.AppendLine("{"); sb_body3.AppendLine(" /// <summary>"); sb_body3.AppendLine(" /// CSVHeaderMap:" + tableDesc + ""); sb_body3.AppendLine(" /// </summary>"); sb_body3.AppendLine(" public class CSVHeaderMap_" + tableName + " : CsvHelper.Configuration.ClassMap<" + tableName + "CmdDto>"); sb_body3.AppendLine(" {"); sb_body3.AppendLine(" public CSVHeaderMap_" + tableName + "()"); sb_body3.AppendLine(" {"); sb_body3.AppendLine(sb3.ToString()); sb_body3.AppendLine(" }"); sb_body3.AppendLine(" }"); sb_body3.AppendLine("}"); sb_body3.AppendLine(""); string file_Model = "C:\\Code\\Json"; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + ".json", sb_body.ToString()); CommonCode.Save(file_Model + "/" + tableName + "_GetColumnValue.txt", sb2.ToString()); CommonCode.Save(file_Model + "/CSVHeaderMap_" + tableName + ".cs", sb_body3.ToString()); CommonCode.Save(file_Model + "/DT_" + tableName + ".txt", sb4.ToString()); CommonCode.Save(file_Model + "/Export_" + tableName + ".txt", sb5.ToString()); }
public string GetStr_SetPrimaryKey(string str_nameSpace, DataTable dt_tables, string tableName) { string temp = tableName; string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine(" QueryConfig.SetPrimaryKey<" + tableName + "Entity>(u => u.SysNo);"); return(sb_body.ToString()); }
public string GetStr_SetObjectName(string str_nameSpace, DataTable dt_tables, string tableName) { string temp = tableName; string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine(" QueryConfig.SetObjectName(\"" + temp + "\", typeof(" + tableName + "Entity), typeof(" + tableName + "Query));"); return(sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); bool isPrimeKey = false; string primaryKey = ""; StringBuilder sb = new StringBuilder(); #region Model //遍历每个字段 foreach (DataRow dr in dt_tables.Rows) { string columnName = dr["columnName"].ToString().Trim(); //字段名 string columnType = dr["columnType"].ToString().Trim(); //字段类型 string columnComment = dr["columnComment"].ToString().Trim(); //字段注释 string nullable = dr["nullable"].ToString().Trim(); //是否可空(Y是不为空,N是为空) string data_default = dr["data_default"].ToString().Trim(); //默認值 string data_maxLength = dr["char_col_decl_length"].ToString().Trim(); //最大長度 string bool_primaryKey = dr["primaryKey"].ToString().Trim(); //主键 值为Y或N if (bool_primaryKey.ToUpper() == "Y") //存在主键 { isPrimeKey = true; primaryKey = columnName.ToUpper(); } if (string.IsNullOrEmpty(columnComment)) { columnComment = columnName; } CommonCode.GetColumnType(ref columnType, ref data_default); nullable = CommonCode.GetNullable(columnType, nullable); sb.Append("\"" + columnName + "\", "); } string str = sb.ToString().Substring(0, sb.ToString().Length - 2); #endregion Model StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using System.Linq;"); sb_body.AppendLine("using System.Text;"); sb_body.AppendLine("using System.Threading.Tasks;"); sb_body.AppendLine("using Lee.Command;"); sb_body.AppendLine("using Lee.Command.RDB;"); sb_body.AppendLine("using Lee.Command.UnitOfWork;"); sb_body.AppendLine("using Lee.Utility.Extension;"); sb_body.AppendLine("using " + str_nameSpace + ".DataAccessInterface." + tablePrefix + ";"); sb_body.AppendLine("using " + str_nameSpace + ".Entity." + tablePrefix + ";"); sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".DataAccess." + tablePrefix + ""); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 数据访问:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public class " + tableName + "DataAccess : RdbDataAccess<" + tableName + "Entity>, I" + tableName + "DbAccess"); sb_body.AppendLine(" {"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取添加字段"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取添加字段"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" protected override string[] GetEditFields()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return new string[] { " + str + " };"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取查询字段"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取查询字段"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" protected override string[] GetQueryFields()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return new string[] { " + str + " };"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); string file_Model = "C:\\Code\\" + str_nameSpace + ".DataAccess\\" + tablePrefix + ""; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + "DataAccess" + ".cs", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); bool isPrimeKey = false; string primaryKey = ""; StringBuilder sb = new StringBuilder(); StringBuilder sb_load = new StringBuilder(); var listModel = CommonCode.GetTableModel(tableName); if (listModel != null) { foreach (var item in listModel) { SetLoad(sb_load, item); } } StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using Lee.Web.Mvc;"); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using System.Linq;"); sb_body.AppendLine("using System.Web;"); sb_body.AppendLine("using System.Web.Mvc;"); sb_body.AppendLine("using Lee.Utility.Extension;"); sb_body.AppendLine("using Lee.Utility.Serialize;"); sb_body.AppendLine("using Lee.CQuery;"); sb_body.AppendLine("using Lee.CQuery.Paging;"); sb_body.AppendLine("using Lee.Utility;"); sb_body.AppendLine("using Lee.Application.Identity.User;"); sb_body.AppendLine("using Lee.Application.Identity.Auth;"); sb_body.AppendLine("using " + str_nameSpace + ".Web.Controllers.Base;"); sb_body.AppendLine("using " + str_nameSpace + ".ServiceInterface;"); sb_body.AppendLine("using " + str_nameSpace + ".ViewModel;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO.Cmd;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO.Query.Filter;"); sb_body.AppendLine("using " + str_nameSpace + ".ViewModel.Common;"); sb_body.AppendLine("using " + str_nameSpace + ".ViewModel.Filter;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO.Query;"); sb_body.AppendLine("using " + str_nameSpace + ".ServiceInterface." + tablePrefix + ";"); sb_body.AppendLine("using Lee.Utility.IoC;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Query.Filter;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Query;"); sb_body.AppendLine("using " + str_nameSpace + ".ViewModel." + tablePrefix + ";"); sb_body.AppendLine("using " + str_nameSpace + ".ViewModel." + tablePrefix + ".Filter;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO." + tablePrefix + ".Cmd;"); sb_body.AppendLine("using " + str_nameSpace + ".Web.Helper;"); sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".Web.Controllers"); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// Controller:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public partial class " + tablePrefix + "Controller : WebBaseController"); sb_body.AppendLine(" {"); sb_body.AppendLine(" I" + tableName + "Service " + tableName + "Service = ContainerManager.Container.Resolve<I" + tableName + "Service>();"); sb_body.AppendLine(" //Guid LoginUserId = UserHelper.GetLoginUserId();"); sb_body.AppendLine(""); //sb_body.AppendLine(" public " + tableName + "Controller() { }"); sb_body.AppendLine(""); sb_body.AppendLine(" #region " + tableDesc + "管理"); sb_body.AppendLine(" public ActionResult " + tableName + "()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return View();"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// " + tableDesc + "列表"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"filter\"></param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" [HttpGet]"); sb_body.AppendLine(" public JsonResult Get" + tableName + "Paging(" + tableName + "FilterViewModel filter)"); sb_body.AppendLine(" {"); sb_body.AppendLine(""); sb_body.AppendLine(" filter.PageSize = filter.rows;"); sb_body.AppendLine(sb_load.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" var pager = " + tableName + "Service.Get" + tableName + "Paging(filter.MapTo<" + tableName + "FilterDto>()).Convert<" + tableName + "Dto, " + tableName + "ViewModel>();"); sb_body.AppendLine(" object objResult = new"); sb_body.AppendLine(" {"); sb_body.AppendLine(" total = pager.TotalCount,"); sb_body.AppendLine(" rows = pager,"); sb_body.AppendLine(" };"); sb_body.AppendLine(" return Json(objResult, JsonRequestBehavior.AllowGet);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 下拉框:" + tableDesc + "列表"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"filter\"></param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" [HttpGet]"); sb_body.AppendLine(" public JsonResult Get" + tableName + "List(" + tableName + "FilterViewModel filter)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var list = " + tableName + "Service.Get" + tableName + "List(filter.MapTo<" + tableName + "FilterDto>());"); sb_body.AppendLine(" list.Insert(0, new " + tableName + "Dto { SysNo = Guid.Empty, " + tableName + "Name = \"\" });"); sb_body.AppendLine(" var result = list.Select(d => new { d.SysNo, d." + tableName + "Name });"); sb_body.AppendLine(" return Json(result, JsonRequestBehavior.AllowGet);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 添加、修改" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"user\"></param>"); sb_body.AppendLine(" /// <param name=\"userRoles\"></param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" [HttpPost]"); sb_body.AppendLine(" public JsonResult Edit" + tableName + "(" + tableName + "ViewModel vm)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" #region 验证是否存在"); sb_body.AppendLine(""); sb_body.AppendLine(" var model = " + tableName + "Service.Get" + tableName + "(new " + tableName + "FilterDto()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" " + tableName + "Name = vm." + tableName + "Name,"); sb_body.AppendLine(" });"); sb_body.AppendLine(" if (model != null && (vm.SysNo == Guid.Empty || model.SysNo != vm.SysNo))"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var result2 = Result<" + tableName + "ViewModel>.ErrorResult(\"" + tableDesc + "名称已存在!\");"); sb_body.AppendLine(" return Json(result2);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion 验证是否存在"); sb_body.AppendLine(" vm.UpdateDate = DateTime.Now;"); sb_body.AppendLine(" vm.UpdateUserID = LoginUserId;"); sb_body.AppendLine(" if (vm.SysNo == Guid.Empty)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" vm.CreateUserID = LoginUserId;"); sb_body.AppendLine(" }"); sb_body.AppendLine(" var saveInfo = new Save" + tableName + "CmdDto()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" " + tableName + " = vm.MapTo<" + tableName + "CmdDto>()"); sb_body.AppendLine(" };"); sb_body.AppendLine(" var result = " + tableName + "Service.Save" + tableName + "(saveInfo);"); sb_body.AppendLine(" return Json(result);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 批量添加、修改" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"user\"></param>"); sb_body.AppendLine(" /// <param name=\"userRoles\"></param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" [HttpPost]"); sb_body.AppendLine(" public JsonResult EditList" + tableName + "(List<" + tableName + "ViewModel> list_vm)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" list_vm.ForEach(d => d.UpdateDate = DateTime.Now);"); sb_body.AppendLine(" list_vm.ForEach(d => d.UpdateUserID = LoginUserId);"); sb_body.AppendLine(" list_vm.Where(d => d.SysNo == Guid.Empty).ToList().ForEach(d => d.CreateUserID = LoginUserId);"); sb_body.AppendLine(" list_vm.Where(d => d.SysNo == Guid.Empty).ToList().ForEach(d => d.CreateDate = DateTime.Now);"); sb_body.AppendLine(""); sb_body.AppendLine(" Result result = " + tableName + "Service.SaveList" + tableName + "(new Save" + tableName + "CmdDto()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" List" + tableName + " = list_vm.Select(d => d.MapTo<" + tableName + "CmdDto>()).ToList(),"); sb_body.AppendLine(" });"); sb_body.AppendLine(" return Json(result);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 删除" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"user\"></param>"); sb_body.AppendLine(" /// <param name=\"userRoles\"></param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" [HttpPost]"); sb_body.AppendLine(" public JsonResult Delete" + tableName + "(Delete" + tableName + "CmdDto vm)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" vm.UpdateUserID = LoginUserId;"); sb_body.AppendLine(" vm.IsRealDeleted = false;"); sb_body.AppendLine(" var result = " + tableName + "Service.Delete" + tableName + "(vm);"); sb_body.AppendLine(" return Json(result);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion " + tableDesc + "管理"); sb_body.AppendLine(""); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); string file_Model = "C:\\Code\\" + str_nameSpace + ".Web\\Controllers\\" + tablePrefix; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + "Controller.cs", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); bool isPrimeKey = false; string primaryKey = ""; StringBuilder sb = new StringBuilder(); #region Model sb.AppendLine(" #region Model"); //遍历每个字段 foreach (DataRow dr in dt_tables.Rows) { string columnName = dr["columnName"].ToString().Trim(); //字段名 string columnType = dr["columnType"].ToString().Trim(); //字段类型 string columnComment = dr["columnComment"].ToString().Trim(); //字段注释 string nullable = dr["nullable"].ToString().Trim(); //是否可空(Y是不为空,N是为空) string data_default = dr["data_default"].ToString().Trim(); //默認值 string data_maxLength = dr["char_col_decl_length"].ToString().Trim(); //最大長度 string bool_primaryKey = dr["primaryKey"].ToString().Trim(); //主键 值为Y或N if (bool_primaryKey.ToUpper() == "Y") //存在主键 { isPrimeKey = true; primaryKey = columnName.ToUpper(); } if (string.IsNullOrEmpty(columnComment)) { columnComment = columnName; } CommonCode.GetColumnType(ref columnType, ref data_default); nullable = CommonCode.GetNullable(columnType, nullable); sb.AppendLine(""); sb.AppendLine(@" /// <summary>"); sb.AppendLine(@" /// " + columnComment); sb.AppendLine(@" /// </summary>"); sb.AppendLine(" public " + columnType + nullable + " " + columnName + " { get; set; }"); } sb.AppendLine(""); sb.AppendLine(" #endregion Model"); SetData(tableName, sb); #endregion Model StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO.Data.Query;"); sb_body.AppendLine("using " + str_nameSpace + ".DTO.Query;"); sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".DTO." + tablePrefix + ".Query"); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// Dto:"+ tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public class " + tableName + "Dto"); sb_body.AppendLine(" {"); sb_body.AppendLine(""); sb_body.Append(sb.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); string file_Model = "C:\\Code\\" + str_nameSpace + ".DTO\\" + tablePrefix + "\\Query"; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + "Dto" + ".cs", sb_body.ToString()); }
public void Create(string str_nameSpace, List <string> listTableName) { string src = CommonCode.projSrc + "/" + str_nameSpace + ".Enum" + "/OperationTypeEnum.cs"; var str = JsonHelper.GetFile(src); StringBuilder sb = new StringBuilder(); string[] arr = JsonHelper.SplitString(str, "\r\n"); for (int j = 0; j < arr.Length; j++) { var item = arr[j]; for (int i = 0; i < listTableName.Count; i++) { string tableName = listTableName[i]; string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); if (item.Contains("#endregion OperationTypeEnum") && !item.Contains(tableName)) { SaveData(tableName, sb); } } sb.AppendLine(item); } string sss = sb.ToString(); string file_Model = "C:\\Code\\" + str_nameSpace + ".Enum"; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save2(file_Model + "//OperationTypeEnum.cs", sb.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); StringBuilder sb_body = new StringBuilder(); StringBuilder sb_List = new StringBuilder(); StringBuilder sb_AllowLoad = new StringBuilder(); StringBuilder sb_SetData = new StringBuilder(); var listModel = CommonCode.GetTableModel(tableName); if (listModel != null) { foreach (var item in listModel) { SetInstance(tableName, sb_List, sb_AllowLoad, sb_SetData, item); } } sb_body.AppendLine("using Lee.CQuery;"); sb_body.AppendLine("using Lee.CQuery.Paging;"); sb_body.AppendLine("using Lee.Utility;"); sb_body.AppendLine("using Lee.Utility.IoC;"); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using System.Linq;"); sb_body.AppendLine("using System.Text;"); sb_body.AppendLine("using System.Threading.Tasks;"); sb_body.AppendLine("using Lee.Utility.Extension;"); sb_body.AppendLine("using Lee.Utility.ExpressionUtil;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain.Model;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain.Service;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Model;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Repository;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Service;"); sb_body.AppendLine("using " + str_nameSpace + ".Query." + tablePrefix + ";"); if (tablePrefix != "Data") { sb_body.AppendLine("using " + str_nameSpace + ".Domain.Data.Model;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain.Data.Service;"); } sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".Domain." + tablePrefix + ".Service"); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 服务:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public static class " + tableName + "Service"); sb_body.AppendLine(" {"); sb_body.AppendLine(" static I" + tableName + "Repository " + tableName + "Repository = ContainerManager.Container.Resolve<I" + tableName + "Repository>();"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 保存"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 保存" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"" + tableName + "\">信息</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static Result<" + tableName + "> Save" + tableName + "(" + tableName + " " + tableName + ")"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (" + tableName + " == null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Result<" + tableName + ">.ErrorResult(\"信息为空\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(" Result<" + tableName + "> result = null;"); sb_body.AppendLine(" if (" + tableName + ".SysNo == Guid.Empty)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" result = Add" + tableName + "(" + tableName + ");"); sb_body.AppendLine(" }"); sb_body.AppendLine(" else"); sb_body.AppendLine(" {"); sb_body.AppendLine(" result = Update" + tableName + "(" + tableName + ");"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" return result;"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 批量保存" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"" + tableName + "\">信息</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static Result SaveList" + tableName + "(IEnumerable<" + tableName + "> List" + tableName + ")"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (List" + tableName + ".IsNullOrEmpty())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Result.ErrorResult(\"信息为空\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" foreach (var item in List" + tableName + ")"); sb_body.AppendLine(" {"); sb_body.AppendLine(" Save" + tableName + "(item);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" return Result.SuccessResult(\"修改成功\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 添加"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 添加" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"" + tableName + "\">信息</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" static Result<" + tableName + "> Add" + tableName + "(" + tableName + " " + tableName + ")"); sb_body.AppendLine(" {"); sb_body.AppendLine(" " + tableName + ".SetDefaultValue();"); sb_body.AppendLine(" " + tableName + ".Save();"); sb_body.AppendLine(" var result = Result<" + tableName + ">.SuccessResult(\"保存成功\");"); sb_body.AppendLine(" result.Data = " + tableName + ";"); sb_body.AppendLine(" return result;"); sb_body.AppendLine(" }"); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 修改"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 修改" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"" + tableName + "\">信息</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" static Result<" + tableName + "> Update" + tableName + "(" + tableName + " " + tableName + ")"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var this" + tableName + " = Get" + tableName + "(" + tableName + ".SysNo);"); sb_body.AppendLine(" if (this" + tableName + " == null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Result<" + tableName + ">.ErrorResult(\"请指定要编辑的数据\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(" var excludeModifyPropertys = ExpressionHelper.GetExpressionPropertyNames<" + tableName + ">(u => u.CreateDate);"); sb_body.AppendLine(""); sb_body.AppendLine(" this" + tableName + ".ModifyFromOther" + tableName + "(" + tableName + ", excludeModifyPropertys);//更新"); sb_body.AppendLine(" this" + tableName + ".Save();"); sb_body.AppendLine(" var result = Result<" + tableName + ">.SuccessResult(\"更新成功\");"); sb_body.AppendLine(" result.Data = this" + tableName + ";"); sb_body.AppendLine(" return result;"); sb_body.AppendLine(" }"); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"query\">查询条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static " + tableName + " Get" + tableName + "(IQuery query)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var " + tableName + " = " + tableName + "Repository.Get(query);"); sb_body.AppendLine(" return " + tableName + ";"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"SysNo\">编号</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static " + tableName + " Get" + tableName + "(Guid? SysNo)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Get" + tableName + "(SysNo ?? Guid.Empty);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"SysNo\">编号</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static " + tableName + " Get" + tableName + "(Guid SysNo)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (SysNo == Guid.Empty)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return null;"); sb_body.AppendLine(" }"); sb_body.AppendLine(" IQuery query = QueryFactory.Create<" + tableName + "Query>(c => c.SysNo == SysNo);"); sb_body.AppendLine(" return Get" + tableName + "(query);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取列表"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc + "列表"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"query\">查询条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static List<" + tableName + "> Get" + tableName + "List(IQuery query)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var " + tableName + "List = " + tableName + "Repository.GetList(query);"); sb_body.AppendLine(" " + tableName + "List = LoadOtherObjectData(" + tableName + "List, query);"); sb_body.AppendLine(" return " + tableName + "List;"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc + "列表"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"listID\"></param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static List<" + tableName + "> Get" + tableName + "List(IEnumerable<Guid> listID)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (listID.IsNullOrEmpty())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return new List<" + tableName + ">(0);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" IQuery query = QueryFactory.Create<" + tableName + "Query>(c => listID.Contains(c.SysNo));"); sb_body.AppendLine(" return Get" + tableName + "List(query);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取分页"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 获取" + tableDesc + "分页"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"query\">查询条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static IPaging<" + tableName + "> Get" + tableName + "Paging(IQuery query)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" var " + tableName + "Paging = " + tableName + "Repository.GetPaging(query);"); sb_body.AppendLine(" var list = LoadOtherObjectData(" + tableName + "Paging, query);"); sb_body.AppendLine(" return new Paging<" + tableName + ">(" + tableName + "Paging.Page, " + tableName + "Paging.PageSize, " + tableName + "Paging.TotalCount, list);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 删除"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 删除" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"" + tableName + "s\">要删除的信息</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static Result Delete" + tableName + "(IEnumerable<" + tableName + "> " + tableName + "s)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (" + tableName + "s.IsNullOrEmpty())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Result.ErrorResult(\"没有指定任何要删除的数据\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(" " + tableName + "Repository.Remove(" + tableName + "s.ToArray());"); sb_body.AppendLine(" return Result.SuccessResult(\"删除成功\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 删除" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"" + tableName + "Ids\">编号</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static Result Delete" + tableName + "(IEnumerable<Guid> " + tableName + "Ids)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (" + tableName + "Ids.IsNullOrEmpty())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Result.ErrorResult(\"没有指定要删除的数据\");"); sb_body.AppendLine(" }"); sb_body.AppendLine(" IEnumerable<" + tableName + "> " + tableName + "s = " + tableName + "Ids.Select(c => " + tableName + ".Create" + tableName + "(c)).ToList();"); sb_body.AppendLine(" return Delete" + tableName + "(" + tableName + "s);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" "); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(""); sb_body.AppendLine(" #region 加载其它数据"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 加载其它数据"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"" + tableName + "s\">数据</param>"); sb_body.AppendLine(" /// <param name=\"query\">筛选条件</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" private static List<" + tableName + "> LoadOtherObjectData(IEnumerable<" + tableName + "> " + tableName + "s, IQuery query)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (" + tableName + "s.IsNullOrEmpty())"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return new List<" + tableName + ">(0);"); sb_body.AppendLine(" }"); sb_body.AppendLine(" if (query == null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return " + tableName + "s.ToList();"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 获取数据"); sb_body.AppendLine(""); sb_body.AppendLine(sb_List.ToString()); sb_body.AppendLine(sb_AllowLoad.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" foreach (var item in " + tableName + "s)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (item == null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" continue;"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(sb_SetData.ToString()); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" return " + tableName + "s.ToList();"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); sb_body.AppendLine(""); string file_Model = "C:\\Code\\" + str_nameSpace + ".Domain\\" + tablePrefix + "\\Service"; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + "Service.cs", sb_body.ToString()); }
public void Create(string str_nameSpace, DataTable dt_tables, string tableName) { string tablePrefix = CommonCode.GetTablePrefix(tableName); tableName = CommonCode.GetTableName(tableName); string tableDesc = CommonCode.GetTableDesc(tableName); bool isPrimeKey = false; string primaryKey = ""; StringBuilder sb = new StringBuilder(); StringBuilder sb2 = new StringBuilder(); StringBuilder sb3 = new StringBuilder(); #region Model //遍历每个字段 foreach (DataRow dr in dt_tables.Rows) { string columnName = dr["columnName"].ToString().Trim(); //字段名 string columnType = dr["columnType"].ToString().Trim(); //字段类型 string columnComment = dr["columnComment"].ToString().Trim(); //字段注释 string nullable = dr["nullable"].ToString().Trim(); //是否可空(Y是不为空,N是为空) string data_default = dr["data_default"].ToString().Trim(); //默認值 string data_maxLength = dr["char_col_decl_length"].ToString().Trim(); //最大長度 string bool_primaryKey = dr["primaryKey"].ToString().Trim(); //主键 值为Y或N if (bool_primaryKey.ToUpper() == "Y") //存在主键 { isPrimeKey = true; primaryKey = columnName.ToUpper(); } if (string.IsNullOrEmpty(columnComment)) { columnComment = columnName; } CommonCode.GetColumnType(ref columnType, ref data_default); nullable = CommonCode.GetNullable(columnType, nullable); sb.AppendLine(""); sb.AppendLine(@" /// <summary>"); sb.AppendLine(@" /// " + columnComment); sb.AppendLine(@" /// </summary>"); sb.AppendLine(" protected " + columnType + nullable + " _" + columnName + ";"); sb2.AppendLine(" /// <summary>"); sb2.AppendLine(" /// " + columnComment); sb2.AppendLine(" /// </summary>"); sb2.AppendLine(" public " + columnType + nullable + " " + columnName); sb2.AppendLine(" {"); sb2.AppendLine(" get { return _" + columnName + "; }"); sb2.AppendLine(" protected set { _" + columnName + " = value; }"); sb2.AppendLine(" }"); sb2.AppendLine(""); SetExcludePropertys(tableName, sb3, columnName); } StringBuilder sb_instance = new StringBuilder(); StringBuilder sb_instanceMethod = new StringBuilder(); StringBuilder sb_SetLazyMember = new StringBuilder(); StringBuilder sb_attribute = new StringBuilder(); var listModel = CommonCode.GetTableModel(tableName); if (listModel != null) { foreach (var item in listModel) { SetSB(sb, item); SetInstance(tableName, sb_instance, sb_instanceMethod, sb_SetLazyMember, item); SetAttribute(sb_attribute, item); } } #endregion Model StringBuilder sb_body = new StringBuilder(); sb_body.AppendLine("using System;"); sb_body.AppendLine("using System.Collections.Generic;"); sb_body.AppendLine("using System.Linq;"); sb_body.AppendLine("using Lee.CQuery;"); sb_body.AppendLine("using Lee.Domain.Aggregation;"); sb_body.AppendLine("using Lee.Utility;"); sb_body.AppendLine("using Lee.Utility.Extension;"); sb_body.AppendLine("using Lee.Utility.ValueType;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain.Model;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain.Service;"); sb_body.AppendLine("using " + str_nameSpace + ".Query;"); sb_body.AppendLine("using " + str_nameSpace + ".Query." + tablePrefix + ";"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Model;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Repository;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain." + tablePrefix + ".Service;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain.Repository;"); if (tablePrefix != "Data") { sb_body.AppendLine("using " + str_nameSpace + ".Domain.Data.Model;"); sb_body.AppendLine("using " + str_nameSpace + ".Domain.Data.Service;"); } sb_body.AppendLine(""); sb_body.AppendLine("namespace " + str_nameSpace + ".Domain." + tablePrefix + ".Model"); sb_body.AppendLine("{"); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// DomainModel:" + tableDesc); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public class " + tableName + " : AggregationRoot<" + tableName + ">"); sb_body.AppendLine(" {"); sb_body.AppendLine(" I" + tableName + "Repository " + tableName + "Repository = null;"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 字段"); sb_body.AppendLine(""); sb_body.AppendLine(sb.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 构造方法"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 实例化对象"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"SysNo\">编号</param>"); sb_body.AppendLine(" internal " + tableName + "(Guid? SysNo = null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" _SysNo = SysNo ?? Guid.Empty;"); sb_body.AppendLine(" " + tableName + "Repository = this.Instance<I" + tableName + "Repository>();"); sb_body.AppendLine(""); sb_body.AppendLine(sb_instance.ToString()); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(sb_instanceMethod.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 设置LazyMember"); sb_body.AppendLine(""); sb_body.AppendLine(sb_SetLazyMember.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 属性"); sb_body.AppendLine(""); sb_body.AppendLine(sb2.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(sb_attribute.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 方法"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 功能方法"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 保存"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 保存"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public override void Save()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" " + tableName + "Repository.Save(this);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 移除"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 移除"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public override void Remove()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" " + tableName + "Repository.Remove(this);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 初始化标识信息"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 初始化标识信息"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public override void InitPrimaryValue()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" base.InitPrimaryValue();"); sb_body.AppendLine(" _SysNo = Generate" + tableName + "Id();"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 内部方法"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 判断标识对象值是否为空"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 判断标识对象值是否为空"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" protected override bool PrimaryValueIsNone()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return _SysNo == Guid.Empty;"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 静态方法"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 生成一个编号"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 生成一个编号"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static Guid Generate" + tableName + "Id()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return Guid.NewGuid();"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 创建"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 创建一个对象"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"SysNo\">编号</param>"); sb_body.AppendLine(" /// <returns></returns>"); sb_body.AppendLine(" public static " + tableName + " Create" + tableName + "(Guid? SysNo = null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" SysNo = SysNo == Guid.Empty ? Generate" + tableName + "Id() : SysNo;"); sb_body.AppendLine(" return new " + tableName + "(SysNo);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 根据给定的对象更新当前信息"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 根据给定的对象更新当前信息"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <param name=\"" + tableName + "\">信息</param>"); sb_body.AppendLine(" /// <param name=\"excludePropertys\">排除更新的属性</param>"); sb_body.AppendLine(" public virtual void ModifyFromOther" + tableName + "(" + tableName + " " + tableName + ", IEnumerable<string> excludePropertys = null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" if (" + tableName + " == null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return;"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" CopyDataFromSimilarObject(" + tableName + ", excludePropertys);"); sb_body.AppendLine(" }"); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 从指定对象复制值"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 从指定对象复制值"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" /// <typeparam name=\"DT\">数据类型</typeparam>"); sb_body.AppendLine(" /// <param name=\"similarObject\">数据对象</param>"); sb_body.AppendLine(" /// <param name=\"excludePropertys\">排除不复制的属性</param>"); sb_body.AppendLine(" protected override void CopyDataFromSimilarObject<DT>(DT similarObject, IEnumerable<string> excludePropertys = null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" base.CopyDataFromSimilarObject<DT>(similarObject, excludePropertys);"); sb_body.AppendLine(" if (similarObject == null)"); sb_body.AppendLine(" {"); sb_body.AppendLine(" return;"); sb_body.AppendLine(" }"); sb_body.AppendLine(" excludePropertys = excludePropertys ?? new List<string>(0);"); sb_body.AppendLine(""); sb_body.AppendLine(" #region 复制值"); sb_body.AppendLine(""); sb_body.AppendLine(sb3.ToString()); sb_body.AppendLine(""); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(" }"); sb_body.AppendLine(" #endregion"); sb_body.AppendLine(""); sb_body.AppendLine(" /// <summary>"); sb_body.AppendLine(" /// 设置默认值"); sb_body.AppendLine(" /// </summary>"); sb_body.AppendLine(" public void SetDefaultValue()"); sb_body.AppendLine(" {"); sb_body.AppendLine(" CreateDate = DateTime.Now;"); sb_body.AppendLine(" IsDelete = false;"); sb_body.AppendLine(" }"); sb_body.AppendLine(" }"); sb_body.AppendLine("}"); sb_body.AppendLine(""); string file_Model = "C:\\Code\\" + str_nameSpace + ".Domain\\" + tablePrefix + "\\Model"; if (!Directory.Exists(file_Model)) { Directory.CreateDirectory(file_Model); } CommonCode.Save(file_Model + "/" + tableName + "" + ".cs", sb_body.ToString()); }