using System;
using System.Collections.Generic;
//using Android.Media;
namespace Shared.SimpleControl.Phone
{
public class PasswordList : FrameLayout
{
DoorLock doorLock;
public PasswordList (DoorLock door_lock)
{
this.doorLock = door_lock;
BackgroundColor = SkinStyle.Current.MainColor;
}
///
/// 读门锁密码信息
///
/// Door lock.
void readStatus (DoorLock door_lock)
{
System.Threading.Tasks.Task.Run (() => {
Application.RunOnMainThread (() => { MainPage.Loading.Start ("Please wait..."); });
try{
for (int i = 1; i <= 10; i++) {
if (door_lock.passwordList.Count < i) {
door_lock.passwordList.Add (new DoorLockPasswrodInfo () {
passwordRemark = "",
passwordImage = "DoorLockPic/door_lock_ headshot.png"
});
}
}
for (int i = 0, lostLink = 0; i < 10; i++) {
byte [] passwordInfoBytes = Control.ControlBytesSendHasReturn (Command.ReadDoorLockUseRemark, door_lock.SubnetID, door_lock.DeviceID, new byte [] { door_lock.LoopID, 0x02, (byte)i });
if (passwordInfoBytes == null) {
lostLink++;
} else {
lostLink = 0;
door_lock.passwordList [i].passwordRemark = CommonPage.MyEncodingGB2312.GetString (passwordInfoBytes, 3, 20);
if (door_lock.passwordList [i].passwordRemark == "ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ") {
door_lock.passwordList [i].passwordRemark =Language .StringByID (R.MyInternationalizationString.AddPasswordUser) ;
}
door_lock.passwordList [i].userPasswordID = (int)(passwordInfoBytes [2]);
}
if (2 <= lostLink) {
break;
}
}
IO.FileUtils.SaveEquipmentMessage (door_lock, door_lock.LoopID.ToString ());
} catch { } finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
});
}
});
}
public void ShowUserPasswordPrint ()
{
if (doorLock.passwordList.Count == 0) {
readStatus (doorLock);
}
#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
#region middleVerticalScrolViewLayout
var middleVerticalScrolViewLayout = new VerticalScrolViewLayout () {
Height = Application.GetRealHeight (1136 - 126 - 98),
Y = topView.Bottom,
BackgroundColor = SkinStyle.Current.ViewColor
};
AddChidren (middleVerticalScrolViewLayout);
#region test
for (int index = 0; index < doorLock.passwordList.Count; index++) {
FrameLayout passwrodRowView = new FrameLayout () {
Height = Application.GetRealHeight (90),
};
middleVerticalScrolViewLayout.AddChidren (passwrodRowView);
var btnRemarkID = new Button () {
Width = Application.GetRealWidth (70),
Height = LayoutParams.MatchParent,
Text = doorLock.passwordList [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
};
passwrodRowView.AddChidren (btnRowLineNull);
}
#endregion
#endregion
#region bottomFrameLayout
var bottomFrameLayout = new FrameLayout () {
Height = Application.GetRealHeight (107),
Y = Application.GetRealHeight (1136 - 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 (doorLock);
ShowUserPasswordPrint ();
};
#endregion
}
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.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.LoopID;
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.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
}
void readDoorLockScene (DoorLock door_lock)
{
System.Threading.Tasks.Task.Run (() => {
Application.RunOnMainThread (() => {
MainPage.Loading.Start ("Please wait...");
});
for (int i = 0, lostLink = 0; i < 9; i++) {
doorLock.stateAndAlarmList.Add (new DoorLockStateAndAlarmInfo ());
byte [] stateAndAlarmInfoBytes = Control.ControlBytesSendHasReturn (Command.ReadDoorLockSceneObj, door_lock.SubnetID, door_lock.DeviceID, new byte [] { door_lock.LoopID, 1,0x02,(byte)i});
if (stateAndAlarmInfoBytes == null) {
lostLink++;
} else {
lostLink = 0;
var doorLockStateAndAlarmInfo = doorLock.stateAndAlarmList [i];
doorLockStateAndAlarmInfo.DoorLockType = stateAndAlarmInfoBytes [2];
doorLockStateAndAlarmInfo.UserID = stateAndAlarmInfoBytes [3];
doorLockStateAndAlarmInfo.DoorLockYear = stateAndAlarmInfoBytes [4].ToString ();
doorLockStateAndAlarmInfo.DoorLockMonth = stateAndAlarmInfoBytes [5].ToString ();
doorLockStateAndAlarmInfo.DoorLockDay = stateAndAlarmInfoBytes [6].ToString ();
doorLockStateAndAlarmInfo.DoorLockHour = stateAndAlarmInfoBytes [7].ToString ();
doorLockStateAndAlarmInfo.DoorLockMinute = stateAndAlarmInfoBytes [8].ToString ();
doorLockStateAndAlarmInfo.DoorLockSec = stateAndAlarmInfoBytes [9].ToString ();
}
if (2 <= lostLink) {
break;
}
}
IO.FileUtils.SaveEquipmentMessage (door_lock, door_lock.LoopID.ToString ());
});
}
}
}