using System;
|
using System.Collections.Generic;
|
using Shared;
|
using Shared.Common;
|
using Shared.R;
|
namespace Shared.Phone.Device.Logic.DoorLockLogic
|
{
|
public class AddCondition : FrameLayout
|
{
|
public AddCondition()
|
{
|
Tag = "LockLogic";
|
}
|
Button selectedIcon = new Button();
|
VerticalRefreshLayout middle;
|
public int conditionsIndex = -1;
|
|
public void Show()
|
{
|
#region 最上面的布局代码
|
var topRowLayout = new RowLayout
|
{
|
BackgroundColor = ZigbeeColor.Current.LogicTopBackgroundColor,
|
Height = Application.GetRealHeight(184),
|
LineColor = ZigbeeColor.Current.LogicRowLayoutTopLineColor,
|
};
|
this.AddChidren(topRowLayout);
|
|
var titleName = new Button
|
{
|
TextSize = 17,
|
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
|
TextAlignment = TextAlignment.CenterLeft,
|
X = Application.GetRealWidth(176),
|
Width = Application.GetRealWidth(600),
|
Height = Application.GetRealHeight(69),
|
Y = Application.GetRealHeight(92),
|
TextID = MyInternationalizationString.userlist,
|
IsBold = true,
|
//Text = "选择用户",
|
};
|
topRowLayout.AddChidren(titleName);
|
|
var clickBtn = new Button
|
{
|
Width = Application.GetRealWidth(81 + 51),
|
Height = Application.GetRealHeight(58 + 40),
|
Y = Application.GetRealHeight(98 - 40),
|
};
|
topRowLayout.AddChidren(clickBtn);
|
clickBtn.MouseDownEventHandler += (sender, e) =>
|
{
|
RemoveFromParent();
|
};
|
|
var back = new Button
|
{
|
Width = Application.GetRealWidth(30),
|
Height = Application.GetRealHeight(51),
|
X = Application.GetRealWidth(81),
|
Y = Application.GetRealHeight(98),
|
//Gravity = Gravity.CenterVertical;
|
UnSelectedImagePath = "ZigeeLogic/back.png",
|
};
|
topRowLayout.AddChidren(back);
|
back.MouseDownEventHandler += (sender, e) =>
|
{
|
RemoveFromParent();
|
};
|
|
#endregion
|
|
middle = new VerticalRefreshLayout
|
{
|
Y = topRowLayout.Bottom,
|
Height = Application.GetRealHeight(1920 - 184),
|
BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
|
};
|
this.AddChidren(middle);
|
middle.BeginHeaderRefreshingAction += () =>
|
{
|
//重新刷新logic列表
|
string macport = Send.CurrentDoorLock.DeviceAddr + "_" + Send.CurrentDoorLock.DeviceEpoint.ToString();
|
for (int i = 0; i < Send.LockList.Count; i++)
|
{
|
if (Send.LockList[i].DoorLockMacPort == macport)
|
{
|
///从列表移除当前门锁全部的旧数据;
|
Send.LockList.Remove(Send.LockList[i]);
|
i--;
|
}
|
}
|
Read();
|
//关闭刷新View;
|
middle.EndHeaderRefreshing();
|
};
|
//Read();
|
CommonPage.Loading.Start();
|
new System.Threading.Thread(() =>
|
{
|
Application.RunOnMainThread(() =>
|
{
|
Read();
|
CommonPage.Loading.Hide();
|
});
|
})
|
{ IsBackground = true }.Start();
|
|
}
|
/// <summary>
|
/// 读取当前门锁的云端数据;
|
/// </summary>
|
public async void Read()
|
{
|
bool d = false;
|
string macport = Send.CurrentDoorLock.DeviceAddr + "_" + Send.CurrentDoorLock.DeviceEpoint.ToString();
|
for (int i = 0; i < Send.LockList.Count; i++)
|
{
|
if (Send.LockList[i].DoorLockMacPort == macport)
|
{
|
///已经存在该门锁信息
|
d = true;
|
break;
|
}
|
}
|
CommonPage.Loading.Start();
|
if (!d)
|
{
|
var allMemberslist = await Send.AllMembers(macport);
|
Send.LockList.AddRange(allMemberslist);
|
}
|
UserAllView(macport);
|
CommonPage.Loading.Hide();
|
}
|
/// <summary>
|
/// 显示所有用户
|
/// </summary>
|
public void UserAllView(string macport)
|
{
|
middle.RemoveAll();
|
for (int i = 0; i < Send.LockList.Count; i++)
|
{
|
var user = Send.LockList[i];
|
if (user.DoorLockMacPort != macport)
|
{
|
continue;
|
}
|
var userFramelayout = new FrameLayout
|
{
|
Height = Application.GetRealHeight(160),
|
BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor,
|
};
|
middle.AddChidren(userFramelayout);
|
|
var userRow = new RowLayout
|
{
|
Y = Application.GetRealHeight(30),
|
Width = Application.GetRealWidth(1080 - 58 - 58),
|
Height = Application.GetRealHeight(130),
|
X = Application.GetRealWidth(58),
|
LineColor = ZigbeeColor.Current.LogicRowLayoutLineColor,
|
};
|
userFramelayout.AddChidren(userRow);
|
|
var usernameBtn = new Button
|
{
|
Text = user.UserName,
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = ZigbeeColor.Current.LogicTextBlackColor,
|
Width = Application.GetRealWidth(600),
|
Height = Application.GetRealHeight(130),
|
Tag = Send.LockList[i],
|
TextSize = 14,
|
};
|
userRow.AddChidren(usernameBtn);
|
|
var btntimeback = new Button
|
{
|
Width = Application.GetRealWidth(58),
|
Height = Application.GetRealHeight(58),
|
UnSelectedImagePath = "ZigeeLogic/next.png",
|
X = userRow.Width - Application.GetRealWidth(58),
|
Gravity = Gravity.CenterVertical,
|
};
|
userRow.AddChidren(btntimeback);
|
|
|
EventHandler<MouseEventArgs> userclick = (sender, e) =>
|
{
|
SelectedUserID(user);
|
};
|
usernameBtn.MouseUpEventHandler += userclick;
|
btntimeback.MouseUpEventHandler += userclick;
|
userFramelayout.MouseUpEventHandler += userclick;
|
userRow.MouseUpEventHandler += userclick;
|
|
|
}
|
}
|
/// <summary>
|
/// 选择某个用户
|
/// </summary>
|
/// <param name="membershipIfon">触发源列表</param>
|
public void SelectedUserID(Send.MembershipIfon membershipIfon)
|
{
|
|
var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicViewBackgroundColor };
|
this.AddChidren(flMain);
|
|
flMain.MouseUpEventHandler += (sender1, e1) =>
|
{
|
flMain.RemoveFromParent();
|
};
|
|
|
|
var lockcolorfra1 = new FrameLayout
|
{
|
|
Width = Application.GetRealWidth(1080),
|
Height = Application.GetRealHeight(530),
|
Y = Application.GetRealHeight(1920 - 530),
|
BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor,
|
Radius = (uint)Application.GetRealHeight(60),
|
};
|
flMain.AddChidren(lockcolorfra1);
|
lockcolorfra1.SetCornerWithSameRadius(Application.GetRealHeight(58), HDLUtils.RectCornerTopLeft | HDLUtils.RectCornerTopRight);
|
|
#region -------取消 完成
|
var lockRow = new RowLayout
|
{
|
Height = Application.GetRealHeight(140),
|
LineColor = ZigbeeColor.Current.LogicRowLayoutLineColor,
|
|
};
|
lockcolorfra1.AddChidren(lockRow);
|
var Btncancel = new Button
|
{
|
TextID = MyInternationalizationString.cancel,
|
TextColor = ZigbeeColor.Current.LogicBtnCancelColor,
|
Height = Application.GetRealHeight(140),
|
Width = Application.GetRealWidth(200),
|
X = Application.GetRealWidth(80),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextSize = 14,
|
};
|
lockRow.AddChidren(Btncancel);
|
Btncancel.MouseUpEventHandler += (sender16, e16) =>
|
{
|
flMain.RemoveFromParent();
|
UserView.HomePage.Instance.ScrollEnabled = true;
|
};
|
|
var Btntitle = new Button
|
{
|
TextID = MyInternationalizationString.security,
|
TextColor = ZigbeeColor.Current.LogicBtnTypeColor,
|
Height = Application.GetRealHeight(140),
|
Width = Application.GetRealWidth(320),
|
TextAlignment = TextAlignment.Center,
|
X = Btncancel.Right + Application.GetRealWidth(100),
|
TextSize = 16,
|
Text = membershipIfon.UserName,
|
};
|
lockRow.AddChidren(Btntitle);
|
var Btncomplete = new Button
|
{
|
TextID = MyInternationalizationString.complete,
|
TextColor = ZigbeeColor.Current.LogicBtnCompleteColor,
|
Height = Application.GetRealHeight(140),
|
Width = Application.GetRealWidth(200),
|
TextAlignment = TextAlignment.CenterRight,
|
X = Btntitle.Right + Application.GetRealWidth(100),
|
TextSize = 14,
|
|
};
|
lockRow.AddChidren(Btncomplete);
|
#endregion
|
|
string SelectedLockStatus = "";
|
lockcolorfra1.Y = Application.GetRealHeight(1920 - 140 - (160 * membershipIfon.UserIdMode.Count) - 20 - 50);
|
lockcolorfra1.Height = Application.GetRealHeight(140 + (160 * membershipIfon.UserIdMode.Count) + 20 + 50);
|
///定义两个变量记录选中状态;
|
string attriButeId = "";
|
string attriButeData2 = "";
|
string modeName = "";
|
for (int j = 0; j < membershipIfon.UserIdMode.Count; j++)
|
{
|
var userIdmode = membershipIfon.UserIdMode[j];
|
var doorlockfra = new FrameLayout
|
{
|
Height = Application.GetRealHeight(160),
|
Y = lockRow.Bottom + Application.GetRealHeight(20 + 160 * j),
|
};
|
lockcolorfra1.AddChidren(doorlockfra);
|
|
var doorlockRow = new RowLayout
|
{
|
Y = Application.GetRealHeight(30),
|
Width = Application.GetRealWidth(920),
|
Height = Application.GetRealHeight(130),
|
X = Application.GetRealWidth(80),
|
LineColor = ZigbeeColor.Current.LogicRowLayoutLineColor,
|
};
|
doorlockfra.AddChidren(doorlockRow);
|
|
var doorlockBtn = new Button
|
{
|
Width = Application.GetRealWidth(600),
|
TextAlignment = TextAlignment.CenterLeft,
|
TextColor = ZigbeeColor.Current.LogicBtnNotSelectedColor,
|
Text = userIdmode.ModeName,
|
TextSize = 14,
|
};
|
doorlockRow.AddChidren(doorlockBtn);
|
|
var doorlockSelected = new Button
|
{
|
X = Application.GetRealWidth(860),
|
Width = Application.GetMinRealAverage(60),
|
Height = Application.GetMinRealAverage(60),
|
UnSelectedImagePath = "ZigeeLogic/selected.png",
|
Visible = false,
|
Gravity = Gravity.CenterVertical,
|
|
};
|
doorlockRow.AddChidren(doorlockSelected);
|
if ((membershipIfon.UserIdMode.Count - 1) == j)
|
{
|
doorlockRow.LineColor = ZigbeeColor.Current.LogicBackgroundColor;
|
}
|
EventHandler<MouseEventArgs> doorlockclick = (sender2, e2) =>
|
{
|
SelectedLockStatus = "DoorLock";
|
selectedIcon.Visible = false;
|
selectedIcon = doorlockSelected;
|
doorlockSelected.Visible = true;
|
//doorlockBtn.TextColor = ZigbeeColor.Current.LogicBtnSelectedColor;
|
attriButeId = userIdmode.OpenMode.ToString();
|
attriButeData2 = userIdmode.UserId;
|
modeName = userIdmode.ModeName;
|
};
|
doorlockRow.MouseUpEventHandler += doorlockclick;
|
doorlockBtn.MouseUpEventHandler += doorlockclick;
|
doorlockSelected.MouseUpEventHandler += doorlockclick;
|
doorlockfra.MouseUpEventHandler += doorlockclick;
|
///显示之前的状态
|
if (conditionsIndex != -1)
|
{
|
var s = Common.Logic.CurrentLogic.Conditions[conditionsIndex];
|
if (s["AttriButeId"] == userIdmode.OpenMode.ToString() && s["AttriButeData2"] == userIdmode.UserId)
|
{
|
selectedIcon.Visible = false;
|
selectedIcon = doorlockSelected;
|
doorlockSelected.Visible = true;
|
}
|
|
|
}
|
}
|
|
Btncomplete.MouseUpEventHandler += (sender, e) =>
|
{
|
var lockConditionsInfo = new Dictionary<string, string>();
|
lockConditionsInfo.Add("Type", "1");
|
lockConditionsInfo.Add("IsValid", "1");
|
lockConditionsInfo.Add("MacAddr", Send.CurrentDoorLock.DeviceAddr);
|
lockConditionsInfo.Add("Epoint", Send.CurrentDoorLock.DeviceEpoint.ToString());
|
lockConditionsInfo.Add("Cluster_ID", "64529");
|
lockConditionsInfo.Add("AttriButeId", attriButeId);
|
lockConditionsInfo.Add("AttriButeData2", attriButeData2);
|
lockConditionsInfo.Add("AttriButeData1", "2");
|
lockConditionsInfo.Add("Range", "0");
|
var accounts = new Dictionary<string, string>();
|
accounts.Add("Type", "1");
|
accounts.Add("Account", membershipIfon.UserName + modeName);
|
accounts.Add("UserId", attriButeData2);
|
if (SelectedLockStatus != "")
|
{
|
if (conditionsIndex == -1)
|
{
|
bool addCondition = false;
|
bool addAccount = false;
|
for (int i = 0; i < Common.Logic.CurrentLogic.Conditions.Count; i++)
|
{
|
if (Common.Logic.CurrentLogic.Conditions[i]["Type"] == "1")
|
{
|
if ((Common.Logic.CurrentLogic.Conditions[i]["MacAddr"] == Send.CurrentDoorLock.DeviceAddr) && (Common.Logic.CurrentLogic.Conditions[i]["Epoint"] == Send.CurrentDoorLock.DeviceEpoint.ToString()))
|
{
|
if (Common.Logic.CurrentLogic.Conditions[i]["AttriButeId"] == lockConditionsInfo["AttriButeId"] && Common.Logic.CurrentLogic.Conditions[i]["AttriButeData2"] == lockConditionsInfo["AttriButeData2"])
|
{
|
addCondition = true;
|
break;
|
}
|
}
|
}
|
}
|
if (!addCondition)
|
{
|
Common.Logic.CurrentLogic.Conditions.Add(lockConditionsInfo);
|
}
|
|
for (int i = 0; i < Common.Logic.CurrentLogic.Accounts.Count; i++)
|
{
|
if (Common.Logic.CurrentLogic.Accounts[i]["Type"] == "1")
|
{
|
if (Common.Logic.CurrentLogic.Accounts[i]["UserId"] == attriButeData2)
|
{
|
addAccount = true;
|
break;
|
}
|
}
|
}
|
if (!addAccount)
|
{
|
Common.Logic.CurrentLogic.Accounts.Add(accounts);
|
}
|
}
|
else
|
{
|
///找出之前的旧数据移除掉,再重新添加新数据;
|
string accountuserId = Common.Logic.CurrentLogic.Conditions[conditionsIndex]["AttriButeData2"];
|
Common.Logic.CurrentLogic.Conditions.RemoveAt(conditionsIndex);
|
Common.Logic.CurrentLogic.Conditions.Insert(conditionsIndex, lockConditionsInfo);
|
for (int i = 0; i < Common.Logic.CurrentLogic.Accounts.Count; i++)
|
{
|
if (Common.Logic.CurrentLogic.Accounts[i]["Type"] == "1")
|
{
|
///找出之前的旧数据移除掉,再重新添加新数据;
|
if (Common.Logic.CurrentLogic.Accounts[i]["UserId"] == accountuserId)
|
{
|
Common.Logic.CurrentLogic.Accounts.RemoveAt(i);
|
Common.Logic.CurrentLogic.Accounts.Insert(i, accounts);
|
break;
|
}
|
}
|
}
|
|
}
|
|
}
|
else
|
{
|
if (conditionsIndex == -1)
|
{
|
var alert = new Alert(Language.StringByID(MyInternationalizationString.Prompt),
|
Language.StringByID(MyInternationalizationString.usertip),
|
Language.StringByID(MyInternationalizationString.confrim));
|
alert.Show();
|
return;
|
}
|
}
|
var lockLogicCommunalPage = new LockLogicCommunalPage();
|
UserView.HomePage.Instance.AddChidren(lockLogicCommunalPage);
|
UserView.HomePage.Instance.PageIndex += 1;
|
lockLogicCommunalPage.Show(() => { });
|
};
|
}
|
|
}
|
}
|