Exemplo n.º 1
0
        public void NpgsqlTableChanged(ListBox listBox, UiShow uiShow)
        {
            IEnumerable<object> enumerable;
            using (NpgsqlConnection connection = new NpgsqlConnection(ConnectionString))
            {
                connection.Open();

                string sql =
                    $"SELECT column_name, is_nullable, udt_name FROM INFORMATION_SCHEMA.COLUMNS\r\nWHERE table_catalog='{connection.Database}' AND table_schema='public' AND table_name='{listBox.SelectedItem}';";
                enumerable = connection.Query(sql, null, null, true, null, null);
            }
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("public class {0}{1}{{{1}", listBox.SelectedItem, Environment.NewLine);
            foreach (dynamic obj2 in enumerable)
            {
                string columnName = (string)obj2.column_name;
                bool isNullable = (bool)(obj2.is_nullable.ToUpper() == "YES");
                string dataType = (string)obj2.udt_name;
                builder.AppendLine(GenerateField(columnName, isNullable, dataType));
            }
            string @class = builder.Append("}").ToString();
            uiShow.txtClass.Text = @class;

            File.AppendAllText("models.cs", @class);
        }
Exemplo n.º 2
0
        public void SQLConnSet_BtnConnClick(ConnSet connSet, UiShow uiShow)
        {
            using (SqlConnection connection = CreateConnection(connSet))
            {
                connection.Open();

                uiShow.lbTableName.Items.Clear();
                IEnumerable<object> enumerable = connection.Query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE='BASE TABLE' ORDER BY TABLE_NAME ASC;", null, null, true, null, null);
                uiShow.lbTableName.Items.AddRange((from d in enumerable select ((dynamic)d).TABLE_NAME).ToArray<object>());
            }
        }
Exemplo n.º 3
0
        public void MySqlConnSet_BtnConnClick(ConnSet connSet, UiShow uiShow)
        {
            StringBuilder sb = new StringBuilder();
            foreach (var item in TableNames)
            {
                sb.AppendLine(GenerateCode(item as string));
            }

            System.IO.File.WriteAllText("ORM.cs", sb.ToString());

            uiShow.lbTableName.Items.Clear();
            uiShow.lbTableName.Items.AddRange(TableNames);
        }
Exemplo n.º 4
0
        public void pgAdminConnSet_BtnConnClick(ConnSet connSet, UiShow uiShow)
        {
            using (NpgsqlConnection connection = CreateConnection(connSet))
            {
                connection.Open();

                uiShow.lbTableName.Items.Clear();
                string sql =
                    $"SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_catalog='{connection.Database}' AND table_schema='public' AND table_type='BASE TABLE' ORDER BY table_name ASC;";
                IEnumerable<object> enumerable = connection.Query(sql, null, null, true, null, null);
                uiShow.lbTableName.Items.AddRange((from d in enumerable select ((dynamic)d).table_name).ToArray<object>());
            }
        }
Exemplo n.º 5
0
 public void SqlLiteTableChanged(ListBox listBox, UiShow uiShow)
 {
     IEnumerable<object> enumerable;
     using (SQLiteConnection connection = new SQLiteConnection(SqLiteConnStr.ToString()))
     {
         connection.Open();
         string sql = $"PRAGMA table_info({listBox.SelectedItem})";
         enumerable = connection.Query(sql, null, null, true, null, null);
     }
     StringBuilder builder = new StringBuilder();
     builder.AppendFormat("public class {0}{1}{{{1}", listBox.SelectedItem, Environment.NewLine);
     foreach (dynamic obj2 in enumerable)
     {
         string columnName = (string)obj2.name;
         bool isNullable = (bool)(obj2.notnull == 0L);
         string dataType = (string)obj2.type;
         builder.AppendLine(GenerateField(columnName, isNullable, dataType));
     }
     uiShow.txtClass.Text = builder.Append("}").ToString();
 }
Exemplo n.º 6
0
 public void ShowSqLiteTables(UiShow uiShow, string path)
 {
     if (uiShow != null)
     {
         SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder
         {
             DataSource = path,
         };
         SqLiteConnStr = builder;
         using (SQLiteConnection connection = new SQLiteConnection(SqLiteConnStr.ToString()))
         {
             connection.Open();
             uiShow.lbTableName.Items.Clear();
             IEnumerable<object> enumerable =
                 connection.Query("SELECT tbl_name FROM sqlite_master WHERE TYPE='table' ORDER BY name ASC;",
                     null, null, true, null, null);
             uiShow.lbTableName.Items.AddRange(
                 (from d in enumerable select ((dynamic)d).tbl_name).ToArray<object>());
         }
     }
 }
Exemplo n.º 7
0
        public void SqlTableChanged(ListBox listBox, UiShow uiShow)
        {
            IEnumerable<object> enumerable;
            using (SqlConnection connection = new SqlConnection(ConnectionString))
            {
                connection.Open();

                string sql =
                    $"SELECT COLUMN_NAME, IS_NULLABLE, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='{listBox.SelectedItem}';";
                enumerable = connection.Query(sql, null, null, true, null, null);
            }
            StringBuilder builder = new StringBuilder();
            builder.AppendFormat("public class {0}{1}{{{1}", listBox.SelectedItem, Environment.NewLine);
            foreach (dynamic obj2 in enumerable)
            {
                string columnName = (string)obj2.COLUMN_NAME;
                bool isNullable = (bool)(obj2.IS_NULLABLE.ToUpper() == "YES");
                string dataType = (string)obj2.DATA_TYPE;
                builder.AppendLine(GenerateField(columnName, isNullable, dataType));
            }
            uiShow.txtClass.Text = builder.Append("}").ToString();
        }
Exemplo n.º 8
0
 public void MySqlTableChanged(ListBox listBox, UiShow uiShow)
 {
     uiShow.txtClass.Text = GenerateCode(listBox.SelectedItem as string);
 }