using System; using System.Collections.Generic; using System.Text; namespace Shared.Phone.UserCenter.DeviceDoorLock { /// /// 门锁记录类型筛选界面 /// public class DoorLockScreeningTypeForm : DialogCommonForm { #region ■ 变量声明___________________________ /// /// 确定选择的回调函数,如果存在-1,则代表全选 /// public Action, List> FinishSelectEvent = null; /// /// 当前选择用户((-1:所有 -9999:其他)) /// private List listSelectUser = new List(); /// /// 当前选择的开锁方式(-1:所有 0:密码 15:指纹 3:IC卡 9000:常开模式(自定义的)) /// private List listSelectLock = new List(); /// /// 前回的选择用户(重置选项专用) /// private List listOldSelectUser = new List(); /// /// 前回的选择开锁方式(重置选项专用) /// private List listOldSelectLock = new List(); #endregion #region ■ 初始化_____________________________ /// /// 画面显示(底层会固定调用此方法,借以完成画面创建) /// /// 用户的显示文本(key + 文本) /// 当前选择的用户 /// 当前选择的开锁方式 public void ShowForm(Dictionary dicUser, List nowSelectUser, List nowSelectLock) { this.listSelectUser.Clear(); this.listSelectUser.AddRange(nowSelectUser); this.listSelectLock.Clear(); this.listSelectLock.AddRange(nowSelectLock); this.listOldSelectUser.Clear(); this.listOldSelectUser.AddRange(nowSelectUser); this.listOldSelectLock.Clear(); this.listOldSelectLock.AddRange(nowSelectLock); //初始化中部信息 this.InitMiddleFrame(dicUser); } /// /// 初始化中部信息 /// private void InitMiddleFrame(Dictionary dicUser) { //弧度的圆的一半的高度(固定) int halfRoundHeigth = Application.GetRealHeight(116) / 2; //头部高度 int topHeight = Application.GetRealHeight(195); //搞一个透明的框 var frameTransparent = new FrameLayout(); frameTransparent.Y = Application.GetRealHeight(933); frameTransparent.Height = Application.GetRealHeight(988) + halfRoundHeigth * 2;//高度就是要它超过,随便搞的 frameTransparent.BackgroundColor = UserCenterColor.Current.Transparent; bodyFrameLayout.AddChidren(frameTransparent); //明细列表的桌布,白色背景(它与实际高度小了半个弧度的圆) var detailBackFrame = new NormalFrameLayout(); detailBackFrame.Y = halfRoundHeigth; detailBackFrame.Height = frameTransparent.Height; detailBackFrame.BackgroundColor = UserCenterColor.Current.White; frameTransparent.AddChidren(detailBackFrame); //弧度的圆 var rowRound = new FrameLayout(); rowRound.Width = bodyFrameLayout.Width; rowRound.Height = halfRoundHeigth * 2; rowRound.BackgroundColor = UserCenterColor.Current.White; rowRound.Radius = (uint)halfRoundHeigth; frameTransparent.AddChidren(rowRound); //类型筛选 var btnTitle = new NormalViewControl(detailBackFrame.Width, Application.GetRealHeight(63), false); btnTitle.Y = Application.GetRealHeight(35); btnTitle.TextID = R.MyInternationalizationString.uScreeningType; btnTitle.TextColor = UserCenterColor.Current.TextColor4; btnTitle.TextSize = 16; btnTitle.TextAlignment = TextAlignment.Center; rowRound.AddChidren(btnTitle); //重置 var btnReset = new NormalViewControl(200, 58, true); btnReset.X = Application.GetRealWidth(81); btnReset.Y = Application.GetRealHeight(40); btnReset.TextColor = UserCenterColor.Current.TextGrayColor1; btnReset.TextID = R.MyInternationalizationString.uResettion; rowRound.AddChidren(btnReset); btnReset.ButtonClickEvent += (sender, e) => { detailBackFrame.RemoveAll(); //线 var btnLine2 = new NormalViewControl(detailBackFrame.Width, HdlControlResourse.BottomLineHeight, false); btnLine2.Y = Application.GetRealHeight(138) - HdlControlResourse.BottomLineHeight - halfRoundHeigth; btnLine2.BackgroundColor = UserCenterColor.Current.ButtomLine; detailBackFrame.AddChidren(btnLine2); this.listSelectUser.Clear(); this.listSelectUser.AddRange(listOldSelectUser); this.listSelectLock.Clear(); this.listSelectLock.AddRange(listOldSelectLock); //初始化选择用户控件 this.InitUserSelectControl(dicUser, detailBackFrame, btnLine2.Bottom); //初始化选择开锁方式控件 this.InitUnLockSelectControl(detailBackFrame, btnLine2.Bottom); }; //确定 var btnFinish = new NormalViewControl(200, 58, true); btnFinish.X = Application.GetRealWidth(800); btnFinish.Y = Application.GetRealHeight(40); btnFinish.TextAlignment = TextAlignment.CenterRight; btnFinish.TextColor = 0xfffb744a; btnFinish.TextID = R.MyInternationalizationString.uConfirm1; rowRound.AddChidren(btnFinish); btnFinish.ButtonClickEvent += (sender, e) => { FinishSelectEvent?.Invoke(listSelectUser, listSelectLock); //关闭自身 this.CloseForm(); }; //线 var btnLine = new NormalViewControl(detailBackFrame.Width, HdlControlResourse.BottomLineHeight, false); btnLine.Y = Application.GetRealHeight(138) - HdlControlResourse.BottomLineHeight - halfRoundHeigth; btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine; detailBackFrame.AddChidren(btnLine); //初始化选择用户控件 this.InitUserSelectControl(dicUser, detailBackFrame, btnLine.Bottom); //初始化选择开锁方式控件 this.InitUnLockSelectControl(detailBackFrame, btnLine.Bottom); } #endregion #region ■ 选择用户___________________________ /// /// 初始化选择用户控件 /// /// /// /// private void InitUserSelectControl(Dictionary i_dicUser, FrameLayout detailBackFrame, int YY) { var dicUser = new Dictionary(); //所有 dicUser.Add("-1", Language.StringByID(R.MyInternationalizationString.uAll)); foreach (string keys in i_dicUser.Keys) { dicUser.Add(keys, i_dicUser[keys]); } //其他 dicUser.Add("-9999", Language.StringByID(R.MyInternationalizationString.uOther)); //选择用户 var btnTitle = new NormalViewControl(600, 58, true); btnTitle.TextID = R.MyInternationalizationString.uUserSelect; btnTitle.X = Application.GetRealWidth(81); btnTitle.Y = YY + Application.GetRealHeight(69); detailBackFrame.AddChidren(btnTitle); var frameDetail = new FrameLayout(); frameDetail.Name = "User"; if (dicUser.Count <= 8) { frameDetail.Height = Application.GetRealHeight(205); frameDetail.Y = btnTitle.Bottom + Application.GetRealHeight(35); frameDetail.Width = Application.GetRealWidth(912); frameDetail.Gravity = Gravity.CenterHorizontal; detailBackFrame.AddChidren(frameDetail); } else { var listView = new VerticalListControl(); listView.Height = Application.GetRealHeight(205); listView.Y = btnTitle.Bottom + Application.GetRealHeight(35); listView.Width = Application.GetRealWidth(912); listView.Gravity = Gravity.CenterHorizontal; detailBackFrame.AddChidren(listView); int rowCount = dicUser.Count % 4 != 0 ? (dicUser.Count / 4) + 1 : dicUser.Count / 4; frameDetail.Height = rowCount * Application.GetRealHeight(63 + 29); listView.AddChidren(frameDetail); } int tempXX = 0; int tempYY = 0; int count = 0; foreach (var keys in dicUser.Keys) { count++; //初始化点击按钮 var btnButton = this.InitUserSelectButton(listSelectUser.Contains(keys)); btnButton.Name = keys; btnButton.X = tempXX; btnButton.Y = tempYY; btnButton.Text = dicUser[keys]; frameDetail.AddChidren(btnButton); tempXX = btnButton.Right + Application.GetRealWidth(26); if (count % 4 == 0) { //X轴重置 tempXX = 0; //Y轴递增 tempYY = btnButton.Bottom + Application.GetRealHeight(29); } } //线 var btnLine = new NormalViewControl(Application.GetRealWidth(919), HdlControlResourse.BottomLineHeight, false); btnLine.Gravity = Gravity.CenterHorizontal; btnLine.Y = YY + Application.GetRealHeight(386); btnLine.BackgroundColor = UserCenterColor.Current.ButtomLine; detailBackFrame.AddChidren(btnLine); } #endregion #region ■ 选择开锁方式_______________________ /// /// 初始化选择开锁方式控件 /// /// private void InitUnLockSelectControl(FrameLayout detailBackFrame, int YY) { //选择开锁方式 var btnTitle = new NormalViewControl(600, 58, true); btnTitle.TextID = R.MyInternationalizationString.uSelectUnLockWay; btnTitle.X = Application.GetRealWidth(81); btnTitle.Y = YY + Application.GetRealHeight(464); detailBackFrame.AddChidren(btnTitle); var frameDetail = new FrameLayout(); frameDetail.Name = "Lock"; frameDetail.Height = Application.GetRealHeight(205); frameDetail.Y = btnTitle.Bottom + Application.GetRealHeight(35); frameDetail.Width = Application.GetRealWidth(912); frameDetail.Gravity = Gravity.CenterHorizontal; detailBackFrame.AddChidren(frameDetail); //所有 var btnAll = this.InitLockSelectButton(listSelectLock.Contains(-1)); btnAll.TextID = R.MyInternationalizationString.uAll; btnAll.Name = "-1"; frameDetail.AddChidren(btnAll); //密码 var btnPsw = this.InitLockSelectButton(listSelectLock.Contains(0)); btnPsw.X = btnAll.Right + Application.GetRealWidth(26); btnPsw.TextID = R.MyInternationalizationString.uPassword; btnPsw.Name = "0"; frameDetail.AddChidren(btnPsw); //指纹 var btnFinger = this.InitLockSelectButton(listSelectLock.Contains(15)); btnFinger.X = btnPsw.Right + Application.GetRealWidth(26); btnFinger.TextID = R.MyInternationalizationString.uFingerPrint; btnFinger.Name = "15"; frameDetail.AddChidren(btnFinger); //IC卡 var btnCard = this.InitLockSelectButton(listSelectLock.Contains(3)); btnCard.X = btnFinger.Right + Application.GetRealWidth(26); btnCard.TextID = R.MyInternationalizationString.uIcCard; btnCard.Name = "3"; frameDetail.AddChidren(btnCard); //常开模式 var btnNormallyOpen = this.InitLockSelectButton(listSelectLock.Contains(9000)); btnNormallyOpen.Y = btnAll.Bottom + Application.GetRealWidth(29); btnNormallyOpen.TextID = R.MyInternationalizationString.uNormallyOpenMode; btnNormallyOpen.Name = "9000"; frameDetail.AddChidren(btnNormallyOpen); //人脸识别 var btnFace = this.InitLockSelectButton(listSelectLock.Contains(14)); btnFace.X = btnNormallyOpen.Right + Application.GetRealWidth(26); btnFace.Y = btnNormallyOpen.Y; btnFace.TextID = R.MyInternationalizationString.uFaceRecognition; btnFace.Name = "14"; frameDetail.AddChidren(btnFace); //静脉纹 var btnStria = this.InitLockSelectButton(listSelectLock.Contains(13)); btnStria.X = btnFace.Right + Application.GetRealWidth(26); btnStria.Y = btnNormallyOpen.Y; btnStria.TextID = R.MyInternationalizationString.uStriaVenosus; btnStria.Name = "13"; frameDetail.AddChidren(btnStria); } #endregion #region ■ 初始化点击按钮_____________________ /// /// 初始化用户点击按钮 /// /// /// private NormalViewControl InitUserSelectButton(bool select) { var btnContr = new NormalViewControl(207, 63, true); btnContr.RadiusEx = 17; btnContr.TextAlignment = TextAlignment.Center; if (select == false) { btnContr.TextColor = UserCenterColor.Current.TextGrayColor3; btnContr.BackgroundColor = 0xffededed; } else { btnContr.TextColor = UserCenterColor.Current.White; btnContr.BackgroundColor = 0xff232323; } btnContr.ButtonClickEvent += (sender, e) => { var value = btnContr.Name; //取消 if (listSelectUser.Contains(value) == true) { if (btnContr.Name == "-1" || listSelectUser.Count == 1) { //不能取消【所有】,并且至少要选择一个 return; } btnContr.TextColor = UserCenterColor.Current.TextGrayColor3; btnContr.BackgroundColor = 0xffededed; listSelectUser.Remove(value); } //选择 else { btnContr.TextColor = UserCenterColor.Current.White; btnContr.BackgroundColor = 0xff232323; listSelectUser.Add(value); if (btnContr.Name == "-1") { //【所有】按钮处于选择状态时 this.ButtonAllSelectClick(btnContr); } else if(listSelectUser.Contains("-1") == true) { //所有按钮取消 var btnAll = btnContr.Parent.GetChildren(0); ((NormalViewControl)btnAll).TextColor = UserCenterColor.Current.TextGrayColor3; btnAll.BackgroundColor = 0xffededed; listSelectUser.Remove("-1"); } } }; return btnContr; } /// /// 初始化开锁方式点击按钮 /// /// /// private NormalViewControl InitLockSelectButton(bool select) { var btnContr = new NormalViewControl(207, 63, true); btnContr.RadiusEx = 17; btnContr.TextAlignment = TextAlignment.Center; if (select == false) { btnContr.TextColor = UserCenterColor.Current.TextGrayColor3; btnContr.BackgroundColor = 0xffededed; } else { btnContr.TextColor = UserCenterColor.Current.White; btnContr.BackgroundColor = 0xff232323; } btnContr.ButtonClickEvent += (sender, e) => { //取消 int index = Convert.ToInt32(btnContr.Name); if (listSelectLock.Contains(index) == true) { if (index == -1 || listSelectLock.Count == 1) { //不能取消【所有】,并且至少要选择一个 return; } btnContr.TextColor = UserCenterColor.Current.TextGrayColor3; btnContr.BackgroundColor = 0xffededed; listSelectLock.Remove(index); } //选择 else { btnContr.TextColor = UserCenterColor.Current.White; btnContr.BackgroundColor = 0xff232323; listSelectLock.Add(index); if (index == -1) { //【所有】按钮处于选择状态时 this.ButtonAllSelectClick(btnContr); } else if (listSelectLock.Contains(-1) == true) { //所有按钮取消 var btnAll = btnContr.Parent.GetChildren(0); ((NormalViewControl)btnAll).TextColor = UserCenterColor.Current.TextGrayColor3; btnAll.BackgroundColor = 0xffededed; listSelectLock.Remove(-1); } } }; return btnContr; } #endregion #region ■ 界面关闭___________________________ /// /// 界面关闭 /// public override void CloseFormBefore() { this.FinishSelectEvent = null; base.CloseFormBefore(); } #endregion #region ■ 一般方法___________________________ /// /// 【所有】按钮处于选择状态时 /// /// private void ButtonAllSelectClick(NormalViewControl btnContr) { var frameParent = (FrameLayout)btnContr.Parent; for (int i = 0; ; i++) { var myView = frameParent.GetChildren(i); if (myView == null) { break; } if (myView.Name == btnContr.Name) { continue; } //非选择状态 ((NormalViewControl)myView).TextColor = UserCenterColor.Current.TextGrayColor3; myView.BackgroundColor = 0xffededed; if (frameParent.Name == "User") { listSelectUser.Remove(myView.Name); } else { listSelectLock.Remove(Convert.ToInt32(myView.Name)); } } } #endregion } }