wxr
2020-01-10 1a4b95a7ebef71838bd3eda2c22056bbf0db65ec
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
using System;
using System.Collections.Generic;
using HDL_ON.DAL;
 
namespace HDL_ON.Entity
{
    public class DB_ResidenceData
    {
        public DB_ResidenceData()
        {
        }
        /// <summary>
        /// 住宅名称
        /// </summary>
        public string residenceName;
        /// <summary>
        /// 住宅图片
        /// </summary>
        public string residenceImage;
        /// <summary>
        /// 房间列表
        /// </summary>
        public List<Room> rooms = new List<Room>();
        /// <summary>
        /// 功能列表
        /// </summary>
        public List<Function> functions = new List<Function>();
        /// <summary>
        /// 场景列表
        /// </summary>
        public List<Scene> scenes = new List<Scene>();
 
        static DB_ResidenceData instance;
        public static DB_ResidenceData residenceData
        {
            get
            {
                if (instance == null)
                {
                    try
                    {
                        var residenceDataBytes = MyIO.FileUtils.ReadFile("DB_ResidenceData");
                        var userConfigString = CommonPage.MyEncodingUTF8.GetString(residenceDataBytes);
                        DB_ResidenceData temp = null;
                        if (userConfigString != null)
                        {
                            temp = Newtonsoft.Json.JsonConvert.DeserializeObject<DB_ResidenceData>(userConfigString);
                        }
                        if (temp == null)
                        {
                            instance = new DB_ResidenceData { };
                        }
                        else
                        {
                            instance = temp;
                        }
                    }
                    catch { }
#if DEBUG
                    instance.residenceName = "妮儿的家";
                    instance.residenceImage = "Classification/Room/Roombg.png";
                    var r = new Room() { sid = "0001", name = "Room-1", floor = "1F", backgroundImage = "Classification/Room/Roombg.png" };
                    r.functions.Add(new Function()
                    {
                        sid = "000000000000000000000000000000000001",
                        funcType = FunctionType.AC,
                        Name = "空调",
                        roomIdList = new List<string>() { "0001" },
                        lastState = "制冷 中风 18°C"
                    });
                    r.functions.Add(new Function()
                    {
                        sid = "000000000000000000000000000000000002",
                        funcType = FunctionType.Light,
                        Name = "客厅灯",
                        roomIdList = new List<string>() { "0001" },
                        lastState = "打开20%亮度"
                    });
                    r.functions.Add(new Function()
                    {
                        sid = "000000000000000000000000000000000003",
                        funcType = FunctionType.Curtain,
                        Name = "窗帘",
                        roomIdList = new List<string>() { "0001" },
                        lastState = "打开20%"
                    });
                    r.functions.Add(new Function()
                    {
                        sid = "000000000000000000000000000000000004",
                        funcType = FunctionType.FloorHeating,
                        Name = "地热",
                        roomIdList = new List<string>() { "0001" },
                        lastState = ""
                    });
 
                    //--------------------
                    instance.functions.Add(new Function()
                    {
                        sid = "000000000000000000000000000000000001",
                        funcType = FunctionType.AC,
                        Name = "空调",
                        roomIdList = new List<string>() { "0001" },
                        lastState = "制冷 中风 18°C"
                    });
                    instance.functions.Add(new Function()
                    {
                        sid = "000000000000000000000000000000000002",
                        funcType = FunctionType.Light,
                        Name = "客厅灯",
                        roomIdList = new List<string>() { "0001" },
                        lastState = "打开20%亮度"
                    });
                    instance.functions.Add(new Function()
                    {
                        sid = "000000000000000000000000000000000003",
                        funcType = FunctionType.Curtain,
                        Name = "窗帘",
                        roomIdList = new List<string>() { "0001" },
                        lastState = "打开20%"
                    });
                    instance.functions.Add(new Function()
                    {
                        sid = "000000000000000000000000000000000004",
                        funcType = FunctionType.FloorHeating,
                        Name = "地热",
                        roomIdList = new List<string>() { "0001" },
                        lastState = ""
                    });
 
                    instance.rooms.Add(r);
#endif
                }
                return instance;
            }
        }
 
        public void SaveResidenceData()
        {
            var ssd = CommonPage.MyEncodingUTF8.GetBytes(Newtonsoft.Json.JsonConvert.SerializeObject(this));
            MyIO.FileUtils.WriteFileByBytes("DB_ResidenceData", ssd);
        }
    }
}