using Shared; using HDL_ON.Stan; using System; using System.Collections.Generic; using System.Text; using HDL_ON.UI.CSS; using HDL_ON.Entity; namespace HDL_ON.UI { /// /// 门锁的控制界面 /// public class DoorLockPage : DeviceFunctionCardCommonForm { #region ■ 变量声明___________________________ /// /// 电池控件 /// private BatteryPersentControl batteryControl = null; /// /// 在线图标控件 /// private IconViewControl btnOnlineIcon = null; /// /// 在线文本控件 /// private NormalViewControl btnOnlineView = null; /// /// 声音图标 /// private IconViewControl btnVoice = null; /// /// 声音的滑动条控件 /// private SeekBarImageControl seekBarVoiceControl = null; /// /// 声音百分比 /// private NormalViewControl btnVoicePersent = null; /// /// 常开模式图标 /// private IconViewControl btnNormallyOpenIcon = null; /// /// 中间的开锁或者关锁图片控件 /// private PicViewControl picLockControl = null; /// /// 临时密码tab页中间的控件容器(它的Y轴是 一键开锁/临时密码开锁的底部(粗体字体)+4) /// private FrameLayout frameTempPsw = null; /// /// 1:选择的是一键开锁 2:选择的是临时密码开锁 /// private int nowSelectMenu = 1; /// /// 门锁数据 /// private DoorLockData doorLockData = new DoorLockData(); /// /// 门锁的历史记录 /// private List listHistoryLog = null; /// /// 成员列表 /// private List listMember = null; /// /// 文本缓存 /// private Dictionary dicText = new Dictionary(); #endregion #region ■ 初始化_____________________________ /// /// 门锁的控制界面 /// public DoorLockPage() { //门锁不允许收藏 this.ShowColltionButton = false; } /// /// 初始化白色区域的内容 /// public override void InitFrameWhiteContent() { //智能门锁 base.SetTitleText(Language.StringByID(StringId.DoorLock)); this.dicText["已连接"] = Language.StringByID(StringId.Connected); this.dicText["未连接"] = Language.StringByID(StringId.UnConnected); //左右翻页的事件 base.PageChangeEvent += (index) => { if (index == 1) { //初始化门锁历史记录以及控件 this.InitDoorHistoryLogAndControl(); } }; //刷新当前设备的状态缓存 this.RefreshNowDeviceStatuMemory(this.device); //初始化第一个索引页的内容 this.InitFrameWhiteContent1(); //初始化第二个索引页(历史记录) this.InitFrameWhiteContent2(); //刷新界面状态 this.RefreshFormStatu(); } /// /// 初始化第一个索引页的内容 /// private void InitFrameWhiteContent1() { //电池控件 this.batteryControl = new BatteryPersentControl(); //它有个最小的X轴 batteryControl.X = Application.GetRealWidth(104) > base.btnRoomName.Right ? Application.GetRealWidth(104) : base.btnRoomName.Right + Application.GetRealWidth(4); FrameWhiteCentet1.AddChidren(batteryControl); if (batteryControl.Height > base.btnRoomName.Height) { //一个是25,一个是21,弄不准到底谁更高,因为计算方法不一样 batteryControl.Y = base.btnRoomName.Y - (batteryControl.Height - base.btnRoomName.Height) / 2; } else { batteryControl.Y = base.btnRoomName.Y + (batteryControl.Height - base.btnRoomName.Height) / 2; } batteryControl.InitControl(); batteryControl.SetValue(100); //在线状态 this.btnOnlineIcon = new IconViewControl(24); btnOnlineIcon.X = batteryControl.Right + Application.GetRealWidth(12); btnOnlineIcon.Y = batteryControl.Y; btnOnlineIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/Connect.png"; FrameWhiteCentet1.AddChidren(btnOnlineIcon); //在线文本 this.btnOnlineView = new NormalViewControl(Application.GetRealWidth(100), btnOnlineIcon.Height, false); btnOnlineView.X = btnOnlineIcon.Right + Application.GetRealWidth(4); btnOnlineView.Y = btnOnlineIcon.Y; btnOnlineView.TextSize = CSS_FontSize.PromptFontSize_SecondaryLevel; btnOnlineView.TextColor = CSS_Color.PromptingColor1; btnOnlineView.TextID = StringId.Connected; FrameWhiteCentet1.AddChidren(btnOnlineView); //右上角配置结束的事件 base.SettionFinishEvent += () => { //从新设置坐标 batteryControl.X = Application.GetRealWidth(104) > base.btnRoomName.Right ? Application.GetRealWidth(104) : base.btnRoomName.Right + Application.GetRealWidth(4); btnOnlineIcon.X = batteryControl.Right + Application.GetRealWidth(12); btnOnlineView.X = btnOnlineIcon.Right + Application.GetRealWidth(4); }; //中间的开锁或者关锁图片控件 this.picLockControl = new PicViewControl(256, 260); picLockControl.Y = Application.GetRealHeight(129); picLockControl.Gravity = Gravity.CenterHorizontal; picLockControl.UnSelectedImagePath = "FunctionIcon/DoorLock/LockPictrue1.png"; FrameWhiteCentet1.AddChidren(picLockControl); picLockControl.ButtonClickEvent += (sender, e) => { //一键开锁 this.DoOneKeyToUnlockDoor(); }; //临时密码的控件容器 this.frameTempPsw = new FrameLayout(); frameTempPsw.Y = Application.GetRealHeight(129); frameTempPsw.Height = Application.GetRealHeight(260); frameTempPsw.Visible = false; FrameWhiteCentet1.AddChidren(frameTempPsw); //声音 this.btnVoice = new IconViewControl(24); btnVoice.UnSelectedImagePath = "FunctionIcon/DoorLock/Voice.png"; btnVoice.X = Application.GetRealWidth(23); btnVoice.Y = Application.GetRealHeight(410); FrameWhiteCentet1.AddChidren(btnVoice); //声音的滑动条 this.seekBarVoiceControl = new SeekBarImageControl(215); seekBarVoiceControl.Gravity = Gravity.CenterHorizontal; FrameWhiteCentet1.AddChidren(seekBarVoiceControl); seekBarVoiceControl.Y = btnVoice.Y - (seekBarVoiceControl.Height - btnVoice.Height) / 2; //绑定PageLayout控件 seekBarVoiceControl.BindPageLayout(); //声音百分比 this.btnVoicePersent = new NormalViewControl(Application.GetRealWidth(50), btnVoice.Height, false); btnVoicePersent.X = seekBarVoiceControl.Right + Application.GetRealWidth(8) - seekBarVoiceControl.SeekBarPadding; btnVoicePersent.Y = btnVoice.Y; btnVoicePersent.TextColor = CSS_Color.PromptingColor1; btnVoicePersent.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnVoicePersent.Text = "100%"; FrameWhiteCentet1.AddChidren(btnVoicePersent); seekBarVoiceControl.ProgressChangedEvent += (div, value) => { btnVoicePersent.Text = value + "%"; if (div == 1) { } }; //初始化开锁菜单(一键开锁,临时密码开锁) this.InitUnLockMenuControl(); //初始化底部菜单图标 this.InitBottomMenuIconControl(); } /// /// 初始化开锁菜单(一键开锁,临时密码开锁) /// private void InitUnLockMenuControl() { //如果是成员,则只有一键开锁 if (DB_ResidenceData.Instance.CurrentRegion.isOtherShare == true) { //一键开锁 var btnOneKey = new NormalViewControl(100, 25, true); btnOneKey.Y = Application.GetRealHeight(100); btnOneKey.TextSize = CSS_FontSize.HeadlineFontSize; btnOneKey.TextColor = CSS_Color.MainColor; btnOneKey.Text = Language.StringByID(StringId.OneKeyUnlocking); btnOneKey.Width = this.GetTextRealWidth(btnOneKey.Text, CSS_FontSize.HeadlineFontSize, true); btnOneKey.Gravity = Gravity.CenterHorizontal; btnOneKey.IsBold = true; FrameWhiteCentet1.AddChidren(btnOneKey); } else { //一键开锁 var btnOneKey = new NormalViewControl(100, 25, true); btnOneKey.Y = Application.GetRealHeight(100); btnOneKey.TextSize = Language.CurrentLanguage == "Chinese" ? CSS_FontSize.HeadlineFontSize : CSS_FontSize.SubheadingFontSize; btnOneKey.TextColor = CSS_Color.MainColor; btnOneKey.Text = Language.StringByID(StringId.OneKeyUnlocking); btnOneKey.TextAlignment = TextAlignment.CenterRight; btnOneKey.IsBold = true; btnOneKey.Width = this.GetTextRealWidth(btnOneKey.Text, CSS_FontSize.HeadlineFontSize, true); FrameWhiteCentet1.AddChidren(btnOneKey); btnOneKey.X = Application.GetRealWidth(140) - btnOneKey.Width; //临时密码开锁 var btnTempPsw = new NormalViewControl(100, 25, true); btnTempPsw.X = btnOneKey.Right + Application.GetRealWidth(36); btnTempPsw.Y = btnOneKey.Y; btnTempPsw.TextColor = CSS_Color.PromptingColor1; btnTempPsw.Text = Language.StringByID(StringId.TemporaryPasswordUnlocking); btnTempPsw.Width = this.GetTextRealWidth(btnTempPsw.Text, CSS_FontSize.HeadlineFontSize, true); FrameWhiteCentet1.AddChidren(btnTempPsw); btnOneKey.ButtonClickEvent += (sender, e) => { //选择的是同一个,则不处理 if (this.nowSelectMenu == 1) { return; } this.nowSelectMenu = 1; btnOneKey.IsBold = true; btnOneKey.TextSize = Language.CurrentLanguage == "Chinese" ? CSS_FontSize.HeadlineFontSize : CSS_FontSize.SubheadingFontSize; btnOneKey.TextColor = CSS_Color.MainColor; btnTempPsw.IsBold = false; btnTempPsw.TextSize = CSS_FontSize.TextFontSize; btnTempPsw.TextColor = CSS_Color.PromptingColor1; //设置中间容器控件可视化 this.SetMiddleFrameControlVisible(); }; btnTempPsw.ButtonClickEvent += (sender, e) => { //选择的是同一个,则不处理 if (this.nowSelectMenu == 2) { return; } this.nowSelectMenu = 2; btnOneKey.IsBold = false; btnOneKey.TextSize = CSS_FontSize.TextFontSize; btnOneKey.TextColor = CSS_Color.PromptingColor1; btnTempPsw.IsBold = true; btnTempPsw.TextSize = Language.CurrentLanguage == "Chinese" ? CSS_FontSize.HeadlineFontSize : CSS_FontSize.SubheadingFontSize; btnTempPsw.TextColor = CSS_Color.MainColor; //设置中间容器控件可视化 this.SetMiddleFrameControlVisible(); }; } } #endregion #region ■ 初始化第二个索引页(历史记录)_______ /// /// 初始化第二个索引页(历史记录) /// private void InitFrameWhiteContent2() { //添加第二个page this.AddSecondPage(); } /// /// 初始化门锁历史记录以及控件 /// private void InitDoorHistoryLogAndControl() { //已经初始化 if (this.listHistoryLog != null) { return; } this.ShowProgressBar(); HdlThreadLogic.Current.RunThread(() => { //初始化成员列表信息 if (this.InitMemberListInfo() == false) { this.CloseProgressBar(); return; } //获取门锁历史记录 this.listHistoryLog = new DAL.Server.HttpServerRequest().GetDoorHistoryLogs(this.device); this.CloseProgressBar(); if (this.listHistoryLog == null) { return; } HdlThreadLogic.Current.RunMain(() => { //初始化门锁历史记录列表控件 this.InitDoorHistoryLogListControl(this.listHistoryLog); }); }); } /// /// 初始化门锁历史记录列表控件 /// /// 显示的门锁记录 private void InitDoorHistoryLogListControl(List listLog) { //按年分组 var dicData = new Dictionary>(); foreach (var info in listLog) { var year = info.Time.Year; if (dicData.ContainsKey(year) == false) { dicData[year] = new List(); } dicData[year].Add(info); } //先清空 base.FrameWhiteCentet2.RemoveAll(); //日志 var btnLog = new NormalViewControl(150, 35, true); btnLog.Y = Application.GetRealHeight(15); btnLog.X = HdlControlResourse.XXLeft; btnLog.TextSize = CSS_FontSize.EmphasisFontSize_FirstLevel; btnLog.TextColor = CSS_Color.FirstLevelTitleColor; btnLog.TextID = StringId.Log; FrameWhiteCentet2.AddChidren(btnLog); //列表容器 var listView = new VerticalFrameControl(); listView.Y = Application.GetRealHeight(72); listView.Height = base.FrameWhiteCentet2.Height - Application.GetRealHeight(72); base.FrameWhiteCentet2.AddChidren(listView); //初始Y轴为0 int yy = 0; foreach (var strYear in dicData.Keys) { //年 var btnYear = new NormalViewControl(100, 24, true); btnYear.X = HdlControlResourse.XXLeft; btnYear.Y = yy; btnYear.TextColor = CSS_Color.FirstLevelTitleColor; btnYear.TextSize = CSS_FontSize.SubheadingFontSize; btnYear.Text = strYear.ToString(); //中文 if (Language.CurrentLanguage == "Chinese") { btnYear.Text += Language.StringByID(StringId.Years); } listView.frameTable.AddChidren(btnYear); //年与消息记录的间距为14 yy = btnYear.Bottom + Application.GetRealHeight(14); foreach (var logInfo in dicData[strYear]) { //消息 var btnMsg = new NormalViewControl(295, 20, true); btnMsg.Y = yy; btnMsg.Gravity = Gravity.CenterHorizontal; btnMsg.TextColor = CSS_Color.FirstLevelTitleColor; btnMsg.Text = logInfo.StrMsg; listView.frameTable.AddChidren(btnMsg); //时间 var btnTime = new NormalViewControl(200, 18, true); btnTime.Y = btnMsg.Bottom + Application.GetRealHeight(2); btnTime.X = btnMsg.X; btnTime.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnTime.TextColor = CSS_Color.PromptingColor1; btnTime.Text = HdlCommonLogic.Current.ConvertDayText(logInfo.Time.Month, logInfo.Time.Day) + " " + logInfo.Time.ToString("HH:mm"); listView.frameTable.AddChidren(btnTime); //线 var btnLine = new NormalViewControl(btnMsg.Width, HdlControlResourse.BottomLineHeight, false); btnLine.Y = btnTime.Bottom + Application.GetRealHeight(11); btnLine.Gravity = Gravity.CenterHorizontal; btnLine.BackgroundColor = CSS_Color.DividingLineColor; listView.frameTable.AddChidren(btnLine); //两条消息的间距为10 yy = btnLine.Bottom + Application.GetRealHeight(10); } //年与年之间的间距为24 yy += Application.GetRealHeight(24); } //调整桌布高度 listView.AdjustTableHeight(); } #endregion #region ■ 初始化底部菜单图标_________________ /// /// 初始化底部菜单图标 /// private void InitBottomMenuIconControl() { //如果是成员,则只有开锁方式管理 if (DB_ResidenceData.Instance.CurrentRegion.isOtherShare == true) { //开锁方式管理图标 var btnManagerIcon = new IconViewControl(40); btnManagerIcon.Gravity = Gravity.CenterHorizontal; btnManagerIcon.Y = Application.GetRealHeight(466); btnManagerIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UnLockManager.png"; this.FrameWhiteCentet1.AddChidren(btnManagerIcon); btnManagerIcon.ButtonClickEvent += (sender, e) => { //初始化成员列表信息 if (this.InitMemberListInfo() == false) { return; } var form = new DoorLockUnlockMethordManagerPage(); form.AddForm(this.device, this.listMember); }; } else { //开锁方式管理图标 var btnManagerIcon = new IconViewControl(40); btnManagerIcon.Y = Application.GetRealHeight(466); btnManagerIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UnLockManager.png"; this.FrameWhiteCentet1.AddChidren(btnManagerIcon); btnManagerIcon.X = (this.FrameWhiteCentet1.Width - btnManagerIcon.Width * 2 - Application.GetRealWidth(40)) / 2; btnManagerIcon.ButtonClickEvent += (sender, e) => { //初始化成员列表信息 if (this.InitMemberListInfo() == false) { return; } var form = new DoorLockUnlockMethordManagerPage(); form.AddForm(this.device, this.listMember); }; //常开模式图标 this.btnNormallyOpenIcon = new IconViewControl(40); btnNormallyOpenIcon.X = btnManagerIcon.Right + Application.GetRealWidth(40); btnNormallyOpenIcon.Y = btnManagerIcon.Y; btnNormallyOpenIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/NormallyOpenIcon2.png"; this.FrameWhiteCentet1.AddChidren(btnNormallyOpenIcon); btnNormallyOpenIcon.ButtonClickEvent += (sender, e) => { var form = new DoorLockAlwaysOnListPage(); form.AddForm(this.device); }; } } #endregion #region ■ 初始化临时密码控件_________________ /// /// 初始化临时密码控件 /// private void InitTempPasswordControl() { this.frameTempPsw.RemoveAll(); //生成临时密码的背景图片 var picBack = new PicViewControl(258, 165); picBack.Gravity = Gravity.CenterHorizontal; picBack.UnSelectedImagePath = "FunctionIcon/DoorLock/CrearPswBackgroud.png"; this.frameTempPsw.AddChidren(picBack); //密码显示控件 var btnPassword = new NormalViewControl(150, 50, true); btnPassword.Gravity = Gravity.CenterHorizontal; btnPassword.TextSize = CSS_FontSize.SubheadingFontSize; btnPassword.TextColor = CSS_Color.MainBackgroundColor; btnPassword.TextAlignment = TextAlignment.Center; this.frameTempPsw.AddChidren(btnPassword); //如果没有临时密码 if (this.doorLockData.TempPassword == string.Empty) { //当没有临时密码时,这个背景放在中间 picBack.Y = Application.GetRealHeight(47); //因为图片的压缩问题,这个Y轴和蓝湖的不一样,蓝湖是99 btnPassword.Y = Application.GetRealHeight(88); //生成临时密码 btnPassword.TextID = StringId.CreatTemporaryPassword; btnPassword.ButtonClickEvent += (sender, e) => { //显示生成临时密码的弹窗界面 this.ShowCreatTemporaryPasswordDialog(DateTime.Now, DateTime.Now.AddDays(1).AddMinutes(-1)); }; } //拥有临时密码 else { //显示临时密码 btnPassword.Text = this.doorLockData.TempPassword; //因为图片的压缩问题,这个Y轴和蓝湖的不一样,蓝湖是51 btnPassword.Y = Application.GetRealHeight(40); //删除临时密码图标 var btnDelete = new IconViewControl(28); btnDelete.UnSelectedImagePath = "FunctionIcon/DoorLock/Delete.png"; btnDelete.X = Application.GetRealWidth(19); btnDelete.Y = Application.GetRealHeight(115); this.frameTempPsw.AddChidren(btnDelete); btnDelete.ButtonClickEvent += (sender, e) => { //清除当前临时密码? HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.ClearTempPsswordMsg), () => { //清空临时密码 this.doorLockData.TempPassword = string.Empty; this.doorLockData.StatrtTime = string.Empty; this.doorLockData.EndTime = string.Empty; //重新初始化临时密码控件 this.InitTempPasswordControl(); }); }; //复制临时密码图标 var btnCopy = new IconViewControl(28); btnCopy.UnSelectedImagePath = "FunctionIcon/DoorLock/Shard.png"; btnCopy.X = this.frameTempPsw.Width - btnCopy.IconSize - btnDelete.X; btnCopy.Y = btnDelete.Y; this.frameTempPsw.AddChidren(btnCopy); btnCopy.ButtonClickEvent += (sender, e) => { //临时密码已经复制 HdlCommonLogic.Current.SetTextToShearPlate(this.doorLockData.TempPassword, Language.StringByID(StringId.TempPsswordHasBeenCopy)); }; //生效时间 var frameEffective = this.CreatEffectiveTimeControl(this.frameTempPsw, Language.StringByID(StringId.EffectiveTime), this.doorLockData.StatrtTime); frameEffective.X = Application.GetRealWidth(24); frameEffective.Y = Application.GetRealHeight(180); //失效时间 var frameFailure = this.CreatEffectiveTimeControl(this.frameTempPsw, Language.StringByID(StringId.FailureTime), this.doorLockData.EndTime); frameFailure.X = this.frameTempPsw.Width - frameFailure.Width - frameEffective.X; frameFailure.Y = frameEffective.Y; //- var btnLine = new NormalViewControl(frameFailure.X - frameEffective.Right, frameFailure.Height, false); btnLine.X = frameEffective.Right; btnLine.Y = frameEffective.Y; btnLine.Text = "-"; btnLine.TextAlignment = TextAlignment.Center; btnLine.TextColor = CSS_Color.FirstLevelTitleColor; btnLine.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; this.frameTempPsw.AddChidren(btnLine); } } /// /// 生成生效/失效时间控件 /// /// 父控件 /// 显示的文本 /// 显示的时间 /// private FrameLayout CreatEffectiveTimeControl(FrameLayout frameTempPsw, string i_text, string i_time) { //线框背景控件 var frameBack = new FrameLayout(); frameBack.Width = Application.GetRealWidth(120); frameBack.Height = Application.GetRealHeight(50); frameBack.Radius = (uint)Application.GetRealWidth(7); frameBack.BorderWidth = 1; frameBack.BorderColor = CSS_Color.PromptingColor1; frameTempPsw.AddChidren(frameBack); //显示文本 var btnText = new NormalViewControl(frameBack.Width, Application.GetRealHeight(18), false); btnText.Y = Application.GetRealHeight(8); btnText.TextColor = CSS_Color.FirstLevelTitleColor; btnText.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnText.Text = i_text; btnText.TextAlignment = TextAlignment.Center; frameBack.AddChidren(btnText); //显示时间 var btnTime = new NormalViewControl(frameBack.Width, Application.GetRealHeight(18), false); btnTime.Y = btnText.Bottom; btnTime.TextColor = CSS_Color.FirstLevelTitleColor; btnTime.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnTime.Text = i_time; btnTime.TextAlignment = TextAlignment.Center; frameBack.AddChidren(btnTime); return frameBack; } #endregion #region ■ 生成临时密码_______________________ /// /// 显示生成临时密码的弹窗界面 /// private void ShowCreatTemporaryPasswordDialog(DateTime startTime, DateTime endTime) { //默认时间Form-To为一天 var contr = new BottomItemEditorControl(2, string.Empty); //点击确认时,不关闭界面 contr.CloseByConfirm = false; //生效时间 var effectiveTime = Language.StringByID(StringId.EffectiveTime); contr.AddRowMenu(effectiveTime, startTime.ToString("yyyy.MM.dd HH:mm"), (btnView, btnValue) => { //关掉界面,然后重新调起来 contr.Close(); var form = new DoorLockSelectTimePage(); form.AddForm(startTime); form.SelectFinshEvent += (selectTime) => { //重新调起界面 this.ShowCreatTemporaryPasswordDialog(selectTime, endTime); }; }); //失效时间 var failTime = Language.StringByID(StringId.FailureTime); contr.AddRowMenu(failTime, endTime.ToString("yyyy.MM.dd HH:mm"), (btnView, btnValue) => { //关掉界面,然后重新调起来 contr.Close(); var form = new DoorLockSelectTimePage(); form.AddForm(endTime); form.SelectFinshEvent += (selectTime) => { //重新调起界面 this.ShowCreatTemporaryPasswordDialog(startTime, selectTime); }; }); contr.FinishEvent += (div) => { //点击了生成 if (div == 1) { if (this.CheckEffectiveTime(startTime, endTime) == false) { return; } //关掉界面 contr.Close(); //生成临时密码 this.doorLockData.TempPassword = "987654"; this.doorLockData.StatrtTime = startTime.ToString("yyyy.MM.dd HH:mm"); this.doorLockData.EndTime = endTime.ToString("yyyy.MM.dd HH:mm"); //重新初始化临时密码控件 this.InitTempPasswordControl(); } }; //需要初始化之后,按钮才不会为null 变更【生成】按钮的宽度和X轴 contr.btnConfirm.TextID = StringId.Generate; contr.btnConfirm.Width = contr.btnConfirm.GetRealWidthByText(); contr.btnConfirm.X = contr.btnConfirm.Parent.Width - contr.btnConfirm.Width - contr.btnCancel.X; } /// /// 检测生效时间是否正确 /// /// 生效时间 /// 失效时间 /// private bool CheckEffectiveTime(DateTime startTime, DateTime endTime) { if (startTime >= endTime) { //生效时间必须大于失效时间 HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, Language.StringByID(StringId.EffectiveTimeMustBeOverFailureTime)); return false; } return true; } #endregion #region ■ 设备状态反馈_______________________ /// /// 设备状态反馈 /// /// public override void DeviceStatuPush(Function i_LocalDevice) { //不是同一个东西 if (this.device.sid != i_LocalDevice.sid) { return; } //刷新当前设备的状态缓存 this.RefreshNowDeviceStatuMemory(i_LocalDevice); //刷新界面状态 this.RefreshFormStatu(); } #endregion #region ■ 刷新界面状态_______________________ /// /// 刷新界面状态 /// private void RefreshFormStatu() { //如果不在线 if (this.doorLockData.IsOnline == false) { //开锁图片 this.picLockControl.UnSelectedImagePath = "FunctionIcon/DoorLock/LockPictrue2.png"; //连接状态 this.btnOnlineIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/UnConnect.png"; this.btnOnlineView.Text = this.dicText["未连接"]; this.btnOnlineView.TextColor = CSS_Color.AuxiliaryColor2; //常开模式图标 if (this.btnNormallyOpenIcon != null) { this.btnNormallyOpenIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/NormallyOpenIcon2.png"; } } else { //开锁图片 this.picLockControl.UnSelectedImagePath = this.doorLockData.Open == true ? "FunctionIcon/DoorLock/UnLockPictrue3.png" : "FunctionIcon/DoorLock/LockPictrue1.png"; //连接状态 this.btnOnlineIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/Connect.png"; this.btnOnlineView.Text = this.dicText["已连接"]; this.btnOnlineView.TextColor = CSS_Color.PromptingColor1; //常开模式图标 if (this.btnNormallyOpenIcon != null) { this.btnNormallyOpenIcon.UnSelectedImagePath = "FunctionIcon/DoorLock/NormallyOpenIcon1.png"; } } } /// /// 设置中间容器控件可视化 /// private void SetMiddleFrameControlVisible() { //如果选择的是 一键开锁 if (this.nowSelectMenu == 1) { this.picLockControl.Visible = true; this.frameTempPsw.Visible = false; } else { this.picLockControl.Visible = false; this.frameTempPsw.Visible = true; //临时密码已经变更,需要刷新界面 if (this.doorLockData.IsTempPasswordChanged == true) { //初始化临时密码控件 this.InitTempPasswordControl(); this.doorLockData.IsTempPasswordChanged = false; } } } #endregion #region ■ 发送各种命令_______________________ /// /// 发送开关命令 /// private void SendSwitchComand() { //this.btnSwitch.CanClick = false; //string statu = this.btnSwitch.IsSelected == true ? "off" : "on"; //HdlThreadLogic.Current.RunThread(() => //{ // var dic = new Dictionary(); // dic.Add(FunctionAttributeKey.OnOff, statu); // Control.Ins.SendWriteCommand(this.device, dic, true); // HdlThreadLogic.Current.RunMain(() => // { // this.btnSwitch.CanClick = true; // }); //}); } #endregion #region ■ 初始化成员列表信息_________________ /// /// 初始化成员列表信息 /// /// private bool InitMemberListInfo() { //已经初始化 if (this.listMember != null) { return true; } //主账号需要去获取成员列表,而子账号只能他自己 if (DB_ResidenceData.Instance.CurrentRegion.isOtherShare == false) { //获取成员列表 var responePack = new DAL.Server.HttpServerRequest().GetResidenceMemberAccount(); if (responePack.Code == DAL.Server.StateCode.SUCCESS) { this.listMember = Newtonsoft.Json.JsonConvert.DeserializeObject>(responePack.Data.ToString()); } //失败 else { //提示 DAL.Server.IMessageCommon.Current.ShowErrorInfoAlter(responePack.Code); return false; } } else { //先初始化 this.listMember = new List(); } //自身加进去,自己位于首位 var info = new ResidenceMemberInfo(); info.childAccountId = OnAppConfig.Instance.LastLoginUserId; info.childAccountType = DB_ResidenceData.Instance.CurrentRegion.isOtherShare == false ? "ADMIN" : "ORDINARY"; info.nickName = UserInfo.Current.userName; this.listMember.Insert(0, info); if (string.IsNullOrEmpty(info.nickName)) { info.nickName = UserInfo.Current.AccountString; } foreach (var info2 in this.listMember) { //设置用户昵称 if (string.IsNullOrEmpty(info2.nickName)) { info2.nickName = info2.memberName; } } return true; } #endregion #region ■ 一键开锁___________________________ /// /// 一键开锁 /// private void DoOneKeyToUnlockDoor() { if (this.doorLockData.IsOnline == false) { //设备不在线 HdlMessageLogic.Current.ShowMassage(ShowMsgType.TipRemind, Language.StringByID(StringId.DeviceNotOnline), null, null, null, 2); return; } //第一次使用,请先绑定门锁密码 //HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.PleaseBindTheDoorPswFirst), () => //{ // var form = new TextInputDialog(Language.StringByID(StringId.PleaseInputDoorAdminPassword), string.Empty, Language.StringByID(StringId.PleaseInputDoorAdminPassword), null, null, true); // form.Show((password) => // { // //门锁绑定成功 // HdlMessageLogic.Current.ShowMassage(ShowMsgType.ConfirmSuccess, Language.StringByID(StringId.BindDoorLockSuccess), () => // { // }); // }); //}); if (UserInfo.Current.appUnlockPage.Contains("3") == true) { //调起安全认证 HdlCheckLogic.Current.CheckUnlockSecurity(true, (div) => { //锁已打开 if (div == 1) { HdlMessageLogic.Current.ShowMassage(ShowMsgType.TipSuccess, Language.StringByID(StringId.LockIsOpened), null, null, null, 2); } else { //为了安全,请跳转至个人中心{0}设置个人密码,并应用于门锁开锁 HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.JumpToPersonalCentetToSetPasswordMsg), () => { var page = new AppUnlockSettingsPage(); MainPage.BasePageView.AddChidren(page); page.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }, Language.StringByID(StringId.Jump)); } }); } else { //为了安全,请跳转至个人中心{0}设置个人密码,并应用于门锁开锁 HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.JumpToPersonalCentetToSetPasswordMsg), () => { var page = new AppUnlockSettingsPage(); MainPage.BasePageView.AddChidren(page); page.LoadPage(); MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1; }, Language.StringByID(StringId.Jump)); } } #endregion #region ■ 一般方法___________________________ /// /// 刷新当前设备的状态缓存 /// private void RefreshNowDeviceStatuMemory(Function i_LocalDevice) { this.doorLockData.IsOnline = i_LocalDevice.online; for (int i = 0; i < i_LocalDevice.attributes.Count; i++) { var data = i_LocalDevice.attributes[i]; //门锁状态 if (data.key == "status") { if (data.state == "open") { this.doorLockData.Open = true; } else if (data.state == "normal_open") { //常开模式 this.doorLockData.Open = true; this.doorLockData.NormalOpen = true; } else { this.doorLockData.Open = false; this.doorLockData.NormalOpen = false; } } //音量 else if (data.key == "volume") { var value = data.state; if (value != string.Empty) { this.doorLockData.Voice = Convert.ToInt32(value); } } //电池百分比 else if (data.key == "battery_percentage") { var value = data.state; if (value != string.Empty) { this.doorLockData.BatteryPersent = Convert.ToInt32(value); } } } } #endregion #region ■ 结构体_____________________________ /// /// 门锁的数据 /// private class DoorLockData { /// /// 是否打开 /// public bool Open = true; /// /// 电池电量 /// public int BatteryPersent = 0; /// /// 是否在线 /// public bool IsOnline = false; /// /// 是否静音 /// public bool Mute = false; /// /// 音量 /// public int Voice = 0; /// /// 是否处于常开模式 /// public bool NormalOpen = false; /// /// 临时密码 /// public string TempPassword = string.Empty; /// /// 临时密码是否被变更 /// public bool IsTempPasswordChanged = true; /// /// 临时密码生效时间(2020.03.17 13:27) /// public string StatrtTime = string.Empty; /// /// 临时密码失效时间(2020.03.17 13:27) /// public string EndTime = string.Empty; } #endregion } }