using System; using System.Collections.Generic; //using Android.Media; namespace Shared.SimpleControl.Phone { public class PasswordList : FrameLayout { DoorLock doorLock; PageLayout bodyView; int pageIndex = 0;//感应卡页码 public PasswordList (DoorLock door_lock) { this.doorLock = door_lock; BackgroundColor = SkinStyle.Current.MainColor; } /// /// 读门锁密码信息 /// void readStatus () { new System.Threading.Thread (() => { Application.RunOnMainThread (() => { MainPage.Loading.Start (Language.StringByID (R.MyInternationalizationString.load)); }); try { int passwordCount = 10; if (doorLock.isDoorLockConverter) { passwordCount = 10* pageIndex + 10; } for (int i = 1; i <= passwordCount; i++) { if (doorLock.passwordList.Count < i) { doorLock.passwordList.Add (new DoorLockPasswrodInfo () { passwordRemark = "", passwordImage = "DoorLockPic/door_lock_ headshot.png" }); } } for (int i = 0, lostLink = 0; i < passwordCount; i++) { byte [] passwordInfoBytes = Control.ControlBytesSendHasReturn (Command.ReadDoorLockUseRemark, doorLock.SubnetID, doorLock.DeviceID, new byte [] { doorLock.PhysicsLoopID, 0x02, (byte)i }); if (passwordInfoBytes == null) { lostLink++; } else { lostLink = 0; doorLock.passwordList [i].passwordRemark = CommonPage.MyEncodingGB2312.GetString (passwordInfoBytes, 3, 20); if (doorLock.passwordList [i].passwordRemark == "ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ") { doorLock.passwordList [i].passwordRemark = Language.StringByID (R.MyInternationalizationString.AddPasswordUser); } doorLock.passwordList [i].userPasswordID = (int)(passwordInfoBytes [2]); } if (2 <= lostLink) { break; } } Application.RunOnMainThread (() => { showPage (); }); } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }) { IsBackground = true }.Start (); } public void ShowUserPasswordPrint () { #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, TextID = R.MyInternationalizationString.PasswordList, TextColor = SkinStyle.Current.TextColor1, TextSize = 19, }; topView.AddChidren (title); var logo = new Button () { Width = Application.GetRealWidth (154), Height = Application.GetRealHeight (90), X = Application.GetRealWidth (486), UnSelectedImagePath = MainPage.LogoString, Gravity = Gravity.CenterVertical, }; 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 bodyView = new PageLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (Application.DesignHeight - 126 - 100), BackgroundColor = SkinStyle.Current.ViewColor, Y = topView.Bottom, }; AddChidren (bodyView); int count = 10; if (doorLock.Type == DeviceType.DoorLockConverter) { count = 6; } for (int i = 0; i < count; i++) { bodyView.AddChidren (new VerticalScrolViewLayout () { Height = Application.GetRealHeight (Application.DesignHeight - 126 - 100), BackgroundColor = SkinStyle.Current.ViewColor, }); } bodyView.PageChange += (s, i) => { pageIndex = i; if (this.doorLock.proximityCarList.Count < (pageIndex * 10 + 9)) { readStatus (); } else { showPage (); } }; if (this.doorLock.proximityCarList.Count == 0 || this.doorLock.proximityCarList.Count < 10) { readStatus (); } else { showPage (); } #region bottomFrameLayout var bottomFrameLayout = new FrameLayout () { Height = Application.GetRealHeight (107), Y = Application.GetRealHeight (Application.DesignHeight - 107), }; AddChidren (bottomFrameLayout); var bottomLine = new Button () { Height = Application.GetRealHeight (1), BackgroundColor = SkinStyle.Current.TitileView, }; bottomFrameLayout.AddChidren (bottomLine); var refreshPasswordListBtn = new Button () { Y = bottomLine.Bottom, Height = Application.GetRealHeight (106), TextID = R.MyInternationalizationString.ReFresh, TextSize = 15, BackgroundColor = SkinStyle.Current.MainColor, TextColor = SkinStyle.Current.TextColor1, }; bottomFrameLayout.AddChidren (refreshPasswordListBtn); refreshPasswordListBtn.MouseUpEventHandler += (sender, e) => { readStatus (); ShowUserPasswordPrint (); }; #endregion } void showPage () { var pageFrameLayout = bodyView.GetChildren (pageIndex) as VerticalScrolViewLayout; pageFrameLayout.RemoveAll (); int count = 10; if (doorLock.Type == DeviceType.DoorLockConverter) { count = 6; } for (int index = 0; index < count; index++) { #region test FrameLayout passwrodRowView = new FrameLayout () { Height = Application.GetRealHeight (90), }; pageFrameLayout.AddChidren (passwrodRowView); var btnRemarkID = new Button () { Width = Application.GetRealWidth (70), Height = LayoutParams.MatchParent, Text = doorLock.passwordList [pageIndex * 10 + index].userPasswordID.ToString (), TextAlignment = TextAlignment.Center, TextColor = SkinStyle.Current.TextColor1, X = Application.GetRealWidth (12), }; passwrodRowView.AddChidren (btnRemarkID); var btnHeadshot = new Button () { X = btnRemarkID.Right, Gravity = Gravity.CenterVertical, //Width = Application.GetRealWidth (56), //Height = Application.GetRealHeight (57), Width = Application.GetRealWidth (0), Height = Application.GetRealHeight (0), UnSelectedImagePath = doorLock.passwordList [index].passwordImage, }; passwrodRowView.AddChidren (btnHeadshot); var btnRemarkName = new Button () { Width = Application.GetRealWidth (342), Height = LayoutParams.MatchParent, TextAlignment = TextAlignment.CenterLeft, X = btnHeadshot.Right + Application.GetRealWidth (15), Text = doorLock.passwordList [index].passwordRemark, TextColor = SkinStyle.Current.TextColor1, }; passwrodRowView.AddChidren (btnRemarkName); var btnEdit = new Button () { X = Application.GetRealWidth (460), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth (80), Height = Application.GetRealHeight (80), UnSelectedImagePath = "Item/Editor.png", SelectedImagePath = "Item/EditorSelected.png", }; passwrodRowView.AddChidren (btnEdit); int indexOfClick = index; btnEdit.MouseUpEventHandler += (sender, e) => { showDialog (btnRemarkName, btnHeadshot, (byte)indexOfClick); }; //var btnScence = new Button () { // X = btnEdit.Right + Application.GetRealWidth (15), // Gravity = Gravity.CenterVertical, // Width = Application.GetRealWidth (56), // Height = Application.GetRealHeight (57), // UnSelectedImagePath = "Scene/Scene.png", //}; Button btnScence = new Button () { X = btnEdit.Right, Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth (120), Height = Application.GetRealHeight (100), UnSelectedImagePath = "DoorLockPic/door_lock_unedit_scene.png", SelectedImagePath = "DoorLockPic/door_lock_edit_scene_on.png", }; passwrodRowView.AddChidren (btnScence); // bool HaveSceneTargets; //doorLock.IsOpenAlarmNotice.TryGetValue (doorLock.passwordList [indexOfClick].userPasswordID.ToString (), out HaveSceneTargets); //if (HaveSceneTargets == true) { // btnScence.IsSelected = true; //} else { // btnScence.IsSelected = false; //} bool HaveSceneTargets = false; doorLock.HaveSceneTargets.TryGetValue ("001_" + 0x02.ToString ("000") + "_" + doorLock.passwordList [indexOfClick].userPasswordID.ToString ("000"), out HaveSceneTargets); string saveSceneFilePath = null; doorLock.DictionaryList.TryGetValue ("001_" + 0x02.ToString ("000") + "_" + doorLock.passwordList [indexOfClick].userPasswordID.ToString ("000"), out saveSceneFilePath); var scene = Scene.GetSceneByFilePath (saveSceneFilePath); if (scene == null) { btnScence.IsSelected = false; } else { if (HaveSceneTargets == true) { btnScence.IsSelected = true; } else { btnScence.IsSelected = false; } } btnScence.MouseUpEventHandler += (sender, e) => { doorLock.doorLockSceneTargetsUserID = doorLock.passwordList [indexOfClick].userPasswordID; doorLock.doorLockSceneRemark = doorLock.passwordList [indexOfClick].passwordRemark;//开锁场景类型 doorLock.doorLockSceneTargetsMethod = 0x02; IO.FileUtils.SaveEquipmentMessage (doorLock, doorLock.LoopID.ToString ()); DoorLockScene recordView = new DoorLockScene (doorLock); UserMiddle.DevicePageView.AddChidren (recordView); recordView.DoorLockSceneShow (); UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1; this.RemoveFromParent (); }; Button btnRowLineNull = new Button () { Y = Application.GetRealHeight (90) - 1, Height = 1, BackgroundColor = SkinStyle.Current.TitileView }; #endregion if (index < 9) passwrodRowView.AddChidren (btnRowLineNull); } } void showDialog (Button btnRemarkName, Button btnHeadshot, byte indexOfClick) { #region Dialog var dialog = new Dialog (); FrameLayout dialogBodyView = new FrameLayout () { BackgroundColor = SkinStyle.Current.DialogColor, Width = Application.GetRealWidth (520), Height = Application.GetRealHeight (350), Radius = 5, BorderColor = SkinStyle.Current.Transparent, BorderWidth = 0, Gravity = Gravity.Center }; dialog.AddChidren (dialogBodyView); var btnEquipmentTitle = new Button () { Width = Application.GetRealWidth (520), Height = Application.GetRealHeight (80), BackgroundColor = SkinStyle.Current.DialogTitle, TextID = R.MyInternationalizationString.ChangeInformation, TextAlignment = TextAlignment.Center, Gravity = Gravity.CenterHorizontal, TextColor = SkinStyle.Current.DialogTextColor }; dialogBodyView.AddChidren (btnEquipmentTitle); var lblTitleName = new Button () { Gravity = Gravity.CenterHorizontal, Y = Application.GetRealHeight (80), Width = Application.GetRealWidth (450), Height = Application.GetRealHeight (60), TextID = R.MyInternationalizationString.Remark, TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor, }; dialogBodyView.AddChidren (lblTitleName); EditText etRemarkBox = new EditText () { Gravity = Gravity.CenterHorizontal, Y = lblTitleName.Bottom + Application.GetRealHeight (10), Width = Application.GetRealWidth (450), Height = Application.GetRealHeight (60), TextAlignment = TextAlignment.CenterLeft, Radius = 2, BorderWidth = 1, BorderColor = SkinStyle.Current.ButtonColor, TextColor = SkinStyle.Current.TextColor, Text = btnRemarkName.Text.Trim (), }; dialogBodyView.AddChidren (etRemarkBox); //Button lblIcon = new Button () { // Gravity = Gravity.CenterHorizontal, // Y = etRemarkBox.Bottom + Application.GetRealHeight (10), // Width = Application.GetRealWidth (450), // Height = btnEquipmentTitle.Height, // TextID = R.MyInternationalizationString.Headshot, // TextAlignment = TextAlignment.CenterLeft, // TextColor = SkinStyle.Current.TextColor, //}; //dialogBodyView.AddChidren (lblIcon); //VerticalScrolViewLayout verIconLayout = new VerticalScrolViewLayout () { // Gravity = Gravity.CenterHorizontal, // Y = lblIcon.Bottom + Application.GetRealHeight (5), // Width = Application.GetRealWidth (450), // Height = Application.GetRealHeight (200), // BackgroundColor = SkinStyle.Current.ViewColor, // ScrollEnabled = false //}; // dialogBodyView.AddChidren (verIconLayout); //FrameLayout inVerFramelayout = new FrameLayout () { // Width = lblIcon.Width, // Height = Application.GetRealHeight (200), //}; //verIconLayout.AddChidren (inVerFramelayout); //var btnBG = new Button () { // Width = Application.GetRealWidth (270), // Height = LayoutParams.MatchParent, // UnSelectedImagePath = btnHeadshot.UnSelectedImagePath, //}; //inVerFramelayout.AddChidren (btnBG); //Button btnTakePictrue = new Button () { // Width = inVerFramelayout.Width - btnBG.Width, // Height = inVerFramelayout.Height / 2, // TextID = R.MyInternationalizationString.TakePhoto, // TextColor = SkinStyle.Current.TextColor1, // BackgroundColor = SkinStyle.Current.ButtonColor, // X = btnBG.Right, //}; //inVerFramelayout.AddChidren (btnTakePictrue); //btnTakePictrue.MouseUpEventHandler += (sender1, e1) => { // Camera.TakePicture ((obj) => { // if (obj == null) { // return; // } // btnBG.UnSelectedImagePath = obj; // }, DateTime.Now.Ticks.ToString ()); //}; //var btnLineP = new Button () { // Width = btnTakePictrue.Width, // Height = 1, // BackgroundColor = SkinStyle.Current.White20Transparent, // X = btnBG.Right, // Y = btnTakePictrue.Bottom, //}; //inVerFramelayout.AddChidren (btnLineP); //var btnSelectPictrue = new Button () { // Width = btnTakePictrue.Width, // Height = btnTakePictrue.Height, // TextID = R.MyInternationalizationString.SelectPicture, // TextColor = SkinStyle.Current.TextColor1, // BackgroundColor = SkinStyle.Current.ButtonColor, // X = btnBG.Right, // Y = btnLineP.Bottom, //}; //inVerFramelayout.AddChidren (btnSelectPictrue); //btnSelectPictrue.MouseUpEventHandler += (sender1, e1) => { // Camera.SelectPicture ((obj) => { // if (obj == null) { // return; // } // btnBG.UnSelectedImagePath = obj; // }, DateTime.Now.Ticks.ToString ()); //}; //var btnLineS = new Button () { // Width = btnTakePictrue.Width, // Height = 1, // BackgroundColor = SkinStyle.Current.White20Transparent, // X = btnBG.Right, // Y = btnSelectPictrue.Bottom, //}; //inVerFramelayout.AddChidren (btnLineS); //FrameLayout systempictureLayout = new FrameLayout { // Height = Application.GetRealHeight (260), // Y = verIconLayout.Bottom + Application.GetRealHeight (20), //}; //dialogBodyView.AddChidren (systempictureLayout); //HorizontalScrolViewLayout horizontalScrolViewLayout = new HorizontalScrolViewLayout () { // Width = Application.GetRealWidth (450), // Height = Application.GetRealHeight (180), // BackgroundColor = SkinStyle.Current.ViewColor, // Gravity = Gravity.CenterHorizontal, //}; //systempictureLayout.AddChidren (horizontalScrolViewLayout); //for (int i = 0; i < 7; i++) { // Button butHeadshotPic = new Button () { // Width = Application.GetRealWidth (200), // Height = LayoutParams.MatchParent, // }; // butHeadshotPic.UnSelectedImagePath = "DoorLockPic/door_lock_ headshot_h" + (i).ToString () + ".png"; // butHeadshotPic.MouseUpEventHandler += (sender1, e1) => { // btnBG.UnSelectedImagePath = butHeadshotPic.UnSelectedImagePath; // }; // horizontalScrolViewLayout.AddChidren (butHeadshotPic); // Button btnNull = new Button () { // Width = 1, // }; // horizontalScrolViewLayout.AddChidren (btnNull); //} var BottomView = new FrameLayout () { Height = Application.GetRealHeight (90), BackgroundColor = SkinStyle.Current.DialogTitle, Y = dialogBodyView.Height - Application.GetRealHeight (90), }; dialogBodyView.AddChidren (BottomView); var btnBack = new Button () { Width = Application.GetRealWidth (119), Height = LayoutParams.MatchParent, 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); var btnSave = new Button () { Width = Application.GetRealWidth (400), Height = LayoutParams.MatchParent, X = btnLineH.Right, TextID = R.MyInternationalizationString.SAVE, TextAlignment = TextAlignment.Center, Radius = 1, }; BottomView.AddChidren (btnSave); btnSave.MouseUpEventHandler += (sender1, e1) => { //如果输入的备注为空就返回 if (string.IsNullOrEmpty (etRemarkBox.Text.Trim ())) { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.RemarkIsEmpty), Language.StringByID (R.MyInternationalizationString.Close)).Show (); return; } MainPage.Loading.Start ("Saving....."); var remarkBytes = CommonPage.MyEncodingGB2312.GetBytes (etRemarkBox.Text.Trim ()); System.Threading.Tasks.Task.Run (() => { bool isSuccess = false; try { var sendBytes = new byte [3 + 20]; sendBytes [0] = doorLock.PhysicsLoopID; sendBytes [1] = 0x02; sendBytes [2] = indexOfClick; System.Array.Copy (remarkBytes, 0, sendBytes, 3, 20 < remarkBytes.Length ? 20 : remarkBytes.Length); var setPasswordInfoBytes = Control.ControlBytesSendHasReturn (Command.SetDoorLockUseRemark, doorLock.SubnetID, doorLock.DeviceID, sendBytes); if (setPasswordInfoBytes != null && setPasswordInfoBytes [0] == 0xF8) { isSuccess = true; } else { Application.RunOnMainThread (() => { new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); isSuccess = false; return; } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); if (isSuccess) { //if (btnBG.UnSelectedImagePath == "HeadShotPicture") { // string newHeadshotPic = "DoorLook_Password_" + indexOfClick; // IO.FileUtils.ReNameFile (btnBG.UnSelectedImagePath, "Image_" + newHeadshotPic); // btnBG.UnSelectedImagePath = "Image_" + newHeadshotPic; //} btnRemarkName.Text = etRemarkBox.Text; //btnHeadshot.UnSelectedImagePath = btnBG.UnSelectedImagePath; doorLock.passwordList [indexOfClick].passwordRemark = etRemarkBox.Text; doorLock.passwordList [indexOfClick].passwordImage = btnHeadshot.UnSelectedImagePath; IO.FileUtils.SaveEquipmentMessage (doorLock, doorLock.LoopID.ToString ()); } dialog.Close (); }); } }); }; dialog.Show (); #endregion } } }