Example #1
0
        public string tableEnumGenerater(MyHelper.DbSchema schema)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine();
            if (!string.IsNullOrEmpty(schema.TableComment))
            {
                sb.AppendLine(getcomment(schema.TableComment));
            }
            string name = MyHelper.StringHelper.upperCaseFirstLetter(MyHelper.StringHelper.DBNamingToCamelCase(schema.TableName));

            if (!string.IsNullOrEmpty(mConnection.enumSuffi))
            {
                name = name + MyHelper.StringHelper.upperCaseFirstLetter(mConnection.enumSuffi);
            }
            sb.AppendLine(tab + $"public enum {name}" + "{");
            if (mConnection.type == DbType.mysql.ToString())
            {
                List <MyHelper.MysqlTabeSchema> myschemas = new MyHelper.MySqlHelper(mConnection.connStr).getTableSchema(schema.TableName);
                for (int i = 0; i < myschemas.Count; i++)
                {
                    sb.AppendLine(tab + tab + myschemas[i].Field + comma);
                }
            }
            else
            {
                List <MyHelper.SqliteTableSchema> myschemas = new MyHelper.SQLiteHelper(mConnection.connStr).getTableSchema(schema.TableName);
                for (int i = 0; i < myschemas.Count; i++)
                {
                    sb.AppendLine(tab + tab + myschemas[i].name + comma);
                }
            }
            sb.AppendLine(tab + "}");
            return(sb.ToString());
        }
Example #2
0
        public string CeneraterClass()
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(getHeader());
            if (mConnection.type == DbType.mysql.ToString())
            {
                List <MyHelper.MysqlTableColumnSchema> schemas = new MyHelper.MySqlHelper(mConnection.connStr).getTableColumnSchema(mConnection.dbName, mTableName);
                for (int i = 0; i < schemas.Count; i++)
                {
                    MyHelper.MysqlTableColumnSchema schema = schemas[i];
                    sb.AppendLine(getcomment(schema.commentValue, schema.isNullable, schema.defaultValue));
                    sb.AppendLine(getProerty(CSharpDbTypeMap.FindType(schema.type), schema.columnName));
                    sb.AppendLine();
                }
            }
            else
            {
                List <MyHelper.SqliteTableSchema> schemas = new MyHelper.SQLiteHelper(mConnection.connStr).getTableSchema(mTableName);
                for (int i = 0; i < schemas.Count; i++)
                {
                    MyHelper.SqliteTableSchema schema = schemas[i];
                    sb.AppendLine(getcomment(null, schema.notnull, schema.dflt_value));
                    sb.AppendLine(getProerty(CSharpDbTypeMap.FindType(schema.type), schema.name));
                    sb.AppendLine();
                }
            }

            sb.AppendLine(tab + "}");
            sb.AppendLine("}");
            return(sb.ToString());
        }
        public string GeneraterSql()
        {
            string res = string.Empty;

            if (mDbType == DbType.mysql.ToString())
            {
                res = new MyHelper.MySqlHelper(connstr).getCreateSql(mTableName);
            }
            else
            {
                res = new MyHelper.SQLiteHelper(connstr).getCreateSql(mTableName);
            }
            return(res);
        }
Example #4
0
 private bool excuted(string sql)
 {
     if (mToConnection.type == DbType.mysql.ToString())
     {
         MyHelper.MySqlHelper tohelper = new MyHelper.MySqlHelper(mToConnection.connStr);
         return(tohelper.ExcuteNoQuery(sql) > 0);
     }
     else if (mFromConnection.type == DbType.sqlite.ToString())
     {
         MyHelper.SQLiteHelper tohelper = new MyHelper.SQLiteHelper(mToConnection.connStr);
         return(tohelper.ExcuteNoQuery(sql) > 0);
     }
     else
     {
         return(false);
     }
 }
Example #5
0
        private string getDataSql()
        {
            string    sql     = string.Empty;
            string    tempsql = string.Empty;
            DataTable dt      = null;

            tempsql = $"Select * from {CurrSchema.TableName}; ";
            if (mFromConnection.type == DbType.mysql.ToString())
            {
                dt = new MyHelper.MySqlHelper(mFromConnection.connStr).select(tempsql);
            }
            else
            {
                dt = new MyHelper.SQLiteHelper(mFromConnection.connStr).select(tempsql);
            }
            //INSERT INTO `{}` ({}) VALUES ({});
            string columSpilt = "`";
            string valueSpilt = "'";
            string colums     = string.Empty;
            string values     = string.Empty;

            if (dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Columns.Count; i++)
                {
                    if (string.IsNullOrEmpty(colums))
                    {
                        colums = columSpilt + dt.Columns[i].ColumnName + columSpilt;
                    }
                    else
                    {
                        colums += "," + columSpilt + dt.Columns[i].ColumnName + columSpilt;
                    }
                }
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    values = string.Empty;
                    for (int j = 0; j < dt.Columns.Count; j++)
                    {
                        string value = string.Empty;
                        if (dt.Rows[i][j] != null && !string.IsNullOrEmpty(dt.Rows[i][j].ToString()))
                        {
                            value = dt.Rows[i][j].ToString();
                        }
                        else
                        {
                            value = "";
                        }

                        if (string.IsNullOrEmpty(values))
                        {
                            values = valueSpilt + value + valueSpilt;
                        }
                        else
                        {
                            values += "," + valueSpilt + value + valueSpilt;
                        }
                    }
                    if (string.IsNullOrEmpty(sql))
                    {
                        sql = $"INSERT INTO `{CurrSchema.TableName}` ({colums}) VALUES({values});";
                    }
                    else
                    {
                        sql += "\r\n" + $"INSERT INTO `{CurrSchema.TableName}` ({colums}) VALUES({values});";
                    }
                }
            }
            else
            {
                sql = string.Empty;
            }
            return(sql);
        }