public static void SaveDBConfig(string str_SetObjectName, string str_SetPrimaryKey)
        {
            string src = CommonCode.projSrc + "/BigDataAnalysis.Config/DbConfig.cs";

            var str = JsonHelper.GetFile(src);

            string[]      arr = JsonHelper.SplitString(str, "\r\n");
            StringBuilder sb  = new StringBuilder();

            foreach (var item in arr)
            {
                if (item.Contains("#endregion 数据库表名配置"))
                {
                    sb.AppendLine(str_SetObjectName);
                }
                else if (item.Contains("#endregion 数据表主键配置"))
                {
                    sb.AppendLine(str_SetPrimaryKey);
                }
                sb.AppendLine(item);
            }

            string file_Model = "C:\\Code\\BigDataAnalysis.Config";

            if (!Directory.Exists(file_Model))
            {
                Directory.CreateDirectory(file_Model);
            }

            CommonCode.Save(file_Model + "/DbConfig.cs", sb.ToString());
        }
Beispiel #2
0
        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());
        }
Beispiel #3
0
        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());
        }
Beispiel #5
0
        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 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());
        }
Beispiel #7
0
        public void Create(string file_Model, string str_nameSpace, DataTable dt_tables, string str_ModelName)
        {
            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;
                }

                #region 数据类型判断

                switch (columnType.ToLower())
                {
                case "bit":
                    columnType = "bool";
                    if (!string.IsNullOrEmpty(data_default))
                    {
                        data_default = " = " + data_default.TrimStart('(').TrimEnd(')');
                    }
                    break;

                case "int":
                case "tinyint":
                case "bigint":
                    columnType = "int";
                    if (!string.IsNullOrEmpty(data_default))
                    {
                        data_default = " = " + data_default.TrimStart('(').TrimEnd(')');
                    }
                    break;

                case "binary":
                case "decimal":
                case "float":
                case "money":
                case "numeric":
                case "smallint":
                case "smallmoney":
                case "varbinary":
                    columnType = "decimal";
                    if (!string.IsNullOrEmpty(data_default))
                    {
                        data_default = " = " + data_default.TrimStart('(').TrimEnd(')');
                    }
                    break;

                case "date":
                case "datetime":
                case "datetime2":
                case "smalldatetime":
                case "time":
                    columnType = "DateTime";
                    if (!string.IsNullOrEmpty(data_default))
                    {
                        if (data_default.ToLower() == "(getdate())")
                        {
                            data_default = " = DateTime.Now";
                        }
                    }
                    break;

                default:
                    columnType = "string";
                    if (!string.IsNullOrEmpty(data_default))
                    {
                        data_default = " = \"" + data_default.Trim('(', ')').Trim('\'') + "\"";
                    }
                    break;
                }

                #endregion 数据类型判断


                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 + " { get; set; }");
            }
            sb.AppendLine("        #endregion Model");

            #endregion Model

            string st_prime_tip = "";
            if (!isPrimeKey)
            {
                st_prime_tip = "没有主键,默认主键为:" + primaryKey;
            }
            else
            {
                st_prime_tip = "有主键,主键为:" + primaryKey;
            }
            StringBuilder sb_body = new StringBuilder();

            sb_body.AppendLine("using System;");
            sb_body.AppendLine("");
            sb_body.AppendLine("namespace " + str_nameSpace + ".Model");
            sb_body.AppendLine("{");
            sb_body.AppendLine("        /// <summary>");
            sb_body.AppendLine("        /// Model实体类:" + str_ModelName);
            sb_body.AppendLine("        /// 创建时间:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            sb_body.AppendLine("        /// </summary>");
            sb_body.AppendLine("    public partial class " + str_ModelName);
            sb_body.AppendLine("    {");
            sb_body.AppendLine("        /// <summary>");
            sb_body.AppendLine("        /// " + st_prime_tip);
            sb_body.AppendLine("        /// </summary>");
            sb_body.AppendLine("        public " + str_ModelName + "() { }");
            sb_body.AppendLine("");

            sb_body.Append(sb.ToString());

            sb_body.AppendLine("");
            sb_body.AppendLine("");
            sb_body.AppendLine("    }");
            sb_body.AppendLine("}");

            CommonCode.Save(file_Model + "/" + str_ModelName + ".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());
        }
Beispiel #9
0
        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());
        }
Beispiel #10
0
        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());
        }
Beispiel #11
0
        public void Create(string file_DAL, string str_table, string str_DALName, string str_IDALName, string str_ModelName, StringBuilder sb_column1, StringBuilder sb_column2, StringBuilder sb_column3, StringBuilder sb_column4, StringBuilder sb_column5, ConfigModel configModel)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("using System;");
            sb.AppendLine("using System.Data;");
            sb.AppendLine("using System.Text;");
            sb.AppendLine("using System.Data.SqlClient;");
            sb.AppendLine("using " + configModel.str_nameSpace + ".IDAL;");
            sb.AppendLine("using " + configModel.str_nameSpace + ".DBUtility;");
            sb.AppendLine("using " + configModel.str_nameSpace + ".Common;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using " + configModel.str_nameSpace + ".Model;");
            sb.AppendLine("");
            sb.AppendLine("namespace " + configModel.str_nameSpace + ".SqlDAL");
            sb.AppendLine("{");
            sb.AppendLine("    /// <summary>");
            sb.AppendLine("    /// 数据访问类:" + str_DALName);
            sb.AppendLine("    /// </summary>");
            sb.AppendLine("    public partial class " + str_DALName + " : " + str_IDALName);
            sb.AppendLine("    {");
            sb.AppendLine("        public " + str_DALName + "() { }");
            sb.AppendLine("");

            #region BasicMethod

            sb.AppendLine("        #region  BasicMethod");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 是否存在该记录");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public bool Exists(string ST_CODE)");
            sb.AppendLine("        {");
            sb.AppendLine("            StringBuilder sb = new StringBuilder();");
            sb.AppendLine("            sb.Append(\"select count(1) from " + str_table.ToUpper() + "\");");
            sb.AppendLine("            sb.Append(\" where ST_CODE=" + configModel.MARK + "ST_CODE \");");
            sb.AppendLine("            SqlParameter[] parameters ={");
            sb.AppendLine("                new SqlParameter(\"" + configModel.MARK + "ST_CODE\",ST_CODE)");
            sb.AppendLine("            };");
            sb.AppendLine("            return " + configModel.str_SqlHelper + "." + configModel.str_ExecuteScalar + "(sb.ToString(), parameters);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 增加一条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public bool Add(" + str_ModelName + " model)");
            sb.AppendLine("        {");
            sb.AppendLine("            StringBuilder strSql;");
            sb.AppendLine("            SqlParameter[] parameters;");
            sb.AppendLine("            AddModel(model, out strSql, out parameters);");
            sb.AppendLine("");
            sb.AppendLine("            return new SqlCode().ReturnBool(strSql.ToString(), parameters);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 增加多条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public int AddList(List<" + str_ModelName + "> list_model)");
            sb.AppendLine("        {");
            sb.AppendLine("            StringBuilder strSql;");
            sb.AppendLine("            SqlParameter[] parameters;");
            sb.AppendLine("            List<" + configModel.str_nameSpace + ".DBUtility.CommandInfo> ci = new List<CommandInfo>();");
            sb.AppendLine("");
            sb.AppendLine("            foreach (" + str_ModelName + " item in list_model)");
            sb.AppendLine("            {");
            sb.AppendLine("                strSql = new StringBuilder();");
            sb.AppendLine("                parameters = null;");
            sb.AppendLine("                AddModel(item, out strSql, out parameters);");
            sb.AppendLine("");
            sb.AppendLine("                " + configModel.str_nameSpace + ".DBUtility.CommandInfo subci = new CommandInfo();");
            sb.AppendLine("                subci.CommandText = strSql.ToString();");
            sb.AppendLine("                subci.Parameters = parameters;");
            sb.AppendLine("                subci.Type = CommandType.Text;");
            sb.AppendLine("                ci.Add(subci);");
            sb.AppendLine("            }");
            sb.AppendLine("            return " + configModel.str_SqlHelper + "." + configModel.str_UpdateDatabase + "(ci);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 更新一条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public bool Update(" + str_ModelName + " model)");
            sb.AppendLine("        {");
            sb.AppendLine("            StringBuilder strSql;");
            sb.AppendLine("            SqlParameter[] parameters;");
            sb.AppendLine("            UpdateModel(model, out strSql, out parameters);");
            sb.AppendLine("");
            sb.AppendLine("            return new SqlCode().ReturnBool(strSql.ToString(), parameters);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 更新多条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public int UpdateList(List<" + str_ModelName + "> list_model)");
            sb.AppendLine("        {");
            sb.AppendLine("            StringBuilder strSql;");
            sb.AppendLine("            SqlParameter[] parameters;");
            sb.AppendLine("            List<" + configModel.str_nameSpace + ".DBUtility.CommandInfo> ci = new List<CommandInfo>();");
            sb.AppendLine("");
            sb.AppendLine("            foreach (" + str_ModelName + " item in list_model)");
            sb.AppendLine("            {");
            sb.AppendLine("                strSql = new StringBuilder();");
            sb.AppendLine("                parameters = null;");
            sb.AppendLine("                UpdateModel(item, out strSql, out parameters);");
            sb.AppendLine("");
            sb.AppendLine("                " + configModel.str_nameSpace + ".DBUtility.CommandInfo subci = new CommandInfo();");
            sb.AppendLine("                subci.CommandText = strSql.ToString();");
            sb.AppendLine("                subci.Parameters = parameters;");
            sb.AppendLine("                subci.Type = CommandType.Text;");
            sb.AppendLine("                ci.Add(subci);");
            sb.AppendLine("");
            sb.AppendLine("            }");
            sb.AppendLine("            return " + configModel.str_SqlHelper + "." + configModel.str_UpdateDatabase + "(ci);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 删除一条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public bool Delete(string ST_CODE)");
            sb.AppendLine("        {");
            sb.AppendLine("            //该表无主键信息,请自定义主键/条件字段");
            sb.AppendLine("            StringBuilder strSql = new StringBuilder();");
            sb.AppendLine("            strSql.Append(\"delete from " + str_table.ToUpper() + " \");");
            sb.AppendLine("            strSql.Append(\" where \");");
            sb.AppendLine("            SqlParameter[] parameters = {");
            sb.AppendLine("			};");
            sb.AppendLine("");
            sb.AppendLine("            return new SqlCode().ReturnBool(strSql.ToString(), parameters);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 删除多条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        /// <param name=\"ST_CODElist\"></param>");
            sb.AppendLine("        /// <returns></returns>");
            sb.AppendLine("        public bool DeleteList(List<string> ST_CODElist)");
            sb.AppendLine("        {");
            sb.AppendLine("            List<string> list_sql = new List<string>();");
            sb.AppendLine("            foreach (string item in ST_CODElist)");
            sb.AppendLine("            {");
            sb.AppendLine("                list_sql.Add(\"delete from " + str_table.ToUpper() + " where ST_CODE ='\" + item + \"'\");");
            sb.AppendLine("            }");
            sb.AppendLine("            int rows = " + configModel.str_SqlHelper + "." + configModel.str_UpdateDatabase + "(list_sql);");
            sb.AppendLine("            if (rows > 0)");
            sb.AppendLine("            {");
            sb.AppendLine("                return true;");
            sb.AppendLine("            }");
            sb.AppendLine("            else");
            sb.AppendLine("            {");
            sb.AppendLine("                return false;");
            sb.AppendLine("            }");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 获得实体对象");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public " + str_ModelName + " GetModel(string ST_CODE)");
            sb.AppendLine("        {");
            sb.AppendLine("            //该表无主键信息,请自定义主键/条件字段");
            sb.AppendLine("            StringBuilder strSql = new StringBuilder();");
            sb.AppendLine("            strSql.Append(\"select " + sb_column1 + " from " + str_table.ToUpper() + " \");");
            sb.AppendLine("            strSql.Append(\" where \");");
            sb.AppendLine("            SqlParameter[] parameters = {");
            sb.AppendLine("			};");
            sb.AppendLine("            return " + configModel.str_SqlHelper + "." + configModel.str_GetModel + "<" + str_ModelName + ">(strSql.ToString(), parameters);");
            sb.AppendLine("");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 获得实体列表");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public List<" + str_ModelName + "> GetModelList(string strWhere)");
            sb.AppendLine("        {");
            sb.AppendLine("            StringBuilder strSql = new StringBuilder();");
            sb.AppendLine("            strSql.Append(\"select " + sb_column1 + " \");");
            sb.AppendLine("            strSql.Append(\" FROM " + str_table.ToUpper() + " \");");
            sb.AppendLine("            if (!string.IsNullOrEmpty(strWhere.Trim()))");
            sb.AppendLine("            {");
            sb.AppendLine("                strSql.Append(\" where \" + strWhere);");
            sb.AppendLine("            }");
            sb.AppendLine("            return " + configModel.str_SqlHelper + "." + configModel.str_GetModelList + "<" + str_ModelName + ">(strSql.ToString());");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 获得数据列表");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public DataTable GetList(string strWhere)");
            sb.AppendLine("        {");
            sb.AppendLine("            StringBuilder strSql = new StringBuilder();");
            sb.AppendLine("            strSql.Append(\"select " + sb_column1 + " \");");
            sb.AppendLine("            strSql.Append(\" FROM " + str_table.ToUpper() + " \");");
            sb.AppendLine("            if (!string.IsNullOrEmpty(strWhere.Trim()))");
            sb.AppendLine("            {");
            sb.AppendLine("                strSql.Append(\" where \" + strWhere);");
            sb.AppendLine("            }");
            sb.AppendLine("            return " + configModel.str_SqlHelper + "." + configModel.str_ExecuteNonQuery + "(strSql.ToString());");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 获取记录总数");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public int GetRecordCount(string strWhere)");
            sb.AppendLine("        {");
            sb.AppendLine("            StringBuilder strSql = new StringBuilder();");
            sb.AppendLine("            strSql.Append(\"select count(1) FROM " + str_table.ToUpper() + " \");");
            sb.AppendLine("            if (!string.IsNullOrEmpty(strWhere.Trim()))");
            sb.AppendLine("            {");
            sb.AppendLine("                strSql.Append(\" where \" + strWhere);");
            sb.AppendLine("            }");
            sb.AppendLine("            object obj = " + configModel.str_SqlHelper + "." + configModel.str_ExecuteScalar + "(strSql.ToString());");
            sb.AppendLine("            if (obj == null)");
            sb.AppendLine("            {");
            sb.AppendLine("                return 0;");
            sb.AppendLine("            }");
            sb.AppendLine("            else");
            sb.AppendLine("            {");
            sb.AppendLine("                return Convert.ToInt32(obj);");
            sb.AppendLine("            }");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 分页获取数据列表");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public DataTable GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)");
            sb.AppendLine("        {");
            sb.AppendLine("            StringBuilder strSql = new StringBuilder();");
            sb.AppendLine("            strSql.Append(\"SELECT * FROM ( \");");
            sb.AppendLine("            strSql.Append(\" SELECT ROW_NUMBER() OVER (\");");
            sb.AppendLine("            if (!string.IsNullOrEmpty(orderby.Trim()))");
            sb.AppendLine("            {");
            sb.AppendLine("                strSql.Append(\"order by T.\" + orderby);");
            sb.AppendLine("            }");
            sb.AppendLine("            else");
            sb.AppendLine("            {");
            sb.AppendLine("                strSql.Append(\"order by T.ST_CODE desc\");");
            sb.AppendLine("            }");
            sb.AppendLine("            strSql.Append(\")AS Row, T.*  from " + str_table.ToUpper() + " T \");");
            sb.AppendLine("            if (!string.IsNullOrEmpty(strWhere.Trim()))");
            sb.AppendLine("            {");
            sb.AppendLine("                strSql.Append(\" WHERE \" + strWhere);");
            sb.AppendLine("            }");
            sb.AppendLine("            strSql.Append(\" ) TT\");");
            sb.AppendLine("            strSql.AppendFormat(\" WHERE TT.Row between {0} and {1}\", startIndex, endIndex);");
            sb.AppendLine("            return " + configModel.str_SqlHelper + "." + configModel.str_ExecuteNonQuery + "(strSql.ToString());");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /*");
            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 分页获取数据列表");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public DataTable GetList(int PageSize,int PageIndex,string strWhere)");
            sb.AppendLine("        {");
            sb.AppendLine("            SqlParameter[] parameters = {");
            sb.AppendLine("                    new SqlParameter(\"" + configModel.MARK + "tblName\", SqlType.VarChar, 255),");
            sb.AppendLine("                    new SqlParameter(\"" + configModel.MARK + "fldName\", SqlType.VarChar, 255),");
            sb.AppendLine("                    new SqlParameter(\"" + configModel.MARK + "PageSize\", SqlType.Number),");
            sb.AppendLine("                    new SqlParameter(\"" + configModel.MARK + "PageIndex\", SqlType.Number),");
            sb.AppendLine("                    new SqlParameter(\"" + configModel.MARK + "IsReCount\", SqlType.Clob),");
            sb.AppendLine("                    new SqlParameter(\"" + configModel.MARK + "OrderType\", SqlType.Clob),");
            sb.AppendLine("                    new SqlParameter(\"" + configModel.MARK + "strWhere\", SqlType.VarChar,1000),");
            sb.AppendLine("                    };");
            sb.AppendLine("            parameters[0].Value = \"" + str_table.ToUpper() + "\";");
            sb.AppendLine("            parameters[1].Value = \"ST_CODE\";");
            sb.AppendLine("            parameters[2].Value = PageSize;");
            sb.AppendLine("            parameters[3].Value = PageIndex;");
            sb.AppendLine("            parameters[4].Value = 0;");
            sb.AppendLine("            parameters[5].Value = 0;");
            sb.AppendLine("            parameters[6].Value = strWhere;	");
            sb.AppendLine("            return " + configModel.str_SqlHelper + ".RunProcedure(\"UP_GetRecordByPage\",parameters,\"ds\");");
            sb.AppendLine("        }*/");
            sb.AppendLine("");

            sb.AppendLine("        #endregion  BasicMethod");
            sb.AppendLine("");

            #endregion BasicMethod

            #region HelperMethod

            sb.AppendLine("        #region HelperMethod");
            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 添加一个Model");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        /// <param name=\"model\">Model类型</param>");
            sb.AppendLine("        /// <param name=\"strSql\">给sql语句赋值</param>");
            sb.AppendLine("        /// <param name=\"parameters\">给参数赋值</param>");
            sb.AppendLine("        private static void AddModel(" + str_ModelName + " model, out StringBuilder strSql, out SqlParameter[] parameters)");
            sb.AppendLine("        {");
            sb.AppendLine("            strSql = new StringBuilder();");
            sb.AppendLine("            strSql.Append(\"insert into " + str_table.ToUpper() + "(\");");
            sb.AppendLine("            strSql.Append(\"" + sb_column1 + ")\");");
            sb.AppendLine("            strSql.Append(\" values (\");");
            sb.AppendLine("            strSql.Append(\"" + sb_column2 + "\");");
            sb.AppendLine("            strSql.Append(\")\");");
            sb.AppendLine("            parameters = SetParameters(model);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 修改一个Model");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        /// <param name=\"model\">Model类型</param>");
            sb.AppendLine("        /// <param name=\"strSql\">给sql语句赋值</param>");
            sb.AppendLine("        /// <param name=\"parameters\">给参数赋值</param>");
            sb.AppendLine("        private static void UpdateModel(" + str_ModelName + " model, out StringBuilder strSql, out SqlParameter[] parameters)");
            sb.AppendLine("        {");
            sb.AppendLine("            strSql = new StringBuilder();");
            sb.AppendLine("            strSql.Append(\"update " + str_table.ToUpper() + " set \");");
            sb.AppendLine(sb_column5.ToString());
            sb.AppendLine("            strSql.Append(\" where \");");
            sb.AppendLine("            strSql.Append(\"NO_ID=" + configModel.MARK + "NO_ID\");");
            sb.AppendLine("            parameters = SetParameters(model);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 给参数列表赋值");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        /// <param name=\"model\">Model类型</param>");
            sb.AppendLine("        /// <returns>SqlParameter[]</returns>");
            sb.AppendLine("        private static SqlParameter[] SetParameters(" + str_ModelName + " model)");
            sb.AppendLine("        {");
            sb.AppendLine("            SqlParameter[] parameters;");
            sb.AppendLine("            parameters = new SqlParameter[]{");
            sb.AppendLine(sb_column3.ToString());
            sb.AppendLine("");
            sb.AppendLine(sb_column4.ToString());
            sb.AppendLine("            return parameters;");
            sb.AppendLine("        }");
            sb.AppendLine("        #endregion HelperMethod");

            #endregion HelperMethod

            sb.AppendLine("");
            sb.AppendLine("    }");
            sb.AppendLine("}");
            CommonCode.Save(file_DAL + "/" + str_DALName + ".cs", sb.ToString());
        }
Beispiel #12
0
        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 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());
        }
Beispiel #14
0
        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 = "";

            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());
        }
Beispiel #16
0
        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());
        }
Beispiel #17
0
        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());
        }
Beispiel #18
0
        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());
        }
Beispiel #19
0
        //生成
        private void btn_save_Click(object sender, EventArgs e)
        {
            ConfigModel configModel = new ConfigModel();

            configModel.MARK          = "@";                  //SQL的连接类型
            configModel.str_nameSpace = textBox1.Text.Trim(); //命名空间
            configModel.str_SqlHelper = textBox2.Text.Trim(); //数据访问类名

            configModel.str_ExecuteNonQuery = textBox5.Text.Trim();
            configModel.str_UpdateDatabase  = textBox6.Text.Trim();
            configModel.str_ExecuteScalar   = textBox4.Text.Trim();
            configModel.str_GetDataTable    = textBox7.Text.Trim();
            configModel.str_Exists          = textBox10.Text.Trim();
            configModel.str_GetModel        = textBox8.Text.Trim();
            configModel.str_GetModelList    = textBox9.Text.Trim();

            #region 生成文件夹

            //string file_BLL = textBox3.Text.Trim();
            //string file_DAL = textBox11.Text.Trim();
            //string file_IDAL = textBox12.Text.Trim();
            //string file_Model = textBox13.Text.Trim();

            //if (!Directory.Exists(file_Model))
            //{
            //    Directory.CreateDirectory(file_Model);
            //}
            //if (!Directory.Exists(file_IDAL))
            //{
            //    Directory.CreateDirectory(file_IDAL);
            //}
            //if (!Directory.Exists(file_BLL))
            //{
            //    Directory.CreateDirectory(file_BLL);
            //}
            //if (!Directory.Exists(file_DAL))
            //{
            //    Directory.CreateDirectory(file_DAL);
            //}

            //if (comboBox1.SelectedIndex == 1)
            //{
            //    string path = textBox3.Text.Trim();
            //    if (!string.IsNullOrEmpty(path))
            //    {
            //        if (path.Contains("\\BLL"))
            //        {
            //            path = path.Replace("\\BLL", "");

            //            string BaseBLLSrc = Directory.GetCurrentDirectory() + "/BaseBll.cs";
            //            string BaseDALSrc = Directory.GetCurrentDirectory() + "/BaseDAL.cs";
            //            string BaseIDALSrc = Directory.GetCurrentDirectory() + "/BaseIDAL.cs";

            //            File.Copy(BaseBLLSrc, path + "\\BaseBll.cs");
            //            File.Copy(BaseDALSrc, path + "\\BaseDAL.cs");
            //            File.Copy(BaseIDALSrc, path + "\\BaseIDAL.cs");
            //        }
            //    }
            //}

            #endregion 生成文件夹

            string str_CreateMap     = "";
            string str_SetObjectName = "";
            string str_SetPrimaryKey = "";
            string str_AddColumn     = "";

            List <string> listTableName = new List <string>();

            //遍历每个表
            for (int i = 0; i < listBox2.Items.Count; i++)
            {
                string str_table = listBox2.Items[i].ToString();//表名

                //string str_BLLName = str_table + textBox17.Text.Trim();
                //string str_DALName = str_table + textBox16.Text.Trim();
                //string str_IDALName = str_table + textBox15.Text.Trim();
                //string str_ModelName = str_table + textBox14.Text.Trim();

                string sql = @"
SELECT
    表名       = case when a.colorder=1 then d.name else '' end,
    表说明     = case when a.colorder=1 then isnull(f.value,'') else '' end,
    字段序号   = a.colorder,
    columnName     = a.name,
    标识       = case when COLUMNPROPERTY( a.id,a.name,'IsIdentity')=1 then 'Y'else 'N' end,
    primaryKey       = case when exists(SELECT 1 FROM sysobjects where xtype='PK' and parent_obj=a.id and name in (
                     SELECT name FROM sysindexes WHERE indid in(
                        SELECT indid FROM sysindexkeys WHERE id = a.id AND colid=a.colid))) then 'Y' else 'N' end,
    columnType       = b.name,
    占用字节数 = a.length,
    char_col_decl_length       = COLUMNPROPERTY(a.id,a.name,'PRECISION'),
    小数位数   = isnull(COLUMNPROPERTY(a.id,a.name,'Scale'),0),
    nullable     = case when a.isnullable=1 then 'N'else 'Y' end,
    data_default     = isnull(e.text,''),
    columnComment   = isnull(g.[value],'')
FROM  syscolumns a
left join systypes b on a.xusertype=b.xusertype
inner join sysobjects d on     a.id=d.id  and d.xtype='U' and  d.name<>'dtproperties'
left join syscomments e on     a.cdefault=e.id
left join sys.extended_properties g on     a.id=g.major_id and a.colid=g.minor_id
left join    sys. extended_properties f on     d.id=f.major_id and f.major_id=0
where     d.name=" + configModel.MARK + "a order by     a.id,a.colorder";

                SqlParameter[] sps       = { new SqlParameter(configModel.MARK + "a", str_table) };
                DataTable      dt_tables = SqlHelper.GetDataTable(sql, sps);

                if (dt_tables == null)
                {
                    return;
                }
                if (dt_tables.Rows.Count > 0)
                {
                    listTableName.Add(str_table);
                    #region 生成内容

                    StringBuilder sb_column1 = new StringBuilder(); //格式如 NO_ID,ST_NAME,ST_VALUES,NO_ORDER,ST_OTHER,ST_VALUES_ENG
                    StringBuilder sb_column2 = new StringBuilder(); //格式如 @NO_ID,@ST_NAME,@ST_VALUES,@NO_ORDER,@ST_OTHER,@ST_VALUES_ENG
                    StringBuilder sb_column3 = new StringBuilder(); //格式如 new SqlParameter("@NO_ID", SqlType.Number,4),
                    StringBuilder sb_column4 = new StringBuilder(); //格式如 parameters[0].Value = model.NO_ID;
                    StringBuilder sb_column5 = new StringBuilder(); //格式如 strSql.Append("ST_NAME=@ST_NAME,");
                    for (int j = 0; j < dt_tables.Rows.Count; j++)
                    {
                        string colName = dt_tables.Rows[j]["columnName"].ToString().Trim();                 //字段名
                        string colType = CommonCode.GetColType(dt_tables.Rows[j]["columnType"].ToString()); //字段类型
                        if (j == dt_tables.Rows.Count - 1)
                        {
                            sb_column1.Append(colName);
                            sb_column2.Append(configModel.MARK + colName);
                            sb_column3.AppendLine("					new SqlParameter(\""+ configModel.MARK + colName + "\", model." + colName + ")};");
                            //sb_column4.AppendLine("            parameters[" + j + "].Value = model." + colName + ";");
                            sb_column4.AppendLine("item." + colName + "=model." + colName + ";");
                            sb_column5.AppendLine("            strSql.Append(\"" + colName + "=" + configModel.MARK + colName + "\");");
                        }
                        else
                        {
                            sb_column1.Append(colName + ",");
                            sb_column2.Append(configModel.MARK + colName + ",");
                            sb_column3.AppendLine("					new SqlParameter(\""+ configModel.MARK + colName + "\", model." + colName + "),");
                            //sb_column4.AppendLine("            parameters[" + j + "].Value = model." + colName + ";");
                            sb_column4.AppendLine("item." + colName + "=model." + colName + ";");
                            sb_column5.AppendLine("            strSql.Append(\"" + colName + "=" + configModel.MARK + colName + ",\");");
                        }
                    }

                    #endregion 生成内容

                    ////生成model
                    //new CreateModel().Create(file_Model, configModel.str_nameSpace, dt_tables, str_ModelName);

                    ////生成IDAL
                    //new CreateIDAL().Create(file_IDAL, configModel.str_nameSpace, str_IDALName, str_ModelName);

                    ////生成BLL
                    //new CreateBLL().Create(file_BLL, configModel.str_nameSpace, str_table, str_BLLName, str_IDALName, str_ModelName);

                    ////生成DAL
                    //new CreateDAL().Create(file_DAL, str_table, str_DALName, str_IDALName, str_ModelName, sb_column1, sb_column2, sb_column3, sb_column4, sb_column5, configModel);


                    //new Create_DeleteCmdDto().Create(configModel.str_nameSpace, dt_tables, str_table);
                    //new Create_SaveCmdDto().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_CmdDto().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_Dto().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_FilterDto().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_Query().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_ViewModel().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_FilterViewModel().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_Entity().Create(configModel.str_nameSpace, dt_tables, str_table);

                    new Create_Repository().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_IRepository().Create(configModel.str_nameSpace, dt_tables, str_table);

                    new Create_DomainService().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_Business().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_IDataAccess().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_DataAccess().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_IService().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_Service().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_IBusiness().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_DomainModel().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_Web_Page().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_Web_Controller().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_Sql().Create(configModel.str_nameSpace, dt_tables, str_table);
                    new Create_Json().Create(configModel.str_nameSpace, dt_tables, str_table);

                    if (checkBox1.Checked)
                    {
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "Business");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "BusinessInterface");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "DataAccess");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "DataAccessInterface");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "Domain");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "Dto");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "Entity");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "Query");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "Repository");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "Service");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "ServiceInterface");
                        new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "ViewModel");
                        //new Create_csproj().Create(configModel.str_nameSpace, dt_tables, str_table, "Web");
                    }

                    str_CreateMap += new Create_Config().GetStr_CreateMap(configModel.str_nameSpace, dt_tables, str_table);

                    str_SetObjectName += new Create_Config().GetStr_SetObjectName(configModel.str_nameSpace, dt_tables, str_table);

                    str_SetPrimaryKey += new Create_Config().GetStr_SetPrimaryKey(configModel.str_nameSpace, dt_tables, str_table);

                    str_AddColumn += new Create_Sql().GetSql_AddColumn(str_table, "IsDelete", "bit not null default(0)", "是否删除");
                }
                label4.Text = "提示信息:" + (i + 1) + "个文件,全部生成成功!" + DateTime.Now;
            }


            string filePath = "C:\\Code\\Config";
            if (!Directory.Exists(filePath))
            {
                Directory.CreateDirectory(filePath);
            }


            CommonCode.Save(filePath + "/AutoMapMapper CreateMap.txt", str_CreateMap);
            CommonCode.Save(filePath + "/DbConfig SetObjectName.txt", str_SetObjectName);
            CommonCode.Save(filePath + "/DbConfig SetPrimaryKey.txt", str_SetPrimaryKey);
            CommonCode.Save(filePath + "/AddColumn.txt", str_AddColumn);

            if (checkBox3.Checked)
            {
                Create_Config.SaveAutoMapMapper(str_CreateMap);
                Create_Config.SaveDBConfig(str_SetObjectName, str_SetPrimaryKey);
            }

            if (checkBox2.Checked)
            {
                new Create_Enum().Create(configModel.str_nameSpace, listTableName);
            }

            if (textBox3.Text != "")
            {
                var arr = textBox3.Text.Split(',');
                if (arr[0] != "ControllerCode")
                {
                    StringBuilder sb_body = new StringBuilder();
                    Create_Sql.SetData2(arr[0], arr[1], arr[2], sb_body);

                    filePath = "C:\\Code\\Sql";
                    if (!Directory.Exists(filePath))
                    {
                        Directory.CreateDirectory(filePath);
                    }
                    CommonCode.Save(filePath + "/生成的.txt", sb_body.ToString());
                    CommonCode.Save(filePath + "/生成的_Delete.txt", Create_Sql.GetSql_Delete(arr[2]));
                }
            }
            //OpenFolder();
        }
Beispiel #20
0
        public void Create(string file_IDAL, string str_nameSpace, string str_IDALName, string str_ModelName)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("using System;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using System.Data;");
            sb.AppendLine("using " + str_nameSpace + ".Model;");
            sb.AppendLine("");
            sb.AppendLine("namespace " + str_nameSpace + ".IDAL");
            sb.AppendLine("{");
            sb.AppendLine("    public interface " + str_IDALName);
            sb.AppendLine("    {");

            #region BasicMethod
            sb.AppendLine("        #region BasicMethod");
            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// 是否存在该记录");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		bool Exists(string ST_CODE);");
            sb.AppendLine("");

            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// 增加一条数据");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		bool Add("+ str_ModelName + " model);");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 增加多条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        int AddList(List<" + str_ModelName + "> list_model);");
            sb.AppendLine("");

            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// 更新一条数据");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		bool Update("+ str_ModelName + " model);");
            sb.AppendLine("");

            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// 更新多条数据");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		int UpdateList(List<"+ str_ModelName + "> list_model);");
            sb.AppendLine("");

            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// 删除一条数据");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		bool Delete(string ST_CODE);");
            sb.AppendLine("");

            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// 删除多条数据");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		bool DeleteList(List<string> ST_CODElist);");
            sb.AppendLine("");

            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// 得到实体对象");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		"+ str_ModelName + " GetModel(string ST_CODE);");
            sb.AppendLine("");

            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// 得到实体列表");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("        List<" + str_ModelName + "> GetModelList(string strWhere);");
            sb.AppendLine("");

            sb.AppendLine("		/// <summary>");
            sb.AppendLine("		/// 获得数据列表");
            sb.AppendLine("		/// </summary>");
            sb.AppendLine("		DataTable GetList(string strWhere);");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 获取记录总数");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        int GetRecordCount(string strWhere);");
            sb.AppendLine("");

            sb.AppendLine("		///// <summary>");
            sb.AppendLine("		///// 分页获取数据列表");
            sb.AppendLine("		///// </summary>");
            sb.AppendLine("		//public int GetRecordCount(string strWhere);");
            sb.AppendLine("");

            sb.AppendLine("		///// <summary>");
            sb.AppendLine("		///// 根据分页获得数据列表");
            sb.AppendLine("		///// </summary>");
            sb.AppendLine("		//DataTable GetList(int PageSize,int PageIndex,string strWhere);");
            sb.AppendLine("		#endregion  BasicMethod");
            #endregion

            sb.AppendLine("");
            sb.AppendLine("");
            sb.AppendLine("    }");
            sb.AppendLine("}");

            CommonCode.Save(file_IDAL + "/" + str_IDALName + ".cs", sb.ToString());
        }
Beispiel #21
0
        public void Create(string file_BLL, string str_nameSpace, string str_table, string str_BLLName, string str_IDALName, string str_ModelName)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine("using System;");
            sb.AppendLine("using System.Data;");
            sb.AppendLine("using System.Collections.Generic;");
            sb.AppendLine("using " + str_nameSpace + ".Model;");
            sb.AppendLine("using " + str_nameSpace + ".IDAL;");
            sb.AppendLine("using " + str_nameSpace + ".DALFactory;");
            sb.AppendLine("");
            sb.AppendLine("namespace " + str_nameSpace + ".BLL");
            sb.AppendLine("{");
            sb.AppendLine("    /// <summary>");
            sb.AppendLine("    /// " + str_BLLName);
            sb.AppendLine("    /// </summary>");
            sb.AppendLine("    public partial class " + str_BLLName);
            sb.AppendLine("    {");
            sb.AppendLine("        private readonly " + str_IDALName + " dal = DataAccess.Create" + str_table.ToUpper() + "();");
            sb.AppendLine("        public " + str_BLLName + "() { }");
            sb.AppendLine("");

            #region BasicMethod
            sb.AppendLine("        #region  BasicMethod");
            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 是否存在该记录");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public bool Exists(string ST_CODE)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.Exists(ST_CODE);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 增加一条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public bool Add(" + str_ModelName + " model)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.Add(model);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 增加多条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public int AddList(List<" + str_ModelName + "> list_model)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.AddList(list_model);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 更新一条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public bool Update(" + str_ModelName + " model)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.Update(model);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 更新多条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public int UpdateList(List<" + str_ModelName + "> list_model)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.UpdateList(list_model);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 删除一条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public bool Delete(string ST_CODE)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.Delete(ST_CODE);");
            sb.AppendLine("        }");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 删除多条数据");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public bool DeleteList(List<string> ST_CODElist)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.DeleteList(ST_CODElist);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 得到实体对象");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public " + str_ModelName + " GetModel(string ST_CODE)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.GetModel(ST_CODE);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 获得实体列表");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public List<" + str_ModelName + "> GetModelList(string strWhere)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.GetModelList(strWhere);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 获得数据列表");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public DataTable GetList(string strWhere)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.GetList(strWhere);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 获得数据列表");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public DataTable GetAllList()");
            sb.AppendLine("        {");
            sb.AppendLine("            return GetList(\"\");");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        /// <summary>");
            sb.AppendLine("        /// 获取记录总数");
            sb.AppendLine("        /// </summary>");
            sb.AppendLine("        public int GetRecordCount(string strWhere)");
            sb.AppendLine("        {");
            sb.AppendLine("            return dal.GetRecordCount(strWhere);");
            sb.AppendLine("        }");
            sb.AppendLine("");

            sb.AppendLine("        ///// <summary>");
            sb.AppendLine("        ///// 分页获取数据列表");
            sb.AppendLine("        ///// </summary>");
            sb.AppendLine("        //public int GetRecordCount(string strWhere)");
            sb.AppendLine("        //{");
            sb.AppendLine("        //    return dal.GetRecordCount(strWhere);");
            sb.AppendLine("        //}");
            sb.AppendLine("");

            sb.AppendLine("        ///// <summary>");
            sb.AppendLine("        ///// 分页获取数据列表");
            sb.AppendLine("        ///// </summary>");
            sb.AppendLine("        //public DataTable GetList(int PageSize,int PageIndex,string strWhere)");
            sb.AppendLine("        //{");
            sb.AppendLine("        //return dal.GetList(PageSize,PageIndex,strWhere);");
            sb.AppendLine("        //}");
            sb.AppendLine("");
            sb.AppendLine("        #endregion  BasicMethod");
            #endregion

            sb.AppendLine("");
            sb.AppendLine("");
            sb.AppendLine("    }");
            sb.AppendLine("}");
            CommonCode.Save(file_BLL + "/" + str_BLLName + ".cs", sb.ToString());
        }