using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows.Input; using Aitex.UI.Charting.ViewModel; using System.Windows; using Aitex.UI.Charting.Model; using Abt.Controls.SciChart; using Abt.Controls.SciChart.Model.DataSeries; using DataAnalysisControl.Core; namespace Aitex.UI.Charting.Command { public class ChangeFactorOffsetCommand : ICommand { public ChangeFactorOffsetCommand(string uniqueDataId, double newFactor, double newOffset) { _newFactor = (float)newFactor; _newOffset = (float)newOffset; _uniqueDataId = uniqueDataId; } string _uniqueDataId = ""; float _newFactor = 1; float _newOffset = 0; public bool CanExecute(object parameter) { return true; } #pragma warning disable 0067 public event EventHandler CanExecuteChanged; #pragma warning restore 0067 private void AsyncShowWarningMessageBox(string message, string title) { Application.Current.Dispatcher.BeginInvoke(new Action(() => MessageBox.Show(message, title, MessageBoxButton.OK, MessageBoxImage.Warning))); } public void Execute(object parameter) { string reason = string.Empty; try { var commonViewModel = (CommonViewModel)parameter; var myLine = commonViewModel.GetDataLineSeries(_uniqueDataId); if (myLine == null) { reason = string.Format("数据名称{0}不存在", _uniqueDataId); AsyncShowWarningMessageBox(reason, "警告"); } else { var dataList = new List(); var timeList = new List(); for (int i = 0; i < myLine.Points.RawData.Count; i++) { dataList.Add(myLine.Points.RawData[i] * _newFactor + _newOffset); timeList.Add(myLine.Points.TimeStamp[i] + myLine.DataSource.TimeMove); } var dataSet = myLine.DataSeries as XyDataSeries; if (dataSet != null && dataList.Count > 0) { dataSet.Clear(); dataSet.Append(timeList, dataList); } commonViewModel.InvokePropertyChanged(); } } catch (Exception ex) { reason = ex.Message; CONTEXT.WriteLog(ex, string.Format("改变数据{0}的缩放因子及偏差值发生异常", _uniqueDataId)); AsyncShowWarningMessageBox(reason, "警告"); } } } }