JLChen
2021-03-10 4a83749337096aae6dd5ec4f44f16653fbc7268a
HDL_ON/UI/UI2/FuntionControlView/Electrical/ClothesHangerPage.cs
@@ -64,8 +64,6 @@
            //初始化第一个索引页的内容
            this.InitFrameWhiteContent1();
            //刷新当前设备的状态缓存
            this.RefreshNowDeviceStatuMemory(this.device);
            //刷新界面状态
            this.RefreshFormStatu();
            //读取状态
@@ -126,6 +124,62 @@
            };
            FrameWhiteCentet1.AddChidren(btnDown);
            #region 控制
            btnUp.MouseDownEventHandler = (sender, e) => {
                btnUp.IsSelected = true;
            };
            btnUp.MouseUpEventHandler = (sender, e) => {
                new System.Threading.Thread(() =>
                {
                    System.Threading.Thread.Sleep(2000);
                    Application.RunOnMainThread(() =>
                    {
                        btnUp.IsSelected = false;
                    });
                })
                { IsBackground = true }.Start();
                Dictionary<string, string> d = new Dictionary<string, string>();
                d.Add(FunctionAttributeKey.Position, "up");
                Control.Ins.SendWriteCommand(device, d);
            };
            //----
            btnStop.MouseDownEventHandler = (sender, e) => {
                btnStop.IsSelected = true;
            };
            btnStop.MouseUpEventHandler = (sender, e) => {
                new System.Threading.Thread(() =>
                {
                    System.Threading.Thread.Sleep(2000);
                    Application.RunOnMainThread(() =>
                    {
                        btnStop.IsSelected = false;
                    });
                })
                { IsBackground = true }.Start();
                Dictionary<string, string> d = new Dictionary<string, string>();
                d.Add(FunctionAttributeKey.Position, "stop");
                Control.Ins.SendWriteCommand(device, d);
            };
            //-----
            btnDown.MouseDownEventHandler = (sender, e) => {
                btnDown.IsSelected = true;
            };
            btnDown.MouseUpEventHandler = (sender, e) => {
                new System.Threading.Thread(() =>
                {
                    System.Threading.Thread.Sleep(2000);
                    Application.RunOnMainThread(() =>
                    {
                        btnDown.IsSelected = false;
                    });
                })
                { IsBackground = true }.Start();
                Dictionary<string, string> d = new Dictionary<string, string>();
                d.Add(FunctionAttributeKey.Position, "down");
                Control.Ins.SendWriteCommand(device, d);
            };
            #endregion
            #endregion
            #region 菜单
@@ -152,10 +206,12 @@
            {
                FrameWhiteCentet1.AddChidren(hotDryView);
                EventHandler<MouseEventArgs> eventHandler = (sender, e) => {
                    device.SetAttrState(FunctionAttributeKey.HotDry, "true");
                EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
                {
                    string onoff = hotDryView.Lighting ? "false" : "true";
                    device.SetAttrState(FunctionAttributeKey.HotDry, onoff);
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add(FunctionAttributeKey.HotDry, "true");
                    d.Add(FunctionAttributeKey.HotDry, onoff);
                    Control.Ins.SendWriteCommand(device, d);
                };
                hotDryView.SetThouchEvent(eventHandler);
@@ -179,10 +235,12 @@
                }
                FrameWhiteCentet1.AddChidren(windDryView);
                EventHandler<MouseEventArgs> eventHandler = (sender, e) => {
                    device.SetAttrState(FunctionAttributeKey.WindDry, "true");
                EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
                {
                    string onoff = windDryView.Lighting ? "false" : "true";
                    device.SetAttrState(FunctionAttributeKey.WindDry, onoff);
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add(FunctionAttributeKey.WindDry, "true");
                    d.Add(FunctionAttributeKey.WindDry, onoff);
                    Control.Ins.SendWriteCommand(device, d);
                };
                windDryView.SetThouchEvent(eventHandler);
@@ -212,10 +270,12 @@
                }
                FrameWhiteCentet1.AddChidren(disinfectView);
                EventHandler<MouseEventArgs> eventHandler = (sender, e) => {
                    device.SetAttrState(FunctionAttributeKey.Disinfect, "true");
                EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
                {
                    string onoff = disinfectView.Lighting ? "false" : "true";
                    device.SetAttrState(FunctionAttributeKey.Disinfect, onoff);
                    Dictionary<string, string> d = new Dictionary<string, string>();
                    d.Add(FunctionAttributeKey.Disinfect, "true");
                    d.Add(FunctionAttributeKey.Disinfect, onoff);
                    Control.Ins.SendWriteCommand(device, d);
                };
                disinfectView.SetThouchEvent(eventHandler);
@@ -235,7 +295,8 @@
                if(index >2)
                {
                    lightingView.Y = Application.GetRealHeight(409);
                }else
                }
                else
                {
                    lightingView.Y = Application.GetRealHeight(304);
                    if (index == 1)
@@ -249,7 +310,8 @@
                }
                FrameWhiteCentet1.AddChidren(lightingView);
                EventHandler<MouseEventArgs> eventHandler = (sender, e) => {
                EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
                {
                    string onoff = lightingView.Lighting ? "off" : "on";
                    device.SetAttrState(FunctionAttributeKey.OnOff, onoff);
                    Dictionary<string, string> d = new Dictionary<string, string>();
@@ -260,6 +322,32 @@
                index++;
            }
            #endregion
            #region 时间设置
            var timeSetView = new ClothesHangerControl(
                                "FunctionIcon/Electrical/ClothesHanger/ClothesHangerTimeIcon.png",
                                "FunctionIcon/Electrical/ClothesHanger/ClothesHangerTimeIconOn.png",
                                Language.StringByID(StringId.Time),
                                "");
            timeSetView.Width = Application.GetRealWidth(96);
            timeSetView.Height = Application.GetRealHeight(74);
            timeSetView.Y = Application.GetRealHeight(409);
            timeSetView.X = Application.GetRealWidth(266 - 33);
            EventHandler<MouseEventArgs> eventHandler_timeSetView = (sender, e) =>
            {
                var setTimePage = new ClothesHangerSetTimePage(device);
                MainPage.BasePageView.AddChidren(setTimePage);
                setTimePage.LoadPage();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            timeSetView.SetThouchEvent(eventHandler_timeSetView);
            FrameWhiteCentet1.AddChidren(timeSetView);
            #endregion
        }
@@ -276,8 +364,6 @@
            //不是同一个东西
            if (this.device.sid != i_LocalDevice.sid) { return; }
            //刷新当前设备的状态缓存
            this.RefreshNowDeviceStatuMemory(i_LocalDevice);
            //刷新界面状态
            this.RefreshFormStatu();
        }
@@ -295,46 +381,48 @@
        /// </summary>
        private void RefreshFormStatu()
        {
            Application.RunOnMainThread(() => {
            Application.RunOnMainThread(() =>
            {
                btnIcon.IsSelected = true;
                #region 点亮文本
                var hotDryTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.HotDry);
                var hotDryTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.HotDry);
                if (hotDryTemp != null)
                {
                    hotDryView.SetViewStatus(hotDryTemp.value == "true");
                    hotDryView.SetViewStatus(hotDryTemp.state == "true");
                }
                var windDryTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.WindDry);
                var windDryTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.WindDry);
                if (windDryTemp != null)
                {
                    windDryView.SetViewStatus(windDryTemp.value == "true");
                    windDryView.SetViewStatus(windDryTemp.state == "true");
                }
                var disinfectTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.Disinfect);
                var disinfectTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.Disinfect);
                if (disinfectTemp != null)
                {
                    disinfectView.SetViewStatus(disinfectTemp.value == "true");
                    disinfectView.SetViewStatus(disinfectTemp.state == "true");
                }
                var lightTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.OnOff);
                var lightTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.OnOff);
                if (lightTemp != null)
                {
                    lightingView.SetViewStatus(lightTemp.value == "on");
                    lightingView.SetViewStatus(lightTemp.state == "on");
                }
                Console.WriteLine($"时间戳:{device.time_stamp}  时间:{device.GeteTime()} 烘干:{hotDryTemp.state} 风干:{windDryTemp.state} 消毒:{disinfectTemp.state} 灯光状态:{lightTemp.state}");
                #endregion
                #region 修改时间
                var hotDryTimeLeftTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.HotDryTimeLeft);
                var hotDryTimeLeftTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.HotDryTimeLeft);
                if (hotDryTimeLeftTemp != null)
                {
                    hotDryView.ChangeTime(hotDryTimeLeftTemp.value);
                    hotDryView.ChangeTime(hotDryTimeLeftTemp.state);
                }
                var windDryTimeLeftTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.WindDryTimeLeft);
                var windDryTimeLeftTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.WindDryTimeLeft);
                if (windDryTimeLeftTemp != null)
                {
                    windDryView.ChangeTime(windDryTimeLeftTemp.value);
                    windDryView.ChangeTime(windDryTimeLeftTemp.state);
                }
                var disinfectTimeLeftTemp = device.status.Find((sta) => sta.key == FunctionAttributeKey.DisinfectTimeLeft);
                var disinfectTimeLeftTemp = device.attributes.Find((sta) => sta.key == FunctionAttributeKey.DisinfectTimeLeft);
                if (disinfectTimeLeftTemp != null)
                {
                    disinfectView.ChangeTime(disinfectTimeLeftTemp.value);
                    disinfectView.ChangeTime(disinfectTimeLeftTemp.state);
                }
                #endregion
@@ -346,18 +434,6 @@
        #region ■ 一般方法___________________________
        /// <summary>
        /// 刷新当前设备的状态缓存
        /// </summary>
        private void RefreshNowDeviceStatuMemory(Function i_LocalDevice)
        {
            foreach (var data in i_LocalDevice.status)
            {
                //开关
                //if (data.key == "on_off") { this.weepRobotData.Cleaning = data.value.ToLower() == "on"; }
            }
        }
        #endregion
    }
@@ -366,6 +442,10 @@
        private Button btnIcon;
        private Button btnTitle;
        private Button btnTime;
        /// <summary>
        /// 倒计时时间
        /// </summary>
        private int leftTime = 0;
        /// <summary>
        /// 控件是否点亮
        /// </summary>
@@ -397,7 +477,7 @@
            btnTime = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Y = btnTitle.Bottom,
                Y = Application.GetRealHeight(74-32),
                Height = Application.GetRealHeight(32),
                Text = time,
                TextColor = 0x00000000,
@@ -412,37 +492,48 @@
        /// <param name="newTime"></param>
        public void ChangeTime (string newTime)
        {
            if(newTime == "0")
            {
                newTime = "";
            }
            int time = 0;
            int.TryParse(newTime, out time);
            time = time * 60;
            if (countdownThread == null)
            {
                countdownThread = new System.Threading.Thread(() => {
                    while(true)
                    {
                        if(time>1)
            int.TryParse(newTime, out leftTime);
            if (leftTime > 0)
                        {
                            Application.RunOnMainThread(() =>
                            {
                                btnTime.Text = new TimeSpan(0, 0, time).ToString();
                    btnTime.Text = new TimeSpan(0, leftTime, 0).ToString().Remove(5, 3);
                            });
                            System.Threading.Thread.Sleep(1000);
                            time--;
                        }else
                leftTime--;
            }
            else if (leftTime == 0)
                        {
                            Application.RunOnMainThread(() =>
                            {
                                btnTime.Text = "";
                            });
                        }
            if (countdownThread == null)
            {
                countdownThread = new System.Threading.Thread(() =>
                {
                    while (true)
                    {
                        if (leftTime > 0)
                        {
                            Application.RunOnMainThread(() =>
                            {
                                btnTime.Text = new TimeSpan(0, leftTime, 0).ToString().Remove(5,3) ;
                            });
                            leftTime--;
                    }
                }) { IsBackground = true };
                        else if(leftTime == 0)
                        {
                            Application.RunOnMainThread(() =>
                            {
                                btnTime.Text = "";
                            });
                        }
                        System.Threading.Thread.Sleep(60000);
                    }
                })
                { IsBackground = true };
                countdownThread.Start();
            }
        }
@@ -450,11 +541,6 @@
        public void SetViewStatus(bool state)
        {
            btnIcon.IsSelected = btnTitle.IsSelected = btnTime.IsSelected = Lighting = state;
        }
        public bool GetViewState()
        {
            return Lighting;
        }
        /// <summary>