using System;
|
using System.Collections.Generic;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class ProximityCard : Dialog
|
{
|
DoorLock doorLock;
|
PageLayout bodyView;
|
int pageIndex = 0;//感应卡页码
|
string flag;
|
|
/// <summary>
|
/// 构造函数
|
/// </summary>
|
/// <param name="door_lock">Door lock.</param>
|
public ProximityCard (DoorLock door_lock, int pageIndex = 0)
|
{
|
this.doorLock = door_lock;
|
showUserProximitycard ();
|
this.pageIndex = pageIndex;
|
BackgroundColor = SkinStyle.Current.MainColor;
|
}
|
|
/// <summary>
|
/// 读门锁感应卡信息
|
/// </summary>
|
void readHistory (Action action)
|
{
|
System.Threading.Tasks.Task.Run (() => {
|
Application.RunOnMainThread (() => { MainPage.Loading.Start ("Please wait..."); });
|
try {
|
//for (int i = 0; i < 101; i++) {
|
for (int i = pageIndex * 10; i < pageIndex * 10 + 10; i++) {
|
if (this.doorLock.proximityCarList.Count -1 < i) {
|
this.doorLock.proximityCarList.Add (new DoorLockProximityCardInfo () {
|
proximityCardRemark = "Unknown",
|
proximityCardImage = "DoorLockPic/door_lock_ headshot.png"
|
});
|
}
|
}
|
|
for (int i = pageIndex * 10, lostLink = 0; i < pageIndex * 10 + 10; i++) {
|
byte [] proximityCardInfoBytes = Control.ControlBytesSendHasReturn (Command.ReadDoorLockUseRemark, this.doorLock.SubnetID, this.doorLock.DeviceID, new byte [] { this.doorLock.LoopID, 0x03, (byte)i });
|
if (proximityCardInfoBytes == null) {
|
lostLink++;
|
} else {
|
lostLink = 0;
|
this.doorLock.proximityCarList [i].proximityCardRemark = CommonPage.MyEncodingGB2312.GetString (proximityCardInfoBytes, 3, 20).TrimEnd ('\0');
|
if (this.doorLock.proximityCarList [i].proximityCardRemark == "") {
|
this.doorLock.proximityCarList [i].proximityCardRemark = Language .StringByID (R.MyInternationalizationString.AddProximityUser);
|
}
|
if (this.doorLock.proximityCarList [i].proximityCardRemark.Contains ("ÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿÿ")) {
|
this.doorLock.proximityCarList [i].proximityCardRemark = Language.StringByID (R.MyInternationalizationString.AddProximityUser);
|
}
|
this.doorLock.proximityCarList [i].proximityCardID = (int)(proximityCardInfoBytes [2]);
|
}
|
if (2 <= lostLink) {
|
break;
|
}
|
}
|
|
IO.FileUtils.SaveEquipmentMessage (doorLock, doorLock.LoopID.ToString ());
|
|
} 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 proximityCard = this.doorLock.proximityCarList [pageIndex * 10 + index];
|
if (null == proximityCard) {
|
proximityCard = new DoorLockProximityCardInfo ();
|
}
|
|
FrameLayout pCardView = new FrameLayout () {
|
Height = Application.GetRealHeight (90),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
pageFrameLayout.AddChidren (pCardView);
|
|
var btnRemarkID = new Button () {
|
Width = Application.GetRealWidth (70),
|
Height = LayoutParams.MatchParent,
|
Text = proximityCard.proximityCardID.ToString (),
|
TextAlignment = TextAlignment.Center,
|
X = Application.GetRealWidth (11),
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
pCardView.AddChidren (btnRemarkID);
|
|
var btnHeadshot = new Button () {
|
X = btnRemarkID.Right +Application.GetRealWidth (5),
|
Gravity = Gravity.CenterVertical,
|
//Width = Application.GetRealWidth (56),
|
//Height = Application.GetRealHeight (57),
|
Width = Application.GetRealWidth (0),
|
Height = Application.GetRealHeight (0),
|
UnSelectedImagePath = proximityCard.proximityCardImage,
|
};
|
pCardView.AddChidren (btnHeadshot);
|
|
var btnRemarkName = new Button () {
|
Width = Application.GetRealWidth (342),
|
Height = LayoutParams.MatchParent,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = btnHeadshot.Right + Application.GetRealWidth (15),
|
Text = proximityCard.proximityCardRemark,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
pCardView.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",
|
};
|
pCardView.AddChidren (btnEdit);
|
|
int indexOfClick = pageIndex * 10 + index;
|
btnEdit.MouseUpEventHandler += (sender, e) => {
|
showDialog (btnHeadshot, btnRemarkName, (byte)indexOfClick);
|
};
|
|
//var btnScence = new Button () {
|
// X = btnEdit.Right + Application.GetRealWidth (10),
|
// Gravity = Gravity.CenterVertical,
|
// Width = Application.GetRealWidth (56),
|
// Height = Application.GetRealHeight (57),
|
// UnSelectedImagePath = "Scene/Scene.png",
|
//};
|
//pCardView.AddChidren (btnScence);
|
|
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",
|
};
|
pCardView.AddChidren (btnScence);
|
|
Action action = () => {
|
bool HaveSceneTargets = false;
|
doorLock.HaveSceneTargets.TryGetValue ("001_" + 0x03.ToString ("000") + "_" + doorLock.proximityCarList [indexOfClick].proximityCardID.ToString ("000"), out HaveSceneTargets);
|
string saveSceneFilePath = null;
|
doorLock.DictionaryList.TryGetValue ("001_" + 0x03.ToString ("000") + "_" + doorLock.proximityCarList [indexOfClick].proximityCardID.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.proximityCarList [indexOfClick].proximityCardID;
|
doorLock.doorLockSceneRemark = doorLock.proximityCarList [indexOfClick].proximityCardRemark;//开锁场景类型
|
doorLock.doorLockSceneTargetsMethod = 0x03;
|
IO.FileUtils.SaveEquipmentMessage (doorLock, doorLock.LoopID.ToString ());
|
new FingerprintAndProximityScene (doorLock){Action = action }.Show ();
|
};
|
Button btnRowLineNull = new Button () {
|
Y = Application.GetRealHeight (90) - 1,
|
Height = 1,
|
BackgroundColor = SkinStyle.Current.TitileView
|
};
|
if (index < 9)
|
pCardView.AddChidren (btnRowLineNull);
|
}
|
}
|
|
void showUserProximitycard ()
|
{
|
#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.ProximityCard,
|
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,
|
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 (1136 - 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 (1136 - 126 - 100),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
});
|
}
|
|
bodyView.PageChange += (s, i) => {
|
pageIndex = i;
|
if (this.doorLock.proximityCarList.Count < (pageIndex * 10 + 9)) {
|
readHistory (() => {
|
showPage ();
|
});
|
} else {
|
showPage ();
|
}
|
};
|
|
if (this.doorLock.proximityCarList.Count == 0 || this.doorLock.proximityCarList.Count < 10) {
|
readHistory (() => {
|
showPage ();
|
});
|
} else {
|
showPage ();
|
}
|
|
|
#region bottomFrameLayout
|
var bottomFrameLayout = new FrameLayout () {
|
Height = Application.GetRealHeight (90),
|
Y = Application.GetRealHeight (1136 - 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,
|
TextSize = 15,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
bottomFrameLayout.AddChidren (refreshPasswordListBtn);
|
refreshPasswordListBtn.MouseUpEventHandler += (sender, e) => {
|
readHistory (() => {
|
showPage ();
|
});
|
};
|
#endregion
|
}
|
|
void showDialog (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 (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.TextColor1
|
};
|
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);
|
var 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,
|
};
|
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] = 0x03;
|
sendBytes [2] = indexOfClick;
|
System.Array.Copy (remarkBytes, 0, sendBytes, 3, 20 < remarkBytes.Length ? 20 : remarkBytes.Length);
|
var setProximityCardInfoBytes = Control.ControlBytesSendHasReturn (Command.SetDoorLockUseRemark, doorLock.SubnetID, doorLock.DeviceID, sendBytes);
|
if (setProximityCardInfoBytes != null && setProximityCardInfoBytes [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) {
|
btnRemarkName.Text = etRemarkBox.Text;
|
btnHeadshot.UnSelectedImagePath = btnBG.UnSelectedImagePath;
|
doorLock.proximityCarList [indexOfClick].proximityCardRemark = etRemarkBox.Text;
|
doorLock.proximityCarList [indexOfClick].proximityCardImage = btnHeadshot.UnSelectedImagePath;
|
IO.FileUtils.SaveEquipmentMessage (doorLock, doorLock.LoopID.ToString ());
|
}
|
dialog.Close ();
|
});
|
}
|
});
|
};
|
|
dialog.Show ();
|
#endregion
|
}
|
}
|
}
|