示例#1
0
 public string GetClassName()
 {
     return(DBTableInfo.GetSingularName(this._TableName));
 }
示例#2
0
        public static DBTableInfo[] GetTables(BackgroundWorker bw)
        {
            DbProviderFactory instance     = SqlClientFactory.Instance;
            IDbConnection     dbConnection = null;

            dbConnection = instance.CreateConnection();
            IDbCommand         dbCommand  = null;
            IDataReader        dataReader = null;
            List <DBTableInfo> list       = new List <DBTableInfo>();

            if (bw != null)
            {
                bw.ReportProgress(0, "Connecting ...");
            }
            dbConnection.ConnectionString = ConfigOut.ConnectString;
            dbConnection.Open();
            try
            {
                dbCommand             = dbConnection.CreateCommand();
                dbCommand.CommandType = CommandType.Text;
                dbCommand.CommandText = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES;";
                dataReader            = dbCommand.ExecuteReader();
                while (dataReader.Read())
                {
                    string @string = dataReader.GetString(0);
                    if ([email protected]("dtproperties"))
                    {
                        if ([email protected]("sys"))
                        {
                            DBTableInfo dbTableInfo = new DBTableInfo(@string);
                            dbTableInfo.GetFields();
                            list.Add(dbTableInfo);
                        }
                    }
                }
                dataReader.Close();
                if (bw != null)
                {
                    bw.ReportProgress(50, "Tables collected");
                }
                foreach (DBTableInfo current in list)
                {
                    current.CollectFields(dbConnection);
                }
                if (bw != null)
                {
                    bw.ReportProgress(100, "Fields collected");
                }
            }
            finally
            {
                if (dataReader != null)
                {
                    dataReader.Close();
                }
                if (dbCommand != null)
                {
                    dbCommand.Dispose();
                }
                dbConnection.Close();
            }
            return(list.ToArray());
        }
示例#3
0
        public string GetNetType()
        {
            string result;

            if (this.IsForeignKey())
            {
                result = DBTableInfo.GetSingularName(this._DbForeignKeyInfo.PK_Table);
            }
            else
            {
                string data_Type = this.Data_Type;
                string str       = this.Is_Nullable ? "?" : "";
                if (data_Type.Equals("bigint"))
                {
                    result = "long" + str;
                }
                else
                {
                    if (data_Type.Equals("int"))
                    {
                        result = "int" + str;
                    }
                    else
                    {
                        if (data_Type.Equals("smallint"))
                        {
                            result = "short" + str;
                        }
                        else
                        {
                            if (data_Type.Equals("tinyint"))
                            {
                                result = "byte" + str;
                            }
                            else
                            {
                                if (data_Type.Equals("bit"))
                                {
                                    result = "bool" + str;
                                }
                                else
                                {
                                    if (data_Type.Equals("decimal"))
                                    {
                                        result = "System.Decimal" + str;
                                    }
                                    else
                                    {
                                        if (data_Type.Equals("numeric"))
                                        {
                                            result = "System.Decimal" + str;
                                        }
                                        else
                                        {
                                            if (data_Type.Equals("money"))
                                            {
                                                result = "System.Decimal" + str;
                                            }
                                            else
                                            {
                                                if (data_Type.Equals("smallmoney"))
                                                {
                                                    result = "System.Decimal" + str;
                                                }
                                                else
                                                {
                                                    if (data_Type.Equals("float"))
                                                    {
                                                        result = "float" + str;
                                                    }
                                                    else
                                                    {
                                                        if (data_Type.Equals("real"))
                                                        {
                                                            result = "double" + str;
                                                        }
                                                        else
                                                        {
                                                            if (data_Type.Equals("datetime"))
                                                            {
                                                                result = "DateTime" + str;
                                                            }
                                                            else
                                                            {
                                                                if (data_Type.Equals("smalldatetime"))
                                                                {
                                                                    result = "DateTime" + str;
                                                                }
                                                                else
                                                                {
                                                                    if (data_Type.Equals("char"))
                                                                    {
                                                                        result = "string";
                                                                    }
                                                                    else
                                                                    {
                                                                        if (data_Type.Equals("varchar"))
                                                                        {
                                                                            result = "string";
                                                                        }
                                                                        else
                                                                        {
                                                                            if (data_Type.Equals("text"))
                                                                            {
                                                                                result = "string";
                                                                            }
                                                                            else
                                                                            {
                                                                                if (data_Type.Equals("nchar"))
                                                                                {
                                                                                    result = "string";
                                                                                }
                                                                                else
                                                                                {
                                                                                    if (data_Type.Equals("nvarchar"))
                                                                                    {
                                                                                        result = "string";
                                                                                    }
                                                                                    else
                                                                                    {
                                                                                        if (data_Type.Equals("ntext"))
                                                                                        {
                                                                                            result = "string";
                                                                                        }
                                                                                        else
                                                                                        {
                                                                                            if (data_Type.Equals("binary"))
                                                                                            {
                                                                                                result = "byte[]";
                                                                                            }
                                                                                            else
                                                                                            {
                                                                                                if (data_Type.Equals("varbinary"))
                                                                                                {
                                                                                                    result = "byte[]";
                                                                                                }
                                                                                                else
                                                                                                {
                                                                                                    if (data_Type.Equals("image"))
                                                                                                    {
                                                                                                        result = "byte[]";
                                                                                                    }
                                                                                                    else
                                                                                                    {
                                                                                                        if (!data_Type.Equals("uniqueidentifier"))
                                                                                                        {
                                                                                                            throw new Exception("Unexpected data type: " + this.Data_Type);
                                                                                                        }
                                                                                                        result = "byte[]";
                                                                                                    }
                                                                                                }
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                }
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(result);
        }