xm
2020-07-21 9a4b76398009cf76c508d61f7e48fb6f5cb7ac2d
ZigbeeApp/Shared/Phone/Device/Logic/Method.cs
New file
@@ -0,0 +1,922 @@
using System;
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using ZigBee.Device;
using ZigBee.Common;
using Shared.Common;
using System.Collections.Specialized;
using System.Net;
using System.IO;
using Shared.R;
namespace Shared.Phone.Device.Logic
{
    public class Method
    {
        // <summary>
        /// 通过设备找到区域(房间)名称
        /// </summary>
        /// <param name="button">Btnregionname.</param>
        /// <param name="device">Device.</param>
        public static void RoomNmae(Button button, CommonDevice device)
        {
            button.Text = UserCenter.HdlRoomLogic.Current.GetRoomNameByDevice(device);
        }
        /// <summary>
        /// 返回楼层所有的房间的列表
        /// </summary>
        /// <param name="type">判断字符串</param>
        /// <param name="floorId">楼层ID</param>
        /// <returns></returns>
        public static List<Common.Room> GetRoomList(string type, string floorId = null)
        {
            var list = new List<Common.Room>();
            var listAllRoom = UserCenter.HdlRoomLogic.Current.GetAllListRooms();
            for (int i = 0; i < listAllRoom.Count; i++)
            {
                if (type == "action_logicscene" || type == "action_lockscene")
                {
                    if (listAllRoom[i].ListSceneId.Count == 0)
                    {   ///过滤掉没有场景的房间
                        continue;
                    }
                }
                else
                {
                    ///区分出输入条件和输出目标设备
                    var listdevicetype = GetDevice(type);
                    var listdevice = GetDeviceUIList(listAllRoom[i], listdevicetype);
                    if (listdevice.Count == 0)
                    {
                        ///过滤掉没有设备的房间
                        continue;
                    }
                }
                list.Add(listAllRoom[i]);
            }
            if (string.IsNullOrEmpty(floorId))
            {
                //没有楼层直接返回所有的房间;
                return list;
            }
            //某楼层所有的房间;
            return list.FindAll((obj) => obj.FloorId == floorId);
        }
        /// <summary>
        /// 获取房间的设备列表
        /// </summary>
        /// <param name="room">当前房间</param>
        /// <param name="deviceTypelist">设备类型</param>
        /// <returns></returns>
        public static List<CommonDevice> GetDeviceUIList(Common.Room room, List<DeviceType> deviceTypelist)
        {
            var deviceUIlist = new List<CommonDevice>();
            foreach (var deviceKey in room.ListDevice)
            {
                var device = LocalDevice.Current.GetDevice(deviceKey);
                if (device == null)
                {
                    continue;
                }
                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);
            }
            return deviceUIlist;
        }
        /// <summary>
        /// 排列所有设备类型的列表
        /// </summary>
        /// <param name="devicelist">设备列表</param>
        /// <returns></returns>
        public static List<string> GetDeviceTypeList(List<CommonDevice> devicelist)
        {
            List<string> devicetypelist = new List<string>();
            devicetypelist.Clear();
            var lightjosn = devicelist.Find((device) => device.Type == DeviceType.DimmableLight || device.Type == DeviceType.OnOffOutput || device.Type == DeviceType.ColorTemperatureLight);
            if (lightjosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Lights));
            }
            var curtainjosn = devicelist.Find((device) => device.Type == DeviceType.WindowCoveringDevice);
            if (curtainjosn != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.Curtains));
            }
            var ac = devicelist.Find((device) => device.Type == DeviceType.Thermostat);
            if (ac != null)
            {
                devicetypelist.Add(Language.StringByID(MyInternationalizationString.AC));
            }
            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;
        }
        /// <summary>
        /// 某个设备类型的列表
        /// </summary>
        /// <param name="devicetype">判断字符串</param>
        /// <returns></returns>
        public static List<DeviceType> GetDeviceType(string devicetype)
        {
            List<DeviceType> DeviceTypeList = new List<DeviceType>();
            DeviceTypeList.Clear();
            if (devicetype == Language.StringByID(MyInternationalizationString.Lights))
            {
                DeviceTypeList.Add(DeviceType.OnOffOutput);//0x0101十进制257
                DeviceTypeList.Add(DeviceType.DimmableLight);
                DeviceTypeList.Add(DeviceType.ColorTemperatureLight);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Curtains))
            {
                DeviceTypeList.Add(DeviceType.WindowCoveringDevice);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.OnOffSwitch))
            {
                DeviceTypeList.Add(DeviceType.OnOffSwitch);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.sensor))
            {
                DeviceTypeList.Add(DeviceType.IASZone);
                DeviceTypeList.Add(DeviceType.TemperatureSensor);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.doorLock))
            {
                DeviceTypeList.Add(DeviceType.DoorLock);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Curtains))
            {
                DeviceTypeList.Add(DeviceType.WindowCoveringDevice);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.AC))
            {
                DeviceTypeList.Add(DeviceType.Thermostat);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Airswitch))
            {
                DeviceTypeList.Add(DeviceType.AirSwitch);
            }
            return DeviceTypeList;
        }
        /// <summary>
        /// 显示某个类型设备的图标
        /// </summary>
        /// <param name="devicetype">判断字符串</param>
        /// <returns></returns>
        public static string GetDeviceTypeIcon(string devicetype)
        {
            string patm = "";
            if (devicetype == Language.StringByID(MyInternationalizationString.OnOffSwitch))
            {
                patm = "ZigeeLogic/selectedpanel.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.sensor))
            {
                patm = "ZigeeLogic/selectedsenor.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.doorLock))
            {
                patm = "ZigeeLogic/selecteddoorlock.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Lights))
            {
                patm = "ZigeeLogic/selectedlight.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Curtains))
            {
                patm = "ZigeeLogic/selectedcurtain.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.AC))
            {
                patm = "ZigeeLogic/selectedac.png";
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Airswitch))
            {
                patm = "ZigeeLogic/selectedairswitch.png";
            }
            return patm;
        }
        /// <summary>
        /// 显示设备的图标
        /// </summary>
        /// <param name="device">设备对象</param>
        /// <param name="button">显示图标的控件</param>
        public static void GetDeviceIcon(CommonDevice device, Button button)
        {
            string patm = "";
            string selectedpatm = "";
            switch (device.Type)
            {
                case DeviceType.OnOffOutput:
                    {
                        patm = "ZigeeLogic/light.png";
                        selectedpatm = "ZigeeLogic/selectedlight.png";
                    }
                    break;
                case DeviceType.IASZone:
                    {
                        var iASZonedevice = device as IASZone;
                        if (iASZonedevice.DeviceID != 1026)
                        {
                            break;
                        }
                        patm = $"ZigeeLogic/sensor{iASZonedevice.IasDeviceType}.png";
                        selectedpatm = $"ZigeeLogic/selectedsensor{iASZonedevice.IasDeviceType}.png";
                    }
                    break;
                case DeviceType.TemperatureSensor:
                    {
                        var temperatureSensor = device as TemperatureSensor;
                        if (temperatureSensor.SensorDiv == 1)
                        {
                            patm = $"ZigeeLogic/temperature.png";
                            selectedpatm = $"ZigeeLogic/selectedtemperature.png";
                        }
                        else
                        {
                            patm = "ZigeeLogic/humidity.png";
                            selectedpatm = "ZigeeLogic/selectedhumidity.png";
                        }
                    }
                    break;
                case DeviceType.OnOffSwitch:
                    {
                        patm = "ZigeeLogic/panel.png";
                        selectedpatm = "ZigeeLogic/selectedpanel.png";
                    }
                    break;
                case DeviceType.DoorLock:
                    {
                        patm = "ZigeeLogic/doorlock.png";
                        selectedpatm = "ZigeeLogic/selecteddoorlock.png";
                    }
                    break;
                case DeviceType.DimmableLight:
                    {
                        patm = "ZigeeLogic/dimmableLight.png";
                        selectedpatm = "ZigeeLogic/selecteddimmableLight.png";
                    }
                    break;
                case DeviceType.WindowCoveringDevice:
                    {
                        patm = "ZigeeLogic/curtain.png";
                        selectedpatm = "ZigeeLogic/selectedcurtain.png";
                    }
                    break;
                case DeviceType.Thermostat:
                    {
                        patm = "ZigeeLogic/ac.png";
                        selectedpatm = "ZigeeLogic/selectedac.png";
                    }
                    break;
                case DeviceType.AirSwitch:
                    {
                        patm = "ZigeeLogic/airswitch.png";
                        selectedpatm = "ZigeeLogic/selectedairswitch.png";
                    }
                    break;
                case DeviceType.ColorTemperatureLight:
                    {
                        patm = "ZigeeLogic/nightLight.png";
                        selectedpatm = "ZigeeLogic/nightLightSelected.png";
                    }
                    break;
            }
            button.UnSelectedImagePath = patm;
            button.SelectedImagePath = selectedpatm;
        }
        /// <summary>
        /// 支持的设备
        /// </summary>
        /// <param name="type">判断字符串</param>
        /// <returns></returns>
        public static List<DeviceType> GetDevice(string type)
        {
            /// 设备类型列表
            List<DeviceType> deviceTypeList = new List<DeviceType>();
            deviceTypeList.Clear();
            switch (type)
            {
                case "condition_logic":
                    {//自动化支持的条件设备
                        deviceTypeList.Add(DeviceType.IASZone);
                        deviceTypeList.Add(DeviceType.OnOffSwitch);
                        deviceTypeList.Add(DeviceType.OnOffOutput);
                        deviceTypeList.Add(DeviceType.DoorLock);
                        deviceTypeList.Add(DeviceType.TemperatureSensor);
                    }
                    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.ColorTemperatureLight);
                        ///门锁特殊
                       // deviceTypeList.Add(DeviceType.DoorLock);
                    }
                    break;
                case "condition_mould":
                    {
                        //自动化模板支持的条件设备
                        deviceTypeList.Add(DeviceType.IASZone);
                    }
                    break;
                case "action_mould":
                    { //自动化模板支持的目标设备
                        deviceTypeList.Add(DeviceType.OnOffOutput);
                    }
                    break;
                case "action_lockaction":
                    {//门锁联动事件支持的目标设备
                        deviceTypeList.Add(DeviceType.OnOffOutput);
                        deviceTypeList.Add(DeviceType.DimmableLight);
                        deviceTypeList.Add(DeviceType.WindowCoveringDevice);
                        deviceTypeList.Add(DeviceType.Thermostat);
                        deviceTypeList.Add(DeviceType.AirSwitch);
                        deviceTypeList.Add(DeviceType.ColorTemperatureLight);
                        ///门锁特殊
                      // deviceTypeList.Add(DeviceType.DoorLock);
                    }
                    break;
            }
            return deviceTypeList;
        }
        /// <summary>
        /// 更新执行周期的方法
        /// </summary>
        /// <param name="button">显示周期文本</param>
        /// <param name="currentLogic">当前逻辑对象</param>
        public static void UpdateWeek(Button button, Common.Logic currentLogic)
        {
            switch (currentLogic.TimeAttribute.Repeat)
            {
                ///0:只执行一次,执行后IsEnable值置;1,今年内执行;2:每天执行;3:每月执行;4:每年执行;5:周重复。
                case 0:
                    {
                        button.Text = Language.StringByID(MyInternationalizationString.executeonce);
                    }; break;
                case 1: { }; break;
                case 2:
                    {
                        button.Text = Language.StringByID(MyInternationalizationString.everyday);
                    }; break;
                case 3:
                    {
                        string len = "", value = "";
                        var stringvalue = Convert.ToString(currentLogic.TimeAttribute.MonthDate, 2);
                        var str = stringvalue.Insert(0, new string('0', 32 - stringvalue.Length));
                        for (int j = 31; j >= 0; j--)
                        {
                            len += str.Substring(j, 1);
                        }
                        for (int j = 0; j < len.Length; j++)
                        {
                            var strvalue = len.Substring(j, 1);
                            if (strvalue == "1")
                            {
                                value += (j + 1).ToString() + ",";
                            }
                        }
                        button.Text = Language.StringByID(MyInternationalizationString.monthly) + value.TrimEnd(',') + Language.StringByID(MyInternationalizationString.day);
                    }; break;
                case 4:
                    {
                        Dictionary<int, int> dictionary = new Dictionary<int, int>();
                        ///找出执行的月份和天数
                        if (currentLogic.TimeAttribute.SelectMonDate.Count != 0)
                        {
                            for (int i = 0; i < currentLogic.TimeAttribute.SelectMonDate.Count; i++)
                            {
                                var dayvalue = currentLogic.TimeAttribute.SelectMonDate[i];
                                if (dayvalue != 0)
                                {
                                    dictionary.Add(i + 1, dayvalue);
                                }
                            }
                        }
                        if (dictionary.Count != 0 && dictionary.Count == 1)
                        {
                            string len = "", leng = "";
                            int minvalue = 0, Maximum = 0;
                            foreach (var value in dictionary)
                            {
                                ///取出月份
                                var month = value.Key;
                                ///取出日数
                                var day = value.Value;
                                var maxvalue = Convert.ToString(day, 2);
                                var str = maxvalue.Insert(0, new string('0', 32 - maxvalue.Length));
                                for (int j = 31; j >= 0; j--)
                                {
                                    len += str.Substring(j, 1);
                                }
                                for (int j = 0; j < len.Length; j++)
                                {
                                    var strvalue = len.Substring(j, 1);
                                    if (strvalue == "1")
                                    {
                                        minvalue = j + 1;
                                        break;
                                    }
                                }
                                for (int j = 0; j < len.Length; j++)
                                {
                                    var strvalue = len.Substring(j, 1);
                                    if (strvalue == "1")
                                    {
                                        Maximum = j + 1;
                                    }
                                }
                                if (month.ToString().Length < 2)
                                {
                                    leng = "0" + month.ToString();
                                }
                                else
                                {
                                    leng = month.ToString();
                                }
                                if (minvalue == Maximum)
                                {
                                    button.Text = Language.StringByID(MyInternationalizationString.everyyear) + leng + "/" + (minvalue.ToString().Length < 2 ? "0" + minvalue.ToString() : minvalue.ToString());
                                }
                                else
                                {
                                    button.Text = Language.StringByID(MyInternationalizationString.everyyear) + leng + "/" + (minvalue.ToString().Length < 2 ? "0" + minvalue.ToString() : minvalue.ToString()) + "-" + leng + "/" + (Maximum.ToString().Length < 2 ? "0" + Maximum.ToString() : Maximum.ToString());
                                }
                            }
                        }
                        else
                        {
                            int b = 0;
                            string stringtext = "";
                            foreach (var value in dictionary)
                            {
                                string len = "", leng = "";
                                int minvalue = 0, Maximum = 0;
                                ///取出月份
                                var month = value.Key;
                                ///取出日数
                                var day = value.Value;
                                var maxvalue = Convert.ToString(day, 2);
                                var str = maxvalue.Insert(0, new string('0', 32 - maxvalue.Length));
                                for (int j = 31; j >= 0; j--)
                                {
                                    len += str.Substring(j, 1);
                                }
                                if (month.ToString().Length < 2)
                                {
                                    leng = "0" + month.ToString();
                                }
                                else
                                {
                                    leng = month.ToString();
                                }
                                if (b == 0)
                                {
                                    for (int j = 0; j < len.Length; j++)
                                    {
                                        var strvalue = len.Substring(j, 1);
                                        if (strvalue == "1")
                                        {
                                            minvalue = j + 1;
                                            break;
                                        }
                                    }
                                    stringtext += leng + "/" + (minvalue.ToString().Length < 2 ? "0" + minvalue.ToString() : minvalue.ToString()) + "-";
                                }
                                if (b == dictionary.Count - 1)
                                {
                                    for (int j = 0; j < len.Length; j++)
                                    {
                                        var strvalue = len.Substring(j, 1);
                                        if (strvalue == "1")
                                        {
                                            Maximum = j + 1;
                                        }
                                    }
                                    stringtext += leng + "/" + (Maximum.ToString().Length < 2 ? "0" + Maximum.ToString() : Maximum.ToString());
                                }
                                b++;
                            }
                            button.Text = Language.StringByID(MyInternationalizationString.everyyear) + stringtext;
                        }
                    }; break;
                case 5:
                    {
                        string len = "", text = "";
                        List<int> listvalueInt = new List<int>();
                        listvalueInt.Clear();
                        var maxvalue = Convert.ToString(currentLogic.TimeAttribute.WeekDay, 2);
                        var str = maxvalue.Insert(0, new string('0', 8 - maxvalue.Length));
                        for (int j = 7; j >= 0; j--)
                        {
                            len += str.Substring(j, 1);
                        }
                        for (int j = 0; j < len.Length; j++)
                        {
                            var strvalue = len.Substring(j, 1);
                            if (strvalue == "1")
                            {
                                listvalueInt.Add(j + 1);
                                if ((j + 1) == 1)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.mon1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.mon) + ",";
                                }
                                else if ((j + 1) == 2)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.tue1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.tue) + ",";
                                }
                                else if ((j + 1) == 3)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.wed1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.wed) + ",";
                                }
                                else if ((j + 1) == 4)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.thu1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.thu) + ",";
                                }
                                else if ((j + 1) == 5)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.frl1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.frl) + ",";
                                }
                                else if ((j + 1) == 6)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.sat1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.sat) + ",";
                                }
                                else if ((j + 1) == 7)
                                {
                                    text += Language.StringByID(MyInternationalizationString.week1) + Language.StringByID(MyInternationalizationString.sun1) + ",";
                                    //text += Language.StringByID(MyInternationalizationString.sun) + ",";
                                }
                            }
                        }
                        //暂时隐藏掉,需要显示周末和工作日再放开;
                        //if (listvalueInt.Count == 5 && !listvalueInt.Contains(6) && !listvalueInt.Contains(7))
                        //{
                        //    btndisplaycycle.Text = Language.StringByID(MyInternationalizationString.workingday);
                        //}
                        //else if (listvalueInt.Count == 2 && listvalueInt.Contains(6) && listvalueInt.Contains(7))
                        //{
                        //    btndisplaycycle.Text = Language.StringByID(MyInternationalizationString.weekend);
                        //}
                        //else if (listvalueInt.Count == 7)
                        //{
                        //    btndisplaycycle.Text = Language.StringByID(MyInternationalizationString.everyday);
                        //}
                        //else
                        //{
                        //    btndisplaycycle.Text = Language.StringByID(MyInternationalizationString.week1) + text.Replace(Language.StringByID(MyInternationalizationString.week1), "").TrimEnd(',');
                        //}
                        button.Text = Language.StringByID(MyInternationalizationString.week1) + text.Replace(Language.StringByID(MyInternationalizationString.week1), "").TrimEnd(',');
                        //btndisplaycycle.Text = text.TrimEnd(',');
                    }; break;
            }
        }
        /// <summary>
        ///返回设备的方法
        /// </summary>
        /// <param name="DeviceAddr">设备Mac</param>
        /// <param name="Epoint">设备端口</param>
        /// <returns></returns>
        public static ZigBee.Device.CommonDevice GetCommonDevice(string DeviceAddr, string Epoint)
        {
            var device = Common.Logic.LogicDviceList.Find((obj) => { return ((obj.DeviceAddr == DeviceAddr) && (obj.DeviceEpoint.ToString() == Epoint)); });
            if (device == null)
            {
                device = new ZigBee.Device.CommonDevice();
            }
            return device;
        }
        /// <summary>
        /// 推送设置的方法
        /// </summary>
        /// <param name="middle"></param>
        public static void Push(VerticalScrolViewLayout middle)
        {
            LogicView.Addview pushview = new LogicView.Addview();
            pushview.switchBtn.Visible = true;
            pushview.titleBtn.TextID = MyInternationalizationString.pushswitch;
            middle.AddChidren(pushview.AddDeviceView());
            LogicView.Addview custompushview = new LogicView.Addview();
            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) =>
            {
                var CustomText = new CustomText();
                UserView.HomePage.Instance.AddChidren(CustomText);
                UserView.HomePage.Instance.PageIndex += 1;
                CustomText.Show();
            };
            custompushview.frameLayout.MouseUpEventHandler += customclick;
            custompushview.clickBtn.MouseUpEventHandler += customclick;
            // bool tag = false;//标记开关状态;
            pushview.clickBtn.MouseUpEventHandler += (sender1, e1) =>
            {
                pushview.switchBtn.IsSelected = !pushview.switchBtn.IsSelected;
                if (pushview.switchBtn.IsSelected)
                {
                    LogicView.IfString.Tag = true;
                    custompushview.frameLayout.Height = Application.GetRealHeight(160);
                    Common.Logic.CurrentLogic.LogicIsCustomPushText = 1;
                    pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor;
                }
                else
                {
                    LogicView.IfString.Tag = false;
                    custompushview.frameLayout.Height = Application.GetRealHeight(0);
                    Common.Logic.CurrentLogic.LogicIsCustomPushText = 0;
                    pushview.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
                }
                if (!Config.Instance.Home.IsVirtually)
                {
                    Send.Zj(LogicView.IfString.Tag, Common.Logic.CurrentLogic);
                }
            };
            if (Common.Logic.CurrentLogic.LogicIsCustomPushText == 0)
            {
                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>
        /// 保存自动化的方法
        /// </summary>
        /// <param name="if_logic">判断跳转界面的字符串</param>
        /// <param name="name">逻辑名称</param>
        /// <param name="tag"></param>
        /// <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,
                  Language.StringByID(MyInternationalizationString.PleaseEnterLogicName),
                  Language.StringByID(MyInternationalizationString.confrim));
                alert.Show();
                return;
            }
            ///先隐藏判断名字相同的功能;
            //var logicname = Common.Logic.LogicList.Find((logic) => Common.Logic.CurrentLogic.LogicId != logic.LogicId && logic.LogicName == name);
            //if (logicname != null)
            //{
            //    new Alert(Language.StringByID(MyInternationalizationString.Tip), Language.StringByID(MyInternationalizationString.Rename), Language.StringByID(MyInternationalizationString.Close)).Show();
            //    return;
            //}
            CurrentLogic.LogicName = name;
            bool succeed = false;
            //判断是新添加逻辑(默认0)还是修改逻辑
            CommonPage.Loading.Start();
            if (Config.Instance.Home.IsVirtually)
            {
                if (Common.Logic.LogicList.Count == 0)
                {
                    CurrentLogic.LogicId = 1;
                    Common.Logic.LogicList.Add(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
            {
                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();
            if (!succeed)//succeed标记是添加成功还是失败
            {
                //网关回复失败,不关闭界面,让它停留当前界面;
                //(原因:考虑到失败重新编辑原来数据给用户带来了麻烦)
                ///提示:添加自动化失败;
                //TipView("添加自动化失败");
                //return;
            }
            UserView.HomePage.Instance.RemoveViewByTag("Logic");//移除所有标记Logic界面
            if (LogicView.IfString._Logic == if_logic)
            {
                //只刷新分类-自动化上下滑动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;
    }
}