黄学彪
2019-10-15 2bf5ec775cb57d8015bee58c745a1e48081ff1b1
ZigbeeApp/Shared/Phone/UserCenter/SharedContent/SearchConfigureSharedListRoomForm.cs
@@ -7,16 +7,16 @@
namespace Shared.Phone.UserCenter.SharedContent
{
    /// <summary>
    /// 查看已共享内容的房间列表界面
    /// 查看已共享内容的房间列表界面★
    /// </summary>
    public class SearchConfigureSharedListRoomForm : UserCenterCommonForm
    public class SearchConfigureSharedListRoomForm : EditorCommonForm
    {
        #region ■ 变量声明___________________________
        /// <summary>
        /// 列表控件
        /// </summary>
        private VerticalScrolViewLayout listView = null;
        private VerticalFrameControl listView = null;
        /// <summary>
        /// 成员信息
        /// </summary>
@@ -33,53 +33,43 @@
        /// <summary>
        /// 画面显示(底层会固定调用此方法,借以完成画面创建)
        /// </summary>
        /// <param name="i_memberResult">成员信息</param>
        /// <param name="i_memberShardInfo">成员的共享信息</param>
        public void ShowForm(MemberInfoRes i_memberResult, MemberShardInfoData i_memberShardInfo)
        {
            this.memberResult = i_memberResult;
        /// <param name="i_memberResult">成员信息</param>
        /// <param name="i_memberShardInfo">成员的共享信息</param>
        public void ShowForm(MemberInfoRes i_memberResult, MemberShardInfoData i_memberShardInfo)
        {
            this.memberResult = i_memberResult;
            this.memberShardInfo = i_memberShardInfo;
            this.memberShardInfo.SubAccountDistributedMark = this.memberResult.SubAccountDistributedMark;
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uHadSharedContent));
            this.memberShardInfo.SubAccountDistributedMark = this.memberResult.SubAccountDistributedMark;
            //设置头部信息
            base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uShared2));
            //添加图标
            var btnAdd = new TopLayoutMostRightView();
            var btnAdd = new MostRightIconControl(69, 69);
            btnAdd.UnSelectedImagePath = "Item/Add.png";
            btnAdd.SelectedImagePath = "Item/AddSelected.png";
            btnAdd.MouseUpEventHandler += (sender, e) =>
            {
                var form = new ConfigureNewSharedListRoomForm();
                base.AddForm(form, this.memberResult, this.memberShardInfo);
            };
            topFrameLayout.AddChidren(btnAdd);
            //初始化中部信息
            this.InitMiddleFrame();
        }
            btnAdd.ButtonClickEvent += (sender, e) =>
            {
                var form = new ConfigureNewSharedListRoomForm();
                form.AddForm(this.memberResult, this.memberShardInfo);
            };
            topFrameLayout.AddChidren(btnAdd);
            btnAdd.InitControl();
            //初始化中部信息
            this.InitMiddleFrame();
        }
        /// <summary>
        /// 初始化中部信息
        /// </summary>
        private void InitMiddleFrame()
        {
            bodyFrameLayout.RemoveAll();
        /// </summary>
        private void InitMiddleFrame()
        {
            //清空bodyFrame
            this.ClearBodyFrame();
            //区域列表
            var btnTitle = new TitleViewControl(1000, true);
            btnTitle.TextID = R.MyInternationalizationString.uAreaList;
            btnTitle.Y = Application.GetRealHeight(30);
            bodyFrameLayout.AddChidren(btnTitle);
            this.listView = new VerticalScrolViewLayout();
            listView.Y = btnTitle.Bottom + Application.GetRealHeight(30);
            listView.Height = bodyFrameLayout.Height - Application.GetRealHeight(30) - btnTitle.Bottom;
            bodyFrameLayout.AddChidren(listView);
            new System.Threading.Thread(async () =>
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //获取成员的共享列表(返回文件的名字和主键)
                //获取成员的共享列表
                var result = await this.GetMemberShardContentListAndSetToLocation();
                if (result == false)
                {
@@ -90,8 +80,7 @@
                //初始化区域列表
                this.InitAreaListRow();
            })
            { IsBackground = true }.Start();
            });
        }
        #endregion
@@ -105,54 +94,115 @@
        {
            if (memberShardInfo.dicShardRoom.Count == 0)
            {
                Application.RunOnMainThread(() =>
                HdlThreadLogic.Current.RunMain(() =>
                {
                    //显示没有分享数据模式
                    this.ShowNotShardMode();
                });
            }
            else
            {
                //合并同一楼层的房间
                var dicGroup = new Dictionary<string, List<Common.Room>>();
                foreach (var room in memberShardInfo.dicShardRoom.Values)
                {
                    if (dicGroup.ContainsKey(room.FloorId) == false)
                    {
                        dicGroup[room.FloorId] = new List<Common.Room>();
                    }
                    dicGroup[room.FloorId].Add(room);
                }
                HdlThreadLogic.Current.RunMain(() =>
                {
                    bodyFrameLayout.RemoveAll();
                    //请配置共享设备
                    var btnMsg = new MsgViewControl(bodyFrameLayout.Width, false);
                    btnMsg.Gravity = Gravity.CenterVertical;
                    btnMsg.TextID = R.MyInternationalizationString.uPleaseConfigureShardDeviceMsg;
                    bodyFrameLayout.AddChidren(btnMsg);
                });
                return;
            }
            foreach (var room in memberShardInfo.dicShardRoom.Values)
            {
                Application.RunOnMainThread(() =>
                {
                    this.AddRoomRow(room);
                    this.listView = new VerticalFrameControl(29);
                    listView.Height = bodyFrameLayout.Height;
                    bodyFrameLayout.AddChidren(listView);
                    //添加各自楼层的房间列表
                    foreach (var floorId in dicGroup.Keys)
                    {
                        this.AddRoomListRow(floorId, dicGroup[floorId]);
                    }
                });
            }
        }
        /// <summary>
        /// 添加房间行
        /// 添加房间列表行
        /// </summary>
        /// <param name="room"></param>
        private void AddRoomRow(Common.Room room)
        /// <param name="listRoom"></param>
        private void AddRoomListRow(string floorId, List<Common.Room> listRoom)
        {
            var row = new StatuRowLayout(listView);
            //房间名
            var btnName = new RowCenterView(false);
            btnName.Text = room.Name;
            row.AddChidren(btnName);
            var frameBack = new FrameListControl(29);
            frameBack.BackgroundColor = UserCenterColor.Current.White;
            frameBack.Height = 10;
            this.listView.AddChidrenFrame(frameBack);
            var btnDelete = new RowDeleteButton();
            row.AddRightView(btnDelete);
            btnDelete.MouseUpEventHandler += (sender, e) =>
            //楼层
            if (string.IsNullOrEmpty(floorId) == false)
            {
                //确定移除该共享区域?
                string msg = Language.StringByID(R.MyInternationalizationString.uDeleteShardAreaMsg);
                this.ShowConfirmMsg(msg, "DoDeleteShardContentByRoom", room);
            };
                var btnFloor = new NormalViewControl(800, 60, true);
                btnFloor.X = ControlCommonResourse.XXLeft;
                btnFloor.Y = Application.GetRealHeight(52);
                btnFloor.TextColor = UserCenterColor.Current.TextColor2;
                btnFloor.TextSize = 15;
                frameBack.AddChidren(btnFloor);
                if (memberShardInfo.dicShardFloor.ContainsKey(floorId) == true)
                {
                    btnFloor.Text = memberShardInfo.dicShardFloor[floorId];
                }
                else
                {
                    btnFloor.Text = "UnKnown";
                }
            }
            row.AddRightIconControl();
            row.MouseUpEvent += (sender, e) =>
            for (int i = 0; i < listRoom.Count; i++)
            {
                var form = new SearchConfigureSharedMainForm();
                this.AddForm(form, room, memberResult, memberShardInfo);
            };
                var room = listRoom[i];
                var frameRow = new RowLayoutControl(frameBack.rowSpace / 2);
                frameBack.AddChidren(frameRow);
                //图标
                var btnIcon = frameRow.frameTable.AddLeftIcon(81);
                btnIcon.UnSelectedImagePath = "Item/RoomIcon.png";
                //名称
                var btnName = frameRow.frameTable.AddLeftCaption(room.Name, 600);
                btnName.TextSize = 15;
                //右箭头
                frameRow.frameTable.AddRightArrow();
                if (i != listRoom.Count - 1)
                {
                    //底线
                    frameRow.frameTable.AddBottomLine();
                }
                frameRow.frameTable.ButtonClickEvent += (sender, e) =>
                {
                };
                //删除
                var btnDelete = new NormalViewControl(Application.GetRealWidth(184), frameRow.Height, false);
                btnDelete.BackgroundColor = 0xfff75858;
                btnDelete.TextSize = 12;
                btnDelete.TextColor = UserCenterColor.Current.White;
                btnDelete.TextAlignment = TextAlignment.Center;
                btnDelete.TextID = R.MyInternationalizationString.uDelete;
                frameRow.AddRightView(btnDelete);
                btnDelete.ButtonClickEvent += (sender, e) =>
                {
                    //确认删除共享房间?
                    string msg = Language.StringByID(R.MyInternationalizationString.uDeleteShardRoomMsg);
                    this.ShowMassage(ShowMsgType.Confirm, msg, () =>
                    {
                        //删除共享区域
                        this.DoDeleteShardContentByRoom(room);
                    });
                };
            }
            //调整子控件Frame高度
            this.listView.AdjustChidrenFrameHeight(frameBack, Application.GetRealHeight(29));
        }
        #endregion
@@ -168,10 +218,11 @@
            var listDevice = new List<CommonDevice>();
            foreach (var deviceUi in room.DeviceUIList)
            {
                var device = deviceUi.CommonDevice;
                var device = deviceUi.CommonDevice;
                if (device == null)
                {
                    var byteData = HdlShardLogic.Current.GetShardFileContent(deviceUi.DeviceFileName);
                    string deviceFile = deviceUi.FileName.Replace("DeviceUI_", string.Empty);
                    var byteData = HdlShardLogic.Current.GetShardFileContent(deviceFile);
                    if (byteData == null)
                    {
                        continue;
@@ -187,20 +238,19 @@
                listScene.Add(sceneUi);
            }
            new System.Threading.Thread(async () =>
            HdlThreadLogic.Current.RunThread(async () =>
            {
                //执行删除
                var result = await HdlShardLogic.Current.DoDeleteSharedContent(memberShardInfo, room, listDevice, listScene);
                if (result == true)
                {
                    Application.RunOnMainThread(() =>
                    HdlThreadLogic.Current.RunMain(() =>
                    {
                        //重新刷新界面
                        this.InitMiddleFrame();
                    });
                }
            })
            { IsBackground = true }.Start();
            });
        }
        #endregion
@@ -228,7 +278,7 @@
                HouseDistributedMark = Shared.Common.Config.Instance.HomeId,
                IsOtherAccountControl = Common.Config.Instance.isAdministrator
            };
            var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", infoPra);
            var result = await UserCenterLogic.GetResponseDataByRequestHttps("ZigbeeDataShare/GetShareDataBySubAccount", false, infoPra);
            if (result == null)
            {
                //关闭进度条
@@ -284,6 +334,9 @@
            memberShardInfo.dicShardRoom = new Dictionary<string, Common.Room>();
            var listFile = HdlShardLogic.Current.GetLocalAllShardFile();
            //设备文件(分享的,而不是本地的)
            var dicDeviceFile = new Dictionary<string, string>();
            //先初始化房间
            foreach (string fileName in listFile)
            {
                if (fileName.StartsWith("Room_") == true)
@@ -299,20 +352,21 @@
                    if (memberShardInfo.dicAllMemberShard.ContainsKey(fileName) == false)
                    {
                        //先初始化房间
                        memberShardInfo.dicAllMemberShard[fileName] = new HashSet<string>();
                    }
                }
                else if (fileName.StartsWith("Device_") == true)
                {
                    //设备文件
                    string[] MyArry = fileName.Split(new string[] { "_" }, StringSplitOptions.RemoveEmptyEntries);
                    if (MyArry.Length == 4)
                    {
                        string mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(MyArry[2], Convert.ToInt32(MyArry[3]));
                        dicDeviceFile[mainKeys] = fileName;
                    }
                }
            }
            //设置房间里面设备的UI对象(因为这个东西是反序列化出来的,设备UI对象是不序列化对象)
            this.InitRoomAttributeData();
        }
        /// <summary>
        /// 初始化房间的属性对象全部的本地文件
        /// </summary>
        private void InitRoomAttributeData()
        {
            //设置房间里面设备的UI对象(因为这个东西是反序列化出来的,设备UI对象是不序列化对象)
            foreach (var tempRoom in memberShardInfo.dicShardRoom.Values)
            {
@@ -321,23 +375,18 @@
                //添加房间
                listShard.Add(tempRoom.FileName);
                //还原UI设备对象
                //还原设备对象
                tempRoom.DeviceUIList.Clear();
                foreach (string uiPath in tempRoom.DeviceUIFilePathList)
                {
                    var byteData = HdlShardLogic.Current.GetShardFileContent(uiPath);
                    if (byteData == null)
                    string deviceFile = uiPath.Replace("DeviceUI_", string.Empty);
                    if (HdlShardLogic.Current.IsFileExists(deviceFile) == false)
                    {
                        continue;
                    }
                    string valueData = System.Text.Encoding.UTF8.GetString(byteData);
                    var tempUi = Newtonsoft.Json.JsonConvert.DeserializeObject<Common.DeviceUI>(valueData);
                    tempRoom.DeviceUIList.Add(tempUi);
                    //设备UI
                    listShard.Add(tempUi.FileName);
                    tempRoom.DeviceUIList.Add(Common.LocalDevice.Current.GetDeviceUI(uiPath));
                    //设备
                    listShard.Add(tempUi.DeviceFileName);
                    listShard.Add(deviceFile);
                }
                //还原场景对象
                tempRoom.SceneUIList.Clear();
@@ -355,22 +404,54 @@
                    //场景的主键
                    listShard.Add(tempUi.FileName);
                    //从场景对象里面获取全部的绑定目标的文件名字
                    this.GetSceneBindFileName(tempUi, ref listShard);
                    this.GetSceneBindFileName(tempUi, dicDeviceFile, ref listShard);
                }
            }
        }
        /// <summary>
        /// 从场景对象里面获取全部的绑定目标的文件名字
        /// </summary>
        /// <param name="scene">场景</param>
        /// <param name="dicDeviceFile">分享的设备文件</param>
        /// <param name="listFile">文件列表(里面存的是设备UI文件和设备文件和场景文件)</param>
        private void GetSceneBindFileName(Common.SceneUI scene, Dictionary<string, string> dicDeviceFile, ref HashSet<string> listFile)
        {
            foreach (var data in scene.AddSceneMemberDataList)
            {
                //设备
                if (data.Type == 0)
                {
                    var mainKeys = Common.LocalDevice.Current.GetDeviceMainKeys(data.DeviceAddr, data.Epoint);
                    if (dicDeviceFile.ContainsKey(mainKeys) == true && listFile.Contains(dicDeviceFile[mainKeys]) == false)
                    {
                        listFile.Add(dicDeviceFile[mainKeys]);
                    }
                }
                if (data.Type == 1)
                {
                    var sceneTemp = new Common.SceneUI();
                    sceneTemp.Id = data.ElseScenesId;
                    if (listFile.Contains(sceneTemp.FileName))
                    {
                        listFile.Add(sceneTemp.FileName);
                    }
                }
            }
        }
        #endregion
        #region ■ 界面重新激活事件___________________
        #region ■ 界面重新激活事件___________________
        /// <summary>
        /// 自身的上层界面关闭后,它自身处于最上层时,触发的事件
        /// </summary>
        public override void FormActionAgainEvent()
        /// </summary>
        public override int FormActionAgainEvent()
        {
            //重新刷新界面
            this.InitMiddleFrame();
            return 1;
        }
        #endregion
@@ -378,38 +459,40 @@
        #region ■ 一般方法___________________________
        /// <summary>
        /// 从场景对象里面获取全部的绑定目标的文件名字
        /// 显示没有分享数据模式
        /// </summary>
        /// <param name="scene">场景</param>
        /// <param name="listFile">文件列表(里面存的是设备UI文件和设备文件和场景文件)</param>
        private void GetSceneBindFileName(Common.SceneUI scene, ref HashSet<string> listFile)
        private void ShowNotShardMode()
        {
            foreach (var data in scene.AddSceneMemberDataList)
            bodyFrameLayout.RemoveAll();
            //图片
            var btnPic = new PicViewControl(383, 279);
            btnPic.Gravity = Gravity.CenterHorizontal;
            btnPic.Y = Application.GetRealHeight(498);
            btnPic.UnSelectedImagePath = "Item/NotShardPic.png";
            bodyFrameLayout.AddChidren(btnPic);
            //还没有共享区域给成员{0}可点击右上角“+”添加
            string msg = Language.StringByID(R.MyInternationalizationString.uNotShardComtentMsg);
            string[] Arry = msg.Split(new string[] { "{0}" }, StringSplitOptions.RemoveEmptyEntries);
            var btnMsg1 = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(50), false);
            btnMsg1.Y = Application.GetRealHeight(962);
            btnMsg1.TextAlignment = TextAlignment.Center;
            btnMsg1.TextSize = 12;
            btnMsg1.TextColor = UserCenterColor.Current.TextGrayColor1;
            btnMsg1.Text = Arry[0];
            bodyFrameLayout.AddChidren(btnMsg1);
            if (Arry.Length > 1)
            {
                //设备
                if (data.Type == 0)
                {
                    var device = Common.LocalDevice.Current.GetDevice(data.DeviceAddr, data.Epoint);
                    if (device != null)
                    {
                        string uiName = "DeviceUI_" + device.FilePath;
                        if (listFile.Contains(uiName) == false)
                        {
                            listFile.Add(uiName);
                            listFile.Add(device.FilePath);
                        }
                    }
                }
                if (data.Type == 1)
                {
                    var sceneTemp = Common.Room.CurrentRoom.GetSceneUIBySceneId(data.ElseScenesId);
                    if (sceneTemp != null && listFile.Contains(sceneTemp.FileName))
                    {
                        listFile.Add(sceneTemp.FileName);
                    }
                }
                var btnMsg2 = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(50), false);
                btnMsg2.Y = btnMsg1.Bottom;
                btnMsg2.TextAlignment = TextAlignment.Center;
                btnMsg2.TextSize = 12;
                btnMsg2.TextColor = UserCenterColor.Current.TextGrayColor1;
                btnMsg2.Text = Arry[1];
                bodyFrameLayout.AddChidren(btnMsg2);
            }
        }
        #endregion
        #region ■ 结构体_____________________________