Skip to content

Commit

Permalink
Merge branch 'release/0.0.4' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
fstueber committed Sep 23, 2021
2 parents ac73646 + b3e3a32 commit 82147e5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/CommandDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ public static Command Export()
{
var command = new Command("export", "Exports data from a BBS-Planung database to ECF files")
{
new Option(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
new Option<FileInfo>(new[] { "--config", "-c" }, "Path to existing JSON configuration file")
{
Argument = new Argument<FileInfo>(),
IsRequired = true
},
};
Expand Down
6 changes: 3 additions & 3 deletions src/Ecf.BbsPlanung.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@

<ItemGroup>
<PackageReference Include="Enbrea.BbsPlanung.Db" Version="0.1.1" />
<PackageReference Include="Enbrea.Csv" Version="0.1.0" />
<PackageReference Include="Enbrea.Ecf" Version="0.1.3" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20574.7" />
<PackageReference Include="Enbrea.Csv" Version="0.2.1" />
<PackageReference Include="Enbrea.Ecf" Version="0.1.9" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.21308.1" />
<PackageReference Include="System.Data.Odbc" Version="5.0.0" />
</ItemGroup>

Expand Down
35 changes: 34 additions & 1 deletion src/Export/ExportManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ public async override Task Execute()
await Execute(EcfTables.SchoolClasses, bbsPlanungDbReader, async (r, w, h) => await ExportSchoolClasses(r, w, h));
await Execute(EcfTables.Students, bbsPlanungDbReader, async (r, w, h) => await ExportStudents(r, w, h));
await Execute(EcfTables.StudentSchoolClassAttendances, bbsPlanungDbReader, async (r, w, h) => await ExportStudentSchoolClassAttendances(r, w, h));
await Execute(EcfTables.StudentSubjects, bbsPlanungDbReader, async (r, w, h) => await ExportStudentSubjects(r, w, h));

// Disconnect reader
await bbsPlanungDbReader.DisconnectAsync();
Expand Down Expand Up @@ -167,7 +168,7 @@ await ecfTableWriter.WriteHeadersAsync(
ecfTableWriter.TrySetValue(EcfHeaders.FirstName, student.Firstname);
ecfTableWriter.TrySetValue(EcfHeaders.Gender, student.GetGender());
ecfTableWriter.TrySetValue(EcfHeaders.Birthdate, student.GetBirthdate());
//ecfTableWriter.TrySetValue(EcfHeaders.StudentNo, student.StudentNo);
ecfTableWriter.TrySetValue(EcfHeaders.StudentNo, student.StudentNo);

await ecfTableWriter.WriteAsync();

Expand All @@ -188,12 +189,44 @@ private async Task<int> ExportStudentSchoolClassAttendances(BbsPlanungDbReader b
else
{
await ecfTableWriter.WriteHeadersAsync(
EcfHeaders.Id,
EcfHeaders.StudentId,
EcfHeaders.SchoolClassId);
}

await foreach (var student in bbsPlanungDbReader.StudentsAsync(_config.EcfExport.SchoolNo))
{
ecfTableWriter.TrySetValue(EcfHeaders.Id, student.Id.ToString() + "_" + student.SchoolClass);
ecfTableWriter.TrySetValue(EcfHeaders.StudentId, student.Id.ToString());
ecfTableWriter.TrySetValue(EcfHeaders.SchoolClassId, student.SchoolClass);

await ecfTableWriter.WriteAsync();

ecfRecordCounter++;
}

return ecfRecordCounter;
}

private async Task<int> ExportStudentSubjects(BbsPlanungDbReader bbsPlanungDbReader, EcfTableWriter ecfTableWriter, string[] ecfHeaders)
{
var ecfRecordCounter = 0;

if (ecfHeaders != null && ecfHeaders.Length > 0)
{
await ecfTableWriter.WriteHeadersAsync(ecfHeaders);
}
else
{
await ecfTableWriter.WriteHeadersAsync(
EcfHeaders.Id,
EcfHeaders.StudentId,
EcfHeaders.SchoolClassId);
}

await foreach (var student in bbsPlanungDbReader.StudentsAsync(_config.EcfExport.SchoolNo))
{
ecfTableWriter.TrySetValue(EcfHeaders.Id, student.Id.ToString() + "_" + student.SchoolClass);
ecfTableWriter.TrySetValue(EcfHeaders.StudentId, student.Id.ToString());
ecfTableWriter.TrySetValue(EcfHeaders.SchoolClassId, student.SchoolClass);

Expand Down

0 comments on commit 82147e5

Please sign in to comment.