using System; using System.Collections.Generic; using Shared; using Shared.Common; using Shared.Phone; using Shared.R; using ZigBee.Device; namespace Shared.Phone.Device.Logic { class SelectedLogicStatus:FrameLayout { public SelectedLogicStatus () { Tag = "Logic"; } public bool IsDeviceEditor; Dictionary logicConditionsInfo = new Dictionary(); public void Show (Common.Logic logic) { this.BackgroundColor = ZigbeeColor.Current.LogicTopViewBackgroundColor; this.AddChidren (new Button { Height = Application.GetRealHeight (80), }); var topFrameLayout = new FrameLayout { Height = Application.GetRealHeight (140), Y = Application.GetRealHeight (80), }; AddChidren (topFrameLayout); var titleName = new Button { TextID = MyInternationalizationString.automation, TextSize = 16, TextColor = ZigbeeColor.Current.LogicTextBlackColor, IsBold = true, }; topFrameLayout.AddChidren (titleName); var back = new Button { Width = Application.GetRealWidth (110), Height = Application.GetRealHeight (110), X = Application.GetRealWidth (20), Gravity = Gravity.CenterVertical, UnSelectedImagePath = "ZigeeLogic/Back.png", }; topFrameLayout.AddChidren (back); back.MouseDownEventHandler += (sender, e) => { RemoveFromParent (); IsDeviceEditor = false; }; var tetleframeLayout = new FrameLayout { Y = topFrameLayout.Bottom, Height = Application.GetRealHeight (180), //BackgroundColor = 0xff0f0f0f, }; AddChidren (tetleframeLayout); var tetlebtn = new Button { Width = Application.GetRealWidth (700), TextID = MyInternationalizationString.selectsavedautomationstate, //Text = "请选择已保存自动化", TextSize = 16, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (40), TextColor = ZigbeeColor.Current.LogicTextBlackColor, }; tetleframeLayout.AddChidren (tetlebtn); var middle = new VerticalScrolViewLayout (); middle.Y = tetleframeLayout.Bottom; middle.Height = Application.GetRealHeight (1920 - 220 - 180 - 174); middle.BackgroundColor = ZigbeeColor.Current.LogicBackgroundColor; this.AddChidren (middle); var openRowLayout = new RowLayout { Height = Application.GetRealHeight (180), }; middle.AddChidren (openRowLayout); var btnlogicopen = new Button { Width = Application.GetRealWidth (600), TextID = MyInternationalizationString.open1, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (40), TextColor = ZigbeeColor.Current.LogicTextBlackColor, }; openRowLayout.AddChidren (btnlogicopen); string IsselectedLogic = null; var disableRowLayout = new RowLayout { Height = Application.GetRealHeight (180), }; middle.AddChidren (disableRowLayout); var btnlogicdisable = new Button { Width = Application.GetRealWidth (600), TextID = MyInternationalizationString.disable, TextAlignment = TextAlignment.CenterLeft, X = Application.GetRealWidth (40), TextColor = ZigbeeColor.Current.LogicTextBlackColor, }; disableRowLayout.AddChidren (btnlogicdisable); ///开启点击事件 EventHandler copenclick = (seder, e) => { openRowLayout.BackgroundColor = 0xfffe5e00; disableRowLayout.BackgroundColor = 0x00000000; IsselectedLogic = "true"; if (logicConditionsInfo.ContainsKey("IsValid")) { logicConditionsInfo.Remove("IsValid"); } logicConditionsInfo.Add("IsValid","1"); }; openRowLayout.MouseUpEventHandler += copenclick; btnlogicopen.MouseUpEventHandler += copenclick; ///禁止点击事件 EventHandler disableclick = (seder, e) => { openRowLayout.BackgroundColor = 0x00000000; disableRowLayout.BackgroundColor = 0xfffe5e00; IsselectedLogic = "false"; if(logicConditionsInfo.ContainsKey("IsValid")){ logicConditionsInfo.Remove("IsValid"); } logicConditionsInfo.Add("IsValid", "0"); }; disableRowLayout.MouseUpEventHandler += disableclick; btnlogicdisable.MouseUpEventHandler += disableclick; if (IsDeviceEditor) { foreach (var conditions in Common.Logic.CurrentLogic.Conditions) { if(conditions["Type"]=="2"){ if(logic.LogicId.ToString()==conditions["Condition_LogicId"]){ if (conditions["IsValid"]== "1") { openRowLayout.BackgroundColor = 0xfffe5e00; disableRowLayout.BackgroundColor = 0x00000000; } else if(conditions["IsValid"] == "0") { openRowLayout.BackgroundColor = 0x00000000; disableRowLayout.BackgroundColor = 0xfffe5e00; } break; } } } }; var btncomplete = new Button { Y = middle.Bottom, Height = Application.GetRealHeight(174), TextID = MyInternationalizationString.complete, TextSize = 16, TextColor = ZigbeeColor.Current.LogicTextBlackColor, }; AddChidren (btncomplete); if (logicConditionsInfo.ContainsKey("Type")) { logicConditionsInfo.Remove("Type"); } if (logicConditionsInfo.ContainsKey("Condition_LogicId")) { logicConditionsInfo.Remove("Condition_LogicId"); } logicConditionsInfo.Add("Type","2"); logicConditionsInfo.Add("Condition_LogicId",logic.LogicId.ToString()); btncomplete.MouseUpEventHandler += (sedder, e) => { if (IsselectedLogic != null) { LogicIfon.AddLogicconditions(logic,logicConditionsInfo); } else { if (!IsDeviceEditor) { var alert = new Alert(Language.StringByID(MyInternationalizationString.Prompt), Language.StringByID(MyInternationalizationString.selectlogiccondition), Language.StringByID(MyInternationalizationString.complete)); alert.Show(); return; } IsDeviceEditor = false; } var logicCommunalPage = new LogicCommunalPage (); UserView.HomePage.Instance.AddChidren (logicCommunalPage); UserView.HomePage.Instance.PageIndex += 1; logicCommunalPage.Show (() => { }); //var selectedLogic = new SelectedLogic (); //MainPage.MainFrameLayout.AddChidren (selectedLogic); //selectedLogic.Show (gateWay, logic); }; } } }