lss
2020-06-10 d0396d3f30d46810f8453bf21f86bd93fe5dbdec
ZigbeeApp/Shared/Phone/UserCenter/SmartSound/Forms/SmartSoundControlContentForm.cs
@@ -1,6 +1,9 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Shared.Common;
using Shared.Phone.UserCenter.SmartSound.Util;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.SmartSound.Forms
@@ -11,7 +14,8 @@
        /// 临时数据
        /// </summary>
        private List<SmartSound.Layer> TempDatas = new List<SmartSound.Layer>();
        private SmartSoundInfo.SoundInfo mSoundInfo;
        /// <summary>
        /// 列表控件
        /// </summary>
@@ -21,9 +25,9 @@
        public int CurrentIndex = 0;
        private BottomClickButton bottomClickButton = null;
        public SmartSoundControlContentForm()
        public SmartSoundControlContentForm(SmartSoundInfo.SoundInfo soundInfo)
        {
           //
            this.mSoundInfo = soundInfo;
        }
        /// <summary>
@@ -41,15 +45,14 @@
            this.bodyFrameLayout.AddChidren(contentLayout);
            
            IniAllDataView();
        }
        #region 加载本地所有数据,生成供用户选择房间的界面
        private void IniAllDataView()
        {
            contentLayout.RemoveAll();
            var pullLayout = new MyPullControl(this, SmartSound.LocaData);
            contentLayout.AddChidren(pullLayout);
            pullLayout.InitControl();
@@ -61,13 +64,27 @@
            bottomClickButton.Text = "确认";
            bottomClickButton.ButtonClickEvent += (sender, e) =>
            {
                //保存数据
                if (SmartSound.CurretnData == null)
                    SmartSound.CurretnData = new List<SmartSound.Layer>();
                HdlThreadLogic.Current.RunThread(async () =>
                {
                    this.ShowProgressBar();
                    //保存数据
                    if (SmartSound.getInstantiate().LayerList == null)
                        SmartSound.getInstantiate().LayerList = new List<SmartSound.Layer>();
                SmartSound.CurretnData.Clear();
                SmartSound.CurretnData = TempDatas;
                this.CloseForm();
                    SmartSound.getInstantiate().LayerList.Clear();
                    SmartSound.getInstantiate().LayerList = CollateData();
                    SmartSound.getInstantiate().TokenID = mSoundInfo.Id;
                    SmartSound.getInstantiate().UserID = mSoundInfo.UserID;
                    //上传数据到服务器
                    string str = await postBatchEdit();
                    CloseProgressBar();
                    HdlThreadLogic.Current.RunMainInThread(() =>
                    {
                        CloseForm();
                    });
                });
            };
            bottomClickButton.Visible = false;
@@ -76,7 +93,7 @@
        private void LoadAllRoomListView()
        {
            try
            {
            {
                if (SmartSound.LocaData == null || SmartSound.LocaData.Count < 1)
                    return;
@@ -84,13 +101,11 @@
                // 加载当前楼层的所有房间 ListView
                SmartSound.Layer layer = SmartSound.LocaData[CurrentIndex];
                if (listView == null)
                {
                {
                    listView = new VerticalListControl();
                    contentLayout.AddChidren(listView);
                    listView.Y = Application.GetRealHeight(173);
                    listView.Height = bodyFrameLayout.Height- Application.GetRealHeight(173);
                    listView.Height = bodyFrameLayout.Height- Application.GetRealHeight(173);
                }
                listView.RemoveAll();
@@ -101,47 +116,34 @@
                    listView.AddChidren(roomRowLayout);
                    roomRowLayout.InitControl();
                }
                //多个的时候,确认按钮会遮挡一部分。追加三个空的行的高度,把它顶上来
                if (listView.ChildrenCount > 5)
                {
                    TextView textView = new TextView();
                    textView.Height = Application.GetRealHeight(127 * 3);
                    listView.AddChidren(textView);
                }
            }
            catch { }
        }
        private async Task<string> postBatchEdit()
        {
            // The remote server returned an error: (400) Bad Request.
            string url = "https://developer.hdlcontrol.com/zigbeespeakerservice/BatchEdit";
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(SmartSound.getInstantiate());
            string response_str = await MyHttpWebResponse.PostWebRequest(url, json, Encoding.UTF8);
            return response_str;
        }
        #endregion
        /// <summary>
        /// 将数据转换为智能音箱使用的数据
        /// </summary>
        private void IniFloorData()
        {
            #region//1.从服务器获取的数据,json反序列化得来
            //2.点击"+"将网关的数据转换为 智能音箱使用的数据
            /*{
                Dictionary<string, string> ss = Config.Instance.Home.FloorDics;//楼层列表
                string currentFloor = Config.Instance.Home.CurrentFloorId;//当前楼层的键
                var listRoom = HdlRoomLogic.Current.GetFloorSortRoom("楼层的主键");//获取当前楼层的所有房间
                var room = listRoom[0];
                for (int i=0;i<room.ListDevice.Count;i++)
                {//设备数据
                    var device = LocalDevice.Current.GetDevice(room.ListDevice[i]);
                    var myType = LocalDevice.Current.GetNotHdlMyDeviceEnumInfo(new List<CommonDevice>() { device });
                    if (myType.BeloneType == DeviceBeloneType.A灯光)
                    {
                        //这里面的就是灯光了
                        var light = device;
                        // light.DeviceAddr;  设备的地址
                        // light.DeviceEpoint;//设备的端口
                    }
                }
                for (int i = 0; i < room.ListSceneId.Count; i++)
                {   //场景数据
                    var device = HdlSceneLogic.Current.GetSceneUIBySceneId(room.ListSceneId[i]);
                    // device.Id;场景 id
                }
            }*/
            #endregion
            if (SmartSound.LocaData == null)
                SmartSound.LocaData = new List<SmartSound.Layer>();
@@ -155,7 +157,7 @@
            {
                //没有楼层,模拟一个
                SmartSound.Layer layer = new SmartSound.Layer();
                layer.LayerID = "0000";
                layer.LayerID = DateTime.Now.ToString("yyyyMMddHHmmssms");
                layer.LayerName = "一楼";
                layer.RoomList.Clear();
                SmartSound.LocaData.Add(layer);
@@ -205,15 +207,17 @@
                                continue;
                            SmartSound.Device smartDevice = new SmartSound.Device();
                            smartDevice.Id = device.DeviceID.ToString();//设备 Id
                            //smartDevice.Id = device.DeviceID.ToString();//设备 Id
                            smartDevice.DeviceAddress = device.DeviceAddr;//设备 MAC
                            smartDevice.Epoint = device.DeviceEpoint;//设备端口
                            smartDevice.ClusterID = 0;
                            //smartDevice.ClusterID = 0;
                            smartDevice.DeviceName = device.DeviceName;//设备名称
                            smartDevice.NicksName = "";
                            smartDevice.DeviceType = GetDeviceType(device);//设备类型
                            smartDevice.GatewayID = device.CurrentGateWayId;//网关 Id
                            smartDevice.RoomID = room.Id;//房间 Id
                            //smartDevice.RoomID = room.Id;//房间 Id
                            if (smartDevice.DeviceName == "" || smartDevice.DeviceName == string.Empty)
                                continue;
                            smartRoom.DeviceList.Add(smartDevice);
@@ -226,15 +230,20 @@
                        for (int k = 0; k < sceneList.Count; k++)
                        {
                            SceneUI scene = sceneList[k];
                            if (scene == null) continue;
                            SmartSound.Scene smartScene = new SmartSound.Scene();
                            smartScene.Id = scene.DeviceID.ToString();
                            //smartScene.Id = scene.DeviceID.ToString();
                            smartScene.SceneName = scene.Name;
                            smartScene.SceneID = scene.Id;
                            smartScene.DelayTime = scene.DelayTime;
                            smartScene.ClusterID = 0;
                            //smartScene.ClusterID = 0;
                            smartScene.NicksName = "";
                            smartScene.RoomID = room.Id;
                            //smartScene.RoomID = room.Id;
                            smartScene.GatewayID = ZbGateway.MainGateWay.CurrentGateWayId;
                            if (smartScene.SceneName == "" || smartScene.SceneName == string.Empty)
                                continue;
                            smartRoom.SceneList.Add(smartScene);
                        }
@@ -304,6 +313,8 @@
            SmartSound.Layer tempLayer = SmartSound.LocaData[CurrentIndex];
            if (tempLayer == null) return;
            #region 添加楼层
            bool floor_exists = false;
@@ -347,6 +358,7 @@
                if (!room_exists)
                {
                    TempDatas[i].RoomList.Add(room);
                    CheckedAll(room);//添加房间成功,默认选中所有设备
                    break;
                }
            }
@@ -372,6 +384,89 @@
                }
            }
            catch { }
        }
        /// <summary>
        /// 默认选择所有设备
        /// </summary>
        /// <param name="room"></param>
        private void CheckedAll(SmartSound.Room room)
        {
            // 标记所有场景
            for (int n = 0; n < room.SceneList.Count; n++)
            {
                SmartSound.Scene _scene = room.SceneList[n];
                _scene.Checked = true;
            }
            //标记所有设备
            for (int k = 0; k < room.DeviceList.Count; k++)
            {
                SmartSound.Device _device = room.DeviceList[k];
                _device.Checked = true;
            }
        }
        /// <summary>
        /// 重新整理数据,把没有选中的数据都剔除掉
        /// </summary>
        private List<SmartSound.Layer> CollateData()
        {
            try
            {
                //移出未选中的设备、场景
                for (int i = 0; i < TempDatas.Count; i++)
                {
                    SmartSound.Layer _layer = TempDatas[i];
                    for (int j = 0; j < _layer.RoomList.Count; j++)
                    {
                        SmartSound.Room _room = _layer.RoomList[j];
                        if (_room.Checked)
                        {
                            #region 清除未选中的设备
                            for (int k = 0; k < _room.DeviceList.Count; k++)
                            {
                                SmartSound.Device _device = _room.DeviceList[k];
                                if (!_device.Checked)
                                {
                                    _room.DeviceList.Remove(_device);
                                }
                            }
                            #endregion
                            #region 清除未选中的场景
                            for (int n = 0; n < _room.SceneList.Count; n++)
                            {
                                SmartSound.Scene _scene = _room.SceneList[n];
                                if (!_scene.Checked)
                                {
                                    _room.SceneList.Remove(_scene);
                                }
                            }
                            #endregion
                        }
                        else
                        {
                            _layer.RoomList.Remove(_room);
                        }
                    }
                }
                //移出没有设备的房间
                for (int j = 0; j < TempDatas.Count; j++)
                {
                    SmartSound.Layer _layer = TempDatas[j];
                    if (_layer.RoomList.Count < 1)
                    {
                        TempDatas.Remove(_layer);
                    }
                }
            }
            catch { }
            return TempDatas;
        }
        #region ■ 自定义楼层选择控件_____________________
@@ -426,7 +521,13 @@
                layout.ButtonClickEvent += (sender, e) =>
                {
                    ShowPullList();
                };
                };
                if (Layers.Count == 1)
                {
                    right_icon.Visible = false;
                    layout.Visible = false;
                }
                
            }
@@ -458,6 +559,7 @@
        private class RoomRowLayout : FrameRowControl
        {
            private SmartSoundControlContentForm smartSoundControlContentForm = null;
            private SmartSound.Room mRoom = null;
            /// <summary>
            /// 房间名称
@@ -477,14 +579,14 @@
                this.BackgroundColor = UserCenterColor.Current.White;
                this.Height = Application.GetRealHeight(170);
            }
            /// <summary>
            /// 初始化控件
            /// </summary>
            public void InitControl()
            {
                //显示文本
                btnName = this.AddLeftCaption(string.Empty, 700);
                btnName = this.AddLeftCaption(string.Empty, 2000);
                btnName.Height = Application.GetRealHeight(60);
                btnName.TextSize = 17;
                btnName.Y = Application.GetRealHeight(57);
@@ -497,6 +599,8 @@
                btnName.ButtonClickEvent += (sender, e) =>
                {
                    mRoom.Checked = true;
                    RefreshRightIconState(mRoom.Checked);
                    SmartSoundContentForDevice deviceForm = new SmartSoundContentForDevice(mRoom);
                    deviceForm.AddForm();
                };