namespace GDNXFD.Alert.Config.Views { using GalaSoft.MvvmLight.Command; using GDNXFD.Alert.Config.ViewModel; using Data; using System.Windows.Controls; using System; using System.Windows; using System.Windows.Input; /// /// Interaction logic for TravelRequestForm.xaml /// public partial class RuleForm : UserControl { /// /// Travel Request form /// public RuleForm(AlertRule alertRule, FormMode fMode) { var vm = ViewModelLocator.Instance.RuleForm;// (RuleFormViewModel)this.DataContext; vm.InitializeData(alertRule, fMode); this.DataContext = vm; InitializeComponent(); } private void ListBoxDI_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { var obj = sender as ListBox; if (obj != null) { var di = obj.SelectedValue as TestingPointBase; if (di != null && di.UniformCode != null) { string ucode = di.UniformCode; if (!ucode.StartsWith("DI")) { ucode = "DI_" + ucode; } int curPos = txtExpression.SelectionStart; txtExpression.Text = txtExpression.Text.Insert(curPos, ucode); txtExpression.SelectionStart = curPos + ucode.Length; //if (!txtTag.Text.Contains(di.ModelId)) //{ // curPos = txtTag.SelectionStart; // txtTag.Text = txtTag.Text.Insert(curPos, di.ModelId + ","); // txtTag.SelectionStart = curPos + di.ModelId.Length + 1; //} if (!txtTag.Text.Contains(di.Name)) { curPos = txtTag.SelectionStart; txtTag.Text = txtTag.Text.Insert(curPos, di.Name+","); txtTag.SelectionStart = curPos + di.Name.Length +1; } } } } private void ListBoxAI_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { var obj = sender as ListBox; if (obj != null) { var di = obj.SelectedValue as TestingPointBase; if (di != null && di.UniformCode != null) { string ucode = di.UniformCode; if (!ucode.StartsWith("AI")) { ucode = "AI_" + ucode; } int curPos = txtExpression.SelectionStart; txtExpression.Text = txtExpression.Text.Insert(curPos, ucode); txtExpression.SelectionStart = curPos + ucode.Length; //if (!txtTag.Text.Contains(di.ModelId)) //{ // curPos = txtTag.SelectionStart; // txtTag.Text = txtTag.Text.Insert(curPos, di.ModelId + ","); // txtTag.SelectionStart = curPos + di.ModelId.Length + 1; //} if (!txtTag.Text.Contains(di.Name)) { curPos = txtTag.SelectionStart; txtTag.Text = txtTag.Text.Insert(curPos, di.Name + ","); txtTag.SelectionStart = curPos + di.Name.Length + 1; } } } } private void ListBoxSymbol_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { var obj = sender as ListBox; if (obj != null) { var item = obj.SelectedValue as ListBoxItem; if (item != null && item.Content != null) { int curPos = txtExpression.SelectionStart; string value = item.Content.ToString(); txtExpression.Text = txtExpression.Text.Insert(curPos, value); txtExpression.SelectionStart = curPos + value.Length; } } } private void ListBoxMath_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e) { var obj = sender as ListBox; if (obj != null) { var item = obj.SelectedValue as string; if (!string.IsNullOrEmpty(item)) { int curPos = txtExpression.SelectionStart; if ("Sustain".Equals(item) || "RiseExceed".Equals(item) || "MR".Equals(item) || "MAR".Equals(item) || "LastUpdateTime".Equals(item)) { string value = item + "()"; txtExpression.Text = txtExpression.Text.Insert(curPos, value); txtExpression.SelectionStart = curPos + value.Length - 1; } else { string value = string.Format("Math.{0}", item); if ("PI".Equals(item) || "E".Equals(item)) { txtExpression.Text = txtExpression.Text.Insert(curPos, value); } else { value = value + "()"; txtExpression.Text = txtExpression.Text.Insert(curPos, value); txtExpression.SelectionStart = curPos + value.Length - 1; } } } } } } }