JasinCole
Well-known member
- Joined
- Feb 16, 2023
- Messages
- 66
- Programming Experience
- 1-3
I've thought about this for a week and I just can't seem which way to go...
My ultimate goal is to have a data structure that contains 4 related objects and I want to be able to use that data structure in my view in something similar to a itemsControl. Like below
The issue I am having is figuring out how to mangle my data into an appropriate data structure using 'good' coding principals.
When accessing my database to get the records I get a list of the records sort and sum the records to get the total amount.
1. one issue I am mulling over is if it is worth getting all the records in one db call and then sorting them locally into different buckets or if I should be making 4 different db calls. Recent discussions lean me toward making 4 different db calls.
2. is this an appropriate use of a class? Classes should be singular objects, so I would need a List<AppropriateClassName> The class would only contain 2 members, a property to hold the string value and a decimal to hold the sum value
3. Or, would this be better as some other data structure like a Dictionary<>
4. Would an Enumeration be ok to hold the string values
This all seems to be complicated in my mind because the string values are opposites. What I mean by that is some are upcoming and other are overdue. Which means any variable name I choose to describe one makes no sense to the other. IE. DaysOverdue makes no sense to DueInDays
All I know is this is how I would like to work with the data structure
I'd love to see some psuedo code and why it is appropriate in this situation to use which ever data structure. What I wanted to use was a List<KeyValuePairs<string, decimal>> but I read that if this is what you want then just use a List<Class>. But the class just feels off to me because it seems I am trying to describe plural related objects. IE. AccountsPayableAgingInvoices
Everything I've tried just feels dirty, can anyone give some good advice??
My ultimate goal is to have a data structure that contains 4 related objects and I want to be able to use that data structure in my view in something similar to a itemsControl. Like below
The issue I am having is figuring out how to mangle my data into an appropriate data structure using 'good' coding principals.
When accessing my database to get the records I get a list of the records sort and sum the records to get the total amount.
1. one issue I am mulling over is if it is worth getting all the records in one db call and then sorting them locally into different buckets or if I should be making 4 different db calls. Recent discussions lean me toward making 4 different db calls.
2. is this an appropriate use of a class? Classes should be singular objects, so I would need a List<AppropriateClassName> The class would only contain 2 members, a property to hold the string value and a decimal to hold the sum value
3. Or, would this be better as some other data structure like a Dictionary<>
4. Would an Enumeration be ok to hold the string values
This all seems to be complicated in my mind because the string values are opposites. What I mean by that is some are upcoming and other are overdue. Which means any variable name I choose to describe one makes no sense to the other. IE. DaysOverdue makes no sense to DueInDays
All I know is this is how I would like to work with the data structure
C#:
<ItemsRepeater Grid.Column="0" Grid.Row="1" Items="{CompiledBinding AccountInvoicesDue}">
<ItemsRepeater.ItemTemplate>
<DataTemplate>
<Grid ColumnDefinitions="*, Auto">
<TextBlock Grid.Column="0" Text="{CompiledBinding /*When it's due in string*/}"/>
<TextBlock Grid.Column="1" Text="{CompiledBinding /*How much is due in decimal value*/, StringFormat={}{0:C2}}"/>
</Grid>
</DataTemplate>
</ItemsRepeater.ItemTemplate>
</ItemsRepeater>
I'd love to see some psuedo code and why it is appropriate in this situation to use which ever data structure. What I wanted to use was a List<KeyValuePairs<string, decimal>> but I read that if this is what you want then just use a List<Class>. But the class just feels off to me because it seems I am trying to describe plural related objects. IE. AccountsPayableAgingInvoices
Everything I've tried just feels dirty, can anyone give some good advice??