JLChen
2020-06-04 6d55af8792cf8fbef0055e677b900fc352dba9a2
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
using System;
namespace Shared.SimpleControl.Phone
{
    public class SystemFan : FrameLayout
    {
        public SystemFan ()
        {
        }
 
        public void SystemFanShow (FanModule fanModule, Common fanDevice)
        {
            #region  top
            RowLayout frameLayout = new RowLayout () {
                Height = Application.GetRealHeight (100),
                Width = LayoutParams.MatchParent,
                BackgroundColor = SkinStyle.Current.MainColor
            };
            AddChidren (frameLayout);
 
            Button backButton = new Button () {
                X = Application.GetRealWidth (0),
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (85),
                UnSelectedImagePath = "Item/Back.png",
                SelectedImagePath = "Item/BackSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            backButton.MouseUpEventHandler += (sender, e) => {
                (Parent as PageLayout).PageIndex -= 1;
                //SystemEquipmentBase.RefreshView (fanDevice);   
            };
            frameLayout.AddChidren (backButton);
 
            EditText textButton = new EditText () {
                X = Application.GetRealWidth (20) + backButton.Right,
                Height = Application.GetRealHeight (50),
                Width = Application.GetRealWidth (400),
                Text = fanModule.Name,
                Gravity = Gravity.CenterVertical,
                TextAlignment = TextAlignment.CenterLeft,
                BackgroundColor = SkinStyle.Current.Transparent,
                SelectedBackgroundColor = SkinStyle.Current.SysEditBox,
                Enable = false,
                TextColor = SkinStyle.Current.TextColor1
            };
            frameLayout.AddChidren (textButton);
 
            Button editor = new Button () {
                X = Application.GetRealWidth(520),
                Height = Application.GetRealHeight (90),
                Width = Application.GetRealWidth (70),
                UnSelectedImagePath = "Item/Editor.png",
                SelectedImagePath = "Item/EditorSelected.png",
                Gravity = Gravity.CenterVertical,
            };
            frameLayout.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, fanModule.SubnetID, fanModule.DeviceID, new byte [] {
                        fanModule.BigClass,fanModule.MinClass,fanModule.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, fanModule.SubnetID, fanModule.DeviceID, updateBytes);
                        if (reBytes != null) {
                            Application.RunOnMainThread (() => {
                                fanModule.Name = textButton.Text.Trim ();
                                IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.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;
                }
            };
            #endregion
            #region MyRegion
            FrameLayout frameLayoutBody = new FrameLayout () {
                Y = Application.GetRealHeight (100),
                Height = Application.GetRealHeight (700),
                Width = LayoutParams.MatchParent,
            };
            AddChidren (frameLayoutBody);
 
            Button btnWindSpeedTitle = new Button () {
                Width = Application.GetRealWidth (310),
                Height = Application.GetRealHeight (80),
                X = Application.GetRealWidth (30),
                TextAlignment = TextAlignment.CenterLeft,
                Y = Application.GetRealHeight (60),
                TextID = R.MyInternationalizationString.WindSpeed
            };
            frameLayoutBody.AddChidren (btnWindSpeedTitle);
 
            Button btnWindSpeedReduce = new Button () {
                Width = Application.GetRealWidth (80),
                Height = Application.GetRealHeight (78),
                X = Application.GetRealWidth (135),
                Y = btnWindSpeedTitle.Bottom,
                UnSelectedImagePath = "Fan/Fan-.png",
                SelectedImagePath = "Fan/Fan-On.png",
            };
            frameLayoutBody.AddChidren (btnWindSpeedReduce);
 
            Button btnWindSpeedText = new Button () {
                Width = Application.GetRealWidth (225),
                Height = Application.GetRealHeight (78),
                X = btnWindSpeedReduce.Right,
                Y = btnWindSpeedReduce.Y,
                BackgroundColor = SkinStyle.Current.ViewColor,
                Text = fanModule.WindSpeed.ToString (),
                TextSize = 12,
            };
            frameLayoutBody.AddChidren (btnWindSpeedText);
 
            Button btnWindSpeedAdd = new Button () {
                Width = Application.GetRealWidth (80),
                Height = Application.GetRealHeight (78),
                X = btnWindSpeedText.Right,
                Y = btnWindSpeedReduce.Y,
                UnSelectedImagePath = "Fan/Fan+.png",
                SelectedImagePath = "Fan/Fan+On.png",
            };
            frameLayoutBody.AddChidren (btnWindSpeedAdd);
            btnWindSpeedAdd.MouseDownEventHandler += (sender2, e2) => {
                btnWindSpeedAdd.IsSelected = true;
                if (fanModule.WindSpeed <8) {
                    fanModule.WindSpeed++;
                    Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                             new byte [] { fanModule.LoopID,fanModule.WindSpeed });
                    btnWindSpeedText.Text = fanModule.WindSpeed.ToString ();
                    IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
                }
            };
            btnWindSpeedAdd.MouseUpEventHandler += (sender2, e2) => {
                btnWindSpeedAdd.IsSelected = false;
            };
 
            btnWindSpeedReduce.MouseDownEventHandler += (sender2, e2) => {
                btnWindSpeedReduce.IsSelected = true;
                 if (fanModule.WindSpeed >0) {
                    fanModule.WindSpeed--;
                    Control.ControlBytesSend (Command.SetSingleLight, fanModule.SubnetID, fanModule.DeviceID,
                                             new byte [] { fanModule.LoopID,fanModule.WindSpeed });
                    btnWindSpeedText.Text = fanModule.WindSpeed.ToString ();
                    IO.FileUtils.SaveEquipmentMessage (fanModule, fanModule.LoopID.ToString ());
                }
            };
            btnWindSpeedReduce.MouseUpEventHandler += (sender2, e2) => {
                btnWindSpeedReduce.IsSelected = false;
            };
 
            #endregion
            //SystemMiddle.hideBottom ();
        }
 
    }
}