From a4924de3136289d10cabbf2f61a228387d44ded7 Mon Sep 17 00:00:00 2001 From: gxc <guoxuecheng@guoxuechengdeMacBook-Pro.local> Date: 星期四, 07 十一月 2019 13:48:36 +0800 Subject: [PATCH] Merge branch 'dev-tzy' into DEV_GXC --- ZigbeeApp/Shared/Phone/UserCenter/SharedContent/SearchConfigureSharedMainForm.cs | 488 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 488 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/SharedContent/SearchConfigureSharedMainForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/SharedContent/SearchConfigureSharedMainForm.cs new file mode 100755 index 0000000..a962d6c --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/SharedContent/SearchConfigureSharedMainForm.cs @@ -0,0 +1,488 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; +using ZigBee.Device; + +namespace Shared.Phone.UserCenter.SharedContent +{ + /// <summary> + /// 鏌ョ湅宸查厤缃叡浜唴瀹圭殑涓荤晫闈� + /// </summary> + public class SearchConfigureSharedMainForm : EditorCommonForm + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 鏌ョ湅鐨勬埧闂村璞� + /// </summary> + private Common.Room lookRoom = null; + /// <summary> + /// 鎴愬憳鐨勫垎浜暟鎹� + /// </summary> + private MemberShardInfoData memberShardInfo = null; + /// <summary> + /// 璁惧妗屽竷鎺т欢 + /// </summary> + private FrameLayout frameDeviceTable = null; + /// <summary> + /// 璁惧妗屽竷鎺т欢 + /// </summary> + private FrameLayout frameSceneTable = null; + /// <summary> + /// 鍒犻櫎鎸夐挳 + /// </summary> + private BottomClickButton btnDelete = null; + /// <summary> + /// 閫夋嫨鐨勫満鏅� + /// </summary> + private Dictionary<int, Common.SceneUI> dicSelectScene = new Dictionary<int, Common.SceneUI>(); + /// <summary> + /// 閫夋嫨鐨勮澶� + /// </summary> + private Dictionary<string, CommonDevice> dicSelectDevice = new Dictionary<string, CommonDevice>(); + /// <summary> + /// 褰撳墠閫夋嫨鐨勫垎鏀� 1锛氬満鏅� 2锛氬姛鑳� + /// </summary> + private int nowSwitchIndex = 1; + /// <summary> + /// 褰撳墠閫夋嫨鐨勮澶囩储寮� + /// </summary> + private string nowDeviceIndex = string.Empty; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) + /// </summary> + /// <param name="i_room">鏌ョ湅鐨勬埧闂村璞�</param> + /// <param name="i_memberShardInfo">鎴愬憳鐨勫垎浜暟鎹�</param> + public void ShowForm(Common.Room i_room, MemberShardInfoData i_memberShardInfo) + { + this.lookRoom = i_room; + this.memberShardInfo = i_memberShardInfo; + + //璁剧疆澶撮儴淇℃伅 + base.SetTitleText(i_room.Name); + + //鍒濆鍖栦腑閮ㄤ俊鎭� + this.InitMiddleFrame(); + } + + /// <summary> + /// 鍒濆鍖栦腑閮ㄤ俊鎭� + /// </summary> + private void InitMiddleFrame() + { + //娓呯┖bodyFrame + this.ClearBodyFrame(); + this.dicSelectDevice = new Dictionary<string, CommonDevice>(); + this.dicSelectScene = new Dictionary<int, Common.SceneUI>(); + + //鍒濆鍖栨甯冩帶浠� + this.frameSceneTable = new FrameLayout(); + frameSceneTable.Y = Application.GetRealHeight(132); + frameSceneTable.Height = bodyFrameLayout.Height - Application.GetRealHeight(132); + bodyFrameLayout.AddChidren(frameSceneTable); + + this.frameDeviceTable = new FrameLayout(); + frameDeviceTable.Y = frameSceneTable.Y; + frameDeviceTable.Height = frameSceneTable.Height; + bodyFrameLayout.AddChidren(frameDeviceTable); + frameDeviceTable.Visible = false; + + //鍒濆鍖栧垎鏀帶浠� + this.InitSwitchControl(); + + //鍒犻櫎鎸夐挳 + this.btnDelete = new BottomClickButton(); + btnDelete.BackgroundColor = 0xfff75858; + btnDelete.TextID = R.MyInternationalizationString.uDelete; + bodyFrameLayout.AddChidren(btnDelete); + btnDelete.Visible = false; + btnDelete.ButtonClickEvent += (sender, e) => + { + //鍒犻櫎鍒嗕韩 + this.DeleteShardData(); + }; + + //鍒濆鍖栧満鏅垪琛� + this.InitSceneList(); + //鍒濆鍔熻兘鍒楄〃 + this.InitFunctionList(); + } + + /// <summary> + /// 鍒濆鍖栧垎鏀帶浠� + /// </summary> + private void InitSwitchControl() + { + var tabControl = new SceneFunctionSwitchControl(); + tabControl.Y = Application.GetRealHeight(40); + bodyFrameLayout.AddChidren(tabControl); + //璁剧疆鍒濆鍖栧�� + tabControl.SetDefultIndex(nowSwitchIndex); + tabControl.SelectTabEvent += (tabIndex) => + { + this.nowSwitchIndex = tabIndex; + if (tabIndex == 1) + { + //鏄剧ず鍦烘櫙鍒楄〃 + this.frameSceneTable.Visible = true; + this.frameDeviceTable.Visible = false; + } + else + { + //鏄剧ず鍔熻兘鍒楄〃 + this.frameSceneTable.Visible = false; + this.frameDeviceTable.Visible = true; + } + }; + tabControl.InitControl(); + } + + #endregion + + #region 鈻� 鍦烘櫙鏄剧ず___________________________ + + /// <summary> + /// 鍒濆鍖栧満鏅垪琛� + /// </summary> + private void InitSceneList() + { + //娓呯┖妗屽竷 + this.frameSceneTable.RemoveAll(); + + var listScene = new List<Common.SceneUI>(); + for (int i = 0; i < lookRoom.SceneUIList.Count; i++) + { + if (HdlShardLogic.Current.IsFileExists(lookRoom.SceneUIList[i].FileName) == true) + { + listScene.Add(lookRoom.SceneUIList[i]); + } + } + if (listScene.Count == 0) + { + //鏃犲彲鍙栨秷鍏变韩鐨勫満鏅� + this.ShowNotDataImage(frameSceneTable, Language.StringByID(R.MyInternationalizationString.uNotCanCancelShardSceneMsg), "Item/NotShardPic.png", 383, 279); + return; + } + + HdlThreadLogic.Current.RunMainInThread(() => + { + var listView = new VerticalFrameControl(29); + listView.Y = Application.GetRealHeight(53); + listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(187); + frameSceneTable.AddChidren(listView); + + foreach (var data in listScene) + { + //鍦烘櫙鍥剧墖 + var frameContr = new FrameLayoutControl(); + frameContr.UseClickStatu = false; + frameContr.Width = Application.GetRealWidth(878); + frameContr.Height = Application.GetRealHeight(440); + frameContr.Gravity = Gravity.CenterHorizontal; + frameContr.BackgroundImagePath = data.IconPath; + listView.AddChidrenFrame(frameContr); + + var btnSelect = new IconViewControl(58); + btnSelect.UnSelectedImagePath = "Item/ItemUnSelected.png"; + btnSelect.SelectedImagePath = "Item/ItemSelected.png"; + btnSelect.X = Application.GetRealWidth(786); + btnSelect.Y = Application.GetRealHeight(35); + frameContr.AddChidren(btnSelect, ChidrenBindMode.BindEventOnly); + if (dicSelectScene.ContainsKey(data.Id) == true) + { + btnSelect.IsSelected = true; + } + frameContr.ButtonClickEvent += (sender, e) => + { + //閫夋嫨 + btnSelect.IsSelected = !btnSelect.IsSelected; + if (btnSelect.IsSelected == true) + { + dicSelectScene[data.Id] = data; + if (this.btnDelete.Visible == false) + { + this.btnDelete.Visible = true; + } + } + else + { + dicSelectScene.Remove(data.Id); + if (dicSelectScene.Count == 0 && dicSelectDevice.Count == 0) + { + this.btnDelete.Visible = false; + } + } + }; + } + }); + } + + #endregion + + #region 鈻� 鍔熻兘鏄剧ず___________________________ + + /// <summary> + /// 鍒濆鍖栧姛鑳藉垪琛� + /// </summary> + private void InitFunctionList() + { + //娓呯┖妗屽竷 + this.frameDeviceTable.RemoveAll(); + + HdlThreadLogic.Current.RunMainInThread(() => + { + //鑾峰彇鍒嗙粍鍚庣殑璁惧鍒楄〃 + var dicGroupDevice = this.GetAllGroupDevice(); + if (dicGroupDevice.Count == 0) + { + //鏃犲彲鍙栨秷鍏变韩鐨勮澶� + this.ShowNotDataImage(frameDeviceTable, Language.StringByID(R.MyInternationalizationString.uNotCanCancelDeviceMsg), "Item/NotShardPic.png", 383, 279); + } + else + { + var frameBack = new FrameLayoutControl(false); + frameBack.X = ControlCommonResourse.XXLeft; + frameBack.Y = Application.GetRealHeight(178); + frameBack.BackgroundColor = UserCenterColor.Current.White; + frameBack.Width = bodyFrameLayout.Width; + frameBack.Height = Application.GetRealHeight(1650); + frameBack.RadiusEx = 20; + frameDeviceTable.AddChidren(frameBack); + + var listView = new VerticalListControl(23); + listView.Y = Application.GetRealHeight(23); + listView.Height = Application.GetRealHeight(1437 - 23); + frameBack.AddChidren(listView); + //鍒濆鍖栬澶囩被鍨嬭 + this.InitDeviceObjectRow(dicGroupDevice, listView); + } + }); + } + + #endregion + + #region 鈻� 鍒濆鍖栬澶囩被鍨嬭___________________ + + /// <summary> + /// 鍒濆鍖栬澶囩被鍨嬭 + /// </summary> + /// <param name="dicData"></param> + /// <param name="listView"></param> + private void InitDeviceObjectRow(Dictionary<int, List<CommonDevice>> dicData, VerticalListControl listView) + { + var scrolContr = new RoomDeviceGroupMenuControl(dicData); + this.frameDeviceTable.AddChidren(scrolContr); + //璁剧疆鍒濆鍊� + scrolContr.SetDefultIndex(nowDeviceIndex); + scrolContr.SelectDeviceEvent += (listdevice) => + { + this.nowDeviceIndex = scrolContr.nowSelectKeys; + //娣诲姞璁惧琛� + this.AddDeviceRow(listdevice, listView); + }; + scrolContr.InitControl(); + } + + #endregion + + #region 鈻� 娣诲姞璁惧琛宊________________________ + + /// <summary> + /// 娣诲姞璁惧琛� + /// </summary> + /// <param name="listDevice"></param> + /// <param name="listView"></param> + private void AddDeviceRow(List<CommonDevice> listDevice, VerticalListControl listView) + { + listView.RemoveAll(); + + foreach (var device in listDevice) + { + var frameRow = new FrameRowControl(listView.rowSpace / 2); + frameRow.LeftOffset = Application.GetRealWidth(46) - ControlCommonResourse.XXLeft; + frameRow.RightOffset = -ControlCommonResourse.XXLeft; + listView.AddChidren(frameRow); + //鍥炬爣 + var btnIcon = frameRow.AddLeftIcon(81); + Common.LocalDevice.Current.SetDeviceIconToControl(btnIcon, device); + //鍚嶇О + var btnView = frameRow.AddLeftCaption(string.Empty, 600); + btnView.Text = Common.LocalDevice.Current.GetDeviceEpointName(device); + btnView.TextSize = 15; + //搴曠嚎 + frameRow.AddBottomLine(); + //閫夋嫨 + var btnSelect = frameRow.AddMostRightEmptyIcon(69, 69); + btnSelect.UnSelectedImagePath = "Item/ItemUnSelected.png"; + btnSelect.SelectedImagePath = "Item/ItemSelected.png"; + + string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(device); + if (dicSelectDevice.ContainsKey(mainKeys) == true) + { + btnSelect.IsSelected = true; + } + frameRow.ButtonClickEvent += (sender, e) => + { + //閫夋嫨 + btnSelect.IsSelected = !btnSelect.IsSelected; + if (btnSelect.IsSelected == true) + { + dicSelectDevice[mainKeys] = device; + if (this.btnDelete.Visible == false) + { + this.btnDelete.Visible = true; + } + } + else + { + dicSelectDevice.Remove(mainKeys); + if (dicSelectScene.Count == 0 && dicSelectDevice.Count == 0) + { + this.btnDelete.Visible = false; + } + } + }; + } + } + + #endregion + + #region 鈻� 鏁村悎璁惧___________________________ + + /// <summary> + /// 鑾峰彇鍒嗙粍鍚庣殑璁惧 + /// </summary> + /// <returns></returns> + private Dictionary<int, List<CommonDevice>> GetAllGroupDevice() + { + //鍏ㄩ儴鐨勮澶� + var listDevice = this.GetShardListDevice(); + var dic = new Dictionary<int, List<CommonDevice>>(); + foreach (var device in listDevice) + { + var typeInfo = Common.LocalDevice.Current.GetNotHdlMyDeviceEnumInfo(new List<ZigBee.Device.CommonDevice>() { device }); + if (device.Type == DeviceType.IASZone) + { + //杩欎釜寮哄埗涓轰紶鎰熷櫒 + typeInfo.BeloneTextId = R.MyInternationalizationString.uDeviceBelongId1200; + typeInfo.ConcreteType = Common.DeviceConcreteType.Sensor; + } + if (device.Type == DeviceType.OnOffOutput) + { + //缁х數鍣ㄧ殑鏃跺��,闇�瑕佺壒娈婂鐞� + if (device.DfunctionType == DeviceFunctionType.A寮�鍏�) + { + typeInfo.BeloneTextId = R.MyInternationalizationString.uSwitch; + } + else if (device.DfunctionType == DeviceFunctionType.A鎻掑骇) + { + typeInfo.BeloneTextId = R.MyInternationalizationString.uSocket1; + } + else if (device.DfunctionType == DeviceFunctionType.A鐏厜) + { + typeInfo.BeloneTextId = R.MyInternationalizationString.uLight; + } + else + { + //缁х數鍣� + typeInfo.BeloneTextId = R.MyInternationalizationString.uDeviceBelongId2300; + } + if (dic.ContainsKey(typeInfo.BeloneTextId) == false) + { + dic[typeInfo.BeloneTextId] = new List<CommonDevice>(); + } + } + else + { + if (dic.ContainsKey(typeInfo.BeloneTextId) == false) + { + dic[typeInfo.BeloneTextId] = new List<CommonDevice>(); + } + } + dic[typeInfo.BeloneTextId].Add(device); + } + return dic; + } + + #endregion + + #region 鈻� 鍒犻櫎鍒嗕韩___________________________ + + /// <summary> + /// 鍒犻櫎鍒嗕韩 + /// </summary> + private void DeleteShardData() + { + //閫夋嫨鐨勮澶� + var listDevice = new List<CommonDevice>(); + foreach (var device in dicSelectDevice.Values) + { + listDevice.Add(device); + } + //閫夋嫨鐨勫満鏅� + var listScene = new List<Common.SceneUI>(); + foreach (var scene in dicSelectScene.Values) + { + listScene.Add(scene); + } + + //纭鍒犻櫎閫夋嫨鐨勫叡浜満鏅拰鍔熻兘锛� + this.ShowMassage(ShowMsgType.Confirm, Language.StringByID(R.MyInternationalizationString.uDeleteShardContentMsg), () => + { + HdlThreadLogic.Current.RunThread(async () => + { + //涓婁紶鏂囦欢 + var result = await HdlShardLogic.Current.DoDeleteSharedContent(memberShardInfo, this.lookRoom, listDevice, listScene); + if (result == true) + { + HdlThreadLogic.Current.RunMain(() => + { + //閲嶆柊鍒濆鍖栫晫闈� + this.InitMiddleFrame(); + }); + } + }); + }); + } + + #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + /// <summary> + /// 鑾峰彇鍒嗕韩鐨勮澶� + /// </summary> + /// <returns></returns> + private List<CommonDevice> GetShardListDevice() + { + //鑾峰彇杩欎釜鎴块棿閲岄潰鐨勫垎浜澶� + var listDevice = new List<CommonDevice>(); + foreach (var deviceFile in this.lookRoom.DeviceUIFilePathList) + { + if (memberShardInfo.dicAllShardKeys.ContainsKey(deviceFile) == true) + { + var strArry = deviceFile.Split('_'); + if (strArry.Length < 3) + { + continue; + } + //浠庡垎浜枃浠朵腑搴忓垪鍖栧洖鏉� + var deviceData = HdlShardLogic.Current.GetShardFileContent(deviceFile); + var device = ZigBee.Device.CommonDevice.CommonDeviceByByteString(strArry[1], System.Text.Encoding.UTF8.GetString(deviceData)); + if (device != null) + { + listDevice.Add(device); + } + } + } + return listDevice; + } + + #endregion + } +} -- Gitblit v1.8.0