CrabtreeOn,印度客户定制APP,迁移2.0平台版本
wxr
2022-11-01 dc14dbad8e3a55b57cadddba40c3f437e5e80fc5
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
186
187
188
189
190
using System;
namespace Shared.SimpleControl.Phone
{
    public class GenericDialog
    {
 
        /// <summary>
        /// 
        /// </summary>
        private static GenericDialog m_Current = null;
        /// <summary>
        /// 
        /// </summary>
        public static GenericDialog Current {
            get {
                if (m_Current == null) {
                    m_Current = new GenericDialog ();
                }
                return m_Current;
            }
        }
 
        /// <summary>
        /// 
        /// </summary>
        /// <param name="commonDevice"></param>
        /// <param name="commonBytes"></param>
        /// <param name="btnEquipment"></param>
        public void ShowModifyRemarksDialog (Common commonDevice, byte[] commonBytes, Button btnEquipment, Action successAction)
        {
 
            Dialog dialog = new Dialog ();
 
            var dialogView = new FrameLayout () {
                Gravity = Gravity.Center,
                Width = Application.GetRealWidth (500),
                Height = Application.GetRealHeight (300),
                BackgroundColor = SkinStyle.Current.DialogColor,
                Radius = 5,
                BorderColor = SkinStyle.Current.Transparent,
                BorderWidth = 1,
            };
            dialog.AddChidren (dialogView);
 
            var etDeviceName = new EditText () {
                Y = Application.GetRealHeight (80),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth (350),
                Height = Application.GetRealHeight (70),
                //Text = commonDevice.Name,
                Text = commonDevice.Name.TrimEnd (),
                TextAlignment = TextAlignment.Center,
                TextColor = SkinStyle.Current.TextColor,
                Radius = 1,
                BorderWidth = 1,
                BorderColor = SkinStyle.Current.BorderColor,
 
            };
            dialogView.AddChidren (etDeviceName);
            etDeviceName.TextChangeEventHandler += (sender, e) => {
                byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (etDeviceName.Text.Trim ());
 
                if (remakeBytes.Length > 20) {
                    etDeviceName.Text = CommonPage.MyEncodingGB2312.GetString (remakeBytes, 0, 20);
                    new Alert ("", ErrorCode.RemarkLengthExceededTheLimit, "Close").Show ();
                }
            };
 
            var dialogBottomView = new FrameLayout () {
                Y = Application.GetRealHeight (213),
                Height = Application.GetRealHeight (90),
                BackgroundColor = SkinStyle.Current.Black50Transparent,
            };
            dialogView.AddChidren (dialogBottomView);
 
            var btnClose = new Button () {
                Width = Application.GetRealWidth (250),
                TextAlignment = TextAlignment.Center,
                TextID = R.MyInternationalizationString.cancel,
                TextColor = SkinStyle.Current.TextColor,
                BackgroundColor = SkinStyle.Current.ButtonColor,
            };
            dialogBottomView.AddChidren (btnClose);
            btnClose.MouseUpEventHandler += (ddss, dddsss) => {
                dialog.Close ();
            };
 
            var editor = new Button () {
                X = btnClose.Right + 1,
                Width = Application.GetRealWidth (250),
                TextAlignment = TextAlignment.Center,
                TextID = R.MyInternationalizationString.SAVE,
                TextColor = SkinStyle.Current.TextColor,
                BackgroundColor = SkinStyle.Current.ButtonColor,
            };
            dialogBottomView.AddChidren (editor);
 
            editor.MouseUpEventHandler += (dff, ffd) => {
                string remakeStr = etDeviceName.Text.Trim ();
                if (string.IsNullOrEmpty (remakeStr)) {
                    //备注不能为空
                    new Alert ("", ErrorCode.RemarksCannotBeEmpty, "Close").Show ();
                    return;
                }
 
                byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (remakeStr);
                if (remakeBytes.Length > 20) {
                    new Alert ("", ErrorCode.RemarkLengthExceededTheLimit, "Close").Show ();
                    return;
                }
 
                MainPage.Loading.Start ();
                //byte [] remakeBytes = CommonPage.MyEncodingGB2312.GetBytes (etDeviceName.Text.Trim ());
                System.Threading.Tasks.Task.Run (() => {
                    byte [] updateBytes = null;
                    if (commonDevice.Type == DeviceType.LightSwitchSocket) {
                        updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, commonDevice.SubnetID, commonDevice.DeviceID, new byte [] { commonDevice.BigClass, 1, commonDevice.LoopID });
                    } else {
                        updateBytes = Control.ControlBytesSendHasReturn (Command.ReadDeviceLoopInfo, commonDevice.SubnetID, commonDevice.DeviceID, new byte [] { commonDevice.BigClass, commonDevice.MinClass, commonDevice.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 ();
                            dialog.Close ();
                        });
                        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);
                    byte [] reBytes = Control.ControlBytesSendHasReturn (Command.SetDeviceLoopInfo, commonDevice.SubnetID, commonDevice.DeviceID, updateBytes);
                    if (reBytes != null) {
                        Application.RunOnMainThread (() => {
                            btnEquipment.Text = commonDevice.Name = etDeviceName.Text.Trim ();
                            if (commonDevice.Type == DeviceType.InfraredMode) {
                                //2020-07-03 修复红外电视修改后变红外模块问题
                                InfraredMode mTV = Newtonsoft.Json.JsonConvert.DeserializeObject<InfraredMode> (System.Text.Encoding.UTF8.GetString (commonBytes));
                                if (mTV == null) {
                                    IO.FileUtils.SaveEquipmentMessage (commonDevice, commonDevice.LoopID.ToString ());
                                } else {
                                    mTV.Name = etDeviceName.Text.Trim ();
                                    IO.FileUtils.SaveEquipmentMessage (mTV, mTV.LoopID.ToString ());
                                }
                            } else {
                                IO.FileUtils.SaveEquipmentMessage (commonDevice, commonDevice.LoopID.ToString ());
                            }
 
                            //IO.FileUtils.SaveEquipmentMessage (commonDevice, commonDevice.LoopID.ToString ());
                            MainPage.Loading.Hide ();
                            dialog.Close ();
                            
                        });
 
                        //修改成功回调
                        successAction?.Invoke ();
                    } else {
                        Application.RunOnMainThread (() => {
                            new Alert (Language.StringByID (R.MyInternationalizationString.Tip), Language.StringByID (R.MyInternationalizationString.FailureToModify), Language.StringByID (R.MyInternationalizationString.Close)).Show ();
                            MainPage.Loading.Hide ();
                            dialog.Close ();
                        });
                    }
                });
            };
            dialog.Show ();
        }
 
 
        /// <summary>
        /// 修改备注成功后刷新房间设备列表的备注
        /// </summary>
        /// <param name="commonDevice"></param>
        public void RefreshRemark (Common commonDevice)
        {
            try {
                foreach (var room in Room.Lists) {
                    foreach (var common in room.DeviceList) {
                        if (common.CommonLoopID != commonDevice.CommonLoopID || common.Type != commonDevice.Type) {
                            continue;
                        }
                        common.Name = commonDevice.Name;
                    }
                }
            } catch {
                Utlis.WriteLine ("RefreshRemark 失败");
            }
        }
    }
}