using System;
|
using System.Collections.Generic;
|
|
namespace Shared.SimpleControl.Phone
|
{
|
public class UserSecurityPage : FrameLayout
|
{
|
VerticalScrolViewLayout contentView;
|
FrameLayout BodyView;
|
SecurityModul sm;
|
public UserSecurityPage (SecurityModul SM)
|
{
|
sm = SM;
|
BackgroundColor = SkinStyle.Current.MainColor;
|
}
|
|
public void ShowSecurityArea ()
|
{
|
#region 标题
|
var topView = new FrameLayout () {
|
Y = Application.GetRealHeight (36),
|
Height = Application.GetRealHeight (90),
|
};
|
AddChidren (topView);
|
|
var title = new Button () {
|
TextAlignment = TextAlignment.Center,
|
Text = sm.Name,
|
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);
|
Button back = new Button () {
|
Height = Application.GetRealHeight (90),
|
Width = Application.GetRealWidth (85),
|
UnSelectedImagePath = "Item/Back.png",
|
SelectedImagePath = "Item/BackSelected.png",
|
};
|
topView.AddChidren (back);
|
back.MouseUpEventHandler += (sender, e) => {
|
(Parent as PageLayout).PageIndex -= 1;
|
};
|
#endregion
|
BodyView = new FrameLayout {
|
Height = Application.GetRealHeight (Application.DesignHeight - 126),
|
Y = Application.GetRealHeight (126),
|
};
|
AddChidren (BodyView);
|
|
FrameLayout roomBackgroundImageView = new FrameLayout () {
|
Height = Application.GetRealHeight (360),
|
BackgroundImagePath = "Security/SecurityBackgoround.png"
|
};
|
BodyView.AddChidren (roomBackgroundImageView);
|
|
FrameLayout securityView = new FrameLayout () {
|
Height = Application.GetRealHeight (Application.DesignHeight - 126 - 360),
|
Y = roomBackgroundImageView.Bottom,
|
BackgroundColor = SkinStyle.Current.ViewColor
|
};
|
BodyView.AddChidren (securityView);
|
|
FrameLayout subtitleView = new FrameLayout () {
|
Height = Application.GetRealHeight (100),
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
securityView.AddChidren (subtitleView);
|
|
Button btnDryContact = new Button () {
|
Width = Application.GetRealWidth (211 + 107),
|
BackgroundColor = SkinStyle.Current.SubtitleView,
|
TextID = R.MyInternationalizationString.SensorState,
|
TextAlignment = TextAlignment.Center,
|
};
|
subtitleView.AddChidren (btnDryContact);
|
|
Button btnHistory = new Button () {
|
X = btnDryContact.Right + Application.GetRealWidth (3),
|
Width = Application.GetRealWidth (212),
|
BackgroundColor = SkinStyle.Current.SubtitleView,
|
TextID = R.MyInternationalizationString.HistoryRecord,
|
TextAlignment = TextAlignment.Center,
|
};
|
//subtitleView.AddChidren (btnHistory);
|
//btnHistory.Text += " (7D)";
|
|
Button btnPasswrod = new Button () {
|
X = btnDryContact.Right + Application.GetRealWidth (4),
|
Width = Application.GetRealWidth (211 + 110),
|
TextID = R.MyInternationalizationString.ModifyPWD,
|
TextAlignment = TextAlignment.Center,
|
BackgroundColor = SkinStyle.Current.SubtitleView,
|
};
|
subtitleView.AddChidren (btnPasswrod);
|
|
contentView = new VerticalScrolViewLayout () {
|
Y = subtitleView.Bottom,
|
Height = Application.GetRealHeight (Application.DesignHeight - 126 - 360 - 100),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
securityView.AddChidren (contentView);
|
|
btnDryContact.MouseUpEventHandler += (sender, e) => {
|
showDrycontactList ();
|
};
|
|
btnHistory.MouseUpEventHandler += (sender, e) => {
|
contentView.RemoveAll ();
|
contentView.ScrollEnabled = true;
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("");
|
});
|
DateTime msgTimeReduce7 = DateTime.Now.AddDays (-7);
|
var msgTotal = Control.ControlBytesSendHasReturn (Command.RED_HSFH_TOTAL, sm.SubnetID, sm.DeviceID, new byte [] {
|
Convert.ToByte (msgTimeReduce7.Year - 2000),Convert.ToByte (msgTimeReduce7.Month),Convert.ToByte (msgTimeReduce7.Day)
|
,Convert.ToByte (DateTime.Now.Year - 2000),Convert.ToByte (DateTime.Now.Month),Convert.ToByte (DateTime.Now.Day)});
|
if (msgTotal != null) {
|
sm.HistoricalRecords.Clear ();
|
int totalCount = msgTotal [0] * 256 + msgTotal [1];
|
int startIndex6 = msgTotal [2] * 256 + msgTotal [3];
|
int endIndex = totalCount + startIndex6;
|
for (int i = 0; i < totalCount; i++) {
|
var msgBytes = Control.ControlBytesSendHasReturn (Command.RED_HSFH_INFORMATION, sm.SubnetID, sm.DeviceID, new byte [] {
|
Convert.ToByte (msgTimeReduce7.Year - 2000),Convert.ToByte (msgTimeReduce7.Month),Convert.ToByte (msgTimeReduce7.Day)
|
,Convert.ToByte (DateTime.Now.Year - 2000),Convert.ToByte (DateTime.Now.Month),Convert.ToByte (DateTime.Now.Day)
|
,msgTotal [2] , msgTotal [3]
|
,Convert.ToByte (endIndex / 256), Convert.ToByte (endIndex % 256) });
|
if (msgBytes != null && msgBytes[0] == 0xF8) {
|
byte [] ddd = new byte [20];
|
Array.Copy (msgBytes, 13, ddd, 0, 20 < msgBytes.Length ? 20 : msgBytes.Length);
|
string msgString = "";
|
switch (msgBytes [12]) {
|
#region
|
case 1:
|
msgString = "Arm Vacation ";
|
break;
|
case 2:
|
msgString = "Arm Away ";
|
break;
|
case 3:
|
msgString = "Arm Night ";
|
break;
|
case 4:
|
msgString = "Arm Night Guest ";
|
break;
|
case 5:
|
msgString = "Arm Day ";
|
break;
|
case 6:
|
msgString = "Disarming ";
|
break;
|
case 7:
|
msgString = "Vacation Alarm ";
|
break;
|
case 8:
|
msgString = "Away Alarm ";
|
break;
|
case 9:
|
msgString = "Night Alarm ";
|
break;
|
case 10:
|
msgString = "Night Guest Alarm ";
|
break;
|
case 11:
|
msgString = "Day Alarm ";
|
break;
|
case 12:
|
msgString = "Silen Alarm ";
|
break;
|
case 13:
|
msgString = "Power Alarm ";
|
break;
|
case 14:
|
msgString = "Temp Alarm ";
|
break;
|
case 15:
|
msgString = "Fire Alarm ";
|
break;
|
case 16:
|
msgString = "Gas Alarm ";
|
break;
|
case 17:
|
msgString = "Panic Alarm ";
|
break;
|
case 18:
|
msgString = "Emergency Alarm ";
|
break;
|
case 19:
|
msgString = "Curren Alarm ";
|
break;
|
#endregion
|
}
|
|
msgString += CommonPage.MyEncodingGB2312.GetString (ddd);
|
sm.HistoricalRecords.Add (msgString);
|
Application.RunOnMainThread (() => {
|
FrameLayout roomView = new FrameLayout () {
|
Height = Application.GetRealHeight (100),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
contentView.AddChidren (roomView);
|
Button btnRoomNull = new Button () {
|
Height = 1,
|
SelectedBackgroundColor = SkinStyle.Current.MainColor,
|
BackgroundColor = SkinStyle.Current.MainColor,
|
};
|
contentView.AddChidren (btnRoomNull);
|
Button btnPoint = new Button () {
|
Width = Application.GetRealWidth (10),
|
Height = Application.GetRealHeight (10),
|
X = Application.GetRealWidth (50),
|
Gravity = Gravity.CenterVertical,
|
UnSelectedImagePath = "Item/Point.png",
|
SelectedImagePath = "Item/Point.png",
|
};
|
roomView.AddChidren (btnPoint);
|
Button btnRoomName = new Button () {
|
Text = msgString,
|
X = btnPoint.Right + Application.GetRealWidth (20),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1,
|
SelectedTextColor = SkinStyle.Current.TextColor1,
|
};
|
roomView.AddChidren (btnRoomName);
|
});
|
}
|
--endIndex;
|
}
|
}
|
} catch (Exception ex) {
|
Console.WriteLine ("arHistory" + ex.ToString ());
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
|
btnPasswrod.MouseUpEventHandler += (sender, e) => {
|
contentView.RemoveAll ();
|
contentView.ScrollEnabled = false;
|
Button btnTipButton = new Button () {
|
X = Application.GetRealWidth(40),
|
Width = Application.GetRealWidth(600),
|
Height = Application.GetRealHeight(80),
|
TextID = R.MyInternationalizationString.PleaseEnterOldPassword,
|
TextAlignment = TextAlignment.CenterLeft
|
};
|
contentView.AddChidren (btnTipButton);
|
|
string pwString = "";
|
Button btnPW = new Button () {
|
Y = btnTipButton.Bottom,
|
Height = Application.GetRealHeight(90),
|
TextAlignment = TextAlignment.Center,
|
TextSize = 34,
|
Text = "- - - - - - - -",
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
contentView.AddChidren (btnPW);
|
|
FrameLayout numberView = new FrameLayout () {
|
X = Application.GetRealWidth(25),
|
Y = btnPW.Bottom + Application.GetRealHeight(40),
|
Height = Application.GetRealHeight(240),
|
};
|
contentView.AddChidren (numberView);
|
|
int pNumber = 1;
|
|
FrameLayout bottomView = new FrameLayout () {
|
Y = numberView.Bottom + Application.GetRealHeight(20),
|
Height = Application.GetRealHeight(140),
|
};
|
contentView.AddChidren (bottomView);
|
|
Button btnClear = new Button () {
|
X = Application.GetRealWidth (40),
|
Y = Application.GetRealHeight(20),
|
Width = Application.GetRealWidth(250),
|
Height = Application.GetRealHeight(80),
|
TextAlignment = TextAlignment.Center,
|
TextID = R.MyInternationalizationString.Clear,
|
BackgroundColor = SkinStyle.Current.ButtonColor1,
|
SelectedBackgroundColor = SkinStyle.Current.ButtonColor1,
|
BorderColor = SkinStyle.Current.Transparent,
|
TextColor = SkinStyle.Current.DialogTextColor,
|
BorderWidth = 0,
|
Radius = 5,
|
};
|
bottomView.AddChidren (btnClear);
|
|
|
Button btnSave = new Button () {
|
X = btnClear.Right + Application.GetRealWidth (70),
|
Y = Application.GetRealHeight (20),
|
Width = Application.GetRealWidth (250),
|
Height = Application.GetRealHeight (80),
|
TextAlignment = TextAlignment.Center,
|
TextID = R.MyInternationalizationString.confirm,
|
BackgroundColor = SkinStyle.Current.ButtonColor,
|
SelectedBackgroundColor = SkinStyle.Current.ButtonColor1,
|
BorderColor = SkinStyle.Current.Transparent,
|
SelectedTextColor = SkinStyle.Current.DialogTextColor,
|
TextColor = SkinStyle.Current.TextColor1,
|
BorderWidth = 0,
|
Radius = 5,
|
};
|
bottomView.AddChidren (btnSave);
|
|
for (int i = 0; i < 2; i++) {
|
for (int j = 0; j < 5; j++) {
|
string unP = "TV/TV2_" + pNumber.ToString ();
|
string uSP = "TV/TV2_" + pNumber.ToString () + "_on";
|
Button btn = new Button () {
|
X = Application.GetRealWidth (120 * j),
|
Y = Application.GetRealHeight (120 * i),
|
Width = Application.GetRealWidth (120),
|
Height = Application.GetRealHeight (120),
|
UnSelectedImagePath = unP + ".png",
|
SelectedImagePath = uSP + ".png",
|
Tag = pNumber
|
};
|
numberView.AddChidren (btn);
|
btn.MouseDownEventHandler += (sende2r, e2) => {
|
btn.IsSelected = true;
|
};
|
btn.MouseUpEventHandler += (sender2, e2) => {
|
btn.IsSelected = false;
|
if (pwString.Length == 8)
|
return;
|
string NumString = ((Button)(sender2)).Tag.ToString ();
|
if (NumString == "10")
|
NumString = "0";
|
pwString += NumString;
|
btnPW.Text = "";
|
|
string btnpws = "";
|
for (int c = 0; c < 8; c++) {
|
if (c < pwString.Length) {
|
btnpws += "* ";
|
} else {
|
btnpws += "- ";
|
}
|
}
|
btnPW.Text = btnpws;
|
|
if (pwString.Length == 8) {
|
btnSave.IsSelected = btnSave.Enable = true;
|
}
|
};
|
pNumber++;
|
|
}
|
}
|
|
btnClear.MouseUpEventHandler += (sender2, e2) => {
|
pwString = "";
|
btnPW.Text = "- - - - - - - -";
|
btnSave.IsSelected = btnSave.Enable = false;
|
};
|
|
string newPasswrod = "";
|
btnSave.MouseUpEventHandler += (sender2, e2) => {
|
if (btnSave.TextID == R.MyInternationalizationString.confirm) {
|
if (pwString == UserConfig.Instance.ArmPW || pwString == "85521566") {
|
new Tip () { Text = Language.StringByID (R.MyInternationalizationString.PleaseEnterNewPassword),CloseTime =3, Direction = AMPopTipDirection.Up }.Show (btnPW);
|
btnTipButton.TextID = R.MyInternationalizationString.PleaseEnterNewPassword;
|
btnSave.TextID = R.MyInternationalizationString.OK;
|
btnSave.IsSelected = btnSave.Enable = false;
|
pwString = "";
|
btnPW.Text = "- - - - - - - -";
|
} else {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.PasswordIsError),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
pwString = "";
|
btnPW.Text = "- - - - - - - -";
|
}
|
} else if (btnSave.TextID == R.MyInternationalizationString.OK) {
|
new Tip () { Text = Language.StringByID (R.MyInternationalizationString.ConfirmNewPassword),CloseTime =3, Direction = AMPopTipDirection.Up }.Show (btnPW);
|
btnTipButton.TextID = R.MyInternationalizationString.ConfirmNewPassword;
|
btnSave.TextID = R.MyInternationalizationString.SAVE;
|
btnSave.IsSelected = btnSave.Enable = false;
|
newPasswrod = pwString;
|
pwString = "";
|
btnPW.Text = "- - - - - - - -";
|
} else if (btnSave.TextID == R.MyInternationalizationString.SAVE) {
|
if (newPasswrod == pwString) {
|
UserConfig.Instance.ArmPW = newPasswrod;
|
UserConfig.Instance.SaveUserConfig ();
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.SetSuccessfully),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
btnSave.IsSelected = btnSave.Enable = false;
|
newPasswrod = "";
|
pwString = "";
|
btnPW.Text = "- - - - - - - -";
|
btnSave.TextID = R.MyInternationalizationString.confirm;
|
btnTipButton.TextID = R.MyInternationalizationString.PleaseEnterOldPassword;
|
} else {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.NewCipherInconsistencies),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
pwString = "";
|
btnPW.Text = "- - - - - - - -";
|
}
|
}
|
};
|
};
|
|
showDrycontactList ();
|
}
|
|
void showDrycontactList ()
|
{
|
contentView.RemoveAll ();
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Start ("");
|
});
|
int loseCount = 0;
|
List<ScurityDryContact> sensorList_Show = new List<ScurityDryContact> ();
|
List<string> securityAreaPaths = IO.FileUtils.ReadFiles ().FindAll ((obj) => obj.Contains (sm.SavePath + "_"));
|
foreach (var securityAreaPath in securityAreaPaths) {
|
var securityArea = Newtonsoft.Json.JsonConvert.DeserializeObject<SecurityModul> (CommonPage.MyEncodingUTF8.GetString (IO.FileUtils.ReadFile (securityAreaPath)));
|
sensorList_Show.AddRange (securityArea.SensorList);
|
}
|
foreach (var dr in sensorList_Show) {
|
string btnTipString = "";
|
if (loseCount < 3) {
|
var drBytes = Control.ControlBytesSendHasReturn (Command.ReadSecurityStatus, sm.SubnetID, sm.DeviceID, new byte [] { dr.AreaNumber, dr.IndexOfScurity, 0 });
|
if (drBytes != null) {
|
loseCount = 0;
|
dr.Status = drBytes [2];
|
dr.ByPass = drBytes [3];
|
if (drBytes [3] == 1) {
|
btnTipString = "Bypass";
|
}
|
} else {
|
loseCount++;
|
btnTipString = Language.StringByID (R.MyInternationalizationString.NotOnline);
|
}
|
}
|
Application.RunOnMainThread (() => {
|
FrameLayout drRowView = new FrameLayout () {
|
Height = Application.GetRealHeight (100),
|
BackgroundColor = SkinStyle.Current.ViewColor,
|
};
|
contentView.AddChidren (drRowView);
|
|
Button btnIcon = new Button () {
|
X = Application.GetRealWidth (10),
|
Y = Application.GetRealHeight (5),
|
Width = Application.GetRealWidth (95),
|
Height = Application.GetRealHeight (90),
|
};
|
drRowView.AddChidren (btnIcon);
|
|
switch (dr.SensorType) {
|
case 0:
|
btnIcon.UnSelectedImagePath = "Security/IconWindow.png";
|
btnIcon.SelectedImagePath = "Security/IconWindowOn.png";
|
break;
|
case 1:
|
btnIcon.UnSelectedImagePath = "Security/IconDoor.png";
|
btnIcon.SelectedImagePath = "Security/IconDoorOn.png";
|
break;
|
default:
|
btnIcon.UnSelectedImagePath = "Security/IconInduction.png";
|
btnIcon.SelectedImagePath = "Security/IconInductionOn.png";
|
break;
|
}
|
|
Button btnName = new Button () {
|
X = btnIcon.Right + Application.GetRealWidth (5),
|
Width = Application.GetRealWidth (360),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = SkinStyle.Current.TextColor1,
|
Text = dr.Name,
|
};
|
drRowView.AddChidren (btnName);
|
|
Button btnStatus = new Button () {
|
X = btnName.Right + Application.GetRealWidth (5),
|
Width = Application.GetRealWidth (140),
|
TextAlignment = TextAlignment.Center,
|
TextColor = SkinStyle.Current.TextColor1,
|
};
|
drRowView.AddChidren (btnStatus);
|
|
btnStatus.MouseLongEventHandler += (sender, e) => {
|
if (dr.Status == 2) {
|
return;
|
}
|
MainPage.Loading.Start ("");
|
byte [] byResult = null;
|
System.Threading.Tasks.Task.Run (() => {
|
try {
|
if (dr.ByPass == 1) {
|
dr.ByPass = 0;//IndexOfScurity
|
byResult = Control.ControlBytesSendHasReturn (Command.SetSecurityByPass, sm.SubnetID, sm.DeviceID, new byte [] { dr.AreaNumber, dr.LoopID, dr.ByPass });
|
} else {
|
dr.ByPass = 1;
|
byResult = Control.ControlBytesSendHasReturn (Command.SetSecurityByPass, sm.SubnetID, sm.DeviceID, new byte [] { dr.AreaNumber, dr.LoopID, dr.ByPass });
|
}
|
} catch (Exception ex) {
|
Console.WriteLine ("Bypass " + ex.ToString ());
|
} finally {
|
Application.RunOnMainThread (() => {
|
if (byResult == null) {
|
new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.OperationFailed),
|
Language.StringByID (R.MyInternationalizationString.Close)).Show ();
|
} else{
|
if (dr.ByPass == 1) {
|
btnStatus.Text = "Bypass";
|
} else {
|
if (dr.Status == 0) {
|
btnStatus.TextID = R.MyInternationalizationString.Close;
|
} else {
|
btnStatus.TextID = R.MyInternationalizationString.Open;
|
}
|
}
|
}
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
};
|
|
if (btnTipString == "") {
|
if (dr.Status == 0) {
|
btnStatus.TextID = R.MyInternationalizationString.Close;
|
} else {
|
btnStatus.TextID = R.MyInternationalizationString.Open;
|
}
|
} else {
|
btnStatus.Text = btnTipString;
|
}
|
|
Button btnNullLine = new Button () {
|
Y = Application.GetRealHeight (97),
|
Height = Application.GetRealHeight (3),
|
BackgroundColor = SkinStyle.Current.White20Transparent,
|
};
|
drRowView.AddChidren (btnNullLine);
|
});
|
}
|
} catch (Exception ex) {
|
Console.WriteLine ("ShowDry" + ex.ToString ());
|
} finally {
|
Application.RunOnMainThread (() => {
|
MainPage.Loading.Hide ();
|
});
|
}
|
});
|
}
|
}
|
}
|