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/AddNewSharedContentForm.cs | 472 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 472 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/SharedContent/AddNewSharedContentForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/SharedContent/AddNewSharedContentForm.cs new file mode 100755 index 0000000..ae802ca --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/SharedContent/AddNewSharedContentForm.cs @@ -0,0 +1,472 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; +using ZigBee.Device; + +namespace Shared.Phone.UserCenter.SharedContent +{ + /// <summary> + /// 閰嶇疆鏂板叡浜唴瀹圭殑涓荤晫闈� + /// </summary> + public class AddNewSharedContentForm : 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 btnShard = 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(Language.StringByID(R.MyInternationalizationString.uAddShared)); + + //鍒濆鍖栦腑閮ㄤ俊鎭� + 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(); + + //鎴块棿 + var btnRoom = new NormalViewControl(400, 63, true); + btnRoom.Y = Application.GetRealHeight(40); + btnRoom.X = bodyFrameLayout.Width - Application.GetRealWidth(58 + 400); + btnRoom.Text = this.lookRoom.Name; + btnRoom.TextAlignment = TextAlignment.CenterRight; + bodyFrameLayout.AddChidren(btnRoom); + + //鍒嗕韩鎸夐挳 + this.btnShard = new BottomClickButton(); + btnShard.TextID = R.MyInternationalizationString.uShared2; + bodyFrameLayout.AddChidren(btnShard); + btnShard.Visible = false; + btnShard.ButtonClickEvent += (sender, e) => + { + //淇濆瓨鍒嗕韩 + this.SaveShardData(); + }; + + //鍒濆鍖栧満鏅垪琛� + 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>(); + if (memberShardInfo.dicShardRoom.ContainsKey(lookRoom.FileName) == false) + { + listScene.AddRange(lookRoom.SceneUIList); + } + else + { + var tempRoom = memberShardInfo.dicShardRoom[lookRoom.FileName]; + foreach (var data in lookRoom.SceneUIList) + { + if (tempRoom.SceneUIFilePathList.Contains(data.FileName) == false) + { + listScene.Add(data); + } + } + } + if (listScene.Count == 0) + { + //鏃犲彲鍏变韩鐨勫満鏅� + this.ShowNotDataImage(frameSceneTable, Language.StringByID(R.MyInternationalizationString.uNotCanShardSceneMsg), "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.btnShard.Visible == false) + { + this.btnShard.Visible = true; + } + } + else + { + dicSelectScene.Remove(data.Id); + if (dicSelectScene.Count == 0 && dicSelectDevice.Count == 0) + { + this.btnShard.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.uNotCanShardDeviceMsg), "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.btnShard.Visible == false) + { + this.btnShard.Visible = true; + } + } + else + { + dicSelectDevice.Remove(mainKeys); + if (dicSelectScene.Count == 0 && dicSelectDevice.Count == 0) + { + this.btnShard.Visible = false; + } + } + }; + } + } + + #endregion + + #region 鈻� 鏁村悎璁惧___________________________ + + /// <summary> + /// 鑾峰彇鍒嗙粍鍚庣殑璁惧 + /// </summary> + /// <returns></returns> + private Dictionary<int, List<CommonDevice>> GetAllGroupDevice() + { + //鍏ㄩ儴鐨勮澶� + var listDevice = lookRoom.GetRoomListDevice(); + var dic = new Dictionary<int, List<CommonDevice>>(); + foreach (var device in listDevice) + { + if (memberShardInfo.dicAllShardKeys.ContainsKey(device.FilePath) == true) + { + //濡傛灉宸茬粡鍒嗕韩浜�,鍒欎笉鏄剧ず + continue; + } + 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 SaveShardData() + { + //閫夋嫨鐨勮澶� + 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); + } + HdlThreadLogic.Current.RunThread(async () => + { + //涓婁紶鏂囦欢 + var result = await HdlShardLogic.Current.DoUploadSharedContent(memberShardInfo, this.lookRoom, listDevice, listScene); + if (result == true) + { + HdlThreadLogic.Current.RunMain(() => + { + //閲嶆柊鍒濆鍖栫晫闈� + this.InitMiddleFrame(); + }); + } + }); + } + + #endregion + } +} -- Gitblit v1.8.0