RecipeInfoConverter.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Data;
  6. using System.Collections.ObjectModel;
  7. namespace Aitex.UI.RecipeEditor
  8. {
  9. public class RecipeInfoConverter : IValueConverter
  10. {
  11. public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  12. {
  13. //try
  14. //{
  15. // if (value == null) return "";
  16. // var recipeRows = value as ObservableCollection<RecipeRow>;
  17. // if (recipeRows == null) return "";
  18. // int timeStepRowId = -1;
  19. // for (int i = 0; i < recipeRows.Count; i++)
  20. // {
  21. // if (recipeRows[i].TechnicalName == "Time")
  22. // {
  23. // timeStepRowId = i;
  24. // break;
  25. // }
  26. // }
  27. // TimeSpan tspan = new TimeSpan();
  28. // for (int stepNo = 0; stepNo < recipeRows[timeStepRowId].RecipeItems.Count; stepNo++)
  29. // {
  30. // var timeDuration = recipeRows[timeStepRowId].RecipeItems[stepNo].Value;
  31. // var timeArr = timeDuration.Split(new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
  32. // if (timeArr.Length == 3)
  33. // {
  34. // int h, mi, s;
  35. // if (int.TryParse(timeArr[0], out h) && int.TryParse(timeArr[1], out mi) && int.TryParse(timeArr[2], out s))
  36. // {
  37. // var ts = new TimeSpan(h, mi, s);
  38. // tspan += ts;
  39. // }
  40. // }
  41. // }
  42. // return string.Format("共{0}步,总时间{1}:{2}:{3}", recipeRows.Count, (int)tspan.TotalHours, tspan.Minutes, tspan.Seconds);
  43. //}
  44. //catch (Exception ex)
  45. //{
  46. // System.Diagnostics.Debug.WriteLine(ex.Message);
  47. //}
  48. return "";
  49. }
  50. public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
  51. {
  52. return null;
  53. }
  54. }
  55. }