Exemple #1
0
        private string GetModelParamCode()
        {
            StringBuilder result = new StringBuilder();

            for (int i = 0; i < _columnsModels.Count; i++)
            {
                var columnModel = _columnsModels[i];
                if (columnModel.IS_NULLABLE == "YES")
                {
                    result.AppendFormat("{0}model.{1} = reader.IsDBNull ? null: reader.GetFieldValue<{2}>({3});\n",
                                        CodeHelp.Tab5(),
                                        CodeHelp.CamelCase(columnModel.COLUMN_NAME),
                                        CodeHelp.GetCSharpTypeString(columnModel.DATA_TYPE, false),
                                        i);
                }
                else
                {
                    result.AppendFormat("{0}model.{1} = reader.GetFieldValue<{2}>({3});\n",
                                        CodeHelp.Tab5(),
                                        CodeHelp.CamelCase(columnModel.COLUMN_NAME),
                                        CodeHelp.GetCSharpTypeString(columnModel.DATA_TYPE, false),
                                        i);
                }
            }
            return(result.ToString());
        }
Exemple #2
0
        private string GetFindByColumnMethodAsyncCode(ColumnModel columnModel)
        {
            StringBuilder result = new StringBuilder();

            result.AppendFormat(CodeHelp.Tab2() + "public async Task<List<{0}>> FindBy{1}Async({2} {3})\n",
                                CodeHelp.CamelCase(_tableName),
                                CodeHelp.CamelCase(columnModel.COLUMN_NAME),
                                CodeHelp.GetCSharpTypeString(columnModel.DATA_TYPE, false),
                                CodeHelp.FirstLower(CodeHelp.CamelCase(columnModel.COLUMN_NAME)));
            result.AppendLine(CodeHelp.Tab2() + "{");
            result.AppendLine(CodeHelp.Tab3() + "using var cmd = Db.Connection.CreateCommand();");
            result.AppendFormat(CodeHelp.Tab3() + "cmd.CommandText = @\"SELECT {0} FROM `{1}` WHERE {2} = @{3}\";\n",
                                GetColumnsCode(),
                                _tableName,
                                columnModel.COLUMN_NAME,
                                CodeHelp.CamelCase(columnModel.COLUMN_NAME));
            result.AppendLine(CodeHelp.Tab3() + "cmd.Parameters.Add(new MySqlParameter");
            result.AppendLine(CodeHelp.Tab3() + "{");
            result.AppendFormat(CodeHelp.Tab4() + "ParameterName = \"@{0}\",\n",
                                CodeHelp.CamelCase(columnModel.COLUMN_NAME));
            result.AppendFormat(CodeHelp.Tab4() + "DbType = DbType.{0},\n",
                                CodeHelp.GetMySqlDBTypeString(columnModel.DATA_TYPE));
            result.AppendFormat(CodeHelp.Tab4() + "Value = {0},\n",
                                CodeHelp.FirstLower(CodeHelp.CamelCase(columnModel.COLUMN_NAME)));
            result.AppendLine(CodeHelp.Tab3() + "});");
            result.AppendLine(CodeHelp.Tab3() + "return await ReadAllAsync(await cmd.ExecuteReaderAsync());");
            result.AppendLine(CodeHelp.Tab2() + "}");
            return(result.ToString());
        }
        public string CreateCode(string tplFile)
        {
            string content = File.ReadAllText(tplFile);

            content = content.Replace("{NameSpace}", _server.NameSpace);
            content = content.Replace("{Table}", CodeHelp.CamelCase(_tableName));

            return(content);
        }
Exemple #4
0
        /// <summary>
        /// {NameSpace}
        /// {Table}
        /// {Columns}
        /// {InsertSQL}
        /// {UpdateSQL}
        /// {DeleteSQL}
        /// {BindId}
        /// {BindParams}
        /// </summary>
        /// <param name="tplFile"></param>
        /// <returns></returns>
        public string CreateCode(string tplFile)
        {
            string content = File.ReadAllText(tplFile);

            content = content.Replace("{NameSpace}", _server.NameSpace);
            content = content.Replace("{Table}", CodeHelp.CamelCase(_tableName));
            content = content.Replace("{Columns}", GetColumnsCode());
            content = content.Replace("{InsertSQL}", GetInsertSQLCode());
            content = content.Replace("{UpdateSQL}", GetUpdateSQLCode());
            content = content.Replace("{DeleteSQL}", GetDeleteSQLCode());
            content = content.Replace("{BindId}", GetBindIdCode());
            content = content.Replace("{BindParams}", GetBindParamsCode());
            return(content);
        }
Exemple #5
0
        /// <summary>
        /// {NameSpace}
        /// {Table}
        /// {table}
        /// {FindOneParams}
        /// {Columns}
        /// {KeyWhere}
        /// {FindByColumnParam}
        /// {KeyParamters}
        /// </summary>
        /// <param name="tplFile"></param>
        /// <returns></returns>
        public string CreateCode(string tplFile)
        {
            string content = File.ReadAllText(tplFile);

            content = content.Replace("{NameSpace}", _server.NameSpace);
            content = content.Replace("{Table}", CodeHelp.CamelCase(_tableName));
            content = content.Replace("{table}", _tableName);
            content = content.Replace("{FindOneParams}", GetFindOneParamsCode());
            content = content.Replace("{Columns}", GetColumnsCode());
            content = content.Replace("{KeyWhere}", GetKeyWhereCode());
            content = content.Replace("{ModelParam}", GetModelParamCode());
            content = content.Replace("{FindByColumnMethodList}", GetFindByColumnMethodListCode());
            content = content.Replace("{KeyParamters}", GetKeyParamtersCode());
            return(content);
        }
Exemple #6
0
        public string GetColumnsCode()
        {
            StringBuilder result = new StringBuilder();

            foreach (var columnModel in _columnsModels)
            {
                result.AppendFormat("{0}/// <summary>\n", CodeHelp.Tab2());
                result.AppendFormat("{0}/// {1}\n", CodeHelp.Tab2(), columnModel.COLUMN_COMMENT);
                result.AppendFormat("{0}/// </summary>\n", CodeHelp.Tab2());
                result.AppendFormat("{0}public {1} {2};\n",
                                    CodeHelp.Tab2(),
                                    CodeHelp.GetCSharpTypeString(columnModel.DATA_TYPE, columnModel.IS_NULLABLE == "YES"),
                                    CodeHelp.CamelCase(columnModel.COLUMN_NAME));
            }
            return(result.ToString());
        }
Exemple #7
0
        public string GetBindIdCode()
        {
            StringBuilder result = new StringBuilder();

            foreach (var columnModel in _columnsModels)
            {
                if (columnModel.COLUMN_KEY == "PRI" && columnModel.EXTRA == "auto_increment")
                {
                    result.AppendLine(CodeHelp.Tab3() + "cmd.Parameters.Add(new MySqlParameter");
                    result.AppendLine(CodeHelp.Tab3() + "{");
                    result.AppendFormat(CodeHelp.Tab4() + "ParameterName = \"@{0}\",\n", columnModel.COLUMN_NAME);
                    result.AppendFormat(CodeHelp.Tab4() + "DbType = DbType.{0},\n", CodeHelp.GetMySqlDBTypeString(columnModel.DATA_TYPE));
                    result.AppendFormat(CodeHelp.Tab4() + "Value = {0}\n", CodeHelp.CamelCase(columnModel.COLUMN_NAME));
                    result.AppendLine(CodeHelp.Tab3() + "});");
                }
            }
            return(result.ToString());
        }
Exemple #8
0
        private string GetKeyParamtersCode()
        {
            StringBuilder result = new StringBuilder();

            foreach (var columnModel in _columnsModels)
            {
                if (columnModel.COLUMN_KEY == "PRI")
                {
                    result.AppendLine(CodeHelp.Tab4() + "cmd.Parameters.Add(new MySqlParameter");
                    result.AppendLine(CodeHelp.Tab4() + "{");
                    result.AppendFormat(CodeHelp.Tab5() + "ParameterName = \"@{0}\",\n",
                                        CodeHelp.CamelCase(columnModel.COLUMN_NAME));
                    result.AppendFormat(CodeHelp.Tab5() + "DbType = DbType.{0},\n",
                                        CodeHelp.GetMySqlDBTypeString(columnModel.DATA_TYPE));
                    result.AppendFormat(CodeHelp.Tab5() + "Value = {0},\n",
                                        CodeHelp.FirstLower(CodeHelp.CamelCase(columnModel.COLUMN_NAME)));
                    result.AppendLine(CodeHelp.Tab4() + "});");
                }
            }
            return(result.ToString());
        }
Exemple #9
0
        private string GetFindOneParamsCode()
        {
            StringBuilder result = new StringBuilder();

            foreach (var columnModel in _columnsModels)
            {
                if (columnModel.COLUMN_KEY == "PRI")
                {
                    if (result.Length == 0)
                    {
                        result.AppendFormat("{0} {1}",
                                            CodeHelp.GetCSharpTypeString(columnModel.DATA_TYPE, false),
                                            CodeHelp.FirstLower(CodeHelp.CamelCase(columnModel.COLUMN_NAME)));
                    }
                    else
                    {
                        result.AppendFormat(", {0} {1}",
                                            CodeHelp.GetCSharpTypeString(columnModel.DATA_TYPE, false),
                                            CodeHelp.FirstLower(CodeHelp.CamelCase(columnModel.COLUMN_NAME)));
                    }
                }
            }
            return(result.ToString());
        }