using System; namespace Shared.SimpleControl.Phone { public class UserSensorSettingTempPushDialog { string TriggerTemp = ""; public UserSensorSettingTempPushDialog() { TriggerTemp = Language.StringByID (R.MyInternationalizationString.TriggerTemp); } public void ShowAutomationChoose (SensorAutomationDevice device,byte targetPushLoopId) { MainPage.Loading.Start ("Please wait..."); System.Threading.Tasks.Task.Run (() => { try { var pushRevertBytes = Control.ControlBytesSendHasReturn (Command.ReadSensorPushMessage, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, device.LoopID, 255 }); System.Collections.Generic.List pushTempList = new System.Collections.Generic.List (); Application.RunOnMainThread (() => { if (pushRevertBytes == null) { new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show (); pushRevertBytes = new byte [27]; return; } Dialog dialog = new Dialog (); FrameLayout dialogView = new FrameLayout () { BackgroundColor = SkinStyle.Current.White20Transparent, }; dialog.AddChidren (dialogView); dialogView.MouseUpEventHandler += (ds, fdd) => { dialog.Close (); }; var verticalScrolView = new VerticalScrolViewLayout () { Y = Application.GetRealHeight (1138 - 400 ), Height = Application.GetRealHeight (100 * 4), BackgroundColor = SkinStyle.Current.DialogColor }; dialogView.AddChidren (verticalScrolView); for (int i = targetPushLoopId; i < targetPushLoopId + 4; i++) { int pushTemp = 0; var pushValuesRevertBytes = Control.ControlBytesSendHasReturn (Command.ReadSensorPushValues, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, (byte)i }); if(pushValuesRevertBytes == null) { pushValuesRevertBytes = new byte [] { device.DevicePushType, (byte)i, 0, 0, 0, 255 }; } pushTemp = pushValuesRevertBytes [4] * 256 + pushValuesRevertBytes [5]; pushTempList.Add (pushValuesRevertBytes); #region ---设置--- RowLayout setTargetTemp1View = new RowLayout () { Height = Application.GetRealHeight (100), }; verticalScrolView.AddChidren (setTargetTemp1View); string setTemp = (pushTemp > 40448 ? ((40448 - pushTemp) / 10).ToString () : ((pushTemp / 10).ToString ())) + "°C"; Button btnTip = new Button () { TextColor = SkinStyle.Current.TextColor, TextAlignment = TextAlignment.Center, Tag = i }; setTargetTemp1View.AddChidren (btnTip); if (targetPushLoopId == 0) { btnTip.Text = TriggerTemp + ":> " + setTemp; } else { btnTip.Text = TriggerTemp + ":< " + setTemp; } btnTip.MouseUpEventHandler += (dfdd, fffd) => { //var uslp = new UserSensorAutomationTargetListPage (); //UserMiddle.DevicePageView.AddChidren (uslp); //uslp.ShowPage (device, Convert.ToInt32(btnTip.Tag)); //UserMiddle.DevicePageView.PageIndex = UserMiddle.DevicePageView.ChildrenCount - 1; dialog.Close (); }; #endregion } dialog.Show (); }); } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); } public void ShowSettingTempPushDialog (Sensor device, byte targetPushLoopId,byte[] pushEnableRevertBytes) { MainPage.Loading.Start ("Please wait..."); System.Threading.Tasks.Task.Run (() => { try { var pushRevertBytes = Control.ControlBytesSendHasReturn (Command.ReadSensorPushMessage, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, device.LoopID, 255 }); System.Collections.Generic.List pushTempList = new System.Collections.Generic.List (); Application.RunOnMainThread (() => { if (pushRevertBytes == null) { new Alert ("", Language.StringByID (R.MyInternationalizationString.TipEquipmentNotOnline), Language.StringByID (R.MyInternationalizationString.Close)).Show (); pushRevertBytes = new byte [27]; return; } Dialog dialog = new Dialog (); FrameLayout bodyView = new FrameLayout () { BackgroundColor = SkinStyle.Current.DialogColor, }; dialog.AddChidren (bodyView); Button btnDialogTitle = new Button () { Height = Application.GetRealHeight (126), TextID = R.MyInternationalizationString.Overheat, TextColor = SkinStyle.Current.TextColor1, BackgroundColor = SkinStyle.Current.DialogTitle, TextAlignment = TextAlignment.Center, TextSize = 21, Padding = new Padding (20, 0, 0, 0) }; bodyView.AddChidren (btnDialogTitle); if (targetPushLoopId == 4) { btnDialogTitle.TextID = R.MyInternationalizationString.Overcooling; } VerticalScrolViewLayout verticalScrolView = new VerticalScrolViewLayout () { Y = Application.GetRealHeight (126), Height = Application.GetRealHeight (1136 - 126 - 110), BackgroundColor = SkinStyle.Current.DialogColor, }; bodyView.AddChidren (verticalScrolView); for (int i = targetPushLoopId; i < targetPushLoopId + 4; i++) { int pushTemp = 0; var pushValuesRevertBytes = Control.ControlBytesSendHasReturn (Command.ReadSensorPushValues, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, (byte)i }); if (pushValuesRevertBytes == null) { pushValuesRevertBytes = new byte [] { device.DevicePushType, (byte)i, 0, 0, 0, 255 }; } if (targetPushLoopId == 3) { pushTemp = pushValuesRevertBytes [4] * 256 + pushValuesRevertBytes [5]; } else { pushTemp = pushValuesRevertBytes [2] * 256 + pushValuesRevertBytes [3]; } pushTempList.Add (pushValuesRevertBytes); #region ---温度推送设置--- RowLayout setTargetTemp1View = new RowLayout () { Height = Application.GetRealHeight (200), }; verticalScrolView.AddChidren (setTargetTemp1View); string setTemp = (pushTemp > 40448 ? ((40448 - pushTemp) / 10).ToString () : ((pushTemp / 10).ToString ())) + "°C"; Button btnTip = new Button () { X = Application.GetRealWidth (30), Width = Application.GetRealWidth (300), Height = Application.GetRealHeight(80), TextColor = SkinStyle.Current.TextColor, TextAlignment = TextAlignment.CenterLeft, }; setTargetTemp1View.AddChidren (btnTip); if (targetPushLoopId == 0) { btnTip.Text = TriggerTemp + ":> " + setTemp; } else { btnTip.Text = TriggerTemp + ":< " + setTemp; } Button btnMin = new Button () { X = Application.GetRealWidth (30), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth (80), Text = "-20°C", TextColor = SkinStyle.Current.TextColor, TextAlignment = TextAlignment.CenterLeft }; setTargetTemp1View.AddChidren (btnMin); var tempSeekBarFrame = new FrameLayout () { Width = Application.GetRealWidth (550 - 120), Height = Application.GetRealHeight (80), X = Application.GetRealWidth (10) + btnMin.Right, Gravity = Gravity.CenterVertical }; setTargetTemp1View.AddChidren (tempSeekBarFrame); var horizontalSeekBar = new HorizontalSeekBar () { ThumbColor = SkinStyle.Current.SelectedColor, Max = 60, Progress = (pushTemp > 40448 ? ( (pushTemp - 40448) / 10) : ( (pushTemp / 10))) +20 , }; tempSeekBarFrame.AddChidren (horizontalSeekBar); Button btnMax = new Button () { Width = Application.GetRealWidth (90), Height = Application.GetRealHeight (80), X = tempSeekBarFrame.Right + Application.GetRealWidth (10), Gravity = Gravity.CenterVertical, Text = 40 + "°C", TextAlignment = TextAlignment.CenterLeft, TextColor = SkinStyle.Current.TextColor }; setTargetTemp1View.AddChidren (btnMax); if (targetPushLoopId == 0) { horizontalSeekBar.ProgressColor = 0xFFCADBE1; horizontalSeekBar.BackgroundColor = 0xFFFF0000; } else { horizontalSeekBar.BackgroundColor = 0xFFCADBE1; horizontalSeekBar.ProgressColor = 0xFF6BDFFE; } horizontalSeekBar.ProgressChanged += (sender22, e4) => { if (targetPushLoopId == 0) { btnTip.Text = TriggerTemp + ":> " + (horizontalSeekBar.Progress - 20) + "°C"; } else { btnTip.Text = TriggerTemp + ":< " + (horizontalSeekBar.Progress - 20) + "°C"; } if (20 > e4) { pushTemp = (20 - e4) * 10 + 40448; } else { pushTemp = (e4 - 20) * 10; } }; horizontalSeekBar.MouseUpEventHandler += (asss, ddd) => { if (targetPushLoopId == 3) { pushValuesRevertBytes [2] = 40848 / 256; pushValuesRevertBytes [3] = 40848 % 256; pushValuesRevertBytes [4] = (byte)(pushTemp / 256); pushValuesRevertBytes [5] = (byte)(pushTemp % 256); } else { pushValuesRevertBytes [2] = (byte)(pushTemp / 256); pushValuesRevertBytes [3] = (byte)(pushTemp % 256); pushValuesRevertBytes [4] = 1250 / 256; pushValuesRevertBytes [5] = 1250 % 256; } }; Button btnPushEnable = new Button () { X = Application.GetRealWidth (300), Y = horizontalSeekBar.Bottom+ Application.GetRealHeight(40), Width = Application.GetRealWidth (300), Height = Application.GetRealHeight (80), //Text = "推送使能:关", TextID = R.MyInternationalizationString.PushEnableClose, TextColor = SkinStyle.Current.TextColor, SelectedTextColor = SkinStyle.Current.TextColor, TextAlignment = TextAlignment.CenterRight, Tag = i, }; setTargetTemp1View.AddChidren (btnPushEnable); if (pushEnableRevertBytes [3 + 3 * i] == 0) { btnPushEnable.TextID = R.MyInternationalizationString.PushEnableClose; btnPushEnable.IsSelected = false; } else { btnPushEnable.TextID = R.MyInternationalizationString.PushEnableOpen; //btnPushEnable.Text = "推送使能:开"; btnPushEnable.IsSelected = true; } btnPushEnable.MouseUpEventHandler += (ddd, sss) => { MainPage.Loading.Start ("Saving..."); byte setPushValua = btnPushEnable.IsSelected == true ? (byte)0 : (byte)1; System.Threading.Tasks.Task.Run (() => { try { var setPushRevertBytes = Control.ControlBytesSendHasReturn (Command.SetSensorPushMessage, device.SubnetID, device.DeviceID, new byte [] { device.DevicePushType, device.LoopID, Convert.ToByte(((Button)ddd).Tag), setPushValua, 255, 255 }); Application.RunOnMainThread (() => { if (setPushRevertBytes == null) { new Alert ("", Language.StringByID (R.MyInternationalizationString.TargetsSetFail), Language.StringByID (R.MyInternationalizationString.Close)).Show (); } else { if (btnPushEnable.IsSelected) { btnPushEnable.TextID = R.MyInternationalizationString.PushEnableClose; //btnPushEnable.Text = "推送使能:关"; btnPushEnable.IsSelected = false; } else { btnPushEnable.TextID = R.MyInternationalizationString.PushEnableOpen; //btnPushEnable.Text = "推送使能:开"; btnPushEnable.IsSelected = true; } pushEnableRevertBytes [3 + 3 * Convert.ToByte (((Button)ddd).Tag)] = setPushValua; } }); } catch (Exception ex) { Console.WriteLine (ex.Message); } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; #endregion } Button btnClose = new Button () { Y = bodyView.Height - Application.GetRealHeight (110), Width = Application.GetRealWidth (319), Height = Application.GetRealHeight (110), TextID = R.MyInternationalizationString.Close, TextColor = SkinStyle.Current.TextColor1, BackgroundColor = SkinStyle.Current.DialogTitle, }; bodyView.AddChidren (btnClose); btnClose.MouseUpEventHandler += (kkk, ddd) => { dialog.Close (); }; Button btnSave = new Button () { Y = btnClose.Y, X = btnClose.Right + 1, Width = Application.GetRealWidth (319), Height = btnClose.Height, TextID = R.MyInternationalizationString.SAVE, TextColor = SkinStyle.Current.TextColor1, BackgroundColor = SkinStyle.Current.DialogTitle, }; bodyView.AddChidren (btnSave); btnSave.MouseUpEventHandler += (kkk, ddd) => { MainPage.Loading.Start ("Saving..."); System.Threading.Tasks.Task.Run (() => { try { foreach (var sendPushBytes in pushTempList) { var setPushValuesACK = Control.ControlBytesSendHasReturn (Command.SetSensorPushValues, device.SubnetID, device.DeviceID, sendPushBytes); if (setPushValuesACK == null) { Application.RunOnMainThread (() => { new Alert ("", Language.StringByID (R.MyInternationalizationString.TargetsSetFail), Language.StringByID (R.MyInternationalizationString.Close)).Show (); }); } else { Application.RunOnMainThread (() => { dialog.Close (); }); } } } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); }; dialog.Show (); }); } catch { } finally { Application.RunOnMainThread (() => { MainPage.Loading.Hide (); }); } }); } } }