Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .vs/TravelAgency/v14/.suo
Binary file not shown.
Binary file modified Data files/ExcursionsReport.pdf
Binary file not shown.
Binary file added ExcelFiles/Destinations.xlsx
Binary file not shown.
70 changes: 69 additions & 1 deletion TravelAgency.Logic/ReadExcelFromZip.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,74 @@
namespace TravelAgency.Logic
{
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.OleDb;
using System.IO;
using System.IO.Compression;
using Data;
using Model;

public class ReadExcelFromZip
{
private static string extractPath = "../../../ExcelFiles";

public void SelectExcelFilesFromZip(string path)
{
using (ZipArchive archive = ZipFile.Open(path, ZipArchiveMode.Update))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
if (entry.FullName.EndsWith(".xlsx"))
{
entry.ExtractToFile(Path.Combine(extractPath, entry.Name));
string connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + Path.Combine(extractPath, entry.Name) + ";Extended Properties='Excel 12.0 xml;HDR=Yes';";

OleDbConnection connection = new OleDbConnection(connectionString);

using (connection)
{
connection.Open();
var excelSchema = connection.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
var sheetName = excelSchema.Rows[0]["TABLE_NAME"].ToString();

this.ReadExcelData(connection, sheetName);
}
}
}
}
}

private void ReadExcelData(OleDbConnection conn, string sheetName)
{
Console.WriteLine("Reading data...");
var excelDbCommand = new OleDbCommand(@"SELECT * FROM [" + sheetName + "]", conn);

using (var oleDbDataAdapter = new OleDbDataAdapter(excelDbCommand))
{
DataSet ds = new DataSet();
oleDbDataAdapter.Fill(ds);
var destinations = new List<Destination>();
using (var reader = ds.CreateDataReader())
{
while (reader.Read())
{
var destination = new Destination();
destination.Country = reader["Country"].ToString();
destination.Distance = double.Parse(reader["Distance"].ToString());
destination.LuxuryFactor = int.Parse(reader["LuxuryFactor"].ToString());
destinations.Add(destination);
}
}

var db = new TravelAgencyDbContext();
foreach (var destination in destinations)
{
db.Destinations.Add(destination);
}

db.SaveChanges();
}
}
}
}
}
22 changes: 22 additions & 0 deletions TravelAgency.Logic/ReadFromSQLite.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace TravelAgency.Logic
{
using System;
using System.Data.SQLite;

public class ReadFromSQLite
{
public void ReadDataFromSQLLite()
{
SQLiteConnection.CreateFile("TravelAgency.sqlite");
SQLiteConnection dataBaseConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
dataBaseConnection.Open();
string sql1 = "select * from Expenses";
SQLiteCommand command1 = new SQLiteCommand(sql1, dataBaseConnection);
SQLiteDataReader reader = command1.ExecuteReader();
while (reader.Read())
{
Console.WriteLine("ID - {0} Hotel - {1}, Transport - {2}", reader["ExpensesId"], reader["HotelExpenses"], reader["TransportExpenses"]);
}
}
}
}
Binary file added TravelAgency.Logic/System.Data.SQLite.dll
Binary file not shown.
4,254 changes: 4,254 additions & 0 deletions TravelAgency.Logic/System.Data.SQLite.xml

Large diffs are not rendered by default.

7 changes: 7 additions & 0 deletions TravelAgency.Logic/TravelAgency.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,13 @@
<Reference Include="System" />
<Reference Include="System.ComponentModel.DataAnnotations" />
<Reference Include="System.Core" />
<Reference Include="System.Data.SQLite">
<HintPath>.\System.Data.SQLite.dll</HintPath>
</Reference>
<Reference Include="System.Drawing" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.IO.Log" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand All @@ -63,6 +69,7 @@
<Compile Include="PdfGenerator.cs" />
<Compile Include="ReadExcelFromZip.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ReadFromSQLite.cs" />
<Compile Include="XMLGenerator.cs" />
</ItemGroup>
<ItemGroup>
Expand Down
Loading