using System; using System.Collections.Generic; namespace Shared.SimpleControl.Phone { public class UserDeviceToDoorLock : FrameLayout { VerticalScrolViewLayout bodyScrolView; VerticalScrolViewLayout equipmentListScrolView; /// ///构造函数 /// public UserDeviceToDoorLock () { BackgroundColor = SkinStyle.Current.MainColor; } public override void RemoveFromParent () { base.RemoveFromParent (); } /// /// 添加的所有门锁列表 /// public void ShowAllRoomDoorLock (List doorLockList) { #region 标题 var topView = new FrameLayout () { Y = Application.GetRealHeight (36), Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.MainColor, }; AddChidren (topView); var title = new Button () { TextAlignment = TextAlignment.Center, Text = Language.StringByID (R.MyInternationalizationString.DoorLock), TextSize = 19, TextColor = SkinStyle.Current.TextColor1 }; topView.AddChidren (title); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, }; topView.AddChidren (logo); var back = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (85), UnSelectedImagePath = "Item/Back.png", SelectedImagePath = "Item/BackSelected.png", Gravity = Gravity.CenterVertical, }; topView.AddChidren (back); back.MouseUpEventHandler += (sender, e) => { this.RemoveFromParent (); }; #endregion FrameLayout powerView = new FrameLayout () { Height = Application.GetRealHeight (110), BackgroundColor = SkinStyle.Current.TitileView, Y = topView.Bottom }; AddChidren (powerView); Button showAllDoorLock = new Button () { Height = Application.GetRealHeight (108), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, TextID = R.MyInternationalizationString.DoorLockList, X = Application.GetRealHeight (20), }; powerView.AddChidren (showAllDoorLock); #region bodyScrolView bodyScrolView = new VerticalScrolViewLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (Application.DesignHeight - 126 - 110), Y = powerView.Bottom, BackgroundColor = SkinStyle.Current.ViewColor }; AddChidren (bodyScrolView); equipmentListScrolView = new VerticalScrolViewLayout () { Height = bodyScrolView.Height - Application.GetRealHeight (110), }; bodyScrolView.AddChidren (equipmentListScrolView); equipmentListScrolView.RemoveAll (); foreach (var doorLockFile in doorLockList) { if (doorLockFile.Split ('_') [1] == DeviceType.DoorLock.ToString ()) { DoorLock doorLock = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (doorLockFile))); ShowDoorLockView (doorLock); } else { LightDoorLock mLightDoorLock = Newtonsoft.Json.JsonConvert.DeserializeObject (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (doorLockFile))); ShowLightDoorLockView (mLightDoorLock); } } #endregion } private void ShowDoorLockView (DoorLock doorLock) { FrameLayout doorLockView = new FrameLayout () { Height = Application.GetRealHeight (110), Tag = doorLock.ToString () + doorLock.DeviceID.ToString () + doorLock.PhysicsLoopID.ToString () }; equipmentListScrolView.AddChidren (doorLockView); var btnPoint = new Button () { Width = Application.GetRealWidth (10), Height = Application.GetRealHeight (10), X = Application.GetRealWidth (40), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Point.png", SelectedImagePath = "Item/Point.png", }; doorLockView.AddChidren (btnPoint); var tempDeviceName = new Button () { Width = Application.GetRealWidth (340), X = btnPoint.Right + Application.GetRealWidth (20), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, Text = doorLock.Name, Tag = doorLock, }; doorLockView.AddChidren (tempDeviceName); var editor = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (70), UnSelectedImagePath = "Item/Editor.png", SelectedImagePath = "Item/EditorSelected.png", Gravity = Gravity.CenterVertical, X = tempDeviceName.Right + Application.GetRealHeight (20), }; doorLockView.AddChidren (editor); editor.MouseUpEventHandler += (sender, e) => { Dialog dialog = new Dialog (); var dialogBodyView = new FrameLayout () { Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (300), BackgroundColor = SkinStyle.Current.DialogColor, //BackgroundColor = 0xff000000, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, Gravity = Gravity.Center }; dialog.AddChidren (dialogBodyView); var btnTitle = new Button () { Height = Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.DialogTitle, TextAlignment = TextAlignment.Center, TextID = R.MyInternationalizationString.ChangeInformation }; dialogBodyView.AddChidren (btnTitle); var textButton = new EditText () { X = Application.GetRealWidth (30), Y = btnTitle.Bottom + Application.GetRealHeight (25), Height = Application.GetRealHeight (80), Width = Application.GetRealWidth (340), Text = tempDeviceName.Text, Gravity = Gravity.CenterVertical, TextAlignment = TextAlignment.Center, Tag = doorLock, TextColor = SkinStyle.Current.TextColor, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, }; dialogBodyView.AddChidren (textButton); var bottomView = new FrameLayout () { Y = dialogBodyView.Height - Application.GetRealHeight (80), Height = Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.DialogTitle, }; dialogBodyView.AddChidren (bottomView); var btnBack = new Button () { Width = Application.GetRealWidth (119), UnSelectedImagePath = "Item/PositioningDialogBack.png", SelectedImagePath = "Item/PositioningDialogBack.png", }; bottomView.AddChidren (btnBack); btnBack.MouseUpEventHandler += (sender1, e1) => { dialog.Close (); }; var btnLineH = new Button () { Width = 1, Height = LayoutParams.MatchParent, BackgroundColor = SkinStyle.Current.White20Transparent, X = btnBack.Right, }; bottomView.AddChidren (btnLineH); Button btnSave = new Button () { Width = Application.GetRealWidth (280), X = btnLineH.Right, TextID = R.MyInternationalizationString.SAVE, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.DialogTextColor, }; bottomView.AddChidren (btnSave); btnSave.MouseUpEventHandler += (sender1, e1) => { tempDeviceName.Text = textButton.Text.Trim (); doorLock.Name = textButton.Text.Trim (); if (doorLock.isDoorLockConverter) { byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (doorLock.Name); System.Threading.Tasks.Task.Run (() => { byte [] updateBytes = null; var bigClass = doorLock.BigClass; var minClass = doorLock.MinClass; if (doorLock.isDoorLockConverter) { bigClass = 0x0E; minClass = 4; } updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, doorLock.SubnetID, doorLock.DeviceID, new byte [] { bigClass, minClass, doorLock.LoopID }); if (updateBytes == null) { return; } byte [] uBytes = new byte [20]; Array.Copy (remakeBytes, 0, uBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20); Array.Copy (uBytes, 0, updateBytes, 3, 20 < uBytes.Length ? 20 : uBytes.Length); byte [] reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, doorLock.SubnetID, doorLock.DeviceID, updateBytes); if (reBytes != null) { IO.FileUtils.SaveEquipmentMessage (doorLock, doorLock.LoopID.ToString ()); } }); } else { CommonPage.UpdateRemark (doorLock.SubnetID, doorLock.DeviceID, textButton.Text.Trim ()); IO.FileUtils.SaveEquipmentMessage (doorLock); } dialog.Close (); }; dialog.Show (); }; var btnRight = new Button () { Width = Application.GetRealWidth (28), Height = Application.GetRealHeight (40), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Right.png", SelectedImagePath = "Item/RightSelected.png", X = Application.GetRealWidth (580), }; doorLockView.AddChidren (btnRight); EventHandler openDoorLockControlPageEvent = (button, mouseEventArgs) => { UserDoorLock toDoorLockView = new UserDoorLock (); UserMiddle.DevicePageView.AddChidren (toDoorLockView); toDoorLockView.ShowDoorLockRoom (doorLock); UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1; }; doorLockView.MouseUpEventHandler += openDoorLockControlPageEvent; tempDeviceName.MouseUpEventHandler += openDoorLockControlPageEvent; btnRight.MouseUpEventHandler += openDoorLockControlPageEvent; Button btnRowNull = new Button () { Y = Application.GetRealHeight (107), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.TitileView }; doorLockView.AddChidren (btnRowNull); } private void ShowLightDoorLockView (LightDoorLock doorLock) { FrameLayout doorLockView = new FrameLayout () { Height = Application.GetRealHeight (110), Tag = doorLock.ToString () + doorLock.DeviceID.ToString () + doorLock.LoopID.ToString () }; equipmentListScrolView.AddChidren (doorLockView); var btnPoint = new Button () { Width = Application.GetRealWidth (10), Height = Application.GetRealHeight (10), X = Application.GetRealWidth (40), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Point.png", SelectedImagePath = "Item/Point.png", }; doorLockView.AddChidren (btnPoint); var tempDeviceName = new Button () { Width = Application.GetRealWidth (340), X = btnPoint.Right + Application.GetRealWidth (20), TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor1, Text = doorLock.Name, Tag = doorLock, }; doorLockView.AddChidren (tempDeviceName); var editor = new Button () { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (70), UnSelectedImagePath = "Item/Editor.png", SelectedImagePath = "Item/EditorSelected.png", Gravity = Gravity.CenterVertical, X = tempDeviceName.Right + Application.GetRealHeight (20), }; doorLockView.AddChidren (editor); editor.MouseUpEventHandler += (sender, e) => { Dialog dialog = new Dialog (); var dialogBodyView = new FrameLayout () { Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (300), BackgroundColor = SkinStyle.Current.DialogColor, //BackgroundColor = 0xff000000, Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, Gravity = Gravity.Center }; dialog.AddChidren (dialogBodyView); var btnTitle = new Button () { Height = Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.DialogTitle, TextAlignment = TextAlignment.Center, TextID = R.MyInternationalizationString.ChangeInformation }; dialogBodyView.AddChidren (btnTitle); var textButton = new EditText () { X = Application.GetRealWidth (30), Y = btnTitle.Bottom + Application.GetRealHeight (25), Height = Application.GetRealHeight (80), Width = Application.GetRealWidth (340), Text = tempDeviceName.Text, Gravity = Gravity.CenterVertical, TextAlignment = TextAlignment.Center, Tag = doorLock, TextColor = SkinStyle.Current.TextColor, BorderWidth = 1, Radius = 5, BorderColor = SkinStyle.Current.BorderColor, }; dialogBodyView.AddChidren (textButton); var bottomView = new FrameLayout () { Y = dialogBodyView.Height - Application.GetRealHeight (80), Height = Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.DialogTitle, }; dialogBodyView.AddChidren (bottomView); var btnBack = new Button () { Width = Application.GetRealWidth (119), UnSelectedImagePath = "Item/PositioningDialogBack.png", SelectedImagePath = "Item/PositioningDialogBack.png", }; bottomView.AddChidren (btnBack); btnBack.MouseUpEventHandler += (sender1, e1) => { dialog.Close (); }; var btnLineH = new Button () { Width = 1, Height = LayoutParams.MatchParent, BackgroundColor = SkinStyle.Current.White20Transparent, X = btnBack.Right, }; bottomView.AddChidren (btnLineH); Button btnSave = new Button () { Width = Application.GetRealWidth (280), X = btnLineH.Right, TextID = R.MyInternationalizationString.SAVE, TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.DialogTextColor, }; bottomView.AddChidren (btnSave); btnSave.MouseUpEventHandler += (sender1, e1) => { tempDeviceName.Text = textButton.Text.Trim (); doorLock.Name = textButton.Text.Trim (); CommonPage.UpdateRemark (doorLock.SubnetID, doorLock.DeviceID, textButton.Text.Trim ()); IO.FileUtils.SaveEquipmentMessage (doorLock); dialog.Close (); }; dialog.Show (); }; var btnRight = new Button () { Width = Application.GetRealWidth (28), Height = Application.GetRealHeight (40), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Item/Right.png", SelectedImagePath = "Item/RightSelected.png", X = Application.GetRealWidth (580), }; doorLockView.AddChidren (btnRight); EventHandler openDoorLockControlPageEvent = (button, mouseEventArgs) => { DoorLockRelayPage mDoorLockRelayPage = new DoorLockRelayPage(doorLock); UserMiddle.DevicePageView.AddChidren (mDoorLockRelayPage); mDoorLockRelayPage.showmLightDoorLocksRoom(); UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1; }; doorLockView.MouseUpEventHandler += openDoorLockControlPageEvent; tempDeviceName.MouseUpEventHandler += openDoorLockControlPageEvent; btnRight.MouseUpEventHandler += openDoorLockControlPageEvent; Button btnRowNull = new Button () { Y = Application.GetRealHeight (107), Height = Application.GetRealHeight (3), BackgroundColor = SkinStyle.Current.TitileView }; doorLockView.AddChidren (btnRowNull); } } }