RuleForm.xaml.cs 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. namespace GDNXFD.Alert.Config.Views
  2. {
  3. using GalaSoft.MvvmLight.Command;
  4. using GDNXFD.Alert.Config.ViewModel;
  5. using Data;
  6. using System.Windows.Controls;
  7. using System;
  8. using System.Windows;
  9. using System.Windows.Input;
  10. /// <summary>
  11. /// Interaction logic for TravelRequestForm.xaml
  12. /// </summary>
  13. public partial class RuleForm : UserControl
  14. {
  15. /// <summary>
  16. /// Travel Request form
  17. /// </summary>
  18. public RuleForm(AlertRule alertRule, FormMode fMode)
  19. {
  20. var vm = ViewModelLocator.Instance.RuleForm;// (RuleFormViewModel)this.DataContext;
  21. vm.InitializeData(alertRule, fMode);
  22. this.DataContext = vm;
  23. InitializeComponent();
  24. }
  25. private void ListBoxDI_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
  26. {
  27. var obj = sender as ListBox;
  28. if (obj != null)
  29. {
  30. var di = obj.SelectedValue as TestingPointBase;
  31. if (di != null && di.UniformCode != null)
  32. {
  33. string ucode = di.UniformCode;
  34. if (!ucode.StartsWith("DI"))
  35. {
  36. ucode = "DI_" + ucode;
  37. }
  38. int curPos = txtExpression.SelectionStart;
  39. txtExpression.Text = txtExpression.Text.Insert(curPos, ucode);
  40. txtExpression.SelectionStart = curPos + ucode.Length;
  41. //if (!txtTag.Text.Contains(di.ModelId))
  42. //{
  43. // curPos = txtTag.SelectionStart;
  44. // txtTag.Text = txtTag.Text.Insert(curPos, di.ModelId + ",");
  45. // txtTag.SelectionStart = curPos + di.ModelId.Length + 1;
  46. //}
  47. if (!txtTag.Text.Contains(di.Name))
  48. {
  49. curPos = txtTag.SelectionStart;
  50. txtTag.Text = txtTag.Text.Insert(curPos, di.Name+",");
  51. txtTag.SelectionStart = curPos + di.Name.Length +1;
  52. }
  53. }
  54. }
  55. }
  56. private void ListBoxAI_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
  57. {
  58. var obj = sender as ListBox;
  59. if (obj != null)
  60. {
  61. var di = obj.SelectedValue as TestingPointBase;
  62. if (di != null && di.UniformCode != null)
  63. {
  64. string ucode = di.UniformCode;
  65. if (!ucode.StartsWith("AI"))
  66. {
  67. ucode = "AI_" + ucode;
  68. }
  69. int curPos = txtExpression.SelectionStart;
  70. txtExpression.Text = txtExpression.Text.Insert(curPos, ucode);
  71. txtExpression.SelectionStart = curPos + ucode.Length;
  72. //if (!txtTag.Text.Contains(di.ModelId))
  73. //{
  74. // curPos = txtTag.SelectionStart;
  75. // txtTag.Text = txtTag.Text.Insert(curPos, di.ModelId + ",");
  76. // txtTag.SelectionStart = curPos + di.ModelId.Length + 1;
  77. //}
  78. if (!txtTag.Text.Contains(di.Name))
  79. {
  80. curPos = txtTag.SelectionStart;
  81. txtTag.Text = txtTag.Text.Insert(curPos, di.Name + ",");
  82. txtTag.SelectionStart = curPos + di.Name.Length + 1;
  83. }
  84. }
  85. }
  86. }
  87. private void ListBoxSymbol_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
  88. {
  89. var obj = sender as ListBox;
  90. if (obj != null)
  91. {
  92. var item = obj.SelectedValue as ListBoxItem;
  93. if (item != null && item.Content != null)
  94. {
  95. int curPos = txtExpression.SelectionStart;
  96. string value = item.Content.ToString();
  97. txtExpression.Text = txtExpression.Text.Insert(curPos, value);
  98. txtExpression.SelectionStart = curPos + value.Length;
  99. }
  100. }
  101. }
  102. private void ListBoxMath_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
  103. {
  104. var obj = sender as ListBox;
  105. if (obj != null)
  106. {
  107. var item = obj.SelectedValue as string;
  108. if (!string.IsNullOrEmpty(item))
  109. {
  110. int curPos = txtExpression.SelectionStart;
  111. if ("Sustain".Equals(item)
  112. || "RiseExceed".Equals(item)
  113. || "MR".Equals(item)
  114. || "MAR".Equals(item)
  115. || "LastUpdateTime".Equals(item))
  116. {
  117. string value = item + "()";
  118. txtExpression.Text = txtExpression.Text.Insert(curPos, value);
  119. txtExpression.SelectionStart = curPos + value.Length - 1;
  120. }
  121. else
  122. {
  123. string value = string.Format("Math.{0}", item);
  124. if ("PI".Equals(item)
  125. || "E".Equals(item))
  126. {
  127. txtExpression.Text = txtExpression.Text.Insert(curPos, value);
  128. }
  129. else
  130. {
  131. value = value + "()";
  132. txtExpression.Text = txtExpression.Text.Insert(curPos, value);
  133. txtExpression.SelectionStart = curPos + value.Length - 1;
  134. }
  135. }
  136. }
  137. }
  138. }
  139. }
  140. }