FrmDatabase.btnExportData_Click >DatabaseBL.Database_ExportData (Permitir exportar datos de tablas seleccionadas, si no se selecciona ninguna se comporta como antes exportando todas)
This commit is contained in:
@@ -65,7 +65,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
||||
txtWriter.WriteLine("</body></html>");
|
||||
}
|
||||
|
||||
public static void Database_ExportData(TextWriter txtWriter, string connectionString, Database database)
|
||||
public static void Database_ExportData(TextWriter txtWriter, string connectionString, Database database, List<Table> tablesToExportData)
|
||||
{
|
||||
const int OneMegaByte = 1 * 1024 * 1024;
|
||||
const int MaxSizePerBatch = OneMegaByte;
|
||||
@@ -75,9 +75,18 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
||||
txtWriter.WriteLine("SET NOCOUNT ON;");
|
||||
txtWriter.WriteLine(string.Empty);
|
||||
|
||||
List<Table> tables = database.Tables;
|
||||
if (tablesToExportData.Any())
|
||||
{
|
||||
tables = tables.Where(t =>
|
||||
tablesToExportData.Select(tted => tted.Schema).Contains(t.Schema) &&
|
||||
tablesToExportData.Select(tted => tted.Name).Contains(t.Name) &&
|
||||
tablesToExportData.Select(tted => tted.Type).Contains(t.Type)).ToList();
|
||||
}
|
||||
|
||||
// Desactivar todas las FKs
|
||||
txtWriter.WriteLine("-- Disable all constraints");
|
||||
foreach (Table table in database.Tables)
|
||||
foreach (Table table in tables)
|
||||
{
|
||||
if (table.Type != "BASE TABLE") { continue; }
|
||||
|
||||
@@ -90,7 +99,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
||||
// Prepara información a exportar
|
||||
long batchLength = 0;
|
||||
long fileLength = 0;
|
||||
foreach (Table table in database.Tables)
|
||||
foreach (Table table in tables)
|
||||
{
|
||||
TableBL.Table_ExportData(table, txtWriter, connectionString, (lenght, onSplit) =>
|
||||
{
|
||||
@@ -118,7 +127,7 @@ namespace VAR.DatabaseExplorer.Code.BusinessLogic
|
||||
|
||||
// Activar todas las FKs
|
||||
txtWriter.WriteLine("-- Enable all constraints");
|
||||
foreach (Table table in database.Tables)
|
||||
foreach (Table table in tables)
|
||||
{
|
||||
if (table.Type != "BASE TABLE") { continue; }
|
||||
|
||||
|
||||
@@ -116,10 +116,22 @@ namespace VAR.DatabaseExplorer.UI
|
||||
{
|
||||
Parent.Enabled = false;
|
||||
|
||||
List<Table> tablesToExportData = new List<Table>();
|
||||
foreach (ListViewItem checkedItem in lsvTablas.CheckedItems)
|
||||
{
|
||||
Table tableToExportData = new Table()
|
||||
{
|
||||
Schema = checkedItem.SubItems[0].Text.ToString(), //Schema
|
||||
Name = checkedItem.SubItems[1].Text.ToString(), //Name
|
||||
Type = checkedItem.SubItems[2].Text.ToString(), //Type
|
||||
};
|
||||
tablesToExportData.Add(tableToExportData);
|
||||
}
|
||||
|
||||
Database database = DatabaseBL.Database_GetSchema(connectionString: _connectionString, fillTableDefinitions: true);
|
||||
string fixedDatabaseName = database.Name.Replace(' ', '_');
|
||||
var streamWriter = new SplittingStreamWriter("05." + fixedDatabaseName + ".{0:000}.Data.sql");
|
||||
DatabaseBL.Database_ExportData(streamWriter, _connectionString, database);
|
||||
DatabaseBL.Database_ExportData(streamWriter, _connectionString, database, tablesToExportData);
|
||||
streamWriter.Close();
|
||||
|
||||
Parent.Enabled = true;
|
||||
|
||||
Reference in New Issue
Block a user