A part of the .NET Framework that provides a unified programming model for building line-of-business desktop applications on Windows.
El programa no se está ejecutando c#
IService1.cs
// ADO.Net Datenbank verbunden
namespace Wetter_WCF
{
[ServiceContract]
public interface IService1
{
[OperationContract]
List<WeatherDataDTO> GetWeatherData(RangeFilter rangeFilter);
}
[DataContract]
public class RangeFilter
{
[DataMember]
public string From { get; set; }
[DataMember]
public string To { get; set; }
public RangeFilter() { }
public RangeFilter(string from, string to)
{
this.From = from;
this.To = to;
}
}
[DataContract]
public class WeatherDataDTO
{
[DataMember]
public int Id { get; set; }
[DataMember]
public string Date { get; set; }
[DataMember]
public string Time { get; set; }
[DataMember]
public double Temperature { get; set; }
[DataMember]
public int Pressure { get; set; }
[DataMember]
public int Rain { get; set; }
[DataMember]
public double Wind { get; set; }
[DataMember]
public int Direction { get; set; }
[DataMember]
public int Humidity { get; set; }
}
}
Service1.svc.cs
namespace Wetter_WCF
{
public class Service1 : IService1
{
private WeatherDataEntities context = new WeatherDataEntities();
public List<WeatherDataDTO> GetWeatherData(RangeFilter rangeFilter)
{
List<WeatherDataDTO> weatherDataDTOs = new List<WeatherDataDTO>();
var start = parseDateTime(rangeFilter.From);
var end = parseDateTime(rangeFilter.To);
var query =
from weatherData in context.WeatherData
where weatherData.Datum >= start && weatherData.Datum <= end
select weatherData;
var i = 0;
foreach(var weatherData in query)
{
weatherDataDTOs.Add(new WeatherDataDTO
{
Id = weatherData.Id,
Date = weatherData.Datum.ToString(),
Direction = weatherData.Richtung.Value,
Humidity = weatherData.Feuchtigkeit.Value,
Pressure = weatherData.Luftdruck.Value,
Rain = weatherData.Regen.Value,
Temperature = weatherData.Temperatur.Value,
Time = weatherData.Zeit.Value.ToString(),
Wind = weatherData.Wind.Value
});
if (i == 200)
{
break;
}
i++;
}
return weatherDataDTOs;
}
private DateTime parseDateTime(string dateTime)
{
return DateTime.Parse(dateTime);
}
}
}
Wetter_WPF
MainWindow.xaml
<Grid>
<DataGrid x:Name="grid" HorizontalAlignment="Left" Height="288" Margin="10,121,0,0" VerticalAlignment="Top" Width="772" AutoGenerateColumns="False">
<DataGrid.Columns>
<DataGridTextColumn Binding="{Binding Id}" ClipboardContentBinding="{x:Null}" Header="Id"/>
<DataGridTextColumn Binding="{Binding Date}" ClipboardContentBinding="{x:Null}" Header="Date"/>
<DataGridTextColumn Binding="{Binding Time}" ClipboardContentBinding="{x:Null}" Header="Time"/>
<DataGridTextColumn Binding="{Binding Temperature}" ClipboardContentBinding="{x:Null}" Header="Temperature"/>
<DataGridTextColumn Binding="{Binding Pressure}" ClipboardContentBinding="{x:Null}" Header="Pressure"/>
<DataGridTextColumn Binding="{Binding Rain}" ClipboardContentBinding="{x:Null}" Header="Rain"/>
<DataGridTextColumn Binding="{Binding Wind}" ClipboardContentBinding="{x:Null}" Header="Wind"/>
<DataGridTextColumn Binding="{Binding Direction}" ClipboardContentBinding="{x:Null}" Header="Direction"/>
<DataGridTextColumn Binding="{Binding Humidity}" ClipboardContentBinding="{x:Null}" Header="Humidity"/>
</DataGrid.Columns>
</DataGrid>
<Label Content="FROM:" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top"/>
<DatePicker x:Name="fromPicker" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="58,11,0,0"/>
<Label Content="TO:" HorizontalAlignment="Left" Margin="28,41,0,0" VerticalAlignment="Top"/>
<DatePicker x:Name="toPicker" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="58,40,0,0"/>
<Button Content="Search" HorizontalAlignment="Left" Margin="10,72,0,0" VerticalAlignment="Top" Width="75" Click="Search_Button_Click"/>
</Grid>
MainWindow.xaml.cs
// ServiceReference holen -> Programm zuerst ausführen!!!
namespace Wetter_WPF {
public partial class MainWindow : Window {
private ServiceReference1.IService1 client = new ServiceReference1.Service1Client();
public MainWindow() {
InitializeComponent();
init();
}
public void init() {
this.fromPicker.SelectedDate = new DateTime(2013, 1, 1);
this.toPicker.SelectedDate = new DateTime(2013, 1, 1);
}
public void update(){
var from = fromPicker.SelectedDate.ToString().Split(' ')[0];
var to = toPicker.SelectedDate.ToString().Split(' ')[0];
var filter = new RangeFilter {
From = from,
To = to
};
var data = this.client.GetWeatherData(filter);
this.grid.ItemsSource = data;
}
private void Search_Button_Click(object sender, RoutedEventArgs e) {
update();
}
}
}
Developer technologies | Windows Presentation Foundation
Developer technologies | .NET | Other
Microsoft Technologies based on the .NET software framework. Miscellaneous topics that do not fit into specific categories.
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.