Skip to content

Commit

Permalink
terminati test
Browse files Browse the repository at this point in the history
  • Loading branch information
marcello committed Dec 7, 2020
1 parent cb9152b commit 5023d57
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 8 deletions.
93 changes: 85 additions & 8 deletions Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,31 @@ static void Main(string[] args)

var config = builder.Build();

Console.WriteLine("Test addRowTotal");
TestAddRowTotal(config);
BuildMenu();
//TestBuildDataForPivot(config);
//TestAddRowTotal(config);
//TestBuildPivot(config);
RunAll(config);

Console.ReadLine();

}

public static void BuildMenu()
{

}

public static void RunAll(IConfigurationRoot config)
{
TestAddRowTotal(config);
//TestBuildPivot(config);
TestPivotAtOnce(config);
}

public static void TestAddRowTotal(IConfigurationRoot config)
{
{
Console.WriteLine("Test addRowTotal");
string sql = @"SELECT TOP 10
ProductName
,sum(quantity) as Bottles_sold
Expand All @@ -37,16 +53,77 @@ FROM [dbo].[Order Details Extended]
var results = GetDataTable(config, sql, null);

var file = AppDomain.CurrentDomain.BaseDirectory + "/output/rowtotal.xlsx";
ExcelHelper eh = ExcelHelper.Create(file);
eh.Dump(results, "SHEET1");
eh.AddRowTotal("SHEET1");
//eh.DoPivotTable("SHEET1", "SHEET2", new string[]{"ProductName"}, new string[] {"Subtotal_per_Wine" });
eh.Save();
if (System.IO.File.Exists(file))
{
System.IO.File.Delete(file);
}
ExcelHelper eh = ExcelHelper.Create(file)
.Dump(results, "SHEET1")
//.DoPivotTable("SHEET1","SHEET2", new string[]{"ProductName"}, new string[]{"Bottles_sold"}, new string[]{"Subtotal_per_Wine" })
.AddRowTotal("SHEET1")
.Save();
eh.Dispose();
Console.WriteLine("file created in " + file);
Console.WriteLine("End testAddRowTotal");
}

public static void TestBuildDataForPivot(IConfigurationRoot config)
{
string sql = "SELECT * FROM Invoices ORDER BY OrderDate";
var results = GetDataTable(config, sql, null);
var file = AppDomain.CurrentDomain.BaseDirectory + "/output/pivot.xlsx";
ExcelHelper eh = ExcelHelper.Create(file)
.Dump(results, "SHEET1")
.Save();
eh.Dispose();
}

public static void TestBuildPivot(IConfigurationRoot config)
{
Console.WriteLine("Begin TestBuildPivot");
var file = AppDomain.CurrentDomain.BaseDirectory + "/output/pivot.xlsx";
if (System.IO.File.Exists(file) != true)
{
TestBuildDataForPivot(config);
}
ExcelHelper eh = ExcelHelper.Create(file)
.DoPivotTable("SHEET1",
"SHEET2",
new string[] { "ShipCountry" },
new string[] { "ProductName" },
new string[] { "ExtendedPrice" }
)
.Save();
eh.Dispose();
Console.WriteLine("file created in " + file);
Console.WriteLine("End testBuildPivot");

}

public static void TestPivotAtOnce(IConfigurationRoot config)
{
Console.WriteLine("Begin TestPivotAtOnce");
string sql = "SELECT * FROM Invoices ORDER BY OrderDate";
var results = GetDataTable(config, sql, null);
var file = AppDomain.CurrentDomain.BaseDirectory + "/output/pivot_at_once.xlsx";
if (System.IO.File.Exists(file))
{
System.IO.File.Delete(file);
}
ExcelHelper eh = ExcelHelper.Create(file)
.Dump(results, "SHEET1")
.DoPivotTable("SHEET1",
"SHEET2",
new string[] { "ShipCountry" },
new string[] { "ProductName" },
new string[] { "ExtendedPrice" }
)
.Save();
eh.Dispose();
Console.WriteLine("file created in " + file);
Console.WriteLine("End testPivotAtOnce");
}

public static DataTable GetDataTable(IConfigurationRoot config, string sql, Hashtable _params = null)
{
//Console.WriteLine(config["ConnectionString"]);
Expand Down
Binary file added img/pivot1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/pivot2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added img/rowTotal.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5023d57

Please sign in to comment.