wei
2021-08-27 eda3fb873e59544ff36301b51e05aef64f87b0f9
HDL_ON/UI/UI2/3-Intelligence/Automation/FunTpye.cs
New file
@@ -0,0 +1,280 @@
using System;
using HDL_ON.UI.UI2.Intelligence.Automation.LogicView;
using Shared;
using System.Collections.Generic;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class FunTpye : FrameLayout
    {
        public FunTpye()
        {
            Tag = "Logic";
        }
        /// <summary>
        /// 默认选中是房间时:全部区域
        /// </summary>
        private Entity.Room selectedRoom = new Entity.Room { roomId ="6688" };
        /// <summary>
        /// 表示是(条件/目标)
        /// </summary>
        private string if_type;
        public void Show(string str)
        {
            if_type = str;
            this.BackgroundColor = CSS.CSS_Color.viewMiddle;
            LogicView.TopView topView = new LogicView.TopView();
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
            {
                RemoveFromParent();
            };
            topView.topNameBtn.TextID = StringId.selectedFunCondition;
            LogicView.FunAllAreaView funAllAreaView = new LogicView.FunAllAreaView();
            funAllAreaView.frameLayout.Y = topView.frameLayout.Bottom;
            this.AddChidren(funAllAreaView.FLayoutView());
            VerticalScrolViewLayout vv = new VerticalScrolViewLayout
            {
                Y = Application.GetRealHeight(117),
                Height = Application.GetRealHeight(667 - 117),
            };
            this.AddChidren(vv);
            //房间点击事件
            EventHandler<MouseEventArgs> roomClick = (sender, e) =>
            {
                #region 区域弹框界面
                FrameLayout fLayout = new FrameLayout
                {
                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                };
                this.AddChidren(fLayout);
                fLayout.MouseUpEventHandler += (sender1, e1) =>
                {
                    fLayout.RemoveFromParent();
                };
                FrameLayout bghFrameLyout = new FrameLayout
                {
                    X = Application.GetRealWidth(10),
                    Y = Application.GetRealHeight(103),
                    Width = Application.GetRealWidth(160),
                    Height = Application.GetRealHeight(21 + 44),
                    //BackgroundImagePath = "LogicIcon/bjicon.png",
                };
                fLayout.AddChidren(bghFrameLyout);
                FrameLayout areaBgh = new FrameLayout
                {
                    X = Application.GetRealWidth(8),
                    Y = Application.GetRealHeight(14),
                    Width = Application.GetRealWidth(144),
                    Height = Application.GetRealHeight(44),
                };
                VerticalScrolViewLayout vvBgh = new VerticalScrolViewLayout
                {
                    X = Application.GetRealWidth(8),
                    Y = Application.GetRealHeight(14),
                    Width = Application.GetRealWidth(144),
                    Height = Application.GetRealHeight(44 * 5),
                };
                var roomList = LogicMethod.CurrLogicMethod.GetGatewayRoomList(Language.StringByID(StringId.allAreas));
                if (roomList.Count > 5)
                {
                    bghFrameLyout.Height = Application.GetRealHeight(21 + 44 * 5);
                    bghFrameLyout.AddChidren(vvBgh);
                    bghFrameLyout.BackgroundImagePath = "LogicIcon/bjicon5.png";
                }
                else
                {
                    bghFrameLyout.AddChidren(areaBgh);
                    bghFrameLyout.Height = Application.GetRealHeight(21 + 44 * roomList.Count);
                    areaBgh.Height = Application.GetRealHeight(44 * roomList.Count);
                    bghFrameLyout.BackgroundImagePath = $"LogicIcon/bjicon{roomList.Count}.png";
                }
                #endregion
                for (int i = 0; i < roomList.Count; i++)
                {
                    var room = roomList[i];
                    LogicView.AreaView areaView = new LogicView.AreaView();
                    if (roomList.Count > 5)
                    {
                        vvBgh.AddChidren(areaView.FLayoutView());
                    }
                    else
                    {
                        areaView.frameLayout.Y = Application.GetRealHeight(i * 44);
                        areaBgh.AddChidren(areaView.FLayoutView());
                    }
                    areaView.btnRoomName.Text = room.roomName;
                    areaView.btnClick.Tag = room;
                    areaView.btnClick.MouseUpEventHandler += (sender2, e2) =>
                    {
                        fLayout.RemoveFromParent();
                        funAllAreaView.btnText1.Text = (areaView.btnClick.Tag as Entity.Room).roomName;
                        ///切换房间默认功能类型全部;
                        funAllAreaView.btnText2.Text = Language.StringByID(StringId.allFun);
                        selectedRoom = (areaView.btnClick.Tag as Entity.Room);
                        ///获取显示设备列表
                        var list = LogicMethod.CurrLogicMethod.GetFunctionDeviceList(areaView.btnClick.Tag as Entity.Room,if_type);
                        DeviceListView(vv, list);
                    };
                    if (roomList.Count-1==i) {
                        ///改变最后那条一个线的颜色,界面显示效果作用;
                        areaView.btnLine.BackgroundColor = CSS.CSS_Color.view;
                    }
                }
            };
            funAllAreaView.btnText1.MouseUpEventHandler += roomClick;
            funAllAreaView.btnIcon1.MouseUpEventHandler += roomClick;
            //功能点击事件
            EventHandler<MouseEventArgs> funClick = (sender3, e3) =>{
                //获取最终显示列表
                var functionList = LogicMethod.CurrLogicMethod.GetFunctionDeviceList(selectedRoom, if_type);
                //获取设备列表的类型(例如:灯光类,窗帘类。。。)
                var deviceTypeList = LogicMethod.CurrLogicMethod.GetDeviceTypeList(functionList);
                if (deviceTypeList.Count==0) {
                    //没有类型直接返回去;
                    return;
                }
                #region 区域弹框界面
                FrameLayout fLayout = new FrameLayout
                {
                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                };
                this.AddChidren(fLayout);
                fLayout.MouseUpEventHandler += (sender1, e1) =>
                {
                    fLayout.RemoveFromParent();
                };
                FrameLayout bghFrameLyout = new FrameLayout
                {
                    X = Application.GetRealWidth(118),
                    Y = Application.GetRealHeight(103),
                    Width = Application.GetRealWidth(160),
                    Height = Application.GetRealHeight(21 + 44),
                    //BackgroundImagePath = "LogicIcon/bjicon5.png",
                };
                fLayout.AddChidren(bghFrameLyout);
                FrameLayout areaBgh = new FrameLayout
                {
                    X = Application.GetRealWidth(8),
                    Y = Application.GetRealHeight(14),
                    Width = Application.GetRealWidth(144),
                    Height = Application.GetRealHeight(44),
                };
                VerticalScrolViewLayout vvBgh = new VerticalScrolViewLayout
                {
                    X = Application.GetRealWidth(8),
                    Y = Application.GetRealHeight(14),
                    Width = Application.GetRealWidth(144),
                    Height = Application.GetRealHeight(44 * 5),
                };
                if (deviceTypeList.Count > 5)
                {
                    bghFrameLyout.Height = Application.GetRealHeight(21 + 44 * 5);
                    bghFrameLyout.AddChidren(vvBgh);
                    bghFrameLyout.BackgroundImagePath = "LogicIcon/bjicon5.png";
                }
                else
                {
                    bghFrameLyout.AddChidren(areaBgh);
                    bghFrameLyout.Height = Application.GetRealHeight(21 + 44 * deviceTypeList.Count);
                    areaBgh.Height = Application.GetRealHeight(44 * deviceTypeList.Count);
                    bghFrameLyout.BackgroundImagePath = $"LogicIcon/bjicon{deviceTypeList.Count}.png";
                }
                #endregion
                for (int i = 0; i < deviceTypeList.Count; i++)
                {
                    var deviceTypeName = deviceTypeList[i];
                    LogicView.AreaView areaView = new LogicView.AreaView();
                    if (deviceTypeList.Count > 5)
                    {
                        vvBgh.AddChidren(areaView.FLayoutView());
                    }
                    else
                    {
                        areaView.frameLayout.Y = Application.GetRealHeight(i * 44);
                        areaBgh.AddChidren(areaView.FLayoutView());
                    }
                    areaView.btnRoomName.Text = deviceTypeName;
                    areaView.btnClick.Tag = deviceTypeName;
                    areaView.btnClick.MouseUpEventHandler += (sender, e2) =>
                    {
                        fLayout.RemoveFromParent();
                        funAllAreaView.btnText2.Text = areaView.btnClick.Tag.ToString();
                        ///获取单个类型(例如:灯光类。。)设备FunctionType列表
                        var typeFunctionList = LogicMethod.CurrLogicMethod.GetDeviceTypeFunctionList(areaView.btnClick.Tag.ToString());
                        ///获取单个灯光类型(例如:灯光1,灯光2。。)显示设备列表
                        var lists = LogicMethod.CurrLogicMethod.GetShowDeviceList(typeFunctionList, functionList);
                        DeviceListView(vv, lists);
                    };
                    if (deviceTypeList.Count - 1 == i)
                    {
                        ///改变最后那条一个线的颜色,界面显示效果作用;
                        areaView.btnLine.BackgroundColor = CSS.CSS_Color.view;
                    }
                }
            };
            funAllAreaView.btnText2.MouseUpEventHandler += funClick;
            funAllAreaView.btnIcon2.MouseUpEventHandler += funClick;
            ///获取显示设备列表
            var deviceList = LogicMethod.CurrLogicMethod.GetFunctionDeviceList(selectedRoom, if_type);
            DeviceListView(vv, deviceList);
        }
        /// <summary>
        /// 显示设备的View
        /// </summary>
        /// <param name="verticalScrolView">上下滑动</param>
        /// <param name="deviceList"></param>
        public void DeviceListView(VerticalScrolViewLayout verticalScrolView, List<HDL_ON.Entity.Function>  deviceList)
        {
            verticalScrolView.RemoveAll();
            foreach (var dev in deviceList)
            {
                LogicView.SelectTypeView funView = new LogicView.SelectTypeView();
                funView.btnText.Visible = false;
                funView.btnDeviceName.Visible = true;
                funView.btnRoomName.Visible = true;
                funView.btnLine.X = Application.GetRealWidth(16);
                funView.btnLine.Width = Application.GetRealWidth(343);
                verticalScrolView.AddChidren(funView.FLayoutView());
                funView.btnIcon.UnSelectedImagePath = LogicMethod.CurrLogicMethod.GetIconPath(dev.spk);
                funView.btnDeviceName.Text = dev.name;
                funView.btnRoomName.Text = dev.GetRoomListName();
                funView.btnClick.MouseUpEventHandler += (sen,e) => {
                    if (if_type == LogicMethod.condition_if) {
                        ConditionDeviceFunList conditionDeviceFunList = new ConditionDeviceFunList();
                        MainPage.BasePageView.AddChidren(conditionDeviceFunList);
                        conditionDeviceFunList.Show(dev, 0, false);
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    } else {
                        TargetDeviceFunList targetDeviceFunList = new TargetDeviceFunList();
                        MainPage.BasePageView.AddChidren(targetDeviceFunList);
                        targetDeviceFunList.Show(dev, 0, false);
                        MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    }
                };
            }
        }
    }
}