using System; using System.Collections.Generic; using Shared.Common; using ZigBee.Device; namespace Shared.Phone.UserCenter.DoorLock { public class TimeSettignPage : DoorLockCommonLayout, ZigBee.Common.IStatus { /// /// 处理变化事件 /// /// /// public void DeviceInfoChange(CommonDevice tempDevice, string typeTag) { if (typeTag == "DeviceStatusReport" && tempDevice != null) { if (tempDevice != null) { if (tempDevice.DeviceEpoint == doorLock.DeviceEpoint && tempDevice.DeviceAddr == doorLock.DeviceAddr) { if (tempDevice.DeviceStatusReport != null && tempDevice.DeviceStatusReport.AttriBute != null) { var dataReport = tempDevice.DeviceStatusReport.AttriBute[0]; if (tempDevice.DeviceStatusReport.CluterID == 10 && dataReport.AttributeId == 0) { CurentDoorLockTime = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetLocalTime(dataReport.AttriButeData); Application.RunOnMainThread(() => { waitGetDoorLockTime = DateTime.MaxValue; textDisplayDate.Text = CurentDoorLockTime.Year + Language.StringByID(R.MyInternationalizationString.Year) + CurentDoorLockTime.Month + Language.StringByID(R.MyInternationalizationString.Month) + CurentDoorLockTime.Day + Language.StringByID(R.MyInternationalizationString.Day); if (CurentDoorLockTime.Minute < 10) { textDisplayTime.Text = CurentDoorLockTime.Hour + ":" + "0" + CurentDoorLockTime.Minute; } else { textDisplayTime.Text = CurentDoorLockTime.Hour + ":" + CurentDoorLockTime.Minute; } CommonPage.Loading.Hide(); }); } } } } } } /// /// 构造函数 /// /// public TimeSettignPage(ZigBee.Device.DoorLock doorLock, string timeType) { this.doorLock = doorLock; setTimeType = timeType; BackgroundColor = Shared.Common.ZigbeeColor.Current.GXCTopViewBackgroundColor; ZigBee.Device.ZbGateway.StatusList.Add(this); } #region ◆ 变量申明__________________________ ZigBee.Device.DoorLock doorLock; string setTimeType = ""; DateTime CurentDoorLockTime; Button textDisplayDate; Button textDisplayTime; int curYear = 0; int curMonth = 0; int curDay = 0; int curHour = 0; int curMin = 0; int curSec = 0; public Action timeSetAction; DateTime waitGetDoorLockTime = DateTime.MaxValue; #endregion /// /// 重写移除方法 /// public override void RemoveFromParent() { ZbGateway.StatusList.Remove(this); base.RemoveFromParent(); } /// /// UI显示 /// public void Show() { if (setTimeType == "ValidTime") { this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.ValidTime)); } else if (setTimeType == "InValidTime") { this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.InValidTime)); } else { this.TopFrameLayout(this, Language.StringByID(R.MyInternationalizationString.DoorLockTime)); } EventHandler eHandlerBack = (sender, e) => { this.RemoveFromParent(); }; this.btnBack.MouseUpEventHandler += eHandlerBack; this.btnBackFrameLayout.MouseUpEventHandler += eHandlerBack; this.MidFrameLayout(this); MidFrameLayoutContent(); } public void MidFrameLayoutContent() { if (setTimeType == "DoorLockTime") { CommonPage.Loading.Start(""); // 只有重新启动时会慢,然后其他时刻都是有值的 new System.Threading.Thread(() => { while (this.Parent != null) { if (DateTime.Now > waitGetDoorLockTime) { Application.RunOnMainThread(() => { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.None, CloseTime = 2 }.Show(CommonPage.Instance); CommonPage.Loading.Hide(); }); } //读门锁时间 //等待10秒,没有收到提示超时退出 waitGetDoorLockTime = DateTime.Now.AddSeconds(+5); doorLock.ReadAttri(ZigBee.Device.Cluster_ID.DoorLock, ZigBee.Device.AttriButeId.DoorLock); System.Threading.Thread.Sleep(5 * 1000); } }) { IsBackground = true }.Start(); } var MidTopFrameLayout = new FrameLayout() { }; this.midFrameLayout.AddChidren(MidTopFrameLayout); var dtNow = DateTime.Now; for (int i = 0; i < 2; i++) { var rowLayout = new FrameLayout() { Height = Application.GetRealHeight(127 + 23), BackgroundColor = Shared.Common.ZigbeeColor.Current.XMWhite, }; MidTopFrameLayout.AddChidren(rowLayout); var btnDateTime = new Button() { Width = Application.GetRealWidth(560), Height = Application.GetRealHeight(58), X = Application.GetRealWidth(58), TextColor = Shared.Common.ZigbeeColor.Current.XMBlack, TextAlignment = TextAlignment.CenterLeft, TextSize = 12, }; rowLayout.AddChidren(btnDateTime); var textDisplayDateFrameLayout = new FrameLayout() { Width = Application.GetRealWidth(333), Height = Application.GetRealHeight(58), X = Application.GetRealWidth(620), }; rowLayout.AddChidren(textDisplayDateFrameLayout); var btnNextFrameLayout = new FrameLayout() { Width = Application.GetRealWidth(116), Height = Application.GetRealHeight(58), X = Application.GetRealWidth(956), }; rowLayout.AddChidren(btnNextFrameLayout); var btnNext = new Button() { Width = Application.GetRealWidth(58), Height = Application.GetRealHeight(58), UnSelectedImagePath = "Item/Next.png", SelectedImagePath = "Item/Down.png", }; btnNextFrameLayout.AddChidren(btnNext); var btnLine = new FrameLayout() { Width = Application.GetRealWidth(965), Height = 1, X = Application.GetRealWidth(58), BackgroundColor = Shared.Common.ZigbeeColor.Current.XMRowLine, }; MidTopFrameLayout.AddChidren(btnLine); if (i == 0) { btnDateTime.Y = textDisplayDateFrameLayout.Y = btnNextFrameLayout.Y = Application.GetRealHeight(50); btnLine.Y = Application.GetRealHeight(23 + 127); textDisplayDate = new Button() { TextColor = Shared.Common.ZigbeeColor.Current.XMGray3, TextAlignment = TextAlignment.CenterRight, TextSize = 12, Text = "_" + Language.StringByID(R.MyInternationalizationString.Year) + "_" + Language.StringByID(R.MyInternationalizationString.Month) + "_" + Language.StringByID(R.MyInternationalizationString.Day), }; textDisplayDateFrameLayout.AddChidren(textDisplayDate); if (setTimeType != "DoorLockTime") { btnDateTime.Text = Language.StringByID(R.MyInternationalizationString.Date); if (setTimeType == "ValidTime") { textDisplayDate.Text = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateMonth + Language.StringByID(R.MyInternationalizationString.Month) + Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateDay + Language.StringByID(R.MyInternationalizationString.Day); } else if (setTimeType == "InValidTime") { textDisplayDate.Text = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateMonth + Language.StringByID(R.MyInternationalizationString.Month) + Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateDay + Language.StringByID(R.MyInternationalizationString.Day); } } else { btnDateTime.Text = Language.StringByID(R.MyInternationalizationString.CurrentDate); } } else if (i == 1) { rowLayout.Y = 1 + Application.GetRealHeight(150); btnDateTime.Y = textDisplayDateFrameLayout.Y = btnNextFrameLayout.Y = Application.GetRealHeight(50); btnLine.Y = Application.GetRealHeight(40 + 127 + 127); textDisplayTime = new Button() { TextColor = Shared.Common.ZigbeeColor.Current.XMGray3, TextAlignment = TextAlignment.CenterRight, TextSize = 12, Text = "00:00", }; textDisplayDateFrameLayout.AddChidren(textDisplayTime); if (setTimeType != "DoorLockTime") { btnDateTime.Text = Language.StringByID(R.MyInternationalizationString.Time); if (setTimeType == "ValidTime") { if (Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateMinute < 10) { textDisplayTime.Text = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateHour + ":" + "0" + Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateMinute; } else { textDisplayTime.Text = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateHour + ":" + Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateMinute; } } else if (setTimeType == "InValidTime") { if (Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateMinute < 10) { textDisplayTime.Text = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateHour + ":" + "0" + Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateMinute; } else { textDisplayTime.Text = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateHour + ":" + Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateMinute; } } } else { btnDateTime.Text = Language.StringByID(R.MyInternationalizationString.CurrentTime); } btnLine.Visible = false; } int curIndex = i; EventHandler hander = (sender, e) => { this.midFrameLayout.AddChidren(this.shadowRadiusFrameLayout); this.BottomRadiusFrameLayout(this); var mUIPickerView = new UIPickerView() { X = Application.GetRealWidth(0), }; this.bottomRadiusFrameLayout.AddChidren(mUIPickerView); if (curIndex == 0) { //日期 if (setTimeType != "DoorLockTime") { this.btnBottomTitle.TextID = R.MyInternationalizationString.Date; } else { this.btnBottomTitle.TextID = R.MyInternationalizationString.CurrentDate; } mUIPickerView.Y = Application.GetRealWidth(110); var mList1 = new List(); var mList2 = new List(); var mList3 = new List(); var oldMonth = dtNow.Month; int year = dtNow.Year + 1; int days = DateTime.DaysInMonth(dtNow.Year, dtNow.Month); for (int y = dtNow.Year - 10; y < dtNow.Year + 1; y++) { mList1.Add(y.ToString()); } for (int m = 1; m < 13; m++) { mList2.Add(m.ToString()); } for (int d = 1; d < days + 1; d++) { mList3.Add(d.ToString()); } if (setTimeType != "DoorLockTime") { mUIPickerView.setNPicker(mList2, mList3, null); mUIPickerView.setCurrentItems(dtNow.Month - 1, dtNow.Day - 1, 0); curMonth = dtNow.Month; curDay = dtNow.Day; if (setTimeType == "ValidTime") { Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateYear = dtNow.Year; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateMonth = curMonth; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateDay = curDay; } else { Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateYear = dtNow.Year; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateMonth = curMonth; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateDay = curDay; } var btnOk = new Button { X = Application.GetRealWidth(919), Y = Application.GetRealHeight(40), Height = Application.GetRealHeight(58), Width = Application.GetRealWidth(101), Text = Language.StringByID(R.MyInternationalizationString.Complete), TextColor = Shared.Common.ZigbeeColor.Current.XMGray3, TextSize = 14, }; this.bottomRadiusFrameLayout.AddChidren(btnOk); btnOk.MouseUpEventHandler += (sender1, e1) => { if (setTimeType == "ValidTime") { Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateYear = dtNow.Year; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateMonth = curMonth; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateDay = curDay; } else { Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateYear = dtNow.Year; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateMonth = curMonth; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateDay = curDay; } if (timeSetAction != null) { timeSetAction(); } this.shadowRadiusFrameLayout.RemoveFromParent(); MidFrameLayoutContent(); }; } else { mUIPickerView.setNPicker(mList1, mList2, mList3); mUIPickerView.setCurrentItems(dtNow.Year, dtNow.Month - 1, dtNow.Day - 1); curYear = dtNow.Year; curMonth = dtNow.Month; curDay = dtNow.Day; if (CurentDoorLockTime != null) { curHour = CurentDoorLockTime.Hour; curMin = CurentDoorLockTime.Minute; curSec = CurentDoorLockTime.Second; } else { curHour = dtNow.Hour; curMin = dtNow.Minute; curSec = dtNow.Second; } } Action dAction = () => { if (curMonth != oldMonth) { oldMonth = curMonth; days = DateTime.DaysInMonth(curYear, curMonth); mList3.Clear(); for (int d = 1; d < days + 1; d++) { mList3.Add(d.ToString()); } if (setTimeType != "DoorLockTime") { mUIPickerView.setNPicker(mList2, mList3, null); mUIPickerView.setCurrentItems(curMonth - 1, curDay - 1, 0); } else { mUIPickerView.setNPicker(mList1, mList2, mList3); mUIPickerView.setCurrentItems(curYear, curMonth - 1, curDay - 1); } } }; mUIPickerView.OnSelectChangeEvent += (y, m, d) => { if (setTimeType != "DoorLockTime") { curYear = dtNow.Year; curMonth = y + 1; curDay = m + 1; } else { curYear = y + 2009; curMonth = m + 1; curDay = d + 1; } dAction(); }; } if (curIndex == 1) { //时间 if (setTimeType != "DoorLockTime") { this.btnBottomTitle.TextID = R.MyInternationalizationString.Time; } else { this.btnBottomTitle.TextID = R.MyInternationalizationString.CurrentTime; } mUIPickerView.Y = Application.GetRealWidth(95); var mList1 = new List(); var mList2 = new List(); for (int h = 0; h < 24; h++) { if (h < 10) { mList1.Add("0" + h.ToString()); } else { mList1.Add(h.ToString()); } } for (int m = 0; m < 60; m++) { if (m < 10) { mList2.Add("0" + m.ToString()); } else { mList2.Add(m.ToString()); } } mUIPickerView.setNPicker(mList1, mList2, null); mUIPickerView.setCurrentItems(dtNow.Hour, dtNow.Minute, 0); if (CurentDoorLockTime != null) { curYear = CurentDoorLockTime.Year; curMonth = CurentDoorLockTime.Month; curDay = CurentDoorLockTime.Day; } else { curYear = dtNow.Year; curMonth = dtNow.Month; curDay = dtNow.Day; } curHour = dtNow.Hour; curMin = dtNow.Minute; curSec = dtNow.Second; mUIPickerView.OnSelectChangeEvent += (h, m, s) => { curHour = h; curMin = m; curSec = dtNow.Second; }; if (setTimeType == "ValidTime") { Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateHour = curHour; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateMinute = curMin; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateSecond = curSec; } else { Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateHour = curHour; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateMinute = curMin; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateSecond = curSec; } if (setTimeType != "DoorLockTime") { var btnOk = new Button { X = Application.GetRealWidth(919), Y = Application.GetRealHeight(40), Height = Application.GetRealHeight(58), Width = Application.GetRealWidth(101), Text = Language.StringByID(R.MyInternationalizationString.Complete), TextColor = Shared.Common.ZigbeeColor.Current.XMGray3, TextSize = 14, }; this.bottomRadiusFrameLayout.AddChidren(btnOk); btnOk.MouseUpEventHandler += (sender1, e1) => { if (setTimeType == "ValidTime") { Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateHour = curHour; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateMinute = curMin; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.ValidDateSecond = curSec; } else { Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateHour = curHour; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateMinute = curMin; Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.InValidDateSecond = curSec; } if (timeSetAction != null) { timeSetAction(); } this.shadowRadiusFrameLayout.RemoveFromParent(); MidFrameLayoutContent(); }; } } }; rowLayout.MouseDownEventHandler += hander; btnDateTime.MouseDownEventHandler += hander; textDisplayDateFrameLayout.MouseDownEventHandler += hander; btnNextFrameLayout.MouseDownEventHandler += hander; btnNext.MouseDownEventHandler += hander; } btnCancel.MouseUpEventHandler += (sender1, e1) => { this.shadowRadiusFrameLayout.RemoveFromParent(); }; btnFinish.MouseUpEventHandler += async (sender1, e1) => { if (setTimeType == "DoorLockTime") { var curDateTime = new DateTime(curYear, curMonth, curDay, curHour, curMin, curSec); var setTimestamp = Shared.Phone.UserCenter.DoorLock.DoorLockCommonInfo.GetUnixTimeStamp(curDateTime); try { CommonPage.Loading.Start(""); var rectifyResult = await doorLock.RectifyDoorLockTimeAsync(int.Parse(setTimestamp)); if (rectifyResult != null && rectifyResult.setWritableValueResponData != null) { if (rectifyResult.setWritableValueResponData.Status == 0) { this.shadowRadiusFrameLayout.RemoveFromParent(); } else { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.RectifyFailed), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinish); } } else { new Tip() { MaxWidth = 150, Text = Language.StringByID(R.MyInternationalizationString.GwResponseOvertime), Direction = AMPopTipDirection.Up, CloseTime = 1 }.Show(btnFinish); } } catch { } finally { System.Threading.Thread.Sleep(3000); CommonPage.Loading.Hide(); } } }; this.shadowRadiusFrameLayout.MouseUpEventHandler += (sender1, e1) => { this.shadowRadiusFrameLayout.RemoveFromParent(); }; if (setTimeType == "DoorLockTime") { if (CurentDoorLockTime != null && CurentDoorLockTime.Year != 1) { waitGetDoorLockTime = DateTime.MaxValue; CommonPage.Loading.Hide(); } } } #region ◆ 接口实现__________________________ /// /// 处理变化事件 --将弃用 改用DeviceInfoChange() /// /// The changed. /// Common. public void Changed(CommonDevice common) { } /// /// Changeds the IL ogic status. /// /// Logic. public void ChangedILogicStatus(ZigBee.Device.Logic logic) { } /// /// Changeds the IS cene status. /// /// Scene. public void ChangedISceneStatus(Scene scene) { } #endregion } }