Beispiel #1
0
        /// <summary>
        /// 根据表名创建列表显示类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateViewMapperClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);                           //类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);                             //News
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            string strTableComment2 = CommonHelper.GetColumnKeyComment(strTableComment);

            string strNewPath = strFilePath + "\\" + strTableNameLower + "\\views-mapper";

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

            StreamWriter sw = new StreamWriter(strNewPath + "\\" + strClassName + "Mapper.xml", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
            sw.WriteLine("<!DOCTYPE mapper PUBLIC \"-//mybatis.org//DTD Mapper 3.0//EN\" \"http://mybatis.org/dtd/mybatis-3-mapper.dtd\">");
            sw.WriteLine("<mapper namespace=\"cc.mrbird.febs." + strTableNameLower + ".mapper." + strClassName + "Mapper\">");
            sw.WriteLine("	<select id=\"findDetailPage\" parameterType=\""+ strTableNameLower + "\"");
            sw.WriteLine("		resultType=\""+ strTableNameLower + "\">");
            sw.WriteLine("		SELECT");
            string result = CommonHelper.GetLeftSelectColumnName2(strTableName, "item");

            result = result.Replace("                                      ", "		");
            sw.WriteLine(result);
            string result2 = CommonHelper.GetDetailsSelectJoinColumn(strTableName, strPrimaryKey, CommonHelper.GetLeftSelectColumnName2(strTableName, "a"));

            result2 = result2.Replace("                                      ", "		");
            sw.WriteLine(result2);
            sw.WriteLine("		FROM "+ strTableName + " item");
            sw.WriteLine(CommonHelper.GetDetailsSelectJoinListForJava(strTableName));
            sw.WriteLine("		where 1=1 	 ");
            sw.WriteLine("");
            sw.WriteLine(CommonHelper.GetSearchListForJava(strTableName));
            sw.WriteLine("");
            sw.WriteLine("	</select>");
            sw.WriteLine("</mapper>");


            sw.Close();
        }
Beispiel #2
0
        /// <summary>
        /// 创建DAL系统文件及项目文件
        /// </summary>
        /// <param name="strFilePath">文件路径</param>
        /// <param name="strProjectName">项目名称</param>
        /// <param name="strTableList">编译文件名称列表</param>
        public static void CreateDALSystemFile(string strFilePath, string strProjectName, string strTableList)
        {
            try
            {
                CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(System.Windows.Forms.Application.StartupPath + "\\config.ini");
                string strFramework       = iniFile.GetString("BASE", "FRAMEWORK", ""); //.net framework版本号
                string strGUID            = iniFile.GetString("GUID", "DAL", "");       //项目GUID
                string strDBSQLHELPERGUID = iniFile.GetString("GUID", "DBSQLHELPER", "");
                string strMODELGUID       = iniFile.GetString("GUID", "MODEL", "");
                string strUTILITYGUID     = iniFile.GetString("GUID", "UTILITY", "");

                Directory.CreateDirectory(strFilePath);

                //创建项目文件-------------------------------------------1
                FileStream   fs1 = new FileStream(Application.StartupPath + "\\template\\system\\DAL_csproj.html", FileMode.OpenOrCreate, FileAccess.Read);
                StreamReader sr1 = new StreamReader(fs1, Encoding.UTF8);
                string       strGetPageHTMLContentForCSPROJ = sr1.ReadToEnd();
                sr1.Close();
                fs1.Close();

                strGetPageHTMLContentForCSPROJ = strGetPageHTMLContentForCSPROJ.Replace("{project_guid}", strGUID);
                strGetPageHTMLContentForCSPROJ = strGetPageHTMLContentForCSPROJ.Replace("{project_name}", strProjectName);
                strGetPageHTMLContentForCSPROJ = strGetPageHTMLContentForCSPROJ.Replace("{framwork_version}", strFramework);
                strGetPageHTMLContentForCSPROJ = strGetPageHTMLContentForCSPROJ.Replace("{compile_table_list}", strTableList);
                strGetPageHTMLContentForCSPROJ = strGetPageHTMLContentForCSPROJ.Replace("{DBSqlHelper_GUID}", strDBSQLHELPERGUID);
                strGetPageHTMLContentForCSPROJ = strGetPageHTMLContentForCSPROJ.Replace("Model_GUID", strMODELGUID);
                strGetPageHTMLContentForCSPROJ = strGetPageHTMLContentForCSPROJ.Replace("Utility_GUID", strUTILITYGUID);

                StreamWriter sw1 = new StreamWriter(strFilePath + "\\" + strProjectName + ".DAL.csproj", false, Encoding.GetEncoding("utf-8"));
                sw1.WriteLine(strGetPageHTMLContentForCSPROJ);
                sw1.Close();

                //创建AssemblyInfo文件-------------------------------------------2
                string strAssemblyPath = strFilePath + "\\Properties";
                if (!Directory.Exists(strAssemblyPath))
                {
                    Directory.CreateDirectory(strAssemblyPath);
                }

                FileStream   fs2 = new FileStream(Application.StartupPath + "\\template\\system\\DAL_AssemblyInfo.html", FileMode.OpenOrCreate, FileAccess.Read);
                StreamReader sr2 = new StreamReader(fs2, Encoding.UTF8);
                string       strGetPageHTMLContentForAssembly = sr2.ReadToEnd();
                sr2.Close();
                fs2.Close();

                strGetPageHTMLContentForAssembly = strGetPageHTMLContentForAssembly.Replace("{project_guid}", strGUID);
                strGetPageHTMLContentForAssembly = strGetPageHTMLContentForAssembly.Replace("{project_name}", strProjectName);
                strGetPageHTMLContentForAssembly = strGetPageHTMLContentForAssembly.Replace("{project_year}", DateTime.Now.Year.ToString());

                StreamWriter sw2 = new StreamWriter(strAssemblyPath + "\\AssemblyInfo.cs", false, Encoding.GetEncoding("utf-8"));
                sw2.WriteLine(strGetPageHTMLContentForAssembly);
                sw2.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(ReadmeHelper), ex, "创建DAL系统文件及项目文件", "CreateDALSystemFile", false);
            }
        }
        /// <summary>
        /// 根据数据库连接类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateDBSqlHelperFile(string strFilePath, string strProjectName)
        {
            try
            {
                CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(System.Windows.Forms.Application.StartupPath + "\\config.ini");

                string strServer   = iniFile.GetString("BASE", "SERVER", "");   //数据库地址
                string strDBName   = iniFile.GetString("BASE", "DBNAME", "");   //数据库名
                string strUserID   = iniFile.GetString("BASE", "USERID", "");   //登录数据库用户名
                string strPassword = iniFile.GetString("BASE", "PASSWORD", ""); //登录数据库密码
                string strCharset  = iniFile.GetString("BASE", "CHARSET", "");  //数据库字符集

                Directory.CreateDirectory(strFilePath);
                StreamWriter sw = new StreamWriter(strFilePath + "\\DBMySQLHelper.cs");
                sw.WriteLine("using System;");
                sw.WriteLine("using System.Collections.Generic;");
                //sw.WriteLine("using System.Data;");
                //sw.WriteLine("using MySql.Data.MySqlClient;");
                sw.WriteLine("");
                sw.WriteLine("namespace " + CodeRobot.Utility.StringHelper.GetTableNameUpper(strProjectName) + ".DBSqlHelper");
                sw.WriteLine("{");
                sw.WriteLine("");
                sw.WriteLine("    /// <summary>");
                sw.WriteLine("    /// 版权所有: Copyright © " + DateTime.Now.Year.ToString() + " Cloudin. 保留所有权利。");
                sw.WriteLine("    /// 内容摘要: DBMySQLHelper");
                sw.WriteLine("    /// 完成日期:" + DateTime.Now.ToString("yyyy年M月d日"));
                sw.WriteLine("    /// 版    本:V1.0 ");
                sw.WriteLine("    /// 作    者:Adin.Lee");
                sw.WriteLine("    /// </summary>");
                sw.WriteLine("    public class DBMySQLHelper");
                sw.WriteLine("    {");
                sw.WriteLine("        /// <summary>");
                sw.WriteLine("        /// 连接数据库");
                sw.WriteLine("        /// <summary>");
                sw.WriteLine("        /// <returns>返回数据库连接字符串</returns>");
                sw.WriteLine("        public static string ConnectMySQL()");
                sw.WriteLine("        {");
                sw.WriteLine("            return \"Server=" + strServer + "; Database=" + strDBName + "; Uid=" + strUserID + "; Pwd=" + strPassword + "; CharSet=" + strCharset + "\";");
                sw.WriteLine("        }");
                sw.WriteLine("    }");
                sw.WriteLine("}");
                sw.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(ReadmeHelper), ex, "创建BLL README文件", "CreateBLLFile");
            }
        }
Beispiel #4
0
        /// <summary>
        /// 生成安卓客户端 Model实体类
        /// </summary>
        /// <param name="strFilePath"></param>
        /// <param name="strProjectName"></param>
        /// <param name="strTableName"></param>
        /// <param name="strPackage"></param>
        public static void CreateAndroidModelClass(string strFilePath, string strProjectName, string strTableName, string strPackage)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");


            string strClassName = CommonHelper.GetClassName(strTableName);//类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);

            var utf8WithoutBom = new System.Text.UTF8Encoding(false);

            Directory.CreateDirectory(strFilePath);
            StreamWriter sw = new StreamWriter(strFilePath + "\\" + strClassName + "Object.java", false, utf8WithoutBom);

            sw.WriteLine("package " + strPackage + ".model;");
            sw.WriteLine("\r\n");
            sw.WriteLine("import org.json.JSONObject;");
            sw.WriteLine("import java.io.Serializable;");
            sw.WriteLine("\r\n");
            sw.WriteLine("/**");
            sw.WriteLine(" * " + CommonHelper.GetTableComment(strTableName));
            sw.WriteLine(" * Author: " + strAuthor + ".");
            sw.WriteLine(" * CreateDate: " + strCreateDate + ".");
            sw.WriteLine(" * UpdateDate: " + DateTime.Now.ToString("yyyy年M月d日") + ".");
            sw.WriteLine(" * Copyright (c) " + DateTime.Now.Year + " " + strCompany + ". All rights reserved.");
            sw.WriteLine(" */");
            sw.WriteLine("public class " + strClassName + "Object implements Serializable{");
            sw.WriteLine("\r\n");
            sw.WriteLine(GetDefineParaList(strTableName) + "\r\n");
            sw.WriteLine("    public " + strClassName + "Object(JSONObject json) {");
            sw.WriteLine("\r\n");
            sw.WriteLine(GetJSONParaList(strTableName) + "\r\n");
            sw.WriteLine("    }");
            sw.WriteLine("    ");
            sw.WriteLine("    public " + strClassName + "Object() {");
            sw.WriteLine("\r\n");
            sw.WriteLine("    }");
            sw.WriteLine("}");
            sw.Close();
        }
Beispiel #5
0
        /// <summary>
        /// 根据表名创建RestAPIHelper类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateRestAPIClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strClassName = CommonHelper.GetClassName(strTableName); //类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);   //首字母大写

            Directory.CreateDirectory(strFilePath);
            StreamWriter sw = new StreamWriter(strFilePath + "\\" + strClassName + "Controller.cs", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("using System;");
            sw.WriteLine("using System.Collections.Generic;");
            sw.WriteLine("using System.Net.Http;");
            sw.WriteLine("using System.Web.Http;");
            sw.WriteLine("");
            sw.WriteLine("namespace " + CommonHelper.GetTableNameUpper(strProjectName) + ".RestAPI.Controllers");
            sw.WriteLine("{");
            sw.WriteLine("");
            sw.WriteLine("    /// <summary>");
            sw.WriteLine("    /// 版权所有: Copyright © " + DateTime.Now.Year.ToString() + " " + strCompany + ". 保留所有权利。");
            sw.WriteLine("    /// 内容摘要: " + strTableComment);
            sw.WriteLine("    /// 完成日期:" + DateTime.Now.ToString("yyyy年M月d日"));
            sw.WriteLine("    /// 版    本:V" + strVersion + "." + strCode + " ");
            sw.WriteLine("    /// 作    者:" + strAuthor);
            sw.WriteLine("    /// </summary>");
            sw.WriteLine("    //[Authorize]");
            sw.WriteLine("    [RoutePrefix(\"api\")]");
            sw.WriteLine("    public class " + strClassName + "Controller : ApiController");
            sw.WriteLine("    {");
            string strFunctionList = GetBLLFunctionList(strProjectName, strTableName);

            sw.WriteLine(strFunctionList);
            sw.WriteLine("    }");
            sw.WriteLine("}");
            sw.Close();
        }
Beispiel #6
0
        /// <summary>
        /// 设置DetailActivity页面模板内容
        /// </summary>
        /// <param name="strContent">模板内容</param>
        /// <param name="strTableName">表名</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strPackage">包名</param>
        /// <returns></returns>
        public static string ReplaceHTMLDataForDetailActivity(string strContent, string strTableName, string strProjectName, string strPackage)
        {
            string strReturnValue = "";

            try
            {
                //读取版权信息
                CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
                string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
                string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
                string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
                string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
                string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

                //获取主键ID
                string strPrimaryID = CommonHelper.GetPrimaryKey(strTableName);
                string strClassName = CommonHelper.GetClassName(strTableName);                //类名
                strClassName = CommonHelper.GetTableNameUpper(strClassName);                  //如:News,NewsType
                string strTableNameLower = CommonHelper.GetClassName(strTableName).ToLower(); //如:news,newstype

                //替换文件名-1
                strContent = strContent.Replace("{packagename}", strPackage);
                strContent = strContent.Replace("{classname_uper}", strClassName);
                strContent = strContent.Replace("{classname_uper_all}", strClassName.ToUpper());
                strContent = strContent.Replace("{classname_lower}", strTableNameLower);
                strContent = strContent.Replace("{projectname}", strProjectName);
                strContent = strContent.Replace("{tablecomment}", CommonHelper.GetTableComment(strTableName));
                strContent = strContent.Replace("{author}", strAuthor);
                strContent = strContent.Replace("{date}", DateTime.Now.ToString("yyyy/M/d"));
                strContent = strContent.Replace("{year}", DateTime.Now.Year.ToString());
                strContent = strContent.Replace("{company}", strCompany);
                strContent = strContent.Replace("{primaryid}", strPrimaryID);

                strReturnValue = strContent;
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(ManageHelper), ex, "处理HTML代码", "ReplaceHTMLDataForListActivity", false);
            }

            return(strReturnValue);
        }
Beispiel #7
0
        /// <summary>
        /// 根据表名创建Context类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateContextClass(string strFilePath, string strProjectName, string strContext)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");


            Directory.CreateDirectory(strFilePath);
            StreamWriter sw = new StreamWriter(strFilePath + "\\" + strProjectName + "ApiContext.cs", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("using System;");
            sw.WriteLine("using Microsoft.EntityFrameworkCore;");
            sw.WriteLine("");
            sw.WriteLine("namespace " + CommonHelper.GetTableNameUpper(strProjectName) + ".API.Data");
            sw.WriteLine("{");
            sw.WriteLine("");
            sw.WriteLine("    /// <summary>");
            sw.WriteLine("    /// 版权所有: Copyright © " + DateTime.Now.Year.ToString() + " " + strCompany + ". 保留所有权利。");
            sw.WriteLine("    /// 内容摘要: " + strProjectName + "ApiContext 数据库上下文类,EF Core ");
            sw.WriteLine("    /// 创建日期:" + Convert.ToDateTime(strCreateDate).ToString("yyyy年M月d日"));
            sw.WriteLine("    /// 更新日期:" + DateTime.Now.ToString("yyyy年M月d日"));
            sw.WriteLine("    /// 版    本:V" + strVersion + "." + strCode + " ");
            sw.WriteLine("    /// 作    者:" + strAuthor);
            sw.WriteLine("    /// </summary>");
            sw.WriteLine("    public class " + strProjectName + "ApiContext : DbContext");
            sw.WriteLine("    {");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 数据库上下文");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        public " + strProjectName + "ApiContext(DbContextOptions<" + strProjectName + "ApiContext> options): base(options)");
            sw.WriteLine("        {");
            sw.WriteLine("        }");
            sw.WriteLine("        ");
            sw.WriteLine(strContext);
            sw.WriteLine("    }");
            sw.WriteLine("}");
            sw.Close();
        }
Beispiel #8
0
        /// <summary>
        /// 根据表名创建DAL类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateBLLClass(string strFilePath, string strProjectName, string strTableName, string strColumnComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strClassName = CommonHelper.GetClassName(strTableName);//类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);

            Directory.CreateDirectory(strFilePath);
            StreamWriter sw = new StreamWriter(strFilePath + "\\" + strClassName + "BLL.cs", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("using System;");
            sw.WriteLine("using System.Collections.Generic;");
            sw.WriteLine("using " + strProjectName + ".Model;");
            sw.WriteLine("using " + strProjectName + ".DAL;");
            sw.WriteLine("");
            sw.WriteLine("namespace " + CommonHelper.GetTableNameUpper(strProjectName) + ".BLL");
            sw.WriteLine("{");
            sw.WriteLine("");
            sw.WriteLine("    /// <summary>");
            sw.WriteLine("    /// 版权所有: Copyright © " + DateTime.Now.Year.ToString() + " " + strCompany + ". 保留所有权利。");
            sw.WriteLine("    /// 内容摘要: " + strClassName + "BLL");
            sw.WriteLine("    /// 创建日期:" + Convert.ToDateTime(strCreateDate).ToString("yyyy年M月d日"));
            sw.WriteLine("    /// 更新日期:" + DateTime.Now.ToString("yyyy年M月d日"));
            sw.WriteLine("    /// 版    本:V" + strVersion + "." + strCode + " ");
            sw.WriteLine("    /// 作    者:" + strAuthor);
            sw.WriteLine("    /// </summary>");
            sw.WriteLine("    public class " + strClassName + "BLL");
            sw.WriteLine("    {");
            string strFunctionList = GetBLLFunctionList(strProjectName, strTableName);

            sw.WriteLine(strFunctionList);
            sw.WriteLine("    }");
            sw.WriteLine("}");
            sw.Close();
        }
Beispiel #9
0
        /// <summary>
        /// 连接数据库
        /// </summary>
        /// <returns></returns>
        public static string ConnectionMySQL()
        {
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");

            string strServer     = iniFile.GetString("BASE", "SERVER", "");   //数据库地址
            string strDBName     = iniFile.GetString("BASE", "DBNAME", "");   //数据库名
            string strDBUser     = iniFile.GetString("BASE", "USERID", "");   //登录数据库用户名
            string strDBPassword = iniFile.GetString("BASE", "PASSWORD", ""); //登录数据库密码
            string strCharset    = iniFile.GetString("BASE", "CHARSET", "");  //数据库字符集

            //解密
            //strServer = CodeRobot.Utility.CryptographyHelper.Decrypt(strServer, CodeRobot.Utility.CommonHelper.cryptographyKey);
            //strDBName = CodeRobot.Utility.CryptographyHelper.Decrypt(strDBName, CodeRobot.Utility.CommonHelper.cryptographyKey);
            //strDBUser = CodeRobot.Utility.CryptographyHelper.Decrypt(strDBUser, CodeRobot.Utility.CommonHelper.cryptographyKey);
            //strDBPassword = CodeRobot.Utility.CryptographyHelper.Decrypt(strDBPassword, CodeRobot.Utility.CommonHelper.cryptographyKey);

            //拼接连接字符串
            string strConnectionStr = "Server=" + strServer + ";Uid=" + strDBUser + ";Pwd=" + strDBPassword + ";CharSet=" + strCharset;

            return(strConnectionStr);
        }
        /// <summary>
        /// 根据表名创建Service类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateServiceImplClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);                           //类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);                             //News
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            string strNewPath = strFilePath + "\\" + strTableNameLower + "\\service\\impl";

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

            StreamWriter sw = new StreamWriter(strNewPath + "\\" + strClassName + "Impl.java", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("/*");
            sw.WriteLine(" * Copyright " + DateTime.Now.Year + " Cloudin.");
            sw.WriteLine(" *");
            sw.WriteLine(" * Licensed under the Apache License, Version 2.0 (the \"License\");");
            sw.WriteLine(" * you may not use this file except in compliance with the License.");
            sw.WriteLine(" * You may obtain a copy of the License at");
            sw.WriteLine(" *");
            sw.WriteLine(" *      http://www.apache.org/licenses/LICENSE-2.0");
            sw.WriteLine(" *");
            sw.WriteLine(" * Unless required by applicable law or agreed to in writing, software");
            sw.WriteLine(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
            sw.WriteLine(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
            sw.WriteLine(" * See the License for the specific language governing permissions and");
            sw.WriteLine(" * limitations under the License.");
            sw.WriteLine(" */");
            sw.WriteLine("package cc.mrbird.febs.news.service.impl;");
            sw.WriteLine("");
            sw.WriteLine("import java.util.Arrays;");
            sw.WriteLine("import java.util.Date;");
            sw.WriteLine("import java.util.List;");
            sw.WriteLine("");
            sw.WriteLine("import org.springframework.stereotype.Service;");
            sw.WriteLine("import org.springframework.transaction.annotation.Propagation;");
            sw.WriteLine("import org.springframework.transaction.annotation.Transactional;");
            sw.WriteLine("");
            sw.WriteLine("import com.baomidou.mybatisplus.core.metadata.IPage;");
            sw.WriteLine("import com.baomidou.mybatisplus.extension.plugins.pagination.Page;");
            sw.WriteLine("import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;");
            sw.WriteLine("");
            sw.WriteLine("import cc.mrbird.febs.common.entity.FebsConstant;");
            sw.WriteLine("import cc.mrbird.febs.common.entity.QueryRequest;");
            sw.WriteLine("import cc.mrbird.febs.common.utils.SortUtil;");
            sw.WriteLine("import cc.mrbird.febs." + strTableNameLower + ".entity." + strClassName + ";");
            sw.WriteLine("import cc.mrbird.febs." + strTableNameLower + ".mapper." + strClassName + "Mapper;");
            sw.WriteLine("import cc.mrbird.febs." + strTableNameLower + ".service.I" + strClassName + "Service;");
            sw.WriteLine("");
            sw.WriteLine("@Service");
            sw.WriteLine("@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)");
            sw.WriteLine("public class " + strClassName + "ServiceImpl extends ServiceImpl<" + strClassName + "Mapper, " + strClassName + "> implements I" + strClassName + "Service {");
            sw.WriteLine("");
            sw.WriteLine("	/**");
            sw.WriteLine("	 * 获取列表");
            sw.WriteLine("	 */");
            sw.WriteLine("	@Override");
            sw.WriteLine("	public IPage<"+ strClassName + "> findList(" + strClassName + " " + strTableNameLower + ", QueryRequest request) {");
            sw.WriteLine("		Page<"+ strClassName + "> page = new Page<>(request.getPageNum(), request.getPageSize());");
            sw.WriteLine("		SortUtil.handlePageSort(request, page, \"userId\", FebsConstant.ORDER_ASC, false);");
            sw.WriteLine("		return this.baseMapper.findDetailPage(page, "+ strTableNameLower + ");");
            sw.WriteLine("	}");
            sw.WriteLine("");
            sw.WriteLine("	/**");
            sw.WriteLine("	 * 创建新闻");
            sw.WriteLine("	 */");
            sw.WriteLine("	@Override");
            sw.WriteLine("	public void create"+ strClassName + "(" + strClassName + " " + strTableNameLower + ") {");
            sw.WriteLine("		news.setCreatedAt(new Date());");
            sw.WriteLine("		save("+ strTableNameLower + ");");
            sw.WriteLine("	}");
            sw.WriteLine("");
            sw.WriteLine("	/**");
            sw.WriteLine("	 * 删除新闻");
            sw.WriteLine("	 */");
            sw.WriteLine("	@Override");
            sw.WriteLine("	@Transactional");
            sw.WriteLine("	public void delete"+ strClassName + "(String[] ids) {");
            sw.WriteLine("		List<String> list = Arrays.asList(ids);");
            sw.WriteLine("		this.removeByIds(list);");
            sw.WriteLine("	}");
            sw.WriteLine("");
            sw.WriteLine("	/**");
            sw.WriteLine("	 * 更新新闻");
            sw.WriteLine("	 */");
            sw.WriteLine("	@Override");
            sw.WriteLine("	@Transactional");
            sw.WriteLine("	public void update"+ strClassName + "(" + strClassName + " " + strTableNameLower + ") {");
            sw.WriteLine("		updateById("+ strTableNameLower + ");");
            sw.WriteLine("	}");
            sw.WriteLine("");
            sw.WriteLine("	/**");
            sw.WriteLine("	 * 根据ID获取详情");
            sw.WriteLine("	 */");
            sw.WriteLine("	@Override");
            sw.WriteLine("	public "+ strClassName + " findById(Long id) {");
            sw.WriteLine("		return getById(id);");
            sw.WriteLine("	}");
            sw.WriteLine("");
            sw.WriteLine("}");

            sw.Close();
        }
        /// <summary>
        /// 根据表名创建Controllers类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateEntityClass(string strFilePath, string strProjectName, string strDefineList, string strValueList, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);                           //类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);                             //News
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            string strNewPath = strFilePath + "\\" + strTableNameLower + "\\entity";

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

            StreamWriter sw = new StreamWriter(strNewPath + "\\" + strClassName + ".java", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("/*");
            sw.WriteLine(" * Copyright 2020 Cloudin.");
            sw.WriteLine(" *");
            sw.WriteLine(" * Licensed under the Apache License, Version 2.0 (the \"License\");");
            sw.WriteLine(" * you may not use this file except in compliance with the License.");
            sw.WriteLine(" * You may obtain a copy of the License at");
            sw.WriteLine(" *");
            sw.WriteLine(" *      http://www.apache.org/licenses/LICENSE-2.0");
            sw.WriteLine(" *");
            sw.WriteLine(" * Unless required by applicable law or agreed to in writing, software");
            sw.WriteLine(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
            sw.WriteLine(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
            sw.WriteLine(" * See the License for the specific language governing permissions and");
            sw.WriteLine(" * limitations under the License.");
            sw.WriteLine(" */");
            sw.WriteLine("package cc.mrbird.febs." + strTableNameLower + ".entity;");
            sw.WriteLine("");
            sw.WriteLine("import java.io.Serializable;");
            sw.WriteLine("import java.util.Date;");
            sw.WriteLine("");
            sw.WriteLine("import com.baomidou.mybatisplus.annotation.IdType;");
            sw.WriteLine("import com.baomidou.mybatisplus.annotation.TableField;");
            sw.WriteLine("import com.baomidou.mybatisplus.annotation.TableId;");
            sw.WriteLine("import com.baomidou.mybatisplus.annotation.TableName;");
            sw.WriteLine("import com.wuwenze.poi.annotation.Excel;");
            sw.WriteLine("");
            sw.WriteLine("import lombok.Data;");
            sw.WriteLine("");
            sw.WriteLine("/**");
            sw.WriteLine(" * " + strTableComment + "类");
            sw.WriteLine(" * @Author Cloudin");
            sw.WriteLine(" * @CreateDate " + Convert.ToDateTime(strCreateDate).ToString("yyyy年M月d日"));
            sw.WriteLine(" * @UpdateDate " + DateTime.Now.ToString("yyyy年M月d日"));
            sw.WriteLine(" * @Version V" + strVersion + "." + strCode);
            sw.WriteLine(" */");
            sw.WriteLine("@Data");
            sw.WriteLine("@TableName(\"" + strTableName + "\")");
            sw.WriteLine("@Excel(\"" + strTableComment + "\")");
            sw.WriteLine("public class " + strClassName + " implements Serializable {");
            sw.WriteLine("");
            sw.WriteLine(strDefineList);
            sw.WriteLine("");
            sw.WriteLine(strValueList);
            sw.WriteLine("}");


            sw.Close();
        }
Beispiel #12
0
        /// <summary>
        /// 根据表名创建Controllers类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateControllersViewClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);                           //类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);                             //News
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            string strNewPath = strFilePath + "\\" + strTableNameLower + "\\controller";

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

            StreamWriter sw = new StreamWriter(strNewPath + "\\ViewController.java", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("package cc.mrbird.febs." + strTableNameLower + ".controller;");
            sw.WriteLine("");
            sw.WriteLine("import org.apache.shiro.authz.annotation.RequiresPermissions;");
            sw.WriteLine("import org.springframework.beans.factory.annotation.Autowired;");
            sw.WriteLine("import org.springframework.stereotype.Controller;");
            sw.WriteLine("import org.springframework.ui.Model;");
            sw.WriteLine("import org.springframework.web.bind.annotation.GetMapping;");
            sw.WriteLine("import org.springframework.web.bind.annotation.PathVariable;");
            sw.WriteLine("");
            sw.WriteLine("import cc.mrbird.febs.common.controller.BaseController;");
            sw.WriteLine("import cc.mrbird.febs.common.entity.FebsConstant;");
            sw.WriteLine("import cc.mrbird.febs.common.utils.FebsUtil;");
            sw.WriteLine("import cc.mrbird.febs." + strTableNameLower + ".entity." + strClassName + ";");
            sw.WriteLine("import cc.mrbird.febs." + strTableNameLower + ".service.I" + strClassName + "Service;");
            sw.WriteLine("");
            sw.WriteLine("@Controller(\"" + strTableNameLower + "View\")");
            sw.WriteLine("public class ViewController extends BaseController {");
            sw.WriteLine("");
            sw.WriteLine("	@Autowired");
            sw.WriteLine("	private I"+ strClassName + "Service" + strTableNameLower + "Service;");
            sw.WriteLine("");
            sw.WriteLine("	@GetMapping(FebsConstant.VIEW_PREFIX + \""+ strTableNameLower + "/list\")");
            sw.WriteLine("	//@RequiresPermissions(\""+ strTableNameLower + ":list\")");
            sw.WriteLine("	public String List() {");
            sw.WriteLine("		return FebsUtil.view(\""+ strTableNameLower + "/list\");");
            sw.WriteLine("	}");
            sw.WriteLine("");
            sw.WriteLine("	@GetMapping(FebsConstant.VIEW_PREFIX + \""+ strTableNameLower + "/create\")");
            sw.WriteLine("	//@RequiresPermissions(\""+ strTableNameLower + ":create\")");
            sw.WriteLine("	public String Create() {");
            sw.WriteLine("		return FebsUtil.view(\""+ strTableNameLower + "/create\");");
            sw.WriteLine("	}");
            sw.WriteLine("");
            sw.WriteLine("	@GetMapping(FebsConstant.VIEW_PREFIX + \""+ strTableNameLower + "/view/{id}\")");
            sw.WriteLine("	//@RequiresPermissions(\""+ strTableNameLower + ":view\")");
            sw.WriteLine("	public String View(@PathVariable Long id, Model model) {");
            sw.WriteLine("		"+ strClassName + " " + strTableNameLower + " = " + strTableNameLower + "Service.findById(id);");
            sw.WriteLine("		model.addAttribute(\""+ strTableNameLower + "\", " + strTableNameLower + ");");
            sw.WriteLine("		return FebsUtil.view(\""+ strTableNameLower + "/view\");");
            sw.WriteLine("	}");
            sw.WriteLine("");
            sw.WriteLine("	@GetMapping(FebsConstant.VIEW_PREFIX + \""+ strTableNameLower + "/edit/{id}\")");
            sw.WriteLine("	//@RequiresPermissions(\""+ strTableNameLower + ":edit\")");
            sw.WriteLine("	public String Edit(@PathVariable Long id, Model model) {");
            sw.WriteLine("		"+ strClassName + " " + strTableNameLower + " = " + strTableNameLower + "Service.findById(id);");
            sw.WriteLine("		model.addAttribute(\""+ strTableNameLower + "\", " + strTableNameLower + ");");
            sw.WriteLine("		return FebsUtil.view(\""+ strTableNameLower + "/edit\");");
            sw.WriteLine("	}");
            sw.WriteLine("");
            sw.WriteLine("}");


            sw.Close();
        }
        /// <summary>
        /// 根据表名创建Views详情页面
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateViewMutiViewsClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);//类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            Directory.CreateDirectory(strFilePath);
            //为每个表创建一个独立目录存放
            string strTableNamePath = strFilePath + "\\" + strClassName;

            if (!Directory.Exists(strTableNamePath))
            {
                Directory.CreateDirectory(strTableNamePath);
            }
            StreamWriter sw = new StreamWriter(strTableNamePath + "\\Views.cshtml", false, Encoding.GetEncoding("utf-8"));//生成物理文件

            string strTableComment2 = CommonHelper.GetColumnKeyComment(strTableComment);

            sw.WriteLine("@{");
            sw.WriteLine("    ViewData[\"Title\"] = \"" + strTableComment2 + "详情\";");
            sw.WriteLine("    Layout = \"~/Views/Shared/_LayoutNone.cshtml\";");
            sw.WriteLine("}");
            sw.WriteLine("");
            sw.WriteLine("<div class=\"layui-fluid\">");
            sw.WriteLine("    <div class=\"layui-row layui-col-space15\">");
            sw.WriteLine("        <div class=\"layui-col-md12\">");
            sw.WriteLine("            <div class=\"layui-card\">");
            sw.WriteLine("                <div class=\"layui-card-body\" pad15>");
            sw.WriteLine("");
            sw.WriteLine("                    <div class=\"layui-form\" wid100 lay-filter=\"\">");
            sw.WriteLine(GetViewsItemList(strTableName));
            sw.WriteLine("                    </div>");
            sw.WriteLine("");
            sw.WriteLine("                </div>");
            sw.WriteLine("            </div>");
            sw.WriteLine("        </div>");
            sw.WriteLine("    </div>");
            sw.WriteLine("");
            sw.WriteLine("    <input type=\"hidden\" name=\"" + strPrimaryKey + "\" id=\"" + strPrimaryKey + "\" value=\"@ViewContext.HttpContext.Request.Query[\"id\"]\" />");
            sw.WriteLine("</div>");
            sw.WriteLine("");
            sw.WriteLine("");
            sw.WriteLine("<script src=\"~/layuiadmin/layui/layui.js\"></script>");
            sw.WriteLine("<script>");
            sw.WriteLine("    layui.config({");
            sw.WriteLine("        base: '/layuiadmin/' //静态资源所在路径");
            sw.WriteLine("    }).extend({");
            sw.WriteLine("        index: '/lib/index' //主入口模块");
            sw.WriteLine("    }).use(['index', 'form'], function () {");
            sw.WriteLine("        var $ = layui.$");
            sw.WriteLine("            , admin = layui.admin");
            sw.WriteLine("");
            sw.WriteLine("        //默认加载");
            sw.WriteLine("        $(function () {");
            sw.WriteLine("            var " + strPrimaryKey + " = $(\"#" + strPrimaryKey + "\").val();");
            sw.WriteLine("");
            sw.WriteLine("            //读取数据加载loading..");
            sw.WriteLine("            loading = layer.load(2, {");
            sw.WriteLine("                shade: [0.2, '#000']");
            sw.WriteLine("            });");
            sw.WriteLine("");
            sw.WriteLine("            admin.req({");
            sw.WriteLine("                url: '/" + strTableNameLower + "/details'");
            sw.WriteLine("                , data: { id: " + strPrimaryKey + " }");
            sw.WriteLine("                , done: function (res) {");
            sw.WriteLine("                    layer.close(loading);");
            sw.WriteLine("                    console.log(res.data);");
            sw.WriteLine(GetViewsItemValueList(strTableName));
            sw.WriteLine("                }");
            sw.WriteLine("            });");
            sw.WriteLine("");
            sw.WriteLine("        });");
            sw.WriteLine("    })");
            sw.WriteLine("</script>");
            sw.Close();
        }
Beispiel #14
0
        /// <summary>
        /// 根据表名创建编辑类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateViewEditClass(string strFilePath, string strProjectName, string strHtmlInputList, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);                           //类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);                             //News
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            string strNewPath = strFilePath + "\\" + strTableNameLower + "\\views";

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

            StreamWriter sw = new StreamWriter(strNewPath + "\\Edit.html", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("<!DOCTYPE html>");
            sw.WriteLine("<html>");
            sw.WriteLine("<head>");
            sw.WriteLine("<meta charset=\"utf-8\">");
            sw.WriteLine("<title>编辑" + strTableComment + "</title>");
            sw.WriteLine("<meta name=\"renderer\" content=\"webkit\">");
            sw.WriteLine("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">");
            sw.WriteLine("<meta name=\"viewport\"");
            sw.WriteLine("	content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0\">");
            sw.WriteLine("<link rel=\"stylesheet\" th:href=\"@{/layuiadmin/layui/css/layui.css}\"");
            sw.WriteLine("	media=\"all\">");
            sw.WriteLine("<link rel=\"stylesheet\" th:href=\"@{/layuiadmin/style/admin.css}\"");
            sw.WriteLine("	media=\"all\">");
            sw.WriteLine("</head>");
            sw.WriteLine("<body>");
            sw.WriteLine("	<div class=\"layui-form\" lay-filter=\"layuiadmin-app-form-list\"");
            sw.WriteLine("		id=\"layuiadmin-app-form-list\" style=\"padding: 20px 30px 0 0;\">");
            sw.WriteLine("");
            sw.WriteLine(strHtmlInputList);
            sw.WriteLine("");
            sw.WriteLine("		<div class=\"layui-form-item layui-hide\">");
            sw.WriteLine("			<input type=\"button\" lay-submit");
            sw.WriteLine("				lay-filter=\"layuiadmin-app-form-submit\"");
            sw.WriteLine("				id=\"layuiadmin-app-form-submit\" value=\"确认添加\"> <input");
            sw.WriteLine("				type=\"button\" lay-submit lay-filter=\"layuiadmin-app-form-edit\"");
            sw.WriteLine("				id=\"layuiadmin-app-form-edit\" value=\"确认编辑\">");
            sw.WriteLine("		</div>");
            sw.WriteLine("	</div>");
            sw.WriteLine("	<script th:src=\"@{/layuiadmin/layui/layui.js}\"></script>");
            sw.WriteLine("	<script>");
            sw.WriteLine("layui.config({");
            sw.WriteLine("    base: '/layuiadmin/' //静态资源所在路径");
            sw.WriteLine("}).extend({");
            sw.WriteLine("    index: '/lib/index', //主入口模块");
            sw.WriteLine("}).use(['index', 'layedit', 'form'], function () {");
            sw.WriteLine("    var $ = layui.$");
            sw.WriteLine("        , form = layui.form");
            sw.WriteLine("        , admin = layui.admin");
            sw.WriteLine("        , layedit = layui.layedit;");
            sw.WriteLine("");
            sw.WriteLine("    //监听指定开关");
            sw.WriteLine("    form.on('switch(switch_status)', function (data) {");
            sw.WriteLine("        if (this.checked) {");
            sw.WriteLine("            $(\"#news_status\").val(true);");
            sw.WriteLine("        } else {");
            sw.WriteLine("            $(\"#news_status\").val(false);");
            sw.WriteLine("        }");
            sw.WriteLine("    });");
            sw.WriteLine("");
            sw.WriteLine("    //监听提交");
            sw.WriteLine("    form.on('submit(layuiadmin-app-form-submit)', function (data) {");
            sw.WriteLine("        var field = data.field; //获取提交的字段");
            sw.WriteLine("        var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引");
            sw.WriteLine("");
            sw.WriteLine("        //提交 Ajax 成功后,关闭当前弹层并重载表格");
            sw.WriteLine("        loading = layer.load(2, {");
            sw.WriteLine("            shade: [0.2, '#000']");
            sw.WriteLine("        });");
            sw.WriteLine("");
            sw.WriteLine("        //提交数据");
            sw.WriteLine("        admin.req({");
            sw.WriteLine("            method: 'POST',");
            sw.WriteLine("            url: '/" + strTableNameLower + "/edit' ");
            sw.WriteLine("            , data: data.field");
            sw.WriteLine("            , done: function (res) {");
            sw.WriteLine("                layer.close(loading);");
            sw.WriteLine("                layer.msg(res.msg, {");
            sw.WriteLine("                    offset: '15px'");
            sw.WriteLine("                    , icon: 1");
            sw.WriteLine("                    , time: 1000");
            sw.WriteLine("                }, function () {");
            sw.WriteLine("                    window.location.reload();");
            sw.WriteLine("                });");
            sw.WriteLine("            }");
            sw.WriteLine("        });");
            sw.WriteLine("    });");
            sw.WriteLine("})");
            sw.WriteLine(" </script>");
            sw.WriteLine("</body>");
            sw.WriteLine("</html>");



            sw.Close();
        }
Beispiel #15
0
        /// <summary>
        /// 根据表名创建Controllers类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateControllersClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);                           //类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);                             //News
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            string strNewPath = strFilePath + "\\" + strTableNameLower + "\\controller";

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

            StreamWriter sw = new StreamWriter(strNewPath + "\\" + strClassName + "Controller.java", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("/*");
            sw.WriteLine(" * Copyright " + DateTime.Now.Year + " Cloudin.");
            sw.WriteLine(" *");
            sw.WriteLine(" * Licensed under the Apache License, Version 2.0 (the \"License\");");
            sw.WriteLine(" * you may not use this file except in compliance with the License.");
            sw.WriteLine(" * You may obtain a copy of the License at");
            sw.WriteLine(" *");
            sw.WriteLine(" *      http://www.apache.org/licenses/LICENSE-2.0");
            sw.WriteLine(" *");
            sw.WriteLine(" * Unless required by applicable law or agreed to in writing, software");
            sw.WriteLine(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
            sw.WriteLine(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
            sw.WriteLine(" * See the License for the specific language governing permissions and");
            sw.WriteLine(" * limitations under the License.");
            sw.WriteLine(" */");
            sw.WriteLine("package cc.mrbird.febs." + strTableNameLower + ".controller;");
            sw.WriteLine("");
            sw.WriteLine("import java.util.Map;");
            sw.WriteLine("");
            sw.WriteLine("import javax.validation.Valid;");
            sw.WriteLine("import javax.validation.constraints.NotBlank;");
            sw.WriteLine("");
            sw.WriteLine("import org.apache.shiro.authz.annotation.RequiresPermissions;");
            sw.WriteLine("import org.springframework.beans.factory.annotation.Autowired;");
            sw.WriteLine("import org.springframework.validation.annotation.Validated;");
            sw.WriteLine("import org.springframework.web.bind.annotation.GetMapping;");
            sw.WriteLine("import org.springframework.web.bind.annotation.PathVariable;");
            sw.WriteLine("import org.springframework.web.bind.annotation.PostMapping;");
            sw.WriteLine("import org.springframework.web.bind.annotation.RequestMapping;");
            sw.WriteLine("import org.springframework.web.bind.annotation.RestController;");
            sw.WriteLine("");
            sw.WriteLine("import com.baomidou.mybatisplus.core.toolkit.StringPool;");
            sw.WriteLine("");
            sw.WriteLine("import cc.mrbird.febs.common.annotation.ControllerEndpoint;");
            sw.WriteLine("import cc.mrbird.febs.common.controller.BaseController;");
            sw.WriteLine("import cc.mrbird.febs.common.entity.QueryRequest;");
            sw.WriteLine("import cc.mrbird.febs.common.entity.ResultResponse;");
            sw.WriteLine("import cc.mrbird.febs.common.exception.FebsException;");
            sw.WriteLine("import cc.mrbird.febs." + strTableNameLower + ".entity." + strClassName + ";");
            sw.WriteLine("import cc.mrbird.febs." + strTableNameLower + ".service.I" + strClassName + "Service;");
            sw.WriteLine("");
            sw.WriteLine("/**");
            sw.WriteLine(" * " + strTableComment + "类");
            sw.WriteLine(" * @Author Cloudin");
            sw.WriteLine(" * @CreateDate " + Convert.ToDateTime(strCreateDate).ToString("yyyy年M月d日"));
            sw.WriteLine(" * @UpdateDate " + DateTime.Now.ToString("yyyy年M月d日"));
            sw.WriteLine(" * @Version V" + strVersion + "." + strCode);
            sw.WriteLine(" */");
            sw.WriteLine("@Validated");
            sw.WriteLine("@RestController");
            sw.WriteLine("@RequestMapping(\"" + strTableNameLower + "\")");
            sw.WriteLine("public class " + strClassName + "Controller extends BaseController {");
            sw.WriteLine("");
            sw.WriteLine("	/**");
            sw.WriteLine("	 * 声明调用"+ strTableComment + "接口");
            sw.WriteLine("	 */");
            sw.WriteLine("	@Autowired");
            sw.WriteLine("	private I"+ strClassName + "Service " + strTableNameLower + "Service;");
            sw.WriteLine("");
            sw.WriteLine("	/**");
            sw.WriteLine("	 * 获取"+ strTableComment + "列表");
            sw.WriteLine("	 * @param "+ strTableNameLower + "");
            sw.WriteLine("	 * @param request");
            sw.WriteLine("	 * @return");
            sw.WriteLine("	 */");
            sw.WriteLine("	@GetMapping(\"list\")");
            sw.WriteLine("	//@RequiresPermissions(\""+ strTableNameLower + ":list\")");
            sw.WriteLine("	public ResultResponse "+ strClassName + "List(" + strClassName + " " + strTableNameLower + ", QueryRequest request) {");
            sw.WriteLine("		Map<String, Object>");
            sw.WriteLine("    dataTable = getDataTable(this." + strTableNameLower + ".findDetailList(" + strTableNameLower + ", request));");
            sw.WriteLine("    return new ResultResponse().success().tableListData(dataTable);");
            sw.WriteLine("    }");
            sw.WriteLine("");
            sw.WriteLine("    /**");
            sw.WriteLine("    * 新增" + strTableComment + "");
            sw.WriteLine("    * @param " + strTableNameLower + "");
            sw.WriteLine("    * @return");
            sw.WriteLine("    */");
            sw.WriteLine("    @PostMapping(\"create\")");
            sw.WriteLine("    //@RequiresPermissions(\"" + strTableNameLower + ":create\")");
            sw.WriteLine("    @ControllerEndpoint(operation = \"新增" + strTableComment + "\", exceptionMessage = \"新增" + strTableComment + "失败\")");
            sw.WriteLine("    public ResultResponse addUser(@Valid " + strClassName + " " + strTableNameLower + ") {");
            sw.WriteLine("    this." + strTableNameLower + ".create" + strClassName + "(" + strTableNameLower + ");");
            sw.WriteLine("    return new ResultResponse().success();");
            sw.WriteLine("    }");
            sw.WriteLine("");
            sw.WriteLine("    /**");
            sw.WriteLine("    * 删除" + strTableComment + ",支持批量删除,逗号分隔");
            sw.WriteLine("    * @param Ids");
            sw.WriteLine("    * @return");
            sw.WriteLine("    */");
            sw.WriteLine("    @PostMapping(\"delete/{Ids}\")");
            sw.WriteLine("    //@RequiresPermissions(\"" + strTableNameLower + ":delete\")");
            sw.WriteLine("    @ControllerEndpoint(operation = \"删除" + strTableComment + "\", exceptionMessage = \"删除" + strTableComment + "失败\")");
            sw.WriteLine("    public ResultResponse deleteUsers(@NotBlank(message = \"{required}\") @PathVariable String Ids) {");
            sw.WriteLine("    String[] ids = Ids.split(StringPool.COMMA);");
            sw.WriteLine("    this." + strTableNameLower + ".delete" + strClassName + "(ids);");
            sw.WriteLine("    return new ResultResponse().success();");
            sw.WriteLine("    }");
            sw.WriteLine("");
            sw.WriteLine("    /**");
            sw.WriteLine("    * 查看" + strTableComment + "");
            sw.WriteLine("    * @param newId");
            sw.WriteLine("    * @return");
            sw.WriteLine("    */");
            sw.WriteLine("    @PostMapping(\"details/{newId}\")");
            sw.WriteLine("    //@RequiresPermissions(\"" + strTableNameLower + ":details\")");
            sw.WriteLine("    @ControllerEndpoint(operation = \"查看" + strTableComment + "\", exceptionMessage = \"查看" + strTableComment + "失败\")");
            sw.WriteLine("    public ResultResponse edit" + strClassName + "(@NotBlank(message = \"{required}\") @PathVariable Long newId) {");
            sw.WriteLine("    " + strClassName + " " + strTableNameLower + " = this." + strTableNameLower + "Service.findById(newId);");
            sw.WriteLine("    return new ResultResponse().success().data(" + strTableNameLower + ");");
            sw.WriteLine("    }");
            sw.WriteLine("");
            sw.WriteLine("    /**");
            sw.WriteLine("    * 编辑" + strTableComment + "");
            sw.WriteLine("    * @param " + strTableNameLower + "");
            sw.WriteLine("    * @return");
            sw.WriteLine("    */");
            sw.WriteLine("    @PostMapping(\"edit\")");
            sw.WriteLine("    //@RequiresPermissions(\"" + strTableNameLower + ":edit\")");
            sw.WriteLine("    @ControllerEndpoint(operation = \"编辑" + strTableComment + "\", exceptionMessage = \"编辑" + strTableComment + "失败\")");
            sw.WriteLine("    public ResultResponse updateNew(@Valid " + strClassName + " " + strTableNameLower + ") {");
            sw.WriteLine("    if (" + strTableNameLower + ".get" + strClassName + "Id() == null)");
            sw.WriteLine("    throw new FebsException(\"ID为空\");");
            sw.WriteLine("    this." + strTableNameLower + "Service.update" + strClassName + "(" + strTableNameLower + ");");
            sw.WriteLine("    return new ResultResponse().success();");
            sw.WriteLine("    }");
            sw.WriteLine("    }");

            sw.Close();
        }
Beispiel #16
0
        /// <summary>
        /// 根据表名创建Index管理页面
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateViewIndexClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);//类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes
            string strNameValue      = strPrimaryKey.Replace("_id", "");

            Directory.CreateDirectory(strFilePath);
            //为每个表创建一个独立目录存放
            string strTableNamePath = strFilePath + "\\" + strClassName;

            if (!Directory.Exists(strTableNamePath))
            {
                Directory.CreateDirectory(strTableNamePath);
            }
            StreamWriter sw = new StreamWriter(strTableNamePath + "\\Index.cshtml", false, Encoding.GetEncoding("utf-8"));//生成物理文件
            string       strTableComment2 = CommonHelper.GetColumnKeyComment(strTableComment);

            sw.WriteLine("@{");
            sw.WriteLine("    ViewData[\"Title\"] = \"" + strTableComment2 + "列表\";");
            sw.WriteLine("    Layout = \"~/Views/Shared/_LayoutNone.cshtml\";");
            sw.WriteLine("}");
            sw.WriteLine("<div class=\"layui-fluid\">");
            sw.WriteLine("    <div class=\"layui-card\">");
            sw.WriteLine("");
            sw.WriteLine("        <div class=\"layui-card-body\">");
            sw.WriteLine("            <div style=\"padding-bottom: 10px;\">");
            sw.WriteLine("                <button class=\"layui-btn layuiadmin-btn-list\" onclick=\"add();\">新增</button>");
            sw.WriteLine("                <button class=\"layui-btn layuiadmin-btn-list\" onclick=\"refresh();\">刷新</button>");
            sw.WriteLine("            </div>");
            sw.WriteLine("            <div id=\"LAY-app-content-list\"></div>");
            sw.WriteLine("        </div>");
            sw.WriteLine("    </div>");
            sw.WriteLine("</div>");
            sw.WriteLine("");
            sw.WriteLine("<script src=\"~/layuiadmin/layui/layui.js\"></script>");
            sw.WriteLine("<script src=\"~/lib/jquery/dist/jquery.min.js\"></script>");
            sw.WriteLine("<script type=\"text/javascript\">");
            sw.WriteLine("    //删除");
            sw.WriteLine("    function del(row) {");
            sw.WriteLine("        layer.confirm(\"确定删除此" + strTableComment2 + "?\", function (e) {");
            sw.WriteLine("");
            sw.WriteLine("            $.ajax({");
            sw.WriteLine("                headers: {");
            sw.WriteLine("                    'RequestVerificationToken': csrfToken");
            sw.WriteLine("                },");
            sw.WriteLine("                url: '/" + strTableNameLower + "/delete/' + row.id,");
            sw.WriteLine("                type: \"POST\",");
            sw.WriteLine("                cache: false,");
            sw.WriteLine("                dataType: \"json\",");
            sw.WriteLine("                success: function (res) {");
            sw.WriteLine("                    console.log(res.msg);");
            sw.WriteLine("                    layer.close(e);");
            sw.WriteLine("                    window.location.reload();");
            sw.WriteLine("                }");
            sw.WriteLine("            });");
            sw.WriteLine("        });");
            sw.WriteLine("    }");
            sw.WriteLine("");
            sw.WriteLine("    //刷新");
            sw.WriteLine("    function refresh() {");
            sw.WriteLine("        window.location.reload();");
            sw.WriteLine("    }");
            sw.WriteLine("");
            sw.WriteLine("    //新增");
            sw.WriteLine("    function add() {");
            sw.WriteLine("");
            sw.WriteLine("        layer.open({");
            sw.WriteLine("            type: 2");
            sw.WriteLine("            , title: '新增" + strTableComment2 + "'");
            sw.WriteLine("            , content: '/" + strTableNameLower + "/create'");
            sw.WriteLine("            , maxmin: true");
            sw.WriteLine("            , area: ['550px', '550px']");
            sw.WriteLine("            , btn: ['确定', '取消']");
            sw.WriteLine("            , yes: function (index, layero) {");
            sw.WriteLine("                //点击确认触发 iframe 内容中的按钮提交");
            sw.WriteLine("                var submit = layero.find('iframe').contents().find(\"#layuiadmin-app-form-submit\");");
            sw.WriteLine("                submit.click();");
            sw.WriteLine("            }");
            sw.WriteLine("        });");
            sw.WriteLine("    }");
            sw.WriteLine("");
            sw.WriteLine("    //编辑");
            sw.WriteLine("    function edit(row) {");
            sw.WriteLine("");
            sw.WriteLine("        layer.open({");
            sw.WriteLine("            type: 2");
            sw.WriteLine("            , title: '编辑" + strTableComment2 + "'");
            sw.WriteLine("            , content: '/" + strTableNameLower + "/edit?id=' + row.id");
            sw.WriteLine("            , maxmin: true");
            sw.WriteLine("            , area: ['550px', '550px']");
            sw.WriteLine("            , btn: ['确定', '取消']");
            sw.WriteLine("            , yes: function (index, layero) {");
            sw.WriteLine("                //点击确认触发 iframe 内容中的按钮提交");
            sw.WriteLine("                var submit = layero.find('iframe').contents().find(\"#layuiadmin-app-form-edit\");");
            sw.WriteLine("                submit.click();");
            sw.WriteLine("            }");
            sw.WriteLine("        });");
            sw.WriteLine("    }");
            sw.WriteLine("");
            sw.WriteLine("    var layout = [");
            sw.WriteLine("        { name: '名称', treeNodes: true, headerClass: 'value_col', colClass: 'value_col', style: '' },");
            sw.WriteLine("        { name: 'ID', field: 'id', headerClass: 'value_col', colClass: 'value_col', style: '' },");
            sw.WriteLine("        { name: '备注', field: 'remark', headerClass: 'value_col', colClass: 'value_col', style: '' },");
            sw.WriteLine("        {");
            sw.WriteLine("            name: '操作',");
            sw.WriteLine("            headerClass: 'value_col',");
            sw.WriteLine("            colClass: 'value_col',");
            sw.WriteLine("            style: 'width: 20%',");
            sw.WriteLine("            render: function (row) {");
            sw.WriteLine("                return \"<a class=\\\"layui-btn layui-btn-xs\\\" onclick='edit(\" + row + \")'><i class=\\\"layui-icon layui-icon-edit\\\"></i>编辑</a> <a class='layui-btn layui-btn-danger layui-btn-sm' onclick='del(\" + row + \")'><i class='layui-icon'>&#xe640;</i> 删除</a>\"; //列渲染");
            sw.WriteLine("            }");
            sw.WriteLine("        },");
            sw.WriteLine("    ];");
            sw.WriteLine("");
            sw.WriteLine("    layui.config({");
            sw.WriteLine("        base: '/layuiadmin/' //静态资源所在路径");
            sw.WriteLine("    }).extend({");
            sw.WriteLine("        treetable: 'treetable-lay/treetable',");
            sw.WriteLine("        index: '/lib/index' //主入口模块");
            sw.WriteLine("    }).use(['index', 'table', 'laydate', 'util', 'treetable', 'layer'], function () {");
            sw.WriteLine("        var layer = layui.layer, form = layui.form, admin = layui.admin, $ = layui.jquery;");
            sw.WriteLine("");
            sw.WriteLine("        $(function () {");
            sw.WriteLine("");
            sw.WriteLine("            //读取数据加载loading..");
            sw.WriteLine("            loading = layer.load(2, {");
            sw.WriteLine("                shade: [0.2, '#000']");
            sw.WriteLine("            });");
            sw.WriteLine("");
            sw.WriteLine("            //列表");
            sw.WriteLine("            admin.req({");
            sw.WriteLine("                url: '/" + strTableNameLower + "/list?id=-1'");
            sw.WriteLine("                , done: function (res) {");
            sw.WriteLine("                    layer.close(loading);");
            sw.WriteLine("                    console.log(res.data);");
            sw.WriteLine("                    var count = res.count;");
            sw.WriteLine("                    var arrayList = [];");
            sw.WriteLine("                    var num = 1;");
            sw.WriteLine("                    $.each(res.data, function (i, item) {");
            sw.WriteLine("                        var " + strPrimaryKey + " = res.data[i]." + strPrimaryKey + ";");
            sw.WriteLine("                        //console.log('" + strPrimaryKey + "=' + " + strPrimaryKey + " + ',count=' + count);");
            sw.WriteLine("");
            sw.WriteLine("                        //获取子节点");
            sw.WriteLine("                        admin.req({");
            sw.WriteLine("                            url: '/" + strTableNameLower + "/list?id=' + " + strPrimaryKey + "");
            sw.WriteLine("                            , done: function (res2) {");
            sw.WriteLine("                                //console.log(res2.data);");
            sw.WriteLine("                                var count2 = res2.count;");
            sw.WriteLine("                                var arrarSubList = [];");
            sw.WriteLine("                                $.each(res2.data, function (a, item) {");
            sw.WriteLine("                                    arrarSubList.push({ \"id\": res2.data[a]." + strPrimaryKey + ", \"name\": res2.data[a]." + strNameValue + "_name, \"remark\": res2.data[a]." + strNameValue + "_remark });");
            sw.WriteLine("                                });");
            sw.WriteLine("");
            sw.WriteLine("                                arrayList.push({ \"id\": res.data[i]." + strPrimaryKey + ", \"name\": res.data[i]." + strNameValue + "_name, \"remark\": res.data[i]." + strNameValue + "_remark, \"children\": arrarSubList });");
            sw.WriteLine("");
            sw.WriteLine("                                if (num == count) {");
            sw.WriteLine("                                    var tree1 = layui.treetable({");
            sw.WriteLine("                                        elem: '#LAY-app-content-list', //传入元素选择器");
            sw.WriteLine("                                        checkbox: false,");
            sw.WriteLine("                                        nodes: arrayList,");
            sw.WriteLine("                                        layout: layout");
            sw.WriteLine("                                    });");
            sw.WriteLine("");
            sw.WriteLine("                                    form.render();");
            sw.WriteLine("                                }");
            sw.WriteLine("                                num++;");
            sw.WriteLine("                            }");
            sw.WriteLine("                        });");
            sw.WriteLine("                    });");
            sw.WriteLine("                }");
            sw.WriteLine("            });");
            sw.WriteLine("");
            sw.WriteLine("        });");
            sw.WriteLine("");
            sw.WriteLine("    });");
            sw.WriteLine("");
            sw.WriteLine("</script>");

            sw.Close();
        }
        /// <summary>
        /// 根据表名创建详情类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateViewDetailsClass(string strFilePath, string strProjectName, string strHtmlInputList, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);                           //类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);                             //News
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            string strNewPath = strFilePath + "\\" + strTableNameLower + "\\views";

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

            StreamWriter sw = new StreamWriter(strNewPath + "\\Details.html", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("<!DOCTYPE html>");
            sw.WriteLine("<html>");
            sw.WriteLine("<head>");
            sw.WriteLine("<meta charset=\"utf-8\">");
            sw.WriteLine("<title>" + strTableComment + "详情</title>");
            sw.WriteLine("<meta name=\"renderer\" content=\"webkit\">");
            sw.WriteLine("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">");
            sw.WriteLine("<meta name=\"viewport\"");
            sw.WriteLine("	content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0\">");
            sw.WriteLine("<link rel=\"stylesheet\" th:href=\"@{/layuiadmin/layui/css/layui.css}\"");
            sw.WriteLine("	media=\"all\">");
            sw.WriteLine("<link rel=\"stylesheet\" th:href=\"@{/layuiadmin/style/admin.css}\"");
            sw.WriteLine("	media=\"all\">");
            sw.WriteLine("</head>");
            sw.WriteLine("<body>");
            sw.WriteLine("");
            sw.WriteLine("	<div class=\"layui-form\" lay-filter=\"layuiadmin-app-form-list\" id=\"layuiadmin-app-form-list\" style=\"padding: 20px 30px 0 0;\">");
            sw.WriteLine("");
            sw.WriteLine(strHtmlInputList);
            sw.WriteLine("");
            sw.WriteLine("		<div class=\"layui-form-item layui-hide\">");
            sw.WriteLine("			<input type=\"button\" lay-submit");
            sw.WriteLine("				lay-filter=\"layuiadmin-app-form-submit\"");
            sw.WriteLine("				id=\"layuiadmin-app-form-submit\" value=\"确认添加\"> <input");
            sw.WriteLine("				type=\"button\" lay-submit lay-filter=\"layuiadmin-app-form-edit\"");
            sw.WriteLine("				id=\"layuiadmin-app-form-edit\" value=\"确认编辑\">");
            sw.WriteLine("		</div>");
            sw.WriteLine("	</div>");
            sw.WriteLine("	<script th:src=\"@{/layuiadmin/layui/layui.js}\"></script>");
            sw.WriteLine("	<script>");
            sw.WriteLine("layui.config({");
            sw.WriteLine("    base: '/layuiadmin/' //静态资源所在路径");
            sw.WriteLine("}).extend({");
            sw.WriteLine("    index: '/lib/index', //主入口模块");
            sw.WriteLine("}).use(['index', 'layedit', 'form'], function () {");
            sw.WriteLine("    var $ = layui.$");
            sw.WriteLine("        , form = layui.form");
            sw.WriteLine("        , admin = layui.admin");
            sw.WriteLine("        , layedit = layui.layedit;");
            sw.WriteLine("   ");
            sw.WriteLine("})");
            sw.WriteLine(" </script>");
            sw.WriteLine("</body>");
            sw.WriteLine("</html>");

            sw.Close();
        }
Beispiel #18
0
        /// <summary>
        /// 根据表名创建列表显示类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateViewListClass(string strFilePath, string strProjectName, string strHtmlInputList, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);                           //类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);                             //News
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            string strTableComment2 = CommonHelper.GetColumnKeyComment(strTableComment);

            string strNewPath = strFilePath + "\\" + strTableNameLower + "\\views";

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

            StreamWriter sw = new StreamWriter(strNewPath + "\\List.html", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("<!DOCTYPE html>");
            sw.WriteLine("<html xmlns:th=\"http://www.thymeleaf.org\" xmlns:shiro=\"http://www.pollix.at/thymeleaf/shiro\">");
            sw.WriteLine("<head>");
            sw.WriteLine("<meta charset=\"utf-8\">");
            sw.WriteLine("<title>" + strTableComment2 + "列表</title>");
            sw.WriteLine("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />");
            sw.WriteLine("<meta name=\"renderer\" content=\"webkit\">");
            sw.WriteLine("<meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge,chrome=1\">");
            sw.WriteLine("<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0\">");
            sw.WriteLine("<link rel=\"stylesheet\" th:href=\"@{/layuiadmin/layui/css/layui.css}\" media=\"all\">");
            sw.WriteLine("<link rel=\"stylesheet\" th:href=\"@{/layuiadmin/style/admin.css}\" media=\"all\">");
            sw.WriteLine("</head>");
            sw.WriteLine("<body>");
            sw.WriteLine("	<div class=\"layui-fluid\">");
            sw.WriteLine("		<div class=\"layui-card\">");
            sw.WriteLine("			<div class=\"layui-form layui-card-header layuiadmin-card-header-auto\">");
            sw.WriteLine("				<div class=\"layui-form-item\">");
            sw.WriteLine(GetSearchItemList(strTableName));
            sw.WriteLine("					<div class=\"layui-inline\">");
            sw.WriteLine("						<button class=\"layui-btn layuiadmin-btn-list\" lay-submit");
            sw.WriteLine("							lay-filter=\"LAY-app-contlist-search\">");
            sw.WriteLine("							<i class=\"layui-icon layui-icon-search layuiadmin-button-btn\"></i>");
            sw.WriteLine("						</button>");
            sw.WriteLine("					</div>");
            sw.WriteLine("				</div>");
            sw.WriteLine("			</div>");
            sw.WriteLine("");
            sw.WriteLine("			<div class=\"layui-card-body\">");
            sw.WriteLine("				<div style=\"padding-bottom: 10px;\">");
            sw.WriteLine("					<button class=\"layui-btn layuiadmin-btn-list\" data-type=\"batchdel\">删除</button>");
            sw.WriteLine("					<button class=\"layui-btn layuiadmin-btn-list\" data-type=\"add\">添加</button>");
            sw.WriteLine("				</div>");
            sw.WriteLine("				<table id=\"LAY-app-content-list\" lay-filter=\"LAY-app-content-list\"></table>");
            sw.WriteLine("				<script type=\"text/html\" id=\"statusTpl\">");
            sw.WriteLine("          {{#  if(d.status){ }}");
            sw.WriteLine("            <button class=\"layui-btn layui-btn-xs\">已发布</button>");
            sw.WriteLine("          {{#  } else { }}");
            sw.WriteLine("            <button class=\"layui-btn layui-btn-primary layui-btn-xs\">待修改</button>");
            sw.WriteLine("          {{#  } }}");
            sw.WriteLine("        </script>");
            sw.WriteLine("				<script type=\"text/html\" id=\"table-content-list\">");
            sw.WriteLine("          <a class=\"layui-btn layui-btn-primary layui-btn-xs\" lay-event=\"views\">查看</a>");
            sw.WriteLine("          <a class=\"layui-btn layui-btn-normal layui-btn-xs\" lay-event=\"edit\"><i class=\"layui-icon layui-icon-edit\"></i>编辑</a>");
            sw.WriteLine("          <a class=\"layui-btn layui-btn-danger layui-btn-xs\" lay-event=\"del\"><i class=\"layui-icon layui-icon-delete\"></i>删除</a>");
            sw.WriteLine("        </script>");
            sw.WriteLine("			</div>");
            sw.WriteLine("		</div>");
            sw.WriteLine("	</div>");
            sw.WriteLine("");
            sw.WriteLine("	<script th:src=\"@{/layuiadmin/layui/layui.js}\"></script>");
            sw.WriteLine("	<script>");
            sw.WriteLine("  layui.config({");
            sw.WriteLine("      base: '/layuiadmin/' //静态资源所在路径");
            sw.WriteLine("  }).extend({");
            sw.WriteLine("      index: '/lib/index' //主入口模块");
            sw.WriteLine("  }).use(['index', 'table'], function () {");
            sw.WriteLine("      var table = layui.table");
            sw.WriteLine("          , admin = layui.admin");
            sw.WriteLine("          , form = layui.form;");
            sw.WriteLine("");
            sw.WriteLine("      //Ajax加载表格数据");
            sw.WriteLine("      table.render({");
            sw.WriteLine("          elem: \"#LAY-app-content-list\",");
            sw.WriteLine("          url: \"/" + strTableNameLower + "/list\",");
            sw.WriteLine("          toolbar: true,");
            sw.WriteLine("          cols: [");
            sw.WriteLine("              [{");
            sw.WriteLine("                  type: \"checkbox\",");
            sw.WriteLine("                  fixed: \"left\"");
            sw.WriteLine("              },");
            sw.WriteLine(GetTableColsList(strTableName));
            sw.WriteLine("              {");
            sw.WriteLine("                  title: \"操作\",");
            sw.WriteLine("                  minWidth: 200,");
            sw.WriteLine("                  align: \"center\",");
            sw.WriteLine("                  fixed: \"right\",");
            sw.WriteLine("                  toolbar: \"#table-content-list\"");
            sw.WriteLine("              }]");
            sw.WriteLine("          ],");
            sw.WriteLine("          page: !0,");
            sw.WriteLine("          limit: 10,");
            sw.WriteLine("          limits: [10, 15, 20, 25, 30],");
            sw.WriteLine("          text: \"对不起,加载出现异常!\"");
            sw.WriteLine("      }),");
            sw.WriteLine("");
            sw.WriteLine("          //右侧操作事件");
            sw.WriteLine("          table.on(\"tool(LAY-app-content-list)\", function (t) {");
            sw.WriteLine("              var " + strPrimaryKey + " = t.data." + strPrimaryKey + ";");
            sw.WriteLine("              console.log('id=' + " + strPrimaryKey + ");");
            sw.WriteLine("              if (\"del\" === t.event) {");
            sw.WriteLine("                  layer.confirm(\"确定删除此" + strTableComment2 + "?\", function (e) {");
            sw.WriteLine("                      admin.req({              ");
            sw.WriteLine("                          method: 'POST',");
            sw.WriteLine("                          url: '/" + strTableNameLower + "/delete/' + " + strPrimaryKey + "");
            sw.WriteLine("                          , done: function (res) {");
            sw.WriteLine("                              //console.log(res.msg);");
            sw.WriteLine("                              t.del();");
            sw.WriteLine("                              layer.close(e);");
            sw.WriteLine("                          }");
            sw.WriteLine("                      });");
            sw.WriteLine("");
            sw.WriteLine("                  });");
            sw.WriteLine("              }");
            sw.WriteLine("              else if (\"edit\" === t.event) {");
            sw.WriteLine("            	  layer.open({");
            sw.WriteLine("                      type: 2,");
            sw.WriteLine("                      title: '编辑" + strTableComment2 + "',");
            sw.WriteLine("                      content: '/febs/views/" + strTableNameLower + "/edit/'+ " + strPrimaryKey + ",");
            sw.WriteLine("                      maxmin: true,");
            sw.WriteLine("                      area: ['550px', '500px'],");
            sw.WriteLine("                      btn: ['确定', '取消'],");
            sw.WriteLine("                      yes: function(index, layero){");
            sw.WriteLine("                        //点击确认触发 iframe 内容中的按钮提交");
            sw.WriteLine("                        var submit = layero.find('iframe').contents().find(\"#layuiadmin-app-form-submit\");");
            sw.WriteLine("                        submit.click();");
            sw.WriteLine("                      }");
            sw.WriteLine("                    }); ");
            sw.WriteLine("              }");
            sw.WriteLine("              else if (\"views\" === t.event) {");
            sw.WriteLine("            	  layer.open({");
            sw.WriteLine("                      type: 2,");
            sw.WriteLine("                      title: '查看" + strTableComment2 + "',");
            sw.WriteLine("                      content: '/febs/views/" + strTableNameLower + "/details/'+ " + strPrimaryKey + ",");
            sw.WriteLine("                      maxmin: true,");
            sw.WriteLine("                      area: ['550px', '500px'],");
            sw.WriteLine("                      btn: ['确定', '取消'],");
            sw.WriteLine("                      yes: function(index, layero){");
            sw.WriteLine("                        //点击确认触发 iframe 内容中的按钮提交");
            sw.WriteLine("                        var submit = layero.find('iframe').contents().find(\"#layuiadmin-app-form-submit\");");
            sw.WriteLine("                        submit.click();");
            sw.WriteLine("                      }");
            sw.WriteLine("                    }); ");
            sw.WriteLine("              }");
            sw.WriteLine("          }),");
            sw.WriteLine("");
            sw.WriteLine("          //监听搜索");
            sw.WriteLine("          form.on('submit(LAY-app-contlist-search)', function (data) {");
            sw.WriteLine("              var field = data.field;");
            sw.WriteLine("");
            sw.WriteLine("              //执行重载");
            sw.WriteLine("              table.reload('LAY-app-content-list', {");
            sw.WriteLine("                  where: field");
            sw.WriteLine("              });");
            sw.WriteLine("          });");
            sw.WriteLine("");
            sw.WriteLine("      var $ = layui.$, active = {");
            sw.WriteLine("          //批量删除");
            sw.WriteLine("          batchdel: function () {");
            sw.WriteLine("              var checkStatus = table.checkStatus('LAY-app-content-list')");
            sw.WriteLine("                  , checkData = checkStatus.data; //得到选中的数据");
            sw.WriteLine("");
            sw.WriteLine("              if (checkData.length === 0) {");
            sw.WriteLine("                  return layer.msg('请选择数据');");
            sw.WriteLine("              }");
            sw.WriteLine("");
            sw.WriteLine("              //批量删除");
            sw.WriteLine("              layer.confirm('确定删除吗?', function (index) {");
            sw.WriteLine("");
            sw.WriteLine("                  checkData.forEach(function (n, i) {");
            sw.WriteLine("                      console.log(\"" + strPrimaryKey + "=\" + n." + strPrimaryKey + ");");
            sw.WriteLine("                      admin.req({");
            sw.WriteLine("                          method: 'POST',");
            sw.WriteLine("                          url: '/" + strTableNameLower + "/delete/' + n." + strPrimaryKey + "");
            sw.WriteLine("                          , done: function (res) {");
            sw.WriteLine("                              console.log(res.msg);");
            sw.WriteLine("                          }");
            sw.WriteLine("                      });");
            sw.WriteLine("                  });");
            sw.WriteLine("");
            sw.WriteLine("                  table.reload('LAY-app-content-list');");
            sw.WriteLine("                  layer.msg('已删除');");
            sw.WriteLine("              });");
            sw.WriteLine("");
            sw.WriteLine("          },");
            sw.WriteLine("          //新增");
            sw.WriteLine("          add: function(){");
            sw.WriteLine("              layer.open({");
            sw.WriteLine("                type: 2,");
            sw.WriteLine("                title: '新增" + strTableComment2 + "',");
            sw.WriteLine("                content: '/febs/views/" + strTableNameLower + "/create',");
            sw.WriteLine("                maxmin: true,");
            sw.WriteLine("                area: ['550px', '500px'],");
            sw.WriteLine("                btn: ['确定', '取消'],");
            sw.WriteLine("                yes: function(index, layero){");
            sw.WriteLine("                  //点击确认触发 iframe 内容中的按钮提交");
            sw.WriteLine("                  var submit = layero.find('iframe').contents().find(\"#layuiadmin-app-form-submit\");");
            sw.WriteLine("                  submit.click();");
            sw.WriteLine("                }");
            sw.WriteLine("              }); ");
            sw.WriteLine("           }, ");
            sw.WriteLine("      };");
            sw.WriteLine("");
            sw.WriteLine("      $('.layui-btn.layuiadmin-btn-list').on('click', function () {");
            sw.WriteLine("          var type = $(this).data('type');");
            sw.WriteLine("          active[type] ? active[type].call(this) : '';");
            sw.WriteLine("      });");
            sw.WriteLine("");
            sw.WriteLine("  });");
            sw.WriteLine("  </script>");
            sw.WriteLine("");
            sw.WriteLine("</body>");
            sw.WriteLine("</html>");


            sw.Close();
        }
        /// <summary>
        /// 根据表名创建Create新增页面
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateViewMutiCreateClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);//类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            Directory.CreateDirectory(strFilePath);
            //为每个表创建一个独立目录存放
            string strTableNamePath = strFilePath + "\\" + strClassName;

            if (!Directory.Exists(strTableNamePath))
            {
                Directory.CreateDirectory(strTableNamePath);
            }
            StreamWriter sw = new StreamWriter(strTableNamePath + "\\Create.cshtml", false, Encoding.GetEncoding("utf-8"));//生成物理文件
            string       strTableComment2 = CommonHelper.GetColumnKeyComment(strTableComment);

            sw.WriteLine("@{");
            sw.WriteLine("    ViewData[\"Title\"] = \"新增" + strTableComment2 + "\";");
            sw.WriteLine("    Layout = \"~/Views/Shared/_LayoutNone.cshtml\";");
            sw.WriteLine("}");
            sw.WriteLine("<div class=\"layui-form\" lay-filter=\"layuiadmin-app-form-list\" id=\"layuiadmin-app-form-list\" style=\"padding: 20px 30px 0 0;\">");
            sw.WriteLine(GetCreateItemList(strTableName));
            sw.WriteLine("    <div class=\"layui-form-item\">");
            sw.WriteLine("        <label class=\"layui-form-label\"></label>");
            sw.WriteLine("        <div class=\"layui-input-inline\">");
            sw.WriteLine("            <input type=\"hidden\" id=\"created_at\" name=\"created_at\" value=\"@DateTime.Now.ToString()\" />");
            sw.WriteLine("            <input type=\"button\" class=\"layui-btn\" lay-submit lay-filter=\"layuiadmin-app-form-edit\" id=\"layuiadmin-app-form-edit\" value=\"确认提交\">");
            sw.WriteLine("        </div>");
            sw.WriteLine("    </div>");
            sw.WriteLine("</div>");
            sw.WriteLine("");
            sw.WriteLine("<script src=\"~/layuiadmin/layui/layui.js\"></script>");
            sw.WriteLine("<script>");
            sw.WriteLine("    layui.config({");
            sw.WriteLine("        base: '/layuiadmin/' //静态资源所在路径");
            sw.WriteLine("    }).extend({");
            sw.WriteLine("        index: '/lib/index' //主入口模块");
            sw.WriteLine("    }).use(['index', 'layedit', 'form'], function () {");
            sw.WriteLine("        var $ = layui.$");
            sw.WriteLine("            , form = layui.form");
            sw.WriteLine("            , admin = layui.admin");
            sw.WriteLine("            , layedit = layui.layedit;");
            sw.WriteLine("");
            sw.WriteLine("        var index = layedit.build('edit_content', {");
            sw.WriteLine("            height: 300");
            sw.WriteLine("        }); //建立编辑器");
            sw.WriteLine("");
            sw.WriteLine(GetSwitchScript(strTableName));
            sw.WriteLine("");
            if (GetSelectScript(strProjectName, strTableName).Contains("admin.req"))
            {
                sw.WriteLine("        //默认加载");
                sw.WriteLine("        $(function () {");
                sw.WriteLine("            //读取数据加载loading..");
                sw.WriteLine("            loading = layer.load(2, {");
                sw.WriteLine("                shade: [0.2, '#000']");
                sw.WriteLine("            });");
                sw.WriteLine(GetSelectScript(strProjectName, strTableName));
                sw.WriteLine("        });");
                sw.WriteLine("");
            }
            sw.WriteLine("        //监听提交");
            sw.WriteLine("        form.on('submit(layuiadmin-app-form-edit)', function (data) {");
            sw.WriteLine("            //data.field." + GetEditorKey(strTableName) + " = layedit.getContent(index);");
            sw.WriteLine("");
            sw.WriteLine("            loading = layer.load(2, {");
            sw.WriteLine("                shade: [0.2, '#000']");
            sw.WriteLine("            });");
            sw.WriteLine("");
            sw.WriteLine("            //提交数据");
            sw.WriteLine("            admin.req({");
            sw.WriteLine("                headers: {");
            sw.WriteLine("                    'RequestVerificationToken': csrfToken");
            sw.WriteLine("                },");
            sw.WriteLine("                method: 'POST',");
            sw.WriteLine("                url: '/" + strTableNameLower + "/create'");
            sw.WriteLine("                , data: data.field");
            sw.WriteLine("                , done: function (res) {");
            sw.WriteLine("                    layer.close(loading);");
            sw.WriteLine("                    layer.msg(res.msg, {");
            sw.WriteLine("                        offset: '15px'");
            sw.WriteLine("                        , icon: 1");
            sw.WriteLine("                        , time: 1000");
            sw.WriteLine("                    }, function () {");
            sw.WriteLine("                        window.location.reload();");
            sw.WriteLine("                    });");
            sw.WriteLine("                }");
            sw.WriteLine("            });");
            sw.WriteLine("        });");
            sw.WriteLine("    })");
            sw.WriteLine("</script>");
            sw.Close();
        }
Beispiel #20
0
        /// <summary>
        /// 根据SMSHelper类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        public static void CreateSMSClass(string strFilePath, string strProjectName)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            Directory.CreateDirectory(strFilePath);
            StreamWriter sw = new StreamWriter(strFilePath + "\\SMSHelper.cs", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("using System;");
            sw.WriteLine("using System.Text;");
            sw.WriteLine("using System.IO;");
            sw.WriteLine("using System.Net;");
            sw.WriteLine("");
            sw.WriteLine("namespace " + CommonHelper.GetTableNameUpper(strProjectName) + ".SMS");
            sw.WriteLine("{");
            sw.WriteLine("");
            sw.WriteLine("    /// <summary>");
            sw.WriteLine("    /// 版权所有: Copyright © " + DateTime.Now.Year.ToString() + " " + strCompany + ". 保留所有权利。");
            sw.WriteLine("    /// 内容摘要: 短信发送封装类");
            sw.WriteLine("    /// 完成日期:" + DateTime.Now.ToString("yyyy年M月d日"));
            sw.WriteLine("    /// 版    本:V" + strVersion + "." + strCode + " ");
            sw.WriteLine("    /// 作    者:" + strAuthor);
            sw.WriteLine("    /// </summary>");
            sw.WriteLine("    public class SMSHelper");
            sw.WriteLine("    {");
            sw.WriteLine("        public static string strSMSUID = \"\";");
            sw.WriteLine("        public static string strSMSPassword = \"\";");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 注册发送验证码");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"strMobile\">手机号码</param>");
            sw.WriteLine("        /// <param name=\"strCode\">验证码</param>");
            sw.WriteLine("        /// <returns></returns>");
            sw.WriteLine("        public static string SendSMSForCode(string strMobile, string strCode)");
            sw.WriteLine("        {");
            sw.WriteLine("            string strReturnValue = \"\";");
            sw.WriteLine("            ");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                string sendurl = \"http://api.sms.cn/mt/\";");
            sw.WriteLine("                string strContent = \"验证码:\"+ strCode + \"【乐骑】\";");
            sw.WriteLine("                StringBuilder sbTemp = new StringBuilder();");
            sw.WriteLine("                string strPassword = "******".Utility.CommonHelper.MD5(strSMSPassword + strSMSUID);");
            sw.WriteLine("                sbTemp.Append(\"uid=\" + strSMSUID + \"&pwd=\" + strPassword + \"&mobile=\" + strMobile + \"&content=\" + strContent);");
            sw.WriteLine("                byte[] bTemp = System.Text.Encoding.GetEncoding(\"GBK\").GetBytes(sbTemp.ToString());");
            sw.WriteLine("                strReturnValue = doPostRequest(sendurl, bTemp);");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                strReturnValue = ex.Message;");
            sw.WriteLine("            }");
            sw.WriteLine("            ");
            sw.WriteLine("            return strReturnValue;");
            sw.WriteLine("            ");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// Post方式请求,并返回结果");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"url\">URL地址</param>");
            sw.WriteLine("        /// <param name=\"bData\">提交数据</param>");
            sw.WriteLine("        /// <returns>返回结果</returns>");
            sw.WriteLine("        public static string doPostRequest(string url, byte[] bData)");
            sw.WriteLine("        {");
            sw.WriteLine("            HttpWebRequest hwRequest = null;");
            sw.WriteLine("            HttpWebResponse hwResponse = null;");
            sw.WriteLine("            string strResultString = \"\";");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                hwRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);");
            sw.WriteLine("                hwRequest.Timeout = 5000;");
            sw.WriteLine("                hwRequest.Method = \"POST\";");
            sw.WriteLine("                hwRequest.ContentType = \"application/x-www-form-urlencoded\";");
            sw.WriteLine("                hwRequest.ContentLength = bData.Length;");
            sw.WriteLine("                System.IO.Stream smWrite = hwRequest.GetRequestStream();");
            sw.WriteLine("                smWrite.Write(bData, 0, bData.Length);");
            sw.WriteLine("                smWrite.Close();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                " + strProjectName + ".Utility.LogHelper.Error(typeof(SMSHelper), ex, \"Post方式请求,并返回结果\", \"doPostRequest\", true);");
            sw.WriteLine("            }");
            sw.WriteLine("");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                hwResponse = (HttpWebResponse)hwRequest.GetResponse();");
            sw.WriteLine("                StreamReader srReader = new StreamReader(hwResponse.GetResponseStream(), Encoding.ASCII);");
            sw.WriteLine("                strResultString = srReader.ReadToEnd();");
            sw.WriteLine("                srReader.Close();");
            sw.WriteLine("                hwResponse.Close();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                " + strProjectName + ".Utility.LogHelper.Error(typeof(SMSHelper), ex, \"Post方式请求,并返回结果\", \"doPostRequest\", true);");
            sw.WriteLine("            }");
            sw.WriteLine("");
            sw.WriteLine("            return strResultString;");
            sw.WriteLine("        }");
            sw.WriteLine("    }");
            sw.WriteLine("}");
            sw.Close();
        }
Beispiel #21
0
        /// <summary>
        /// 创建数据库连接文件
        /// </summary>
        /// <param name="strFilePath">文件路径</param>
        /// <param name="strProjectName">项目名称</param>
        public static void CreateDBSqlHelperFile(string strFilePath, string strProjectName)
        {
            try
            {
                CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(System.Windows.Forms.Application.StartupPath + "\\config.ini");

                string strGetServer     = iniFile.GetString("BASE", "SERVER", "");      //数据库地址
                string strGetDBName     = iniFile.GetString("BASE", "DBNAME", "");      //数据库名
                string strGetDBUser     = iniFile.GetString("BASE", "USERID", "");      //登录数据库用户名
                string strGetDBPassword = iniFile.GetString("BASE", "PASSWORD", "");    //登录数据库密码
                string strCharset       = iniFile.GetString("BASE", "CHARSET", "");     //数据库字符集
                string strFramework     = iniFile.GetString("BASE", "FRAMEWORK", "");   //.net framework版本号
                string strGUID          = iniFile.GetString("GUID", "DBSQLHELPER", ""); //项目GUID

                //读取版权信息
                string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
                string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
                string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
                string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
                string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

                //strGetServer = CodeRobot.Utility.CryptographyHelper.Decrypt(strGetServer, CodeRobot.Utility.CommonHelper.cryptographyKey);
                //strGetDBName = CodeRobot.Utility.CryptographyHelper.Decrypt(strGetDBName, CodeRobot.Utility.CommonHelper.cryptographyKey);
                //strGetDBUser = CodeRobot.Utility.CryptographyHelper.Decrypt(strGetDBUser, CodeRobot.Utility.CommonHelper.cryptographyKey);
                //strGetDBPassword = CodeRobot.Utility.CryptographyHelper.Decrypt(strGetDBPassword, CodeRobot.Utility.CommonHelper.cryptographyKey);

                Directory.CreateDirectory(strFilePath);

                StreamWriter sw = new StreamWriter(strFilePath + "\\DBMySQLHelper.cs");
                sw.WriteLine("using System;");
                sw.WriteLine("using System.Collections.Generic;");
                //sw.WriteLine("using System.Data;");
                //sw.WriteLine("using MySql.Data.MySqlClient;");
                sw.WriteLine("");
                sw.WriteLine("namespace " + CommonHelper.GetTableNameUpper(strProjectName) + ".DBSqlHelper");
                sw.WriteLine("{");
                sw.WriteLine("");
                sw.WriteLine("    /// <summary>");
                sw.WriteLine("    /// 版权所有: Copyright © " + DateTime.Now.Year.ToString() + " " + strCompany + ". 保留所有权利。");
                sw.WriteLine("    /// 内容摘要: 数据库连接底层封装类");
                sw.WriteLine("    /// 完成日期:" + DateTime.Now.ToString("yyyy年M月d日"));
                sw.WriteLine("    /// 版    本:V" + strVersion + "." + strCode);
                sw.WriteLine("    /// 作    者:" + strAuthor);
                sw.WriteLine("    /// </summary>");
                sw.WriteLine("    public class DBMySQLHelper");
                sw.WriteLine("    {");
                sw.WriteLine("        /// <summary>");
                sw.WriteLine("        /// 连接数据库");
                sw.WriteLine("        /// <summary>");
                sw.WriteLine("        /// <returns>返回数据库连接字符串</returns>");
                sw.WriteLine("        public static string ConnectMySQL()");
                sw.WriteLine("        {");
                sw.WriteLine("            return \"Server=" + strGetServer + "; Database=" + strGetDBName + "; Uid=" + strGetDBUser + "; Pwd=" + strGetDBPassword + "; CharSet=" + strCharset + "\";");
                sw.WriteLine("        }");
                sw.WriteLine("    }");
                sw.WriteLine("}");
                sw.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(ReadmeHelper), ex, "创建数据库连接文件", "CreateDBSqlHelperFile", false);
            }
        }
        /// <summary>
        /// 根据表名创建Index管理页面
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateViewIndexClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);//类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            Directory.CreateDirectory(strFilePath);
            //为每个表创建一个独立目录存放
            string strTableNamePath = strFilePath + "\\" + strClassName;

            if (!Directory.Exists(strTableNamePath))
            {
                Directory.CreateDirectory(strTableNamePath);
            }
            StreamWriter sw = new StreamWriter(strTableNamePath + "\\Index.cshtml", false, Encoding.GetEncoding("utf-8"));//生成物理文件
            string       strTableComment2 = CommonHelper.GetColumnKeyComment(strTableComment);

            sw.WriteLine("@{");
            sw.WriteLine("    ViewData[\"Title\"] = \"" + strTableComment2 + "列表\";");
            sw.WriteLine("    Layout = \"~/Views/Shared/_LayoutNone.cshtml\";");
            sw.WriteLine("}");
            sw.WriteLine("<div class=\"layui-fluid\">");
            sw.WriteLine("    <div class=\"layui-card\">");
            sw.WriteLine("        <div class=\"layui-form layui-card-header layuiadmin-card-header-auto\">");
            sw.WriteLine("            <div class=\"layui-form-item\">");
            sw.WriteLine("                <div class=\"layui-inline\">");
            sw.WriteLine("                    <label class=\"layui-form-label\">选择日期</label>");
            sw.WriteLine("                    <div class=\"layui-input-inline\">");
            sw.WriteLine("                        <input type=\"text\" class=\"layui-input\" id=\"created_at\" name=\"created_at\" placeholder=\"yyyy-MM-dd\">");
            sw.WriteLine("                    </div>");
            sw.WriteLine("                </div>");
            sw.WriteLine(GetSearchItemList(strTableName));
            sw.WriteLine("                <div class=\"layui-inline\">");
            sw.WriteLine("                    <button class=\"layui-btn layuiadmin-btn-list\" lay-submit lay-filter=\"LAY-app-contlist-search\">");
            sw.WriteLine("                        <i class=\"layui-icon layui-icon-search layuiadmin-button-btn\"></i>");
            sw.WriteLine("                    </button>");
            sw.WriteLine("                </div>");
            sw.WriteLine("            </div>");
            sw.WriteLine("        </div>");
            sw.WriteLine("");
            sw.WriteLine("        <div class=\"layui-card-body\">");
            sw.WriteLine("            <div style=\"padding-bottom: 10px;\">");
            sw.WriteLine("                <button class=\"layui-btn layuiadmin-btn-list\" data-type=\"add\">新增</button>");
            sw.WriteLine("                <button class=\"layui-btn layuiadmin-btn-list\" data-type=\"refresh\">刷新</button>");
            sw.WriteLine("            </div>");
            sw.WriteLine("            <table id=\"LAY-app-content-list\" lay-filter=\"LAY-app-content-list\"></table>");
            sw.WriteLine("            <script type=\"text/html\" id=\"table-content-list\">");
            sw.WriteLine("                <a class=\"layui-btn layui-btn-xs\" lay-event=\"edit\"><i class=\"layui-icon layui-icon-edit\"></i>编辑</a>");
            sw.WriteLine("                <a class=\"layui-btn layui-btn-danger layui-btn-xs\" lay-event=\"del\"><i class=\"layui-icon layui-icon-delete\"></i>删除</a>");
            sw.WriteLine("            </script>");
            sw.WriteLine("        </div>");
            sw.WriteLine("    </div>");
            sw.WriteLine("</div>");
            sw.WriteLine("");
            sw.WriteLine("<script src=\"~/layuiadmin/layui/layui.js\"></script>");
            sw.WriteLine("<script>");
            sw.WriteLine("    layui.config({");
            sw.WriteLine("        base: '/layuiadmin/' //静态资源所在路径");
            sw.WriteLine("    }).extend({");
            sw.WriteLine("        index: '/lib/index' //主入口模块");
            sw.WriteLine("    }).use(['index', 'table', 'laydate','util'], function () {");
            sw.WriteLine("        var table = layui.table");
            sw.WriteLine("            , admin = layui.admin");
            sw.WriteLine("            , form = layui.form");
            sw.WriteLine("            , laydate = layui.laydate");
            sw.WriteLine("            , util = layui.util;");
            sw.WriteLine("");
            sw.WriteLine("        laydate.render({");
            sw.WriteLine("            elem: '#created_at'");
            sw.WriteLine("        });");
            sw.WriteLine("");
            sw.WriteLine("        //Ajax加载表格数据");
            sw.WriteLine("        table.render({");
            sw.WriteLine("            elem: \"#LAY-app-content-list\",");
            sw.WriteLine("            url: \"/" + strTableNameLower + "/list\",");
            sw.WriteLine("            cols: [");
            sw.WriteLine("                [");
            sw.WriteLine(GetTableColsList(strTableName));
            sw.WriteLine("                {");
            sw.WriteLine("                    title: \"操作\",");
            sw.WriteLine("                    minWidth: 200,");
            sw.WriteLine("                    align: \"center\",");
            sw.WriteLine("                    fixed: \"right\",");
            sw.WriteLine("                    toolbar: \"#table-content-list\"");
            sw.WriteLine("                }]");
            sw.WriteLine("            ],");
            sw.WriteLine("            page: !0,");
            sw.WriteLine("            limit: 10,");
            sw.WriteLine("            limits: [10, 15, 20, 25, 30]");
            sw.WriteLine("        }),");
            sw.WriteLine("");
            sw.WriteLine("            //右侧操作事件");
            sw.WriteLine("            table.on(\"tool(LAY-app-content-list)\", function (t) {");
            sw.WriteLine("                var " + strPrimaryKey + " = t.data." + strPrimaryKey + ";");
            sw.WriteLine("                console.log('id=' + " + strPrimaryKey + ");");
            sw.WriteLine("                if (\"del\" === t.event) {");
            sw.WriteLine("                    layer.confirm(\"确定删除此" + strTableComment2 + "?\", function (e) {");
            sw.WriteLine("                        admin.req({");
            sw.WriteLine("                            headers: {");
            sw.WriteLine("                                'RequestVerificationToken': csrfToken");
            sw.WriteLine("                            },");
            sw.WriteLine("                            method: 'POST',");
            sw.WriteLine("                            url: '/" + strTableNameLower + "/delete/' + " + strPrimaryKey + "");
            sw.WriteLine("                            , done: function (res) {");
            sw.WriteLine("                                console.log(res.msg);");
            sw.WriteLine("                                t.del();");
            sw.WriteLine("                                layer.close(e);");
            sw.WriteLine("                            }");
            sw.WriteLine("                        });");
            sw.WriteLine("");
            sw.WriteLine("                    });");
            sw.WriteLine("                }");
            sw.WriteLine("                else if (\"edit\" === t.event) {");
            sw.WriteLine("                    layer.open({");
            sw.WriteLine("                        type: 2,");
            sw.WriteLine("                        title: \"编辑" + strTableComment2 + "\",");
            sw.WriteLine("                        content: \"/" + strTableNameLower + "/edit?id=\" + " + strPrimaryKey + ",");
            sw.WriteLine("                        maxmin: !0,");
            sw.WriteLine("                        area: [\"550px\", \"550px\"],");
            sw.WriteLine("                        btn: [\"确定\", \"取消\"],");
            sw.WriteLine("                        yes: function (e, i) {");
            sw.WriteLine("                            a = i.find(\"iframe\").contents().find(\"#layuiadmin-app-form-edit\");");
            sw.WriteLine("                            a.trigger(\"click\");");
            sw.WriteLine("                        }");
            sw.WriteLine("                    })");
            sw.WriteLine("                }");
            sw.WriteLine("            }),");
            sw.WriteLine("");
            sw.WriteLine("            //监听搜索");
            sw.WriteLine("            form.on('submit(LAY-app-contlist-search)', function (data) {");
            sw.WriteLine("                var field = data.field;");
            sw.WriteLine("");
            sw.WriteLine("                //执行重载");
            sw.WriteLine("                table.reload('LAY-app-content-list', {");
            sw.WriteLine("                    where: field");
            sw.WriteLine("                });");
            sw.WriteLine("            });");
            sw.WriteLine("");
            sw.WriteLine("        var $ = layui.$, active = {");
            sw.WriteLine("            add: function () {");
            sw.WriteLine("                layer.open({");
            sw.WriteLine("                    type: 2");
            sw.WriteLine("                    , title: '添加" + strTableComment2 + "'");
            sw.WriteLine("                    ,content: '/" + strTableNameLower + "/create'");
            sw.WriteLine("                    ,maxmin: true");
            sw.WriteLine("                    ,area: ['550px', '550px']");
            sw.WriteLine("                    ,btn: ['确定', '取消']");
            sw.WriteLine("                    ,yes: function(index, layero){");
            sw.WriteLine("                        //点击确认触发 iframe 内容中的按钮提交");
            sw.WriteLine("                        var submit = layero.find('iframe').contents().find(\"#layuiadmin-app-form-submit\");");
            sw.WriteLine("                        submit.click();");
            sw.WriteLine("                    }");
            sw.WriteLine("                });");
            sw.WriteLine("            },");
            sw.WriteLine("            refresh: function () {");
            sw.WriteLine("                table.reload('LAY-app-content-list');");
            sw.WriteLine("            }");
            sw.WriteLine("        };");
            sw.WriteLine("");
            sw.WriteLine("        $('.layui-btn.layuiadmin-btn-list').on('click', function () {");
            sw.WriteLine("            var type = $(this).data('type');");
            sw.WriteLine("            active[type] ? active[type].call(this) : '';");
            sw.WriteLine("        });");
            sw.WriteLine("");
            sw.WriteLine("    });");
            sw.WriteLine("</script>");
            sw.Close();
        }
        /// <summary>
        /// 根据表名创建Mapper类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateMapperClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);                           //类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);                             //News
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            string strNewPath = strFilePath + "\\" + strTableNameLower + "\\mapper";

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

            StreamWriter sw = new StreamWriter(strNewPath + "\\" + strClassName + "Controller.java", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("/*");
            sw.WriteLine(" * Copyright " + DateTime.Now.Year + " Cloudin.");
            sw.WriteLine(" *");
            sw.WriteLine(" * Licensed under the Apache License, Version 2.0 (the \"License\");");
            sw.WriteLine(" * you may not use this file except in compliance with the License.");
            sw.WriteLine(" * You may obtain a copy of the License at");
            sw.WriteLine(" *");
            sw.WriteLine(" *      http://www.apache.org/licenses/LICENSE-2.0");
            sw.WriteLine(" *");
            sw.WriteLine(" * Unless required by applicable law or agreed to in writing, software");
            sw.WriteLine(" * distributed under the License is distributed on an \"AS IS\" BASIS,");
            sw.WriteLine(" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.");
            sw.WriteLine(" * See the License for the specific language governing permissions and");
            sw.WriteLine(" * limitations under the License.");
            sw.WriteLine(" */");
            sw.WriteLine("package cc.mrbird.febs." + strTableNameLower + ".mapper;");
            sw.WriteLine("");
            sw.WriteLine("import org.apache.ibatis.annotations.Param;");
            sw.WriteLine("");
            sw.WriteLine("import com.baomidou.mybatisplus.core.mapper.BaseMapper;");
            sw.WriteLine("import com.baomidou.mybatisplus.core.metadata.IPage;");
            sw.WriteLine("import com.baomidou.mybatisplus.extension.plugins.pagination.Page;");
            sw.WriteLine("");
            sw.WriteLine("import cc.mrbird.febs." + strTableNameLower + ".entity." + strClassName + ";");
            sw.WriteLine("");
            sw.WriteLine("public interface " + strClassName + "Mapper extends BaseMapper<" + strClassName + ">{");
            sw.WriteLine("");
            sw.WriteLine("");
            sw.WriteLine("	/**");
            sw.WriteLine("	* 分页显示数据");
            sw.WriteLine("	* @param page");
            sw.WriteLine("	* @param "+ strTableNameLower + "");
            sw.WriteLine("	* @return");
            sw.WriteLine("	*/");
            sw.WriteLine("	IPage<"+ strClassName + ">");
            sw.WriteLine("		findDetailPage(Page page, @Param(\""+ strTableNameLower + "\") " + strClassName + " " + strTableNameLower + ");");
            sw.WriteLine("");
            sw.WriteLine("}");


            sw.Close();
        }
Beispiel #24
0
        /// <summary>
        /// 根据表名创建Index管理页面
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateViewMutiIndexClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);//类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            Directory.CreateDirectory(strFilePath);
            //为每个表创建一个独立目录存放
            string strTableNamePath = strFilePath + "\\" + strClassName;

            if (!Directory.Exists(strTableNamePath))
            {
                Directory.CreateDirectory(strTableNamePath);
            }
            StreamWriter sw = new StreamWriter(strTableNamePath + "\\Index.cshtml", false, Encoding.GetEncoding("utf-8"));//生成物理文件

            string strTableComment2 = CommonHelper.GetColumnKeyComment(strTableComment);

            sw.WriteLine("@{");
            sw.WriteLine("    ViewData[\"Title\"] = \"" + strTableComment2 + "列表\";");
            sw.WriteLine("    Layout = \"~/Views/Shared/_LayoutNone.cshtml\";");
            sw.WriteLine("}");
            sw.WriteLine("<div class=\"layui-fluid\">");
            sw.WriteLine("    <div class=\"layui-card\">");
            sw.WriteLine("        <div class=\"layui-form layui-card-header layuiadmin-card-header-auto\">");
            sw.WriteLine("            <div class=\"layui-form-item\">");
            sw.WriteLine(GetSearchItemList(strTableName));
            sw.WriteLine("                <div class=\"layui-inline\">");
            sw.WriteLine("                    <button class=\"layui-btn layuiadmin-btn-list\" lay-submit lay-filter=\"LAY-app-contlist-search\">");
            sw.WriteLine("                        <i class=\"layui-icon layui-icon-search layuiadmin-button-btn\"></i>");
            sw.WriteLine("                    </button>");
            sw.WriteLine("                </div>");
            sw.WriteLine("            </div>");
            sw.WriteLine("        </div>");
            sw.WriteLine("");
            sw.WriteLine("        <div class=\"layui-card-body\">");
            sw.WriteLine("            <div style=\"padding-bottom: 10px;\">");
            sw.WriteLine("                <button class=\"layui-btn layuiadmin-btn-list\" data-type=\"batchdel\">删除</button>");
            sw.WriteLine("                <button class=\"layui-btn layuiadmin-btn-list\" data-type=\"add\">新增</button>");
            sw.WriteLine("                <button class=\"layui-btn layuiadmin-btn-list\" data-type=\"refresh\">刷新</button>");
            sw.WriteLine("            </div>");
            sw.WriteLine("            <table id=\"LAY-app-content-list\" lay-filter=\"LAY-app-content-list\"></table>");
            sw.WriteLine("            <script type=\"text/html\" id=\"buttonTpl\">");
            sw.WriteLine("                {{#  if(d.news_status){ }}");
            sw.WriteLine("                <button class=\"layui-btn layui-btn-normal layui-btn-xs\">已发布</button>");
            sw.WriteLine("                {{#  } else { }}");
            sw.WriteLine("                <button class=\"layui-btn layui-btn-primary layui-btn-xs\">未发布</button>");
            sw.WriteLine("                {{#  } }}");
            sw.WriteLine("            </script>");
            sw.WriteLine("            <script type=\"text/html\" id=\"table-content-list\">");
            sw.WriteLine("                <a class=\"layui-btn layui-btn-primary layui-btn-xs\" lay-event=\"views\">查看</a>");
            sw.WriteLine("                <a class=\"layui-btn layui-btn-xs\" lay-event=\"edit\"><i class=\"layui-icon layui-icon-edit\"></i>编辑</a>");
            sw.WriteLine("                <a class=\"layui-btn layui-btn-danger layui-btn-xs\" lay-event=\"del\"><i class=\"layui-icon layui-icon-delete\"></i>删除</a>");
            sw.WriteLine("            </script>");
            sw.WriteLine("        </div>");
            sw.WriteLine("    </div>");
            sw.WriteLine("</div>");
            sw.WriteLine("");
            sw.WriteLine("<script src=\"~/layuiadmin/layui/layui.js\"></script>");
            sw.WriteLine("<script>");
            sw.WriteLine("    layui.config({");
            sw.WriteLine("        base: '/layuiadmin/' //静态资源所在路径");
            sw.WriteLine("    }).extend({");
            sw.WriteLine("        index: '/lib/index' //主入口模块");
            sw.WriteLine("    }).use(['index', 'table'], function () {");
            sw.WriteLine("        var table = layui.table");
            sw.WriteLine("            , admin = layui.admin");
            sw.WriteLine("            , form = layui.form;");
            sw.WriteLine("");
            sw.WriteLine("        //Ajax加载表格数据");
            sw.WriteLine("        table.render({");
            sw.WriteLine("            elem: \"#LAY-app-content-list\",");
            sw.WriteLine("            url: \"/" + strTableNameLower + "/list\",");
            sw.WriteLine("            cols: [");
            sw.WriteLine("                [{");
            sw.WriteLine("                    type: \"checkbox\",");
            sw.WriteLine("                    fixed: \"left\"");
            sw.WriteLine("                },");
            sw.WriteLine(GetTableColsList(strTableName));
            sw.WriteLine("                {");
            sw.WriteLine("                    title: \"操作\",");
            sw.WriteLine("                    minWidth: 200,");
            sw.WriteLine("                    align: \"center\",");
            sw.WriteLine("                    fixed: \"right\",");
            sw.WriteLine("                    toolbar: \"#table-content-list\"");
            sw.WriteLine("                }]");
            sw.WriteLine("            ],");
            sw.WriteLine("            page: !0,");
            sw.WriteLine("            limit: 10,");
            sw.WriteLine("            limits: [10, 15, 20, 25, 30]");
            sw.WriteLine("        }),");
            sw.WriteLine("");
            sw.WriteLine("            //右侧操作事件");
            sw.WriteLine("            table.on(\"tool(LAY-app-content-list)\", function (t) {");
            sw.WriteLine("                var " + strPrimaryKey + " = t.data." + strPrimaryKey + ";");
            sw.WriteLine("                console.log('id=' + " + strPrimaryKey + ");");
            sw.WriteLine("                if (\"del\" === t.event) {");
            sw.WriteLine("                    layer.confirm(\"确定删除此" + strTableComment2 + "?\", function (e) {");
            sw.WriteLine("                        admin.req({");
            sw.WriteLine("                            headers: {");
            sw.WriteLine("                                'RequestVerificationToken': csrfToken");
            sw.WriteLine("                            },");
            sw.WriteLine("                            method: 'POST',");
            sw.WriteLine("                            url: '/" + strTableNameLower + "/delete/' + " + strPrimaryKey + "");
            sw.WriteLine("                            , done: function (res) {");
            sw.WriteLine("                                console.log(res.msg);");
            sw.WriteLine("                                t.del();");
            sw.WriteLine("                                layer.close(e);");
            sw.WriteLine("                            }");
            sw.WriteLine("                        });");
            sw.WriteLine("");
            sw.WriteLine("                    });");
            sw.WriteLine("                }");
            sw.WriteLine("                else if (\"edit\" === t.event) {");
            sw.WriteLine("                    parent.layui.index.openTabsPage('/" + strTableNameLower + "/edit/?id=' + " + strPrimaryKey + ", '编辑" + strTableComment2 + "');");
            sw.WriteLine("                }");
            sw.WriteLine("                else if (\"views\" === t.event) {");
            sw.WriteLine("                    parent.layui.index.openTabsPage('/" + strTableNameLower + "/views/?id=' + " + strPrimaryKey + ", '" + strTableComment2 + "详情');");
            sw.WriteLine("                }");
            sw.WriteLine("            }),");
            sw.WriteLine("");
            sw.WriteLine("            //监听搜索");
            sw.WriteLine("            form.on('submit(LAY-app-contlist-search)', function (data) {");
            sw.WriteLine("                var field = data.field;");
            sw.WriteLine("");
            sw.WriteLine("                //执行重载");
            sw.WriteLine("                table.reload('LAY-app-content-list', {");
            sw.WriteLine("                    where: field");
            sw.WriteLine("                });");
            sw.WriteLine("            });");
            sw.WriteLine("");
            sw.WriteLine("        var $ = layui.$, active = {");
            sw.WriteLine("            batchdel: function () {");
            sw.WriteLine("                var checkStatus = table.checkStatus('LAY-app-content-list')");
            sw.WriteLine("                    , checkData = checkStatus.data; //得到选中的数据");
            sw.WriteLine("");
            sw.WriteLine("                if (checkData.length === 0) {");
            sw.WriteLine("                    return layer.msg('请选择数据');");
            sw.WriteLine("                }");
            sw.WriteLine("");
            sw.WriteLine("                //批量删除");
            sw.WriteLine("                layer.confirm('确定删除吗?', function (index) {");
            sw.WriteLine("");
            sw.WriteLine("                    checkData.forEach(function (n, i) {");
            sw.WriteLine("                        console.log(\"" + strPrimaryKey + "=\" + n." + strPrimaryKey + ");");
            sw.WriteLine("                        admin.req({");
            sw.WriteLine("                            headers: {");
            sw.WriteLine("                                'RequestVerificationToken': csrfToken");
            sw.WriteLine("                            },");
            sw.WriteLine("                            method: 'POST',");
            sw.WriteLine("                            url: '/" + strTableNameLower + "/delete/' + n." + strPrimaryKey + "");
            sw.WriteLine("                            , done: function (res) {");
            sw.WriteLine("                                console.log(res.msg);");
            sw.WriteLine("                            }");
            sw.WriteLine("                        });");
            sw.WriteLine("                    });");
            sw.WriteLine("");
            sw.WriteLine("                    //table.reload('LAY-app-content-list');");
            sw.WriteLine("                    layer.msg('已删除');");
            sw.WriteLine("                });");
            sw.WriteLine("");
            sw.WriteLine("            },");
            sw.WriteLine("            add: function () {");
            sw.WriteLine("                parent.layui.index.openTabsPage('/" + strTableNameLower + "/create', '新增" + strTableComment2 + "');");
            sw.WriteLine("            },");
            sw.WriteLine("            refresh: function () {");
            sw.WriteLine("                table.reload('LAY-app-content-list');");
            sw.WriteLine("            }");
            sw.WriteLine("        };");
            sw.WriteLine("");
            sw.WriteLine("        $('.layui-btn.layuiadmin-btn-list').on('click', function () {");
            sw.WriteLine("            var type = $(this).data('type');");
            sw.WriteLine("            active[type] ? active[type].call(this) : '';");
            sw.WriteLine("        });");
            sw.WriteLine("");
            sw.WriteLine("    });");
            sw.WriteLine("</script>");
            sw.Close();
        }
Beispiel #25
0
        /// <summary>
        /// 创建项目解决方案
        /// </summary>
        /// <param name="strFilePath">项目路径</param>
        /// <param name="strProjectName">项目名称</param>
        public static void CreateSolutionSystemFile(string strFilePath, string strProjectName)
        {
            try
            {
                CodeRobot.Utility.IniFile iniFile    = new Utility.IniFile(System.Windows.Forms.Application.StartupPath + "\\config.ini");
                string strVisualStudio               = iniFile.GetString("BASE", "VS", "");
                string strVisualStudioVersion        = iniFile.GetString("BASE", "VS_VERSION", "");
                string strMinimumVisualStudioVersion = iniFile.GetString("BASE", "MINI_VS_VERSION", "");
                string strNetFramework               = iniFile.GetString("BASE", "FRAMEWORK", "");//.net framework版本号
                string strGUIDSolutionFramework      = iniFile.GetString("GUID", "SOLUTION_FRAMEWORK", "").ToUpper();
                string strGUIDSolutionWeb            = iniFile.GetString("GUID", "SOLUTION_WEB", "").ToUpper();
                string strGUIDDBSqlHelper            = iniFile.GetString("GUID", "DBSQLHELPER", "").ToUpper();
                string strGUIDModel     = iniFile.GetString("GUID", "MODEL", "").ToUpper();
                string strGUIDDAL       = iniFile.GetString("GUID", "DAL", "").ToUpper();
                string strGUIDBLL       = iniFile.GetString("GUID", "BLL", "").ToUpper();
                string strGUIDUtility   = iniFile.GetString("GUID", "UTILITY", "").ToUpper();
                string strGUIDSMS       = iniFile.GetString("GUID", "SMS", "").ToUpper();
                string strGUIDPush      = iniFile.GetString("GUID", "PUSH", "").ToUpper();
                string strGUIDPay       = iniFile.GetString("GUID", "PAY", "").ToUpper();
                string strGUIDUI        = iniFile.GetString("GUID", "UI", "").ToUpper();
                string strGUIDHTML      = iniFile.GetString("GUID", "HTML", "").ToUpper();
                string strGUIDPM        = iniFile.GetString("GUID", "PM", "").ToUpper();
                string strGUIDTest      = iniFile.GetString("GUID", "TEST", "").ToUpper();
                string strGUIDData      = iniFile.GetString("GUID", "DATA", "").ToUpper();
                string strGUIDH5        = iniFile.GetString("GUID", "H5", "").ToUpper();
                string strGUIDManage    = iniFile.GetString("GUID", "MANAGE", "").ToUpper();
                string strGUIDWeb       = iniFile.GetString("GUID", "WEB", "").ToUpper();
                string strGUIDWeChatApp = iniFile.GetString("GUID", "WeChatApp", "").ToUpper();

                //创建WEB项目浏览虚拟端口
                int nUIPort        = int.Parse(CodeRobot.Utility.CommonHelper.GenerateRandomNum(5));
                int nHTMLPort      = nUIPort + 1;
                int nPMPort        = nHTMLPort + 1;
                int nTestPort      = nPMPort + 1;
                int nDataPort      = nTestPort + 1;
                int nH5Port        = nDataPort + 1;
                int nManagePort    = nH5Port + 1;
                int nWebPort       = nManagePort + 1;
                int nWeChatAppPort = nWebPort + 1;

                Directory.CreateDirectory(strFilePath);

                //创建项目文件-------------------------------------------1
                FileStream   fs1 = new FileStream(Application.StartupPath + "\\template\\system\\Solution.html", FileMode.OpenOrCreate, FileAccess.Read);
                StreamReader sr1 = new StreamReader(fs1, Encoding.UTF8);
                string       strGetPageHTMLContentForSolution = sr1.ReadToEnd();
                sr1.Close();
                fs1.Close();

                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_SOLUTION_FRAMEWORK", strGUIDSolutionFramework);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_SOLUTION_WEB", strGUIDSolutionWeb);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{project_name}", strProjectName);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_DBSQLHELPER", strGUIDDBSqlHelper);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_MODEL", strGUIDModel);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_DAL", strGUIDDAL);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_BLL", strGUIDBLL);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_UTILITY", strGUIDUtility);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_SMS", strGUIDSMS);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_UI", strGUIDUI);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_HTML", strGUIDHTML);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_PM", strGUIDPM);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_TEST", strGUIDTest);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_H5", strGUIDH5);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_MANAGE", strGUIDManage);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_DATA", strGUIDData);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_WEB", strGUIDWeb);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("GUID_WeChatApp", strGUIDWeChatApp);

                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{UI_PORT}", nUIPort.ToString());
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{HTML_PORT}", nHTMLPort.ToString());
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{PM_PORT}", nPMPort.ToString());
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{TEST_PORT}", nTestPort.ToString());
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{DATA_PORT}", nDataPort.ToString());
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{H5_PORT}", nH5Port.ToString());
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{MANAGE_PORT}", nManagePort.ToString());
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{WEB_PORT}", nWebPort.ToString());
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{WeChatApp_PORT}", nWeChatAppPort.ToString());

                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{VS}", strVisualStudio);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{VS_VERSION}", strVisualStudioVersion);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{MINI_VS_VERSION}", strMinimumVisualStudioVersion);
                strGetPageHTMLContentForSolution = strGetPageHTMLContentForSolution.Replace("{NET_FRAMEWORK}", strNetFramework);

                StreamWriter sw1 = new StreamWriter(strFilePath + "\\" + strProjectName + "Solution.sln", false, Encoding.GetEncoding("utf-8"));
                sw1.WriteLine(strGetPageHTMLContentForSolution);
                sw1.Close();
            }
            catch (Exception ex)
            {
                CodeRobot.Utility.LogHelper.Error(typeof(ReadmeHelper), ex, "创建项目解决方案", "CreateSolutionSystemFile", false);
            }
        }
Beispiel #26
0
        /// <summary>
        /// 根据表名创建Controllers类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateControllersClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);//类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            Directory.CreateDirectory(strFilePath);
            StreamWriter sw = new StreamWriter(strFilePath + "\\" + strClassName + "Controller.cs", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("using System;");
            sw.WriteLine("using System.Linq;");
            sw.WriteLine("using System.Threading.Tasks;");
            sw.WriteLine("using Microsoft.AspNetCore.Mvc;");
            sw.WriteLine("using Microsoft.EntityFrameworkCore;");
            sw.WriteLine("using log4net;");
            sw.WriteLine("using System.Collections.Generic;");
            sw.WriteLine("using " + strProjectName + ".Manage.Data;");
            sw.WriteLine("using " + strProjectName + ".Models;");
            sw.WriteLine("");
            sw.WriteLine("namespace " + strProjectName + ".Manage.Controllers");
            sw.WriteLine("{");
            sw.WriteLine("");
            sw.WriteLine("    /// <summary>");
            sw.WriteLine("    /// 版权所有: Copyright © " + DateTime.Now.Year.ToString() + " " + strCompany + ". 保留所有权利。");
            sw.WriteLine("    /// 内容摘要: " + strClassName + " 处理请求的类");
            sw.WriteLine("    /// 创建日期:" + Convert.ToDateTime(strCreateDate).ToString("yyyy年M月d日"));
            sw.WriteLine("    /// 更新日期:" + DateTime.Now.ToString("yyyy年M月d日"));
            sw.WriteLine("    /// 版    本:V" + strVersion + "." + strCode + " ");
            sw.WriteLine("    /// 作    者:" + strAuthor);
            sw.WriteLine("    /// </summary>");
            sw.WriteLine("    public class " + strClassName + "Controller : Controller");
            sw.WriteLine("    {");
            sw.WriteLine("        private readonly " + strProjectName + "ManageContext _context;");
            sw.WriteLine("        private readonly ILog log;");
            sw.WriteLine("");
            sw.WriteLine("        // " + strTableComment + " 实例化数据上下文");
            sw.WriteLine("        public " + strClassName + "Controller(" + strProjectName + "ManageContext context)");
            sw.WriteLine("        {");
            sw.WriteLine("            _context = context;");
            sw.WriteLine("            this.log = LogManager.GetLogger(Startup.repository.Name, typeof(" + strClassName + "Controller));");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        // GET: /<controller>/ Index.cshtml");
            sw.WriteLine("        public IActionResult Index()");
            sw.WriteLine("        {");
            sw.WriteLine("            return View();");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        // GET: /<controller>/ Create.cshtml");
            sw.WriteLine("        public IActionResult Create()");
            sw.WriteLine("        {");
            sw.WriteLine("            return View();");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        // GET: /<controller>/ Edit.cshtml");
            sw.WriteLine("        public IActionResult Edit()");
            sw.WriteLine("        {");
            sw.WriteLine("            return View();");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        // GET: /<controller>/ Views.cshtml");
            sw.WriteLine("        public IActionResult Views()");
            sw.WriteLine("        {");
            sw.WriteLine("            return View();");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        // GET: " + strTableNameLower + "/lists/?page=1&limit=10");
            sw.WriteLine("        public async Task<IActionResult> List(int page, int limit)");
            sw.WriteLine("        {");
            sw.WriteLine("            var list = new List<" + strClassName + ">();");
            sw.WriteLine("            long lCount = 0;");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("               var result = _context." + strTableName + ".Where(n => n." + strPrimaryKey + " > 0);");
            sw.WriteLine("               //if (!string.IsNullOrEmpty(news_title))");
            sw.WriteLine("                   //result = result.Where(n => n.news_title.Contains(news_title));");
            sw.WriteLine("");
            sw.WriteLine("               list = await result.OrderByDescending(n => n." + strPrimaryKey + ").Skip((page - 1) * limit).Take(limit).ToListAsync();");
            sw.WriteLine("               lCount = result.LongCount();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> List\", ex);");
            sw.WriteLine("            }");
            sw.WriteLine("");
            sw.WriteLine("            return Json(new { code = 0, msg = \"success\", data = list, count = lCount });");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("");
            sw.WriteLine("        // GET: " + strTableNameLower + "/select");
            sw.WriteLine("        public async Task<IActionResult> Select()");
            sw.WriteLine("        {");
            sw.WriteLine("            var list = new List<" + strClassName + ">();");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("               var result = _context." + strTableName + ".Where(n => n." + strPrimaryKey + " > 0);");
            sw.WriteLine("");
            sw.WriteLine("               list = await result.OrderByDescending(n => n." + strPrimaryKey + ").ToListAsync();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> Select\", ex);");
            sw.WriteLine("            }");
            sw.WriteLine("");
            sw.WriteLine("            return Json(new { code = 0, msg = \"success\", data = list });");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        // GET: " + strTableNameLower + "/details/1");
            if (CommonHelper.ChecktKeyIsBigint(strTableName, strPrimaryKey))
            {
                sw.WriteLine("        public async Task<IActionResult> Details(long? id)");
            }
            else
            {
                sw.WriteLine("        public async Task<IActionResult> Details(int? id)");
            }

            sw.WriteLine("        {");
            sw.WriteLine("            var " + strTableNameSpec + " = new " + strClassName + "();");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("               //log.Debug(\"id=\"+id);");
            sw.WriteLine("               if (id == null)");
            sw.WriteLine("               {");
            sw.WriteLine("                   return Json(new { code = 1, msg = \"获取数据失败\" });");
            sw.WriteLine("               }");
            sw.WriteLine("");
            sw.WriteLine("               " + strTableNameSpec + " = await _context." + strTableName + "");
            sw.WriteLine("                   .FirstOrDefaultAsync(m => m." + strPrimaryKey + " == id);");
            sw.WriteLine("               if (" + strTableNameSpec + " == null)");
            sw.WriteLine("               {");
            sw.WriteLine("                   return Json(new { code = 1, msg = \"获取数据失败\" });");
            sw.WriteLine("               }");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> Details\", ex);");
            sw.WriteLine("            }");
            sw.WriteLine("");
            sw.WriteLine("            return Json(new { code = 0, msg = \"获取数据成功\", data = " + strTableNameSpec + "});");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        // POST: " + strTableNameLower + "/create");
            sw.WriteLine("        [HttpPost]");
            sw.WriteLine("        [ValidateAntiForgeryToken]");
            sw.WriteLine("        public async Task<IActionResult> Create([Bind(\"" + strAllColumnNameNotKey + "\")] " + strClassName + " " + strTableNameSpec + ")");
            sw.WriteLine("        {");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                //log.Debug(" + CommonHelper.GetSaveLogColumnName(strTableName, strTableNameSpec) + ");");
            if (CommonHelper.ChecktCreatedAtKey(strTableName, "created_at"))
            {
                sw.WriteLine("                " + strTableNameSpec + ".created_at = DateTime.Now;");
            }

            sw.WriteLine("                _context.Add(" + strTableNameSpec + ");");
            sw.WriteLine("                await _context.SaveChangesAsync();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> Create\", ex);");
            sw.WriteLine("            }");
            sw.WriteLine("");
            sw.WriteLine("            return Json(new { code = 0, msg = \"添加成功\" });");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        // POST: " + strTableNameLower + "/edit/1");
            sw.WriteLine("        [HttpPost]");
            sw.WriteLine("        [Route(\"/api/" + strTableNameLower + "/update/{id}\")]");
            sw.WriteLine("        [ValidateAntiForgeryToken]");
            if (CommonHelper.ChecktKeyIsBigint(strTableName, strPrimaryKey))
            {
                sw.WriteLine("        public async Task<IActionResult> Edit(long id, [Bind(\"" + strAllColumnName + "\")] " + strClassName + " " + strTableNameSpec + ")");
            }
            else
            {
                sw.WriteLine("        public async Task<IActionResult> Edit(int id, [Bind(\"" + strAllColumnName + "\")] " + strClassName + " " + strTableNameSpec + ")");
            }

            sw.WriteLine("        {");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                //log.Debug(" + CommonHelper.GetSaveLogColumnName(strTableName, strTableNameSpec) + ");");
            sw.WriteLine("                if (id != " + strTableNameSpec + "." + strPrimaryKey + ")");
            sw.WriteLine("                {");
            sw.WriteLine("                    return Json(new { code = 0, msg = \"ID不存在\" });");
            sw.WriteLine("                }");
            sw.WriteLine("");
            sw.WriteLine("                try");
            sw.WriteLine("                {");
            sw.WriteLine("                    _context.Update(" + strTableNameSpec + ");");
            sw.WriteLine("                    await _context.SaveChangesAsync();");
            sw.WriteLine("                }");
            sw.WriteLine("                catch (DbUpdateConcurrencyException)");
            sw.WriteLine("                {");
            sw.WriteLine("                    if (!" + strClassName + "Exists(" + strTableNameSpec + "." + strPrimaryKey + "))");
            sw.WriteLine("                    {");
            sw.WriteLine("                        return Json(new { code = 0, msg = \"更新失败\" });");
            sw.WriteLine("                    }");
            sw.WriteLine("                    else");
            sw.WriteLine("                    {");
            sw.WriteLine("                        throw;");
            sw.WriteLine("                    }");
            sw.WriteLine("                }");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> Edit\", ex);");
            sw.WriteLine("            }");
            sw.WriteLine("");
            sw.WriteLine("            return Json(new { code = 0, msg = \"更新成功\" });");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        // POST: " + strTableNameLower + "/delete/1");
            sw.WriteLine("        [HttpPost]");
            sw.WriteLine("        [Route(\"/api/" + strTableNameLower + "/del/{id}\")]");
            sw.WriteLine("        [ValidateAntiForgeryToken]");
            if (CommonHelper.ChecktKeyIsBigint(strTableName, strPrimaryKey))
            {
                sw.WriteLine("        public async Task<IActionResult> Delete(long id)");
            }
            else
            {
                sw.WriteLine("        public async Task<IActionResult> Delete(int id)");
            }
            sw.WriteLine("        {");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                var " + strTableNameSpec + " = await _context." + strTableName + ".FirstOrDefaultAsync(c => c." + strPrimaryKey + " == id);");
            sw.WriteLine("                _context." + strTableName + ".Remove(" + strTableNameSpec + ");");
            sw.WriteLine("                await _context.SaveChangesAsync();");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> Delete\", ex);");
            sw.WriteLine("            }");
            sw.WriteLine("");
            sw.WriteLine("            return Json(new { code = 0, msg = \"删除成功\" });");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        // 检测id是否存在");
            if (CommonHelper.ChecktKeyIsBigint(strTableName, strPrimaryKey))
            {
                sw.WriteLine("        private bool " + strClassName + "Exists(long id)");
            }
            else
            {
                sw.WriteLine("        private bool " + strClassName + "Exists(int id)");
            }
            sw.WriteLine("        {");
            sw.WriteLine("            return _context." + strTableName + ".Any(e => e." + strPrimaryKey + " == id);");
            sw.WriteLine("        }");
            sw.WriteLine("    }");
            sw.WriteLine("}");
            sw.Close();
        }
Beispiel #27
0
        /// <summary>
        /// 根据表名创建Edit编辑页面
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateViewEditClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);//类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            Directory.CreateDirectory(strFilePath);
            //为每个表创建一个独立目录存放
            string strTableNamePath = strFilePath + "\\" + strClassName;

            if (!Directory.Exists(strTableNamePath))
            {
                Directory.CreateDirectory(strTableNamePath);
            }
            StreamWriter sw = new StreamWriter(strTableNamePath + "\\Edit.cshtml", false, Encoding.GetEncoding("utf-8"));//生成物理文件
            string       strTableComment2 = CommonHelper.GetColumnKeyComment(strTableComment);

            sw.WriteLine("@{");
            sw.WriteLine("    ViewData[\"Title\"] = \"编辑" + strTableComment2 + "\";");
            sw.WriteLine("    Layout = \"~/Views/Shared/_LayoutNone.cshtml\";");
            sw.WriteLine("}");
            sw.WriteLine("<div class=\"layui-form\" lay-filter=\"layuiadmin-app-form-list\" id=\"layuiadmin-app-form-list\" style=\"padding: 20px 30px 0 0;\">");
            sw.WriteLine(GetEditItemList(strTableName));
            sw.WriteLine("    <div class=\"layui-form-item layui-hide\">");
            sw.WriteLine("        <input type=\"hidden\" id=\"created_at\" name=\"created_at\" value=\"@DateTime.Now.ToString()\" />");
            sw.WriteLine("        <input type=\"hidden\" id=\"" + strPrimaryKey + "\" name=\"" + strPrimaryKey + "\" value=\"@ViewContext.HttpContext.Request.Query[\"id\"]\" />");
            sw.WriteLine("        <input type=\"button\" lay-submit lay-filter=\"layuiadmin-app-form-submit\" id=\"layuiadmin-app-form-submit\" value=\"确认添加\">");
            sw.WriteLine("        <input type=\"button\" lay-submit lay-filter=\"layuiadmin-app-form-edit\" id=\"layuiadmin-app-form-edit\" value=\"确认编辑\">");
            sw.WriteLine("    </div>");
            sw.WriteLine("");
            sw.WriteLine("</div>");
            sw.WriteLine("");
            sw.WriteLine("<script src=\"~/layuiadmin/layui/layui.js\"></script>");
            sw.WriteLine("<script>");
            sw.WriteLine("    layui.config({");
            sw.WriteLine("        base: '/layuiadmin/' //静态资源所在路径");
            sw.WriteLine("    }).extend({");
            sw.WriteLine("        index: '/lib/index' //主入口模块");
            sw.WriteLine("    }).use(['index', 'laydate', 'form'], function () {");
            sw.WriteLine("        var $ = layui.$");
            sw.WriteLine("            , form = layui.form");
            sw.WriteLine("            , admin = layui.admin");
            sw.WriteLine("            , laydate = layui.laydate;");
            sw.WriteLine("");
            sw.WriteLine(GetSwitchScript(strTableName));
            sw.WriteLine("");
            sw.WriteLine("        //默认加载");
            sw.WriteLine("        $(function () {");
            sw.WriteLine("            var " + strPrimaryKey + " = $(\"#" + strPrimaryKey + "\").val();");
            sw.WriteLine("");
            sw.WriteLine("            //读取数据加载loading..");
            sw.WriteLine("            loading = layer.load(2, {");
            sw.WriteLine("                shade: [0.2, '#000']");
            sw.WriteLine("            });");
            sw.WriteLine("");
            sw.WriteLine("            admin.req({");
            sw.WriteLine("                url: '/" + strTableNameLower + "/details'");
            sw.WriteLine("                , data: { id: " + strPrimaryKey + " }");
            sw.WriteLine("                , done: function (res) {");
            sw.WriteLine("                    layer.close(loading);");
            sw.WriteLine("                    console.log(res.data);");
            sw.WriteLine(GetEditItemValueList(strTableName));
            sw.WriteLine("                    //if (!res.data." + GetSwitchStatusKey(strTableName) + ") {");
            sw.WriteLine("                        //$(\".layui-unselect\").removeClass(\"layui-form-onswitch\");");
            sw.WriteLine("                        //$(\"#switch_" + GetSwitchStatusKey(strTableName) + "\").removeAttr(\"checked\");");
            sw.WriteLine("                        //$(\".layui-unselect>em\").html(\"禁用\");");
            sw.WriteLine("                    //}");
            sw.WriteLine("");
            sw.WriteLine(GetSelectScript(strProjectName, strTableName));
            sw.WriteLine("");
            sw.WriteLine("                }");
            sw.WriteLine("            });");
            sw.WriteLine("");
            sw.WriteLine("        });");
            sw.WriteLine("");
            sw.WriteLine("        //监听提交");
            sw.WriteLine("        form.on('submit(layuiadmin-app-form-edit)', function (data) {");
            sw.WriteLine("            var field = data.field; //获取提交的字段");
            sw.WriteLine("            var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引");
            sw.WriteLine("");
            sw.WriteLine("            //提交 Ajax 成功后,关闭当前弹层并重载表格");
            sw.WriteLine("            loading = layer.load(2, {");
            sw.WriteLine("                shade: [0.2, '#000']");
            sw.WriteLine("            });");
            sw.WriteLine("            console.log('data=' + data.field." + strPrimaryKey + ");");
            sw.WriteLine("            //提交数据");
            sw.WriteLine("            admin.req({");
            sw.WriteLine("                headers: {");
            sw.WriteLine("                    'RequestVerificationToken': csrfToken");
            sw.WriteLine("                },");
            sw.WriteLine("                method: 'POST',");
            sw.WriteLine("                url: '/" + strTableNameLower + "/edit?id=' + data.field." + strPrimaryKey + "");
            sw.WriteLine("                , data: data.field");
            sw.WriteLine("                , done: function (res) {");
            sw.WriteLine("                    layer.close(loading);");
            sw.WriteLine("                    parent.layui.table.reload('LAY-app-content-list'); //重载表格");
            sw.WriteLine("                    layer.msg(res.msg, {");
            sw.WriteLine("                        offset: '15px'");
            sw.WriteLine("                        , icon: 1");
            sw.WriteLine("                        , time: 1000");
            sw.WriteLine("                    }, function () {");
            sw.WriteLine("                        parent.layer.close(index); //再执行关闭");
            sw.WriteLine("                    });");
            sw.WriteLine("                }");
            sw.WriteLine("            });");
            sw.WriteLine("");
            sw.WriteLine("        });");
            sw.WriteLine("");
            sw.WriteLine("");
            sw.WriteLine("    })");
            sw.WriteLine("</script>");

            sw.Close();
        }
        /// <summary>
        /// 根据表名创建Controllers类
        /// </summary>
        /// <param name="strFilePath">保存路径</param>
        /// <param name="strProjectName">项目名</param>
        /// <param name="strTableName">表名</param>
        public static void CreateControllersClass(string strFilePath, string strProjectName, string strTableName, string strTableComment)
        {
            //读取版权信息
            CodeRobot.Utility.IniFile iniFile = new Utility.IniFile(Application.StartupPath + "\\config.ini");
            string strCompany    = iniFile.GetString("COPYRIGHT", "COMPANY", "");
            string strAuthor     = iniFile.GetString("COPYRIGHT", "AUTHOR", "");
            string strVersion    = iniFile.GetString("COPYRIGHT", "VERSION", "");
            string strCode       = iniFile.GetString("COPYRIGHT", "CODE", "");
            string strCreateDate = iniFile.GetString("BASE", "CREATE_DATE", "");

            string strTableNameUpper = CommonHelper.GetTableNameUpper(strTableName);

            string strPrimaryKey = CommonHelper.GetPrimaryKey(strTableName);//如:news_id

            string strAllColumnName       = CommonHelper.GetAllColumnName(strTableName);
            string strAllColumnNameNotKey = CommonHelper.GetAllColumnNameNotKey(strTableName);

            string strClassName = CommonHelper.GetClassName(strTableName);//类名

            strClassName = CommonHelper.GetTableNameUpper(strClassName);
            string strTableNameSpec  = CommonHelper.GetTableNameFirstLowerSecondUpper(strClassName); //如:newsTypes
            string strTableNameLower = strTableNameSpec.ToLower();                                   //如:newstypes

            Directory.CreateDirectory(strFilePath);
            StreamWriter sw = new StreamWriter(strFilePath + "\\" + strClassName + "Controller.cs", false, Encoding.GetEncoding("utf-8"));

            sw.WriteLine("using Microsoft.AspNetCore.Http;");
            sw.WriteLine("using Microsoft.AspNetCore.Mvc;");
            sw.WriteLine("using System.Collections.Generic;");
            sw.WriteLine("using System.Linq;");
            sw.WriteLine("using Microsoft.EntityFrameworkCore;");
            sw.WriteLine("using " + strProjectName + ".API.Data;");
            sw.WriteLine("using " + strProjectName + ".Models;");
            sw.WriteLine("using System;");
            sw.WriteLine("using log4net;");
            sw.WriteLine("using System.Threading.Tasks;");
            sw.WriteLine("");
            sw.WriteLine("namespace " + strProjectName + ".API.Controllers");
            sw.WriteLine("{");
            sw.WriteLine("    /// <summary>");
            sw.WriteLine("    /// " + strTableComment + "类,定义了CURD相关操作");
            sw.WriteLine("    /// </summary>");
            sw.WriteLine("    [Produces(\"application/json\")]");
            sw.WriteLine("    [Route(\"api/[controller]\")]");
            sw.WriteLine("    [ApiController]");
            sw.WriteLine("    public class " + strClassName + "Controller : Controller");
            sw.WriteLine("    {");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 初始化数据库上下文");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        private readonly " + strProjectName + "ApiContext _context;");
            sw.WriteLine("        private readonly ILog log;");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 构造及初始化类参数");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        public " + strClassName + "Controller(" + strProjectName + "ApiContext context)");
            sw.WriteLine("        {");
            sw.WriteLine("            _context = context;");
            sw.WriteLine("            this.log = LogManager.GetLogger(Startup.repository.Name, typeof(" + strClassName + "Controller));");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 分页显示" + strTableComment + "数据");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"page\">分页</param>");
            sw.WriteLine("        /// <param name=\"limit\">每页显示数量</param>");
            sw.WriteLine("        /// <returns></returns>");
            sw.WriteLine("        [HttpGet]");
            sw.WriteLine("        [Route(\"/api/" + strTableNameLower + "\")]");
            sw.WriteLine("        public async Task<IActionResult> GetByPage(int page, int limit)");
            sw.WriteLine("        {");
            sw.WriteLine("            long lCount = 0;");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            if (!string.IsNullOrEmpty(CommonHelper.GetDetailsSelectJoinList(strTableName)))
            {
                sw.WriteLine("                var result = from item in _context.Set<" + strClassName + ">()");
                sw.WriteLine("                             " + CommonHelper.GetDetailsSelectJoinList(strTableName));
                sw.WriteLine("                             select new");
                sw.WriteLine("                             {");
                sw.WriteLine(CommonHelper.GetLeftSelectColumnName2(strTableName, "item"));
                sw.WriteLine(CommonHelper.GetDetailsSelectJoinColumn(strTableName, strPrimaryKey, CommonHelper.GetLeftSelectColumnName2(strTableName, "item")));
                sw.WriteLine("");
                sw.WriteLine("                              };");
                sw.WriteLine("                //if (!string.IsNullOrEmpty(search_key))");
                sw.WriteLine("                    //result = result.Where(n => n.search_key.Contains(search_key));");
                sw.WriteLine("                var list = await result.OrderByDescending(n => n." + strPrimaryKey + ").Skip((page - 1) * limit).Take(limit).ToListAsync();");
                sw.WriteLine("                lCount = result.LongCount();");
                sw.WriteLine("                if (lCount <= 0)");
                sw.WriteLine("                {");
                sw.WriteLine("                    return Json(new { code = 0, msg = \"暂无数据\" });");
                sw.WriteLine("                }");
                sw.WriteLine("                else");
                sw.WriteLine("                {");
                sw.WriteLine("                    return Json(new { code = 0, msg = \"success\", data = list, count = lCount });");
                sw.WriteLine("                }");
            }
            else
            {
                sw.WriteLine("                var result = _context." + strTableName + ".Where(n => n." + strPrimaryKey + " > 0);");
                sw.WriteLine("                lCount = result.LongCount();");
                sw.WriteLine("                var list =  await result.OrderByDescending(n => n." + strPrimaryKey + ").Skip((page - 1) * limit).Take(limit).ToListAsync();");
                sw.WriteLine("                return Json(new { code = 0, msg = \"success\", data = list, count = lCount });");
            }

            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> GetDataByPage\", ex);");
            sw.WriteLine("                return Json(new { code = 1, msg = ex.Message });");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 获取" + strTableComment + "表中数据填充下拉表单");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <returns>返回数据列表</returns>");
            sw.WriteLine("        [HttpGet]");
            sw.WriteLine("        [Route(\"/api/" + strTableNameLower + "/select\")]");
            sw.WriteLine("        public async Task<IActionResult> Select()");
            sw.WriteLine("        {");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                var list = await _context." + strTableName + ".OrderByDescending(n => n." + strPrimaryKey + ").ToListAsync();");
            sw.WriteLine("                return Json(new { code = 0, msg = \"success\", data = list });");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> GetAll\", ex);");
            sw.WriteLine("                return Json(new { code = 1, msg = ex.Message });");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 根据ID获取" + strTableComment + "详情");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"id\">" + strTableComment + "ID</param>");
            sw.WriteLine("        /// <returns>返回" + strTableComment + "详情</returns>");
            sw.WriteLine("        [HttpGet(\"{id}\")]");
            if (CommonHelper.ChecktKeyIsBigint(strTableName, strPrimaryKey))
            {
                sw.WriteLine("        public async Task<IActionResult> GetById(long id)");
            }
            else
            {
                sw.WriteLine("        public async Task<IActionResult> GetById(int id)");
            }
            sw.WriteLine("        {");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                //log.Debug(\"id=\"+id);");
            sw.WriteLine("                var item = await _context." + strTableName + ".FirstOrDefaultAsync(m => m." + strPrimaryKey + " == id);");
            sw.WriteLine("                if (item == null)");
            sw.WriteLine("                {");
            sw.WriteLine("                    return Json(new { code = 0, msg = \"数据为空\" });");
            sw.WriteLine("                }");
            sw.WriteLine("                else");
            sw.WriteLine("                {");
            if (!string.IsNullOrEmpty(CommonHelper.GetDetailsSelectJoin(strTableName)))
            {
                sw.WriteLine("                    var result = (" + CommonHelper.GetDetailsSelectJoin(strTableName));
                sw.WriteLine("                                  select new");
                sw.WriteLine("                                  {");
                sw.WriteLine(CommonHelper.GetLeftSelectColumnName2(strTableName, "item"));
                sw.WriteLine(CommonHelper.GetDetailsSelectJoinColumn(strTableName, strPrimaryKey, CommonHelper.GetLeftSelectColumnName2(strTableName, "item")));
                sw.WriteLine("");
                sw.WriteLine("                                  }).FirstOrDefault();");
                sw.WriteLine("                    return Json(new { code = 0, msg = \"success\", data = result });");
                sw.WriteLine("");
            }
            else
            {
                sw.WriteLine("                    return Json(new { code = 0, msg = \"success\", data = item });");
            }
            sw.WriteLine("                }");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> GetById\", ex);");
            sw.WriteLine("                return Json(new { code = 1, msg = ex.Message });");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 新增" + strTableComment + "");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"" + strTableNameSpec + "\">构造" + strTableComment + "对象数据</param>");
            sw.WriteLine("        /// <returns>返回新增的" + strTableComment + "</returns>          ");
            sw.WriteLine("        [HttpPost]");
            sw.WriteLine("        public async Task<IActionResult> Create(" + strClassName + " " + strTableNameSpec + ")");
            sw.WriteLine("        {");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                //log.Debug(" + CommonHelper.GetSaveLogColumnName(strTableName, strTableNameSpec) + ");");
            if (CommonHelper.ChecktCreatedAtKey(strTableName, "created_at"))
            {
                sw.WriteLine("                " + strTableNameSpec + ".created_at = DateTime.Now;");
            }
            sw.WriteLine("                _context." + strTableName + ".Add(" + strTableNameSpec + ");");
            sw.WriteLine("                await _context.SaveChangesAsync();");
            sw.WriteLine("                return Json(new { code = 0, msg = \"success\", data = " + strTableNameSpec + " });");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> Create\", ex);");
            sw.WriteLine("                return Json(new { code = 1, msg = ex.Message });");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 根据ID更新" + strTableComment + "");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"id\">ID</param>");
            sw.WriteLine("        /// <param name=\"" + strTableNameSpec + "\">构造" + strTableComment + "对象数据</param>");
            sw.WriteLine("        /// <returns></returns>");
            sw.WriteLine("        [HttpPost]");
            sw.WriteLine("        [Route(\"/api/" + strTableNameLower + "/update/{id}\")]");
            if (CommonHelper.ChecktKeyIsBigint(strTableName, strPrimaryKey))
            {
                sw.WriteLine("        public async Task<IActionResult> Update(long id, " + strClassName + " " + strTableNameSpec + ")");
            }
            else
            {
                sw.WriteLine("        public async Task<IActionResult> Update(int id, " + strClassName + " " + strTableNameSpec + ")");
            }
            sw.WriteLine("        {");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                //log.Debug(" + CommonHelper.GetSaveLogColumnName(strTableName, strTableNameSpec) + ");");
            sw.WriteLine("                if (" + strTableNameSpec + " == null || " + strTableNameSpec + "." + strPrimaryKey + " != id)");
            sw.WriteLine("                {");
            sw.WriteLine("                    return Json(new { code = 1, msg = \"ID不存在\" });");
            sw.WriteLine("                }");
            sw.WriteLine("");
            sw.WriteLine("                var item = _context." + strTableName + ".Find(id);");
            sw.WriteLine("");
            sw.WriteLine("                if (item == null)");
            sw.WriteLine("                {");
            sw.WriteLine("                    return Json(new { code = 1, msg = \"ID不存在,更新失败!\" });");
            sw.WriteLine("                }");
            sw.WriteLine("");
            sw.WriteLine(GetUpdateItems(strTableNameSpec, strTableName));
            sw.WriteLine("");
            sw.WriteLine("                _context." + strTableName + ".Update(item);");
            sw.WriteLine("                await _context.SaveChangesAsync();");
            sw.WriteLine("");
            sw.WriteLine("                return Json(new { code = 0, msg = \"更新成功\"});");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> Update\", ex);");
            sw.WriteLine("                return Json(new { code = 1, msg = ex.Message });");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("        ");
            sw.WriteLine("        /// <summary>");
            sw.WriteLine("        /// 删除" + strTableComment + "");
            sw.WriteLine("        /// </summary>");
            sw.WriteLine("        /// <param name=\"id\">ID</param>");
            sw.WriteLine("        /// <returns>返回是否删除成功</returns>");
            sw.WriteLine("        [HttpPost]");
            sw.WriteLine("        [Route(\"/api/" + strTableNameLower + "/del/{id}\")]");
            if (CommonHelper.ChecktKeyIsBigint(strTableName, strPrimaryKey))
            {
                sw.WriteLine("        public async Task<IActionResult> Delete(long id)");
            }
            else
            {
                sw.WriteLine("        public async Task<IActionResult> Delete(int id)");
            }

            sw.WriteLine("        {");
            sw.WriteLine("            try");
            sw.WriteLine("            {");
            sw.WriteLine("                var item = _context." + strTableName + ".Find(id);");
            sw.WriteLine("                if (item == null)");
            sw.WriteLine("                {");
            sw.WriteLine("                    return Json(new { code = 1, msg = \"ID为空,删除失败!\" });");
            sw.WriteLine("                }");
            sw.WriteLine("");
            sw.WriteLine("                _context." + strTableName + ".Remove(item);");
            sw.WriteLine("                await _context.SaveChangesAsync();");
            sw.WriteLine("");
            sw.WriteLine("                return Json(new { code = 0, msg = \"删除成功\" });");
            sw.WriteLine("            }");
            sw.WriteLine("            catch (Exception ex)");
            sw.WriteLine("            {");
            sw.WriteLine("                log.Error(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType.Name + \" -> Create\", ex);");
            sw.WriteLine("                return Json(new { code = 1, msg = ex.Message });");
            sw.WriteLine("            }");
            sw.WriteLine("        }");
            sw.WriteLine("");
            sw.WriteLine("    }");
            sw.WriteLine("}");
            sw.Close();
        }