我的应用程序中有两个DatePicker
,我必须根据用户选择的日期(从日期 - 到日期)选择记录。下图显示了我的设计Datepicker
。我想显示succeddedtxtBox中成功进程的计数和failedtxtBox中失败进程的计数,具体取决于这些日期选择器中的日期选择
XAML
<Label>displays the succedded process</Label>
<Border BorderThickness="1" BorderBrush="Gray">
<TextBlock FontWeight="SemiBold" FontSize="12" x:Name="success_Txtbox" Width="50" VerticalAlignment="Stretch" TextAlignment="Right"/>
</Border>
<Label>displays the failed process</Label>
<Border BorderBrush="Gray" BorderThickness="1">
<TextBlock FontWeight="SemiBold" FontSize="12" x:Name="fail_Txtbox" Width="50" TextAlignment="Left"></TextBlock>
</Border>
我想出了 linq 查询的逻辑,看起来像这样。
var query_success = ( from x in this.db.Processes
where x.date = "from date" && x.date = "to date" &&
(x.Type == "completed")
select x).Count();
success_Txtbox.Text = query_success.ToString();
var query_failed = ( from x in this.db.Processes
where x.date = "from date" && x.date = "to date" &&
(x.Type == "Failed")
select x).Count();
failed_Txtbox.Text = query_failed.ToString();
更新-XAML
<StackPanel Orientation="Horizontal">
<Label>From</Label>
<Border>
<DatePicker x:Name="fromDP"></DatePicker>
</Border>
<Label>To</Label>
<Border>
<DatePicker x:Name="toDP"></DatePicker>
</Border>
<Button Content="Go !" Height="23" Name="Go_Btn" Width="75" Click="Go_Btn_Click" />
</StackPanel>
更新答案
private void Go_Btn_Click(object sender, SelectionChangedEventArgs e)
{
var query_History = (this.db.Processes
.Where(x => x.Date >= fromDP.SelectedDate.Value && x.Date <= toDP.SelectedDate.Value));
var query_Success = query_History.Count(p => p.Type == "Complete");
var query_Failed = query_History.Count(p => p.Type == "Failed");
success_Txtbox.Text = query_Success.ToString();
fail_Txtbox.Text = query_Failed.ToString();
}
我尝试了上述解决方案,但它在 txtbox 中显示 0 作为结果。