陈嘉乐
2020-05-15 d5b9ff8bf8cc36f5b13c46b66682f5988d3a6f36
ZigbeeApp/Shared/Phone/Device/Logic/Method.cs
@@ -21,8 +21,7 @@
        /// <param name="device">Device.</param>
        public static void RoomNmae(Button button, CommonDevice device)
        {
            var room = new Common.Room();
            button.Text = room.GetRoomNameByDevice(device);
            button.Text = UserCenter.HdlRoomLogic.Current.GetRoomNameByDevice(device);
        }
        /// <summary>
        /// 返回楼层所有的房间的列表
@@ -33,11 +32,12 @@
        public static List<Common.Room> GetRoomList(string type, string floorId = null)
        {
            var list = new List<Common.Room>();
            for (int i = 0; i < Common.Room.Lists.Count; i++)
            var listAllRoom = UserCenter.HdlRoomLogic.Current.GetAllListRooms();
            for (int i = 0; i < listAllRoom.Count; i++)
            {
                if (type == "action_logicscene" || type == "action_lockscene")
                {
                    if (Common.Room.Lists[i].SceneUIList.Count == 0)
                    if (listAllRoom[i].ListSceneId.Count == 0)
                    {   ///过滤掉没有场景的房间
                        continue;
                    }
@@ -46,14 +46,14 @@
                {
                    ///区分出输入条件和输出目标设备
                    var listdevicetype = GetDevice(type);
                    var listdevice = GetDeviceUIList(Common.Room.Lists[i], listdevicetype);
                    var listdevice = GetDeviceUIList(listAllRoom[i], listdevicetype);
                    if (listdevice.Count == 0)
                    {
                        ///过滤掉没有设备的房间
                        continue;
                    }
                }
                list.Add(Common.Room.Lists[i]);
                list.Add(listAllRoom[i]);
            }
            if (string.IsNullOrEmpty(floorId))
            {
@@ -69,19 +69,30 @@
        /// <param name="room">当前房间</param>
        /// <param name="deviceTypelist">设备类型</param>
        /// <returns></returns>
        public static List<DeviceUI> GetDeviceUIList(Common.Room room, List<DeviceType> deviceTypelist)
        public static List<CommonDevice> GetDeviceUIList(Common.Room room, List<DeviceType> deviceTypelist)
        {
            var deviceUIlist = new List<DeviceUI>();
            foreach (var device in room.DeviceUIList)
            var deviceUIlist = new List<CommonDevice>();
            foreach (var deviceKey in room.ListDevice)
            {
                if (device.CommonDevice == null)
                var device = LocalDevice.Current.GetDevice(deviceKey);
                if (device == null)
                {
                    continue;
                }
                if (!deviceTypelist.Contains(device.CommonDevice.Type))
                if (!deviceTypelist.Contains(device.Type))
                {
                    //过滤掉不支持的设备
                    continue;
                }
                if (device.Type == DeviceType.DoorLock)
                {
                    var myInfo = LocalDevice.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
                    if (myInfo.ConcreteType == DeviceConcreteType.IntelligentLocks_Sone)
                    {
                        //暂时不支持S-one门锁;
                        //过滤掉不支持S-one门锁设备;
                        continue;
                    }
                }
                deviceUIlist.Add(device);
            }
@@ -90,47 +101,53 @@
        /// <summary>
        /// 排列所有设备类型的列表
        /// </summary>
        /// <param name="type">判断字符串</param>
        /// <param name="devicelist">设备列表</param>
        /// <returns></returns>
        public static List<string> GetDeviceTypeList(string type, List<DeviceUI> devicelist)
        public static List<string> GetDeviceTypeList(List<CommonDevice> devicelist)
        {
            List<string> devicetypelist = new List<string>();
            devicetypelist.Clear();
            var lightjosn = devicelist.Find((device) => device.CommonDevice.Type == DeviceType.ColorDimmableLight || device.CommonDevice.Type == DeviceType.OnOffOutput);
            var lightjosn = devicelist.Find((device) => device.Type == DeviceType.DimmableLight || device.Type == DeviceType.OnOffOutput);
            if (lightjosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Lights));
            }
            var iASZonejosn = devicelist.Find((device) => device.CommonDevice.Type == DeviceType.IASZone || device.CommonDevice.Type == DeviceType.TemperatureSensor);
            if (iASZonejosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.sensor));
            }
            var onOffSwitchjson = devicelist.Find((device) => device.CommonDevice.Type == DeviceType.OnOffSwitch);
            if (onOffSwitchjson != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.OnOffSwitch));
            }
            var doorLock = devicelist.Find((device) => device.CommonDevice.Type == DeviceType.DoorLock);
            if (doorLock != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.doorLock));
            }
            var curtainjosn = devicelist.Find((device) => device.CommonDevice.Type == DeviceType.WindowCoveringDevice);
            var curtainjosn = devicelist.Find((device) => device.Type == DeviceType.WindowCoveringDevice);
            if (curtainjosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Curtains));
            }
            var ac = devicelist.Find((device) => device.CommonDevice.Type == DeviceType.Thermostat);
            var ac = devicelist.Find((device) => device.Type == DeviceType.Thermostat);
            if (ac != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.AC));
            }
            var airSwitch = devicelist.Find((device) => device.CommonDevice.Type == DeviceType.AirSwitch);
            var onOffSwitchjson = devicelist.Find((device) => device.Type == DeviceType.OnOffSwitch);
            if (onOffSwitchjson != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.OnOffSwitch));
            }
            var doorLock = devicelist.Find((device) => device.Type == DeviceType.DoorLock);
            if (doorLock != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.doorLock));
            }
            var airSwitch = devicelist.Find((device) => device.Type == DeviceType.AirSwitch);
            if (airSwitch != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Airswitch));
            }
            var iASZonejosn = devicelist.Find((device) => device.Type == DeviceType.IASZone || device.Type == DeviceType.TemperatureSensor);
            if (iASZonejosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.sensor));
            }
            return devicetypelist;
@@ -224,11 +241,11 @@
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="button">显示图标的控件</param>
        public static void GetDeviceIcon(DeviceUI device, Button button)
        public static void GetDeviceIcon(CommonDevice device, Button button)
        {
            string patm = "";
            string selectedpatm = "";
            switch (device.CommonDevice.Type)
            switch (device.Type)
            {
                case DeviceType.OnOffOutput:
                    {
@@ -238,7 +255,7 @@
                    break;
                case DeviceType.IASZone:
                    {
                        var iASZonedevice = device.CommonDevice as IASZone;
                        var iASZonedevice = device as IASZone;
                        if (iASZonedevice.DeviceID != 1026)
                        {
                            break;
@@ -249,7 +266,7 @@
                    break;
                case DeviceType.TemperatureSensor:
                    {
                        var temperatureSensor = device.CommonDevice as TemperatureSensor;
                        var temperatureSensor = device as TemperatureSensor;
                        if (temperatureSensor.SensorDiv == 1)
                        {
                            patm = $"ZigeeLogic/temperature.png";
@@ -325,12 +342,16 @@
                    }
                    break;
                case "action_logic":
                    { //自动化支持的目标设备
                    {
                        //自动化支持的目标设备
                        deviceTypeList.Add(DeviceType.OnOffOutput);
                        deviceTypeList.Add(DeviceType.DimmableLight);
                        deviceTypeList.Add(DeviceType.WindowCoveringDevice);
                        deviceTypeList.Add(DeviceType.Thermostat);
                        deviceTypeList.Add(DeviceType.AirSwitch);
                        ///门锁特殊
                       // deviceTypeList.Add(DeviceType.DoorLock);
                    }
                    break;
                case "condition_mould":
@@ -351,6 +372,8 @@
                        deviceTypeList.Add(DeviceType.WindowCoveringDevice);
                        deviceTypeList.Add(DeviceType.Thermostat);
                        deviceTypeList.Add(DeviceType.AirSwitch);
                        ///门锁特殊
                      // deviceTypeList.Add(DeviceType.DoorLock);
                    }
                    break;
@@ -648,6 +671,7 @@
            custompushview.iconBtn.Visible = true;
            custompushview.iconBtn.UnSelectedImagePath = "ZigeeLogic/next.png";
            custompushview.titleBtn.TextID = MyInternationalizationString.custompush;
            custompushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
            middle.AddChidren(custompushview.AddDeviceView());
            EventHandler<MouseEventArgs> customclick = (sender, e) =>
@@ -668,6 +692,7 @@
                    LogicView.IfString.Tag = true;
                    custompushview.frameLayout.Height = Application.GetRealHeight(160);
                    Common.Logic.CurrentLogic.LogicIsCustomPushText = 1;
                    pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor;
                }
                else
@@ -675,8 +700,13 @@
                    LogicView.IfString.Tag = false;
                    custompushview.frameLayout.Height = Application.GetRealHeight(0);
                    Common.Logic.CurrentLogic.LogicIsCustomPushText = 0;
                    pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
                }
                Send.Zj(LogicView.IfString.Tag, Common.Logic.CurrentLogic);
                if (!Config.Instance.Home.IsVirtually)
                {
                    Send.Zj(LogicView.IfString.Tag, Common.Logic.CurrentLogic);
                }
            };
            if (Common.Logic.CurrentLogic.LogicIsCustomPushText == 0)
@@ -684,12 +714,14 @@
                LogicView.IfString.Tag = false;
                pushview.switchBtn.IsSelected = false;
                custompushview.frameLayout.Height = Application.GetRealHeight(0);
                pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
            }
            else
            {
                LogicView.IfString.Tag = true;
                pushview.switchBtn.IsSelected = true;
                custompushview.frameLayout.Height = Application.GetRealHeight(160);
                pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor;
            }
        }
        /// <summary>
@@ -701,6 +733,16 @@
        /// <param name="CurrentLogic">当前逻辑</param>
        public async static void SaveLogic(string if_logic, string name, bool tag, Common.Logic CurrentLogic)
        {
            if (CurrentLogic.Conditions.Count == 0 || CurrentLogic.Actions.Count == 0)
            {
                var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Normal,
                  Language.StringByID(MyInternationalizationString.addnull),
                  Language.StringByID(MyInternationalizationString.confrim));
                alert.Show();
                return;
            }
            if (string.IsNullOrEmpty(name))
            {
                var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Normal,
@@ -721,28 +763,94 @@
            bool succeed = false;
            //判断是新添加逻辑(默认0)还是修改逻辑
            CommonPage.Loading.Start();
            if (CurrentLogic.LogicId == 0)
            if (Config.Instance.Home.IsVirtually)
            {
                //发送添加逻辑命令
                var logicifon = await Send.AddModifyLogic(CurrentLogic);
                if (logicifon != null && logicifon.LogicId != 0)
                if (Common.Logic.LogicList.Count == 0)
                {
                    succeed = true;
                    CurrentLogic.LogicId = logicifon.LogicId;
                    CurrentLogic.LogicId = 1;
                    Common.Logic.LogicList.Add(CurrentLogic);
                    if (tag)
                    {
                        Send.Zj(tag, CurrentLogic);
                    }
                }
                if (CurrentLogic.LogicId == 0)
                {
                    bool d = false;
                    for (int i = 1; i < 50; i++)
                    {
                        for (int j = 0; j < Common.Logic.LogicList.Count; j++)
                        {
                            if (i != Common.Logic.LogicList[j].LogicId)
                            {
                                CurrentLogic.LogicId = i;
                                Common.Logic.LogicList.Add(CurrentLogic);
                                d = true;
                                break;
                            }
                        }
                        if (d)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    for (int j = 0; j < Common.Logic.LogicList.Count; j++)
                    {
                        if (CurrentLogic.LogicId == Common.Logic.LogicList[j].LogicId)
                        {
                            Common.Logic.LogicList.RemoveAt(j);
                            Common.Logic.LogicList.Insert(j,CurrentLogic);
                            break;
                        }
                    }
                }
                //自动化逻辑列表
            }
            else
            {
                //发送修改逻辑命令;
                //修改命令不需要等待回复;
                Send.AddModifyLogic(CurrentLogic);
                //编辑默认成功(不考虑网络情况);
                succeed = true;
                if (CurrentLogic.LogicId == 0)
                {
                    //发送添加逻辑命令
                    var logicifon = await Send.AddModifyLogic(CurrentLogic);
                    if (logicifon != null && logicifon.LogicId != 0)
                    {
                        succeed = true;
                        CurrentLogic.LogicId = logicifon.LogicId;
                        if (LogicView.IfString._Logic == if_logic || LogicView.IfString._SoneLogic == if_logic)
                        {
                            //自动化逻辑列表
                            Common.Logic.LogicList.Add(CurrentLogic);
                        }
                        if (LogicView.IfString._LockLogic == if_logic)
                        {
                            //门锁联动事件逻辑列表
                            Common.Logic.LockLogicList.Add(CurrentLogic);
                        }
                        if (LogicView.IfString._SoneLogic == if_logic)
                        {
                            //Sone门锁联动事件逻辑列表
                            Common.Logic.SoneLogicList.Add(CurrentLogic);
                        }
                        if (tag)
                        {
                            Send.Zj(tag, CurrentLogic);
                        }
                    }
                }
                else
                {
                    //发送修改逻辑命令;
                    //修改命令不需要等待回复;
                    Send.AddModifyLogic(CurrentLogic);
                    //编辑默认成功(不考虑网络情况);
                    succeed = true;
                }
            }
            CommonPage.Loading.Hide();
@@ -754,20 +862,52 @@
                //TipView("添加自动化失败");
                //return;
            }
            UserView.HomePage.Instance.RemoveViewByTag("Logic");
            UserView.HomePage.Instance.RemoveViewByTag("Logic");//移除所有标记Logic界面
            if (LogicView.IfString._Logic == if_logic)
            {
                Category.Category.instance?.RefreshBodyView();
                //只刷新分类-自动化上下滑动view;
                Phone.Category.CategoryMainForm.instance?.RefreshBodyView();
                // Category.Category.instance?.RefreshBodyView();
            }
            else if (LogicView.IfString._LockLogic == if_logic)
            {
                //跳到门锁联动事件列表界面
                UserView.HomePage.Instance.RemoveViewByTag("LockListView");//移除所有标记LockListView界面
                var doorLockLogicList = new DoorLockLogic.LockLogicList();
                UserView.HomePage.Instance.AddChidren(doorLockLogicList);
                UserView.HomePage.Instance.PageIndex += 1;
                doorLockLogicList.Show();
            }
            else if (LogicView.IfString._SoneLogic == if_logic)
            {
                //跳到Sone门锁联动事件列表界面
                //UserView.HomePage.Instance.RemoveViewByTag("SoneLogic");//移除所有标记LockListView界面
                //var soneLogicList = new SoneLogicList();
                //UserView.HomePage.Instance.AddChidren(soneLogicList);
                //UserView.HomePage.Instance.PageIndex += 1;
                //soneLogicList.Show();
                SoneLogicList.soneLogicList?.RefreshView();
            }
        }
        /// <summary>
        /// 跳入输出目标功能界面的方法
        /// </summary>
        /// <param name="str1">设备界面识别字符串</param>
        /// <param name="str2">场景界面识别字符串</param>
        public static void View(string str1, string str2)
        {
            var deviceTarget = new DeviceTarget();
            UserView.HomePage.Instance.AddChidren(deviceTarget);
            UserView.HomePage.Instance.PageIndex += 1;
            deviceTarget.Show(str1, str2);
        }
        /// <summary>
        /// 界面高度
        /// </summary>
        public static int H = 1922;
    }
}