WJC
2020-04-15 323876bfe85fc2684871d5d95c213c6e2713f3f4
ZigbeeApp/Shared/Phone/Device/Logic/SkipView.cs
@@ -13,12 +13,13 @@
        /// <summary>
        /// 其它界面跳进来的入口
        /// </summary>
        public static void SkipAddLogic(int intvalue,DoorLock doorLock=null,UserCenter.MemberInfoRes accountObj = null)
        public static void SkipAddLogic(int intvalue, DoorLock doorLock = null, UserCenter.MemberInfoRes accountObj = null)
        {
            /// 0.正常自动化;1.门锁自动化;2.门锁常开.关;
            switch (intvalue)
            {
                case 0: {
                case 0:
                    {
                        //new一个新逻辑对象;
                        //新增正常自动化入口
                        Common.Logic.CurrentLogic = new Common.Logic();
@@ -29,15 +30,17 @@
                        UserView.HomePage.Instance.AddChidren(addLogicPage);
                        UserView.HomePage.Instance.PageIndex += 1;
                        addLogicPage.Show();
                    } break;
                case 1: {
                    }
                    break;
                case 1:
                    {
                        //进入门锁联动事件入口
                        Send.UserMemberInfoRes = accountObj;
                        Send.CurrentDoorLock = doorLock;
                        if (accountObj == null)
                        {
                            ///防止抛异常
                            Send.UserMemberInfoRes = new UserCenter.MemberInfoRes();
                            Send.UserMemberInfoRes = new UserCenter.MemberInfoRes();
                        }
                        if (doorLock == null)
                        {
@@ -54,8 +57,10 @@
                        UserView.HomePage.Instance.AddChidren(doorLockLogicList);
                        UserView.HomePage.Instance.PageIndex += 1;
                        doorLockLogicList.Show();
                    } break;
                case 2: {
                    }
                    break;
                case 2:
                    {
                        Common.Logic.LogicDviceList.Clear();
                        if (Common.Logic.LogicDviceList.Count == 0)
                        {
@@ -79,7 +84,7 @@
                        actionsInfo.Add("LinkType", 8);
                        actionsInfo.Add("DeviceAddr", doorLock.DeviceAddr);
                        actionsInfo.Add("Epoint", doorLock.DeviceEpoint);
                        actionsInfo.Add("PassData", "055704010112");//默认门锁常开
                        actionsInfo.Add("PassData", "055704010113");//默认门锁常关
                        //new一个新逻辑对象;
                        //新增门锁常开模式自动化入口;
@@ -93,7 +98,8 @@
                        UserView.HomePage.Instance.AddChidren(oneLogic);
                        UserView.HomePage.Instance.PageIndex += 1;
                        oneLogic.Show(false);
                    } break;
                    }
                    break;
            }
        }
@@ -175,7 +181,7 @@
                Y = scenehorizontalScrol.Bottom,
            };
            functionSceneAutoBodyView.AddChidren(logicScrolView);
            logicScrolView.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft);
            bool no = false;
            //显示默认模板的界面事件
@@ -282,8 +288,8 @@
                logicScrolView.EndHeaderRefreshing();
            };
           //自动化
           Read(logicScrolView, no);
            //自动化
            Read(logicScrolView, no);
        }
        /// <summary>
@@ -339,6 +345,9 @@
        /// 加载自动化列表界面
        /// </summary>
        /// <param name="refresview">Refresview.</param>
        static  RowLayout selectedRow = new RowLayout() { Tag="0"};//记录左滑状态
        private static async void Automationview(VerticalRefreshLayout refresview, bool no)
        {
            refresview.RemoveAll();
@@ -348,7 +357,7 @@
                refresview.BackgroundColor = 0x00000000;
                var noFrameLayout = new FrameLayout
                {
                    Height = Application.GetRealHeight(434 + 200 + 32 + 294-55),
                    Height = Application.GetRealHeight(434 + 200 + 32 + 294 - 55),
                    //BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
                };
                refresview.AddChidren(noFrameLayout);
@@ -356,9 +365,9 @@
                var noIconBtn = new Button
                {
                    Y = Application.GetRealHeight(294-55),
                    Width = Application.GetMinRealAverage(756),
                    Height = Application.GetMinRealAverage(434),
                    Y = Application.GetRealHeight(294 - 55),
                    Width = Application.GetMinRealAverage(757),
                    Height = Application.GetMinRealAverage(435),
                    UnSelectedImagePath = "Item/NoFunction.png",
                    X = Application.GetRealWidth(104),
                };
@@ -411,17 +420,27 @@
                    LineColor = ZigbeeColor.Current.LogicBackgroundColor,
                    BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
                    SubViewWidth = Application.GetRealWidth(184),//改变编辑控件宽度多少;
                    Tag = i.ToString(),
                };
                fLayout.AddChidren(logicRowlayout);
                //左滑菜单事件
                logicRowlayout.OpenMenuAction += () =>
                {
                    if (selectedRow.Tag.ToString() != logicRowlayout.Tag.ToString())
                    {   //保留左滑只有一个;
                        selectedRow.HideMenu();//
                    }
                    selectedRow = logicRowlayout;
                };
                if (i == 1)
                {
                    //实现android显示逻辑列表的圆角;
                    fLayout.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft);
                    logicRowlayout.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft);
                    i = 2;
                }
                i++;
                var logicnameBtn = new Button
                {
                    Height = Application.GetRealHeight(58),
@@ -537,8 +556,8 @@
                    BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor,
                };
                fLayout.AddChidren(line);
            }
        }
@@ -577,8 +596,8 @@
                    indexlist.Add(linkType);
                }
            }
             //排列图标顺序;
            if (indexlist.Contains("0")|| indexlist.Contains("8"))
            //排列图标顺序;
            if (indexlist.Contains("0") || indexlist.Contains("8"))
            {
                iconIndexlist.Add("0");
            }
@@ -706,7 +725,7 @@
        /// <param name="timeVlaue">时间值</param>
        /// <param name="common">设备</param>
        /// <returns></returns>
        public  static void LockAddModifyLogic(int timeVlaue, CommonDevice common)
        public static async System.Threading.Tasks.Task<bool> LockAddModifyLogic(int timeVlaue, CommonDevice common)
        {
            //读取系统当前时间:时-分
            var h = DateTime.Now.ToString("HH");
@@ -735,78 +754,51 @@
            currentLogic.Conditions.Add(timeConditionsInfo);
            currentLogic.Actions.Add(actionsInfo);
            Exist(3);//查找是否存在设置过失效时间(有的话删除,再添加)
            Send.AddModifyLogic(currentLogic);
            var logicIfon = await Send.AddModifyLogic(currentLogic);
            if (logicIfon != null && logicIfon.LogicId != 0)
            {
                return true;
            }
            return false;
        }
        ///<summary>
        /// s-one门锁是否存在自动化的方法(true为存在)
        /// </summary>
        public static async System.Threading.Tasks.Task<bool> Exist(int valueInt=2)
      ///<summary>
      /// s-one门锁是否存在自动化的方法;
      /// 注意(参数2;3):valueInt=3是删除设置失效时间自动化;valueInt=2判断是否存在自动化;
      /// 返回值:0不存在;1存在;2删除成功;3删除失败;
      /// </summary>
      public static async System.Threading.Tasks.Task<int> Exist(int valueInt = 2)
        {
            bool exist = false;
            int exist = 0;
            var Idlist = await Send.GetLogicId(valueInt);
            if (Idlist.Count != 0)
            {
                if (valueInt==3) {
                if (valueInt == 3)
                {
                    for (int i = 0; i < Idlist.Count; i++)
                    {
                        //valueInt=3一条特殊的自动化(用来设置失效时间)
                        Send.DelLogic(Idlist[i]);
                    }
                }
                exist = true;
                        var d=await Send.DelLogic(Idlist[i]);
                  if (d != 0)
                  {
                     //删除成功
                     exist = 2;
                  }
                  else
                  {
                     //删除失败
                     exist = 3;
                  }
                  return exist;
               }
            }
                exist = 1;
            }
            return exist;
        }
        ///<summary>
        /// s-one门锁确认取消(使满足条件所有逻辑失能一次)发送的方法
        /// </summary>
        public static async void LockCloseLogic(CommonDevice common)
        {
            //读取系统当前时间:时-分
            int h =int.Parse(DateTime.Now.ToString("HH"));
            int m= int.Parse(DateTime.Now.ToString("mm"));
            //转化为多少分钟;
            int s = h * 60 + m;
            var logicList = new List<Common.Logic>();
            logicList.Clear();
            var Idlist = await Send.GetLogicId(2);
            if (Idlist.Count != 0)
            {   //先去读取网关看是否存在数据;
                var list = await Send.ReadList(Idlist.Count, 2);
                for (int j = 0; j < list.Count; j++)
                {
                    var logic = list[j];
                    foreach (var conditions in logic.Conditions)
                    {
                        var linkType = conditions["Type"];
                        if (linkType == "5")
                        {
                            int startMin = int.Parse(conditions["StartMin"]);
                            int startHour = int.Parse(conditions["StartHour"]);
                            int stopMin = int.Parse(conditions["StopMin"]);
                            int stopHour = int.Parse(conditions["StopHour"]);
                            int s1 = startMin + startHour * 60;//开始时间值
                            int s2 = stopMin + stopHour * 60;//结束时间值
                            if (s >= s1&&s<=s2)
                            {
                                //查找系统时间值是否属于这个范围;
                                logicList.Add(logic);
                            }
                        }
                    }
                }
            }
            foreach (var logic in logicList)
            {
                logic.IsEnable = 3;//改变逻辑使能状态;
                //用foreach发送命令;
                Send.AddModifyLogic(logic);
            }
        }
    }
}