1
wxr
2023-03-31 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d
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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
using Shared.SimpleControl.Phone;
using System;
using System.Collections.Generic;
 
namespace Shared.SimpleControl.Pad
{
    public class SystemFloorHeatingPanel
    {
        public SystemFloorHeatingPanel ()
        {
        }
        public void ShowSystemFloorHeatingPanel (FoolHeatPanel thp, ButtonPanel bp)
        {
            SystemMiddle.ThirdScrolView.RemoveAll ();
 
            byte [] thpBytes = null;
 
            EditText textButton = new EditText () {
                X = Application.GetRealWidth (40),
                Height = Application.GetRealHeight (50),
                Width = Application.GetRealWidth (400),
                Text = thp.Name,
                Gravity = Gravity.CenterVertical,
                TextAlignment = TextAlignment.CenterLeft,
                SelectedBackgroundColor = 0xFF000000,
                Enable = false,
                TextSize = 15,
                IsSelected = false,
 
            };
            SystemMiddle.ThirdScrolView.TitleView.AddChidren (textButton);
 
            Button editor = new Button () {
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (70),
                UnSelectedImagePath = "Item/Editor.png",
                SelectedImagePath = "Item/EditorSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            SystemMiddle.ThirdScrolView.TitleView.AddChidren (editor);
            editor.MouseUpEventHandler += (sender, e) => {
                if (editor.IsSelected) {
                    MainPage.Loading.Start ();
                    editor.IsSelected = textButton.IsSelected = textButton.Enable = false;
                    byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (textButton.Text.Trim ());
                    System.Threading.Tasks.Task.Run (() => {
                        byte [] updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, thp.SubnetID, thp.DeviceID, new byte [] {
                        thp.BigClass,thp.MinClass,thp.LoopID
                        });
                        if (updateBytes == null) {
                            Application.RunOnMainThread (() => {
                                new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                MainPage.Loading.Hide ();
                            });
                            return;
                        }
                        byte [] uBytes = new byte [20];
                        Array.Copy (remakeBytes, 0, uBytes, 0, remakeBytes.Length < 20 ? remakeBytes.Length : 20);
                        Array.Copy (uBytes, 0, updateBytes, 3, 20 < uBytes.Length ? 20 : uBytes.Length);
                        var reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, thp.SubnetID, thp.DeviceID, updateBytes);
                        if (reBytes != null) {
                            Application.RunOnMainThread (() => {
                                thp.Name = textButton.Text.Trim ();
                                IO.FileUtils.SaveEquipmentMessage (thp, thp.LoopID.ToString ());
                                MainPage.Loading.Hide ();
                            });
                        } else {
                            Application.RunOnMainThread (() => {
                                new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                MainPage.Loading.Hide ();
                            });
                        }
                    });
                } else {
                    textButton.Enable = textButton.IsSelected = editor.IsSelected = true;
                }
            };
 
 
            Button btnOutput = new Button () {
                Width = Application.GetRealWidth (503),
                Height = Application.GetRealHeight (50),
                X = Application.GetRealWidth (60),
                Y = Application.GetRealHeight (40),
                TextID = R.MyInternationalizationString.ChooseFloorHeatingLoop,
                TextAlignment = TextAlignment.CenterLeft,
            };
            SystemMiddle.ThirdScrolView.AddChidren (btnOutput);
            VerticalScrolViewLayout verticalScrolView = new VerticalScrolViewLayout {
                Width = Application.GetRealWidth (480),
                Height = Application.GetRealHeight (680),
                Y = btnOutput.Bottom + Application.GetRealHeight (5),
                Gravity = Gravity.CenterHorizontal,
                BackgroundColor = SkinStyle.Current.MainColor
            };
            SystemMiddle.ThirdScrolView.AddChidren (verticalScrolView);
 
            List<string> willBeShowList = IO.FileUtils.ReadFiles ().FindAll ((fileName) => {
                return fileName.Contains ("Equipment_") && fileName.Contains (DeviceType.FoolHeat.ToString () + "_") && (fileName.Split ('_').Length == 5);
            });
 
            int num = 0;
            foreach (string equipment in willBeShowList)//显示在本地找到的所有设备
            {
                var v = IO.FileUtils.ReadFile (equipment);
                string data = CommonPage.MyEncodingUTF8.GetString (v);
                FoolHeat th = Newtonsoft.Json.JsonConvert.DeserializeObject<FoolHeat> (data);
                Button btnEquipment = new Button () {
                    Width = LayoutParams.MatchParent,
                    Height = Application.GetRealHeight (90),
                    TextAlignment = TextAlignment.Center,
                    Text = th.Name,
                    Tag = th,
                    SelectedBackgroundColor = 0xFFDBDDDF,
                    BackgroundColor = SkinStyle.Current.MainColor,
                    Gravity = Gravity.CenterHorizontal
                };
                verticalScrolView.AddChidren (btnEquipment);
 
                btnEquipment.Y = Application.GetRealHeight (10) + num * (btnEquipment.Height + Application.GetRealHeight (30));
                num++;
 
                btnEquipment.MouseUpEventHandler += (sender, e) => {
                    Alert alert = new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.SureBindDevice), Language.StringByID (R.MyInternationalizationString.Cancel), Language.StringByID (R.MyInternationalizationString.Confrim));
                    alert.Show ();
                    alert.ResultEventHandler += (sender2, e2) => {
                        if (e2) {
                            FoolHeat h = (FoolHeat)btnEquipment.Tag;
                            if (thpBytes [0] == 0xFF) {
                                thpBytes [0] = 0;
                            }
                            for (int li = 0; li < 8; li++) {
                                if (thpBytes [li * 4 + 1] == 0xFF) {
                                    thpBytes [li * 4 + 1] = 0;
                                }
                            }
                            int i = 4 * thpBytes [0];
                            thpBytes [i + 1] = 1;
                            thpBytes [i + 2] = h.SubnetID;
                            thpBytes [i + 3] = h.DeviceID;
                            thpBytes [i + 4] = h.LoopID;
                            byte [] reFalg = Control.ControlBytesSendHasReturn (Command.SetACFloorHeatingSettingEquipment, thp.SubnetID, thp.DeviceID, thpBytes);
                            if (reFalg [0] == 0xF8) {
                                new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.ThePerationWasSuccessful), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                                this.ShowSystemFloorHeatingPanel (thp, bp);
                            }
                        }
                    };
                };
 
                Button btnLine = new Button () {
                    Width = LayoutParams.MatchParent,
                    Height = 1,
                    BackgroundColor = 0xFF2f2f2f
                };
                verticalScrolView.AddChidren (btnLine);
            }
 
            //--------------bottom--------------
            System.Threading.Tasks.Task.Run (() => {
                //面板可以预设8个地热通道,只能启用一个,1976回的第一个byte表示第几个地热被启用,再截取相应的子网号设备号回路号
                thpBytes = Control.ControlBytesSendHasReturn (Command.ReadACFloorHeatingSettingEquipment, thp.SubnetID, thp.DeviceID, new byte [] { });
                Application.RunOnMainThread (() => {
                    for (int i = 0; i < verticalScrolView.ChildrenCount; i++) {
                        if (verticalScrolView.GetChildren (i).GetType () == typeof (Button)) {
                            Button btn = (Button)verticalScrolView.GetChildren (i);
                            if (btn.Tag != null) {
                                var th = (FoolHeat)btn.Tag;
                                if (thpBytes != null) {
                                    if (thpBytes [0] < 10) {
                                        int kik = 4 * thpBytes [0];
                                        if (thpBytes [kik + 2] == th.SubnetID && thpBytes [kik + 3] == th.DeviceID && thpBytes [kik + 4] == th.LoopID) {
                                            btn.IsSelected = true;
                                        }
                                        kik += 4;
                                    }
                                }
                            }
                        }
                    }
                });
            });
        }
    }
}