DynAreaWinder.xaml.cs 6.94 KB
Newer Older
潘栩锋's avatar
潘栩锋 committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
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.Windows.Threading;
using FLY.OBJComponents.Client;
using FLY.OBJComponents.Common;
潘栩锋's avatar
潘栩锋 committed
19 20 21
using FLY.OBJComponents.IService;
using FLY.Thick.Base.UI;
using FLY.Winder.IService;
潘栩锋's avatar
潘栩锋 committed
22
using FLY.Winder.UI.Client;
潘栩锋's avatar
潘栩锋 committed
23 24 25 26
using FObjBase;
using MultiLayout;
using MultiLayout.UiModule;
using Unity;
潘栩锋's avatar
潘栩锋 committed
27

潘栩锋's avatar
潘栩锋 committed
28
namespace FLY.Winder.UI.Client.UiModule
潘栩锋's avatar
潘栩锋 committed
29 30 31 32
{
    /// <summary>
    /// Page_DynArea.xaml 的交互逻辑
    /// </summary>
潘栩锋's avatar
潘栩锋 committed
33
    public partial class DynAreaWinder : UserControl
潘栩锋's avatar
潘栩锋 committed
34 35 36 37 38 39
    {

        #region 延时推送 MARKNO
        const int MARKNO_UPDATEERROR = 1;
        #endregion

潘栩锋's avatar
潘栩锋 committed
40 41 42 43 44
        IUnityContainer container;
        IWinderSystemService winderSystem;
        WarningReasonWindow warningReasonWindow;
        IWarningService warningService;

潘栩锋's avatar
潘栩锋 committed
45 46 47 48 49
        DispatcherTimer timer_error;
        DynAreaViewModelParams props = new DynAreaViewModelParams();
        SetPLCUpdatePlan setPlan_accessory;
        SetPLCUpdatePlan[] setPlan_winders = new SetPLCUpdatePlan[2];

潘栩锋's avatar
潘栩锋 committed
50
        public DynAreaWinder()
潘栩锋's avatar
潘栩锋 committed
51 52 53 54
        {
            InitializeComponent();

        }
潘栩锋's avatar
潘栩锋 committed
55 56 57 58 59 60
        [InjectionMethod]
        public void Init(
            IUnityContainer container,
            [Dependency("winderWarningReasonWindow")] WarningReasonWindow warningReasonWindow,
            [Dependency("winderWarningService")]IWarningService warningService,
            IWinderSystemService winderSystemService)
潘栩锋's avatar
潘栩锋 committed
61
        {
潘栩锋's avatar
潘栩锋 committed
62 63
            this.container = container;
            winderSystem = winderSystemService;
潘栩锋's avatar
潘栩锋 committed
64 65

            //创建窗口观察 报警原因列表
潘栩锋's avatar
潘栩锋 committed
66 67
            this.warningReasonWindow = warningReasonWindow;
            this.warningService = warningService;
潘栩锋's avatar
潘栩锋 committed
68 69 70 71 72 73 74 75

            //报警原因轮流显示
            timer_error = new DispatcherTimer();
            timer_error.Interval = TimeSpan.FromSeconds(3);
            timer_error.Tick += (s, e) =>
            {
                reason_list_index--;
                if (reason_list_index < 0)
潘栩锋's avatar
潘栩锋 committed
76
                    reason_list_index = warningReasonWindow.Record.Count();
潘栩锋's avatar
潘栩锋 committed
77 78
                updateError();
            };
潘栩锋's avatar
潘栩锋 committed
79
            warningReasonWindow.Record.CollectionChanged += Record_CollectionChanged;
潘栩锋's avatar
潘栩锋 committed
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



            grid_winder.DataContext = winderSystem;
            grid_error.DataContext = props;

            //注册属性更新计划
            setPlan_accessory = new SetPLCUpdatePlan(
                winderSystem.PLCos,
                winderSystem.Accessory,
                new string[] 
                {
                    "Velocity"
                });
            for (int i = 0; i < 2; i++)
            {
                setPlan_winders[i] = new SetPLCUpdatePlan(
                    winderSystem.PLCos,
                    winderSystem.Items[i],
                    new string[] 
                    {
                        "MeasureLen",
                        "MeasurePreWarning"
                    });
            }

            winderSystem.PropertyChanged += (s, e) =>
            {
                if (e.PropertyName == "IsConnected")
                {
                    updateError();
                }
            };

            updateError();
        }


        private void Record_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
        {
            FObjBase.PollModule.Current.Poll_JustOnce(
                new FObjBase.PollModule.PollHandler(delegate ()
                {
潘栩锋's avatar
潘栩锋 committed
123
                    reason_list_index = warningReasonWindow.Record.Count() - 1;
潘栩锋's avatar
潘栩锋 committed
124 125 126 127 128 129 130

                    updateError();
                }), this, MARKNO_UPDATEERROR);
        }

        void updateError()
        {
潘栩锋's avatar
潘栩锋 committed
131
            if (winderSystem is FObjServiceClient)
潘栩锋's avatar
潘栩锋 committed
132
            {
潘栩锋's avatar
潘栩锋 committed
133 134 135 136 137 138 139 140 141
                
                if (!(winderSystem as FObjServiceClient).IsConnected)
                {
                    props.Error = "收卷服务器连接断开";
                    props.IsError = true;
                    reason_list_index = -1;
                    timer_error.Stop();
                    return;
                }
潘栩锋's avatar
潘栩锋 committed
142 143
            }

潘栩锋's avatar
潘栩锋 committed
144
            if (warningReasonWindow.Record.Count == 0)
潘栩锋's avatar
潘栩锋 committed
145 146 147 148 149
            {
                props.IsError = false;
                props.Error = "";
                reason_list_index = -1;
                timer_error.Stop();
潘栩锋's avatar
潘栩锋 committed
150
                return;
潘栩锋's avatar
潘栩锋 committed
151
            }
潘栩锋's avatar
潘栩锋 committed
152 153 154 155 156 157 158 159 160 161 162 163

            
            if (reason_list_index >= warningReasonWindow.Record.Count)
                reason_list_index = warningReasonWindow.Record.Count - 1;
            else if (reason_list_index < 0)
                reason_list_index = 0;


            props.Error = warningReasonWindow.Record[reason_list_index].Description;
            props.IsError = true;
            timer_error.Start();

潘栩锋's avatar
潘栩锋 committed
164 165 166 167 168 169 170
        }
        private int reason_list_index = -1;



        private void Button_Click(object sender, RoutedEventArgs e)
        {
潘栩锋's avatar
潘栩锋 committed
171 172 173
            PgErrorTable2 p = new PgErrorTable2();
            p.Init(container, warningService, warningReasonWindow);
            FlyLayoutManager.NavigationService.Navigate(p);
潘栩锋's avatar
潘栩锋 committed
174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189
        }
    }
    public class DynAreaViewModelParams : INotifyPropertyChanged
    {
        /// <summary>
        /// 有异常
        /// </summary>
        public bool IsError { get; set; }
        /// <summary>
        /// 异常消息
        /// </summary>
        public string Error { get; set; }

        public event PropertyChangedEventHandler PropertyChanged;
    }

潘栩锋's avatar
潘栩锋 committed
190
    public class UiModule2_DynAreaWinder : IUiModule2
潘栩锋's avatar
潘栩锋 committed
191 192 193 194 195
    {
        /// <summary>
        /// 控件标题
        /// 它的值取决于culture
        /// </summary>
潘栩锋's avatar
潘栩锋 committed
196 197 198
        public string Title=>"收卷状态";
        public ComponentType Type => ComponentType.DynArea;
        public bool IsUnique => true;
潘栩锋's avatar
潘栩锋 committed
199 200 201 202 203 204
        /// <summary>
        /// 控件
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
潘栩锋's avatar
潘栩锋 committed
205
        public FrameworkElement GetComponent(int id,IUnityContainer container)
潘栩锋's avatar
潘栩锋 committed
206
        {
潘栩锋's avatar
潘栩锋 committed
207 208
            DynAreaWinder graph = new DynAreaWinder();
            container.BuildUp(graph);
潘栩锋's avatar
潘栩锋 committed
209 210 211 212 213 214 215 216 217
            return graph;
        }

        /// <summary>
        /// 控件缩略图,用于编辑界面时,大致看看
        /// 创建时,需要给它唯一ID,让加载自己的数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
潘栩锋's avatar
潘栩锋 committed
218
        public FrameworkElement GetThumbnail()
潘栩锋's avatar
潘栩锋 committed
219 220 221 222 223 224 225 226 227 228 229 230 231 232
        {
            return new System.Windows.Controls.Grid();
        }


        /// <summary>
        /// 给出全部控件ID, 控件自行删除没有的参数
        /// </summary>
        /// <param name="IDs"></param>
        public void MatchParam(int[] IDs)
        {
        }
    }
}