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/SmartSoundControlContentForm.cs | 718 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 718 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundControlContentForm.cs b/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundControlContentForm.cs new file mode 100755 index 0000000..9ccdd57 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/SmartSound/Forms/SmartSoundControlContentForm.cs @@ -0,0 +1,718 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; +using System.Threading.Tasks; +using Shared.Common; +using Shared.Phone.UserCenter.SmartSound.Util; +using Shared.Phone.UserCenter.SmartSound.Widget; +using ZigBee.Device; + +namespace Shared.Phone.UserCenter.SmartSound.Forms +{ + public class SmartSoundControlContentForm : EditorCommonForm + { + /// <summary> + /// 涓存椂鏁版嵁 + /// </summary> + private List<SmartSound.Layer> TempDatas = new List<SmartSound.Layer>(); + + private SmartSoundInfo.SoundInfo mSoundInfo; + /// <summary> + /// 鍒楄〃鎺т欢 + /// </summary> + private VerticalListControl listView = null; + + private FrameLayout contentLayout = null; + /// <summary> + /// 褰撳墠妤煎眰鐨勭储寮� + /// </summary> + public int CurrentIndex = 0; + private BottomClickButton bottomClickButton = null; + /// <summary> + /// 褰撳墠妤煎眰鐨勫悕绉� + /// </summary> + private static NormalViewControl pullLayoutText = null; + + public SmartSoundControlContentForm(SmartSoundInfo.SoundInfo soundInfo) + { + this.mSoundInfo = soundInfo; + } + + /// <summary> + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) + /// </summary> + public void ShowForm() + { + IniFloorData();//鍏堝姞杞芥暟鎹� + TempDatas.Clear(); + + this.ScrollEnabled = false; + base.SetTitleText("閫夋嫨鎴块棿");//璁剧疆鏍囬淇℃伅 + + contentLayout = new FrameLayout(); + this.bodyFrameLayout.AddChidren(contentLayout); + + IniAllDataView(); + } + + #region 鍔犺浇鏈湴鎵�鏈夋暟鎹紝鐢熸垚渚涚敤鎴烽�夋嫨鎴块棿鐨勭晫闈� + + private void IniAllDataView() + { + contentLayout.RemoveAll(); + + var pullLayout = new MyPullControl(this, SmartSound.LocaData); + contentLayout.AddChidren(pullLayout); + pullLayout.InitControl(); + + LoadAllRoomListView(); + + bottomClickButton = new BottomClickButton(); + this.bodyFrameLayout.AddChidren(bottomClickButton); + bottomClickButton.Text = "纭"; + bottomClickButton.ButtonClickEvent += (sender, e) => + { + if (SmartSound.getInstantiate().LayerList != null && SmartSound.getInstantiate().LayerList.Count > 0) + { + //鐢熸垚涓�涓脊绐楃敾闈� + var dialogForm = new TextDialog("纭鍒犻櫎鐜版湁鎴块棿鍒楄〃鐨勬墍鏈夋帶鍒跺唴瀹癸紝娣诲姞鍏ㄦ柊鐨勫満鏅拰鍔熻兘锛�", "纭"); + dialogForm.SetTitleText("鎻愮ず"); + + //鎸変笅纭鎸夐挳 + dialogForm.ComfirmClickEvent += () => + { + //鐢婚潰鍏抽棴 + dialogForm.CloseDialog(); + uploadData(); + }; + } + else + { + uploadData(); + } + + }; + + bottomClickButton.Visible = false; + } + + /// <summary> + /// 鎻愪氦鏁版嵁鍒版湇鍔″櫒 + /// </summary> + private void uploadData() + { + HdlThreadLogic.Current.RunThread(async () => + { + this.ShowProgressBar(); + //淇濆瓨鏁版嵁 + if (SmartSound.getInstantiate().LayerList == null) + SmartSound.getInstantiate().LayerList = new List<SmartSound.Layer>(); + + SmartSound.getInstantiate().LayerList.Clear(); + SmartSound.getInstantiate().LayerList = CollateData(); + SmartSound.getInstantiate().TokenID = mSoundInfo.Id; + SmartSound.getInstantiate().UserID = mSoundInfo.UserID; + SmartSound.getInstantiate().HomeID = mSoundInfo.HomeID; + + //涓婁紶鏁版嵁鍒版湇鍔″櫒 + string str = await postBatchEdit(); + CloseProgressBar(); + + HdlThreadLogic.Current.RunMainInThread(() => + { + CloseForm(); + }); + }); + } + + private void LoadAllRoomListView() + { + try + { + + if (SmartSound.LocaData == null || SmartSound.LocaData.Count < 1) + return; + + // 鍔犺浇褰撳墠妤煎眰鐨勬墍鏈夋埧闂� 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); + } + + pullLayoutText.Text = layer.LayerName; + listView.RemoveAll(); + + foreach(SmartSound.Room room in layer.RoomList) + { + var roomRowLayout = new RoomRowLayout(this, room); + 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 = MyHttpWebResponse.PostWebRequest(url, json, Encoding.UTF8); + return response_str; + } + + #endregion + + /// <summary> + /// 灏嗘暟鎹浆鎹负鏅鸿兘闊崇浣跨敤鐨勬暟鎹� + /// </summary> + private void IniFloorData() + { + + if (SmartSound.LocaData == null) + SmartSound.LocaData = new List<SmartSound.Layer>(); + + SmartSound.LocaData.Clear(); + + Dictionary<string, string> floorDictionary = Config.Instance.Home.FloorDics;//妤煎眰鍒楄〃 + + #region 鍒嗘ゼ灞� + if (floorDictionary.Count < 1) + { + //娌℃湁妤煎眰,妯℃嫙涓�涓� + SmartSound.Layer layer = new SmartSound.Layer(); + layer.LayerID = DateTime.Now.ToString("yyyyMMddHHmmssms"); + layer.LayerName = "涓�妤�"; + layer.RoomList.Clear(); + SmartSound.LocaData.Add(layer); + } + else + { + foreach (string layer_id in floorDictionary.Keys) + { + SmartSound.Layer layer = new SmartSound.Layer(); + layer.LayerID = layer_id; + layer.LayerName = floorDictionary[layer_id]; + layer.RoomList.Clear(); + SmartSound.LocaData.Add(layer); + } + } + #endregion + + #region 鎴块棿鍏ヤ綇瀵瑰簲鐨勬ゼ灞� + var roomList = HdlRoomLogic.Current.GetAllListRooms();//鑾峰彇鎵�鏈夋埧闂� + + for (int n = 0; n < SmartSound.LocaData.Count; n++) + { + SmartSound.Layer layer = SmartSound.LocaData[n]; + foreach (Room room in roomList) + { + try + { + if (layer.LayerID != room.FloorId && SmartSound.LocaData.Count > 1) + continue; + + //娣诲姞鎴块棿 + SmartSound.Room smartRoom = new SmartSound.Room(); + layer.RoomList.Add(smartRoom); + + smartRoom.RoomID = room.Id; + smartRoom.RoomName = room.Name; + smartRoom.DeviceList.Clear(); + smartRoom.SceneList.Clear(); + + #region 娣诲姞璁惧 鐏厜銆佺獥甯樸�佸満鏅�佺┖璋� + for (int j = 0; j < room.ListDevice.Count; j++) + { + string key = room.ListDevice[j].ToString(); + var device = LocalDevice.Current.GetDevice(key); + if (device == null) + continue; + + SmartSound.Device smartDevice = new SmartSound.Device(); + smartDevice.DeviceAddress = device.DeviceAddr;//璁惧 MAC + smartDevice.Epoint = device.DeviceEpoint;//璁惧绔彛 + smartDevice.DeviceName = Common.LocalDevice.Current.GetDeviceEpointName(device);//璁惧鍚嶇О + smartDevice.NicksName = ""; + smartDevice.DeviceType = GetDeviceType(device);//璁惧绫诲瀷 + if (smartDevice.DeviceType == 0) + continue; + + if(ZbGateway.GateWayBaseInfomations.ContainsKey(device.CurrentGateWayId) ==true) + { + smartDevice.GatewayID = ZbGateway.GateWayBaseInfomations[device.CurrentGateWayId].MacMark;//缃戝叧 Id + } + else + { + smartDevice.GatewayID = device.CurrentGateWayId;//缃戝叧 Id + } + + if (smartDevice.DeviceName == "" || smartDevice.DeviceName == string.Empty) + continue; + + smartRoom.DeviceList.Add(smartDevice); + } + #endregion + + var sceneList = HdlSceneLogic.Current.GetRoomSceneList(room); + + #region //娣诲姞鍦烘櫙 + for (int k = 0; k < sceneList.Count; k++) + { + try + { + SceneUI scene = sceneList[k]; + + if (scene == null) continue; + SmartSound.Scene smartScene = new SmartSound.Scene(); + smartScene.SceneName = scene.Name; + smartScene.SceneID = scene.Id; + smartScene.DelayTime = scene.DelayTime; + smartScene.NicksName = ""; + if (ZbGateway.GateWayBaseInfomations.ContainsKey(ZbGateway.MainGateWay.GwId) == true) + { + smartScene.GatewayID = ZbGateway.GateWayBaseInfomations[ZbGateway.MainGateWay.GwId].MacMark;//缃戝叧 Id + } + else + { + smartScene.GatewayID = ZbGateway.MainGateWay.GwId;//缃戝叧 Id + } + + if (smartScene.SceneName == "" || smartScene.SceneName == string.Empty) + continue; + + smartRoom.SceneList.Add(smartScene); + } + catch (Exception e) { } + } + #endregion + + if (smartRoom.DeviceList.Count == 0 && sceneList.Count == 0) + layer.RoomList.Remove(smartRoom); + + } + catch (Exception e) + { + string errpr = e.Message; + } + } + } + #endregion + + } + + /// <summary> + /// Zigbee璁惧绫诲瀷杞崲涓烘櫤鑳介煶绠变娇鐢ㄧ殑绫诲瀷 + /// </summary> + /// <returns></returns> + private int GetDeviceType(ZigBee.Device.CommonDevice device) + { + int type = 0;//1=寮�鍏崇伅锛�2=璋冨厜鐏紝3=RGB 鐏紝4=绐楀笜妯″潡锛�5=寮�鍚堝笜锛�6=鍗峰笜锛�7=绌鸿皟锛�8=闈㈡澘锛�9=鏂伴 + + if (device.Type == DeviceType.OnOffOutput && device.DfunctionType == DeviceFunctionType.A鐏厜) + { + type = 1;//杩欓噷闈㈢殑灏辨槸缁х數鍣ㄧ伅鍏変簡 + } + else if (device.Type == DeviceType.DimmableLight) + { + type = 2;//璋冨厜 + } + else if (device.Type == DeviceType.ColorDimmableLight) + { + type = 3; + } + else if (device.Type == DeviceType.WindowCoveringDevice) + { + //绐楀笜 + if (((Rollershade)device).WcdType == 4)//寮�鍚堝笜 + { + type = 5; + } + else if (((Rollershade)device).WcdType == 0)//鍗峰笜 + type = 6;//鍗峰笜 + } + else if (device.Type == DeviceType.Thermostat) + { + type = 7; + } + else if (device.Type == DeviceType.FreshAir) + { + type = 9; + } + + return type; + } + + /// <summary> + /// 灏嗛�変腑鐨勬暟鎹坊鍔犲埌涓存椂鏁版嵁鍒楄〃涓紝渚夸簬鍚庢湡鐨�"淇濆瓨" + /// </summary> + private void AddData(SmartSound.Room room) + { + if (TempDatas == null) + TempDatas = new List<SmartSound.Layer>(); + + SmartSound.Layer tempLayer = SmartSound.LocaData[CurrentIndex]; + if (tempLayer == null) return; + + + #region 娣诲姞妤煎眰 + + bool floor_exists = false; + // 杩囨护鐩稿悓鐨勬ゼ灞� + for (int i = 0; i < TempDatas.Count; i++) + { + if (tempLayer.LayerID == TempDatas[i].LayerID) + { + floor_exists = true; + break; + } + } + + if (!floor_exists) + { + tempLayer.RoomList.Clear(); + TempDatas.Add(tempLayer); + } + + + #endregion + + #region 娣诲姞鎴块棿 + + for (int i = 0; i < TempDatas.Count; i++) + { + if (SmartSound.LocaData[CurrentIndex].LayerID != TempDatas[i].LayerID) + continue; + + bool room_exists = false; + + for (int n = 0; n < TempDatas[i].RoomList.Count; n++) + { + if (room.RoomID == TempDatas[i].RoomList[n].RoomID) + { + room_exists = true; + break; + } + } + + if (!room_exists) + { + TempDatas[i].RoomList.Add(room); + CheckedAll(room);//娣诲姞鎴块棿鎴愬姛锛岄粯璁ら�変腑鎵�鏈夎澶� + break; + } + } + + #endregion + + } + + private void RemoveData(SmartSound.Room room) + { + try + { + for (int i = 0; i < TempDatas.Count; i++) + { + + for (int j = 0; j < TempDatas[i].RoomList.Count; j++) + { + if (TempDatas[i].RoomList[j].RoomID == room.RoomID) + { + TempDatas[i].RoomList.RemoveAt(j); + } + } + } + } + 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); + k--; + } + } + #endregion + + #region 娓呴櫎鏈�変腑鐨勫満鏅� + for (int n = 0; n < _room.SceneList.Count; n++) + { + SmartSound.Scene _scene = _room.SceneList[n]; + if (!_scene.Checked) + { + _room.SceneList.Remove(_scene); + n--; + } + } + #endregion + } + else + { + _layer.RoomList.Remove(_room); + j--; + } + } + } + + //绉诲嚭娌℃湁璁惧鐨勬埧闂� + for (int j = 0; j < TempDatas.Count; j++) + { + SmartSound.Layer _layer = TempDatas[j]; + if (_layer.RoomList.Count < 1) + { + TempDatas.Remove(_layer); + j--; + } + } + } + catch { } + + return TempDatas; + } + + #region 鈻� 鑷畾涔夋ゼ灞傞�夋嫨鎺т欢_____________________ + + /// <summary> + /// 鎴块棿鍒楄〃琛� + /// </summary> + private class MyPullControl : FrameRowControl + { + + private SmartSoundControlContentForm smartSoundDataAdd = null; + private List<SmartSound.Layer> Layers = null; + /// <summary> + /// 鎴块棿鍒楄〃 + /// </summary> + private NormalViewControl btnName = null; + + /// <summary> + /// 鎴块棿鍒楄〃琛� + /// </summary> + public MyPullControl(SmartSoundControlContentForm _SmartSoundDataAdd,List<SmartSound.Layer> _layers) + { + this.smartSoundDataAdd = _SmartSoundDataAdd; + this.Layers = _layers; + this.UseClickStatu = false; + this.BackgroundColor = UserCenterColor.Current.White; + this.Height = Application.GetRealHeight(173); + } + + /// <summary> + /// 鍒濆鍖栨帶浠� + /// </summary> + public void InitControl() + { + //鏄剧ず鏂囨湰 + 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[smartSoundDataAdd.CurrentIndex].LayerName, 300, false); + pullLayoutText.Name = "pullLayout"; + pullLayoutText.ButtonClickEvent += (sender, e) => + { + ShowPullList(); + }; + pullLayoutText.Text = Layers[smartSoundDataAdd.CurrentIndex].LayerName; + + if (Layers.Count == 1) + { + right_icon.Visible = false; + pullLayoutText.Visible = false; + } + } + + 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", () => + { + smartSoundDataAdd.CurrentIndex = index; + smartSoundDataAdd.LoadAllRoomListView(); + }); + } + } + } + #endregion + + #region 鈻� 鑷畾涔夋埧闂撮�夋嫨鎺т欢_____________________ + + /// <summary> + /// 鎴块棿鍒楄〃琛� + /// </summary> + private class RoomRowLayout : FrameRowControl + { + private SmartSoundControlContentForm smartSoundControlContentForm = null; + + private SmartSound.Room mRoom = null; + /// <summary> + /// 鎴块棿鍚嶇О + /// </summary> + private NormalViewControl btnName = null; + + private MostRightIconControl Right_icon = null; + + /// <summary> + /// 鎴块棿鍒楄〃琛� + /// </summary> + public RoomRowLayout(SmartSoundControlContentForm _smartSoundControlContentForm,SmartSound.Room _room) + { + this.smartSoundControlContentForm = _smartSoundControlContentForm; + this.mRoom = _room; + this.UseClickStatu = false; + this.BackgroundColor = UserCenterColor.Current.White; + this.Height = Application.GetRealHeight(170); + } + + /// <summary> + /// 鍒濆鍖栨帶浠� + /// </summary> + public void InitControl() + { + //鏄剧ず鏂囨湰 + btnName = this.AddLeftCaption(string.Empty, 2000); + btnName.Height = Application.GetRealHeight(60); + btnName.TextSize = 14; + btnName.Y = Application.GetRealHeight(57); + btnName.Text = mRoom.RoomName; + + Right_icon = this.AddMostRightEmptyIcon(58, 58); + Right_icon.Gravity = Gravity.CenterVertical; + + btnName.ButtonClickEvent += (sender, e) => + { + mRoom.Checked = true; + RefreshRightIconState(mRoom.Checked); + SmartSoundContentForDevice deviceForm = new SmartSoundContentForDevice(mRoom); + deviceForm.AddForm(); + }; + + this.Right_icon.ButtonClickEvent += (sender, e) => + { + mRoom.Checked = !mRoom.Checked; + RefreshRightIconState(mRoom.Checked); + }; + + RefreshRightIconState(mRoom.Checked); + AddBottomLine(); + + } + + private void RefreshRightIconState(bool bol = false) + { + try + { + if (bol) + { + Right_icon.SelectedImagePath = "Item/ItemSelected.png"; + Right_icon.UnSelectedImagePath = "Item/ItemSelected.png"; + + smartSoundControlContentForm.AddData(mRoom); + } + else + { + Right_icon.SelectedImagePath = "Item/ItemUnSelected.png"; + Right_icon.UnSelectedImagePath = "Item/ItemUnSelected.png"; + + smartSoundControlContentForm.RemoveData(mRoom); + } + + bool isShow = false; + + if(smartSoundControlContentForm==null) return; + + foreach (SmartSound.Room _room in SmartSound.LocaData[smartSoundControlContentForm.CurrentIndex].RoomList) + { + if (_room.Checked) + { + isShow = true; + break; + } + } + + smartSoundControlContentForm.bottomClickButton.Visible = isShow; + } + catch(Exception e) + { + string error = e.Message; + } + } + + } + #endregion + } +} -- Gitblit v1.8.0