using System;
using System.Collections.Generic;
namespace Shared.SimpleControl.Phone
{
public class FingerPrint : Dialog
{
DoorLock doorLock;
PageLayout bodyView;
int pageIndex = 0;//指纹页码
string flag;
///
/// 构造函数
///
/// Door lock.
public FingerPrint (DoorLock door_lock,int pageIndex = 0)
{
this.doorLock = door_lock;
showUserFingerprint ();
this.pageIndex = pageIndex;
BackgroundColor = SkinStyle.Current.MainColor;
}
///
/// 读门锁指纹信息
///
void readHistory (Action action)
{
System.Threading.Tasks.Task.Run (() => {
Application.RunOnMainThread (() => { MainPage.Loading.Start (Language.StringByID(R.MyInternationalizationString.load));});
try {
for (int i = pageIndex * 10; i < pageIndex * 10 + 10; i++) {
if (this.doorLock.fingerprintList.Count - 1 < i) {
this.doorLock.fingerprintList.Add (new DoorLockFingerprintInfo () {
fingerprintRemark = "Unknown",
fingerprintImage = "DoorLockPic/door_lock_ headshot.png"
});
}
}
for (int i = pageIndex*10, lostLink = 0; i < pageIndex*10+10; i++) {
byte [] fingerprintInfoBytes = Control.ControlBytesSendHasReturn (Command.ReadDoorLockUseRemark, this.doorLock.SubnetID, this.doorLock.DeviceID, new byte [] { this.doorLock.PhysicsLoopID, 0x01, (byte)i });
if (fingerprintInfoBytes == null) {
lostLink++;
} else {
lostLink = 0;
this.doorLock.fingerprintList [i].fingerprintRemark = CommonPage.MyEncodingGB2312.GetString (fingerprintInfoBytes, 3, 20).TrimEnd('\0');
if(this.doorLock.fingerprintList[i].fingerprintRemark.Contains ("ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ"))
{
this.doorLock.fingerprintList[i].fingerprintRemark= Language.StringByID (R.MyInternationalizationString.AddFingerprintUser);
}
this.doorLock.fingerprintList [i].userFingerprintID = (int)(fingerprintInfoBytes [2]);
}
if (2 <= lostLink) {
break;
}
}
} catch { } finally {
Application.RunOnMainThread (() => {
MainPage.Loading.Hide ();
action ();
});
}
});
}
void showPage ()
{
var pageFrameLayout = bodyView.GetChildren (pageIndex) as VerticalScrolViewLayout;
pageFrameLayout.RemoveAll ();
for (int index = 0; index < 10; index++) {
var fingerprint = this.doorLock.fingerprintList [pageIndex * 10 + index];
if (null == fingerprint) {
fingerprint = new DoorLockFingerprintInfo ();
}
FrameLayout fingerRowView = new FrameLayout () {
Height = Application.GetRealHeight (90),
BackgroundColor = SkinStyle.Current.ViewColor,
};
pageFrameLayout.AddChidren (fingerRowView);
var btnRemarkID = new Button () {
Width = Application.GetRealWidth (70),
Height = LayoutParams.MatchParent,
Text = (fingerprint.userFingerprintID).ToString (),
TextAlignment = TextAlignment.Center,
X = Application.GetRealWidth (10),
TextColor = SkinStyle.Current.TextColor1,
};
fingerRowView.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 = fingerprint.fingerprintImage,
Radius = 5,
};
fingerRowView.AddChidren (btnHeadshot);
Button btnRemarkName = new Button () {
Width = Application.GetRealWidth (342),
Height = LayoutParams.MatchParent,
TextAlignment = TextAlignment.CenterLeft,
X = btnHeadshot.Right + Application.GetRealWidth (15),
Text = fingerprint.fingerprintRemark,
TextColor = SkinStyle.Current.TextColor1,
};
fingerRowView.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",
};
fingerRowView.AddChidren (btnEdit);
int indexOfClick = pageIndex * 10 + index;
btnEdit.MouseUpEventHandler += (sender, e) => {
showSetFingerInfoDialog (btnHeadshot, btnRemarkName, (byte)indexOfClick);
};
Button btnScence = new Button () {
X = btnEdit.Right,
Width = Application.GetRealWidth (120),
Height = Application.GetRealHeight (100),
UnSelectedImagePath = "DoorLockPic/door_lock_unedit_scene.png",
SelectedImagePath = "DoorLockPic/door_lock_edit_scene_on.png",
};
fingerRowView.AddChidren (btnScence);
Action action = () => {
bool HaveSceneTargets = false;
doorLock.HaveSceneTargets.TryGetValue ("001_" + 0x01.ToString ("000") + "_" + doorLock.fingerprintList [indexOfClick].userFingerprintID.ToString ("000"), out HaveSceneTargets);
string saveSceneFilePath = null;
doorLock.DictionaryList.TryGetValue ("001_" + 0x01.ToString ("000") + "_" + doorLock.fingerprintList [indexOfClick].userFingerprintID.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;
}
}
};
action ();
btnScence.MouseUpEventHandler += (sender, e) => {
doorLock.doorLockSceneTargetsUserID = doorLock.fingerprintList [indexOfClick].userFingerprintID;
doorLock.doorLockSceneRemark = doorLock.fingerprintList [indexOfClick].fingerprintRemark;//开锁场景类型
doorLock.doorLockSceneTargetsMethod = 0x01;
new FingerprintAndProximityScene (doorLock){Action=action}.Show ();
//Close ();
};
Button btnRowLineNull = new Button () {
Y = Application.GetRealHeight(90)-1,
Height = 1,
BackgroundColor = SkinStyle.Current.TitileView
};
if (index < 9)
fingerRowView.AddChidren (btnRowLineNull);
}
}
void showUserFingerprint ()
{
#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.UneditFingerprint,
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) => {
Close ();
};
#endregion
bodyView = new PageLayout () {
Width = LayoutParams.MatchParent,
Height = Application.GetRealHeight (Application.DesignHeight - 126-100),
BackgroundColor = SkinStyle.Current.ViewColor,
Y = topView.Bottom,
};
AddChidren (bodyView);
for (int i = 0; i < 10; i++) {
bodyView.AddChidren (new VerticalScrolViewLayout () {
Height = Application.GetRealHeight (Application.DesignHeight - 126-100),
BackgroundColor = SkinStyle.Current.TitileView
});
}
//int j = 0;
//bodyView.PageChange += (s, i) => {
// if (pageIndex < i && j < i) {
// readHistory (() => {
// showPage ();
// });
// j = i;
// } else {
// showPage ();
// }
// pageIndex = i;
//};
bodyView.PageChange += (s, i) => {
pageIndex = i;
if (this.doorLock.fingerprintList.Count < (pageIndex * 10 + 9)){
readHistory (() => {
showPage ();
});
} else {
showPage ();
}
};
if (this .doorLock .fingerprintList.Count == 0 || this.doorLock.fingerprintList.Count < 10) {
readHistory (() => {
showPage ();
});
}else{
showPage ();
}
#region bottomFrameLayout
var bottomFrameLayout = new FrameLayout () {
Height = Application.GetRealHeight (90),
Y = Application.GetRealHeight (Application.DesignHeight - 100),
};
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 (97),
TextID = R.MyInternationalizationString.ReFresh,
TextColor = SkinStyle.Current.TextColor1,
TextSize = 15,
};
bottomFrameLayout.AddChidren (refreshPasswordListBtn);
refreshPasswordListBtn.MouseUpEventHandler += (sender, e) => {
readHistory (() => {
showPage ();
});
};
#endregion
}
void showSetFingerInfoDialog (Button btnHeadshot, Button btnRemarkName, byte indexOfClick)
{
#region Dialog
Dialog dialog = new Dialog ();
FrameLayout dialogBodyView = new FrameLayout () {
BackgroundColor = SkinStyle.Current.DialogColor,
Width = Application.GetRealWidth (520),
Height = Application.GetRealHeight (80 + 50 + 50 + 170),
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) => {
// flag = DateTime.Now.Ticks.ToString ();
// Camera.TakePicture ((obj) => {
// if (obj == null) {
// return;
// }
// btnBG.UnSelectedImagePath = flag;
// }, flag);
//};
//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) => {
// flag = DateTime.Now.Ticks.ToString ();
// Camera.SelectPicture ((obj) => {
// if (obj == null) {
// return;
// }
// btnBG.UnSelectedImagePath = flag;
// }, flag);
//};
//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,
TextColor = SkinStyle.Current.DialogTextColor
};
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] = 0x01;
sendBytes [2] = indexOfClick;
System.Array.Copy (remarkBytes, 0, sendBytes, 3, 20 < remarkBytes.Length ? 20 : remarkBytes.Length);
var setFingerprintInfoBytes = Control.ControlBytesSendHasReturn (Command.SetDoorLockUseRemark, doorLock.SubnetID, doorLock.DeviceID, sendBytes);
if (setFingerprintInfoBytes != null && setFingerprintInfoBytes [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) {
//btnHeadshot.UnSelectedImagePath = btnBG.UnSelectedImagePath;
btnRemarkName.Text = etRemarkBox.Text;
doorLock.fingerprintList [indexOfClick].fingerprintRemark = etRemarkBox.Text;
doorLock.fingerprintList [indexOfClick].fingerprintImage = btnHeadshot.UnSelectedImagePath;
IO.FileUtils.SaveEquipmentMessage (doorLock, doorLock.PhysicsLoopID.ToString ());
}
dialog.Close ();
});
}
});
};
dialog.Show ();
#endregion
}
}
}