Skip to content

Commit

Permalink
Validar inserção de participantes duplicados
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonReis committed Aug 23, 2012
1 parent f5679bb commit e4e934e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 14 deletions.
4 changes: 2 additions & 2 deletions src/SilverlightApp/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
xmlns:SorteioViews="clr-namespace:SilverlightApp.Views"
DataContext="{StaticResource ViewModel}"
d:DesignHeight="600"
d:DesignWidth="800">
d:DesignWidth="800" Loaded="UserControl_Loaded">
<UserControl.Resources>
<con:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
</UserControl.Resources>
Expand Down Expand Up @@ -54,7 +54,7 @@
</StackPanel>

<Grid Grid.Row="2" Margin="0,36,0,0">
<SorteioViews:Participantes x:Name="viewParticipantes" Visibility="{Binding ElementName=Participantes, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}" Loaded="viewParticipantes_Loaded" />
<SorteioViews:Participantes x:Name="viewParticipantes" Visibility="{Binding ElementName=Participantes, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
<SorteioViews:Sorteio x:Name="viewSorteio" Visibility="{Binding ElementName=Sorteio, Path=IsChecked, Converter={StaticResource BooleanToVisibilityConverter}}"/>
</Grid>

Expand Down
6 changes: 3 additions & 3 deletions src/SilverlightApp/MainPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace SilverlightApp
{
public partial class MainPage : UserControl
{

#region Fields
private List<string> _participantes = new List<string>
{
Expand Down Expand Up @@ -78,9 +78,9 @@ private void Sorteio_Checked(object sender, RoutedEventArgs e)
}
}

private void viewParticipantes_Loaded(object sender, RoutedEventArgs e)
private void UserControl_Loaded(object sender, RoutedEventArgs e)
{

this.viewParticipantes.LerParticipantes();
}


Expand Down
30 changes: 21 additions & 9 deletions src/SilverlightApp/Views/Participantes.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ private void RemoveParticipant_Click(object sender, RoutedEventArgs e)

private void AddParticipant_Click(object sender, RoutedEventArgs e)
{
// valdiate there's text
// validate there's text
if (String.IsNullOrEmpty(NewParticipant.Text))
return;

// validate that the participant doesn't get duplicated
var alreadyExists = ParticipantsList.Items.Where(p => string.Compare(p as string, NewParticipant.Text, StringComparison.CurrentCultureIgnoreCase) == 0).Count();
if (alreadyExists > 0)
{
// TODO: should show some kind of message
return;
}

// add new participant
ParticipantsList.Items.Add(NewParticipant.Text);
}
Expand All @@ -63,12 +71,12 @@ private void Ler_Click(object sender, RoutedEventArgs e)

if (dialog.ShowDialog().Value)
{
this.PreencherParticipante(dialog.File);
this.PreencherParticipantes(dialog.File);
}
}
#endregion

private void PreencherParticipante(FileInfo file)
private void PreencherParticipantes(FileInfo file)
{
// clear the participants list
ParticipantsList.Items.Clear();
Expand All @@ -87,13 +95,17 @@ private void PreencherParticipante(FileInfo file)
}
}

public void LerParticipantes(string path)
public void LerParticipantes()
{
var file = new FileInfo(path);
if (file.Exists)
{
this.PreencherParticipante(file);
}
// TODO: ler participantes no arranque
// Silverlight não permite aceder diretamente aos ficheiros, poderá ser utilizado o IsolatedStorage
// http://blogs.silverlight.net/blogs/msnow/archive/2008/07/16/tip-of-the-day-19-using-isolated-storage.aspx
//var path = @"Data\Participantes.txt";
//var file = new FileInfo(path);
//if (file.Exists)
//{
// this.PreencherParticipantes(file);
//}
}


Expand Down

0 comments on commit e4e934e

Please sign in to comment.