黄学彪
2020-12-16 0d9f64668fd7350d6a21fd157e32009a96d98134
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
using System;
using System.Collections.Generic;
using System.Text;
 
namespace Shared.Phone
{
    /// <summary>
    /// 消息中心控件
    /// </summary>
    public class MessageManagementControl : ButtonBase
    {
        /// <summary>
        /// 消息中心控件
        /// </summary>
        public MessageManagementControl()
        {
            this.Height = this.GetPictrueRealSize(69);
            this.Width = this.GetPictrueRealSize(69);
            this.UnSelectedImagePath = "Item/MessageManagement.png";
            this.SelectedImagePath = "Item/MessageManagementSelected.png";
 
            //如果住宅为虚拟住宅,则此功能无效
            if (Common.Config.Instance.Home.IsVirtually == false)
            {
                this.ButtonClickEvent += (sender, e) =>
                {
                    //点击后,清空状态
                    this.IsSelected = false;
                    HdlControlResourse.HadNewMessage = false;
 
                    var form = new UserCenter.UserMain.MessageManagementForm();
                    form.AddForm();
                };
                //添加缓存
                HdlControlResourse.listMessageManaContr.Add(this);
                //刷新状态
                this.RefreshStatu();
            }
        }
 
        /// <summary>
        /// 刷新状态(也就是如果数据有更新的话,会显示红色角标)
        /// </summary>
        public void RefreshStatu()
        {
            //如果住宅为虚拟住宅,则此功能无效
            if (Common.Config.Instance.Home.IsVirtually == true)
            {
                return;
            }
 
            if (HdlControlResourse.HadNewMessage == true)
            {
                //如果已经有新消息过来了,就不用读了
                HdlControlResourse.ReadMessageAgain = false;
                this.IsSelected = true;
                return;
            }
            if (HdlControlResourse.ReadMessageAgain == false)
            {
                //无需再次读取
                return;
            }
            HdlControlResourse.ReadMessageAgain = false;
 
            HdlThreadLogic.Current.RunThread(() =>
            {
                //获取消息列表
                string nowHomeId = Common.Config.Instance.Home.Id;
                var listMsg = HdlMessageLogic.Current.GetListMessageFromDb();
                if (listMsg == null)
                {
                    //出错,需要重新读取
                    HdlControlResourse.ReadMessageAgain = true;
                    return;
                }
                if (nowHomeId != Common.Config.Instance.Home.Id)
                {
                    //检测:切换了住宅??
                    return;
                }
                for (int i = 0; i < listMsg.Count; i++)
                {
                    if (listMsg[i].IsRead == false)
                    {
                        if (listMsg[i].MessageTitle == "/DoorLock/DoorLockOperatingEventNotificationCommand")
                        {
                            //暂时不处理这个主题
                            continue;
                        }
                        HdlControlResourse.HadNewMessage = true;
                        HdlThreadLogic.Current.RunMain(() =>
                        {
                            //有新消息
                            this.IsSelected = true;
                        }, ShowErrorMode.NO);
                        break;
                    }
                }
            });
        }
 
        /// <summary>
        /// 控件移除
        /// </summary>
        public override void RemoveFromParent()
        {
            HdlControlResourse.listMessageManaContr.Remove(this);
 
            base.RemoveFromParent();
        }
    }
}