using System; using System.Collections.Generic; using Shared; using Shared.SimpleControl; using Shared.SimpleControl.R; using SmartHome; namespace SuperGateWay { public class LogicCommunalPage : FrameLayout { object logicrowlayout; public void Show (GateWay superGateWay,Action Action) { MainPage.MainFrameLayout.RemoveViewByTag ("Logic"); Tag = "Logic"; this.AddChidren (new Button { Height = Application.GetRealHeight (30), BackgroundColor = 0xFF1f1f1f, }); var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight (100), Y = Application.GetRealHeight (30), BackgroundColor = 0xFF1F1F1F, }; AddChidren (topFrameLayout); var hdl = new Button { Width = Application.GetRealWidth (104), Height = Application.GetRealHeight (32), X = Application.GetRealWidth (530), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Logo/Logo.png", }; //if (superGateWay.Tag != "LogicEdit") { // topFrameLayout.AddChidren (hdl); //} var titleName = new Button { //Text = "时间条件", TextID = MyInternationalizationString.Timecondition, TextSize = 17, }; topFrameLayout.AddChidren (titleName); var back = new Button { Width = Application.GetRealWidth (82), Height = Application.GetRealHeight (89), X = Application.GetRealWidth (10), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/HomepageBack.png", }; if (Logic.CurrentLogic.Tag=="true") { topFrameLayout.AddChidren (back); } back.MouseDownEventHandler += (sender, e) => { RemoveFromParent (); Action (); ///编辑完成返回发送逻辑修改命令; //System.Threading.Tasks.Task.Run (() => { Control.modifylogic (Logic.CurrentLogic); //}); superGateWay.save ("LogicListFilePath"); }; var buteditor = new Button { Height = Application.GetRealHeight (90), Width = Application.GetRealWidth (70), UnSelectedImagePath = "Item/Editor.png", SelectedImagePath = "Item/EditorSelected.png", Gravity = Gravity.CenterVertical, X = Application.GetRealWidth (525), }; if (Logic.CurrentLogic.Tag == "true") { topFrameLayout.AddChidren (buteditor); } buteditor.MouseUpEventHandler += (sender, e) => { #region 编辑名称View var dialog = new Dialog { Height = Application.GetRealHeight (300), Width = Application.GetRealWidth (450), BackgroundColor = 0xffffffff, }; var btnname = new Button { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (80), //Text = "请输入名称", TextID = MyInternationalizationString.thename, TextSize = 16, TextColor = 0xff121212, }; dialog.AddChidren (btnname); var logicTextBox = new EditText () { Y = btnname.Bottom + Application.GetRealHeight (10), Width = Application.GetRealWidth (390), Height = Application.GetRealHeight (80), BackgroundColor = 0xff505050, X = Application.GetRealWidth (30), Radius = (uint)Application.GetRealHeight (8), Text = Logic.CurrentLogic.name, }; dialog.AddChidren (logicTextBox); var BottomView = new FrameLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (80), Y = dialog.Height - Application.GetRealHeight (80), }; dialog.AddChidren (BottomView); var cancel = new Button { //Text = "取消", TextID = MyInternationalizationString.cancel, TextColor = 0xff121212, TextSize = 16, Width = Application.GetRealWidth (224), Height = Application.GetRealHeight (80), }; BottomView.AddChidren (cancel); cancel.MouseUpEventHandler += (sender11, e11) => { dialog.Close (); }; var btnLineS = new Button () { Width = Application.GetRealWidth (2), Height = Application.GetRealHeight (90), BackgroundColor = 0xff121212, X = cancel.Right, }; BottomView.AddChidren (btnLineS); var Confirm = new Button { X = btnLineS.Right, //Text = "确定", TextID = MyInternationalizationString.confirm, TextSize = 16, TextColor = 0xff121212, Width = Application.GetRealWidth (224), Height = Application.GetRealHeight (80), }; BottomView.AddChidren (Confirm); Confirm.MouseUpEventHandler += (sender1, e1) => { var name = logicTextBox.Text.Trim (); if (string.IsNullOrEmpty (name)) { new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.PleaseEnterLogicName), Language.StringByID (MyInternationalizationString.Close)).Show (); return; } var logicname = superGateWay.Logics.Find ((dev) => Logic.CurrentLogic.sid != dev.sid && dev.name == name); if (logicname != null) { new Alert (Language.StringByID (MyInternationalizationString.Tip),Language.StringByID (MyInternationalizationString.Rename), Language.StringByID (MyInternationalizationString.Close)).Show (); return; } Logic.CurrentLogic.name = name; dialog.Close (); }; var btnLine1 = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (2), BackgroundColor = 0xff121212, }; BottomView.AddChidren (btnLine1); dialog.Show (); #endregion }; var middle = new VerticalScrolViewLayout (); middle.Y = topFrameLayout.Bottom; middle.Height = Application.GetRealHeight (Application.DesignHeight - 130 - 80); middle.BackgroundColor = 0xff2F2F2F; this.AddChidren (middle); var conditionRowLayout = new RowLayout { Height = Application.GetRealHeight (100), BackgroundColor = 0xff323232, }; middle.AddChidren (conditionRowLayout); ///条件VerticalScrolViewLayout var inputVerticalScrolViewLayout = new VerticalScrolViewLayout { Height = 0, BackgroundColor = 0xffffffff, }; middle.AddChidren (inputVerticalScrolViewLayout); conditionRowLayout.AddChidren (new Button { Width = Application.GetRealWidth (200), //Text = "条件", TextID = MyInternationalizationString.condition, TextSize = 16, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (40), Gravity = Gravity.CenterVertical, }); var conditionadd = new Button { Width = Application.GetRealWidth (72), Height = Application.GetRealHeight (58), UnSelectedImagePath = "MusicIcon/add.png", X = Application.GetRealWidth (525), Gravity = Gravity.CenterVertical, }; conditionRowLayout.AddChidren (conditionadd); ///添加条件的点击事件 conditionadd.MouseUpEventHandler += (sender, e) => { if (!Logic.CurrentLogic.param.ContainsKey ("trigger")) { Logic.CurrentLogic.param.Add ("trigger", "true"); } if ((Logic.CurrentLogic.input.Count+Logic.CurrentLogic.time.Count)== 1) { #region 组合条件View FrameLayout flMain = new FrameLayout { BackgroundColor = 0x00000000 }; this.AddChidren (flMain); flMain.MouseUpEventHandler += (sender2, e2) => { flMain.RemoveFromParent (); }; var frameLayout = new FrameLayout { Y = Application.GetRealHeight (Application.DesignHeight - 400), Height = Application.GetRealHeight (400), BackgroundColor = 0xff505050,//0xFFFFFFff }; flMain.AddChidren (frameLayout); var titlerow = new RowLayout { Height = Application.GetRealHeight (100), }; frameLayout.AddChidren (titlerow); var titlebtn = new Button { //Text = "请选择多条件组合", TextID = MyInternationalizationString.Multicondition, TextSize = 16, }; titlerow.AddChidren (titlebtn); var androw = new RowLayout { Height = Application.GetRealHeight (100), Y = titlerow.Bottom, }; frameLayout.AddChidren (androw); var andbtn = new Button { Width = Application.GetRealWidth (400), TextID = MyInternationalizationString.Allconditions, //Text = "满足全部条件时", }; androw.AddChidren (andbtn); var orrow = new RowLayout { Height = Application.GetRealHeight (100), Y = androw.Bottom, }; frameLayout.AddChidren (orrow); var orbtn = new Button { Width = Application.GetRealWidth (400), TextID = MyInternationalizationString.anycondition, //Text = "满足任一条件时", }; orrow.AddChidren (orbtn); var cancelbtn = new Button { TextID = MyInternationalizationString.cancel, TextSize = 16, Y = orrow.Bottom, Height = Application.GetRealHeight (100), }; frameLayout.AddChidren (cancelbtn); cancelbtn.MouseUpEventHandler += (sender4, e4) => { flMain.RemoveFromParent (); }; #endregion //满足全部条件时点击事件 simulation; EventHandler andclick = (sender6, e6) => { flMain.RemoveFromParent (); if (Logic.CurrentLogic.param.ContainsKey ("operatorX")) { Logic.CurrentLogic.param.Remove ("operatorX"); Logic.CurrentLogic.param.Add ("operatorX", "&&"); } else { Logic.CurrentLogic.param.Add ("operatorX", "&&"); } var addLogicPage = new AddLogicPage (); MainPage.MainFrameLayout.AddChidren (addLogicPage); addLogicPage.Show (superGateWay); }; androw.MouseUpEventHandler += andclick; andbtn.MouseUpEventHandler += andclick; //满足任一条件时点击事件 EventHandler orclick = (sender6, e6) => { flMain.RemoveFromParent (); if (Logic.CurrentLogic.param.ContainsKey ("operatorX")) { Logic.CurrentLogic.param.Remove ("operatorX"); Logic.CurrentLogic.param.Add ("operatorX", "||"); } else { Logic.CurrentLogic.param.Add ("operatorX", "||"); } var addLogicPage = new AddLogicPage (); MainPage.MainFrameLayout.AddChidren (addLogicPage); addLogicPage.Show (superGateWay); }; orrow.MouseUpEventHandler += orclick; orbtn.MouseUpEventHandler += orclick; } else { var addLogicPage = new AddLogicPage (); MainPage.MainFrameLayout.AddChidren (addLogicPage); addLogicPage.Show (superGateWay); } }; #region -----显示逻辑条件----- inputVerticalScrolViewLayout.Height = Application.GetRealHeight (100 * (Logic.CurrentLogic.input.Count + Logic.CurrentLogic.time.Count)); if (Logic.CurrentLogic.sunrise.type != 0) { inputVerticalScrolViewLayout.Height = inputVerticalScrolViewLayout.Height + Application.GetRealHeight (100); var sunrowLayout = new RowLayout { Height = Application.GetRealHeight (100), BackgroundColor = 0xff505050, }; inputVerticalScrolViewLayout.AddChidren (sunrowLayout); ///显示时间 var sunvalue = new Button { X = Application.GetRealWidth (40), Width = Application.GetRealWidth (300), TextAlignment = TextAlignment.CenterLeft, Gravity = Gravity.CenterVertical, //TextColor = 0xff121212, }; sunrowLayout.AddChidren (sunvalue); string strleng = ""; if (Logic.CurrentLogic.sunrise.type == 1) { strleng = Language.StringByID (MyInternationalizationString.sunrise); } else if (Logic.CurrentLogic.sunrise.type == 2) { strleng = Language.StringByID (MyInternationalizationString.sunset); } else if (Logic.CurrentLogic.sunrise.type == 3) { strleng = Language.StringByID (MyInternationalizationString.beforesunrise1); } else if (Logic.CurrentLogic.sunrise.type == 4) { strleng = Language.StringByID (MyInternationalizationString.aftersunrise1); } else if (Logic.CurrentLogic.sunrise.type == 5) { strleng = Language.StringByID (MyInternationalizationString.beforesunset); } else if (Logic.CurrentLogic.sunrise.type == 6) { strleng = Language.StringByID (MyInternationalizationString.aftersunset); } if (Logic.CurrentLogic.sunrise.time != "") { string [] min = Logic.CurrentLogic.sunrise.time.Split (':'); sunvalue.Text = strleng + min [1].ToString () + Language.StringByID (MyInternationalizationString.minute1); } else { sunvalue.Text = strleng; } var sunedit = new Button { BackgroundColor = 0xFF253451, Text = Language.StringByID (MyInternationalizationString.edit), }; sunrowLayout.AddRightView (sunedit); sunedit.MouseUpEventHandler += (sender, e) => { var timePage = new TimePage (); MainPage.MainFrameLayout.AddChidren (timePage); timePage.str = "false"; timePage.IsDeviceEditor = true; timePage.Show (superGateWay); }; ///删除控件 var sundel = new Button { BackgroundColor = 0xFFFF0000, Text = Language.StringByID (MyInternationalizationString.del), }; sunrowLayout.AddRightView (sundel); sundel.MouseUpEventHandler += (sender, e) => { Logic.CurrentLogic.sunrise.type = 0; Logic.CurrentLogic.sunrise.time = ""; var logicCommunalPage = new LogicCommunalPage (); MainPage.MainFrameLayout.AddChidren (logicCommunalPage); logicCommunalPage.Show (superGateWay, () => { }); }; } string h1 = "", s1 = "", h2 = "", s2 = ""; for (int i = 0; i < Logic.CurrentLogic.time.Count;i++) { var times = Logic.CurrentLogic.time [i]; string [] starttime = times.Split ('-') [0].Split (':'); string [] endtime = times.Split ('-') [1].Split (':'); if (starttime [0].Length < 2) { h1 = "0" + starttime [0]; } else { h1 = starttime [0]; } if (starttime [1].Length < 2) { s1 = "0" + starttime [1]; } else { s1 = starttime [1]; } if (endtime [0].Length < 2) { h2 = "0" + endtime [0]; } else { h2 = endtime [0]; } if (endtime [1].Length < 2) { s2 = "0" + endtime [1]; } else { s2 = endtime [1]; } var s = h1 + ":" + s1 + "-" + h2 + ":" + s2; var timerowLayout = new RowLayout { Height = Application.GetRealHeight (100), BackgroundColor = 0xff505050, }; inputVerticalScrolViewLayout.AddChidren (timerowLayout); ///显示时间 var timevalue = new Button { X = Application.GetRealWidth (40), Width = Application.GetRealWidth (300), TextAlignment = TextAlignment.CenterLeft, Gravity = Gravity.CenterVertical, Text = s, //TextColor = 0xff121212, }; timerowLayout.AddChidren (timevalue); var timeedit = new Button { BackgroundColor = 0xFF253451, Text = Language.StringByID (MyInternationalizationString.edit), }; timerowLayout.AddRightView (timeedit); timeedit.MouseUpEventHandler += (sender, e) => { var timePage = new TimePage (); MainPage.MainFrameLayout.AddChidren (timePage); timePage.str = times; timePage.IsDeviceEditor = true; timePage.Show (superGateWay); }; ///删除控件 var del = new Button { BackgroundColor = 0xFFFF0000, Text = Language.StringByID (MyInternationalizationString.del), }; timerowLayout.AddRightView (del); del.MouseUpEventHandler += (sender, e) => { Logic.CurrentLogic.time.Remove (times); var logicCommunalPage = new LogicCommunalPage (); MainPage.MainFrameLayout.AddChidren (logicCommunalPage); logicCommunalPage.Show (superGateWay, () => { }); }; } foreach (var deviceinput in Logic.CurrentLogic.input) { if (deviceinput.sid == null || deviceinput.sid == "") { ///显示界面作用; //inputVerticalScrolViewLayout.Height = inputVerticalScrolViewLayout.Height - Application.GetRealHeight (100); continue; } var tempSid = deviceinput.sid; //判断SID是否有效的,如果不是有效的当前这个场景数据就不处理 Convert.ToUInt64 (tempSid, 16); var sidUlong = Convert.ToUInt64 (tempSid, 16); ///1:设备;2:场景;3:逻辑; var type = (byte)((sidUlong >> 60) & 0xF); var statevalue = deviceinput.value.ToString (); var inputrowLayout = new RowLayout { Height = Application.GetRealHeight (100), BackgroundColor = 0xff505050, }; inputVerticalScrolViewLayout.AddChidren (inputrowLayout); ///显示设备名称 var devicename = new Button { X = Application.GetRealWidth (40), Width = Application.GetRealWidth (300), TextAlignment = TextAlignment.CenterLeft, Gravity = Gravity.CenterVertical, //TextColor = 0xff121212, }; inputrowLayout.AddChidren (devicename); ///显示设备条件状态控件 var devicestatus = new Button { Width = Application.GetRealWidth (130), Height = Application.GetRealHeight (100), Gravity = Gravity.CenterVertical, //TextColor = 0xff121212, X = Application.GetRealWidth (500), }; inputrowLayout.AddChidren (devicestatus); switch (type) { case 1: { var subnetId = (byte)((sidUlong >> 40) & 0xFF); var deviceId = (byte)((sidUlong >> 32) & 0xFF); var targetType = (byte)((sidUlong >> 24) & 0xFF); var property = (byte)((sidUlong >> 16) & 0xFF); var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF); ///用来判断为条件,查找当前设备; var commonLoopID = subnetId + "_" + deviceId + "_" + targetNumber; var Type = Logic.devicetype (targetType,property); var commonDevice = superGateWay.Commons.Find ((obj) => obj.Type.ToString () == Type && obj.CommonLoopID == commonLoopID); if (commonDevice == null) { continue; } devicename.Text = commonDevice.Name; try { switch (commonDevice.Type) { case DeviceType.CurtainModel: { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } break; case DeviceType.CurtainRoller: { devicestatus.Text = statevalue + "%"; } break; case DeviceType.LightDimming: { devicestatus.Text = statevalue + "%"; } break; case DeviceType.LightSwitch: { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } break; case DeviceType.HVAC: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } else if (property == 1) { if (statevalue == "0") { //制冷 devicestatus.Text = Language.StringByID (MyInternationalizationString.Cool); } else if (statevalue == "1") { //制热 devicestatus.Text =Language.StringByID (MyInternationalizationString.Heating); } else if (statevalue == "2") { //通风 devicestatus.Text =Language.StringByID (MyInternationalizationString.Ventila); } else if (statevalue == "3") { //自动 devicestatus.Text =Language.StringByID (MyInternationalizationString.Auto); } else if (statevalue == "4") { //抽湿 devicestatus.Text =Language.StringByID (MyInternationalizationString.Dehumidify); } } else if (property == 3) { //空调温度 devicestatus.Text = statevalue + "%"; } else if (property == 5) { //环境温度 devicestatus.Text = statevalue + "%"; } } break; case DeviceType.FoolHeat: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } else if (property == 2) { devicestatus.Text = statevalue + "℃"; } } break; case DeviceType.FreshAir: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } else if (property == 1) { if (statevalue == "0") { devicestatus.Text = Language.StringByID (MyInternationalizationString.Smart); } else if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.FreshAir); } else if (statevalue == "2") { devicestatus.Text = Language.StringByID (MyInternationalizationString.InternalCirculation); } else if (statevalue == "3") { devicestatus.Text = Language.StringByID (MyInternationalizationString.ConstantTemp); } } } break; case DeviceType.MechanicalSwitch: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } } break; case DeviceType.AutomaticSwitch: { if (property == 1) { if (statevalue == "1") { devicestatus.Text =Language.StringByID (MyInternationalizationString.singleclick); } else if (statevalue == "2") { devicestatus.Text =Language.StringByID (MyInternationalizationString.longpress); } else if (statevalue == "3") { devicestatus.Text =Language.StringByID (MyInternationalizationString.longpressrelease); } else if (statevalue == "4") { devicestatus.Text =Language.StringByID (MyInternationalizationString.doubleclick); } } } break; case DeviceType.DryContact: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } } break; case DeviceType.MusicModel: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.play); } else if(statevalue == "2"){ devicestatus.Text =Language.StringByID (MyInternationalizationString.pause); } } else if (property == 1) { //devicestatus.Text = Language.StringByID (MyInternationalizationString.close); devicestatus.Text = statevalue + "%"; } } break; case DeviceType.DoorLock: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } else if (property == 1) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.low); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.normal); } } else if (property == 2) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.trigger); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.nontrigger); } } } break; case DeviceType.DoorLockID: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.trigger); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.nontrigger); } } } break; case DeviceType.Sensor: { if (property == 0) { devicestatus.Text = statevalue + "℃"; } else if (property == 1) { devicestatus.Text = statevalue + "%"; } else if (property == 5) { int intvalue = 90; intvalue = int.Parse (statevalue); if (0 <= intvalue && intvalue < 60) { devicestatus.Text = Language.StringByID (MyInternationalizationString.difference); } else if (60 <= intvalue && intvalue < 75) { devicestatus.Text = Language.StringByID (MyInternationalizationString.middle); } else if (75 <= intvalue && intvalue <= 100) { devicestatus.Text = Language.StringByID (MyInternationalizationString.excellent); } } else if (property == 10) { int intvalue = 90; intvalue = int.Parse (statevalue); if (0 <= intvalue && intvalue < 60) { devicestatus.Text = Language.StringByID (MyInternationalizationString.difference); } else if (60 <= intvalue && intvalue < 75) { devicestatus.Text = Language.StringByID (MyInternationalizationString.middle); } else if (75 <= intvalue && intvalue <= 100) { devicestatus.Text = Language.StringByID (MyInternationalizationString.excellent); } } } break; } } catch { } ///比较状态条件(<,=,>) var btncompare = new Button { BackgroundColor =0xff676767, Text = Language.StringByID (MyInternationalizationString.compare), }; inputrowLayout.AddRightView (btncompare); btncompare.MouseUpEventHandler += (sender, e) => { var window = new Dialog (); window.Width = Application.GetRealWidth (620); window.Height = Application.GetRealHeight (200); window.X = Application.GetRealWidth (10); window.Y = Application.GetRealHeight (330); window.BackgroundColor = 0xFF1f1f1f; window.Show (); var txetfl = new FrameLayout { Height = Application.GetRealHeight (100), BackgroundColor =0xff0f0f0f , }; window.AddChidren (txetfl); var btncomparetxet = new Button { Width = Application.GetRealWidth (300), Height = Application.GetRealHeight (80), TextID = MyInternationalizationString.compare, Y = Application.GetRealHeight (10), TextSize = 16, //TextColor = SkinStyle.Current.MusicTipTextColor, Gravity = Gravity.Center, TextAlignment=TextAlignment.Center, }; txetfl.AddChidren (btncomparetxet); var ipback = new Button { Width = Application.GetRealWidth (82), Height = Application.GetRealHeight (89), X = Application.GetRealWidth (10), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "MusicIcon/HomepageBack.png", }; txetfl.AddChidren (ipback); ipback.MouseUpEventHandler += (sender0,e0) => { window.Close (); }; var comparefl = new FrameLayout { Height = Application.GetRealHeight (100), Y=txetfl.Bottom, BackgroundColor = 0xFF1f1f1f, }; window.AddChidren (comparefl); var btnthan = new Button { Width = Application.GetRealWidth (180), Height = Application.GetRealHeight (80), TextID = MyInternationalizationString.than, //TextColor = SkinStyle.Current.MusicTipTextColor, //Text ="大于",// ">", X = Application.GetRealWidth (20), Y = Application.GetRealHeight (10), BackgroundColor=0xff676767, }; comparefl.AddChidren (btnthan); var btnequal = new Button { Width = Application.GetRealWidth (180), Height = Application.GetRealHeight (80), // TextColor = SkinStyle.Current.MusicTipTextColor, // Text = "等于", X = Application.GetRealWidth (20+200), Y = Application.GetRealHeight (10), BackgroundColor = 0xff676767, TextID = MyInternationalizationString.equal, }; comparefl.AddChidren (btnequal); var btnless = new Button { Width = Application.GetRealWidth (180), Height = Application.GetRealHeight (80), //TextColor = SkinStyle.Current.MusicTipTextColor, X = Application.GetRealWidth (20 + 200+180+20), Y = Application.GetRealHeight (10), BackgroundColor = 0xff676767, //Text = "小于", TextID = MyInternationalizationString.less, }; comparefl.AddChidren (btnless); if (deviceinput.compare == ">") { btnthan.BackgroundColor = 0xfffe5e00; btnequal.BackgroundColor = 0xff676767; btnless.BackgroundColor = 0xff676767; } else if (deviceinput.compare == "=") { btnthan.BackgroundColor = 0xff676767; btnequal.BackgroundColor = 0xfffe5e00; btnless.BackgroundColor = 0xff676767; } else if (deviceinput.compare == "<") { btnthan.BackgroundColor = 0xff676767; btnequal.BackgroundColor = 0xff676767; btnless.BackgroundColor = 0xfffe5e00; } btnthan.MouseUpEventHandler += (sender1,e1) => { btnthan.BackgroundColor = 0xfffe5e00; btnequal.BackgroundColor = 0xff676767; btnless.BackgroundColor = 0xff676767; deviceinput.compare = ">"; }; btnequal.MouseUpEventHandler += (sender2, e2) => { btnthan.BackgroundColor = 0xff676767; btnequal.BackgroundColor = 0xfffe5e00; btnless.BackgroundColor = 0xff676767; deviceinput.compare = "="; }; btnless.MouseUpEventHandler += (sender3, e3) => { btnthan.BackgroundColor = 0xff676767; btnequal.BackgroundColor = 0xff676767; btnless.BackgroundColor = 0xfffe5e00; deviceinput.compare = "<"; }; }; ///编辑设备控件 var btndeviceedit = new Button { BackgroundColor = 0xFF253451, Text = Language.StringByID (MyInternationalizationString.edit), }; inputrowLayout.AddRightView (btndeviceedit); btndeviceedit.MouseUpEventHandler += (sender, e) => { var selectedDeviceState = new SelectedDeviceState () { IsDeviceEditor = true }; MainPage.MainFrameLayout.AddChidren (selectedDeviceState); selectedDeviceState.Show (commonDevice, superGateWay); }; } break; case 3: { var logic = superGateWay.Logics.Find ((obj) => obj.sid == tempSid); if (logic == null) { continue; } devicename.Text = logic.name; if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open1); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.disable); } ///编辑设备控件 var btndeviceedit = new Button { BackgroundColor = 0xFF253451, Text = Language.StringByID (MyInternationalizationString.edit), }; inputrowLayout.AddRightView (btndeviceedit); btndeviceedit.MouseUpEventHandler += (sender, e) => { var SelectedLogicStatus = new SelectedLogicStatus () { IsDeviceEditor = true }; MainPage.MainFrameLayout.AddChidren (SelectedLogicStatus); SelectedLogicStatus.Show (superGateWay,logic); }; } break; } ///删除控件 var del = new Button { BackgroundColor = 0xFFFF0000, Text = Language.StringByID (MyInternationalizationString.del), }; inputrowLayout.AddRightView (del); del.MouseUpEventHandler += (sender, e) => { Logic.CurrentLogic.input.Remove (deviceinput); var logicCommunalPage = new LogicCommunalPage () { }; MainPage.MainFrameLayout.AddChidren (logicCommunalPage); logicCommunalPage.Show (superGateWay, () => { }); }; } #endregion var targetRowLayout = new RowLayout { Height = Application.GetRealHeight (100), BackgroundColor = 0xff323232, }; middle.AddChidren (targetRowLayout); ///目标targetVerticalScrolViewLayout var targetVerticalScrolViewLayout = new VerticalScrolViewLayout { Height = 0, BackgroundColor = 0xffffffff, }; middle.AddChidren (targetVerticalScrolViewLayout); var btntargettitle = new Button { // Text = "执行目标", TextSize = 16, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (40), Gravity = Gravity.CenterVertical, TextID = MyInternationalizationString.Implementationgoals, }; targetRowLayout.AddChidren (btntargettitle); var btntargetadd = new Button { Width = Application.GetRealWidth (72), Height = Application.GetRealHeight (58), UnSelectedImagePath = "MusicIcon/add.png", X = Application.GetRealWidth (525), Gravity = Gravity.CenterVertical, }; targetRowLayout.AddChidren (btntargetadd); btntargetadd.MouseUpEventHandler += (sender, e) => { var deviceTarget = new DeviceTarget (); MainPage.MainFrameLayout.AddChidren (deviceTarget); deviceTarget.Show (superGateWay); }; #region ----显示执行目标---- foreach (var deviceoutput in Logic.CurrentLogic.output) { targetVerticalScrolViewLayout.Height = Application.GetRealHeight (100 * deviceoutput.objects.Count); foreach (var device in deviceoutput.objects) { if (!device.ContainsKey ("sid")) { continue; } var tempSid = device ["sid"]?.ToString (); if (tempSid == "") { continue; } //判断SID是否有效的,如果不是有效的当前这个场景数据就不处理 Convert.ToUInt64 (tempSid, 16); var sidUlong = Convert.ToUInt64 (tempSid, 16); ///1:设备;2:场景;3:逻辑; var type = (byte)((sidUlong >> 60) & 0xF); string delay = ""; string statevalue = ""; if (device.ContainsKey ("value")) { statevalue = device ["value"]?.ToString (); } if (device.ContainsKey ("delay")) { delay = device ["delay"]?.ToString (); } var inputrowLayout = new RowLayout { Height = Application.GetRealHeight (100), BackgroundColor = 0xff505050, }; targetVerticalScrolViewLayout.AddChidren (inputrowLayout); var devicename = new Button { // Text = device.Name, X = Application.GetRealWidth (40), Width = Application.GetRealWidth (300), TextAlignment = TextAlignment.CenterLeft, Gravity = Gravity.CenterVertical, //TextColor = 0xff121212, }; inputrowLayout.AddChidren (devicename); var btndelay = new Button { Width = Application.GetRealWidth (150), Height = Application.GetRealHeight (50), X = Application.GetRealWidth (300), Y = Application.GetRealHeight (25), TextAlignment = TextAlignment.Center, TextColor = 0xffcccccc, }; inputrowLayout.AddChidren (btndelay); ///延时控件 var btndelaytext= new Button { BackgroundColor = 0xff676767, Text =Language.StringByID (MyInternationalizationString.delayed), }; inputrowLayout.AddRightView (btndelaytext); if (delay != ""&&delay!="0") { var l = int.Parse (delay) / 10; btndelay.Text = l.ToString ()+"s"; } btndelaytext.MouseUpEventHandler += (sender, e) => { Dialog window = new Dialog (); window.Show (); var frameLayout = new FrameLayout { Width = Application.GetRealWidth (580), Height = Application.GetRealHeight (300), X = Application.GetRealWidth (30), Y = Application.GetRealHeight (330), BackgroundColor = 0xffffffff, }; window.AddChidren (frameLayout); var Modifyname = new Button { Width = Application.GetRealWidth (580), Height = Application.GetRealHeight (80), TextID = MyInternationalizationString.devicedelaytime, //Text = "请输入设备延时的时间(单位/s)", Y = Application.GetRealHeight (10), // TextColor = 0xff000000, TextSize = 16, TextColor = SkinStyle.Current.MusicTipTextColor, }; frameLayout.AddChidren (Modifyname); var delaytext = new EditText { Width = Application.GetRealWidth (540), Height = Application.GetRealHeight (80), Y = Application.GetRealHeight (80), X = Application.GetRealWidth (20), Gravity = Gravity.CenterVertical, BackgroundColor = SkinStyle.Current.MusicTipBackgroundColor, //TextColor = 0xff000000, Radius = 1, BorderWidth = 1, BorderColor = SkinStyle.Current.MusicEditBorderColor, TextColor = SkinStyle.Current.MusicTextColor, }; frameLayout.AddChidren (delaytext); var line = new Button { Height = Application.GetRealHeight (2), Y = Application.GetRealHeight (218), BackgroundColor = 0xff666666, }; frameLayout.AddChidren (line); var cancelrow = new RowLayout { Y = Application.GetRealHeight (220), Height = Application.GetRealHeight (80), Width = Application.GetRealWidth (289), BackgroundColor = 0xffcccccc, }; frameLayout.AddChidren (cancelrow); var cancel = new Button { TextID = MyInternationalizationString.cancel, //TextColor = 0xff000000, TextSize = 18, TextColor = SkinStyle.Current.MusicTextColor, }; cancelrow.AddChidren (cancel); cancel.MouseUpEventHandler += (sender1, e1) => { window.Close (); }; var ther = new Button { Y = Application.GetRealHeight (220), Height = Application.GetRealHeight (80), Width = Application.GetRealWidth (2), X = Application.GetRealHeight (289), BackgroundColor = 0xff666666, }; frameLayout.AddChidren (ther); var confirmrow = new RowLayout { Y = Application.GetRealHeight (220), X = Application.GetRealWidth (291), Height = Application.GetRealHeight (80), Width = Application.GetRealWidth (289), BackgroundColor = 0xffcccccc, }; frameLayout.AddChidren (confirmrow); var confirm = new Button { TextID = MyInternationalizationString.confirm, //TextColor = 0xff000000, TextSize = 18, TextColor = SkinStyle.Current.MusicTextColor, }; confirmrow.AddChidren (confirm); confirm.MouseUpEventHandler += (sender1, e1) => { var isNumber = delaytext.Text.Trim (); if (!int.TryParse (isNumber, out int number) || isNumber == "") { new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.inputnumber), Language.StringByID (MyInternationalizationString.Close)).Show (); return; } var vel = int.Parse (isNumber); if (device.ContainsKey ("delay")) { device.Remove ("delay"); device.Add ("delay", vel * 10); } else { device.Add ("delay", vel * 10); } btndelay.Text = isNumber+"s"; window.Close (); var logicCommunalPage = new LogicCommunalPage () { }; MainPage.MainFrameLayout.AddChidren (logicCommunalPage); logicCommunalPage.Show (superGateWay, () => { }); }; }; ///显示设备状态控件 var devicestatus = new Button { Width = Application.GetRealWidth (130), Height = Application.GetRealHeight (100), Gravity = Gravity.CenterVertical, //TextColor = 0xff121212, X = Application.GetRealWidth (500), }; inputrowLayout.AddChidren (devicestatus); switch (type) { case 1: { var subnetId = (byte)((sidUlong >> 40) & 0xFF); var deviceId = (byte)((sidUlong >> 32) & 0xFF); var targetType = (byte)((sidUlong >> 24) & 0xFF); var property = (byte)((sidUlong >> 16) & 0xFF); var targetNumber = (uint)((sidUlong >> 0) & 0xFFFF); ///用来判断为条件,查找当前设备; var commonLoopID = subnetId + "_" + deviceId + "_" + targetNumber; var Type = Logic.devicetype (targetType, property); var commonDevice = superGateWay.Commons.Find ((obj) => obj.Type.ToString () == Type && obj.CommonLoopID == commonLoopID); if (commonDevice == null) { continue; } devicename.Text = commonDevice.Name; try { switch (commonDevice.Type) { case DeviceType.CurtainModel: { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } break; case DeviceType.CurtainRoller: { devicestatus.Text = statevalue + "%"; } break; case DeviceType.LightDimming: { devicestatus.Text = statevalue + "%"; } break; case DeviceType.LightSwitch: { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } break; case DeviceType.HVAC: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } else if (property == 1) { if (statevalue == "0") { //制冷 devicestatus.Text = Language.StringByID (MyInternationalizationString.Cool); } else if (statevalue == "1") { //制热 devicestatus.Text = Language.StringByID (MyInternationalizationString.Heating); } else if (statevalue == "2") { //通风 devicestatus.Text = Language.StringByID (MyInternationalizationString.Ventila); } else if (statevalue == "3") { //自动 devicestatus.Text = Language.StringByID (MyInternationalizationString.Auto); } else if (statevalue == "4") { //抽湿 devicestatus.Text = Language.StringByID (MyInternationalizationString.Dehumidify); } } else if (property == 3) { //空调温度 devicestatus.Text = statevalue + "%"; } else if (property == 5) { //环境温度 devicestatus.Text = statevalue + "%"; } } break; case DeviceType.FoolHeat: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } else if (property == 2) { devicestatus.Text = statevalue + "℃"; } } break; case DeviceType.FreshAir: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } else if (property == 1) { if (statevalue == "0") { devicestatus.Text = Language.StringByID (MyInternationalizationString.Smart); } else if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.FreshAir); } else if (statevalue == "2") { devicestatus.Text = Language.StringByID (MyInternationalizationString.InternalCirculation); } else if (statevalue == "3") { devicestatus.Text = Language.StringByID (MyInternationalizationString.ConstantTemp); } } } break; case DeviceType.MechanicalSwitch: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } } break; case DeviceType.AutomaticSwitch: { if (property == 1) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.singleclick); } else if (statevalue == "2") { devicestatus.Text = Language.StringByID (MyInternationalizationString.longpress); } else if (statevalue == "3") { devicestatus.Text = Language.StringByID (MyInternationalizationString.longpressrelease); } else if (statevalue == "4") { devicestatus.Text = Language.StringByID (MyInternationalizationString.doubleclick); } } } break; case DeviceType.DryContact: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } } break; case DeviceType.MusicModel: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.play); } else if (statevalue == "2") { devicestatus.Text = Language.StringByID (MyInternationalizationString.pause); } } else if (property == 1) { //devicestatus.Text = Language.StringByID (MyInternationalizationString.close); devicestatus.Text = statevalue + "%"; } } break; case DeviceType.DoorLock: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.close); } } else if (property == 1) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.low); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.normal); } } else if (property == 2) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.trigger); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.nontrigger); } } } break; case DeviceType.DoorLockID: { if (property == 0) { if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.trigger); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.nontrigger); } } } break; case DeviceType.Sensor: { if (property == 0) { devicestatus.Text = statevalue + "℃"; } else if (property == 1) { devicestatus.Text = statevalue + "%"; } else if (property == 5) { int intvalue = 90; intvalue = int.Parse (statevalue); if (0 <= intvalue && intvalue < 60) { devicestatus.Text = Language.StringByID (MyInternationalizationString.difference); } else if (60 <= intvalue && intvalue < 75) { devicestatus.Text = Language.StringByID (MyInternationalizationString.middle); } else if (75 <= intvalue && intvalue <= 100) { devicestatus.Text = Language.StringByID (MyInternationalizationString.excellent); } } else if (property == 10) { int intvalue = 90; intvalue = int.Parse (statevalue); if (0 <= intvalue && intvalue < 60) { devicestatus.Text = Language.StringByID (MyInternationalizationString.difference); } else if (60 <= intvalue && intvalue < 75) { devicestatus.Text = Language.StringByID (MyInternationalizationString.middle); } else if (75 <= intvalue && intvalue <= 100) { devicestatus.Text = Language.StringByID (MyInternationalizationString.excellent); } } } break; } } catch { } ///编辑设备控件 var btndeviceedit = new Button { BackgroundColor = 0xFF253451, Text = Language.StringByID (MyInternationalizationString.edit), }; inputrowLayout.AddRightView (btndeviceedit); btndeviceedit.MouseUpEventHandler += (sender, e) => { var deviceStatePage = new DeviceStatePage () { IsDeviceEditor = true }; MainPage.MainFrameLayout.AddChidren (deviceStatePage); deviceStatePage.Show (commonDevice, superGateWay); }; } break; case 2: { var scene = superGateWay.Scenes.Find ((obj) => obj.sid == tempSid); if (scene == null) { continue; } devicename.Text = scene.name; } break; case 3: { var logic = superGateWay.Logics.Find ((obj) => obj.sid == tempSid); if (logic == null) { continue; } devicename.Text = logic.name; if (statevalue == "1") { devicestatus.Text = Language.StringByID (MyInternationalizationString.open1); } else { devicestatus.Text = Language.StringByID (MyInternationalizationString.disable); } var btnlogicedit = new Button { BackgroundColor = 0xFF253451, Text = Language.StringByID (MyInternationalizationString.edit), }; inputrowLayout.AddRightView (btnlogicedit); btnlogicedit.MouseUpEventHandler += (sender, e) => { var selectedLogicState = new SelectedLogicState { IsDeviceEditor = true }; MainPage.MainFrameLayout.AddChidren (selectedLogicState); selectedLogicState.Show (superGateWay, logic); }; } break; } ///删除控件 var del = new Button { BackgroundColor = 0xFFFF0000, Text = Language.StringByID (MyInternationalizationString.del), }; inputrowLayout.AddRightView (del); del.MouseUpEventHandler += (sender, e) => { deviceoutput.objects.Remove (device); var logicCommunalPage = new LogicCommunalPage () { }; MainPage.MainFrameLayout.AddChidren (logicCommunalPage); logicCommunalPage.Show (superGateWay, () => { }); }; } } #endregion var cyclerowlayout = new RowLayout { Height = Application.GetRealHeight (100), BackgroundColor = 0xff323232, }; middle.AddChidren (cyclerowlayout); ///执行周期 var btncycle = new Button { TextSize = 16, //Text = "执行周期", TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (40), Width = Application.GetRealWidth (210), Gravity = Gravity.CenterVertical, TextID = MyInternationalizationString.cycle }; cyclerowlayout.AddChidren (btncycle); ///显示周期时间 var btndisplaycycle = new Button { TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (250), Width = Application.GetRealWidth (300), Gravity = Gravity.CenterVertical, }; cyclerowlayout.AddChidren (btndisplaycycle); ///更新周期的方法 updateweek (btndisplaycycle); var btncycleback = new Button { Width = Application.GetRealWidth (87), Height = Application.GetRealHeight (100), UnSelectedImagePath = "MusicIcon/Next.png", SelectedImagePath = "MusicIcon/NextSelecte.png", X = Application.GetRealWidth (525),//550 }; cyclerowlayout.AddChidren (btncycleback); EventHandler cycleclick = (sender, e) => { var cycle = new Cycle (() => { ///更新周期的方法 updateweek (btndisplaycycle); }); MainPage.MainFrameLayout.AddChidren (cycle); cycle.Show (superGateWay); }; cyclerowlayout.MouseUpEventHandler += cycleclick; btncycle.MouseUpEventHandler += cycleclick; btndisplaycycle.MouseUpEventHandler += cycleclick; btncycleback.MouseUpEventHandler += cycleclick; var fra = new FrameLayout { Height = Application.GetRealHeight (80), Y = middle.Bottom, BackgroundColor = 0xff1f1f1f, }; AddChidren (fra); var cancel1 = new Button { //Text = "取消", TextID = MyInternationalizationString.cancel, TextSize = 16, Width = Application.GetRealWidth (340), Height = Application.GetRealHeight (80), }; fra.AddChidren (cancel1); cancel1.MouseUpEventHandler += (sender11, e11) => { var alert = new Alert (Language.StringByID (MyInternationalizationString.Prompt), Language.StringByID (MyInternationalizationString.Whethertocancel), Language.StringByID (MyInternationalizationString.cancel), Language.StringByID (MyInternationalizationString.OK)); alert.ResultEventHandler += (sender, e) => { if (e) { MainPage.MainFrameLayout.RemoveViewByTag ("Logic"); MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1); ScenePage.isScene = true; var scenePage = new ScenePage (); MainPage.MainFrameLayout.AddChidren (scenePage); scenePage.Show (superGateWay); } else { } }; alert.Show (); }; var btncomplete = new Button { Width = Application.GetRealWidth (340), X = Application.GetRealWidth (340), Height = Application.GetRealHeight (80), TextID = MyInternationalizationString.complete, TextSize = 16, }; fra.AddChidren (btncomplete); var btnLine = new Button () { Height = Application.GetRealHeight (80), Width = Application.GetRealWidth (2), X = Application.GetRealWidth (339), BackgroundColor = 0xff121212, }; fra.AddChidren (btnLine); btncomplete.MouseUpEventHandler += (sedder, e) => { // RemoveFromParent (); #region ----创建逻辑名称界面---- var dialog = new Dialog { Height = Application.GetRealHeight (300), Width = Application.GetRealWidth (450), BackgroundColor = 0xffffffff, }; var btnname = new Button { Gravity = Gravity.CenterHorizontal, Width = Application.GetRealWidth (400), Height = Application.GetRealHeight (80), TextID = MyInternationalizationString.thename, TextSize = 16, TextColor = 0xff121212, }; dialog.AddChidren (btnname); var logicTextBox = new EditText () { Y = btnname.Bottom + Application.GetRealHeight (10), Width = Application.GetRealWidth (390), Height = Application.GetRealHeight (80), BackgroundColor = 0xff505050, X = Application.GetRealWidth (30), Radius = (uint)Application.GetRealHeight (8), Text = Logic.CurrentLogic.name, }; dialog.AddChidren (logicTextBox); var BottomView = new FrameLayout () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (80), Y = dialog.Height - Application.GetRealHeight (80), }; dialog.AddChidren (BottomView); var cancel = new Button { TextID = MyInternationalizationString.cancel, TextColor = 0xff121212, TextSize = 16, Width = Application.GetRealWidth (224), Height = Application.GetRealHeight (80), }; BottomView.AddChidren (cancel); cancel.MouseUpEventHandler += (sender11, e11) => { dialog.Close (); }; var btnLineS = new Button () { Width = Application.GetRealWidth (2), Height = Application.GetRealHeight (90), BackgroundColor = 0xff121212, X = cancel.Right, }; BottomView.AddChidren (btnLineS); var Confirm = new Button { X = btnLineS.Right, TextID = MyInternationalizationString.confirm, TextSize = 16, TextColor = 0xff121212, Width = Application.GetRealWidth (224), Height = Application.GetRealHeight (80), }; BottomView.AddChidren (Confirm); Confirm.MouseUpEventHandler += (sender1, e1) => { var objects = new List> { }; foreach (var deviceoutput in Logic.CurrentLogic.output) { objects = deviceoutput.objects; } if (string.IsNullOrEmpty (logicTextBox.Text.Trim ())) { new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.PleaseEnterLogicName), Language.StringByID (MyInternationalizationString.Close)).Show (); return; } if (objects.Count == 0 || ((Logic.CurrentLogic.time.Count + Logic.CurrentLogic.input.Count) == 0)&&Logic.CurrentLogic.sunrise.type==0) { new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.empty), Language.StringByID (MyInternationalizationString.Close)).Show (); return; } var name = logicTextBox.Text.Trim (); if (Logic.CurrentLogic.sid == "") { Logic.CurrentLogic.sid = SuperGateWay.Logic.NewSid; } var logicname = superGateWay.Logics.Find ((dev) => Logic.CurrentLogic.sid != dev.sid && dev.name == name); if (logicname != null) { new Alert (Language.StringByID (MyInternationalizationString.Tip), Language.StringByID (MyInternationalizationString.Rename), Language.StringByID (MyInternationalizationString.Close)).Show (); return; } Logic.CurrentLogic.name = name; ///周期默认执行一次 if (Logic.CurrentLogic.date.Count == 0) { var datetime = DateTime.Now.ToString ("yyyy/MM/dd"); Logic.CurrentLogic.date.Add ("type", "day"); Logic.CurrentLogic.date.Add ("date", datetime + "-" + datetime); } ///先默认新历false/(农历true) if (!Logic.CurrentLogic.date.ContainsKey ("chinese_calendar")) { Logic.CurrentLogic.date.Add ("chinese_calendar", "false"); } superGateWay.save ("LogicListFilePath"); //MainPage.Loading.Start (Language.StringByID (MyInternationalizationString.load)); //System.Threading.Tasks.Task.Run (() => { if (Logic.CurrentLogic.Tag == "true") { Control.modifylogic (Logic.CurrentLogic); } else { Control.AppendLogic (Logic.CurrentLogic); superGateWay.Logics.Add (Logic.CurrentLogic); } // Application.RunOnMainThread (() => { //MainPage.Loading.Hide (); dialog.Close (); MainPage.MainFrameLayout.RemoveViewByTag ("Logic"); MainPage.MainFrameLayout.RemoveAt (MainPage.MainFrameLayout.ChildrenCount - 1); ScenePage.isScene = true; ScenePage scenePage = new ScenePage (); MainPage.MainFrameLayout.AddChidren (scenePage); scenePage.Show (superGateWay); // }); // }); }; var btnLine1 = new Button () { Width = LayoutParams.MatchParent, Height = Application.GetRealHeight (2), BackgroundColor = 0xff121212, }; BottomView.AddChidren (btnLine1); dialog.Show (); #endregion }; } void updateweek (Button btndisplaycycle) { btndisplaycycle.Text = ""; if (Logic.CurrentLogic.date.ContainsKey ("type")) { var type = Logic.CurrentLogic.date ["type"]?.ToString (); switch (type) { case "week": { //var weekvalue =Newtonsoft.Json.JsonConvert.DeserializeObject>(Newtonsoft.Json.JsonConvert.SerializeObject(Logic.CurrentLogic.date ["week"])); var weekvalue = Newtonsoft.Json.JsonConvert.DeserializeObject (Newtonsoft.Json.JsonConvert.SerializeObject (Logic.CurrentLogic.date ["week"])); if (weekvalue != null) { int a0 = Array.IndexOf (weekvalue, 0); int a1 = Array.IndexOf (weekvalue, 1); int a2 = Array.IndexOf (weekvalue, 2); int a3 = Array.IndexOf (weekvalue, 3); int a4 = Array.IndexOf (weekvalue, 4); int a5 = Array.IndexOf (weekvalue, 5); int a6 = Array.IndexOf (weekvalue, 6); if (weekvalue.Length == 2 && a0 != -1 && a6 != -1) { ///周未 btndisplaycycle.Text = Language.StringByID (MyInternationalizationString.weekend); } else if (weekvalue.Length == 5 && a1 != -1 && a2 != -1 && a3 != -1 && a4 != -1 && a5 != -1) { ///工作日 btndisplaycycle.Text = Language.StringByID (MyInternationalizationString.workingday); } else { for (int i = 0; i < 7; i++) { int a = Array.IndexOf (weekvalue, i); if (a != -1) { if (i == 1) { btndisplaycycle.Text += Language.StringByID (MyInternationalizationString.mon) + ","; } else if (i == 2) { btndisplaycycle.Text += Language.StringByID (MyInternationalizationString.tue) + ","; } else if (i == 3) { btndisplaycycle.Text += Language.StringByID (MyInternationalizationString.wed) + ","; } else if (i == 4) { btndisplaycycle.Text += Language.StringByID (MyInternationalizationString.thu) + ","; } else if (i == 5) { btndisplaycycle.Text += Language.StringByID (MyInternationalizationString.frl) + ","; } else if (i == 6) { btndisplaycycle.Text += Language.StringByID (MyInternationalizationString.sat) + ","; } else if (i == 0) { btndisplaycycle.Text += Language.StringByID (MyInternationalizationString.sun) + ","; } } } ///排列星期顺序(1,2,3......) //int b = Array.IndexOf (weekvalue, 0); //if (b != -1) { // btndisplaycycle.Text += Language.StringByID (MyInternationalizationString.sat) + ","; //} ///去掉字符串最后符号 btndisplaycycle.Text = btndisplaycycle.Text.TrimEnd (','); } } } break; case "day": { var weekvalue = Logic.CurrentLogic.date ["date"]?.ToString (); string [] s = weekvalue.Split ('-'); if (s [0] == s [1]) { btndisplaycycle.Text = s [0]; } else { btndisplaycycle.Text = weekvalue; } } break; case "every_day": { btndisplaycycle.Text = Language.StringByID (MyInternationalizationString.everyday); } break; case "every_month": { var weekvalue = Logic.CurrentLogic.date ["date"]?.ToString (); string [] s = weekvalue.Split ('-'); var startvalue = s [0].Split ('/') [2]; var endtvalue = s [1].Split ('/') [2]; if (s [0] == s [1]) { btndisplaycycle.Text = Language.StringByID (MyInternationalizationString.monthly) + startvalue + Language.StringByID (MyInternationalizationString.day); } else { btndisplaycycle.Text = Language.StringByID (MyInternationalizationString.monthly) + startvalue + Language.StringByID (MyInternationalizationString.day) + "-" + Language.StringByID (MyInternationalizationString.monthly) + endtvalue + Language.StringByID (MyInternationalizationString.day); } } break; case "every_year": { var weekvalue = Logic.CurrentLogic.date ["date"]?.ToString (); string [] s = weekvalue.Split ('-'); var startvalue = weekvalue.Split ('-') [0].Split ('/') [1] + "/" + weekvalue.Split ('-') [0].Split ('/') [2]; var endtvalue = weekvalue.Split ('-') [1].Split ('/') [1] + "/" + weekvalue.Split ('-') [1].Split ('/') [2]; if (s [0] == s [1]) { btndisplaycycle.Text = Language.StringByID (MyInternationalizationString.everyyear) + startvalue; } else { btndisplaycycle.Text = Language.StringByID (MyInternationalizationString.everyyear) + startvalue + "-" + Language.StringByID (MyInternationalizationString.everyyear) + endtvalue; } } break; } } } } }