mac
2024-07-25 f9181a9c8125136f597add7c30cb2ff508d54ba7
HDL_ON/UI/UI2/4-PersonalCenter/CombinedDimming/CombinedDimmingListPage.cs
@@ -1,8 +1,10 @@
using System;
using System.Collections.Generic;
using HDL_ON.Common;
using HDL_ON.DAL.Server;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Newtonsoft.Json;
using Shared;
namespace HDL_ON.UI
@@ -20,14 +22,21 @@
        public void LoadPage()
        {
            new TopViewDiv(bodyView, Language.StringByID(StringId.CombinedDimming)).LoadTopView_AddIcon("CombinedDimming",
                (s,c)=>{
            var topView = new TopViewDiv(bodyView, Language.StringByID(StringId.GroupControl));
            topView.maginY = 10;
            topView.LoadTopView_AddIcon("CombinedDimming",
                (s, c) =>
                {
                    try
                    {
                        var page = new AddGroupControlPage(new System.Collections.Generic.List<Function>(),new GroupControl(),
                            ()=> {
                            });
                        var page = new AddGroupControlPage(null,
                            (newGC) =>
                            {
                                Application.RunOnMainThread(() =>
                                {
                                    LoadGroupControlView();
                                });
                            }, () => { });
                        MainPage.BasePageView.AddChidren(page);
                        page.LoadPage();
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
@@ -37,24 +46,93 @@
            contentView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64),
                Height = Application.GetRealHeight(550),
                Y = Application.GetRealHeight(64+10),
                Height = Application.GetRealHeight(667 - 64-10),
                BackgroundColor = CSS_Color.MainBackgroundColor,
            };
            bodyView.AddChidren(contentView);
            ReadGroupControlList();
            new System.Threading.Thread(() => {
                var http = new HttpServerRequest();
                var pack = http.GetGroupControlList();
                if(pack != null)
            #region
            contentView.AddChidren(new Button() { Height = Application.GetRealHeight(8) });
            #endregion
        }
        /// <summary>
        /// 读取组控数据
        /// </summary>
        private void ReadGroupControlList()
        {
            new System.Threading.Thread(() =>
            {
                var pack = ApiUtlis.Ins.HttpRequest.GetGroupControlList();
                if (pack != null)
                {
                    if(pack.Code == StateCode.SUCCESS  )
                    if (pack.Code == StateCode.SUCCESS)
                    {
                        try
                        {
                            var groupControlList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GroupControl>>(pack.Data.ToString());
                            LoadGroupControlView(groupControlList);
                            //FunctionList.List.groupControls.Clear();
                            //FunctionList.List.groupControls = Newtonsoft.Json.JsonConvert.DeserializeObject<List<GroupControl>>(pack.Data.ToString());
                            try
                            {
                                var groupControlList = JsonConvert.DeserializeObject<List<GroupControl>>(pack.Data.ToString());
                                var readSidList = new List<string>();
                                foreach (var temp in groupControlList)
                                {
                                    FunctionList.List.groupControls.Clear();
                                    readSidList.Add(temp.userDeviceGroupControlId);
                                    if (readSidList.Count >= 20)
                                    {
                                        var data = ApiUtlis.Ins.HttpRequest.GetGroupControInfo(readSidList);
                                        if (data != null)
                                        {
                                            if (data.Code == StateCode.SUCCESS)
                                            {
                                                var groupControlInfoList = JsonConvert.DeserializeObject<List<GroupControl>>(data.Data.ToString());
                                                FunctionList.List.groupControls.AddRange(groupControlInfoList);
                                            }
                                            else
                                            {
                                                IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                                            }
                                        }
                                        readSidList.Clear();
                                    }
                                }
                                if (readSidList.Count > 0)
                                {
                                    var data = ApiUtlis.Ins.HttpRequest.GetGroupControInfo(readSidList);
                                    if (data != null)
                                    {
                                        if (data.Code == StateCode.SUCCESS)
                                        {
                                            var groupControlInfoList = JsonConvert.DeserializeObject<List<GroupControl>>(data.Data.ToString());
                                            FunctionList.List.groupControls.AddRange(groupControlInfoList);
                                        }
                                        else
                                        {
                                            IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                                        }
                                    }
                                    readSidList.Clear();
                                }
                            }
                            catch (Exception ex)
                            {
                                MainPage.Log($"读取组控列表失败:{ex.Message}");
                            }
                            Application.RunOnMainThread(() =>
                            {
                                LoadGroupControlView();
                            });
                        }
                        catch (Exception ex)
                        {
@@ -66,79 +144,176 @@
                        IMessageCommon.Current.ShowErrorInfoAlter(pack.Code);
                    }
                }
            }) { IsBackground = true }.Start();
            #region
            contentView.AddChidren(new Button() { Height = Application.GetRealHeight(8) });
            #endregion
            })
            { IsBackground = true }.Start();
        }
        private void LoadGroupControlView(List<GroupControl> list)
        private void LoadGroupControlView()
        {
            if(list.Count == 0)
            {
            contentView.RemoveAll();
            }
            else
            foreach (var groupControl in FunctionList.List.groupControls)
            {
                contentView.RemoveAll();
                foreach (var function in list)
                var functionRow = new RowLayout()
                {
                    var functionRow = new FrameLayout()
                    Height = Application.GetRealHeight(65),
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                    LineColor = 0x00000000
                };
                contentView.AddChidren(functionRow);
                var btnRight = new Button()
                {
                    X = Application.GetRealWidth(339),
                    Gravity = Gravity.CenterVertical,
                    Width = Application.GetMinRealAverage(16),
                    Height = Application.GetMinRealAverage(16),
                    UnSelectedImagePath = "Public/Right.png",
                };
                functionRow.AddChidren(btnRight);
                var btnFunctionName = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = Application.GetRealHeight(10),
                    Width = Application.GetRealWidth(308),
                    Height = Application.GetRealHeight(24),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = CSS_FontSize.SubheadingFontSize,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    Text = groupControl.name,
                };
                functionRow.AddChidren(btnFunctionName);
                var btnFunctionLocationInfo = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Y = btnFunctionName.Bottom,
                    Width = Application.GetRealWidth(308),
                    Height = Application.GetRealHeight(21),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                    TextColor = CSS_Color.PromptingColor1,
                    Text = groupControl.GetRoomListName(),
                };
                functionRow.AddChidren(btnFunctionLocationInfo);
                functionRow.AddChidren(
                    new Button()
                    {
                        Height = Application.GetRealHeight(65),
                        BackgroundColor = CSS_Color.MainBackgroundColor,
                    };
                    contentView.AddChidren(functionRow);
                        Gravity = Gravity.CenterHorizontal,
                        Y = Application.GetRealHeight(64),
                        Height = Application.GetRealHeight(1),
                        Width = Application.GetRealWidth(343),
                        BackgroundColor = CSS_Color.DividingLineColor,
                    });
                    var btnFunctionName = new Button()
                EventHandler<MouseEventArgs> eventHandler = (sender, e) =>
                {
                    var page = new AddGroupControlPage(groupControl,
                       (newGC) =>
                       {
                           try
                           {
                               if (newGC != null)
                               {
                                   Application.RunOnMainThread(() =>
                                   {
                                       var localTemp = FunctionList.List.groupControls.Find((obj) => obj.deviceId == newGC.deviceId);
                                       localTemp.roomIds = newGC.roomIds;
                                       localTemp.uids = newGC.uids;
                                       localTemp.sids = newGC.sids;
                                       localTemp.name = newGC.name;
                                       btnFunctionLocationInfo.Text = newGC.GetUidListName();
                                       btnFunctionName.Text = newGC.name;
                                   });
                               }
                           }
                           catch (Exception ex)
                           {
                               MainPage.Log($"刷新群控房间信息异常:{ex.Message}");
                           }
                       }, () =>
                       {
                           LoadGroupControlView();
                       });
                    MainPage.BasePageView.AddChidren(page);
                    page.LoadPage();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                };
                functionRow.MouseUpEventHandler = eventHandler;
                btnRight.MouseUpEventHandler = eventHandler;
                btnFunctionName.MouseUpEventHandler = eventHandler;
                btnFunctionLocationInfo.MouseUpEventHandler = eventHandler;
                var btnDelGroupControl = new Button()
                {
                    TextColor = CSS_Color.MainBackgroundColor,
                    BackgroundColor = CSS_Color.WarningColor,
                    TextID = StringId.Del,
                    TextAlignment = TextAlignment.Center,
                };
                functionRow.AddRightView(btnDelGroupControl);
                btnDelGroupControl.MouseUpEventHandler = (sender1, e1) =>
                {
                    var waitPage = new Loading();
                    this.AddChidren(waitPage);
                    waitPage.Start("");
                    new System.Threading.Thread(() =>
                    {
                        X = Application.GetRealWidth(16),
                        Y = Application.GetRealHeight(10),
                        Width = Application.GetRealWidth(308),
                        Height = Application.GetRealHeight(24),
                        TextAlignment = TextAlignment.CenterLeft,
                        TextSize = CSS_FontSize.SubheadingFontSize,
                        TextColor = CSS_Color.FirstLevelTitleColor,
                        Text = function.name,
                    };
                    functionRow.AddChidren(btnFunctionName);
                    var btnFunctionLocationInfo = new Button()
                    {
                        X = Application.GetRealWidth(16),
                        Y = btnFunctionName.Bottom,
                        Width = Application.GetRealWidth(308),
                        Height = Application.GetRealHeight(21),
                        TextAlignment = TextAlignment.CenterLeft,
                        TextSize = CSS_FontSize.PromptFontSize_FirstLevel,
                        TextColor = CSS_Color.PromptingColor1,
                        Text = function.GetRoomListName(),
                    };
                    functionRow.AddChidren(btnFunctionLocationInfo);
                    functionRow.AddChidren(
                        new Button()
                        try
                        {
                            Gravity = Gravity.CenterHorizontal,
                            Y = Application.GetRealHeight(64),
                            Height = Application.GetRealHeight(1),
                            Width = Application.GetRealWidth(343),
                            BackgroundColor = CSS_Color.DividingLineColor,
                        });
                }
                            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);
                                            LoadGroupControlView();
                                        }
                                        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();
                };
            }
        }