PgTempAreaParam.xaml.cs 4.18 KB
Newer Older
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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
using FLY.DownBlowing.Client;
using FLY.DownBlowing.Common;
using FLY.DownBlowing.IService;
using FObjBase.Reflect;
using System.Collections.Generic;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using Unity;

namespace FLY.DownBlowing.UI.Client
{
    /// <summary>
    /// Page_System.xaml 的交互逻辑
    /// </summary>
    public partial class PgTempAreaParam : Page
    {
        IDownBlowingSystemService downBlowingSystemService;
        TempArea tempArea;
        FLY.OBJComponents.Client.SetPLCUpdatePlan setPlan;

        static string[] update_propertynames;
        static PgTempAreaParam()
        {

            string[] propertynames = new string[] {
                nameof(Common.TempArea.TempPV1),
                nameof(Common.TempArea.Channel1),
                nameof(Common.TempArea.PSet1),
                nameof(Common.TempArea.IsPChanged1),
                nameof(Common.TempArea.ISet1),
                nameof(Common.TempArea.IsIChanged1),
                nameof(Common.TempArea.DSet1),
                nameof(Common.TempArea.IsDChanged1),
                nameof(Common.TempArea.TempCorr1),
                nameof(Common.TempArea.CoolingSet1),
                nameof(Common.TempArea.IsSelfAdjusting1),
                nameof(Common.TempArea.IsSelfAdjustingSet1),

                nameof(Common.TempArea.P1),
                nameof(Common.TempArea.I1),
                nameof(Common.TempArea.D1)
            };
            List<string> update_propertynames = new List<string>();
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < propertynames.Count(); j++)
                {
                    update_propertynames.Add(propertynames[i].Replace("1", (i + 1).ToString()));
                }
            }

            PgTempAreaParam.update_propertynames = update_propertynames.ToArray();
        }
        public PgTempAreaParam()
        {
            InitializeComponent();
        }

        [InjectionMethod]
        public void Init(
             IDownBlowingSystemService downBlowingSystemService,
             TempArea tempArea)

        {
            this.downBlowingSystemService = downBlowingSystemService;

            //注册属性更新计划
潘栩锋's avatar
潘栩锋 committed
69 70 71 72
            int index = this.downBlowingSystemService.TAreas.IndexOf(tempArea);

            string objname = $"{nameof(IDownBlowingSystemService.TAreas)}[{index}]";

73 74
            setPlan = new FLY.OBJComponents.Client.SetPLCUpdatePlan(
                downBlowingSystemService.PLCos,
潘栩锋's avatar
潘栩锋 committed
75
                objname,
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 128
                update_propertynames);
            this.tempArea = tempArea;
            this.DataContext = tempArea;

            for (int i = 0; i < tempArea.Temperatures.Count(); i++)
            {
                tempArea.Temperatures[i].PropertyChanged += PgTempAreaParam_PropertyChanged;
            }
        }

        private void PgTempAreaParam_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
        {
            if (downBlowingSystemService is Reflect_SeviceClient)
            {
                var client = downBlowingSystemService as Reflect_SeviceClient;
                if (client.IsInPushValue)
                    return;
            }

            var tempCell = sender as TempCell;
            if (e.PropertyName == nameof(TempCell.PSet))
            {
                tempCell.IsPChanged = true;
            }
            else if (e.PropertyName == nameof(TempCell.ISet))
            {
                tempCell.IsIChanged = true;
            }
            else if (e.PropertyName == nameof(TempCell.DSet))
            {
                tempCell.IsDChanged = true;
            }
        }

        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            for (int i = 0; i < tempArea.Temperatures.Count(); i++)
            {
                tempArea.Temperatures[i].PropertyChanged -= PgTempAreaParam_PropertyChanged;
            }
            setPlan.Dispose();
        }

        private void btnATClick(object sender, RoutedEventArgs e)
        {


            var button = sender as Button;
            var tempCell = button.Tag as TempCell;
            tempCell.IsSelfAdjustingSet = !tempCell.IsSelfAdjustingSet;
        }
    }
}