WPF:使用 "time" 文本框以秒为单位搜索数据库

WPF: Using a "time" textbox to search a database using seconds

我有一个数据table,其中有一列Total,它以秒为单位显示总时间。 (因为这可能超过 24 小时,所以我使用 DateDiff 来计算以秒为单位的时间,这个 returns 一个 INT)如下:

SET tmTotals = DATEDIFF(Second, tmStartTime, tmEndTime)

数据table 如下所示:

StartTime                 EndTime                   Total
-----------------------------------------------------------        
2018-12-03 00:00:19.257   2018-12-04 00:00:23.288   86404
2018-12-02 10:13:32.586   2018-12-04 10:14:57.298   172885
2018-12-04 12:07:50.636   2018-12-04 18:04:25.526   21395
2018-12-04 03:15:25.061   2018-12-04 13:15:34.665   36009
2018-12-03 20:56:12.947   2018-12-04 03:11:07.992   22495
2018-12-02 00:11:46.020   2018-12-04 00:29:55.051   173889

在我的 WPF 应用程序中,我想使用两个 textboxes 在 table 中的两个 Total 次之间进行搜索。我希望这些 textboxes 格式为 hhh:mm:ss(时间可以超过 100 小时)。我怎样才能将其设置为 Int 值以便在 StoredProcedure 中可用?

我用过不到24小时,现在不能用了:

CONVERT(varchar, DATEADD(second,  DATEDIFF(second, tmStartTime, tmEndTime), 0), 108)

计算总时间,在我的 WPF 应用程序中我做了:

<TextBox Name="Activeto" Text="{Binding Path=TotalEnd,  StringFormat= \hh\:mm\:ss }" Width="60"/>

和code-behind:

TimeSpan timeSpanStart = TimeSpan.Parse(Activefrom.Text);

string 转换为 timespan,可用于在 to 时间之间进行搜索。

我找到了解决办法。最后,我简单地将时间输入 textboxes 分成三个单独的 textboxes,因此:hhmmss。在后面的代码中,我计算了以秒为单位的输入并添加了它们:

int TotalBegin = (int.Parse(TotalStarthh.Text) * 3600) + (int.Parse(TotalStartmm.Text) * 60) + (int.Parse(TotalStartss.Text));
int TotalEnd = (int.Parse(TotalEndhh.Text) * 3600) + (int.Parse(TotalEndmm.Text) * 60) + (int.Parse(TotalEndss.Text));

也许不是最好的解决方案,但对我有用!