gxc
2019-12-25 944b87b6bcccb095cd73f13f4410fb20faf48f74
ZigbeeApp/Shared/Phone/UserCenter/Residence/AddNewRoomForm.cs
@@ -54,22 +54,37 @@
            //清空bodyFrame
            this.ClearBodyFrame();
            var btnPic = new PicViewControl(887, 444);
            btnPic.Y = Application.GetRealHeight(60);
            btnPic.Gravity = Gravity.CenterHorizontal;
            btnPic.UnSelectedImagePath = "Room/r0.png";
            bodyFrameLayout.AddChidren(btnPic);
            //房间图片
            var framePic = new FrameLayout();
            framePic.Y = Application.GetRealHeight(60);
            framePic.Width = Application.GetMinRealAverage(887);
            framePic.Height = Application.GetMinRealAverage(444);
            framePic.Gravity = Gravity.CenterHorizontal;
            framePic.Radius = 8;
            framePic.BackgroundColor = UserCenterColor.Current.BodyFrameLayout;
            bodyFrameLayout.AddChidren(framePic);
            var btnPic = new ImageView();
            btnPic.Radius = 8;
            btnPic.ImagePath = "RoomIcon/0.JPG";
            framePic.AddChidren(btnPic);
            btnPic.MouseUpEventHandler += (sender, e) =>
            {
                //房间图片选择
                this.RoomPictrueSelect(btnPic);
            };
            //添加阴影特效
            framePic.SetViewShadow(true);
            this.newRoom = new Common.Room();
            newRoom.FloorId = this.floorKeys;
            newRoom.BackgroundImage = btnPic.UnSelectedImagePath;
            newRoom.BackgroundImage = btnPic.ImagePath;
            //初始化桌布
            var tableContr = new InformationEditorControl();
            this.listview = tableContr.InitControl(bodyFrameLayout, Language.StringByID(R.MyInternationalizationString.uInfoEditor), 562, 1175);
            //添加全部菜单
            this.AddAllMenuRow(tableContr);
            this.AddAllMenuRow(tableContr, btnPic);
        }
        #endregion
@@ -79,7 +94,7 @@
        /// <summary>
        /// 添加全部菜单
        /// </summary>
        private void AddAllMenuRow(InformationEditorControl tableContr)
        private void AddAllMenuRow(InformationEditorControl tableContr, ImageView btnPic)
        {
            //【房间名称】
            var txtRoomName = new FrameCaptionInputControl(Language.StringByID(R.MyInternationalizationString.uRoomName), string.Empty, this.listview.rowSpace / 2);
@@ -152,6 +167,18 @@
                {
                    return;
                }
                if (newRoom.BackgroundImageType == 1 || newRoom.BackgroundImageType == 2)
                {
                    //生成图片
                    string picName = $"RoomIcon_{DateTime.Now.ToString("yyyyMMddHHmmss")}.png";
                    string picFullName = System.IO.Path.Combine(Common.Config.Instance.FullPath, picName);
                    Shared.IO.FileUtils.WriteFileByBytes(picFullName, btnPic.ImageBytes);
                    newRoom.BackgroundImage = picName;
                    //备份
                    Phone.UserCenter.HdlAutoBackupLogic.AddOrEditorFile(picName);
                }
                newRoom.FloorId = this.floorKeys;
                var result = newRoom.AddRoom(newRoom);
                if (result == false)
                {
@@ -254,8 +281,8 @@
            //获取中...
            btnTemper.Text = Language.StringByID(R.MyInternationalizationString.uGetting);
            HdlDeviceAttributeLogic.Current.RemoveEvent("TemperatrueDevice");
            HdlDeviceAttributeLogic.Current.AddAttributeEvent("TemperatrueDevice", "DeviceStatusReport", (Action<ZigBee.Device.CommonDevice>)((report) =>
            HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice");
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("TemperatrueDevice", ReceiveComandDiv.A设备属性上报, (Action<ZigBee.Device.CommonDevice>)((report) =>
            {
                string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report);
                if (newRoom.TemperatrueDevice != mainKeys || btnTemper == null)
@@ -263,7 +290,7 @@
                    return;
                }
                //移除掉事件
                HdlDeviceAttributeLogic.Current.RemoveEvent("TemperatrueDevice");
                HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice");
                foreach (var data in report.DeviceStatusReport.AttriBute)
                {
@@ -347,8 +374,8 @@
            //获取中...
            btnHumi.Text = Language.StringByID(R.MyInternationalizationString.uGetting);
            HdlDeviceAttributeLogic.Current.RemoveEvent("HumidityDevice");
            HdlDeviceAttributeLogic.Current.AddAttributeEvent("HumidityDevice", "DeviceStatusReport", (report) =>
            HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice");
            HdlGatewayReceiveLogic.Current.AddAttributeEvent("HumidityDevice", ReceiveComandDiv.A设备属性上报, (report) =>
            {
                string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(report);
                if (newRoom.HumidityDevice != mainKeys || btnHumi == null)
@@ -356,7 +383,7 @@
                    return;
                }
                //移除掉事件
                HdlDeviceAttributeLogic.Current.RemoveEvent("HumidityDevice");
                HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice");
                foreach (var data in report.DeviceStatusReport.AttriBute)
                {
                    if (data.AttributeId == (int)ZigBee.Device.AttriButeId.MeasuredValue)
@@ -382,19 +409,83 @@
        #endregion
        #region ■ 房间图片选择_______________________
        /// <summary>
        /// 房间图片选择
        /// </summary>
        /// <param name="imageContr"></param>
        private void RoomPictrueSelect(ImageView imageContr)
        {
            var menuContr = new BottomMenuSelectForm();
            menuContr.AddForm(3);
            //默认图库
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.LocalPicture), () =>
            {
                var localPic = new Phone.Device.Room.AddRoomSelectPicByLocal();
                Shared.Phone.UserView.HomePage.Instance.AddChidren(localPic);
                Shared.Phone.UserView.HomePage.Instance.PageIndex += 1;
                localPic.Show();
                localPic.action = (imgPath) =>
                {
                    if (string.IsNullOrEmpty(imgPath) == true)
                    {
                        return;
                    }
                    this.newRoom.BackgroundImageType = 0;
                    this.newRoom.BackgroundImage = imgPath;
                    imgPath = IO.FileUtils.GetImageFilePath(imgPath);
                    imageContr.ImageBytes = IO.FileUtils.ReadFile(imgPath);
                };
            });
            //拍照
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.Photograph), () =>
            {
                //通过相机拍照裁剪
                CropImage.TakePicture((imagePath) =>
                {
                    if (string.IsNullOrEmpty(imagePath) == true)
                    {
                        return;
                    }
                    this.newRoom.BackgroundImageType = 1;
                    imageContr.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                    System.IO.File.Delete(imagePath);
                }, "HdlPic", 2, 1);
            });
            //我的相册
            menuContr.AddMenu(Language.StringByID(R.MyInternationalizationString.MyAblums), () =>
            {
                //从相册选择图片裁剪
                CropImage.SelectPicture((imagePath) =>
                {
                    if (string.IsNullOrEmpty(imagePath) == true)
                    {
                        return;
                    }
                    this.newRoom.BackgroundImageType = 2;
                    imageContr.ImageBytes = Shared.IO.FileUtils.ReadFile(imagePath);
                    System.IO.File.Delete(imagePath);
                }, "HdlPic", 2, 1);
            });
        }
        #endregion
        #region ■ 界面关闭___________________________
        /// <summary>
        /// 界面关闭
        /// </summary>
        public override void CloseForm()
        public override void CloseFormBefore()
        {
            this.FinishEditorEvent = null;
            HdlDeviceAttributeLogic.Current.RemoveEvent("TemperatrueDevice");
            HdlDeviceAttributeLogic.Current.RemoveEvent("HumidityDevice");
            HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice");
            HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice");
            base.CloseForm();
            base.CloseFormBefore();
        }
        #endregion
@@ -430,13 +521,6 @@
                    return false;
                }
            }
            if (newRoom.BackgroundImageType == 1 || newRoom.BackgroundImageType == 2)
            {
                this.newRoom.MoveBackGroundIamageFileToDirectory(newRoom.BackgroundImage, newRoom.BackgroundImage);
                this.newRoom.BackgroundImage = $"{Common.Config.Instance.Guid}/{Common.Config.Instance.HomeId}/{newRoom.BackgroundImage}";
            }
            newRoom.FloorId = this.floorKeys;
            return true;
        }