WJC
2019-10-18 2bc230cf2e7a7329c2329b07307a47b059835bbc
ZigbeeApp/Shared/Phone/UserCenter/Device/DeviceMacInfoEditorForm.cs
@@ -1,22 +1,22 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Shared.Common;
using Shared.Phone.UserView;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.Device
{
    /// <summary>
    /// 编辑设备的信息(这里修改的是MAC名,这个画面会更改MAC的物理名字)
    /// </summary>
    public class DeviceMacInfoEditorForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 设备对象
        /// </summary>
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Shared.Common;
using Shared.Phone.UserView;
using ZigBee.Device;
namespace Shared.Phone.UserCenter.Device
{
    /// <summary>
    /// 编辑设备的信息(这里修改的是MAC名,这个画面会更改MAC的物理名字)
    /// </summary>
    public class DeviceMacInfoEditorForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 设备对象
        /// </summary>
        private List<CommonDevice> listNewDevice = null;
        /// <summary>
        /// 列表控件
@@ -31,16 +31,16 @@
        /// </summary>
        private DeviceEnumInfo deviceEnumInfo = null;
        #endregion
        #endregion
        #region ■ 初始化_____________________________
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="deviceMac">设备mac地址</param>
        public void ShowForm(string deviceMac)
        {
        /// <param name="deviceMac">设备mac地址</param>
        public void ShowForm(string deviceMac)
        {
            this.listNewDevice = Common.LocalDevice.Current.GetDevicesByMac(deviceMac);
            //排序
            this.listNewDevice.Sort((obj1, obj2) =>
@@ -50,40 +50,41 @@
                    return 1;
                }
                return -1;
            });
            this.listDeviceType.Clear();
            });
            this.listDeviceType.Clear();
            foreach (var device in listNewDevice)
            {
                //收集设备类型
                this.listDeviceType.Add(device.Type);
            }
            //获取这一堆设备时属于什么类型的
            this.deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listNewDevice);
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDeviceInfo));
            //初始化右上角菜单
            this.deviceEnumInfo = Common.LocalDevice.Current.GetMyDeviceEnumInfo(listNewDevice);
            //设置标题信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uDeviceInfo));
            //初始化右上角菜单
            this.InitTopRightMenu();
            //初始化中部控件
            this.InitMiddleFrame();
            //重新获取硬件信息
            this.RefreshHardFirmwareInfo();
        }
            this.InitMiddleFrame();
            //重新获取硬件信息
            this.RefreshHardFirmwareInfo();
        }
        /// <summary>
        /// 初始化中部控件
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
            //初始化桌布
            this.InitFrameTable();
            var tableContr = new InformationEditorControl();
            this.listview = tableContr.InitControl(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 369, 1368);
            //图片
            var btnPic = new DeviceInfoIconControl(listNewDevice[0]);
@@ -93,12 +94,12 @@
            btnPic.InitControl();
            //设备备注
            string caption = Language.StringByID(R.MyInternationalizationString.uDeviceNote);
            string deviceName = Common.LocalDevice.Current.GetDeviceMacName(listNewDevice[0]);
            var btnNote = new FrameCaptionInputControl(caption, deviceName, listview.rowSpace / 2);
            listview.AddChidren(btnNote);
            btnNote.InitControl();
            //划线
            string caption = Language.StringByID(R.MyInternationalizationString.uDeviceNote);
            string deviceName = Common.LocalDevice.Current.GetDeviceMacName(listNewDevice[0]);
            var btnNote = new FrameCaptionInputControl(caption, deviceName, listview.rowSpace / 2);
            listview.AddChidren(btnNote);
            btnNote.InitControl();
            //划线
            btnNote.AddBottomLine();
            btnNote.txtInput.FinishInputEvent += () =>
            {
@@ -115,93 +116,75 @@
            };
            //设备类型
            caption = Language.StringByID(R.MyInternationalizationString.uDeviceType);
            deviceName = Common.LocalDevice.Current.GetDeviceObjectText(listNewDevice);
            caption = Language.StringByID(R.MyInternationalizationString.uDeviceType);
            deviceName = Common.LocalDevice.Current.GetDeviceObjectText(listNewDevice);
            var btnType = new FrameCaptionViewControl(caption, deviceName, listview.rowSpace / 2);
            btnType.UseClickStatu = false;
            listview.AddChidren(btnType);
            listview.AddChidren(btnType);
            btnType.InitControl();
            //划线
            //划线
            btnType.AddBottomLine();
            //所属区域
            var rowBeloneArea = new BelongAreaControl(listview.rowSpace / 2);
            listview.AddChidren(rowBeloneArea);
            rowBeloneArea.InitControl(Language.StringByID(R.MyInternationalizationString.uBelongArea), this.listNewDevice);
            //底线
            rowBeloneArea.AddBottomLine();
            var listCheck = new List<string>();
            rowBeloneArea.SelectRoomEvent += (roomKeys) =>
            {
                foreach (var device in this.listNewDevice)
                {
                    //保存这个设备属于哪个区域
                    device.DeviceRoomId = roomKeys;
                    device.ReSave();
                    var room = Room.CurrentRoom.GetRoomByDevice(device);
                    string mainKeys = LocalDevice.Current.GetDeviceMainKeys(device);
                    if (room == null)
                    {
                        //这里有点特殊,如果回路没有设置有区域的时候,才设置
                        listCheck.Add(mainKeys);
                        Room.CurrentRoom.ChangedRoom(device, roomKeys);
                    }
                    else if (listCheck.Contains(mainKeys) == true)
                    {
                        //如果这个回路之前都还没有区域,在本界面还没有关闭之前,可以无条件随便变更
                        Room.CurrentRoom.ChangedRoom(device, roomKeys);
                    }
                }
            };
            //添加全部菜单
            this.AddAllMenuRow();
            //初始化桌布完成
            tableContr.FinishInitControl(bodyFrameLayout, this.listview);
            tableContr = null;
            //保存
            var btnFinish = new BottomClickButton();
            //借用Y轴坐标(让这个区域不能点击菜单)
            var frameBack = new FrameLayout();
            frameBack.Y = btnFinish.Yaxis;
            frameBack.Height = bodyFrameLayout.Height - btnFinish.Yaxis;
            bodyFrameLayout.AddChidren(frameBack);
            btnFinish.TextID = R.MyInternationalizationString.uSave;
            bodyFrameLayout.AddChidren(btnFinish);
            btnFinish.ButtonClickEvent += (sender, e) =>
            var btnFinish = new BottomClickButton();
            btnFinish.TextID = R.MyInternationalizationString.uSave;
            bodyFrameLayout.AddChidren(btnFinish);
            btnFinish.ButtonClickEvent += (sender, e) =>
            {
                string oldName = Common.LocalDevice.Current.GetDeviceMacName(listNewDevice[0]);
                if (btnNote.Text.Trim() == string.Empty)
                {
                    btnNote.Text = oldName;
                }
                }
                if (oldName != btnNote.Text.Trim())
                {
                    //修改名字
                    this.DeviceReName(btnNote.Text.Trim(), true);
                }
                }
                else
                {
                    //关闭自身
                    this.CloseForm();
                }
                }
            };
            var realHeight = listview.GetChildren(0).Height * listview.ChildrenCount;
            if (bodyFrameLayout.Height - btnFinish.Yaxis + realHeight > listview.Height)
            {
                //促使被挡住的菜单能够向上滑动
                var frameTemp = new FrameLayout();
                frameTemp.Height = frameBack.Height + Application.GetRealHeight(115);
                listview.AddChidren(frameTemp);
            }
        }
        #endregion
        #region ■ 初始化桌布_________________________
        /// <summary>
        /// 初始化桌布
        /// </summary>
        private void InitFrameTable()
        {
            //弧度的圆的一半的高度(固定)
            int halfRoundHeigth = Application.GetRealHeight(116) / 2;
            //弧度的圆
            var btnRound = new NormalViewControl(bodyFrameLayout.Width, halfRoundHeigth * 2, false);
            btnRound.Y = Application.GetRealHeight(369);
            btnRound.BackgroundColor = UserCenterColor.Current.White;
            btnRound.Radius = (uint)halfRoundHeigth;
            bodyFrameLayout.AddChidren(btnRound);
            //明细列表的桌布,白色背景(覆盖弧度的圆的半边)
            var detailBackFrame = new FrameLayout();
            detailBackFrame.Y = btnRound.Bottom - btnRound.Height / 2;
            detailBackFrame.Height = Application.GetRealHeight(1368);//高度就是要它超过
            detailBackFrame.BackgroundColor = UserCenterColor.Current.White;
            bodyFrameLayout.AddChidren(detailBackFrame);
            //信息编辑
            var btnTile = new NormalViewControl(800, 60, true);
            btnTile.X = ControlCommonResourse.XXLeft;
            btnTile.TextSize = 15;
            btnTile.TextColor = UserCenterColor.Current.TextColor2;
            btnTile.TextID = R.MyInternationalizationString.uInfoEditor;
            detailBackFrame.AddChidren(btnTile);
            this.listview = new VerticalListControl(12);
            listview.Y = btnTile.Bottom + Application.GetRealHeight(17);
            listview.Height = Application.GetRealHeight(1368) - halfRoundHeigth - btnTile.Bottom - Application.GetRealHeight(17);
            detailBackFrame.AddChidren(listview);
        }
        #endregion
@@ -246,13 +229,13 @@
            }
        }
        #endregion
        #endregion
        #region ■ 用户管理(门锁)_____________________
        /// <summary>
        /// 添加【用户管理】行(门锁专用)
        /// </summary>
        /// </summary>
        private void AddUserManageRow()
        {
            //如果是智能门锁
@@ -264,11 +247,16 @@
                listview.AddChidren(btnRow);
                btnRow.AddLeftCaption(caption, 600);
                //向右图标
                btnRow.AddRightIconControl();
                btnRow.AddRightArrow();
                //底线
                btnRow.AddBottomLine();
                var doorLock = this.listNewDevice[0] as ZigBee.Device.DoorLock;
                btnRow.ButtonClickEvent += (sender, e) =>
                {
                    var userManagement = new Shared.Phone.UserCenter.DoorLock.UserManagement(doorLock);
                    Shared.Phone.UserView.HomePage.Instance.AddChidren(userManagement);
                    Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                    userManagement.Show();
                };
            }
        }
@@ -279,7 +267,7 @@
        /// <summary>
        /// 添加【远程开锁】行(门锁专用)
        /// </summary>
        /// </summary>
        private void AddRemoteUnLocksRow()
        {
            //如果是智能门锁
@@ -291,17 +279,27 @@
                btnRow.UseClickStatu = false;
                listview.AddChidren(btnRow);
                btnRow.AddLeftCaption(caption, 600);
                //向右图标
                var btnswitch = btnRow.AddMostRightEmptyIcon(104, 63);
                btnRow.ChangedChidrenBindMode(btnswitch, ChidrenBindMode.NotBind);
                btnswitch.UnSelectedImagePath = "Item/Switch.png";
                btnswitch.SelectedImagePath = "Item/SwitchSelected.png";
                //开关图标
                var btnswitch = btnRow.AddMostRightSwitchIcon();
                //底线
                btnRow.AddBottomLine();
                if (string.IsNullOrEmpty(ZigBee.Device.DoorLock.RemoteUnlockPassword) == false)
                {
                    btnswitch.IsSelected = true;
                }
               var doorLock= (ZigBee.Device.DoorLock)listNewDevice[0];
                btnswitch.ButtonClickEvent += (sender, e) =>
                {
                    btnswitch.IsSelected = !btnswitch.IsSelected;
                    if (btnswitch.IsSelected == true)
                    {
                        btnswitch.IsSelected = false;
                        ZigBee.Device.DoorLock.RemoteUnlockPassword = string.Empty;
                        return;
                    }
                    var frame = new DoorLock.DoorLockCommonLayout();
                    frame.RemotePasswordDialog((ZigBee.Device.DoorLock)listNewDevice[0], btnswitch.btnIcon);
                    frame = null;
                };
            }
        }
@@ -312,7 +310,7 @@
        /// <summary>
        /// 添加【门锁时间】行(门锁专用)
        /// </summary>
        /// </summary>
        private void AddDoorLocksTimeRow()
        {
            //如果是智能门锁
@@ -324,7 +322,7 @@
                listview.AddChidren(btnRow);
                btnRow.AddLeftCaption(caption, 600);
                //向右图标
                btnRow.AddRightIconControl();
                btnRow.AddRightArrow();
                //底线
                btnRow.AddBottomLine();
                btnRow.ButtonClickEvent += (sender, e) =>
@@ -339,7 +337,7 @@
        /// <summary>
        /// 添加【按键设置】行
        /// </summary>
        /// </summary>
        private void AddPanelSettionRow()
        {
            //必须是河东设备,必须是面板,并且有干接点才行
@@ -353,7 +351,7 @@
            listview.AddChidren(btnFunction);
            btnFunction.AddLeftCaption(caption, 600);
            //向右图标
            btnFunction.AddRightIconControl();
            btnFunction.AddRightArrow();
            //底线
            btnFunction.AddBottomLine();
            btnFunction.ButtonClickEvent += (sender, e) =>
@@ -369,7 +367,7 @@
        /// <summary>
        /// 添加【功能设置】行
        /// </summary>
        /// </summary>
        private void AddFunctionSettionRow()
        {
            //功能设置
@@ -378,7 +376,7 @@
            listview.AddChidren(btnFunction);
            btnFunction.AddLeftCaption(caption, 600);
            //向右图标
            btnFunction.AddRightIconControl();
            btnFunction.AddRightArrow();
            //底线
            btnFunction.AddBottomLine();
            btnFunction.ButtonClickEvent += (sender, e) =>
@@ -397,13 +395,13 @@
            };
        }
        #endregion;
        #endregion;
        #region ■ 干接点设置(干接点)_________________
        /// <summary>
        /// 添加【干接点设置】行
        /// </summary>
        /// </summary>
        private void AddDryContactSettionRow()
        {
            if (this.listDeviceType.Contains(DeviceType.OnOffSwitch) == false)
@@ -424,7 +422,7 @@
            listview.AddChidren(btnBackLight);
            btnBackLight.AddLeftCaption(caption, 600);
            //向右图标
            btnBackLight.AddRightIconControl();
            btnBackLight.AddRightArrow();
            //底线
            btnBackLight.AddBottomLine();
            btnBackLight.ButtonClickEvent += (sender, e) =>
@@ -448,7 +446,7 @@
            listview.AddChidren(btnGeneral);
            btnGeneral.AddLeftCaption(caption, 600);
            //向右图标
            btnGeneral.AddRightIconControl();
            btnGeneral.AddRightArrow();
            //底线
            btnGeneral.AddBottomLine();
            btnGeneral.ButtonClickEvent += (sender, e) =>
@@ -464,7 +462,7 @@
        /// <summary>
        /// 添加【固件升级】行
        /// </summary>
        /// </summary>
        private void AddFirmwareUpdateRow()
        {
            //拥有200端口这个东西的时候,才会显示这一行
@@ -480,7 +478,7 @@
            listview.AddChidren(rowUpDate);
            rowUpDate.AddLeftCaption(caption, 600);
            //向右图标
            rowUpDate.AddRightIconControl();
            rowUpDate.AddRightArrow();
            //底线
            rowUpDate.AddBottomLine();
@@ -510,7 +508,7 @@
        /// <param name="oTADevice">ota设备</param>
        private void SetDeviceVersionInfo(PicViewControl btnNewVersion, OTADevice oTADevice)
        {
            new System.Threading.Thread(async () =>
            HdlThreadLogic.Current.RunThread(async () =>
            {
                bool receiveImageInfo = false;
                //设置设备全部的镜像信息
@@ -548,53 +546,52 @@
                        }
                    });
                }
            })
            { IsBackground = true }.Start();
            });
        }
        #endregion
        #endregion
        #region ■ 修改名字___________________________
        /// <summary>
        /// 设备重命名
        /// </summary>
        /// <param name="i_deviceName">deviceName.</param>
        private async void DeviceReName(string i_deviceName,bool closeForm)
        {
            //开启进度条
            this.ShowProgressBar();
            //修改MAC名
            string deviceName = i_deviceName.Trim();
        /// <summary>
        /// 设备重命名
        /// </summary>
        /// <param name="i_deviceName">deviceName.</param>
        private async void DeviceReName(string i_deviceName,bool closeForm)
        {
            //开启进度条
            this.ShowProgressBar();
            //修改MAC名
            string deviceName = i_deviceName.Trim();
            var result = await Common.LocalDevice.Current.ReMacName(this.listNewDevice, deviceName);
            //关闭进度条
            this.CloseProgressBar();
            if (result == false)
            if (result == false)
            {
                return;
            }
            }
            if (closeForm == true)
            {
                //关闭界面
                this.CloseForm();
            }
            }
            else
            {
                //设备备注修改成功!
                string msg = Language.StringByID(R.MyInternationalizationString.uDeviceReNoteSuccess);
                this.ShowMassage(ShowMsgType.Tip, msg);
            }
            }
        }
        #endregion
        #endregion
        #region ■ 右上角菜单_________________________
        #region ■ 右上角菜单_________________________
        /// <summary>
        /// 初始化右上角菜单
        /// </summary>
        /// </summary>
        private void InitTopRightMenu()
        {
            var btnIcon = new MostRightIconControl(69, 69);
@@ -606,11 +603,11 @@
                //显示右上角菜单界面
                this.ShowTopRightMenu();
            });
        }
        }
        /// <summary>
        /// 显示右上角菜单界面
        /// </summary>
        /// </summary>
        private void ShowTopRightMenu()
        {
            int menuCount = 1;
@@ -648,45 +645,45 @@
        }
        /// <summary>
        /// 删除指定设备
        /// </summary>
        private async void DoDeleteDevice()
        /// <summary>
        /// 删除指定设备
        /// </summary>
        private async void DoDeleteDevice()
        {
            //开启进度条
            this.ShowProgressBar();
            //删除设备
            this.ShowProgressBar();
            //删除设备
            bool result = await Common.LocalDevice.Current.DeleteDevice(listNewDevice);
            this.CloseProgressBar();
            this.CloseProgressBar();
            if (result == false)
            {
                return;
            }
            Application.RunOnMainThread(() =>
            }
            Application.RunOnMainThread(() =>
            {
                //关闭界面
                this.CloseForm();
            });
            });
        }
        #endregion
        #endregion
        #region ■ 关闭界面___________________________
        #region ■ 关闭界面___________________________
        /// <summary>
        /// 画面关闭
        /// </summary>
        public override void CloseForm()
        /// </summary>
        public override void CloseForm()
        {
            //移除获取设备硬件信息的监听线程
            HdlDeviceHardInfoLogic.Current.RemoveDeviceHardInfoThread(listNewDevice[0]);
            base.CloseForm();
            HdlDeviceHardInfoLogic.Current.RemoveDeviceHardInfoThread(listNewDevice[0]);
            base.CloseForm();
        }
        #endregion
        #endregion
        #region ■ 硬件信息___________________________
@@ -714,8 +711,8 @@
        #endregion
        #region ■ 一般方法___________________________
        #endregion
    }
}
        #region ■ 一般方法___________________________
        #endregion
    }
}