[#5] MemberDataSheet: Add generating a member data sheet
This commit is contained in:
@ -63,6 +63,7 @@ namespace Elwig.Helpers {
|
||||
private readonly Dictionary<int, Dictionary<int, Dictionary<string, (int, int)>>> _memberRightsAndObligations = new();
|
||||
private readonly Dictionary<int, Dictionary<int, Dictionary<string, int>>> _memberDeliveryBuckets = new();
|
||||
private readonly Dictionary<int, Dictionary<int, Dictionary<string, int>>> _memberPaymentBuckets = new();
|
||||
private readonly Dictionary<int, Dictionary<int, Dictionary<string, int>>> _memberBucketAreas = new();
|
||||
|
||||
public AppDbContext() {
|
||||
if (App.Config.DatabaseLog != null) {
|
||||
@ -256,6 +257,24 @@ namespace Elwig.Helpers {
|
||||
_memberPaymentBuckets[year] = buckets;
|
||||
}
|
||||
|
||||
private async Task FetchMemberBucketAreas(int year, SqliteConnection? cnx = null) {
|
||||
var ownCnx = cnx == null;
|
||||
cnx ??= await ConnectAsync();
|
||||
var buckets = new Dictionary<int, Dictionary<string, int>>();
|
||||
using (var cmd = cnx.CreateCommand()) {
|
||||
cmd.CommandText = $"SELECT mgnr, bucket, area FROM v_area_commitment_bucket_strict WHERE year = {year}";
|
||||
using var reader = await cmd.ExecuteReaderAsync();
|
||||
while (await reader.ReadAsync()) {
|
||||
var mgnr = reader.GetInt32(0);
|
||||
var bucket = reader.GetString(1);
|
||||
if (!buckets.ContainsKey(mgnr)) buckets[mgnr] = new();
|
||||
buckets[mgnr][bucket] = reader.GetInt32(2);
|
||||
}
|
||||
}
|
||||
if (ownCnx) await cnx.DisposeAsync();
|
||||
_memberBucketAreas[year] = buckets;
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, (int, int)>> GetMemberRightsAndObligations(int year, int mgnr, SqliteConnection? cnx = null) {
|
||||
if (!_memberRightsAndObligations.ContainsKey(year))
|
||||
await FetchMemberRightsAndObligations(year, cnx);
|
||||
@ -274,6 +293,12 @@ namespace Elwig.Helpers {
|
||||
return _memberPaymentBuckets[year].GetValueOrDefault(mgnr, new());
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, int>> GetMemberBucketAreas(int year, int mgnr, SqliteConnection? cnx = null) {
|
||||
if (!_memberBucketAreas.ContainsKey(year))
|
||||
await FetchMemberBucketAreas(year, cnx);
|
||||
return _memberBucketAreas[year].GetValueOrDefault(mgnr, new());
|
||||
}
|
||||
|
||||
public async Task<Dictionary<string, (string, int, int, int, int)>> GetMemberBuckets(int year, int mgnr, SqliteConnection? cnx = null) {
|
||||
var ownCnx = cnx == null;
|
||||
cnx ??= await ConnectAsync();
|
||||
|
Reference in New Issue
Block a user