using Shared;
using HDL_ON.UI.CSS;
using HDL_ON.Stan;
using System;
using System.Collections.Generic;
using System.Text;
using HDL_ON.Entity;
using HDL_ON.DAL.Server;
namespace HDL_ON.UI
{
///
/// 门锁的选择日期时间界面
///
public class DoorLockUnlockMethordManagerPage : EditorCommonForm
{
#region ■ 变量声明___________________________
///
/// 列表控件
///
private VerticalFrameControl listView = null;
///
/// 开锁方式列表
///
private List listUnlockInfo = new List();
///
/// 成员列表
///
private List listMember = null;
///
/// 白色背景的容器控件集合(坐标变更时使用)
///
private List listWhiteFrame = new List();
///
/// 选择的场景(key:门锁的数据库主键 value:场景列表的主键)
///
private Dictionary> dicSelectScene = new Dictionary>();
///
/// 门锁对象
///
private Function doorDevice = null;
#endregion
#region ■ 初始化_____________________________
///
/// 画面显示(底层会固定调用此方法,借以完成画面创建)
///
/// 门锁对象
/// 成员列表
public void ShowForm(Function i_doorDevice, List i_listMember)
{
this.doorDevice = i_doorDevice;
this.listMember = i_listMember;
this.dicSelectScene = new Dictionary>();
//开锁方式管理
base.SetTitleText(Language.StringByID(StringId.UnlockingManagement));
//初始化中部信息
this.InitMiddleFrame();
}
///
/// 初始化中部信息
///
private void InitMiddleFrame()
{
//清空bodyFrame
this.ClearBodyFrame();
//列表控件
this.listView = new VerticalFrameControl();
listView.Height = bodyFrameLayout.Height;
bodyFrameLayout.AddChidren(listView);
//打开转圈的那个东西
this.ShowProgressBar();
HdlThreadLogic.Current.RunThread(() =>
{
//初始化开锁方式信息列表
var result = this.InitUnlockMethordInfoFromClound();
//关闭转圈的那个东西
this.CloseProgressBar();
if (result == false)
{
return;
}
HdlThreadLogic.Current.RunMain(() =>
{
//初始化未分配控件
this.InitNotAssignControl();
//初始化全部成员控件
this.InitAllMemberControl();
//调整桌布大小
this.listView.AdjustTableHeight();
});
});
}
#endregion
#region ■ 初始化未分配控件___________________
///
/// 初始化未分配控件
///
private void InitNotAssignControl()
{
//先初始化
this.listWhiteFrame = new List();
//获取未分配的开锁方式
var listInfo = new List();
foreach (var info in this.listUnlockInfo)
{
if (info.UserId != string.Empty)
{
continue;
}
listInfo.Add(info);
}
//白色背景容器
var frameBack = new NormalFrameLayout();
frameBack.Y = Application.GetRealHeight(12);
frameBack.Width = Application.GetRealWidth(343);
frameBack.Gravity = Gravity.CenterHorizontal;
frameBack.MainKey = "NotAssign";
frameBack.Radius = (uint)Application.GetRealWidth(12);
frameBack.Height = Application.GetRealHeight(50);
frameBack.BackgroundColor = CSS_Color.MainBackgroundColor;
frameBack.Visible = listInfo.Count > 0;
this.listView.frameTable.AddChidren(frameBack);
this.listWhiteFrame.Add(frameBack);
//未分配
var frameRow = new FrameRowControl();
frameBack.AddChidren(frameRow);
var btnNotAssign = frameRow.AddLeftCaption(Language.StringByID(StringId.Unallocated), 300);
btnNotAssign.TextSize = CSS_FontSize.SubheadingFontSize;
btnNotAssign.TextColor = CSS_Color.FirstLevelTitleColor;
frameRow.AddBottomLine();
for (int i = 0; i < listInfo.Count; i++)
{
//添加密码行控件
this.AddUnlockPasswordRowControl(frameBack, listInfo[i], i != listInfo.Count - 1);
}
//调整桌布高度
listView.AdjustChidrenFrameHeight(frameBack, 0);
}
#endregion
#region ■ 初始化成员控件_____________________
///
/// 初始化全部成员控件
///
private void InitAllMemberControl()
{
//头像列表
var listIcon = new List();
foreach (var info in this.listMember)
{
//根据成员信息初始化成员控件
var btnIcon = this.InitMemberControlByMemberInfo(info);
listIcon.Add(btnIcon);
}
//再加一个空白间隙
var frameSpace = new NormalFrameLayout();
frameSpace.Height = Application.GetRealHeight(12);
frameSpace.Y = this.listView.frameTable.GetChildren(this.listView.frameTable.ChildrenCount - 1).Bottom;
this.listView.frameTable.AddChidren(frameSpace);
this.listWhiteFrame.Add(frameSpace);
//下载用户头像
this.DownLoadUserIcon(listIcon);
}
///
/// 根据成员信息初始化成员控件
///
private ImageView InitMemberControlByMemberInfo(ResidenceMemberInfo memberInfo)
{
//获取分配给这个成员的开锁方式
var listInfo = new List();
foreach (var info in this.listUnlockInfo)
{
if (info.UserId != memberInfo.childAccountId)
{
continue;
}
listInfo.Add(info);
}
//白色背景容器
var frameBack = new NormalFrameLayout();
frameBack.Width = Application.GetRealWidth(343);
if (listInfo.Count > 0)
{
frameBack.Y = this.listView.frameTable.GetChildren(this.listView.frameTable.ChildrenCount - 1).Bottom + Application.GetRealHeight(12);
}
else
{
//如果没有开锁方式,则暂时隐藏
frameBack.Visible = false;
}
frameBack.Gravity = Gravity.CenterHorizontal;
frameBack.MainKey = memberInfo.childAccountId;
frameBack.Radius = (uint)Application.GetRealWidth(12);
frameBack.Height = Application.GetRealHeight(80);
frameBack.BackgroundColor = CSS_Color.MainBackgroundColor;
this.listView.frameTable.AddChidren(frameBack);
this.listWhiteFrame.Add(frameBack);
//用户行
var frameUserRow = new FrameRowControl();
frameUserRow.Width = frameBack.Width;
frameUserRow.Height = Application.GetRealHeight(80);
frameBack.AddChidren(frameUserRow);
//用户头像
var btnUserIcon = new ImageView();
btnUserIcon.X = HdlControlResourse.XXLeft;
btnUserIcon.Width = Application.GetRealWidth(48);
btnUserIcon.Height = Application.GetRealWidth(48);
btnUserIcon.Gravity = Gravity.CenterVertical;
btnUserIcon.ImagePath = "LoginIcon/2.png";
btnUserIcon.Radius = (uint)btnUserIcon.Height / 2;
frameUserRow.AddChidren(btnUserIcon, ChidrenBindMode.NotBind);
//用户名
var btnUserName = frameUserRow.AddLeftCaption(memberInfo.nickName, 150);
btnUserName.X = btnUserIcon.Right + Application.GetRealWidth(12);
btnUserName.TextColor = CSS_Color.FirstLevelTitleColor;
//底线
frameUserRow.AddBottomLine();
//成员身份背景图片
var frameUserType = new FrameLayout();
frameUserType.X = Application.GetRealWidth(220);
frameUserType.Y = Application.GetRealHeight(16);
frameUserType.Height = Application.GetRealHeight(58);
frameUserType.Width = Application.GetRealWidth(180);
frameUserType.BackgroundImagePath = "PersonalCenter/UserTypebg2.png";//用最长图标的那个
frameUserRow.AddChidren(frameUserType, ChidrenBindMode.NotBind);
//成员身份翻译
var btnUserTypeName = new NormalViewControl(270, 54, true);
btnUserTypeName.X = Application.GetRealWidth(35);
btnUserTypeName.Y = Application.GetRealHeight(-2);
btnUserTypeName.TextColor = CSS_Color.MainBackgroundColor;
btnUserTypeName.TextSize = CSS_FontSize.PromptFontSize_FirstLevel;
btnUserTypeName.TextID = memberInfo.childAccountType == "ADMIN" ? StringId.Administrators : StringId.Member;
btnUserTypeName.Width = btnUserTypeName.GetRealWidthByText();
frameUserType.AddChidren(btnUserTypeName);
//按照控件实际长度,变更背景图的X轴 Application.GetRealWidth(10)为右边余白
frameUserType.X = frameBack.Width - btnUserTypeName.X - btnUserTypeName.Width - Application.GetRealWidth(10);
for (int i = 0; i < listInfo.Count; i++)
{
//添加密码行控件
this.AddUnlockPasswordRowControl(frameBack, listInfo[i], i != listInfo.Count - 1);
}
//调整桌布高度
listView.AdjustChidrenFrameHeight(frameBack, 0);
return btnUserIcon;
}
#endregion
#region ■ 生成密码行控件_____________________
///
/// 生成密码行控件
///
/// 父控件
/// 开锁方式信息
/// 是否添加底线
private void AddUnlockPasswordRowControl(NormalFrameLayout frameFather, UnlockMethordInfo unlockInfo, bool addLine)
{
//行控件
var frameRow = new FrameRowControl();
frameRow.MainKey = unlockInfo.Id;
frameRow.RightOffset = Application.GetRealWidth(-32);
if (frameFather.ChildrenCount > 0)
{
//往最底下添加
frameRow.Y = frameFather.GetChildren(frameFather.ChildrenCount - 1).Bottom;
}
frameFather.AddChidren(frameRow);
if (addLine == true)
{
frameRow.AddBottomLine();
}
//开锁方式备注
var btnCaption = frameRow.AddLeftCaption(unlockInfo.Remark, 120);
btnCaption.TextColor = CSS_Color.FirstLevelTitleColor;
//场景联动图标
IconViewControl btnScene = null;
//备注编辑图标
IconViewControl btnEditor = null;
//分配图标
IconViewControl btnMove = null;
//删除图标
IconViewControl btnDelete = null;
//更多图标
var btnMore = frameRow.AddMostRightEmptyIcon(28, 28);
btnMore.UnSelectedImagePath = "FunctionIcon/DoorLock/More.png";
btnMore.SelectedImagePath = "FunctionIcon/DoorLock/Hide.png";
btnMore.ButtonClickEvent += (sender, e) =>
{
btnMore.IsSelected = !btnMore.IsSelected;
btnEditor.Visible = btnMore.IsSelected;
btnMove.Visible = btnMore.IsSelected;
btnDelete.Visible = btnMore.IsSelected;
//变更分享场景图标的X轴
int intSceneX = btnMore.IsSelected == true ? btnEditor.X : btnMore.X;
btnScene.X = intSceneX - btnScene.Width - Application.GetRealWidth(12);
};
//删除图标
btnDelete = new IconViewControl(28);
btnDelete.UnSelectedImagePath = "FunctionIcon/DoorLock/Delete.png";
btnDelete.Gravity = Gravity.CenterVertical;
btnDelete.X = btnMore.X - btnDelete.Width - Application.GetRealWidth(12);
btnDelete.Visible = false;
frameRow.AddChidren(btnDelete, ChidrenBindMode.NotBind);
btnDelete.ButtonClickEvent += (sender, e) =>
{
//删除操作将被同步于实体锁上{0}是否还需要删除?
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Confirm, Language.StringByID(StringId.DeleteUnlockingMethordMsg), () =>
{
//删除开锁方式
this.DeleteUnlockMethrod(frameFather, unlockInfo);
}, Language.StringByID(StringId.ConfirmDeletion));
};
//分配图标
btnMove = new IconViewControl(28);
btnMove.UnSelectedImagePath = "FunctionIcon/DoorLock/Redistribution.png";
btnMove.Gravity = Gravity.CenterVertical;
btnMove.X = btnDelete.X - btnMove.Width - Application.GetRealWidth(12);
btnMove.Visible = false;
frameRow.AddChidren(btnMove, ChidrenBindMode.NotBind);
btnMove.ButtonClickEvent += (sender, e) =>
{
//分配开锁方式
this.DistributeUnlockMethord(frameFather, unlockInfo);
};
//编辑图标
btnEditor = new IconViewControl(28);
btnEditor.UnSelectedImagePath = "FunctionIcon/DoorLock/Editor.png";
btnEditor.Gravity = Gravity.CenterVertical;
btnEditor.X = btnMove.X - btnEditor.Width - Application.GetRealWidth(12);
btnEditor.Visible = false;
frameRow.AddChidren(btnEditor, ChidrenBindMode.NotBind);
btnEditor.ButtonClickEvent += (sender, e) =>
{
new UI.PublicAssmebly().LoadDialog_EditParater(StringId.EditorRemarkName, btnCaption.Text,(textValue)=>
{
btnCaption.Text = textValue;
}, StringId.RemarkNameCanNotEmpty, 0, new List());
};
//场景联动图标
btnScene = new IconViewControl(28);
btnScene.UnSelectedImagePath = "FunctionIcon/DoorLock/BindScene.png";
btnScene.Gravity = Gravity.CenterVertical;
btnScene.X = btnMore.X - btnScene.Width - Application.GetRealWidth(12);
frameRow.AddChidren(btnScene, ChidrenBindMode.NotBind);
btnScene.ButtonClickEvent += (sender, e) =>
{
//显示选择场景弹窗
this.ShowSelectSceneDialog(unlockInfo);
};
}
#endregion
#region ■ 调整白色容器控件的坐标及高度_______
///
/// 调整全部白色容器控件的坐标
///
private void AdjustAllWhiteFrameLocation()
{
//初始Y轴
int defultYY = 0;
for (int i = 0; i < this.listWhiteFrame.Count; i++)
{
var frame = this.listWhiteFrame[i];
//不显示的,不做处理
if (frame.Visible == false) { continue; }
//白色容器间的间距为12,最后一个是余白,不需要再添加间距
frame.Y = i != this.listWhiteFrame.Count - 1 ? defultYY + Application.GetRealHeight(12) : defultYY;
defultYY = frame.Bottom;
}
}
///
/// 调整白色容器控件的高度
///
/// 指定白色区域的容器控件
private void AdjustWhiteFrameHeight(NormalFrameLayout frameFather)
{
if (frameFather.ChildrenCount == 1)
{
//如果这个容器里面已经没有了开锁方式,则将它置顶,并隐藏
frameFather.Y = 0;
frameFather.Visible = false;
}
else
{
//从新计算它的高度
var rowLast = frameFather.GetChildren(frameFather.ChildrenCount - 1);
frameFather.Height = rowLast.Bottom;
if (rowLast is FrameRowControl)
{
//将它的底线移除掉
((FrameRowControl)rowLast).RemoveBottomLine();
}
}
}
#endregion
#region ■ 初始化开锁方式信息列表_____________
///
/// 初始化开锁方式信息列表
///
///
private bool InitUnlockMethordInfoFromClound()
{
//先初始优化
this.listUnlockInfo = new List();
for (int i = 0; i < 2; i++)
{
var unlockInfo = new UnlockMethordInfo();
unlockInfo.Id = "MimaKey" + i.ToString();
unlockInfo.Remark = "密码" + i;
this.listUnlockInfo.Add(unlockInfo);
}
for (int i = 0; i < 2; i++)
{
var unlockInfo = new UnlockMethordInfo();
unlockInfo.Id = "ZhiwenKey" + i.ToString();
unlockInfo.Remark = "指纹" + i;
this.listUnlockInfo.Add(unlockInfo);
}
return true;
}
///
/// 开锁方式信息
///
private class UnlockMethordInfo
{
///
/// 数据库主键
///
public string Id = string.Empty;
///
/// 密码备注
///
public string Remark = string.Empty;
///
/// 用户账号id
///
public string UserId = string.Empty;
}
#endregion
#region ■ 显示选择场景弹窗___________________
///
/// 显示选择场景弹窗
///
/// 开锁方式
private void ShowSelectSceneDialog(UnlockMethordInfo unlockInfo)
{
if (FunctionList.List.scenes.Count == 0)
{
//检测不到可供选择的场景
HdlMessageLogic.Current.ShowMassage(ShowMsgType.Tip, Language.StringByID(StringId.NotHadCanSelectScene));
return;
}
var listText = new List();
var listSelectIndex = new List();
var listSelect = new List();
if (this.dicSelectScene.ContainsKey(unlockInfo.Id) == true)
{
//当前已经选择了的场景
listSelect = this.dicSelectScene[unlockInfo.Id];
}
for (int i = 0; i < FunctionList.List.scenes.Count; i++)
{
var info = FunctionList.List.scenes[i];
listText.Add(info.name);
if (listSelect.Contains(info.userSceneId) == true)
{
//初始选择
listSelectIndex.Add(i);
}
}
//调起弹窗
var form = new BottomItemSelectControl(FunctionList.List.scenes.Count, Language.StringByID(StringId.SelectScene));
form.AddRowMenu(listText, listSelectIndex);
form.FinishOnlyEvent += (div, selectIndex) =>
{
if (div == 1)
{
this.dicSelectScene[unlockInfo.Id] = new List();
this.dicSelectScene[unlockInfo.Id].Add(FunctionList.List.scenes[selectIndex].userSceneId);
}
};
}
#endregion
#region ■ 删除开锁方式_______________________
///
/// 删除开锁方式
///
/// 父控件
/// 开锁信息
private void DeleteUnlockMethrod(NormalFrameLayout frameFather, UnlockMethordInfo unlockInfo)
{
//移除指定开锁方式的行控件
this.RemoveUnlockMethrodRowControl(frameFather, unlockInfo);
//调整白色容器控件的高度
this.AdjustWhiteFrameHeight(frameFather);
//调整全部白色容器控件的坐标
this.AdjustAllWhiteFrameLocation();
}
///
/// 移除指定开锁方式的行控件
///
/// 父控件
/// 开锁信息
private void RemoveUnlockMethrodRowControl(NormalFrameLayout frameFather, UnlockMethordInfo unlockInfo)
{
//从索引1开始,因为索引0是标题
for (int i = 1; i < frameFather.ChildrenCount; i++)
{
var row = frameFather.GetChildren(i) as FrameRowControl;
if (row == null || row.MainKey != unlockInfo.Id)
{
//不是它
continue;
}
//移除掉它
row.RemoveFromParent();
break;
}
//然后重新整一下全部行的Y轴
int newYY = frameFather.GetChildren(0).Bottom;
for (int i = 1; i < frameFather.ChildrenCount; i++)
{
var row = frameFather.GetChildren(i) as FrameRowControl;
if (row == null)
{
//理论上应该不会
continue;
}
row.Y = newYY;
newYY = row.Bottom;
}
}
#endregion
#region ■ 分配开锁方式_______________________
///
/// 分配开锁方式
///
/// 父控件
/// 开锁信息
private void DistributeUnlockMethord(NormalFrameLayout frameFather, UnlockMethordInfo unlockInfo)
{
//如果是未分配的开锁方式,则弹起成员选择窗口
if (frameFather.MainKey == "NotAssign")
{
var listText = new List();
foreach (var info in this.listMember)
{
listText.Add(info.nickName);
}
//调起弹窗
var form = new BottomItemSelectControl(this.listMember.Count, Language.StringByID(StringId.AssignTo));
form.AddRowMenu(listText, new List());
form.FinishOnlyEvent += (div, selectIndex) =>
{
if (div == 1)
{
//移除指定开锁方式的行控件
this.RemoveUnlockMethrodRowControl(frameFather, unlockInfo);
//调整白色容器控件的高度
this.AdjustWhiteFrameHeight(frameFather);
//添加新的开锁方式行控件
this.AddNewUnlockMethrodRowControl(this.listMember[selectIndex].childAccountId, unlockInfo);
//调整全部白色容器控件的坐标
this.AdjustAllWhiteFrameLocation();
//调整桌布高度
listView.AdjustTableHeight();
}
};
}
//如果是成员的,则把它放回未分配
else
{
//移除指定开锁方式的行控件
this.RemoveUnlockMethrodRowControl(frameFather, unlockInfo);
//调整白色容器控件的高度
this.AdjustWhiteFrameHeight(frameFather);
//添加新的开锁方式行控件到未分配
this.AddNewUnlockMethrodRowControl("NotAssign", unlockInfo);
//调整全部白色容器控件的坐标
this.AdjustAllWhiteFrameLocation();
//调整桌布高度
listView.AdjustTableHeight();
}
}
///
/// 添加新的开锁方式行控件
///
/// userId
/// 开锁方式信息
private void AddNewUnlockMethrodRowControl(string i_childId, UnlockMethordInfo unlockInfo)
{
NormalFrameLayout fatherFrame = null;
foreach (var frame in this.listWhiteFrame)
{
//获取指定的父控件
if (frame.MainKey != i_childId) { continue; }
fatherFrame = frame;
break;
}
//应该不会存在
if (fatherFrame == null) { return; }
if (fatherFrame.ChildrenCount > 1)
{
//先为最后一行画底线
var lastRow = fatherFrame.GetChildren(fatherFrame.ChildrenCount - 1) as FrameRowControl;
lastRow?.AddBottomLine();
}
else
{
//它可以显示出来了
fatherFrame.Visible = true;
}
//向指定的容器添加开锁方式控件
this.AddUnlockPasswordRowControl(fatherFrame, unlockInfo, true);
//调整白色容器控件的高度
this.AdjustWhiteFrameHeight(fatherFrame);
}
#endregion
#region ■ 下载用户头像_______________________
///
/// 下载用户头像
///
/// 头像控件列表,它的索引和this.listMember一致
private void DownLoadUserIcon(List listIcon)
{
//索引0是当前的登陆账号
listIcon[0].ImagePath = UserInfo.Current.headImagePagePath;
HdlThreadLogic.Current.RunThread(() =>
{
for (int i = 1; i < this.listMember.Count; i++)
{
var resultData = ImageUtlis.Current.DownHeadImageByImageKey(this.listMember[i].memberHeadIcon, true, this.listMember[i].childAccountRegionUrl);
if (this.Parent == null)
{
//界面已经关闭
return;
}
if (resultData != null && resultData.Length > 0)
{
int nowIndex = i;
HdlThreadLogic.Current.RunMain(() =>
{
listIcon[nowIndex].ImageBytes = resultData;
}, ShowErrorMode.NO);
}
System.Threading.Thread.Sleep(200);
}
}, ShowErrorMode.NO);
}
#endregion
}
}