Skip to content

Commit

Permalink
Add XML Reading of MatchDays.
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanDeveloper committed Jun 25, 2017
1 parent 4046af2 commit 1c617cd
Show file tree
Hide file tree
Showing 47 changed files with 353 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,12 @@ public interface IAdminClientService {

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAdminClientService/GenerateMatches", ReplyAction="http://tempuri.org/IAdminClientService/GenerateMatchesResponse")]
System.Threading.Tasks.Task<bool> GenerateMatchesAsync(LigaManagerAdminClient.AdminClientService.Season season, System.DateTime beginDateTime, System.DateTime endDateTime);

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAdminClientService/AddMatchDay", ReplyAction="http://tempuri.org/IAdminClientService/AddMatchDayResponse")]
bool AddMatchDay(System.Xml.Linq.XElement xmlElement, LigaManagerAdminClient.AdminClientService.Season selectedSeason, int matchday);

[System.ServiceModel.OperationContractAttribute(Action="http://tempuri.org/IAdminClientService/AddMatchDay", ReplyAction="http://tempuri.org/IAdminClientService/AddMatchDayResponse")]
System.Threading.Tasks.Task<bool> AddMatchDayAsync(System.Xml.Linq.XElement xmlElement, LigaManagerAdminClient.AdminClientService.Season selectedSeason, int matchday);
}

[System.CodeDom.Compiler.GeneratedCodeAttribute("System.ServiceModel", "4.0.0.0")]
Expand Down Expand Up @@ -823,5 +829,13 @@ public bool GenerateMatches(LigaManagerAdminClient.AdminClientService.Season sea
public System.Threading.Tasks.Task<bool> GenerateMatchesAsync(LigaManagerAdminClient.AdminClientService.Season season, System.DateTime beginDateTime, System.DateTime endDateTime) {
return base.Channel.GenerateMatchesAsync(season, beginDateTime, endDateTime);
}

public bool AddMatchDay(System.Xml.Linq.XElement xmlElement, LigaManagerAdminClient.AdminClientService.Season selectedSeason, int matchday) {
return base.Channel.AddMatchDay(xmlElement, selectedSeason, matchday);
}

public System.Threading.Tasks.Task<bool> AddMatchDayAsync(System.Xml.Linq.XElement xmlElement, LigaManagerAdminClient.AdminClientService.Season selectedSeason, int matchday) {
return base.Channel.AddMatchDayAsync(xmlElement, selectedSeason, matchday);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@
<wsdl:message name="IAdminClientService_GenerateMatches_OutputMessage">
<wsdl:part name="parameters" element="tns:GenerateMatchesResponse" />
</wsdl:message>
<wsdl:message name="IAdminClientService_AddMatchDay_InputMessage">
<wsdl:part name="parameters" element="tns:AddMatchDay" />
</wsdl:message>
<wsdl:message name="IAdminClientService_AddMatchDay_OutputMessage">
<wsdl:part name="parameters" element="tns:AddMatchDayResponse" />
</wsdl:message>
<wsdl:portType name="IAdminClientService">
<wsdl:operation name="IsOpen">
<wsdl:input wsaw:Action="http://tempuri.org/ILigaManagerService/IsOpen" message="tns:IAdminClientService_IsOpen_InputMessage" />
Expand Down Expand Up @@ -258,6 +264,10 @@
<wsdl:input wsaw:Action="http://tempuri.org/IAdminClientService/GenerateMatches" message="tns:IAdminClientService_GenerateMatches_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/IAdminClientService/GenerateMatchesResponse" message="tns:IAdminClientService_GenerateMatches_OutputMessage" />
</wsdl:operation>
<wsdl:operation name="AddMatchDay">
<wsdl:input wsaw:Action="http://tempuri.org/IAdminClientService/AddMatchDay" message="tns:IAdminClientService_AddMatchDay_InputMessage" />
<wsdl:output wsaw:Action="http://tempuri.org/IAdminClientService/AddMatchDayResponse" message="tns:IAdminClientService_AddMatchDay_OutputMessage" />
</wsdl:operation>
</wsdl:portType>
<wsdl:binding name="BasicHttpBinding_IAdminClientService" type="tns:IAdminClientService">
<soap:binding transport="http://schemas.xmlsoap.org/soap/http" />
Expand Down Expand Up @@ -486,6 +496,15 @@
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
<wsdl:operation name="AddMatchDay">
<soap:operation soapAction="http://tempuri.org/IAdminClientService/AddMatchDay" style="document" />
<wsdl:input>
<soap:body use="literal" />
</wsdl:input>
<wsdl:output>
<soap:body use="literal" />
</wsdl:output>
</wsdl:operation>
</wsdl:binding>
<wsdl:service name="AdminClientService">
<wsdl:port name="BasicHttpBinding_IAdminClientService" binding="tns:BasicHttpBinding_IAdminClientService">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,4 +341,26 @@
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="AddMatchDay">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="xmlElement" nillable="true">
<xs:complexType>
<xs:sequence>
<xs:any minOccurs="0" processContents="lax" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element xmlns:q28="http://schemas.datacontract.org/2004/07/LigaManagerServer.Models" minOccurs="0" name="selectedSeason" nillable="true" type="q28:Season" />
<xs:element minOccurs="0" name="matchday" type="xs:int" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="AddMatchDayResponse">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" name="AddMatchDayResult" type="xs:boolean" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,11 @@ protected void ExecuteBackCommand(object obj)
/// <param name="errorHeader"></param>
protected void UpdateModels(bool isUpdated, string errorMessage, string errorHeader)
{
if (isUpdated)
{
ReloadModels();
}
else
if (!isUpdated)
{
MessageBox.Show(errorMessage, errorHeader, MessageBoxButton.OK, MessageBoxImage.Error);
}
ReloadModels();
}
}
}
65 changes: 58 additions & 7 deletions LigaManagerAdminClient/Controllers/MatchesWindowController.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
using System;
using System.IO;
using System.Linq;
using System.Windows;
using System.Xml;
using System.Xml.Linq;
using LigaManagerAdminClient.AdminClientService;
using LigaManagerAdminClient.Framework;
using LigaManagerAdminClient.ViewModels;
using LigaManagerAdminClient.Views;
using LigaManagerBettorClient.Frameworks;
using Microsoft.Win32;

namespace LigaManagerAdminClient.Controllers
{
Expand Down Expand Up @@ -35,7 +39,8 @@ public override async void Initialize(MainWindow mainWindow)
AddCommand = new RelayCommand(ExecuteAddCommand),
DeleteCommand = new RelayCommand(ExecuteDeleteCommand),
ChangeCommand = new RelayCommand(ExecuteChangeCommand),
GenerateMatchesCommand = new RelayCommand(ExecuteGenerateCommand)
GenerateMatchesCommand = new RelayCommand(ExecuteGenerateCommand),
LoadMatchDayCommand = new RelayCommand(ExecuteLoadMatchCommand)
};
_view.DataContext = _viewModel;
_viewModel.SelectionSeasonChanged += UpdateSeason;
Expand All @@ -44,6 +49,56 @@ public override async void Initialize(MainWindow mainWindow)
MainWindow.Content = _view;
}

private async void ExecuteLoadMatchCommand(object obj)
{
// Create OpenFileDialog
var dlg = new OpenFileDialog
{
DefaultExt = ".xml",
Filter = "XML File (.xml)|*.xml",
Multiselect = false
};

// Display OpenFileDialog by calling ShowDialog method
bool? result = dlg.ShowDialog();

// Get the selected file name and display in a TextBox
if (result == true)
{
var setMatchDay = new SetMatchDayWindowController();
var matchDay = setMatchDay.SetMatchDay();

if (matchDay == -1) return;


var isAdded = false;
try
{
// Open document
string filename = dlg.FileName;
XmlDocument booksFromFile = new XmlDocument();
booksFromFile.Load(dlg.InitialDirectory + dlg.FileName);
isAdded = await _adminClient.AddMatchDayAsync(
GetXElementFromXmlElement(booksFromFile.DocumentElement),
_viewModel.SelectedSeason, matchDay);
}
catch (Exception e)
{
Console.WriteLine(e);
}
finally
{
UpdateModels(isAdded, "Spieltag konnte nicht hinzugefügt werden! Die Datei entspricht nicht dem vorgegebenen Format!",
"Hinzufügen fehlgeschlagen");
}
}
}

public XElement GetXElementFromXmlElement(XmlElement xmlElement)
{
return XElement.Load(xmlElement.CreateNavigator().ReadSubtree());
}

private void UpdateSeason(object sender, Season e)
{
ReloadModels();
Expand Down Expand Up @@ -86,16 +141,12 @@ protected override async void ExecuteChangeCommand(object obj)
// Check if service is available
if (!await AdminClientHelper.IsAvailable(_adminClient)) return;
var teams = await _adminClient.GetAllTeamsAsync();
var homeTeams = teams.Where(x => !x.Name.ToUpper()
.Equals(_viewModel.SelectedMatch.AwayTeam.Name.ToUpper()));
var awayTeams = teams.Where(x => !x.Name.ToUpper()
.Equals(_viewModel.SelectedMatch.HomeTeam.Name.ToUpper()));

var addBettorWindow = new AddMatchWindowController
{
Match = _viewModel.SelectedMatch,
AwayTeams = awayTeams.ToList(),
HomeTeams = homeTeams.ToList()
AwayTeams = teams.ToList(),
HomeTeams = teams.ToList()
};

var showMatch = addBettorWindow.ShowMatch();
Expand Down
53 changes: 53 additions & 0 deletions LigaManagerAdminClient/Controllers/SetMatchDayWindowController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
using System;
using System.Windows;
using LigaManagerAdminClient.ViewModels;
using LigaManagerAdminClient.Views;
using LigaManagerBettorClient.Frameworks;

namespace LigaManagerAdminClient.Controllers
{
public class SetMatchDayWindowController
{
private SetMatchDayWindow _view;
private SetMatchDayWindowViewModel _viewModel;
public int MatchDay { get; set; }
public int SetMatchDay()
{
#region View and ViewModel
_view = new SetMatchDayWindow();
_viewModel = new SetMatchDayWindowViewModel
{
OkCommand = new RelayCommand(ExecuteOkCommand),
CancelCommand = new RelayCommand(ExecuteCancelCommand),
MatchDay = MatchDay

};
_view.DataContext = _viewModel;
#endregion

return _view.ShowDialog() == true ? _viewModel.MatchDay : -1;
}
#region Execute Commands
public void ExecuteOkCommand(object obj)
{
if (_view.MatchDayTextBox.Equals(string.Empty))
{
MessageBox.Show("Spieltag ist leer!", "Kein Spieltag ausgewählt",
MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
_view.DialogResult = true;
_view.Close();
}

}

public void ExecuteCancelCommand(object obj)
{
_view.DialogResult = false;
_view.Close();
}
#endregion
}
}
7 changes: 0 additions & 7 deletions LigaManagerAdminClient/Data/Images/Resources.xaml

This file was deleted.

Binary file removed LigaManagerAdminClient/Data/Images/calendar-5.png
Binary file not shown.
Binary file added LigaManagerAdminClient/Data/Images/calendar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LigaManagerAdminClient/Data/Images/edit.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LigaManagerAdminClient/Data/Images/error.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added LigaManagerAdminClient/Data/Images/folder.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LigaManagerAdminClient/Data/Images/football.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LigaManagerAdminClient/Data/Images/group.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LigaManagerAdminClient/Data/Images/left-arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LigaManagerAdminClient/Data/Images/plus.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed LigaManagerAdminClient/Data/Images/settings-4.png
Binary file not shown.
Binary file added LigaManagerAdminClient/Data/Images/settings.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LigaManagerAdminClient/Data/Images/soccer.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LigaManagerAdminClient/Data/Images/success.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LigaManagerAdminClient/Data/Images/trash.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified LigaManagerAdminClient/Data/Images/user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 16 additions & 8 deletions LigaManagerAdminClient/LigaManagerAdminClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
<Compile Include="Controllers\AddTeamWindowController.cs" />
<Compile Include="Controllers\GenerateMatchesWindowController.cs" />
<Compile Include="Controllers\MenuWindowController.cs" />
<Compile Include="Controllers\SetMatchDayWindowController.cs" />
<Compile Include="Framework\AdminClientHelper.cs" />
<Compile Include="Framework\RelayCommand.cs" />
<Compile Include="Framework\ViewModelBase.cs" />
Expand All @@ -95,6 +96,7 @@
<Compile Include="ViewModels\MatchesWindowViewModel.cs" />
<Compile Include="ViewModels\MenuWindowViewModel.cs" />
<Compile Include="ViewModels\SeasonWindowViewModel.cs" />
<Compile Include="ViewModels\SetMatchDayWindowViewModel.cs" />
<Compile Include="ViewModels\TeamWindowViewModel.cs" />
<Compile Include="Views\AddBettorWindow.xaml.cs">
<DependentUpon>AddBettorWindow.xaml</DependentUpon>
Expand Down Expand Up @@ -126,6 +128,9 @@
<Compile Include="Views\SeasonWindow.xaml.cs">
<DependentUpon>SeasonWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\SetMatchDayWindow.xaml.cs">
<DependentUpon>SetMatchDayWindow.xaml</DependentUpon>
</Compile>
<Compile Include="Views\TeamWindow.xaml.cs">
<DependentUpon>TeamWindow.xaml</DependentUpon>
</Compile>
Expand Down Expand Up @@ -222,10 +227,6 @@
</None>
</ItemGroup>
<ItemGroup>
<Page Include="Data\Images\Resources.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\AddBettorWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down Expand Up @@ -266,6 +267,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\SetMatchDayWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Views\TeamWindow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand All @@ -286,9 +291,6 @@
<ItemGroup>
<Resource Include="Data\Images\left-arrow.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Data\Images\settings-4.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Data\Images\error.png" />
<Resource Include="Data\Images\success.png" />
Expand All @@ -297,14 +299,20 @@
<Resource Include="Data\Images\football.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Data\Images\calendar-5.png" />
<Resource Include="Data\Images\calendar.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Data\Images\user.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Data\Images\group.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Data\Images\settings.png" />
</ItemGroup>
<ItemGroup>
<Resource Include="Data\Images\folder.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Fody.2.0.0\build\dotnet\Fody.targets" Condition="Exists('..\packages\Fody.2.0.0\build\dotnet\Fody.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class MatchesWindowViewModel : ViewModelBase
public ICommand AddCommand { get; set; }
public ICommand ChangeCommand { get; set; }
public ICommand DeleteCommand { get; set; }
public ICommand LoadMatchDayCommand { get; set; }
private Season _selectedSeason;
public event EventHandler<Season> SelectionSeasonChanged;
public Season SelectedSeason
Expand Down
12 changes: 12 additions & 0 deletions LigaManagerAdminClient/ViewModels/SetMatchDayWindowViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
using System.Windows.Input;
using LigaManagerAdminClient.Framework;

namespace LigaManagerAdminClient.ViewModels
{
public class SetMatchDayWindowViewModel : ViewModelBase
{
public int MatchDay { get; set; }
public ICommand OkCommand { get; set; }
public ICommand CancelCommand { get; set; }
}
}
10 changes: 7 additions & 3 deletions LigaManagerAdminClient/Views/AddMatchWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,15 @@
<TextBox x:Name="AwayTeamScore" MaxLength="3" HorizontalContentAlignment="Center" Grid.Column="1" HorizontalAlignment="Left" Height="23" Margin="50,30,0,0" Grid.Row="2" TextWrapping="Wrap" Text="{Binding SelectedMatch.AwayTeamScore}" VerticalAlignment="Top" Width="120" ToolTip="Spieltip" UndoLimit="3"/>
<TextBox x:Name="HomeTeamScore" MaxLength="3" HorizontalContentAlignment="Center" TextChanged="OnTextChanged" HorizontalAlignment="Left" Height="23" Margin="50,30,0,0" Grid.Row="2"
Grid.Column="0" TextWrapping="Wrap" Text="{Binding SelectedMatch.HomeTeamScore}" VerticalAlignment="Top" Width="120" ToolTip="Spieltip" UndoLimit="3"/>
<TextBox x:Name="MinuteTextBox" MaxLength="2" TextChanged="OnMinuteChanged" HorizontalContentAlignment="Center" HorizontalAlignment="Left" Height="23" Margin="128,99,0,0" Grid.Row="3"
<TextBox x:Name="MinuteTextBox" MaxLength="2" TextChanged="OnMinuteChanged" HorizontalContentAlignment="Center" HorizontalAlignment="Left" Height="23" Margin="128,49,0,0" Grid.Row="3"
Grid.Column="0" TextWrapping="Wrap" Text="{Binding Minute}" VerticalAlignment="Top" Width="55" UndoLimit="2"/>
<TextBox x:Name="HourTextBox" MaxLength="2" TextChanged="OnHourChanged" HorizontalContentAlignment="Center" HorizontalAlignment="Left" Height="23" Margin="60,99,0,0" Grid.Row="3"
<TextBox x:Name="HourTextBox" MaxLength="2" TextChanged="OnHourChanged" HorizontalContentAlignment="Center" HorizontalAlignment="Left" Height="23" Margin="60,49,0,0" Grid.Row="3"
Grid.Column="0" TextWrapping="Wrap" Text="{Binding Hour}" VerticalAlignment="Top" Width="55" UndoLimit="2"/>
<TextBlock HorizontalAlignment="Left" Margin="120,102,0,0" Grid.Row="3" Grid.Column="0" TextWrapping="Wrap" Text=":" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" Margin="120,52,0,0" Grid.Row="3" Grid.Column="0" TextWrapping="Wrap" Text=":" VerticalAlignment="Top"/>
<Label Content="Spieltag" HorizontalAlignment="Left" HorizontalContentAlignment="Center" Margin="10,113,0,0" VerticalAlignment="Top" Grid.Row="3"
Grid.Column="0" Width="220"/>
<TextBox x:Name="MatchDayTextBox" MaxLength="2" TextChanged="OnTextChanged" HorizontalContentAlignment="Center" HorizontalAlignment="Left" Height="23" Margin="90,144,0,0" Grid.Row="3"
Grid.Column="0" TextWrapping="Wrap" Text="{Binding SelectedMatch.MatchDay}" VerticalAlignment="Top" Width="55" UndoLimit="4"/>

</Grid>
</Window>
Loading

0 comments on commit 1c617cd

Please sign in to comment.