wxr
2022-07-19 bb4bcd1b320502b36d19aacec52ed886a975249a
HDL_ON/UI/UI2/FuntionControlView/FunctionBaseInfoSetPage.cs
@@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using HDL_ON.DAL.Server;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Newtonsoft.Json.Linq;
@@ -367,6 +369,8 @@
            else if (function.spk == SPK.HvacCac)
            {
                #region 露点温度
                if (function.GetAttribute(FunctionAttributeKey.dew_point_temp) != null)
                {
@@ -385,7 +389,7 @@
                    var btnText = new Button()
                    {
                        X = Application.GetRealWidth(16),
                        Width = Application.GetRealWidth(160),
                        Width = Application.GetRealWidth(260),
                        TextAlignment = TextAlignment.CenterLeft,
                        TextColor = CSS_Color.FirstLevelTitleColor,
                        TextSize = CSS_FontSize.SubheadingFontSize,
@@ -406,14 +410,526 @@
                #endregion
                #region 表面温度
                if (function.GetAttribute(FunctionAttributeKey.surface_temp) != null)
                {
                    contentView.AddChidren(new Button
                    {
                        Height = Application.GetRealHeight(10),
                    });
                    var surfaceTempRow = new FrameLayout()
                    {
                        Height = Application.GetRealHeight(55),
                        BackgroundColor = CSS_Color.MainBackgroundColor,
                    };
                    contentView.AddChidren(surfaceTempRow);
                    var btnSurfacaTempText = new Button()
                    {
                        X = Application.GetRealWidth(16),
                        Width = Application.GetRealWidth(260),
                        TextAlignment = TextAlignment.CenterLeft,
                        TextColor = CSS_Color.FirstLevelTitleColor,
                        TextSize = CSS_FontSize.SubheadingFontSize,
                        TextID = StringId.SurfaceTemperature,
                    };
                    surfaceTempRow.AddChidren(btnSurfacaTempText);
                    var btnSurfaceTempValue = new Button()
                    {
                        Width = Application.GetRealWidth(355),
                        TextAlignment = TextAlignment.CenterRight,
                        TextColor = CSS_Color.PromptingColor1,
                        TextSize = CSS_FontSize.TextFontSize,
                        Text = function.GetAttrState(FunctionAttributeKey.surface_temp) + "°C",
                    };
                    surfaceTempRow.AddChidren(btnSurfaceTempValue);
                }
                #endregion
                #region 温度校准
                if (function.GetAttribute(FunctionAttributeKey.room_temp_cc) != null)
                {
                    contentView.AddChidren(new Button
                    {
                        Height = Application.GetRealHeight(10),
                    });
                    var tempCCrow = new FrameLayout()
                    {
                        Height = Application.GetRealHeight(55),
                        BackgroundColor = CSS_Color.MainBackgroundColor,
                    };
                    contentView.AddChidren(tempCCrow);
                    var btnTempCcText = new Button()
                    {
                        X = Application.GetRealWidth(16),
                        Width = Application.GetRealWidth(260),
                        TextAlignment = TextAlignment.CenterLeft,
                        TextColor = CSS_Color.FirstLevelTitleColor,
                        TextSize = CSS_FontSize.SubheadingFontSize,
                        TextID = StringId.TemperatureCalibration,
                    };
                    tempCCrow.AddChidren(btnTempCcText);
                    var btnTempCcValue = new Button()
                    {
                        Width = Application.GetRealWidth(335),
                        TextAlignment = TextAlignment.CenterRight,
                        TextColor = CSS_Color.PromptingColor1,
                        TextSize = CSS_FontSize.TextFontSize,
                        Text = function.GetAttrState(FunctionAttributeKey.room_temp_cc) + "°C",
                    };
                    tempCCrow.AddChidren(btnTempCcValue);
                    var btnRightTempCc = new Button()
                    {
                        X = Application.GetRealWidth(339),
                        Gravity = Gravity.CenterVertical,
                        Width = Application.GetMinRealAverage(16),
                        Height = Application.GetMinRealAverage(16),
                        UnSelectedImagePath = "Public/RightIcon.png",
                    };
                    tempCCrow.AddChidren(btnRightTempCc);
                    btnTempCcValue.MouseUpEventHandler = (sender, e) =>
                    {
                        LoadEditDialog(-5, 5, Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.room_humidity_cc)), (reslut) =>
                        {
                            btnTempCcValue.Text = reslut + "°C";
                            Dictionary<string, string> dic = new Dictionary<string, string>();
                            dic.Add(FunctionAttributeKey.room_temp_cc, reslut);
                            Control.Ins.SendWriteCommand(function, dic);
                        });
                    };
                }
                #endregion
                #region 湿度校准
                if (function.GetAttribute(FunctionAttributeKey.room_humidity_cc) != null)
                {
                    contentView.AddChidren(new Button
                    {
                        Height = Application.GetRealHeight(10),
                    });
                    var humidityCCrow = new FrameLayout()
                    {
                        Height = Application.GetRealHeight(55),
                        BackgroundColor = CSS_Color.MainBackgroundColor,
                    };
                    contentView.AddChidren(humidityCCrow);
                    var btnHumidityCcText = new Button()
                    {
                        X = Application.GetRealWidth(16),
                        Width = Application.GetRealWidth(260),
                        TextAlignment = TextAlignment.CenterLeft,
                        TextColor = CSS_Color.FirstLevelTitleColor,
                        TextSize = CSS_FontSize.SubheadingFontSize,
                        TextID = StringId.HumidityCalibration,
                    };
                    humidityCCrow.AddChidren(btnHumidityCcText);
                    var btnHumidityCcValue = new Button()
                    {
                        Width = Application.GetRealWidth(335),
                        TextAlignment = TextAlignment.CenterRight,
                        TextColor = CSS_Color.PromptingColor1,
                        TextSize = CSS_FontSize.TextFontSize,
                        Text = function.GetAttrState(FunctionAttributeKey.room_humidity_cc) + "%",
                    };
                    humidityCCrow.AddChidren(btnHumidityCcValue);
                    var btnRightHumidityCc = new Button()
                    {
                        X = Application.GetRealWidth(339),
                        Gravity = Gravity.CenterVertical,
                        Width = Application.GetMinRealAverage(16),
                        Height = Application.GetMinRealAverage(16),
                        UnSelectedImagePath = "Public/RightIcon.png",
                    };
                    humidityCCrow.AddChidren(btnRightHumidityCc);
                    btnHumidityCcValue.MouseUpEventHandler = (sender, e) =>
                    {
                        LoadEditDialog(-10, 10, Convert.ToInt32(function.GetAttrState(FunctionAttributeKey.room_humidity_cc)), (reslut) =>
                        {
                            btnHumidityCcValue.Text = reslut + "%";
                            Dictionary<string, string> dic = new Dictionary<string, string>();
                            dic.Add(FunctionAttributeKey.room_humidity_cc, reslut);
                            Control.Ins.SendWriteCommand(function, dic);
                        });
                    };
                }
                #endregion
                #region 毛细阀门
                if (function.GetAttribute(FunctionAttributeKey.cac_valve) != null)
                {
                    contentView.AddChidren(new Button
                    {
                        Height = Application.GetRealHeight(10),
                    });
                    var cacValveRow = new FrameLayout()
                    {
                        Height = Application.GetRealHeight(55),
                        BackgroundColor = CSS_Color.MainBackgroundColor,
                    };
                    contentView.AddChidren(cacValveRow);
                    var btnCacValveText = new Button()
                    {
                        X = Application.GetRealWidth(16),
                        Width = Application.GetRealWidth(260),
                        TextAlignment = TextAlignment.CenterLeft,
                        TextColor = CSS_Color.FirstLevelTitleColor,
                        TextSize = CSS_FontSize.SubheadingFontSize,
                        TextID = StringId.CapillaryValve,
                    };
                    cacValveRow.AddChidren(btnCacValveText);
                    var btnCacValvaValue = new Button()
                    {
                        Width = Application.GetRealWidth(355),
                        TextAlignment = TextAlignment.CenterRight,
                        TextColor = CSS_Color.PromptingColor1,
                        TextSize = CSS_FontSize.TextFontSize,
                        Text = function.GetAttrState(FunctionAttributeKey.cac_valve) + "°C",
                    };
                    cacValveRow.AddChidren(btnCacValvaValue);
                }
                #endregion
                #region 地暖阀门
                if (function.GetAttribute(FunctionAttributeKey.fh_valve) != null)
                {
                    contentView.AddChidren(new Button
                    {
                        Height = Application.GetRealHeight(10),
                    });
                    var fhValveRow = new FrameLayout()
                    {
                        Height = Application.GetRealHeight(55),
                        BackgroundColor = CSS_Color.MainBackgroundColor,
                    };
                    contentView.AddChidren(fhValveRow);
                    var btnFhValveText = new Button()
                    {
                        X = Application.GetRealWidth(16),
                        Width = Application.GetRealWidth(260),
                        TextAlignment = TextAlignment.CenterLeft,
                        TextColor = CSS_Color.FirstLevelTitleColor,
                        TextSize = CSS_FontSize.SubheadingFontSize,
                        TextID = StringId.FloorHeatingValve,
                    };
                    fhValveRow.AddChidren(btnFhValveText);
                    var btnFhValvaValue = new Button()
                    {
                        Width = Application.GetRealWidth(355),
                        TextAlignment = TextAlignment.CenterRight,
                        TextColor = CSS_Color.PromptingColor1,
                        TextSize = CSS_FontSize.TextFontSize,
                        Text = function.GetAttrState(FunctionAttributeKey.fh_valve),
                    };
                    fhValveRow.AddChidren(btnFhValvaValue);
                }
                #endregion
            }
            else if(function.spk == SPK.SenesorMegahealth)
            {
                contentView.AddChidren(new Button
                {
                    Height = Application.GetRealHeight(8),
                });
                #region 推送开关
                var viewRow0 = new FrameLayout()
                {
                    Height = Application.GetRealHeight(55),
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                };
                contentView.AddChidren(viewRow0);
                var btnRowTitle0 = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Width = Application.GetRealWidth(160),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.SubheadingFontSize,
                    TextID = StringId.AlarmFunction,
                };
                viewRow0.AddChidren(btnRowTitle0);
                var btnSwtichIcon0 = new Button()
                {
                    X = Application.GetRealWidth(322),
                    Gravity = Gravity.CenterVertical,
                    Width = Application.GetMinRealAverage(36),
                    Height = Application.GetMinRealAverage(36),
                    UnSelectedImagePath = "Public/Switch_2.png",
                    SelectedImagePath = "Public/SwitchOn_2.png",
                };
                viewRow0.AddChidren(btnSwtichIcon0);
                DeviceMessageRules deviceMessageRules = new DeviceMessageRules()
                {
                    deviceId = function.deviceId
                };
                btnSwtichIcon0.MouseUpEventHandler = (sender, e) => {
                    var push = btnSwtichIcon0.IsSelected = !btnSwtichIcon0.IsSelected;
                    new System.Threading.Thread(() => {
                        var result = new HttpServerRequest().DeviceMessageRulesSet(function.deviceId, deviceMessageRules.conditionIdentify, push);//设置推送信息
                        Application.RunOnMainThread(() =>
                        {
                            if (result != null && result.Code == StateCode.SUCCESS)
                            {
                                if (result.Data.ToString() == "true")
                                {
                                    deviceMessageRules.push = push;
                                }
                                else
                                {
                                    btnSwtichIcon0.IsSelected = deviceMessageRules.push;
                                }
                            }
                            else
                            {
                                btnSwtichIcon0.IsSelected = deviceMessageRules.push;
                            }
                        });
                    })
                    { IsBackground = true }.Start();
                };
                Loading waitView = new Loading();
                viewRow0.AddChidren(waitView);
                new System.Threading.Thread(() => {
                    Application.RunOnMainThread(() => {
                        waitView.Start("");
                    });
                    var result = new HttpServerRequest().GetDeviceMessageRulesSet(function.deviceId);
                    //var result1 = new HttpServerRequest().DeviceMessageRulesSet(function.deviceId);//设置推送信息
                    Application.RunOnMainThread(() =>
                    {
                        if (result != null && result.Code == StateCode.SUCCESS && result.Data != null)
                        {
                            var data = Newtonsoft.Json.JsonConvert.DeserializeObject<List<DeviceMessageRules>>(result.Data.ToString());
                            if (data.Count > 0)
                            {
                                deviceMessageRules = data[0];
                                btnSwtichIcon0.IsSelected = deviceMessageRules.push;
                            }
                        }
                        else
                        {
                            btnSwtichIcon0.IsSelected = false;
                        }
                        waitView.Hide();
                        waitView.RemoveFromParent();
                    });
                })
                { IsBackground = true }.Start();
                viewRow0.AddChidren(new Button()
                {
                    Gravity = Gravity.CenterHorizontal,
                    Y = Application.GetRealHeight(54),
                    BackgroundColor = CSS_Color.DividingLineColor,
                    Width = Application.GetRealWidth(343),
                    Height = Application.GetRealHeight(1)
                });
                #endregion
                #region 演示模式
                var viewRow = new FrameLayout()
                {
                    Height = Application.GetRealHeight(55),
                    BackgroundColor = CSS_Color.MainBackgroundColor,
                };
                contentView.AddChidren(viewRow);
                var btnRowTitle = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Width = Application.GetRealWidth(160),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextColor = CSS_Color.FirstLevelTitleColor,
                    TextSize = CSS_FontSize.SubheadingFontSize,
                    TextID = StringId.LaboratoryMode,
                };
                viewRow.AddChidren(btnRowTitle);
                var btnSwtichIcon = new Button()
                {
                    X = Application.GetRealWidth(322),
                    Gravity = Gravity.CenterVertical,
                    Width = Application.GetMinRealAverage(36),
                    Height = Application.GetMinRealAverage(36),
                    UnSelectedImagePath = "Public/Switch_2.png",
                    SelectedImagePath = "Public/SwitchOn_2.png",
                    IsSelected = function.extSet.labModel
                };
                viewRow.AddChidren(btnSwtichIcon);
                btnSwtichIcon.MouseUpEventHandler = (sender, e) =>
                {
                    btnSwtichIcon.IsSelected = function.extSet.labModel = !btnSwtichIcon.IsSelected;
                    new System.Threading.Thread(() =>
                    {
                        var result = new HttpServerRequest().DeviceExtSet(function.deviceId, function.extSet);
                        Application.RunOnMainThread(() =>
                        {
                            if (result != null && result.Code == StateCode.SUCCESS)
                            {
                                if (Convert.ToBoolean( result.Data ))
                                {
                                    function.extSet.labModel = btnSwtichIcon.IsSelected;
                                }
                                else
                                {
                                    btnSwtichIcon.IsSelected = function.extSet.labModel = !btnSwtichIcon.IsSelected;
                                }
                            }
                            else
                            {
                                btnSwtichIcon.IsSelected = function.extSet.labModel = !btnSwtichIcon.IsSelected;
                            }
                        });
                    })
                    { IsBackground = true }.Start();
                };
                #endregion
            }
            LoadEventList();
        }
        /// <summary>
        /// 加载选择弹窗
        /// </summary>
        void LoadEditDialog(int min ,int max,int curValue,Action<string> action)
        {
            List<string> pickerItems = new List<string>();
            Dialog dialog = new Dialog();
            var pView = new FrameLayout()
            {
                BackgroundColor = CSS_Color.DialogTransparentColor1,
            };
            dialog.AddChidren(pView);
            var optionBaseView = new FrameLayout()
            {
                Y = Application.GetRealHeight(456 - 60),
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealHeight(260),
                AnimateSpeed = 0.3f,
                Animate = Animate.DownToUp,
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(12),
            };
            pView.AddChidren(optionBaseView);
            var topView = new FrameLayout()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealHeight(40),
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Radius = (uint)Application.GetRealWidth(12),
            };
            optionBaseView.AddChidren(topView);
            topView.AddChidren(new Button() { Y = Application.GetRealHeight(39), Height = Application.GetRealHeight(1), BackgroundColor = CSS_Color.DividingLineColor });
            var btnCancel = new Button()
            {
                X = Application.GetRealWidth(21),
                Width = Application.GetRealWidth(100),
                TextAlignment = TextAlignment.CenterLeft,
                TextColor = CSS_Color.PromptingColor1,
                TextSize = CSS_FontSize.TextFontSize,
                TextID = StringId.Cancel,
            };
            topView.AddChidren(btnCancel);
            var btnConfrim = new Button()
            {
                X = Application.GetRealWidth(160),
                Width = Application.GetRealWidth(160),
                TextAlignment = TextAlignment.CenterRight,
                TextColor = CSS_Color.MainColor,
                TextSize = CSS_FontSize.TextFontSize,
                TextID = StringId.Confirm,
            };
            topView.AddChidren(btnConfrim);
            UIPickerView uIPickerView = new UIPickerView()
            {
                Y = Application.GetRealHeight(40),
                Height = Application.GetRealHeight(210),
                Radius = (uint)Application.GetRealWidth(12),
            };
            for (int i = min; i <= max; i += 1)
            {
                pickerItems.Add(i.ToString());
            }
            uIPickerView.setNPicker(pickerItems, null, null);
            optionBaseView.AddChidren(uIPickerView);
            uIPickerView.setCurrentItems(pickerItems.IndexOf(curValue.ToString()), 4, 5);
            string selectItem = pickerItems[0];
            if (pickerItems.Contains(curValue.ToString()))
            {
                selectItem = curValue.ToString();
            }
            dialog.Show();
            pView.MouseUpEventHandler = (sender, e) => {
                dialog.Close();
            };
            btnCancel.MouseUpEventHandler = (sender, e) => {
                dialog.Close();
            };
            uIPickerView.OnSelectChangeEvent = (int1, int2, int3) => {
                selectItem = pickerItems[int1];
            };
            btnConfrim.MouseUpEventHandler = (sender, e) => {
                dialog.Close();
                action?.Invoke(selectItem);
            };
        }
    }
}