From 9b44e30275621a48335fbea7b32b5065a2859c9c Mon Sep 17 00:00:00 2001
From: wxr <464027401@qq.com>
Date: 星期二, 16 三月 2021 16:54:33 +0800
Subject: [PATCH] Merge branch 'WJC' into temp-wxr

---
 HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs |  409 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 220 insertions(+), 189 deletions(-)

diff --git a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs
index 8ba618f..6af3af1 100644
--- a/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs
+++ b/HDL_ON/UI/UI2/4-PersonalCenter/PirDevice/DeviceSet.cs
@@ -11,234 +11,265 @@
         {
             Tag = "PirView";
         }
-        public void Show() {
+        public void Show(Action action)
+        {
             #region 鐣岄潰甯冨眬
             this.BackgroundColor = CSS.CSS_Color.viewMiddle;
             PirDevice.View.TopView topView = new View.TopView();
             topView.topNameBtn.TextID = StringId.shebeigaunli;
             topView.topIconBtn.Visible = true;
             this.AddChidren(topView.FLayoutView());
-            topView.clickBackBtn.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent(); };
-            VerticalScrolViewLayout vv = new VerticalScrolViewLayout();
+            topView.clickBackBtn.MouseUpEventHandler += (sender, e) =>
+            {
+                action();
+                this.RemoveFromParent();
+            };
+            VerticalRefreshLayout vv = new VerticalRefreshLayout();
             vv.Height = Application.GetRealHeight(667 - 64);
             vv.Y = Application.GetRealHeight(64);
             this.AddChidren(vv);
-            #endregion
-            int a = 3;
-            int b = 3;
-            for (int i = 0; i < b; i++)
+            vv.BeginHeaderRefreshingAction += () =>
             {
+                //鍏抽棴鍒锋柊View锛�
+                vv.EndHeaderRefreshing();
+                //鑾峰彇鍒楄〃
+                Method.GetPirDeviceList(this, () =>
+                 {
+                     Application.RunOnMainThread(() =>
+                     {
+                         //鍒锋柊鐣岄潰
+                         UIView(vv);
+                     });
+                 });
+
+            };
+            #endregion
+            UIView(vv);
+
+        }
+        /// <summary>
+        /// 鍔犺浇UI鐣岄潰
+        /// </summary>
+        /// <param name="vv">涓婁笅婊戞帶浠�</param>
+        void UIView(VerticalRefreshLayout vv)
+        {
+            vv.RemoveAll();
+            for (int i = 0; i < Pir.pirDeviceList.Count; i++)
+            {
+                var pirDevice = Pir.pirDeviceList[i];
                 #region 绾㈠瀹濆浘鏍� 鐗堟湰鍙� 鍚嶇О 鐘舵��
                 FrameLayout fLayout = new FrameLayout
                 {
                     Width = Application.GetRealWidth(375),
-                    Height = Application.GetRealHeight(12+92+(50* a)),
+                    Height = Application.GetRealHeight(12 + 92 + (50 * pirDevice.FunctioList.Count)),
                 };
                 vv.AddChidren(fLayout);
-               
-                //绾㈠瀹濇樉绀虹埗鎺т欢
-                FrameLayout devfLayout = new FrameLayout
-                {
-                    Y = Application.GetRealHeight(12),
-                    X = Application.GetRealWidth(16),
-                    Width = Application.GetRealWidth(375-16*2),
-                    Height = Application.GetRealHeight(92 + (50 * a)),
-                    BackgroundColor = CSS.CSS_Color.view,
-                    Radius = (uint)Application.GetRealHeight(12),
-                };
-                fLayout.AddChidren(devfLayout);
-                //绾㈠瀹濆浘鏍�
-                Button priequipmentBtn = new Button
-                {
-                    Y=Application.GetRealHeight(16),
-                    X = Application.GetRealWidth(5),
-                    Width = Application.GetRealWidth(60),
-                    Height = Application.GetRealWidth(60),
-                    UnSelectedImagePath = "PirIcon/priequipment.png",
-                    TextAlignment = TextAlignment.Center,
-                };
-                devfLayout.AddChidren(priequipmentBtn);
+                View.PirView pirView = new View.PirView();
                 //绾㈠瀹濆悕绉�
-                Button deviceNameBtn = new Button
+                pirView.deviceNameBtn.Text = pirDevice.name;
+                //绾㈠瀹濆綋鍓嶆湁澶氬皯涓仴鎺у櫒
+                pirView.geBtn.Text = pirDevice.FunctioList.Count.ToString();
+                //绾㈠瀹濇槸鍚﹀湪绾�-绂荤嚎
+                if (pirDevice.online)
                 {
-                    Y=Application.GetRealHeight(16),
-                    X = priequipmentBtn.Right + Application.GetRealWidth(7),
-                    Width = Application.GetRealWidth(120),
-                    Height = Application.GetRealHeight(20),
-                    Text = "绾㈠瀹滱"+i.ToString(),
-                    TextAlignment = TextAlignment.CenterLeft,
-                    TextSize = TextSize.text14,
-                    TextColor = CSS.CSS_Color.textColor,
-                    IsBold = true,
-                };
-                devfLayout.AddChidren(deviceNameBtn);
-                //鐗堟湰鍙�
-                Button versionBtn = new Button
+                    pirView.stateIconBtn.IsSelected = true;
+                    pirView.stateTextBtn.IsSelected = true;
+                }
+                else
                 {
-                    Y = deviceNameBtn.Bottom+ Application.GetRealHeight(4),
-                    X = priequipmentBtn.Right + Application.GetRealWidth(7),
-                    Width = Application.GetRealWidth(120),
-                    Height = Application.GetRealHeight(17),
-                    Text = "鐗堟湰鍙穠1.3.5",
-                    TextAlignment = TextAlignment.CenterLeft,
-                    TextSize = TextSize.text12,
-                    TextColor = CSS.CSS_Color.textCancelColor,
-                };
-                devfLayout.AddChidren(versionBtn);
-                // 5/10
-                Button geBtn = new Button
+                    pirView.stateIconBtn.IsSelected = false;
+                    pirView.stateTextBtn.IsSelected = false;
+                }
+                //鏍囪绾㈠瀹�
+                pirView.clickBtn.Tag = pirDevice;
+                //绾㈠瀹濈偣鍑讳簨浠�
+                pirView.clickBtn.MouseUpEventHandler += (sender, e) =>
                 {
-                    Y = versionBtn.Bottom + Application.GetRealHeight(2),
-                    X = priequipmentBtn.Right + Application.GetRealWidth(7),
-                    Width = Application.GetRealWidth(120),
-                    Height = Application.GetRealHeight(17),
-                    Text = "2",
-                    TextAlignment = TextAlignment.CenterLeft,
-                    TextSize = TextSize.text12,
-                    TextColor = CSS.CSS_Color.textConfirmColor,
+                    var pirclick = (pirView.clickBtn.Tag as Pir);
+                    NewSwitchView(pirclick, vv);
                 };
-                devfLayout.AddChidren(geBtn);
-                geBtn.Width = geBtn.GetTextWidth();
-                // 5/10
-                Button sumBtn = new Button
-                {
-                    Y = versionBtn.Bottom + Application.GetRealHeight(2),
-                    X = geBtn.Right,
-                    Width = Application.GetRealWidth(20),
-                    Height = Application.GetRealHeight(17),
-                    Text ="/10",
-                    TextAlignment = TextAlignment.CenterLeft,
-                    TextSize = TextSize.text12,
-                    TextColor = CSS.CSS_Color.textCancelColor,
-                };
-                devfLayout.AddChidren(sumBtn);
-                //鐘舵�佸浘鏍�
-                Button stateIconBtn = new Button
-                {
-                    Y =Application.GetRealHeight(23),
-                    X = Application.GetRealWidth(291),
-                    Width = Application.GetRealWidth(8),
-                    Height = Application.GetRealWidth(8),
-                    UnSelectedImagePath = "PirIcon/online.png",
-                };
-                devfLayout.AddChidren(stateIconBtn);
-                //绾㈠瀹濈姸鎬侊紙鍦ㄧ嚎-绂荤嚎锛�
-                Button stateTextBtn = new Button
-                {
-                    Y = Application.GetRealHeight(18),
-                    X = Application.GetRealWidth(303),
-                    Width = Application.GetRealWidth(30),
-                    Height = Application.GetRealHeight(17),
-                    TextID=StringId.zaixianhwb,
-                    TextAlignment = TextAlignment.CenterLeft,
-                    TextSize = TextSize.text12,
-                    TextColor = 0xFF67D569,// CSS.CSS_Color.textColor,
-                    IsBold=true,
-                };
-                devfLayout.AddChidren(stateTextBtn);
-                //绾�
-                Button lineBtn = new Button
-                {
-                    Y = Application.GetRealHeight(92)-1,
-                    X = Application.GetRealWidth(16),
-                    Width = Application.GetRealWidth(343-16*2),
-                    Height =1,
-                    BackgroundColor = CSS.CSS_Color.viewLine,
-                };
-                devfLayout.AddChidren(lineBtn);
-
-                if (b - 1 == i)
+                //鍔犺浇鐣岄潰
+                pirView.Show(pirDevice.FunctioList.Count, fLayout);
+                if (Pir.pirDeviceList.Count - 1 == i)
                 {
                     //鏈�鍚庝竴涓悗闈㈠鍔犻棿闅旇儗鏅�
                     vv.AddChidren(new FrameLayout { Height = Application.GetRealHeight(20) });
                 }
                 #endregion
 
-                for (int j = 0; j < a; j++) {
-                    RowLayout funControlRow = new RowLayout
-                    {
-                        Y = Application.GetRealHeight(92 + (50 * j)),
-                        Width = Application.GetRealWidth(375 - 16 * 2),
-                        Height = Application.GetRealHeight(50),
-                        LineColor = CSS.CSS_Color.textWhiteColor,
-                        SubViewWidth=Application.GetRealWidth(68),
-                    };
-                    devfLayout.AddChidren(funControlRow);
+                for (int j = 0; j < pirDevice.FunctioList.Count; j++)
+                {
+                    var control = pirDevice.FunctioList[j];
+
+                    View.ControlView controlView = new View.ControlView();
+                    controlView.Show(pirView.devfLayout, j);
                     //閬ユ帶鍣ㄥ悕绉�
-                    Button nameBtn = new Button
+                    controlView.nameBtn.Text = control.name;
+                    //閬ユ帶鍣ㄥ瓨鏀惧尯鍩�
+                    controlView.areaBtn.Text = Intelligence.Automation.LogicMethod.GetGetRoomName(control);
+                    //鏍囪閬ユ帶鍣�
+                    controlView.delBtn.Tag = control;
+                    //鍒犻櫎鐐瑰嚮浜嬩欢
+                    controlView.delBtn.MouseUpEventHandler += (sender, e) =>
                     {
-                        X = Application.GetRealWidth(16),
-                        Width = Application.GetRealWidth(150),
-                        Height = Application.GetRealHeight(20),
-                        Text =j.ToString(),
-                        TextAlignment=TextAlignment.CenterLeft,
-                        TextSize = TextSize.text14,
-                        TextColor = CSS.CSS_Color.textColor,
-                        Gravity=Gravity.CenterVertical,
+                        var Function = controlView.delBtn.Tag as Entity.Function;
+                        string text = Language.StringByID(StringId.shanchushebei) + Function.name + "?";
+                        TipPopView tipPopView = new TipPopView();
+                        tipPopView.TipBox(StringId.tip, text, (dialog) =>
+                        {
+                            Thread(dialog, (responsePackNew) =>
+                            {
+                                dialog.Close();
+                                var function = pirDevice.FunctioList.Find((c) => c.sid == Function.sid);
+                                if (function != null)
+                                {
+                                    pirDevice.FunctioList.Remove(Function);
+                                    if (Pir.currPir != null && pirDevice.sid == Pir.currPir.sid)
+                                    {
+                                        Pir.currPir.FunctioList = pirDevice.FunctioList;
+                                    }
+                                }
+                                UIView(vv);
+
+                            }, "鍒犻櫎", Function.deviceId, "");
+
+                        }, () => { }, false);
                     };
-                    funControlRow.AddChidren(nameBtn);
-                    //閬ユ帶鍣ㄥ尯鍩�
-                    Button areaBtn = new Button
-                    {
-                        X=Application.GetRealWidth(311+16-(40+100)),
-                        Width = Application.GetRealWidth(100),
-                        Height = Application.GetRealHeight(17),
-                        Text = j.ToString(),
-                        TextAlignment = TextAlignment.CenterRight,
-                        TextSize = TextSize.text12,
-                        TextColor = CSS.CSS_Color.textCancelColor,
-                        Gravity =Gravity.CenterVertical,
-                    };
-                    funControlRow.AddChidren(areaBtn);
-                    //涓嬩竴绾у浘鏍�
-                    Button nextIconBtn = new Button
-                    {
-                        X = Application.GetRealWidth(295+16),
-                        Width = Application.GetRealWidth(16),
-                        Height = Application.GetRealWidth(16),
-                        UnSelectedImagePath = "PirIcon/next.png",
-                        Gravity = Gravity.CenterVertical,
-                    };
-                    funControlRow.AddChidren(nextIconBtn);
-                    //鍒犻櫎
-                    Button delBtn = new Button
-                    {
-                        Width = Application.GetRealWidth(50),
-                        Height = Application.GetRealHeight(22),
-                        TextID = StringId.Del,
-                        TextAlignment = TextAlignment.Center,
-                        TextSize = TextSize.text16,
-                        TextColor = CSS.CSS_Color.textWhiteColor,
-                        IsBold=true,
-                        BackgroundColor= CSS.CSS_Color.textRedColor,
-                    };
-                    funControlRow.AddRightView(delBtn);
-                    //绾�
-                    Button line1Btn = new Button
-                    {
-                        Y = Application.GetRealHeight(50 - 2),
-                        X = Application.GetRealWidth(16),
-                        Width = Application.GetRealWidth(311),
-                        Height = 1,
-                        BackgroundColor = CSS.CSS_Color.viewLine,
-                    };
-                    funControlRow.AddChidren(line1Btn);
-                    if (j == a - 1)
+                    //view鐐瑰嚮浜嬩欢
+                    controlView.clickBtn.MouseUpEventHandler += (sender, e) =>
+                     {
+                         EditControl editControl = new EditControl();
+                         MainPage.BasePageView.AddChidren(editControl);
+                         editControl.Show(control, pirDevice, (device) =>
+                         {
+                             //鍥炶皟鏇存柊鍚嶅瓧/鍖哄煙
+                             controlView.nameBtn.Text = device.name;
+                             controlView.areaBtn.Text = Intelligence.Automation.LogicMethod.GetGetRoomName(device);
+
+                         });
+                         MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
+                     };
+                    if (j == pirDevice.FunctioList.Count - 1)
                     {
                         //鏈�鍚庢敼鍙樹竴涓嚎鐨勯鑹�
-                        line1Btn.BackgroundColor = CSS.CSS_Color.viewTranslucence;
-                        funControlRow.LineColor = CSS.CSS_Color.viewTranslucence;
+                        controlView.line1Btn.BackgroundColor = CSS.CSS_Color.viewTranslucence;
+                        controlView.funControlRow.LineColor = CSS.CSS_Color.viewTranslucence;
                     }
-                    delBtn.MouseUpEventHandler += (sender,e) => {
 
 
-                    };
                 }
 
-               
-
             }
+        }
+        /// <summary>
+        /// 鍔犺浇寮规
+        /// </summary>
+        /// <param name="pirclick"></param>
+        /// <param name="vv"></param>
+        void NewSwitchView(Pir pirclick, VerticalRefreshLayout vv)
+        {
+            FrameLayout frame = new FrameLayout { BackgroundColor = CSS.CSS_Color.viewTrans60lucence };
+            this.AddChidren(frame);
+            SwitchView switchView = new SwitchView();
+            switchView.btnOff.TextColor = CSS.CSS_Color.textConfirmColor;
+            switchView.FLayoutView(frame, StringId.shanchushebei, StringId.xiugaimingzi, "", (intValue) =>
+            {
+                if (StringId.xiugaimingzi == intValue)
+                {
+                    List<string> list = new List<string>();
+                    for (int b = 0; b < PirDevice.Pir.pirDeviceList.Count; b++)
+                    {
+                        list.Add(PirDevice.Pir.pirDeviceList[b].name);
+                    }
+                    Method methodView = new Method();
+                    methodView.EditControlName(StringId.xiugaimingzi, list, pirclick.name, (name, view) =>
+                    {
+                        Thread(view, (responsePackNew) =>
+                        {
+                            pirclick.name = name;
+                            view.Close();
+                            UIView(vv);
+                        }, "淇敼鍚嶇О", pirclick.deviceId, pirclick.name);
+                    }, () =>
+                    {
+                        NewSwitchView(pirclick, vv);
+                    }, false);
 
+                }
+                else
+                {
+                    string text = Language.StringByID(StringId.shanchushebei) + pirclick.name + "?";
+                    TipPopView tipPopView = new TipPopView();
+                    tipPopView.TipBox(StringId.tip, text, (dialog) =>
+                    {
+                        Thread(dialog, (responsePackNew) =>
+                                {
+                                    var pir = Pir.pirDeviceList.Find((c) => c.deviceId == pirclick.deviceId);
+                                    if (pir != null)
+                                    {
+                                        Pir.pirDeviceList.Remove(pirclick);
+                                    }
+                                    dialog.Close();
+                                    UIView(vv);
+                                }, "鍒犻櫎", pirclick.deviceId, "");
+                    }, () =>
+                    {
+                        NewSwitchView(pirclick, vv);
+                    }, false);
+
+                }
+            });
+        }
+        /// <summary>
+        /// 鍙戦�佺嚎绋�
+        /// </summary>
+        /// <param name="dialog"></param>
+        /// <param name="action"></param>
+        /// <param name="str"></param>
+        /// <param name="deviceId"></param>
+        /// <param name="obj"></param>
+        void Thread(Dialog dialog, Action<HDL_ON.DAL.Server.ResponsePackNew> action, string str, string deviceId, string obj)
+        {
+            //鍔犺浇log
+            Loading loading = new Loading();
+            dialog.AddChidren(loading);
+            HDL_ON.DAL.Server.ResponsePackNew responsePackNew = null;
+            loading.Start();
+            new System.Threading.Thread(() =>
+            {
+                try
+                {
+                    if (str == "鍒犻櫎")
+                    {
+                        responsePackNew = PirSend.DeleteDevice(deviceId);
+                    }
+                    else if (str == "淇敼鍚嶇О")
+                    {
+
+                        responsePackNew = PirSend.DeviceRename(deviceId, obj);
+                    }
+                }
+                catch { }
+                finally
+                {
+                    Application.RunOnMainThread(() =>
+                    {
+                        loading.Hide();
+                        if (responsePackNew != null && responsePackNew.Code == "0" && responsePackNew.Data.ToString() != "")
+                        {
+                            action(responsePackNew);
+                        }
+                        else
+                        {
+                            Method method = new Method();
+                            method.ErrorShow(responsePackNew,"");
+                        }
+
+                    });
+                }
+
+            })
+            { IsBackground = true }.Start();
         }
     }
 }

--
Gitblit v1.8.0