From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001
From: xm <1271024303@qq.com>
Date: 星期一, 14 十二月 2020 09:59:01 +0800
Subject: [PATCH] 请合并代码,完成晾衣架最终功能。

---
 ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundControlForm.cs |  403 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 403 insertions(+), 0 deletions(-)

diff --git a/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundControlForm.cs b/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundControlForm.cs
new file mode 100755
index 0000000..f156c91
--- /dev/null
+++ b/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundControlForm.cs
@@ -0,0 +1,403 @@
+锘縰sing System;
+using System.Collections.Generic;
+using System.Text;
+using System.Threading.Tasks;
+using Shared.Common;
+using Shared.Phone.UserCenter.SmartSound.Forms;
+using Shared.Phone.UserCenter.SmartSound.Util;
+using Shared.Phone.UserCenter.SmartSound.Widget;
+using ZigBee.Device;
+
+namespace Shared.Phone.UserCenter.SmartSound
+{
+
+    public class SmartSoundControlForm : EditorCommonForm
+    {
+
+        /// <summary>
+        /// 鍒楄〃鎺т欢
+        /// </summary>
+        private VerticalListControl listView = null;
+        private FrameLayout contentLayout = null;
+        public int CurrentIndex = 0;
+        private MostRightIconControl btnAddDeviceIcon = null;
+        /// <summary>
+        /// 褰撳墠妤煎眰鐨勫悕绉�
+        /// </summary>
+        private static NormalViewControl pullLayoutText = null;
+        /// <summary>
+        ///  鏅鸿兘闊崇鏁版嵁
+        /// </summary>
+        private static SmartSoundInfo.SoundInfo mSoundInfo = null;
+        /// <summary>
+        /// 妤煎眰鎺т欢
+        /// </summary>
+        private MyPullControl myPullControl;
+
+        public SmartSoundControlForm(SmartSoundInfo.SoundInfo soundInfo)
+        {
+            mSoundInfo = soundInfo;
+        }
+
+        /// <summary>
+        /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓)
+        /// </summary>
+        public void ShowForm()
+        {            
+            //璁剧疆鏍囬淇℃伅
+            base.SetTitleText("璇煶鎺у埗");
+
+            //鍙充笂娣诲姞鎸夐挳
+            if (btnAddDeviceIcon == null)
+            {
+                btnAddDeviceIcon = new MostRightIconControl(69, 69);
+                btnAddDeviceIcon.UnSelectedImagePath = "Item/Add.png";
+                topFrameLayout.AddChidren(btnAddDeviceIcon);
+                btnAddDeviceIcon.InitControl();
+                btnAddDeviceIcon.ButtonClickEvent += (sender, e) =>
+                {
+                    var smartSoundDataAdd = new SmartSoundControlContentForm(mSoundInfo);
+                    smartSoundDataAdd.AddForm();
+                };
+            }
+
+            //鍒濆鍖栦腑閮ㄦ帶浠�
+            this.InitMiddleFrame();
+        }
+
+        private void InitMiddleFrame()
+        {
+            this.ClearBodyFrame();
+
+            HdlThreadLogic.Current.RunThread(async () =>
+            {
+                this.ShowProgressBar();
+
+                string json = await GetData();//鑾峰彇鏁版嵁
+                SmartSoundDataInfo dataInfo = Newtonsoft.Json.JsonConvert.DeserializeObject<SmartSoundDataInfo>(json);
+                if (dataInfo != null)
+                {
+                    if (dataInfo.StateCode == "SUCCESS")
+                    {
+                        SmartSound.getInstantiate().LayerList = dataInfo.ResponseData.LayerList;
+                        SmartSound.getInstantiate().TokenID = mSoundInfo.Id;
+                        SmartSound.getInstantiate().UserID = mSoundInfo.UserID;
+                        SmartSound.getInstantiate().HomeID = mSoundInfo.HomeID;
+                    }
+                }
+
+                HdlThreadLogic.Current.RunMainInThread(() =>
+                {
+                    if (SmartSound.getInstantiate().LayerList == null || SmartSound.getInstantiate().LayerList.Count < 1)
+                    {
+                        this.CloseProgressBar();
+                        this.ShowNotDataImage(this.bodyFrameLayout, new string[] { "杩樻病鏈夋帶鍒跺唴瀹瑰摝锛�", "鐐瑰嚮\"+\"娣诲姞" });
+                        return;
+                    }
+
+                    contentLayout = new FrameLayout();
+                    this.bodyFrameLayout.AddChidren(contentLayout);
+                    contentLayout.RemoveAll();
+
+                    myPullControl = new MyPullControl(this, SmartSound.getInstantiate().LayerList);
+                    contentLayout.AddChidren(myPullControl);
+                    myPullControl.InitControl();
+
+                    LoadAllRoomListView();
+                    
+                    this.CloseProgressBar();
+
+                });
+            });
+        }
+
+
+        /// <summary>
+        /// 鍒ゆ柇鏄惁鏈夋暟鎹�
+        /// </summary>
+        /// <returns></returns>
+        private bool HaveData()
+        {
+            bool bol = false;
+            for (int i = 0; i < SmartSound.getInstantiate().LayerList.Count; i++)
+            {
+                if (SmartSound.getInstantiate().LayerList[i].RoomList.Count > 0)
+                {
+                    bol = true;
+                    break;
+                }
+            }
+            return bol;
+        }
+
+        /// <summary>
+        /// 鍔犺浇鎴块棿鍒楄〃
+        /// </summary>
+        private void LoadAllRoomListView()
+        {
+            try
+            {
+                if (SmartSound.getInstantiate().LayerList == null || SmartSound.getInstantiate().LayerList.Count < 1)                            
+                    return;
+                                
+                // 鍔犺浇褰撳墠妤煎眰鐨勬墍鏈夋埧闂� ListView
+                if (listView == null)
+                {
+                    listView = new VerticalListControl();
+                    contentLayout.AddChidren(listView);
+                    listView.Y = Application.GetRealHeight(173);
+                    listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(173);
+
+                }
+                else if (listView.Parent == null)
+                {
+                    listView = new VerticalListControl();
+                    contentLayout.AddChidren(listView);
+                    listView.Y = Application.GetRealHeight(173);
+                    listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(173);
+                }
+
+                SmartSound.Layer layer = SmartSound.getInstantiate().LayerList[CurrentIndex];
+                pullLayoutText.Text = layer.LayerName;
+                listView.RemoveAll();                               
+
+                foreach (SmartSound.Room room in layer.RoomList)
+                {
+                    var roomRowLayout = new RoomRowLayout(this, room);
+                    listView.AddChidren(roomRowLayout);
+                    roomRowLayout.InitControl();
+
+                    roomRowLayout.frameTable.ButtonClickEvent += (sender, e) =>
+                    {
+                        // 鐐瑰嚮鎴块棿锛岃繘鍏ラ�夋嫨璁惧鐣岄潰
+                        var deviceChange = new SmartSoundContentForDeviceChange(room);
+                        deviceChange.AddForm();
+                    };
+
+                    roomRowLayout.btnDelect.ButtonClickEvent += (sender, e) =>
+                    {
+                        var delBtn = sender as NormalViewControl;
+                        DelectRoom(delBtn);
+                    };
+                }
+
+                if (!HaveData())
+                {
+                    SmartSound.getInstantiate().LayerList.Clear();
+                    myPullControl.Visible = false;
+                    this.ShowNotDataImage(this.bodyFrameLayout, new string[] { "杩樻病鏈夋帶鍒跺唴瀹瑰摝锛�", "鐐瑰嚮\"+\"娣诲姞" });
+                }
+            }
+            catch (Exception e)
+            {
+                string error = e.Message;
+            }
+        }
+
+        private void DelectRoom(NormalViewControl delBtn)
+        {
+            this.ShowMassage(ShowMsgType.Confirm, "纭鍒犻櫎璇ユ埧闂寸殑鎺у埗鍐呭锛�", async () =>
+            {
+
+                HdlThreadLogic.Current.RunThread(async () =>
+                {
+
+                    this.ShowProgressBar("姝e湪鍒犻櫎鏁版嵁....");
+                    //鍒犻櫎鎴块棿
+                    var tag = (SmartSound.Room)delBtn.GetTagByKey("obj");
+
+                    if (SmartSound.getInstantiate().LayerList == null)
+                        return;
+
+                    for (int i = 0; i < SmartSound.getInstantiate().LayerList.Count; i++)
+                    {
+                        SmartSound.Layer _layer = SmartSound.getInstantiate().LayerList[i];
+
+                        for (int j = 0; j < _layer.RoomList.Count; j++)
+                        {
+                            SmartSound.Room _room = _layer.RoomList[j];
+
+                            if (_room.RoomName == tag.RoomName)
+                            {
+                                _layer.RoomList.Remove(_room);                                
+                            }
+                        }
+                    }
+                    
+                    // 閲嶆柊涓婁紶鏁版嵁
+                    string json = await postBatchEdit();
+
+                    HdlThreadLogic.Current.RunMainInThread(() =>
+                    {
+                        //this.InitMiddleFrame();
+                        this.LoadAllRoomListView();
+                    });
+                    this.CloseProgressBar();
+                });
+
+            }, Language.StringByID(R.MyInternationalizationString.OkMsg));
+        }
+
+        private async Task<string> GetData()
+        {
+            // 浠庢湇鍔″櫒鑾峰彇鏁版嵁
+            string url = string.Format("https://developer.hdlcontrol.com/zigbeespeakerservice/BatchEdit?Platform&UserID={0}&TokenID={1}&HomeID={2}", mSoundInfo.UserID, mSoundInfo.Id,mSoundInfo.HomeID);
+            return await MyHttpWebResponse.GetWebRequest(url);
+        }
+
+        private async Task<string> postBatchEdit()
+        {
+            // 鎻愪氦鏁版嵁鑷虫湇鍔″櫒
+            string url = "https://developer.hdlcontrol.com/zigbeespeakerservice/BatchEdit";
+            string json = Newtonsoft.Json.JsonConvert.SerializeObject(SmartSound.getInstantiate());
+            string response_str = MyHttpWebResponse.PostWebRequest(url, json, Encoding.UTF8);
+            return response_str;
+        }
+
+        public override int FormActionAgainEvent()
+        {
+            ShowForm();
+            return base.FormActionAgainEvent();
+        }
+
+        #region 鈻� 鑷畾涔夋ゼ灞傞�夋嫨鎺т欢_____________________
+
+        /// <summary>
+        /// 鎴块棿鍒楄〃琛�
+        /// </summary>
+        private class MyPullControl : FrameRowControl
+        {
+
+            private SmartSoundControlForm smartSoundControlData = null;
+            private List<SmartSound.Layer> Layers = null;
+            /// <summary>
+            /// 鎴块棿鍒楄〃
+            /// </summary>
+            private NormalViewControl btnName = null;
+
+            /// <summary>
+            /// 鎴块棿鍒楄〃琛�
+            /// </summary>
+            public MyPullControl(SmartSoundControlForm _SmartSoundDataAdd, List<SmartSound.Layer> _layers)
+            {
+                this.smartSoundControlData = _SmartSoundDataAdd;
+                this.Layers = _layers;
+                this.UseClickStatu = false;
+                this.BackgroundColor = UserCenterColor.Current.White;
+                this.Height = Application.GetRealHeight(173);
+            }
+
+            /// <summary>
+            /// 鍒濆鍖栨帶浠�
+            /// </summary>
+            public void InitControl()
+            {
+                try
+                {
+                    //鏄剧ず鏂囨湰
+                    btnName = this.AddLeftCaption(string.Empty, 700);
+                    btnName.Height = Application.GetRealHeight(60);
+                    btnName.TextSize = 17;
+                    btnName.Y = Application.GetRealHeight(57);
+                    btnName.Text = "鎴块棿鍒楄〃";
+
+                    var right_icon = this.AddRightArrow();
+                    right_icon.SelectedImagePath = "SmartSound/PullDown.png";
+                    right_icon.UnSelectedImagePath = "SmartSound/PullDown.png";
+                    right_icon.ButtonClickEvent += (sender, e) =>
+                    {
+                        ShowPullList();
+                    };
+
+                    pullLayoutText = this.AddMostRightView(Layers[smartSoundControlData.CurrentIndex].LayerName, 300, false);
+                    pullLayoutText.Name = "pullLayout";
+                    pullLayoutText.ButtonClickEvent += (sender, e) =>
+                    {
+                        ShowPullList();
+                    };
+                    pullLayoutText.Text = Layers[smartSoundControlData.CurrentIndex].LayerName;
+                    if (SmartSound.getInstantiate().LayerList.Count < 2)
+                    {
+                        right_icon.Visible = false;
+                        pullLayoutText.Visible = false;
+                    }
+                }
+                catch(Exception e)
+                {
+                    string error = e.Message;
+                }
+            }
+
+            private void ShowPullList()
+            {
+                //鎴块棿鍒楄〃琛寋鎴块棿鍒楄〃 textView锛屾ゼ灞備笅鎷夌獥}
+                //鏄剧ず鎴块棿{甯﹂�夋嫨妗嗙殑锛涘綋閫変腑浜嗘埧闂村悗闇�瑕佸湪搴曢儴寮瑰嚭纭鎸夐挳锛岀偣鍑荤‘璁よ烦杞埌鏂扮殑鐣岄潰}
+                var pull_frame = new TopRightMenuControl(Layers.Count, 2);
+                pull_frame.Y = this.Height;
+
+                for (int i = 0; i < Layers.Count; i++)
+                {
+                    int index = i;
+                    //鍒涘缓妤煎眰
+                    pull_frame.AddRowMenu(Layers[i].LayerName, "Item/CreatFloor.png", "Item/CreatFloorSelected.png", () =>
+                    {
+                        smartSoundControlData.CurrentIndex = index;
+                        smartSoundControlData.LoadAllRoomListView();
+                    });
+                }
+            }
+        }
+        #endregion
+
+        #region 鈻� 鑷畾涔夋櫤鑳介煶绠辨帶浠禵____________________
+
+        /// <summary>
+        /// 璇煶鎺у埗鎴块棿琛�
+        /// </summary>
+        private class RoomRowLayout : RowLayoutControl
+        {
+
+            /// <summary>
+            /// 鎴块棿鍚嶅瓧
+            /// </summary>
+            private NormalViewControl btnName = null;
+
+            /// <summary>
+            /// 鍒犻櫎鎸夐挳
+            /// </summary>
+            public NormalViewControl btnDelect = null;
+
+            private SmartSoundControlForm smartSoundControlForm;
+            private SmartSound.Room room;
+          
+            /// <summary>
+            /// 鑷畾闊崇鍏虫帶浠�
+            /// </summary>
+            public RoomRowLayout(SmartSoundControlForm _smartSoundControlForm, SmartSound.Room _room)
+            {
+                this.smartSoundControlForm = _smartSoundControlForm;
+                this.room = _room;
+                this.BackgroundColor = UserCenterColor.Current.White;
+                this.Height = Application.GetRealHeight(173);               
+            }
+
+            /// <summary>
+            /// 鍒濆鍖栧唴閮ㄦ帶浠�
+            /// </summary>
+            public void InitControl()
+            {
+                //璁惧           
+                frameTable.AddLeftCaption(this.room.RoomName, 800);
+                frameTable.AddRightArrow();
+                //搴曠嚎
+                frameTable.AddBottomLine();
+                
+                btnDelect = base.AddDeleteControl();
+                btnDelect.Text = "鍒犻櫎";
+                btnDelect.AddTag("obj", room);
+            }
+        }
+
+        #endregion
+    }
+}
\ No newline at end of file

--
Gitblit v1.8.0