WJC
2019-12-30 f1c3921b08bb22ac6f5db22d620e01d7e8e5c49f
ZigbeeApp/Shared/Phone/UserCenter/Residence/AddNewRoomForm.cs
@@ -12,6 +12,10 @@
        #region ■ 变量声明___________________________
        /// <summary>
        /// 完成添加房间的事件
        /// </summary>
        public Action FinishEditorEvent = null;
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalListControl listview = null;
@@ -50,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
@@ -75,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);
@@ -85,19 +104,23 @@
            //底线
            txtRoomName.AddBottomLine();
            //【所属楼层】
            var btnBelone = new FrameCaptionViewControl(Language.StringByID(R.MyInternationalizationString.uBelongeFloor), Common.Config.Instance.Home.FloorDics[this.floorKeys], this.listview.rowSpace / 2);
            listview.AddChidren(btnBelone);
            btnBelone.InitControl();
            //右箭头
            btnBelone.AddRightArrow();
            //底线
            btnBelone.AddBottomLine();
            btnBelone.ButtonClickEvent += (sender, e) =>
            //该APP为有楼层的模式才开启这个菜单
            if (floorKeys != string.Empty)
            {
                //楼层选择
                this.ShowSelectFloor(btnBelone);
            };
                //【所属楼层】
                var btnBelone = new FrameCaptionViewControl(Language.StringByID(R.MyInternationalizationString.uBelongeFloor), Common.Config.Instance.Home.FloorDics[this.floorKeys], this.listview.rowSpace / 2);
                listview.AddChidren(btnBelone);
                btnBelone.InitControl();
                //右箭头
                btnBelone.AddRightArrow();
                //底线
                btnBelone.AddBottomLine();
                btnBelone.ButtonClickEvent += (sender, e) =>
                {
                    //楼层选择
                    this.ShowSelectFloor(btnBelone);
                };
            }
            //【温度】
            var rowTemperature = new FrameRowControl(this.listview.rowSpace / 2);
@@ -144,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)
                {
@@ -152,6 +187,8 @@
                }
                else
                {
                    this.FinishEditorEvent?.Invoke();
                    this.CloseForm();
                }
            };
@@ -244,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)
@@ -253,7 +290,7 @@
                    return;
                }
                //移除掉事件
                HdlDeviceAttributeLogic.Current.RemoveEvent("TemperatrueDevice");
                HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice");
                foreach (var data in report.DeviceStatusReport.AttriBute)
                {
@@ -337,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)
@@ -346,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)
@@ -372,17 +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()
        {
            HdlDeviceAttributeLogic.Current.RemoveEvent("TemperatrueDevice");
            HdlDeviceAttributeLogic.Current.RemoveEvent("HumidityDevice");
            this.FinishEditorEvent = null;
            base.CloseForm();
            HdlGatewayReceiveLogic.Current.RemoveEvent("TemperatrueDevice");
            HdlGatewayReceiveLogic.Current.RemoveEvent("HumidityDevice");
            base.CloseFormBefore();
        }
        #endregion
@@ -405,7 +508,7 @@
            {
                if (Shared.Common.Room.Lists.Find((obj) => obj.Name == this.newRoom.Name && obj.Id != this.newRoom.Id) != null)
                {
                    this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.HadSameRoom));
                    this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uRoomNameIsExist));
                    return false;
                }
            }
@@ -414,17 +517,10 @@
                var listRoom = Common.Room.CurrentRoom.GetFloorSortRoom(this.floorKeys);
                if (listRoom.Find((obj) => obj.Name == this.newRoom.Name && obj.Id != this.newRoom.Id) != null)
                {
                    this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.HadSameRoom));
                    this.ShowMassage(ShowMsgType.Error, Language.StringByID(R.MyInternationalizationString.uRoomNameIsExist));
                    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;
        }