Skip to content

Commit 6284bbd

Browse files
committed
Finishing touches
1 parent 21c59d4 commit 6284bbd

File tree

8 files changed

+146
-14
lines changed

8 files changed

+146
-14
lines changed

README.md

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
# TODO / IDEAPAD
2-
- [ ] open source zdroje
3-
- [ ] editable history grid
4-
- [ ] 1 default input
5-
- [ ] feature breakdown
6-
- [ ] fun lottery wheel
7-
- [ ] import
1+
# Stream Utilities
2+
This is small code project, made as a portfolio showcasing my experience in frontend using WPF technology in C# language.
3+
4+
## Ticket Lottery
5+
Application which has intuitive UI for inputting new tickets and drawing a winner. It features editable and filterable history list, ticket calculations, and a simple design with rich code base representing latest modern frontend solutions.

StreamUtilities.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TicketLottery", "TicketLott
77
EndProject
88
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{8EC462FD-D22E-90A8-E5CE-7E832BA40C5D}"
99
ProjectSection(SolutionItems) = preProject
10+
README.md = README.md
1011
.github\workflows\release.yml = .github\workflows\release.yml
1112
EndProjectSection
1213
EndProject

TicketLottery/Dialogs/LotterySettingsDialog.xaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@
1111
<RowDefinition />
1212
<RowDefinition />
1313
</Grid.RowDefinitions>
14-
<TextBox Margin="8" Text="{Binding DonationSplit, Mode=TwoWay}">
14+
<TextBox Margin="8"
15+
md:HintAssist.Hint="Donation Split"
16+
Style="{StaticResource MaterialDesignFloatingHintTextBox}"
17+
Text="{Binding DonationSplit, Mode=TwoWay}">
1518
<i:Interaction.Behaviors>
1619
<b:NumericTextBoxBehavior />
1720
</i:Interaction.Behaviors>
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
2+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
3+
xmlns:b="clr-namespace:TicketLottery.Behaviors"
4+
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
5+
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
6+
xmlns:p="clr-namespace:TicketLottery.Properties"
7+
xmlns:vm="clr-namespace:TicketLottery.ViewModels">
8+
<DataTemplate DataType="{x:Type vm:SpinWinnerViewModel}">
9+
<Grid Width="300" Height="180">
10+
<i:Interaction.Triggers>
11+
<i:EventTrigger EventName="Loaded">
12+
<i:InvokeCommandAction Command="{Binding InitializeCommand}" />
13+
</i:EventTrigger>
14+
</i:Interaction.Triggers>
15+
<Grid.RowDefinitions>
16+
<RowDefinition Height="Auto" />
17+
<RowDefinition Height="Auto" />
18+
<RowDefinition Height="Auto" />
19+
</Grid.RowDefinitions>
20+
<TextBlock Grid.Row="0"
21+
Margin="16"
22+
HorizontalAlignment="Center"
23+
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
24+
Text="{Binding Header}" />
25+
<TextBlock Grid.Row="1"
26+
Margin="16"
27+
HorizontalAlignment="Center"
28+
Text="{Binding WinnerUserName}" />
29+
<StackPanel Grid.Row="2"
30+
Margin="8"
31+
HorizontalAlignment="Center"
32+
Orientation="Horizontal">
33+
<Button Margin="8"
34+
Command="{x:Static md:DialogHost.CloseDialogCommand}"
35+
Content="Done"
36+
Style="{StaticResource MaterialDesignRaisedButton}" />
37+
<Button Margin="8"
38+
Command="{Binding InitializeCommand}"
39+
Content="Reroll"
40+
Style="{StaticResource MaterialDesignOutlinedButton}" />
41+
</StackPanel>
42+
</Grid>
43+
</DataTemplate>
44+
</ResourceDictionary>

TicketLottery/TicketInputWindow.xaml

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@
55
xmlns:conv="clr-namespace:TicketLottery.Converters"
66
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
77
xmlns:dgx="urn:tom-englert.de/DataGridExtensions"
8+
xmlns:enum="clr-namespace:TicketLottery.Enums"
89
xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
910
xmlns:local="clr-namespace:TicketLottery"
1011
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
1112
xmlns:md="http://materialdesigninxaml.net/winfx/xaml/themes"
1213
xmlns:p="clr-namespace:TicketLottery.Properties"
14+
xmlns:sys="clr-namespace:System;assembly=mscorlib"
1315
xmlns:vm="clr-namespace:TicketLottery.ViewModels"
1416
Title="Stream Utilites"
1517
Width="1200"
@@ -22,9 +24,19 @@
2224
<ResourceDictionary>
2325
<ResourceDictionary.MergedDictionaries>
2426
<ResourceDictionary Source="/Dialogs/LotterySettingsDialog.xaml" />
27+
<ResourceDictionary Source="/Dialogs/SpinWinnerDialog.xaml" />
2528
<ResourceDictionary>
2629
<conv:KeyDownEventArgsConverter x:Key="KeyDownEventArgsConverter" />
2730
</ResourceDictionary>
31+
<ResourceDictionary>
32+
<ObjectDataProvider x:Key="TicketTypeData"
33+
MethodName="GetValues"
34+
ObjectType="{x:Type sys:Enum}">
35+
<ObjectDataProvider.MethodParameters>
36+
<x:Type TypeName="enum:TicketType" />
37+
</ObjectDataProvider.MethodParameters>
38+
</ObjectDataProvider>
39+
</ResourceDictionary>
2840
</ResourceDictionary.MergedDictionaries>
2941
</ResourceDictionary>
3042
</Window.Resources>
@@ -61,8 +73,7 @@
6173
Style="{StaticResource MaterialDesignHeadline5TextBlock}"
6274
Text="Ticket Lottery" />
6375
<Button Grid.Column="2"
64-
Command="{x:Static md:DialogHost.OpenDialogCommand}"
65-
CommandParameter="{x:Static p:Settings.Default}"
76+
Command="{Binding ShowSettingsDialogCommand}"
6677
Content="{md:PackIcon Settings}"
6778
Style="{StaticResource MaterialDesignIconButton}" />
6879
</Grid>
@@ -133,9 +144,10 @@
133144
<DataGridTextColumn MinWidth="100"
134145
Binding="{Binding Count, UpdateSourceTrigger=PropertyChanged}"
135146
Header="Count" />
136-
<DataGridTextColumn MinWidth="100"
137-
Binding="{Binding Type, UpdateSourceTrigger=PropertyChanged}"
138-
Header="Type" />
147+
<DataGridComboBoxColumn MinWidth="120"
148+
Header="Type"
149+
ItemsSource="{Binding Source={StaticResource TicketTypeData}, Mode=OneWay}"
150+
SelectedValueBinding="{Binding Type, UpdateSourceTrigger=PropertyChanged}" />
139151
<DataGridTextColumn MinWidth="100"
140152
Binding="{Binding InsertTime, StringFormat=g}"
141153
Header="Insert Time"
@@ -156,6 +168,7 @@
156168
AutoGenerateColumns="False"
157169
BorderThickness="2"
158170
CanUserAddRows="False"
171+
IsReadOnly="True"
159172
ItemsSource="{Binding Tickets}"
160173
SelectionUnit="FullRow">
161174
<DataGrid.Columns>
@@ -169,6 +182,7 @@
169182
</DataGrid>
170183
<Button Grid.Row="1"
171184
HorizontalAlignment="Center"
185+
Command="{Binding ShowSpinWinnerDialogCommand}"
172186
Content="Spin!" />
173187
</Grid>
174188
</Grid>

TicketLottery/Utilities/TicketWriter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace TicketLottery.Utilities
66
{
77
public static class TicketWriter
88
{
9-
private static string JsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "data.json");
9+
private static string JsonPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "TicketLottery", "data.json");
1010

1111
public static void Save(IEnumerable<InsertHistoryModel> data)
1212
{
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
using CommunityToolkit.Mvvm.ComponentModel;
2+
using CommunityToolkit.Mvvm.Input;
3+
using System.Diagnostics;
4+
using System.Windows.Threading;
5+
using TicketLottery.Models;
6+
7+
namespace TicketLottery.ViewModels
8+
{
9+
public partial class SpinWinnerViewModel : ObservableObject
10+
{
11+
[ObservableProperty]
12+
private IEnumerable<TicketModel> _tickets;
13+
14+
[ObservableProperty]
15+
private string? _winnerUserName;
16+
17+
[ObservableProperty]
18+
private string _header;
19+
20+
public SpinWinnerViewModel(IEnumerable<TicketModel> tickets)
21+
{
22+
_tickets = tickets;
23+
_header = "And the winner is ...";
24+
}
25+
26+
[RelayCommand]
27+
public async Task Initialize()
28+
{
29+
// Create a weighted list based on the number of tickets each user has
30+
List<string> weightedTickets = Tickets.SelectMany(ticket => Enumerable.Repeat(ticket.Username, ticket.Count)).ToList();
31+
32+
// Randomly select a winner from the weighted list
33+
Random random = new Random();
34+
35+
int currentValue = 0;
36+
int currentIncrement = 0;
37+
38+
while (currentValue < 500)
39+
{
40+
currentValue += currentIncrement;
41+
42+
currentIncrement += 1;
43+
44+
await Task.Delay(currentValue);
45+
46+
string newWinnerUserName = string.Empty;
47+
do
48+
{
49+
newWinnerUserName = weightedTickets[random.Next(weightedTickets.Count)];
50+
}
51+
while (newWinnerUserName == WinnerUserName);
52+
53+
WinnerUserName = newWinnerUserName;
54+
}
55+
56+
Header = "Congratulations!";
57+
}
58+
}
59+
}

TicketLottery/ViewModels/TicketInputViewModel.cs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using CommunityToolkit.Mvvm.ComponentModel;
22
using CommunityToolkit.Mvvm.Input;
3+
using MaterialDesignThemes.Wpf;
34
using System.Collections.ObjectModel;
45
using System.Windows.Input;
56
using TicketLottery.Models;
@@ -76,5 +77,17 @@ private void Save()
7677
TicketWriter.Save(InsertHistory);
7778
Tickets = TicketCalculator.GetTickets(InsertHistory).ToList();
7879
}
80+
81+
[RelayCommand]
82+
private async Task ShowSpinWinnerDialog()
83+
{
84+
await DialogHost.Show(new SpinWinnerViewModel(Tickets));
85+
}
86+
87+
[RelayCommand]
88+
private async Task ShowSettingsDialog()
89+
{
90+
await DialogHost.Show(Properties.Settings.Default);
91+
}
7992
}
8093
}

0 commit comments

Comments
 (0)