private static void WriteFile(string namespacestr, Table item) { using (StreamWriter sw = new StreamWriter(Application.StartupPath + "\\" + namespacestr + "\\" + item.TableName + ".cs", false)) { StringBuilder sbText = FormatString(namespacestr, item); sw.Write(sbText.ToString()); } }
private static StringBuilder FormatString(string namespacestr, Table item) { StringBuilder sbText = new StringBuilder(); sbText.AppendLine("namespace " + namespacestr); sbText.AppendLine("{"); sbText.AppendLine(" public class " + item.TableName); sbText.AppendLine(" {"); foreach (var col in item.Columns) { string fieldName = Util.FieldNameConvert(col.ColumnName); sbText.AppendLine(" private " + Util.GetTypeFromDbType(col.Type) + " " + fieldName + ";"); sbText.AppendLine(" public " + Util.GetTypeFromDbType(col.Type) + " " + col.ColumnName); sbText.AppendLine(" {"); sbText.AppendLine(" get { return " + fieldName + "; }"); sbText.AppendLine(" set { " + fieldName + "=value; }"); sbText.AppendLine(" }"); } sbText.AppendLine(" }"); sbText.AppendLine("}"); return sbText; }
public static List<Table> GetTables(string tableList) { List<Table> tables = new List<Table>(); string sql; if (Version == "9") sql = sqlGetTables; else sql = sqlGetTables2K; string condition = string.Empty; if (tableList != null && tableList.Trim().Length>0) { string[] tableArray = tableList.Split(','); if (sql.Contains("d.name")) { condition = " and d.name IN ("; } else { condition = " and o.name IN ("; } bool isfirst = true; foreach (var item in tableArray) { if (isfirst) { condition += "'" + item + "'"; isfirst = false; } else { condition += ",'" + item + "'"; } } condition += ")"; } sql = sql.Replace("$Tables", condition); using (SqlDataReader reader = SqlHelper.ExecuteReader(ConnString, CommandType.Text, sql)) { while (reader.Read()) { Table table = new Table(); table.TableId = Convert.ToInt32(reader["TableId"].ToString()); table.TableName = reader["TableName"].ToString(); table.Columns = GetColumns(table.TableName); tables.Add(table); } } return tables; }