SmartCellData.cs 6.5 KB

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