黄学彪
2020-12-17 9f326f4000847e6167d8166fa2f6a66f53cb3734
ZigbeeApp/Shared/Phone/Device/Logic/Method.cs
@@ -21,7 +21,7 @@
        /// <param name="device">Device.</param>
        public static void RoomNmae(Button button, CommonDevice device)
        {
            button.Text = UserCenter.HdlRoomLogic.Current.GetRoomNameByDevice(device);
            button.Text = HdlRoomLogic.Current.GetRoomNameByDevice(device);
        }
        /// <summary>
        /// 返回楼层所有的房间的列表
@@ -32,7 +32,7 @@
        public static List<Common.Room> GetRoomList(string type, string floorId = null)
        {
            var list = new List<Common.Room>();
            var listAllRoom = UserCenter.HdlRoomLogic.Current.GetAllListRooms();
            var listAllRoom = HdlRoomLogic.Current.GetAllListRooms();
            for (int i = 0; i < listAllRoom.Count; i++)
            {
                if (type == "action_logicscene" || type == "action_lockscene")
@@ -46,7 +46,7 @@
                {
                    ///区分出输入条件和输出目标设备
                    var listdevicetype = GetDevice(type);
                    var listdevice = GetDeviceUIList(listAllRoom[i], listdevicetype);
                    var listdevice = GetDeviceUIList(listAllRoom[i], listdevicetype, type);
                    if (listdevice.Count == 0)
                    {
                        ///过滤掉没有设备的房间
@@ -68,13 +68,14 @@
        /// </summary>
        /// <param name="room">当前房间</param>
        /// <param name="deviceTypelist">设备类型</param>
        ///  /// <param name="type">逻辑类型</param>
        /// <returns></returns>
        public static List<CommonDevice> GetDeviceUIList(Common.Room room, List<DeviceType> deviceTypelist)
        public static List<CommonDevice> GetDeviceUIList(Common.Room room, List<DeviceType> deviceTypelist,string type)
        {
            var deviceUIlist = new List<CommonDevice>();
            foreach (var deviceKey in room.ListDevice)
            {
                var device = LocalDevice.Current.GetDevice(deviceKey);
                var device = HdlDeviceCommonLogic.Current.GetDevice(deviceKey);
                if (device == null)
                {
                    continue;
@@ -83,15 +84,31 @@
                {
                    //过滤掉不支持的设备
                    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;
                }
                if (device.Type == DeviceType.DoorLock)
                {
                    var myInfo = HdlDeviceCommonLogic.Current.GetMyDeviceEnumInfo(new List<CommonDevice>() { device });
                    if (myInfo.ConcreteType == DeviceConcreteType.IntelligentLocks_Sone)
                    {
                        //暂时不支持S-one门锁;
                        //过滤掉不支持S-one门锁设备;
                        continue;
                    }
                }
                if (type == "condition_mould")
                {
                    if (device.Type == DeviceType.IASZone)
                    {
                        if (device.IasDeviceType != 13)
                        {//自动化模板只支持红外传感器
                            continue;
                        }
                        if (device.ModelIdentifier == "MSPIRB-ZB.10")
                        {
                            //自动化模板不支持光照度
                            continue;
                        }
                    }
                }
                deviceUIlist.Add(device);
@@ -108,7 +125,7 @@
            List<string> devicetypelist = new List<string>();
            devicetypelist.Clear();
            var lightjosn = devicelist.Find((device) => device.Type == DeviceType.DimmableLight || device.Type == DeviceType.OnOffOutput);
            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));
@@ -166,6 +183,7 @@
            {
                DeviceTypeList.Add(DeviceType.OnOffOutput);//0x0101十进制257
                DeviceTypeList.Add(DeviceType.DimmableLight);
                DeviceTypeList.Add(DeviceType.ColorTemperatureLight);
            }
            else if (devicetype == Language.StringByID(MyInternationalizationString.Curtains))
            {
@@ -260,8 +278,17 @@
                        {
                            break;
                        }
                        patm = $"ZigeeLogic/sensor{iASZonedevice.IasDeviceType}.png";
                        selectedpatm = $"ZigeeLogic/selectedsensor{iASZonedevice.IasDeviceType}.png";
                        if (device.ModelIdentifier == "MSPIRB-ZB.10")
                        {
                            patm = $"ZigeeLogic/sensor541.png";
                            selectedpatm = $"ZigeeLogic/selectedsensor541.png";
                        }
                        else
                        {
                            patm = $"ZigeeLogic/sensor{iASZonedevice.IasDeviceType}.png";
                            selectedpatm = $"ZigeeLogic/selectedsensor{iASZonedevice.IasDeviceType}.png";
                        }
                    }
                    break;
                case DeviceType.TemperatureSensor:
@@ -316,6 +343,12 @@
                        selectedpatm = "ZigeeLogic/selectedairswitch.png";
                    }
                    break;
                case DeviceType.ColorTemperatureLight:
                    {
                        patm = "ZigeeLogic/nightLight.png";
                        selectedpatm = "ZigeeLogic/nightLightSelected.png";
                    }
                    break;
            }
            button.UnSelectedImagePath = patm;
            button.SelectedImagePath = selectedpatm;
@@ -350,6 +383,7 @@
                        deviceTypeList.Add(DeviceType.WindowCoveringDevice);
                        deviceTypeList.Add(DeviceType.Thermostat);
                        deviceTypeList.Add(DeviceType.AirSwitch);
                        deviceTypeList.Add(DeviceType.ColorTemperatureLight);
                        ///门锁特殊
                       // deviceTypeList.Add(DeviceType.DoorLock);
                    }
@@ -372,6 +406,7 @@
                        deviceTypeList.Add(DeviceType.WindowCoveringDevice);
                        deviceTypeList.Add(DeviceType.Thermostat);
                        deviceTypeList.Add(DeviceType.AirSwitch);
                        deviceTypeList.Add(DeviceType.ColorTemperatureLight);
                        ///门锁特殊
                      // deviceTypeList.Add(DeviceType.DoorLock);
                    }
@@ -559,7 +594,9 @@
                    }; break;
                case 5:
                    {
                        string len = "", text = "";
                        string len = "";
                         string   text = "";
                        string weekStr = Language.StringByID(MyInternationalizationString.week1);
                        List<int> listvalueInt = new List<int>();
                        listvalueInt.Clear();
                        var maxvalue = Convert.ToString(currentLogic.TimeAttribute.WeekDay, 2);
@@ -575,44 +612,36 @@
                            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) + ",";
                                switch ((j + 1)) {
                                    case 1: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.mon1) + ",";
                                        }
                                        break;
                                    case 2: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.tue1) + ",";
                                        }
                                        break;
                                    case 3: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.wed1) + ",";
                                        }
                                        break;
                                    case 4: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.thu1) + ",";
                                        }
                                        break;
                                    case 5: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.frl1) + ",";
                                        }
                                        break;
                                    case 6: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.sat1) + ",";
                                        }
                                        break;
                                    case 7: {
                                            text += weekStr + Language.StringByID(MyInternationalizationString.sun1) + ",";
                                        }
                                        break;
                                }
                                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) + ",";
                                }
                            }
                        }
@@ -633,8 +662,7 @@
                        //{
                        //    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(',');
                        button.Text = weekStr + text.Replace(weekStr, "").TrimEnd(',');
                    }; break;
            }
@@ -702,7 +730,11 @@
                    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)
@@ -732,7 +764,7 @@
            if (CurrentLogic.Conditions.Count == 0 || CurrentLogic.Actions.Count == 0)
            {
                var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Normal,
                var alert = new ShowMsgControl(ShowMsgType.Normal,
                  Language.StringByID(MyInternationalizationString.addnull),
                  Language.StringByID(MyInternationalizationString.confrim));
                alert.Show();
@@ -741,7 +773,7 @@
            if (string.IsNullOrEmpty(name))
            {
                var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Normal,
                var alert = new ShowMsgControl(ShowMsgType.Normal,
                  Language.StringByID(MyInternationalizationString.PleaseEnterLogicName),
                  Language.StringByID(MyInternationalizationString.confrim));
                alert.Show();
@@ -759,43 +791,94 @@
            bool succeed = false;
            //判断是新添加逻辑(默认0)还是修改逻辑
            CommonPage.Loading.Start();
            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);
                    }
            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
            {
                //发送修改逻辑命令;
                //修改命令不需要等待回复;
                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();
@@ -811,6 +894,60 @@
            UserView.HomePage.Instance.RemoveViewByTag("Logic");//移除所有标记Logic界面
            if (LogicView.IfString._Logic == if_logic)
            {
                //查询-当前逻辑-是否添加地理位置作为条件
                var exist = Common.Logic.CurrentLogic.Conditions.Find((obj) => obj["Type"] == "7");
                if (exist==null)
                {
                    bool if_type = false;
                    //查询-逻辑列表-是否添加过地理位置作为条件
                    for (int a = 0; a < Common.Logic.LogicList.Count; a++)
                    {
                        var logic = Common.Logic.LogicList[a];
                        var exist_logic = logic.Conditions.Find((obj) => obj["Type"] == "7");
                        if (exist_logic != null)
                        {
                            //是否存在地理位置条件
                            if_type = true;
                            //退出for循环
                            break;
                        }
                    }
                    if (if_type)
                    {
                        //查询之前状态是否已经开启GPS服务(以本地存储状态为主 0:没开启; 1:开启)
                        if (Send.If_Exist == "0")
                        {
                            //开启GPS服务
                            Application.StartGPSLocationService();
                            //保存GPS服务开启状态
                            Send.SaveLocalFile(Config.Instance.HomeId + "_GPS_File", "1");
                        }
                    }
                    else
                    {
                        //如果找不到地理位置作为条件的话,关闭GPS服务(减少耗电)
                        if (Send.If_Exist == "1")
                        {
                            //关闭GPS服务
                            Application.StopGPSLocationService();
                            //保存GPS服务关闭状态
                            Send.SaveLocalFile(Config.Instance.HomeId + "_GPS_File", "0");
                        }
                    }
                }
                else
                {
                    //查询之前状态是否已经开启GPS服务(以本地存储状态为主 0:没开启; 1:开启)
                    if (Send.If_Exist == "0")
                    {
                        //开启GPS服务
                        Application.StartGPSLocationService();
                        //保存GPS服务开启状态
                        Send.SaveLocalFile(Config.Instance.HomeId + "_GPS_File", "1");
                    }
                }
                //只刷新分类-自动化上下滑动view;
                Phone.Category.CategoryMainForm.instance?.RefreshBodyView();
                // Category.Category.instance?.RefreshBodyView();
@@ -827,11 +964,13 @@
            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();
                //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();
            }
        }
@@ -852,5 +991,8 @@
        /// 界面高度
        /// </summary>
        public static int H = 1922;
    }
}