xm
2021-12-01 6d73bf6e816570291865674bef8bce8972e4de3f
HDL_ON/UI/UI2/3-Intelligence/Automation/WeatherCondition.cs
@@ -16,29 +16,7 @@
            topView.frameLayout.Height = Application.GetRealHeight(64 + 20);
            this.AddChidren(topView.FLayoutView());
            topView.topNameBtn.TextID = StringId.selectionCondition;
            //获取宽度
            int widthValue = topView.topNameBtn.GetTextWidth();
            int textWidth = (Application.GetRealWidth(255) - widthValue) / 2;
            Button locationBtn = new Button
            {
                Width = Application.GetRealWidth(18),
                Height = Application.GetRealWidth(18),
                X = Application.GetRealWidth(60 + 4) + textWidth + widthValue,
                Y = Application.GetRealHeight(34 + 1),
                UnSelectedImagePath = "LogicIcon/location.png",
            };
            topView.frameLayout.AddChidren(locationBtn);
            Button textBtn = new Button
            {
                Height = Application.GetRealHeight(14),
                Y = Application.GetRealHeight(57),
                TextSize = LogicView.TextSize.text10,
                TextColor = CSS.CSS_Color.textCancelColor,
                Text = "广东广州市番禺区石楼镇",
            };
            topView.frameLayout.AddChidren(textBtn);
            topView.Location();
            topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
            {
                RemoveFromParent();
@@ -78,15 +56,15 @@
                    string text = view.btnClick.Tag.ToString();
                    if (text == Language.StringByID(StringId.clearday))
                    {
                        value = "sunny";
                        value = "Sunny";
                    }
                    else if (text == Language.StringByID(StringId.cloudy))
                    {
                        value = "cloudy";
                        value = "Cloudy";
                    }
                    else if (text == Language.StringByID(StringId.rain))
                    {
                        value = "rainy";
                        value = "Rain";
                    }
                    AddDic(value);
                };
@@ -100,21 +78,21 @@
        private void AddDic(string value)
        {
            Input input = new Input(); 
            input.sid = LogicMethod.NewSid();
            input.sid = LogicMethod.CurrLogicMethod.NewSid();
            input.condition_type = "6";
            Dictionary<string, string> dic = new Dictionary<string, string>();
            LogicMethod.dictionary(dic, "key", "weather");
            LogicMethod.dictionary(dic, "comparator", "=");
            LogicMethod.dictionary(dic, "data_type", "string");
            LogicMethod.dictionary(dic, "value", value);
            LogicMethod.CurrLogicMethod.dictionary(dic, "key", "weather");
            LogicMethod.CurrLogicMethod.dictionary(dic, "comparator", "=");
            LogicMethod.CurrLogicMethod.dictionary(dic, "data_type", "string");
            LogicMethod.CurrLogicMethod.dictionary(dic, "value", value);
            input.condition.Add(dic);
            AddCondition(input);
            AddCondition(input, "weather",  "=");
        }
        /// <summary>
        /// 添加条件
        /// </summary>
        /// <param name="input"></param>
        private void AddCondition(Input input)
        private void AddCondition(Input input, string keyValue, string comparator)
        {
            ///记录索引值
            int index = -1;
@@ -123,9 +101,13 @@
                var condition_type = Logic.currlogic.input[i].condition_type;
                if (condition_type == "6")
                {
                    ///找到标记索引,退出循环体
                    index = i;
                    break;
                    var dicList = Logic.currlogic.input[i].condition;
                    if (ExistKey(dicList, keyValue, comparator))
                    {
                        ///找到标记索引,退出循环体
                        index = i;
                        break;
                    }
                }
            }
            if (index != -1)
@@ -140,12 +122,34 @@
                Logic.currlogic.input.Add(input);
            }
            LogicMethod.RemoveAllView();
            LogicMethod.CurrLogicMethod.RemoveAllView();
            AddLogic addLogic = new AddLogic();
            MainPage.BasePageView.AddChidren(addLogic);
            addLogic.Show();
            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
        }
        /// <summary>
        /// 判断是否存在Key
        /// </summary>
        /// <param name="dicList"></param>
        /// <param name="keyValue"></param>
        /// <param name="comparator">比较关系</param>
        /// <returns></returns>
        private bool ExistKey(List<Dictionary<string, string>> dicList, string keyValue, string comparator)
        {
            for (int i = 0; i < dicList.Count; i++)
            {
                var dic = dicList[i];
                string key = dic["key"];
                string comparatorValue = dic["comparator"];
                if (key == keyValue && comparatorValue == comparator)
                {
                    //判断是否存在
                    return true;
                }
            }
            return false;
        }
    }
}