wxr
2021-07-01 43b0d5870d528f23ecd6aeceb6cfd4325188b46f
HDL_ON/UI/UI2/3-Intelligence/Automation/MainView.cs
@@ -9,7 +9,7 @@
    public class MainView
    {
        /// <summary>
        /// 记录逻辑自动化父控件
        /// VerticalRefreshLayout父控件
        /// </summary>
        public static FrameLayout automationPage;
        /// <summary>
@@ -34,8 +34,8 @@
            };
            //获取自动化列表
            GetLogicList();
            // for (int i = Logic.LogicList.Count-1; i >= 0; i--)降序排列
            for (int i = 0; i < Logic.LogicList.Count; i++)
            for (int i = Logic.LogicList.Count - 1; i >= 0; i--)//降序排列
            //for (int i = 0; i < Logic.LogicList.Count; i++)
            {
                var currLogic = Logic.LogicList[i];
                ///上下间隔12像素
@@ -43,15 +43,17 @@
                LogicView.SingleLogicView logicView = new LogicView.SingleLogicView();
                vv.AddChidren(logicView.FLayoutView());
                logicView.btnLogicName.Text = currLogic.name;
                logicView.btnWeekText.Text = GetWeekText(currLogic);
                logicView.btnWeekText.Text = GetCyclicText(currLogic);
                logicView.btnclick.MouseUpEventHandler += (sen, e) =>
                {
                    Logic.currlogic = currLogic;
                    var addLogic = new AddLogic();
                    MainPage.BasePageView.AddChidren(addLogic);
                    addLogic.Show();
                    MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    //Logic.currlogic = currLogic;
                    //var addLogic = new AddLogic();
                    //MainPage.BasePageView.AddChidren(addLogic);
                    //addLogic.Show();
                    //MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                    new MainView { }.SkipAddLogicPage(currLogic);
                };
                //开关图标的点击事件
                logicView.btnSwitchIcon.MouseUpEventHandler += (sender1, e1) =>
                {
                    logicView.btnSwitchIcon.IsSelected = !logicView.btnSwitchIcon.IsSelected;
@@ -59,19 +61,29 @@
                    {
                        logicView.btnSwitchIcon.IsSelected = true;
                        currLogic.enable = "true";
                    }
                    else
                    {
                        logicView.btnSwitchIcon.IsSelected = false;
                        currLogic.enable = "false";
                    }
                    Send.switchLogic(currLogic);
                    //Send.switchLogic(currLogic);
                    new System.Threading.Thread(() =>
                    {
                        try
                        {
                            //逻辑使能的命令
                            Send.SwitchLogic(currLogic);
                        }
                        catch { }
                    })
                    { IsBackground = true }.Start();
                };
                //if (i==0)降序排列
                if (Logic.LogicList.Count - 1 == i)
                GetSelectIcon(logicView.frameLayout, currLogic);
                if (i == 0)//降序排列
                //if (Logic.LogicList.Count - 1 == i)
                {
                    ///最后一个距离最底部12,界面显示效果作用;
                    vv.AddChidren(new FrameLayout { Height = Application.GetRealHeight(12) });
@@ -99,12 +111,12 @@
                automationPage.AddChidren(btnTipNot);
                Button btnTipNotText = new Button()
                {
                    Y = btnTipNot.Bottom,
                    Height = Application.GetRealWidth(100),
                    TextID = StringId.TipNotOpen,
                    Y = btnTipNot.Bottom + Application.GetRealHeight(16),
                    Height = Application.GetRealHeight(20),
                    TextID = StringId.logicnull,
                    TextAlignment = TextAlignment.Center,
                    TextColor = CSS.CSS_Color.TextualColor,
                    TextSize = CSS.CSS_FontSize.PromptFontSize_FirstLevel,
                    TextSize = LogicView.TextSize.text14,
                    TextColor = CSS.CSS_Color.textConfirmColor,
                };
                automationPage.AddChidren(btnTipNotText);
            }
@@ -112,19 +124,36 @@
        /// <summary>
        ///  按+跳转到逻辑界面的方法
        /// </summary>
        public static void SkipAddLogicPage()
        public void SkipAddLogicPage(Logic logic=null)
        {
            Logic.currlogic = new Logic();
            var addLogic = new AddLogic();
            MainPage.BasePageView.AddChidren(addLogic);
            addLogic.Show();
            MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            if (logic == null)
            {
                Logic.currlogic = new Logic();
            }
            else {
                Logic.currlogic = logic;
            }
            if (IsGatewayType)
            {
                var addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            }
            else
            {
                var onePortAutomation = new OnePortAutomation();
                MainPage.BasePageView.AddChidren(onePortAutomation);
                onePortAutomation.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            }
        }
        /// <summary>
        ///返回循环描述文本
        /// </summary>
        /// <param name="logic"></param>
        public static string GetWeekText(Logic logic)
        public static string GetCyclicText(Logic logic)
        {
            string weekName = "";
@@ -157,39 +186,38 @@
            return weekName;
        }
        /// <summary>
        /// 获取星期的字符串
        /// 返回星期描述文本
        /// </summary>
        /// <param name="weekList"></param>
        /// <returns></returns>
        public static string GetWeekString(List<string> weekList)
        {
            string weekTextName = "";
            if (weekList.Contains("0"))
            if (weekList.Contains("1"))
            {
                weekTextName += Language.StringByID(StringId.monday) + ",";
            }
            if (weekList.Contains("1"))
            if (weekList.Contains("2"))
            {
                weekTextName += Language.StringByID(StringId.tuesday) + ",";
            }
            if (weekList.Contains("2"))
            if (weekList.Contains("3"))
            {
                weekTextName += Language.StringByID(StringId.wednesday) + ",";
            }
            if (weekList.Contains("3"))
            if (weekList.Contains("4"))
            {
                weekTextName += Language.StringByID(StringId.thursday) + ",";
            }
            if (weekList.Contains("4"))
            if (weekList.Contains("5"))
            {
                weekTextName += Language.StringByID(StringId.friday) + ",";
            }
            if (weekList.Contains("5"))
            if (weekList.Contains("6"))
            {
                weekTextName += Language.StringByID(StringId.saturday) + ",";
            }
            if (weekList.Contains("6"))
            if (weekList.Contains("0"))
            {
                weekTextName += Language.StringByID(StringId.sunday) + ",";
            }
@@ -220,9 +248,8 @@
        /// <summary>
        /// 获取逻辑列表
        /// </summary>
        private static void GetLogicList()
        public static void GetLogicList()
        {
            if (Logic.LogicList.Count != 0)
            {
                //自动化列表为0才去获取自动化列表;
@@ -230,8 +257,8 @@
            }
            List<string> logicIdList = new List<string>();
            //获取逻辑ID列表
            var idStr = Send.getLogicIdList();
            if (idStr.Code == "0" && idStr.Data != null)
            var idStr = Send.GetLogicIdList();
            if (idStr.Code == "0" && idStr.Data != null && idStr.Data.ToString() != "")
            {
                var date = Newtonsoft.Json.JsonConvert.SerializeObject(idStr.Data);
                var dateList = Newtonsoft.Json.JsonConvert.DeserializeObject<List<Date>>(date);
@@ -242,8 +269,8 @@
                }
            }
            //获取自动化列表
            var logicStr = Send.getLogic(logicIdList);
            if (logicStr.Code == "0" && logicStr.Data != null)
            var logicStr = Send.GetLogic(logicIdList);
            if (logicStr.Code == "0" && logicStr.Data != null && logicStr.Data.ToString() != "")
            {
                //获取逻辑详细返回是一个数组(object类型转换为数组);
                var jArray = JArray.Parse(logicStr.Data.ToString());
@@ -259,8 +286,40 @@
                        var if_logic = Logic.LogicList.Find((c) => c.userLogicId == logic.userLogicId);
                        if (if_logic == null)
                        {
                            Logic newlogic = new Logic();
                            newlogic.name = logic.name;
                            newlogic.userLogicId = logic.userLogicId;
                            newlogic.sid = logic.sid;
                            newlogic.relation = logic.relation;
                            newlogic.enable = logic.enable;
                            newlogic.cycle = logic.cycle;
                            for (int i = 0; i < logic.input.Count; i++)
                            {
                                if (logic.input[i] == null || string.IsNullOrEmpty(logic.input[i].condition_type))
                                {
                                    //防止调试软件乱传东西上来;
                                    //防止有空对象;
                                    //正常情况下不会出现的现象;
                                    continue;
                                }
                                newlogic.input.Add(logic.input[i]);
                            }
                            for (int i = 0; i < logic.output.Count; i++)
                            {
                                if (logic.output[i] == null || string.IsNullOrEmpty(logic.output[i].target_type))
                                {
                                    //防止调试软件乱传东西上来;
                                    //防止有空对象;
                                    //正常情况下不会该现象;
                                    continue;
                                }
                                newlogic.output.Add(logic.output[i]);
                            }
                            newlogic.noticeConfig = logic.noticeConfig;
                            newlogic.pushConfigs = logic.pushConfigs;
                            //添加逻辑
                            Logic.LogicList.Add(logic);
                            Logic.LogicList.Add(newlogic);
                        }
                    }
@@ -283,6 +342,189 @@
            }
            return false;
        }
        /// <summary>
        /// 显示条件或者目标类型图标
        /// </summary>
        /// <param name="layouFrame">父控件</param>
        /// <param name="logic">当前自动化</param>
        private static void GetSelectIcon(FrameLayout layouFrame, Logic logic)
        {
            //重新排列图标序号
            List<int> iconIntValue = new List<int>();
            iconIntValue.Clear();
            //1-10(表示条件图标)自己局部定义为了显示选中条件类型图标
            //1-时间图标
            //2-功能图标
            for (int i = 0; i < logic.input.Count; i++)
            {
                if (logic.input[i] == null)
                    continue;
                var int1 = int.Parse(logic.input[i].condition_type);
                int iconInt = 0;
                switch (int1)
                {
                    case 1:
                    case 2:
                        {
                            iconInt = 1;
                        }
                        break;
                    case 3:
                        {
                            iconInt = 2;
                        }
                        break;
                    case 4:
                    case 6:
                    case 9:
                        {
                            iconInt = 3;
                        }
                        break;
                }
                if (!iconIntValue.Contains(iconInt))
                {
                    iconIntValue.Add(iconInt);
                }
            }
            //分割条件和目标的图标
            iconIntValue.Add(11);
            //12-20(表示目标图标)自己局部定义为了显示选中目标类型图标
            //12-功能图标
            //13-场景图标
            //14-延时图标
            for (int i = 0; i < logic.output.Count; i++)
            {
                var int1 = int.Parse(logic.output[i].target_type);
                int iconInt = 0;
                switch (int1)
                {
                    case 1:
                        {
                            iconInt = 12;
                        }
                        break;
                    case 2:
                        {
                            iconInt = 13;
                        }
                        break;
                    case 3:
                        {
                            iconInt = 14;
                        }
                        break;
                }
                if (!iconIntValue.Contains(iconInt))
                {
                    iconIntValue.Add(iconInt);
                }
            }
            //图标控件的父控件
            FrameLayout frame = new FrameLayout
            {
                Height = Application.GetRealHeight(40),
                Width = Application.GetRealWidth(275),
                Y = Application.GetRealHeight(56),
            };
            layouFrame.AddChidren(frame);
            for (int i = 0; i < iconIntValue.Count; i++)
            {
                //图标控件
                Button btnIcon = new Button
                {
                    Width = Application.GetRealWidth(28),
                    Height = Application.GetRealWidth(28),
                    Gravity = Gravity.CenterVertical,
                };
                frame.AddChidren(btnIcon);
                if (i == 0)
                {
                    btnIcon.X = Application.GetRealWidth(12);
                }
                else
                {
                    btnIcon.X = Application.GetRealWidth(12 + (28 + 4) * i);
                }
                string strIcon = "";
                switch (iconIntValue[i])
                {
                    case 1:
                        {
                            strIcon = "LogicIcon/selectTheTime.png";
                        }
                        break;
                    case 2:
                        {
                            strIcon = "LogicIcon/selectTheFun.png";
                        }
                        break;
                    case 3:
                        {
                            strIcon = "LogicIcon/shiwaitianqi.png";
                        }
                        break;
                    case 11:
                        {
                            //分割条件和目标的图标
                            strIcon = "LogicIcon/link.png";
                        }
                        break;
                    case 12:
                        {
                            strIcon = "LogicIcon/selectTheFun.png";
                        }
                        break;
                    case 13:
                        {
                            strIcon = "LogicIcon/selectTheScene.png";
                        }
                        break;
                    case 14:
                        {
                            //strIcon = "LogicIcon/timeicon.png";
                        }
                        break;
                }
                btnIcon.UnSelectedImagePath = strIcon;
            }
        }
        /// <summary>
        /// 判断网关类型(0:bus网关;1:A协议网关)
        /// </summary>
        /// <returns></returns>
        public static bool IsGatewayType
        {
            get
            {
                if (Entity.DB_ResidenceData.Instance.GatewayType == 1)
                {
                    return true;
                }
                return false;
            }
        }
    }
    class Date
    {
@@ -290,12 +532,21 @@
        /// 云端唯一id
        /// </summary>
        public string userLogicId = "";
        /// <summary>
        /// 网关id
        /// </summary>
        public string gatewayId = "";
        /// <summary>
        /// 逻辑唯一标识
        /// </summary>
        public string sid = "";
        /// <summary>
        /// 逻辑名称
        /// </summary>
        public string name = "";
        /// <summary>
        /// 逻辑使能(开,关)
        /// </summary>
        public string enable = "";
        //public CycleA cycle;
        //public string modifyTime = "";