using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Documents; using System.Windows.Input; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Navigation; using System.Windows.Shapes; using System.ComponentModel; using System.Collections.ObjectModel; using System.Net; using ThickTcpUiInWindow; using FObjBase; using FLY.Thick.Blowing.IService; using FLY.Thick.Blowing.Client; using FLY.Thick.Blowing.Common; namespace FLY.Thick.Blowing.UI.Fix.Client { /// <summary> /// Page_ProfileBlowing.xaml 的交互逻辑 /// </summary> public partial class Page_ProfileBlowing : Page, INotifyPropertyChanged { private double alarmpercent = 3; public double AlarmPercent { get { return alarmpercent; } set { if (alarmpercent != value) { alarmpercent = value; NotifyPropertyChanged("AlarmPercent"); } } } private double alarm = 3; public double Alarm { get { return alarm; } set { if (alarm != value) { alarm = value; NotifyPropertyChanged("Alarm"); } } } private double target = 30; public double Target { get { return target; } set { if (target != value) { target = value; NotifyPropertyChanged("Target"); } } } public ObservableCollection<string> mList = new ObservableCollection<string>(); public BlowingFixProfileService mProfile = null; bool NeedKeepContext = false; public Page_ProfileBlowing() { InitializeComponent(); } public void Init(IPEndPoint serverep) { mProfile = new BlowingFixProfileService(); FObjBase.FObjSys.Current.Connect_to_Another_OBJSys( serverep, mProfile.ID); this.DataContext = mProfile.Param; this.listview_profile.ItemsSource = mList; this.stackpanel_technological.DataContext = this; AlarmPercent = (double)mProfile.Param.Alarm / mProfile.Param.Target; Alarm = mProfile.Param.Alarm / 100.0; Target = mProfile.Param.Target / 100.0; handler_profile = new PropertyChangedEventHandler(mProfile_PropertyChanged); handler_page_profile = new PropertyChangedEventHandler(Page_Profile_PropertyChanged); this.PropertyChanged += handler_page_profile; mProfile.Param.PropertyChanged += new PropertyChangedEventHandler(mProfile_PropertyChanged); mProfile.GetList( new AsyncCBHandler( delegate(object AsyncState, object retData) { List<string> list = (List<string>)retData; mList.Clear(); for (int i = 0; i < list.Count(); i++) mList.Add(list[i]); if (mList.Contains(mProfile.Param.PName)) { listview_profile.SelectedItem = mList.First(s => s == mProfile.Param.PName); } }), null); } PropertyChangedEventHandler handler_page_profile; PropertyChangedEventHandler handler_profile; void Page_Profile_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (e.PropertyName == "AlarmPercent") { Alarm = Math.Round(Target * AlarmPercent, 2); } else if (e.PropertyName == "Target") { Alarm = Math.Round(Target * AlarmPercent,2); } } void mProfile_PropertyChanged(object sender, PropertyChangedEventArgs e) { if ((e.PropertyName == "Target") || (e.PropertyName == "Alarm")) { FObjBase.PollModule.Current.Poll_JustOnce(delegate() { this.PropertyChanged -= handler_page_profile; AlarmPercent = (double)mProfile.Param.Alarm / mProfile.Param.Target; Alarm = mProfile.Param.Alarm / 100.0; Target = mProfile.Param.Target / 100.0; this.PropertyChanged += handler_page_profile; }, this, 0); } } private void Page_Loaded(object sender, RoutedEventArgs e) { if (NeedKeepContext) { NeedKeepContext = false; return; } } private void button_read_Click(object sender, RoutedEventArgs e) { if (listview_profile.SelectedItem != null) { string productname = listview_profile.SelectedItem as string; mProfile.Read( productname, new AsyncCBHandler( delegate(object AsyncState, object retData) { BlowingFixProfileParam p = (BlowingFixProfileParam)retData; p.CopyTo(mProfile.Param); }), null); } } private void button_apply_Click(object sender, RoutedEventArgs e) { mProfile.Param.PropertyChanged -= handler_profile; mProfile.Param.Target = (int)(Target * 100.0); mProfile.Param.Alarm = (int)(Alarm * 100.0); mProfile.Param.PropertyChanged += handler_profile; //有效性检查 if (mProfile.Param.SolveEnable) { if (mProfile.Param.FilmWidth < 500) { FLY.ControlLibrary.Window_WarningTip.Show("参数出错", "膜宽<500mm 异常"); return; } else if (mProfile.Param.FilmPosH > mProfile.Param.FilmWidth / 3) { FLY.ControlLibrary.Window_WarningTip.Show("参数出错", "探头位置>(膜宽/3) 异常"); return; } else if (mProfile.Param.FilmPosH < 0 ) { FLY.ControlLibrary.Window_WarningTip.Show("参数出错", "探头位置<0 异常"); return; } } if (mProfile.Param.Target <= 0) { FLY.ControlLibrary.Window_WarningTip.Show("参数出错", "目标值<=0 异常"); return; } if (mProfile.Param.Alarm <= 0) { FLY.ControlLibrary.Window_WarningTip.Show("参数出错", "公差<=0 异常"); return; } mProfile.Apply(); if (!mList.Contains(mProfile.Param.PName)) { mList.Add(mProfile.Param.PName); } FLY.ControlLibrary.Window_Tip.Show("应用 & 保存成功", mProfile.Param.PName, TimeSpan.FromSeconds(2)); } private void button_del_Click(object sender, RoutedEventArgs e) { if (listview_profile.SelectedItem != null) { string productname = listview_profile.SelectedItem as string; mProfile.Del(productname); mList.Remove(productname); FLY.ControlLibrary.Window_Tip.Show("删除成功", productname, TimeSpan.FromSeconds(2)); } } private void button_abhelper_Click(object sender, RoutedEventArgs e) { Window_AHelper w = new Window_AHelper(); w.Init(mProfile.Param.Comp); w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this); if (w.ShowDialog() == true) { mProfile.Param.Comp = w.A; } } private void Page_Unloaded(object sender, RoutedEventArgs e) { if (NeedKeepContext) return; mProfile.Dispose(); } #region INotifyPropertyChanged 成员 public event PropertyChangedEventHandler PropertyChanged; protected void NotifyPropertyChanged(string propertyname) { if (PropertyChanged != null) { PropertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyname)); } } #endregion } }