陈嘉乐
2020-05-11 446b27177064d14561d43e5ce33cde5d7df075c7
ZigbeeApp/Shared/Phone/Device/Logic/SoneLogicList.cs
@@ -3,7 +3,6 @@
using Shared.Common;
using Shared.R;
using Shared;
using Shared.Phone.UserCenter.DoorLock;
namespace Shared.Phone.Device.Logic
{
@@ -14,6 +13,7 @@
        {
            Tag = "SoneLogic";
            soneLogicList = this;
        }
        /// 给徐梅刷新界面用的
        public  Action<bool> action;
@@ -29,9 +29,17 @@
        FrameLayout listLogicFl = new FrameLayout();
        ///常开自动化列表上下滑动的控件
        VerticalRefreshLayout verticalRefresh = new VerticalRefreshLayout();
        /// <summary>
        /// 记录逻辑id
        /// </summary>
        public int logicId = 0;
        /// <summary>
        /// 记录选中时间
        /// </summary>
        public int timeValue = 0;
        public async void Show()
        {
            #region  界面的布局代码
            UserView.HomePage.Instance.ScrollEnabled = false;//锁住左滑
            TopView view = new TopView();
@@ -57,6 +65,23 @@
            };
            this.AddChidren(middle);
            #endregion
            //是常开模式再去读取
            if (Send.CurrentDoorLock.IsDoorLockNormallyMode)
            {
                //进来更新一次
                //查找是否存在时效性自动化;有的话就返回自动化对象;
                var logic = await SkipView.GetLogicIfon();
                if (logic != null)
                {
                    try
                    {
                        //进来更新一次值
                        logicId = logic.LogicId;
                        timeValue = int.Parse(logic.Conditions[0]["DoorLockOpenDelayTime"]);
                    }
                    catch { }
                }
            }
            #region  常开模式图标 时效性常开设置
            ///第二块第一级父控件
@@ -93,7 +118,6 @@
            modeFl.AddChidren(button2);
            ModeView();
            #endregion
            #region 常开自动化
            ///第三块第一级父控件
            listLogicFl = new FrameLayout
@@ -141,7 +165,7 @@
            var addIconclickBtn = new Button
            {
                Width = Application.GetRealWidth(90+69+63),
                Width = Application.GetRealWidth(90 + 69 + 63),
                Height = Application.GetRealHeight(69),
                X = Application.GetRealWidth(800),
                Y = Application.GetRealHeight(60),
@@ -202,6 +226,21 @@
            };
            Read(true);
            #endregion
            DoorLockCommonInfo.LogicAction = (_bool) =>
            {
                try
                {
                    Application.RunOnMainThread(() =>
                    {
                        Send.CurrentDoorLock.IsDoorLockNormallyMode = _bool;
                        ModeView();
                    });
                }
                catch { }
            };
        }
        /// <summary>
        /// 常开模式开关切换图标界面
@@ -211,9 +250,6 @@
            
            if (Send.CurrentDoorLock.IsDoorLockNormallyMode)
            {
                /// 查找是否存在时效性自动化;有的话就返回自动化对象;
                var logic = await SkipView.GetLogicIfon();
                fLayout.Height = Application.GetRealHeight(780);//改变高度 
                modeIconBtn.UnSelectedImagePath = "ZigeeLogic/openMode.png";//改变图标状态
                modeFl.Y = modeIconBtn.Bottom + Application.GetRealHeight(64);
@@ -243,11 +279,10 @@
                        var result = await UserCenter.DoorLock.DoorLockCommonInfo.DelNormallyOpenMode(Send.CurrentDoorLock);
                        if (result)
                        {
                            if (logic != null)
                            if (logicId != 0)
                            {
                                ///有可能只有常开模式,没有时效性自动化
                                ///没有判断的话,逻辑会为空,抛出异常;
                                Send.DelLogic(logic.LogicId);
                                Send.DelLogic(logicId);
                            }
                            Send.CurrentDoorLock.IsDoorLockNormallyMode = false;
                            ModeView();
@@ -267,7 +302,7 @@
                        });
                    }
                };
                if (logic != null)
                if (logicId != 0)
                {
                    ///显示失效设置时间文本控件
                    button2.Y = Application.GetRealHeight(127 + 69);
@@ -282,9 +317,8 @@
                    var m = DateTime.Now.Month.ToString();//那一月
                    var d = DateTime.Now.ToString("dd");//那一天
                    var h = int.Parse(DateTime.Now.ToString("HH"));//当前系统时间
                    var timeInt = int.Parse(logic.Conditions[0]["DoorLockOpenDelayTime"]);
                    int dayInt = (h + timeInt) / 24;//算出几天后执行
                    int hour = (h + timeInt) % 24;//算出几天后那个时间执行
                    int dayInt = (h + timeValue) / 24;//算出几天后执行
                    int hour = (h + timeValue) % 24;//算出几天后那个时间执行
                    int days = int.Parse(d) + dayInt;
                    string text1 = Language.StringByID(MyInternationalizationString.timeSensitive);
                    string text2 = Language.StringByID(MyInternationalizationString.yearSone);
@@ -293,7 +327,8 @@
                    string text5 = Language.StringByID(MyInternationalizationString.executeSone);
                    button2.Text = text1 + y + text2 + m + text3 + days.ToString() + text4 + hour.ToString() + text5;
                }
                else {
                else
                {
                    button2.Y = Application.GetRealHeight(0);
                    button2.X = Application.GetRealWidth(0);
                    button2.Width = Application.GetRealWidth(0);
@@ -348,7 +383,6 @@
                            try
                            {
                                ///xm
                                var result = await UserCenter.DoorLock.DoorLockCommonInfo.SetNormallyOpenModeFuncAsync(Send.CurrentDoorLock);
                                if (!result)
                                {
@@ -360,7 +394,7 @@
                                    ///因为有常开模式下才可以创建失效逻辑;
                                    SkipView.GetLogicAll();//删除之前所有失效逻辑
                                    var addResult = await SkipView.LockAddModifyLogic(int.Parse(str), Send.CurrentDoorLock);//添加一条失效逻辑
                                    if (!addResult)
                                    if (addResult == 0)
                                    {
                                        ///可欣说如果常开模式开,创建自动化失败,那么将要发一条常开模式关闭命令;
                                        UserCenter.DoorLock.DoorLockCommonInfo.DelNormallyOpenMode(Send.CurrentDoorLock);
@@ -368,8 +402,13 @@
                                        LogicView.TipView.ShowFlashTip(Language.StringByID(MyInternationalizationString.addFailed));
                                        return;
                                    }
                                    Send.CurrentDoorLock.IsDoorLockNormallyMode = true;
                                    ModeView();
                                    else
                                    {
                                        logicId = addResult;
                                        timeValue = int.Parse(str);
                                        Send.CurrentDoorLock.IsDoorLockNormallyMode = true;
                                        ModeView();
                                    }
                                }
@@ -542,10 +581,7 @@
                    TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor,
                };
                logicRow.AddRightView(edit);
                if (logic.LogicType == 2)
                {
                    edit.TextID = MyInternationalizationString.look;
                }
                ///删除
                var del = new Button
                {
@@ -611,35 +647,6 @@
                };
            }
        }
        //public static Action<bool> action1=DoorLockCommonInfo.LogicAction;
        /// <summary>
        /// 定时更新常开模式(防止通过门锁关闭没及时刷新状态)
        /// </summary>
        //System.Threading.Thread updateThread;
        //public void UpdateModeIcon()
        //{
        //    updateThread = new System.Threading.Thread(() =>
        //    {
        //        while (this.Parent != null)
        //        {
        //            System.Threading.Thread.Sleep(1000);
        //            Application.RunOnMainThread(() =>
        //            {
        //                try
        //                {
        //                    ModeView();
        //                }
        //                catch { }
                //            });
        //        }
        //    });
        //    updateThread.Start();
        //}
    }
}