mac
2024-07-25 f9181a9c8125136f597add7c30cb2ff508d54ba7
HDL_ON/UI/UI2/4-PersonalCenter/CombinedDimming/AddGroupControlPage.cs
@@ -2,6 +2,7 @@
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;
@@ -50,7 +51,8 @@
        /// <summary>
        /// 回调刷新
        /// </summary>
        Action backActon;
        Action<GroupControl> addActon;
        Action delAction;
        /// <summary>
        /// 是否新增群控
        /// </summary>
@@ -64,7 +66,7 @@
        GroupControlType groupControlType = new GroupControlType();
        public AddGroupControlPage(GroupControl groupControl, Action action)
        public AddGroupControlPage(GroupControl groupControl, Action<GroupControl> addAction,Action delAction)
        {
            bodyView = this;
            if(groupControl == null)
@@ -78,19 +80,90 @@
                editDataString = Newtonsoft.Json.JsonConvert.SerializeObject(this.groupControl);
            }
            groupControlLightList = new List<Function>();
            backActon = action;
            this.addActon = addAction;
            this.delAction = delAction;
            lightList = FunctionList.List.GetLightList();
        }
        public void LoadPage()
        {
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(StringId.CombinedDimming)).LoadTopView();
            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),
                Height = Application.GetRealHeight(550),
                Y = Application.GetRealHeight(64+10),
                Height = Application.GetRealHeight(667-64-10),
            };
            bodyView.AddChidren(contentView);
@@ -105,7 +178,7 @@
            Button btnGroupNameTitle = new Button()
            {
                X = Application.GetRealWidth(16),
                Width = Application.GetRealWidth(78),
                Width = Application.GetRealWidth(178),
                TextID = StringId.GroupNmae,
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.SubheadingFontSize,
@@ -182,6 +255,7 @@
                Action chooseRoomBackAction = () => {
                    try
                    {
                        groupControl.uids = groupControl.roomIds;
                        btnLocationValues.Text = groupControl.GetRoomListName();
                    }
                    catch { }
@@ -253,13 +327,13 @@
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextID = StringId.SelectedAll,
            };
            if (groupControlLightList.Count > 0)
            if (groupControlLightList.Count == lightList.Count)
            {
                btnChooseAll.TextID = StringId.Cancel;
            }
            roomFloorChangeView.AddChidren(btnChooseAll);
            btnChooseAll.MouseUpEventHandler = (sender, e) => {
                if (groupControlLightList.Count > 0)
                if (groupControlLightList.Count == lightList.Count)
                {
                    groupControlLightList.Clear();
                    btnChooseAll.TextID = StringId.SelectAll;
@@ -267,11 +341,33 @@
                }
                else
                {
                    groupControlLightList.Clear();
                    groupControlLightList.AddRange(lightList);
                    btnChooseAll.TextID = StringId.Cancel;
                    btnConfrim.IsSelected = true;
                }
                LoadLightRow(lightList);
                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
@@ -279,7 +375,7 @@
            functionListView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(220),
                Height = Application.GetRealHeight(640 - 12 - 52 - 100 -100),
                Height = Application.GetRealHeight(640 - 12 - 52 - 100 -100-10),
            };
            bodyView.AddChidren(functionListView);
@@ -326,6 +422,7 @@
                        new PublicAssmebly().TipMsg(StringId.Tip, StringId.PlsEntryGroupName);
                        return;
                    }
                    groupControl.name = name;
                    if (groupControlLightList.Count < 2)
                    {
                        new PublicAssmebly().TipMsg(StringId.Tip, StringId.PlsSelectMoreData);
@@ -333,7 +430,6 @@
                    }
                    if (isAdd)
                    {
                        groupControl.name = name;
                        groupControl.sids.Clear();
                        foreach (var light in groupControlLightList)
                        {
@@ -349,83 +445,137 @@
                                MainPage.Log($"新增群控转换数据异常:{ex.Message}");
                            }
                        }
                        try
                        var waitPage = new Loading();
                        bodyView.AddChidren(waitPage);
                        waitPage.Start("");
                        new Thread(() =>
                        {
                            groupControl.type = groupControlType.type;
                            groupControl.sid = groupControl.NewGroupControlSid();
                            var pack = Common.ApiUtlis.Ins.HttpRequest.AddGroupControl(new List<GroupControl>() { groupControl });
                            if (pack != null)
                            try
                            {
                                if (pack.Code == StateCode.SUCCESS)
                                groupControl.type = groupControlType.type;
                                groupControl.sid = groupControl.NewGroupControlSid();
                                var pack = ApiUtlis.Ins.HttpRequest.AddGroupControl(new List<GroupControl>() { groupControl });
                                if (pack != null)
                                {
                                    if (pack.Code == StateCode.SUCCESS)
                                    {
                                        try
                                        {
                                            var addTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GroupControl>>(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
                                    {
                                        var addTemp = Newtonsoft.Json.JsonConvert.DeserializeObject<GroupControl>(pack.Data.ToString());
                                        FunctionList.List.groupControls.Add(addTemp);
                                        waitPage.Hide();
                                        waitPage = null;
                                    }
                                    catch (Exception ex)
                                    {
                                        MainPage.Log($"添加群控成功,转译返回数据失败:{ex.Message}");
                                    }
                                    backActon?.Invoke();
                                    this.RemoveFromParent();
                                }
                                else
                                {
                                    IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                                }
                                    catch { }
                                });
                            }
                        }
                        catch (Exception ex)
                        {
                            MainPage.Log($"新增群控异常:{ex.Message}");
                        }
                        })
                        { IsBackground = true }.Start();
                    }
                    else
                    {
                        try
                        var waitPage = new Loading();
                        bodyView.AddChidren(waitPage);
                        waitPage.Start("");
                        new Thread(() =>
                        {
                            var newEditDataString = Newtonsoft.Json.JsonConvert.SerializeObject(this.groupControl);
                            //没有更新数据则直接退出
                            if (newEditDataString == editDataString)
                            try
                            {
                                this.RemoveFromParent();
                                return;
                            }
                            groupControl.sids.Clear();
                            foreach (var light in groupControlLightList)
                            {
                                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)
                                {
                                    var gc = new GroupControlFunction();
                                    gc.sid = light.sid;
                                    gc.spk = light.spk;
                                    groupControl.sids.Add(gc);
                                    try
                                    {
                                        var gc = new GroupControlFunction();
                                        gc.sid = light.sid;
                                        gc.spk = light.spk;
                                        groupControl.sids.Add(gc);
                                    }
                                    catch (Exception ex)
                                    {
                                        MainPage.Log($"新增群控转换数据异常:{ex.Message}");
                                    }
                                }
                                catch (Exception ex)
                                {
                                    MainPage.Log($"新增群控转换数据异常:{ex.Message}");
                                }
                            }
                            var pack = Common.ApiUtlis.Ins.HttpRequest.EditGroupControl(new List<GroupControl>() { groupControl });
                            if (pack != null)
                            {
                                if (pack.Code == StateCode.SUCCESS)
                                var pack = ApiUtlis.Ins.HttpRequest.EditGroupControl(new List<GroupControl>() { groupControl });
                                if (pack != null)
                                {
                                    backActon?.Invoke();
                                    this.RemoveFromParent();
                                }
                                else
                                {
                                    IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                                    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}");
                        }
                            catch (Exception ex)
                            {
                                MainPage.Log($"编辑群控异常:{ex.Message}");
                            }
                            finally
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    try
                                    {
                                        waitPage.Hide();
                                        waitPage = null;
                                    }
                                    catch { }
                                });
                            }
                        })
                        { IsBackground = true }.Start();
                    }
                }
@@ -451,6 +601,12 @@
                                var groupControlTypes = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GroupControlType>>(pack.Data.ToString());
                                if (groupControlTypes != null && groupControlTypes.Count > 0)
                                {
                                    //groupControlType = new GroupControlType {
                                    //      type = "LIGHT",
                                    //        typeName ="灯光控制",
                                    //        spks = new List<string> { "light.switch" },
                                    //         spkAttrs = new List<string> { "on_off" }
                                    //};
                                    groupControlType = groupControlTypes[0];
                                    Application.RunOnMainThread(() => {
                                        LoadLightRow(lightList);
@@ -484,6 +640,10 @@
                                    groupControl = groupControlTemps[0];
                                    Application.RunOnMainThread(() =>
                                    {
                                        if (groupControl.sids.Count == lightList.Count)
                                        {
                                            btnChooseAll.TextID = StringId.Cancel;
                                        }
                                        LoadLightRow(lightList);
                                    });
                                }
@@ -511,7 +671,7 @@
        /// <summary>
        /// 显示的设备的总数
        /// </summary>
        int showCount = 0;
        int showCount = -1;
        /// <summary>
        /// 加载功能row
@@ -531,18 +691,19 @@
                    {
                        if (!isAppend)
                        {
                            showCount = 0;
                            showCount = -1;
                            functionListView.RemoveAll();
                        }
                        int i = 0;
                        foreach (var function in functions)
                        for(var i =0;i<100;i++)
                        //foreach (var function in functions)
                        {
                            i++;
                            if (i > 100)
                            showCount++;
                            if (showCount >= functions.Count)
                            {
                                break;
                            }
                            showCount++;
                            var function = functions[showCount];
                            var functionDiv = new LightRow(function)
                            {
                                Gravity = Gravity.CenterHorizontal,
@@ -550,7 +711,7 @@
                                BorderColor = 0x00FFFFFF,
                                BorderWidth = 1,
                                BackgroundColor = CSS_Color.MainBackgroundColor,
                                Tag = function.spk + function.sid
                                Tag = "row"
                            };
                            functionDiv.AddChidren(new Button()
                            {
@@ -563,13 +724,22 @@
                            Action setAction = () =>
                            {
                                if (groupControlLightList.Count > 0)
                                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)
@@ -634,8 +804,12 @@
                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 > 0)
                        if (groupControlLightList.Count == listFunc.Count)
                        {
                            groupControlLightList.Clear();
                            btnChooseAll.TextID = StringId.SelectAll;
@@ -643,6 +817,7 @@
                        }
                        else
                        {
                            groupControlLightList.Clear();
                            groupControlLightList.AddRange(listFunc);
                            btnChooseAll.TextID = StringId.Cancel;
                            btnConfrim.IsSelected = true;