Page_ProfileBlowing.xaml.cs 9.84 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
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
    {
33 34 35
        public double AlarmPercent { get; set; } = 3;

        public double Alarm { get; set; } = 3;
潘栩锋's avatar
潘栩锋 committed
36

37
        public double Target { get; set; } = 30;
潘栩锋's avatar
潘栩锋 committed
38 39

        public ObservableCollection<string> mList = new ObservableCollection<string>();
40
        public BlowingFixProfileServiceClient mProfile = null;
潘栩锋's avatar
潘栩锋 committed
41 42 43 44 45 46 47

        public Page_ProfileBlowing()
        {
            InitializeComponent();
        }
        public void Init(IPEndPoint serverep)
        {
48
            mProfile = new BlowingFixProfileServiceClient();
潘栩锋's avatar
潘栩锋 committed
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127

            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)
        {
        }

        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;
128 129
                        Misc.PropertiesManager.CopyTo<BlowingFixProfileParam>(p, mProfile.Param);
                        
潘栩锋's avatar
潘栩锋 committed
130 131 132 133 134 135 136 137 138 139 140 141
                    }), 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;

            //有效性检查
142
            switch (mProfile.Param.MMode)
潘栩锋's avatar
潘栩锋 committed
143
            {
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198
                case MeasureMode.Edge:
                    break;
                case MeasureMode.Normal:
                    {
                        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;
                        }
                    }break;
                default:
                    //case MeasureMode.Bag:
                    {
                        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;
                        }
                        else if (mProfile.Param.BagFold0 < mProfile.Param.FilmPosH)
                        {
                            FLY.ControlLibrary.Window_WarningTip.Show("参数出错", "探头下的折边 < 探头位置");
                            return;
                        }
                        else if (mProfile.Param.BagFold1 < mProfile.Param.FilmPosH)
                        {
                            FLY.ControlLibrary.Window_WarningTip.Show("参数出错", "另一边的折边 < 探头位置");
                            return;
                        }
                        else if (mProfile.Param.FilmWidth < (mProfile.Param.BagFold0 + mProfile.Param.BagFold1))
                        {
                            FLY.ControlLibrary.Window_WarningTip.Show("参数出错", "折边 >(膜宽/2) 异常");
                            return;
                        }
                    }
                    break;
潘栩锋's avatar
潘栩锋 committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256
            }

            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)
        {
            mProfile.Dispose();
        }
        #region INotifyPropertyChanged 成员

        public event PropertyChangedEventHandler PropertyChanged;
257

潘栩锋's avatar
潘栩锋 committed
258 259 260

        #endregion

261 262 263 264 265 266 267
        private void button_legend_Click(object sender, RoutedEventArgs e)
        {
            Window_ProfileLegend w = new Window_ProfileLegend();
            w.DataContext = mProfile.Param;
            w.Owner = FLY.ControlLibrary.COMMON.GetWindow(this);
            w.ShowDialog();
        }
潘栩锋's avatar
潘栩锋 committed
268 269
    }
}