SmartCellData.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Windows.Media;
  6. using System.Windows;
  7. using System.ComponentModel;
  8. namespace Aitex.UI.RecipeEditor
  9. {
  10. /// <summary>
  11. /// cell type enum
  12. /// </summary>
  13. public enum CellType
  14. {
  15. ReadOnly,
  16. TextInput,
  17. EditableSelection,
  18. TimeInput,
  19. ReadOnlySelection,
  20. NumInput,
  21. CheckBox
  22. }
  23. /// <summary>
  24. /// reicpe variable definition
  25. /// </summary>
  26. public class RecipeVariableDefine
  27. {
  28. public CellType CellType { get; set; }
  29. public string CatalogName { get; set; }
  30. public string GroupName { get; set; }
  31. public string FriendlyName { get; set; }
  32. public string TechnicalName { get; set; }
  33. public string DeviceType { get; set; }
  34. public string Description { get; set; }
  35. public double MinValue { get; set; }
  36. public double MaxValue { get; set; }
  37. public List<Tuple<string, string>> DropdownItemList { get; set; }
  38. }
  39. /// <summary>
  40. /// cell data definition
  41. /// </summary>
  42. public class SmartCellData : INotifyPropertyChanged
  43. {
  44. public RecipeVariableDefine RecipeVariableDefine { get; set; }
  45. public int RowIndex { get; set; }
  46. public int ColIndex { get; set; }
  47. public bool IsRunning { get; set; }
  48. public bool IsHidden { get; set; }
  49. public bool IsMasked { get; set; }
  50. public Brush Foreground { get; set; }
  51. public Brush Background { get; set; }
  52. public FontWeight FontWeight { get; set; }
  53. public string Value { get; set; }
  54. public string ErrInfo { get; set; }
  55. public object Tag { get; set; }
  56. public string AdditionalInfo { get; set; }
  57. //public bool IsJump { get; set; }
  58. //public bool ShowsJumpControl { get; set; }
  59. public override string ToString()
  60. {
  61. return Display;
  62. }
  63. public string ToolTip
  64. {
  65. get
  66. {
  67. string str = "n/a";
  68. switch (RecipeVariableDefine.CellType)
  69. {
  70. case CellType.NumInput:
  71. str = string.Format("{0}\r\nMax:{1}\r\nValue:{2}", RecipeVariableDefine.FriendlyName, RecipeVariableDefine.MaxValue.ToString("N2").TrimEnd('0').TrimEnd('.').Replace(',', '\''), Display);
  72. break;
  73. default:
  74. str = string.Format("{0}\r\nValue:{1}", RecipeVariableDefine.FriendlyName, string.IsNullOrEmpty(Display) ? "Empty" : Display);
  75. break;
  76. }
  77. if (!string.IsNullOrEmpty(AdditionalInfo))
  78. str += "\r\n" + AdditionalInfo;
  79. if (!string.IsNullOrEmpty(ErrInfo))
  80. str = str + "\r\n\r\nError:" + ErrInfo;
  81. return str;
  82. }
  83. }
  84. public string Display
  85. {
  86. get
  87. {
  88. try
  89. {
  90. if (IsHidden)
  91. return "";
  92. if (IsMasked)
  93. return "*";
  94. if (RecipeVariableDefine.CellType == CellType.ReadOnlySelection && RecipeVariableDefine.DropdownItemList != null)
  95. {
  96. var v = RecipeVariableDefine.DropdownItemList.Find((o) => o.Item1 == Value);
  97. if (v != null) return v.Item2;
  98. }
  99. else if (RecipeVariableDefine.CellType == CellType.CheckBox)
  100. {
  101. if (Tag != null && Tag is int)
  102. {
  103. if (bool.Parse(Value))
  104. return "【√】 " + Tag.ToString();
  105. else
  106. return " " + Tag.ToString();
  107. }
  108. if (bool.Parse(Value))
  109. return "【√】";
  110. return " ";
  111. }
  112. else if (RecipeVariableDefine.CellType == CellType.NumInput)
  113. {
  114. double d;
  115. if (double.TryParse(Value.ToString(), out d))
  116. {
  117. return d.ToString("N2").TrimEnd('0').TrimEnd('.').Replace(',', '\'');
  118. }
  119. }
  120. }
  121. catch (Exception ex)
  122. {
  123. System.Diagnostics.Debug.WriteLine(ex.Message);
  124. }
  125. return Value;
  126. }
  127. }
  128. #region INotifyPropertyChanged
  129. public event PropertyChangedEventHandler PropertyChanged;
  130. public void InvokePropertyChanged()
  131. {
  132. if (PropertyChanged != null)
  133. {
  134. foreach (var pro in this.GetType().GetProperties())
  135. {
  136. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(pro.Name));
  137. }
  138. }
  139. }
  140. public void InvokePropertyChanged(string proName)
  141. {
  142. if (PropertyChanged != null)
  143. {
  144. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(proName));
  145. }
  146. }
  147. #endregion
  148. }
  149. }