using System; using System.Collections.Generic; using Shared.Common; using Shared.R; using Shared; namespace Shared.Phone.Device.Logic { public class SoneLogicList : FrameLayout { public static SoneLogicList soneLogicList; public SoneLogicList() { Tag = "SoneLogic"; soneLogicList = this; } /// 给徐梅刷新界面用的 public Action action; // 刷新上报界面的Action public Action updateCurrentDoorlockActionTemp; ///第二块第一级父控件 FrameLayout fLayout = new FrameLayout(); ///第三块第一级父控件 FrameLayout listLogicFl = new FrameLayout(); ///常开自动化列表上下滑动的控件 VerticalRefreshLayout verticalRefresh = new VerticalRefreshLayout(); /// /// 记录逻辑id /// public int logicId = 0; /// /// 记录选中时间 /// public int timeValue = 0; /// /// 记录时间戳 /// public int timeLong = 0; public async void Show() { #region 界面的布局代码 UserView.HomePage.Instance.ScrollEnabled = false;//锁住左滑 TopView view = new TopView(); this.AddChidren(view.TopRowView()); view.toptitleNameBtn.TextID = MyInternationalizationString.openmode; view.clickBtn.MouseDownEventHandler += (sender, e) => { UserView.HomePage.Instance.ScrollEnabled = true; //把静态变量的这个东西置空 soneLogicList = null; this.RemoveFromParent(); if (action != null) { action(Send.CurrentDoorLock.IsDoorLockNormallyMode); } }; var middle = new FrameLayout { Y = view.topRowLayout.Bottom, Height = Application.GetRealHeight(Method.H - 184), BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor, }; this.AddChidren(middle); #endregion //是常开模式再去读取 if (Send.CurrentDoorLock.IsDoorLockNormallyMode) { //进来更新一次 //查找是否存在时效性自动化;有的话就返回自动化对象; var logic = await SkipView.GetLogicIfon(Send.CurrentDoorLock); if (logic != null) { try { //进来更新一次值 logicId = logic.LogicId; timeValue = int.Parse(logic.Conditions[0]["DoorLockOpenDelayTime"]) / 3600; timeLong = int.Parse(logic.Conditions[0]["TriggerTime"]); } catch { } } } #region 常开模式图标 时效性常开设置 ///第二块第一级父控件 fLayout = new FrameLayout { Width = Application.GetRealWidth(1080), Height = Application.GetRealHeight(829 - 184), BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor, }; middle.AddChidren(fLayout); #endregion #region 常开自动化 ///第三块第一级父控件 listLogicFl = new FrameLayout { Y = fLayout.Bottom, X = Application.GetRealWidth(58), Height = middle.Height - fLayout.Height, Width = Application.GetRealWidth(1022), BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor, }; middle.AddChidren(listLogicFl); listLogicFl.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft); ModeView(); ///添加常开自动化的父控件 var addLogicfL = new FrameLayout { Height = Application.GetRealHeight(187), Width = Application.GetRealWidth(1080 - 58), }; listLogicFl.AddChidren(addLogicfL); ///常开自动化显示文本的控件 var addTextBtn = new Button { Y = Application.GetRealHeight(46), X = Application.GetRealWidth(58), Width = Application.GetRealWidth(600), Height = Application.GetRealHeight(95), TextSize = 24, TextColor = ZigbeeColor.Current.LogicTextBlackColor, TextAlignment = TextAlignment.CenterLeft, //Text = "常开自动化", TextID = MyInternationalizationString.openAutomationSone, }; addLogicfL.AddChidren(addTextBtn); ///添加自动化图标的控件 var addIconBtn = new Button { Width = Application.GetMinRealAverage(69), Height = Application.GetMinRealAverage(69), X = Application.GetRealWidth(890), Y = Application.GetRealHeight(60), UnSelectedImagePath = "ZigeeLogic/add.png", }; addLogicfL.AddChidren(addIconBtn); ///加大点击热键 var addIconclickBtn = new Button { Width = Application.GetRealWidth(90 + 69 + 63), Height = Application.GetRealHeight(69), X = Application.GetRealWidth(800), Y = Application.GetRealHeight(60), }; addLogicfL.AddChidren(addIconclickBtn); addIconclickBtn.MouseUpEventHandler += (sender, e) => { //读取系统当前时间:时-分 //读取系统当前时间:时-分 var h = DateTime.Now.ToString("HH"); var m = DateTime.Now.ToString("mm"); Dictionary timeConditionsInfo = new Dictionary(); timeConditionsInfo.Add("Type", "0"); timeConditionsInfo.Add("IsValid", "1"); timeConditionsInfo.Add("DateType", "0"); timeConditionsInfo.Add("RemindTime", "0"); timeConditionsInfo.Add("EnDelay", "0"); timeConditionsInfo.Add("DelayTime", "0"); timeConditionsInfo.Add("DoorLockOpenDelayTime", "0"); timeConditionsInfo.Add("StartHour", h); timeConditionsInfo.Add("StartMin", m); Dictionary actionsInfo = new Dictionary(); actionsInfo.Add("LinkType", 8); actionsInfo.Add("DeviceAddr", Send.CurrentDoorLock.DeviceAddr); actionsInfo.Add("Epoint", "200"); actionsInfo.Add("PassData", "055704010113");//默认门锁常关 Dictionary accounts = new Dictionary(); accounts.Add("Type", "8"); accounts.Add("Option4", Send.CurrentDoorLock.DeviceAddr.ToString());//用于判断识别是哪个门锁; accounts.Add("Option2", Send.CurrentDoorLock.DeviceEpoint.ToString()); //new一个新逻辑对象; //新增门锁常开模式自动化入口; Common.Logic.CurrentLogic = new Common.Logic(); Common.Logic.CurrentLogic.IsEnable = 1;//默认为开 Common.Logic.CurrentLogic.LogicType = 2;//标记逻辑类型 Common.Logic.CurrentLogic.LogicName = Language.StringByID(MyInternationalizationString.openmode); Common.Logic.CurrentLogic.Conditions.Add(timeConditionsInfo);//添加条件 Common.Logic.CurrentLogic.Actions.Add(actionsInfo);//添加目标 Common.Logic.CurrentLogic.Accounts.Add(accounts); var oneLogic = new OneLogic(); UserView.HomePage.Instance.AddChidren(oneLogic); UserView.HomePage.Instance.PageIndex += 1; oneLogic.Show(false); }; ///常开自动化列表上下滑动的控件 verticalRefresh = new VerticalRefreshLayout { Y = addLogicfL.Bottom, X = Application.GetRealWidth(46), Height = listLogicFl.Height - addLogicfL.Height, Width = listLogicFl.Width - Application.GetRealWidth(46), }; listLogicFl.AddChidren(verticalRefresh); verticalRefresh.BeginHeaderRefreshingAction += () => { Common.Logic.SoneLogicList.Clear(); Read(false); verticalRefresh.EndHeaderRefreshing(); }; Read(true); #endregion UserCenter.DoorLock.DoorLockCommonInfo.LogicAction = (_bool) => { try { Application.RunOnMainThread(() => { Send.CurrentDoorLock.IsDoorLockNormallyMode = _bool; ModeView(); }); } catch { } }; updateCurrentDoorlockActionTemp = (DoorlockKey, _bool) => { var key = Send.CurrentDoorLock.DeviceAddr; if (DoorlockKey == key) { try { Application.RunOnMainThread(() => { Send.CurrentDoorLock.IsDoorLockNormallyMode = _bool; ModeView(); }); } catch { } } }; UserCenter.DoorLock.DoorLockCommonInfo.UpdateCurrentDoorlockAction += updateCurrentDoorlockActionTemp; } /// /// 常开模式开关切换图标界面 /// public void ModeView() { fLayout.RemoveAll(); ///常开模式图标 Button modeIconBtn = new Button { X = Application.GetRealWidth(395), Y = Application.GetRealHeight(92), Width = Application.GetMinRealAverage(294), Height = Application.GetMinRealAverage(294), }; fLayout.AddChidren(modeIconBtn); if (Send.CurrentDoorLock.IsDoorLockNormallyMode) { fLayout.Height = Application.GetRealHeight(780);//改变高度 modeIconBtn.UnSelectedImagePath = "ZigeeLogic/openMode.png";//改变图标状态 ///第二级父控件 var openModeFl = new FrameLayout { Y = Application.GetRealHeight(455), Height = Application.GetRealHeight(127 + 199), Width = Application.GetRealWidth(1080), }; fLayout.AddChidren(openModeFl); ///关闭时效性自动化 Button closeBtn = new Button { X = Application.GetRealWidth(86), Height = Application.GetRealHeight(127), Width = Application.GetRealWidth(907), Radius = (uint)Application.GetRealHeight(58), BackgroundColor = ZigbeeColor.Current.LogicBtnSaveBackgroundColor, TextID = MyInternationalizationString.closeUp, TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor, TextSize = 16, }; openModeFl.AddChidren(closeBtn); closeBtn.MouseUpEventHandler += async (sender, e) => { CommonPage.Loading.Start(); try { var result = await UserCenter.DoorLock.DoorLockCommonInfo.DelNormallyOpenMode(Send.CurrentDoorLock); if (result) { if (logicId != 0) { ///有可能只有常开模式,没有时效性自动化 Send.DelLogic(logicId); } Send.CurrentDoorLock.IsDoorLockNormallyMode = false; ModeView(); } else { LogicView.TipView.ShowFlashTip(Language.StringByID(MyInternationalizationString.closeFailed)); } } catch { } finally { Application.RunOnMainThread(() => { CommonPage.Loading.Hide(); }); } }; if (logicId != 0) { ///显示失效设置时间文本控件 var timeTextBtn = new Button { Y = Application.GetRealHeight(127 + 69), X = Application.GetRealWidth(80),//125 Width = Application.GetRealWidth(907 + 12),//634 + 200 Height = Application.GetRealHeight(60), TextSize = 15, TextColor = ZigbeeColor.Current.LogicTextBlackColor, }; openModeFl.AddChidren(timeTextBtn); string text1 = Language.StringByID(MyInternationalizationString.timeSensitive); string text2 = Language.StringByID(MyInternationalizationString.yearSone); string text3 = Language.StringByID(MyInternationalizationString.monthSone); string text4 = Language.StringByID(MyInternationalizationString.numberSone); string text5 = Language.StringByID(MyInternationalizationString.hour1); string text6 = Language.StringByID(MyInternationalizationString.executeSone); string year = ""; string month = ""; int days = 0; int hour = 0; int minute = 0; if (timeLong != 0) { ///读取网关时间; var datetime = GetLocalTime(timeLong); ///有时效性常开才显示时间条件文本 year = datetime.Year.ToString();//那一年 month = datetime.Month.ToString();//那一月 days = int.Parse(datetime.ToString("dd"));//那一天 hour = int.Parse(datetime.ToString("HH"));//小时 minute = datetime.Minute;//分钟 timeLong = 0; } else { ///读取系统时间 year = DateTime.Now.Year.ToString();//那一年 month = DateTime.Now.Month.ToString();//那一月 var d = DateTime.Now.ToString("dd");//那一天 var h = int.Parse(DateTime.Now.ToString("HH"));//小时 int dayInt = (h + timeValue) / 24;//设置时间+当前系统时间是否超出24小时 hour = (h + timeValue) % 24;//设置时间+当前系统时间是否超出24小时剩下多少小时 days = int.Parse(d) + dayInt;//当前系统天数+执行后天数 minute = DateTime.Now.Minute;//分钟 } timeTextBtn.Text = text1 + year + text2 + month + text3 + days.ToString() + text4 + hour.ToString() + text5 + minute.ToString() + text6; } } else { fLayout.Height = Application.GetRealHeight(645);//改变高度 modeIconBtn.UnSelectedImagePath = "ZigeeLogic/noMode.png";//改变图标状态 ///第二级父控件 var modeFl = new FrameLayout { Y = Application.GetRealHeight(478), X = Application.GetRealWidth(58), Height = Application.GetRealHeight(138), Width = Application.GetRealWidth(1022), BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor, }; fLayout.AddChidren(modeFl); modeFl.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerBottomLeft); ///时效性常开设置显示文本控件 var modeTextBtn = new Button { Y = Application.GetRealHeight(40), X = Application.GetRealWidth(58), Width = Application.GetRealWidth(600), Height = Application.GetRealHeight(60), TextSize = 15, TextColor = ZigbeeColor.Current.LogicTextBlackColor, TextAlignment = TextAlignment.CenterLeft, // Text = "时效性常开设置", TextID = MyInternationalizationString.timeSetSone, }; modeFl.AddChidren(modeTextBtn); ///下一级菜单图标控件 var nextIconBtn = new Button { Width = Application.GetMinRealAverage(104), Height = Application.GetMinRealAverage(104), X = Application.GetRealWidth(861), Y = Application.GetRealHeight(17), UnSelectedImagePath = "ZigeeLogic/nextIconSone.png", }; modeFl.AddChidren(nextIconBtn); ///加大点击热键 var clickBtn = new Button { Width = Application.GetRealWidth(104 + 161 + 30), Height = Application.GetRealHeight(138), X = Application.GetRealWidth(700), }; modeFl.AddChidren(clickBtn); clickBtn.MouseUpEventHandler += (sender, e) => { LogicView.TipView.ShowConfrimTip(() => {///再次确认 LogicView.TipView.ShowInputTip(true, async (str) => {///确认发送命令 CommonPage.Loading.Start(); try { ///xm var result = await UserCenter.DoorLock.DoorLockCommonInfo.SetNormallyOpenModeFuncAsync(Send.CurrentDoorLock); if (!result) { LogicView.TipView.ShowFlashTip(Language.StringByID(MyInternationalizationString.openFailed)); return; } else { ///因为有常开模式下才可以创建失效逻辑; SkipView.DelAllLogic(Send.CurrentDoorLock);//删除之前所有失效逻辑 var addResult = await SkipView.LockAddModifyLogic(int.Parse(str), Send.CurrentDoorLock);//添加一条失效逻辑 if (addResult == 0) { ///可欣说如果常开模式开,创建自动化失败,那么将要发一条常开模式关闭命令; UserCenter.DoorLock.DoorLockCommonInfo.DelNormallyOpenMode(Send.CurrentDoorLock); ///提示失败 LogicView.TipView.ShowFlashTip(Language.StringByID(MyInternationalizationString.addFailed)); return; } else { logicId = addResult; timeValue = int.Parse(str); Send.CurrentDoorLock.IsDoorLockNormallyMode = true; ModeView(); ///添加APP开启常开模式的历史记录 UserCenter.HdlDeviceDoorLockLogic.Current.AddDoorHistoryLog(Send.CurrentDoorLock, 9001, string.Empty); } } } catch { } finally { Application.RunOnMainThread(() => { CommonPage.Loading.Hide(); }); } }); }); }; } listLogicFl.Y = fLayout.Bottom; listLogicFl.X = Application.GetRealWidth(58); listLogicFl.Height = Application.GetRealHeight(Method.H - 184) - fLayout.Height; listLogicFl.Width = Application.GetRealWidth(1022); listLogicFl.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor; verticalRefresh.Y = Application.GetRealHeight(187); verticalRefresh.X = Application.GetRealWidth(46); verticalRefresh.Height = listLogicFl.Height - Application.GetRealHeight(187);//动态改动上下滑动view高度; verticalRefresh.Width = listLogicFl.Width - Application.GetRealWidth(46); } /// /// 读取自动化列表数据; /// /// private async void Read(bool yes) { //if (yes) // { CommonPage.Loading.Start(); // } try { if (Common.Logic.SoneLogicList.Count == 0) { var Idlist = await Send.GetLogicId(2);//门锁常开模式 if (Idlist.Count != 0) { var listlogic = await Send.ReadList(Idlist.Count, 2); for (int i = 0; i < listlogic.Count; i++) { var logic = listlogic[i]; if (logic.LogicType != 2) { continue; } if (SkipView.ExistLogic(logic, Send.CurrentDoorLock)) { Common.Logic.SoneLogicList.Add(logic); } } } } } catch (Exception e) { var dd = e.Message; } finally { Application.RunOnMainThread(() => { // if (yes) // { CommonPage.Loading.Hide(); // } //自动化 RefreshView(); }); } } /// /// 记录左滑状态 /// RowLayout selectedRow = new RowLayout() { Tag = "0" }; int a = 1; /// /// 加载自动化列表 /// public void RefreshView() { verticalRefresh.RemoveAll(); foreach (var logic in Common.Logic.SoneLogicList) { if (!SkipView.ExistLogic(logic, Send.CurrentDoorLock)) { ///不是该门锁自动化就不显示出来; continue; } #region 自动化布局View ///自动化父控件 var fLayoutLogic = new FrameLayout { Height = Application.GetRealHeight(184), }; verticalRefresh.AddChidren(fLayoutLogic); ///左右可滑动控件 var logicRow = new RowLayout { LineColor = ZigbeeColor.Current.LogicBackgroundColor, BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor, SubViewWidth = Application.GetRealWidth(184),//改变编辑控件宽度多少; Tag = a.ToString(), }; fLayoutLogic.AddChidren(logicRow); //左滑菜单事件 logicRow.OpenMenuAction += () => { if (selectedRow.Tag.ToString() != logicRow.Tag.ToString()) { //保留左滑只有一个; selectedRow.HideMenu();// } selectedRow = logicRow; }; a++; ///显示逻辑名称的控件 var nameBtn = new Button { Height = Application.GetRealHeight(58), Width = Application.GetRealWidth(350), Text = logic.LogicName, X = Application.GetRealWidth(12), Y = Application.GetRealHeight(3), TextAlignment = TextAlignment.CenterLeft, TextColor = ZigbeeColor.Current.LogicTextBlackColor, TextSize = 14, }; logicRow.AddChidren(nameBtn); ///显示目标功能背景颜色的控件 var typeBjBtn = new FrameLayout { Width = Application.GetMinRealAverage(82), Height = Application.GetMinRealAverage(82), X = Application.GetRealWidth(17), Y = Application.GetRealHeight(84), Radius = (uint)Application.GetMinRealAverage(41), BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor, }; logicRow.AddChidren(typeBjBtn); ///显示目标功能图标的控件 var typeIconBtn = new Button { Width = Application.GetMinRealAverage(58), Height = Application.GetMinRealAverage(58), Gravity = Gravity.Center, }; typeBjBtn.AddChidren(typeIconBtn); ///逻辑开关图标的控件 var switchBtn = new Button { Width = Application.GetMinRealAverage(104), Height = Application.GetMinRealAverage(63), UnSelectedImagePath = "ZigeeLogic/logicclose.png", SelectedImagePath = "ZigeeLogic/logicopen.png", X = Application.GetRealWidth(815), Y = Application.GetRealHeight(92), }; logicRow.AddChidren(switchBtn); if (logic.IsEnable == 1) { switchBtn.IsSelected = true; typeIconBtn.UnSelectedImagePath = "ZigeeLogic/function1.png"; typeBjBtn.BackgroundColor = ZigbeeColor.Current.LogicFunction1Color; } else if (logic.IsEnable == 0) { switchBtn.IsSelected = false; typeIconBtn.UnSelectedImagePath = "ZigeeLogic/nofunction.png"; typeBjBtn.BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor; } ///编辑 var edit = new Button { BackgroundColor = ZigbeeColor.Current.LogicEditBlackColor1, Text = Language.StringByID(MyInternationalizationString.edit), TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor, }; logicRow.AddRightView(edit); ///删除 var del = new Button { BackgroundColor = ZigbeeColor.Current.LogicDelBlackColor1, Text = Language.StringByID(MyInternationalizationString.del), TextColor = ZigbeeColor.Current.LogicBtnSaveTextColor, }; logicRow.AddRightView(del); ///线的控件 var line = new Button { Y = fLayoutLogic.Height - 1, Height = 1, Width = Application.GetRealWidth(976), BackgroundColor = ZigbeeColor.Current.LogicRowLayoutLineColor, }; fLayoutLogic.AddChidren(line); #endregion ///开关点击事件 switchBtn.MouseUpEventHandler += (sender1, e1) => { switchBtn.IsSelected = !switchBtn.IsSelected; if (switchBtn.IsSelected) { //逻辑开 logic.IsEnable = 1; typeIconBtn.UnSelectedImagePath = "ZigeeLogic/function1.png"; typeBjBtn.BackgroundColor = ZigbeeColor.Current.LogicFunction1Color; } else { //逻辑关 logic.IsEnable = 0; typeIconBtn.UnSelectedImagePath = "ZigeeLogic/nofunction.png"; typeBjBtn.BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor; } Send.LogicControlSwitch(logic); //Logic.Send.AddModifyLogic(logic); }; ///编辑点击事件 edit.MouseUpEventHandler += (sender, e) => { Common.Logic.CurrentLogic = logic; var oneLogic = new OneLogic(); UserView.HomePage.Instance.AddChidren(oneLogic); UserView.HomePage.Instance.PageIndex += 1; oneLogic.Show(false); }; ///删除点击事件 del.MouseUpEventHandler += (sender, e) => { var alert = new UserCenter.ShowMsgControl(UserCenter.ShowMsgType.Confirm, Language.StringByID(MyInternationalizationString.doyouwanttodelete), Language.StringByID(MyInternationalizationString.confrim)); alert.Show(); alert.ConfirmClickEvent += () => { Common.Logic.SoneLogicList.Remove(logic); //logicRow.Parent.RemoveFromParent(); fLayoutLogic.RemoveFromParent(); Send.DelLogic(logic.LogicId); }; }; } } /// /// 时间戳转换成时间格式 /// /// 时间戳 /// public DateTime GetLocalTime(int unixTimeStamp) { DateTime dtStart = TimeZone.CurrentTimeZone.ToLocalTime(new DateTime(1970, 1, 1)); long lTime = long.Parse(unixTimeStamp + "0000000"); TimeSpan toNow = new TimeSpan(lTime); DateTime dtResult = dtStart.Add(toNow); return dtResult; } } }