本文整理汇总了C#中System.TimeSpan.FormatAsString方法的典型用法代码示例。如果您正苦于以下问题:C# TimeSpan.FormatAsString方法的具体用法?C# TimeSpan.FormatAsString怎么用?C# TimeSpan.FormatAsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.TimeSpan
的用法示例。
在下文中一共展示了TimeSpan.FormatAsString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteButton
private async void DeleteButton(object sender, RoutedEventArgs e)
{
var selected = DataModel.LockedTimers.Where(x => x.IsSelected).ToList();
if (selected.Count == 0)
{
await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Nothing Selected", "You Have Not Selected Any Locked Time To Delete");
Focus();
return;
}
var selectedTime = new TimeSpan();
selectedTime = selected.Aggregate(selectedTime, (current, lockedTimerModel) => current.Add(lockedTimerModel.IdleTime));
var result = await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Are You Sure?", $"Are you Sure You Want To Delete Locked Timers Worth {selectedTime.FormatAsString(false)}?", MessageDialogStyle.AffirmativeAndNegative, new MetroDialogSettings { AffirmativeButtonText = "Yes", NegativeButtonText = "No", DefaultButtonFocus = MessageDialogResult.Affirmative });
if (result == MessageDialogResult.Affirmative)
{
foreach (var lockedTimerModel in selected)
{
modelHelpers.Gallifrey.IdleTimerCollection.RemoveTimer(lockedTimerModel.UniqueId);
}
if (!modelHelpers.Gallifrey.IdleTimerCollection.GetUnusedLockTimers().Any())
{
modelHelpers.CloseFlyout(this);
return;
}
DataModel.RefreshLockedTimers(modelHelpers.Gallifrey.IdleTimerCollection.GetUnusedLockTimers());
}
Focus();
}
示例2: AddButton
private async void AddButton(object sender, RoutedEventArgs e)
{
var selected = DataModel.LockedTimers.Where(x => x.IsSelected).ToList();
if (selected.Count == 0)
{
await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Nothing Selected", "You Have Not Selected Any Locked Time To Add");
Focus();
return;
}
var selectedTimers = selected.Select(x => modelHelpers.Gallifrey.IdleTimerCollection.GetTimer(x.UniqueId)).Where(x => x != null).ToList();
if (selected.Count != selectedTimers.Count)
{
await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Out Of Date", "The Timer Window Is Out Of Date And Needs To Be Refreshed");
DataModel.RefreshLockedTimers(modelHelpers.Gallifrey.IdleTimerCollection.GetUnusedLockTimers());
Focus();
return;
}
var selectedTime = new TimeSpan();
var lockedTimerDate = DateTime.MinValue;
foreach (var lockedTimerModel in selected)
{
if (lockedTimerDate == DateTime.MinValue || lockedTimerDate.Date == lockedTimerModel.DateForTimer)
{
lockedTimerDate = lockedTimerModel.DateForTimer;
selectedTime = selectedTime.Add(lockedTimerModel.IdleTime);
}
else
{
await DialogCoordinator.Instance.ShowMessageAsync(modelHelpers.DialogContext, "Invalid Selection", "All Timers Must Be On The Same Date!");
Focus();
return;
}
}
JiraTimer runningTimer = null;
var runningTimerId = modelHelpers.Gallifrey.JiraTimerCollection.GetRunningTimerId();
if (runningTimerId.HasValue)
{
runningTimer = modelHelpers.Gallifrey.JiraTimerCollection.GetTimer(runningTimerId.Value);
if (runningTimer.DateStarted.Date != lockedTimerDate.Date)
{
runningTimer = null;
}
}
var dialog = (BaseMetroDialog)this.Resources["TimeLocation"];
await DialogCoordinator.Instance.ShowMetroDialogAsync(modelHelpers.DialogContext, dialog);
var message = dialog.FindChild<TextBlock>("Message");
var runningTimerButton = dialog.FindChild<Button>("RunningTimerButton");
if (runningTimer != null)
{
message.Text = $"Where Would You Like To Add The Time Worth {selectedTime.FormatAsString(false)}?\n\nNote:- Running Timer Is\n{runningTimer.JiraReference} - {runningTimer.JiraName}";
runningTimerButton.Visibility = Visibility.Visible;
}
else
{
message.Text = $"Where Would You Like To Add The Time Worth {selectedTime.FormatAsString(false)}?";
runningTimerButton.Visibility = Visibility.Collapsed;
}
await dialog.WaitUntilUnloadedAsync();
}
示例3: SetExportTargetStats
private void SetExportTargetStats()
{
var exportedTime = gallifrey.JiraTimerCollection.GetTotalExportedTimeThisWeek();
var target = new TimeSpan();
var n = 0;
while (n++ < (int)DateTime.Today.DayOfWeek)
{
target = target.Add(gallifrey.AppSettings.TargetLogPerDay);
}
lblExportedWeek.Text = string.Format("Exported: {0}", exportedTime.FormatAsString(false));
lblExportTargetWeek.Text = string.Format("Target: {0}", target.FormatAsString(false));
progExportTarget.Maximum = (int)target.TotalMinutes;
progExportTarget.Value = (int)exportedTime.TotalMinutes;
}