黄学彪
2020-04-02 9904031f5291daaf56985146bb671f25e18ebbdf
ZigbeeApp/Shared/Phone/Device/Logic/DoorLockLogic/AddCondition.cs
@@ -17,13 +17,12 @@
        public void Show()
        {
            #region  上面的布局代码
            #region  界面布局代码
            TopView view = new TopView();
            this.AddChidren(view.TopRowView());
            view.toptitleNameBtn.TextID = MyInternationalizationString.userlist;
            view.clickBtn.MouseDownEventHandler += (sender, e) => { RemoveFromParent(); };
            #endregion
            middle = new VerticalRefreshLayout
            {
                Y = view.topRowLayout.Bottom,
@@ -31,6 +30,7 @@
                BackgroundColor = ZigbeeColor.Current.LogicMiddleBackgroundColor,
            };
            this.AddChidren(middle);
            #endregion
            middle.BeginHeaderRefreshingAction += () =>
            {
                //重新刷新logic列表
@@ -95,7 +95,6 @@
        /// </summary>
        public void UserAllView(string macport)
        {
            middle.RemoveAll();
            for (int i = 0; i < Send.LockList.Count; i++)
            {
                var user = Send.LockList[i];
@@ -103,218 +102,110 @@
                {
                    continue;
                }
                var userFramelayout = new FrameLayout
                FunView userView = new FunView();
                userView.iconBtn.Visible = false;
                userView.funnameBtn.X = Application.GetRealWidth(81);
                userView.funnameBtn.Text = user.UserName;
                userView.funnextBtn.X = Application.GetRealWidth(1080 - 81 - 58);
                userView.lineBtn.X = Application.GetRealWidth(81);
                userView.lineBtn.Width = Application.GetRealWidth(1080 - 81 - 58);
                if (Send.LockList.Count - 1 == i)
                {
                    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) =>
                    userView.funFrameLayout.Height = Application.GetRealHeight(160 + 20);//最后一行增加20高度;
                    userView.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBlankBackgroundColor;
                }
                middle.AddChidren(userView.FunFrameView());
                userView.clickviewBtn.MouseUpEventHandler += (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)
        /// <param name="user">触发源列表</param>
        public void SelectedUserID(Send.MembershipIfon user)
        {
            var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicViewBackgroundColor };
            this.AddChidren(flMain);
            flMain.MouseUpEventHandler += (sender1, e1) =>
            //元素超出9个就用上下滑动控件;
            VerticalScrolViewLayout vV = null;
            int count = user.UserIdMode.Count;
            if (count > 9)
            {
                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);
                ///元素超出9个;
                count = 6;
                //元素超出9个就用上下滑动控件;
                vV = new VerticalScrolViewLayout
                {
                    Y = Application.GetRealHeight(140 + 20),
                    Height = Application.GetRealHeight(160 * count),
                };
                //清除之前的控件;
                vV.RemoveAll();
            }
            #region  -------取消   完成
            var lockRow = new RowLayout
            var flMain = new FrameLayout { BackgroundColor = ZigbeeColor.Current.LogicTranslucentColor };
            this.AddChidren(flMain);
            CompleteView completeView = new CompleteView();
            flMain.AddChidren(completeView.Show(count));
            completeView.Btntitle.Text = user.UserName;
            EventHandler<MouseEventArgs> clickcancel = (sender, e) =>
            {
                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;
                flMain.RemoveFromParent();
            };
            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);
            flMain.MouseUpEventHandler += clickcancel;
            completeView.Btncancel.MouseUpEventHandler += clickcancel;
            #endregion
            ///定两个变量记录之前的只值;
            string userId = "";
            string openMode = "";
            string accountName = "";
            string SelectedDeviceStatuscondition = "";
            lockcolorfra1.Y = Application.GetRealHeight(1920 - 140 - (160 * membershipIfon.UserIdMode.Count) - 20 - 50);
            lockcolorfra1.Height = Application.GetRealHeight(140 + (160 * membershipIfon.UserIdMode.Count) + 20 + 50);
            if (membershipIfon.UserIdMode.Count > 9)
            for (int i = 0; i < user.UserIdMode.Count; i++)
            {
                ///元素超出10个,暂时默认显示10;
                lockcolorfra1.Y = Application.GetRealHeight(1920 - 140 - (160 * 9) - 20 - 50);
                lockcolorfra1.Height = Application.GetRealHeight(140 + (160 * 9) + 20 + 50);
            }
            string SelectedLockStatus = "";
            ///定义两个变量记录选中状态;
            string attriButeId = "";
            string attriButeData2 = "";
            string modeName = "";
                var userifon = user.UserIdMode[i];
            for (int j = 0; j < membershipIfon.UserIdMode.Count; j++)
            {
                var userIdmode = membershipIfon.UserIdMode[j];
                var doorlockfra = new FrameLayout
                mFunView lockView = new mFunView();
                if (user.UserIdMode.Count > 9)
                {
                    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;
                    //元素超出9个就用上下滑动控件;
                    completeView.Show(count).AddChidren(vV);
                    vV.AddChidren(lockView.Show());
                }
                EventHandler<MouseEventArgs> doorlockclick = (sender2, e2) =>
                else
                {
                    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;
                    lockView.frameLayout.Y = Application.GetRealHeight(140 + 20 + 160 * i);
                    completeView.Show(count).AddChidren(lockView.Show());
                }
                lockView.titleBtn.Text = userifon.ModeName;
                if (string.IsNullOrEmpty(doorlockBtn.Text))
                if ((user.UserIdMode.Count - 1) == i)
                {
                    lockView.lineBtn.BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor;
                }
                lockView.clickviewBtn.MouseUpEventHandler += (sender, e) =>
                {
                    SelectedDeviceStatuscondition = "DoorLock";
                    selectedIcon.Visible = false;
                    selectedIcon = lockView.selectedIconBtn;
                    lockView.selectedIconBtn.Visible = true;
                    userId = userifon.UserId;
                    openMode = userifon.OpenMode.ToString();
                    accountName = completeView.Btntitle.Text + lockView.titleBtn.Text;
                };
                if (string.IsNullOrEmpty(lockView.titleBtn.Text))
                {
                    string strname = "";
                    switch (userIdmode.OpenMode)
                    switch (userifon.OpenMode)
                    {
                        case 0:
                            {
@@ -332,25 +223,31 @@
                            }
                            break;
                    }
                    doorlockBtn.Text = userIdmode.UserId + strname;
                    lockView.titleBtn.Text = userifon.UserId + strname;
                }
                ///显示之前的状态
                if (conditionsIndex != -1)
                {
                    var s = Common.Logic.CurrentLogic.Conditions[conditionsIndex];
                    if (s["AttriButeId"] == userIdmode.OpenMode.ToString() && s["AttriButeData2"] == userIdmode.UserId)
                    ///显示之前的状态
                    if (conditionsIndex != -1)
                    {
                        selectedIcon.Visible = false;
                        selectedIcon = doorlockSelected;
                        doorlockSelected.Visible = true;
                        var s = Common.Logic.CurrentLogic.Conditions[conditionsIndex];
                        if (s["AttriButeId"] == userifon.OpenMode.ToString() && s["AttriButeData2"] == userifon.UserId)
                        {
                            selectedIcon.Visible = false;
                            selectedIcon = lockView.selectedIconBtn;
                            lockView.selectedIconBtn.Visible = true;
                        }
                    }
                }
            }
            Btncomplete.MouseUpEventHandler += (sender, e) =>
            completeView.Btncomplete.MouseUpEventHandler += (sender, e) =>
            {
                var lockConditionsInfo = new Dictionary<string, string>();
                lockConditionsInfo.Add("Type", "1");
@@ -358,15 +255,16 @@
                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("AttriButeId", openMode);
                lockConditionsInfo.Add("AttriButeData2", userId);
                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 != "")
                accounts.Add("Account", Config.Instance.Guid);
                accounts.Add("AccountName",accountName);
                accounts.Add("UserId", userId);
                if (SelectedDeviceStatuscondition != "")
                {
                    if (conditionsIndex == -1)
                    {
@@ -386,24 +284,24 @@
                                }
                            }
                        }
                        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)
                                if (Common.Logic.CurrentLogic.Accounts[i]["UserId"] == userId)
                                {
                                    addAccount = true;
                                    break;
                                }
                            }
                        }
                        if (!addCondition)
                        {//没有存在数据新加
                            Common.Logic.CurrentLogic.Conditions.Add(lockConditionsInfo);
                        }
                        if (!addAccount)
                        {
                        {//没有存在数据新加
                            Common.Logic.CurrentLogic.Accounts.Add(accounts);
                        }
                    }
@@ -447,6 +345,6 @@
                lockLogicCommunalPage.Show(() => { });
            };
        }
    }
}