using System; using System.Collections.Generic; using System.Threading; using HDL_ON.Common; using HDL_ON.DAL.Server; using HDL_ON.DriverLayer; using HDL_ON.Entity; using HDL_ON.UI.CSS; using Shared; namespace HDL_ON.UI { public class AddGroupControlPage : FrameLayout { #region 控件列表 /// /// 当前窗体 /// FrameLayout bodyView; /// /// 楼层选择下拉图标 /// Button btnFloorDownIcon; /// /// 楼层显示 /// Button btnFloor; /// /// 全选按钮 /// Button btnChooseAll; /// /// 功能列表集合显示区域 /// VerticalScrolViewLayout functionListView; /// /// 完成按钮 /// Button btnConfrim; #endregion /// /// 功能列表 /// List groupControlLightList; /// /// 本地的灯光列表 /// List lightList; /// /// 回调刷新 /// Action addActon; Action delAction; /// /// 是否新增群控 /// bool isAdd = true; /// /// 编辑的组控数据 /// string editDataString = ""; GroupControl groupControl; GroupControlType groupControlType = new GroupControlType(); public AddGroupControlPage(GroupControl groupControl, Action addAction,Action delAction) { bodyView = this; if(groupControl == null) { this.groupControl = new GroupControl(); } else { isAdd = false; this.groupControl = groupControl; editDataString = Newtonsoft.Json.JsonConvert.SerializeObject(this.groupControl); } groupControlLightList = new List(); this.addActon = addAction; this.delAction = delAction; lightList = FunctionList.List.GetLightList(); } public void LoadPage() { bodyView.BackgroundColor = CSS_Color.BackgroundColor; if (isAdd) { var topView = new TopViewDiv(bodyView, Language.StringByID(StringId.GroupControl)); topView.maginY = 10; topView.LoadTopView(); } else { var topView = new TopViewDiv(bodyView, ""); topView.maginY = 10; topView.LoadTopView_SettingText(()=> { Action action = () => { var waitPage = new Loading(); this.AddChidren(waitPage); waitPage.Start(""); new System.Threading.Thread(() => { try { var pack = ApiUtlis.Ins.HttpRequest.DelGroupControl(groupControl.userDeviceGroupControlId); if (pack != null) { Application.RunOnMainThread(() => { try { if (pack.Code == StateCode.SUCCESS) { var delTemp = FunctionList.List.groupControls.Find((obj) => groupControl.sid == obj.sid); FunctionList.List.groupControls.Remove(delTemp); //list.Remove(groupControl); this.RemoveFromParent(); delAction?.Invoke(); } else { IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); } } catch (Exception ex) { MainPage.Log($"刷新组控数据异常:{ex.Message}"); } }); } } catch (Exception ex) { MainPage.Log($"删除组控异常:{ex.Message}"); } finally { Application.RunOnMainThread(() => { if (waitPage != null) { waitPage.Hide(); waitPage.RemoveFromParent(); waitPage = null; } }); } }) { IsBackground = true }.Start(); }; new PublicAssmebly().TipOptionMsg(StringId.Tip, StringId.DoYouWantDelCombinedDimming, action); }, Language.StringByID(StringId.DelGroupControl),true); } var contentView = new FrameLayout() { Y = Application.GetRealHeight(64+10), Height = Application.GetRealHeight(667-64-10), }; bodyView.AddChidren(contentView); #region 组名称 FrameLayout groupNameView; groupNameView = new FrameLayout() { Height = Application.GetRealHeight(50), BackgroundColor = CSS_Color.MainBackgroundColor, }; contentView.AddChidren(groupNameView); Button btnGroupNameTitle = new Button() { X = Application.GetRealWidth(16), Width = Application.GetRealWidth(178), TextID = StringId.GroupNmae, TextAlignment = TextAlignment.CenterLeft, TextSize = CSS_FontSize.SubheadingFontSize, TextColor = CSS_Color.FirstLevelTitleColor, }; groupNameView.AddChidren(btnGroupNameTitle); var etGroupName = new EditText() { X = Application.GetRealWidth(155), Width = Application.GetRealWidth(200), PlaceholderText = Language.StringByID(StringId.PlsEntry), TextSize = CSS_FontSize.TextFontSize, TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.TextualColor, PlaceholderTextColor = CSS_Color.PromptingColor1, }; groupNameView.AddChidren(etGroupName); groupNameView.AddChidren( new Button() { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight(49), Height = Application.GetRealHeight(1), Width = Application.GetRealWidth(343), BackgroundColor = CSS_Color.DividingLineColor, }); #endregion #region 位置管理 var locationMagtView = new FrameLayout() { Y = Application.GetRealHeight(50), Height = Application.GetRealHeight(50), BackgroundColor = CSS_Color.MainBackgroundColor, }; contentView.AddChidren(locationMagtView); var btnLocationMagtTitle = new Button() { X = Application.GetRealWidth(16), Width = Application.GetRealWidth(160), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.SubheadingFontSize, TextID = StringId.LocationManagement, }; locationMagtView.AddChidren(btnLocationMagtTitle); var btnLocationValues = new Button() { X = Application.GetRealWidth(86), Width = Application.GetRealWidth(237), TextAlignment = TextAlignment.CenterRight, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.TextFontSize, Text = groupControl.GetRoomListName(), }; locationMagtView.AddChidren(btnLocationValues); var btnLocationInfoRight = new Button() { X = Application.GetRealWidth(339), Gravity = Gravity.CenterVertical, Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), UnSelectedImagePath = "Public/RightIcon.png", }; locationMagtView.AddChidren(btnLocationInfoRight); EventHandler eventHandler = (sender, e) => { Application.HideSoftInput(); //修改功能所属房间之后的回调事件 Action chooseRoomBackAction = () => { try { groupControl.uids = groupControl.roomIds; btnLocationValues.Text = groupControl.GetRoomListName(); } catch { } }; var view = new GroupChooseRoomPage(groupControl, chooseRoomBackAction); MainPage.BasePageView.AddChidren(view); view.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }; btnLocationInfoRight.MouseUpEventHandler = eventHandler; btnLocationValues.MouseUpEventHandler = eventHandler; //locationMagtView.AddChidren( // new Button() // { // Y = Application.GetRealHeight(49), // Gravity = Gravity.CenterHorizontal, // BackgroundColor = CSS_Color.DividingLineColor, // Width = Application.GetRealWidth(343), // Height = Application.GetRealHeight(1) // }); #endregion //contentView.AddChidren(new Button() //{ // Y = Application.GetRealHeight(164), // BackgroundColor = CSS_Color.BackgroundColor, //}); /// /// 房间内容显示区域 /// var roomFloorChangeView = new FrameLayout() { Y = Application.GetRealHeight(172), Height = Application.GetRealHeight(52), BackgroundColor = CSS_Color.BackgroundColor, }; bodyView.AddChidren(roomFloorChangeView); #region 房间顶部切换显示区域 btnFloorDownIcon = new Button() { Width = Application.GetMinRealAverage(16), Height = Application.GetMinRealAverage(16), X = Application.GetRealWidth(16), Y = Application.GetRealHeight(18), UnSelectedImagePath = "Public/DownIcon.png", }; roomFloorChangeView.AddChidren(btnFloorDownIcon); btnFloor = new Button() { X = btnFloorDownIcon.Right, Width = Application.GetRealWidth(200), TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextAlignment = TextAlignment.CenterLeft, Text = DB_ResidenceData.Instance.CurFloor.roomName, }; roomFloorChangeView.AddChidren(btnFloor); btnChooseAll = new Button() { X = Application.GetRealWidth(245), Width = Application.GetRealWidth(109), TextAlignment = TextAlignment.CenterRight, TextSize = CSS_FontSize.TextFontSize, TextColor = CSS_Color.FirstLevelTitleColor, TextID = StringId.SelectedAll, }; if (groupControlLightList.Count == lightList.Count) { btnChooseAll.TextID = StringId.Cancel; } roomFloorChangeView.AddChidren(btnChooseAll); btnChooseAll.MouseUpEventHandler = (sender, e) => { if (groupControlLightList.Count == lightList.Count) { groupControlLightList.Clear(); btnChooseAll.TextID = StringId.SelectAll; btnConfrim.IsSelected = false; } else { groupControlLightList.Clear(); groupControlLightList.AddRange(lightList); btnChooseAll.TextID = StringId.Cancel; btnConfrim.IsSelected = true; } for (int i = 0; i < functionListView.ChildrenCount; i++) { var view = functionListView.GetChildren(i); if (view.GetType() == typeof(LightRow)) { if (view.Tag != null && view.Tag.ToString() == "row") { for (int j = 0; j < (view as FrameLayout).ChildrenCount; j++) { var btn = (view as FrameLayout).GetChildren(j); if (btn.GetType() == typeof(Button)) { if (btn.Tag != null && btn.Tag.ToString() == "ChooseIcon") { (btn as Button).IsSelected = groupControlLightList.Count == lightList.Count; } } } } } } }; #endregion functionListView = new VerticalScrolViewLayout() { Y = Application.GetRealHeight(220), Height = Application.GetRealHeight(640 - 12 - 52 - 100 -100-10), }; bodyView.AddChidren(functionListView); functionListView.AddChidren(new Button() { Height = Application.GetRealHeight(10), }); #region 底部view var bottomView = new FrameLayout() { Y = Application.GetRealHeight(591), Height = Application.GetRealHeight(100), BackgroundColor = CSS_Color.MainBackgroundColor, Radius = (uint)Application.GetRealWidth(12), }; this.AddChidren(bottomView); btnConfrim = new Button() { Y = Application.GetRealHeight(12), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(220), Height = Application.GetRealHeight(44), Radius = (uint)Application.GetRealHeight(22), TextAlignment = TextAlignment.Center, TextColor = CSS_Color.MainBackgroundColor, BackgroundColor = CSS_Color.BackgroundColor, TextID = StringId.Confirm, TextSize = CSS_FontSize.SubheadingFontSize, SelectedTextColor = CSS_Color.MainBackgroundColor, SelectedBackgroundColor = CSS_Color.MainColor, IsSelected = !isAdd }; bottomView.AddChidren(btnConfrim); btnConfrim.MouseUpEventHandler = (sender, e) => { if (btnConfrim.IsSelected) { //保存群控数据 var name = etGroupName.Text.Trim(); if (string.IsNullOrEmpty(name)) { new PublicAssmebly().TipMsg(StringId.Tip, StringId.PlsEntryGroupName); return; } groupControl.name = name; if (groupControlLightList.Count < 2) { new PublicAssmebly().TipMsg(StringId.Tip, StringId.PlsSelectMoreData); return; } if (isAdd) { groupControl.sids.Clear(); foreach (var light in groupControlLightList) { try { var gc = new GroupControlFunction(); gc.sid = light.sid; gc.spk = light.spk; groupControl.sids.Add(gc); } catch (Exception ex) { MainPage.Log($"新增群控转换数据异常:{ex.Message}"); } } var waitPage = new Loading(); bodyView.AddChidren(waitPage); waitPage.Start(""); new Thread(() => { try { groupControl.type = groupControlType.type; groupControl.sid = groupControl.NewGroupControlSid(); var pack = ApiUtlis.Ins.HttpRequest.AddGroupControl(new List() { groupControl }); if (pack != null) { if (pack.Code == StateCode.SUCCESS) { try { var addTemp = Newtonsoft.Json.JsonConvert.DeserializeObject>(pack.Data.ToString()); if (addTemp != null && addTemp.Count > 0) groupControl.userDeviceGroupControlId = addTemp[0].userDeviceGroupControlId; FunctionList.List.groupControls.Add(groupControl); } catch (Exception ex) { MainPage.Log($"添加群控异常,转译返回数据失败:{ex.Message}"); } Application.RunOnMainThread(() => { addActon?.Invoke(groupControl); this.RemoveFromParent(); }); } else { IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); } } } catch (Exception ex) { MainPage.Log($"新增群控异常:{ex.Message}"); } finally { Application.RunOnMainThread(() => { try { waitPage.Hide(); waitPage = null; } catch { } }); } }) { IsBackground = true }.Start(); } else { var waitPage = new Loading(); bodyView.AddChidren(waitPage); waitPage.Start(""); new Thread(() => { try { //var newEditDataString = Newtonsoft.Json.JsonConvert.SerializeObject(this.groupControl); //var newEditDataString1 = Newtonsoft.Json.JsonConvert.SerializeObject(groupControlLightList); //var newEditDataString2 = Newtonsoft.Json.JsonConvert.SerializeObject(this.groupControl.sids); ////没有更新数据则直接退出 //if (newEditDataString == editDataString && newEditDataString1 == newEditDataString2) //{ // this.RemoveFromParent(); // return; //} groupControl.sids.Clear(); foreach (var light in groupControlLightList) { try { var gc = new GroupControlFunction(); gc.sid = light.sid; gc.spk = light.spk; groupControl.sids.Add(gc); } catch (Exception ex) { MainPage.Log($"新增群控转换数据异常:{ex.Message}"); } } var pack = ApiUtlis.Ins.HttpRequest.EditGroupControl(new List() { groupControl }); if (pack != null) { if (pack.Code == StateCode.SUCCESS) { var temp = FunctionList.List.groupControls.Find((obj) => obj.userDeviceGroupControlId == groupControl.userDeviceGroupControlId); if (temp != null) { temp = groupControl; } Application.RunOnMainThread(() => { addActon?.Invoke(temp); this.RemoveFromParent(); }); } else { IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); } } } catch (Exception ex) { MainPage.Log($"编辑群控异常:{ex.Message}"); } finally { Application.RunOnMainThread(() => { try { waitPage.Hide(); waitPage = null; } catch { } }); } }) { IsBackground = true }.Start(); } } }; #endregion LoadDialog_ChangeFloor(); new Thread(() => { if (isAdd) { var pack = Common.ApiUtlis.Ins.HttpRequest.GetGroupControlTypes("light.switch"); if (pack != null) { if (pack.Code == StateCode.SUCCESS) { try { var groupControlTypes = Newtonsoft.Json.JsonConvert.DeserializeObject>(pack.Data.ToString()); if (groupControlTypes != null && groupControlTypes.Count > 0) { //groupControlType = new GroupControlType { // type = "LIGHT", // typeName ="灯光控制", // spks = new List { "light.switch" }, // spkAttrs = new List { "on_off" } //}; groupControlType = groupControlTypes[0]; Application.RunOnMainThread(() => { LoadLightRow(lightList); }); } } catch (Exception ex) { MainPage.Log($"读取组控类型失败:{ex.Message}"); } } else { IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); } } } else { var pack = Common.ApiUtlis.Ins.HttpRequest.GetGroupControInfo(groupControl.userDeviceGroupControlId); if (pack != null) { if (pack.Code == StateCode.SUCCESS) { try { var groupControlTemps = Newtonsoft.Json.JsonConvert.DeserializeObject>(pack.Data.ToString()); if (groupControlTemps != null && groupControlTemps.Count > 0) { groupControl = groupControlTemps[0]; Application.RunOnMainThread(() => { if (groupControl.sids.Count == lightList.Count) { btnChooseAll.TextID = StringId.Cancel; } LoadLightRow(lightList); }); } } catch (Exception ex) { MainPage.Log($"读取组控信息失败:{ex.Message}"); } } else { IMessageCommon.Current.ShowErrorInfoAlter(pack.Code); } } } }) { IsBackground = true }.Start(); if (!isAdd) { etGroupName.Text = groupControl.name; btnLocationValues.Text = groupControl.GetRoomListName(); } } /// /// 显示的设备的总数 /// int showCount = -1; /// /// 加载功能row /// /// void LoadLightRow(List functions, bool isAppend = false) { var waitPage = new Loading(); bodyView.AddChidren(waitPage); waitPage.Start(""); new Thread(() => { try { Application.RunOnMainThread(() => { if (!isAppend) { showCount = -1; functionListView.RemoveAll(); } for(var i =0;i<100;i++) //foreach (var function in functions) { showCount++; if (showCount >= functions.Count) { break; } var function = functions[showCount]; var functionDiv = new LightRow(function) { Gravity = Gravity.CenterHorizontal, Height = Application.GetRealHeight(62), BorderColor = 0x00FFFFFF, BorderWidth = 1, BackgroundColor = CSS_Color.MainBackgroundColor, Tag = "row" }; functionDiv.AddChidren(new Button() { Y = Application.GetRealHeight(61), Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth(343), Height = Application.GetRealWidth(1), BackgroundColor = CSS_Color.DividingLineColor, }); Action setAction = () => { if (groupControlLightList.Count > 1) { btnConfrim.IsSelected = true; } else { btnConfrim.IsSelected = false; } if (groupControlLightList.Count != functions.Count) { btnChooseAll.TextID = StringId.SelectedAll; } else { if(btnChooseAll.TextID != StringId.Cancel) btnChooseAll.TextID = StringId.Cancel; } }; if (groupControl.sids.Find((obj) => obj.sid == function.sid) != null) { groupControlLightList.Add(function); } functionDiv.LoadDiv(groupControlLightList, setAction); functionListView.AddChidren(functionDiv); } if (functions.Count > showCount) { var btnAppend = new Button() { Height = Application.GetRealHeight(60), TextAlignment = TextAlignment.Center, TextSize = CSS_FontSize.SubheadingFontSize, TextColor = CSS_Color.FirstLevelTitleColor, TextID = StringId.LoadMore, }; functionListView.AddChidren(btnAppend); btnAppend.MouseUpEventHandler = (sender, e) => { btnAppend.RemoveFromParent(); LoadLightRow(functions, true); }; } }); } catch (Exception ex) { MainPage.Log("ShowFunctionRowError : " + ex.Message); } finally { Application.RunOnMainThread(() => { if (waitPage != null) { waitPage.RemoveFromParent(); waitPage = null; } }); } }) { IsBackground = true }.Start(); } /// /// 住宅列表点击事件 /// void LoadDialog_ChangeFloor() { string nowSelectId = null; btnFloor.MouseUpEventHandler += (sender, e) => { Application.HideSoftInput(); //显示下拉列表 var form = new FloorRoomSelectPopupView(); form.ShowDeviceFunctionView(btnFloor, this.lightList, (selectId, listFunc) => { groupControlLightList.Clear(); groupControl.sids.Clear(); btnChooseAll.TextID = StringId.SelectAll; btnConfrim.IsSelected = false; btnChooseAll.MouseUpEventHandler = (sender2, e2) => { if (groupControlLightList.Count == listFunc.Count) { groupControlLightList.Clear(); btnChooseAll.TextID = StringId.SelectAll; btnConfrim.IsSelected = false; } else { groupControlLightList.Clear(); groupControlLightList.AddRange(listFunc); btnChooseAll.TextID = StringId.Cancel; btnConfrim.IsSelected = true; } LoadLightRow(listFunc); }; nowSelectId = selectId; //重新加载界面 LoadLightRow(listFunc); }, nowSelectId,100); }; } } }