xm
2021-12-01 6d73bf6e816570291865674bef8bce8972e4de3f
HDL_ON/UI/UI2/3-Intelligence/Automation/AddTarget.cs
@@ -36,21 +36,29 @@
            viewLayout.AddChidren(functionView.FLayoutView());
            //场景
            LogicView.SelectTypeView sceneView = new LogicView.SelectTypeView();
            LogicView.SelectTypeView sceneView= new LogicView.SelectTypeView();
            sceneView.frameLayout.Y = functionView.frameLayout.Bottom;
            sceneView.btnText.TextID = StringId.Scenes;
            sceneView.btnIcon.UnSelectedImagePath = "LogicIcon/scene.png";
            viewLayout.AddChidren(sceneView.FLayoutView());
            //安防
            LogicView.SelectTypeView securityView = new LogicView.SelectTypeView();
            securityView.frameLayout.Y = sceneView.frameLayout.Bottom;
            securityView.btnText.TextID = StringId.anfang;
            securityView.btnIcon.UnSelectedImagePath = "LogicIcon/security.png";
            viewLayout.AddChidren(securityView.FLayoutView());
            //延时
            LogicView.SelectTypeView delayView = new LogicView.SelectTypeView();
            delayView.frameLayout.Y = sceneView.frameLayout.Bottom;
            delayView.btnText.TextID = StringId.delayLogic;
            delayView.btnIcon.UnSelectedImagePath = "LogicIcon/delayed.png";
            viewLayout.AddChidren(delayView.FLayoutView());
            delayView.btnIcon.UnSelectedImagePath = "LogicIcon/time.png";
            //viewLayout.AddChidren(delayView.FLayoutView());
            #endregion
            #region  所有点击事件
            //功能点击事件
            functionView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                FunTpye funTpye = new FunTpye();
@@ -59,18 +67,22 @@
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            //场景点击事件
            sceneView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                FrameLayout fLayout = new FrameLayout
                {
                    BackgroundColor = CSS.CSS_Color.viewTrans60lucence,
                };
                this.AddChidren(fLayout);
                SceneMethod(fLayout);
                SceneMethod();
            };
            //安防点击事件
            securityView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
                Security security = new Security();
                MainPage.BasePageView.AddChidren(security);
                security.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
                //SecurityMethod(this);
            };
            //延时点击事件
            delayView.btnClick.MouseUpEventHandler += (sen, e) =>
            {
@@ -88,84 +100,66 @@
        /// <summary>
        /// 添加场景
        /// </summary>
        /// <param name="fLayout">弹框主控件</param>
        public void SceneMethod(FrameLayout fLayout)
        public void SceneMethod()
        {
            LogicView.DateView dateView = new LogicView.DateView();
            dateView.btnTitle.TextID = StringId.addSceneLogic;
            dateView.FLayoutView(fLayout, 5);
            dateView.btnCancel.MouseUpEventHandler += (sender2, e2) =>
            {
                fLayout.RemoveFromParent();
            };
            VerticalRefreshLayout verticalRefresh = new VerticalRefreshLayout
            {
                Y = Application.GetRealHeight(56),
                Height = Application.GetRealHeight(50 * 5),
            };
            dateView.frameLayout.AddChidren(verticalRefresh);
            //定义一个局部变量记录选中状态
            Button buttonClick = new Button();
            HDL_ON.Entity.Scene sceneSelecetd = null;
            var sceneList = LogicMethod.GetSceneList();
            verticalRefresh.BeginHeaderRefreshingAction += () =>
            {
                //关闭刷新View;
                verticalRefresh.EndHeaderRefreshing();
            };
            for (int i = 0; i < sceneList.Count; i++)
            {
            var sceneList = LogicMethod.CurrLogicMethod.GetSceneList();
            List<string> nameList = new List<string>();
            for (int i = 0; i < sceneList.Count; i++) {
                var scene = sceneList[i];
                LogicView.SelectTypeView sceneView = new LogicView.SelectTypeView();
                sceneView.frameLayout.BackgroundColor = CSS.CSS_Color.viewTranslucence;
                sceneView.btnIcon.Visible = false;
                sceneView.btnText.X = Application.GetRealWidth(20);
                sceneView.btnText.Text = scene.name;
                sceneView.btnLine.X = Application.GetRealWidth(20);
                sceneView.btnLine.Width = Application.GetRealWidth(303);
                sceneView.btnNextIcon.X = Application.GetRealWidth(303);
                sceneView.btnNextIcon.Width = Application.GetMinRealAverage(28);
                sceneView.btnNextIcon.Height = Application.GetMinRealAverage(28);
                sceneView.btnNextIcon.UnSelectedImagePath = "LogicIcon/weekoff.png";
                sceneView.btnNextIcon.SelectedImagePath = "LogicIcon/weekon.png";
                verticalRefresh.AddChidren(sceneView.FLayoutView());
                sceneView.btnClick.Tag = scene;//标记索引
                //场景的点击事件
                sceneView.btnClick.MouseUpEventHandler += (sender, e) =>
                {
                    buttonClick.IsSelected = false;
                    sceneView.btnNextIcon.IsSelected = true;
                    buttonClick = sceneView.btnNextIcon;
                    sceneSelecetd =sceneView.btnClick.Tag as HDL_ON.Entity.Scene;
                };
                nameList.Add(scene.name);
            }
            //确认点击事件
            dateView.btnConfirm.MouseUpEventHandler += (sender1, e1) =>
            PublicInterface publicInterface = new PublicInterface();
            publicInterface.FrameOrVv(this, nameList,new List<string> { }, StringId.addSceneLogic, (index) =>
            {
                if (sceneSelecetd == null)
                {
                    //提示:还没选中执行周期
                    return;
                }
                var sceneSelecetd = sceneList[index];
                Output outputDevice = new Output();
                outputDevice.target_type = "2";
                outputDevice.sid = sceneSelecetd.sid;
                //没啥作用,为了数据格式统一,发送时不再判断
                outputDevice.status = new List<Dictionary<string, string>> { new Dictionary<string, string> { { "key", "scene"},{ "value", "0" } } };
                //没啥作用,为了发送数据格式统一;
                outputDevice.status = new List<Dictionary<string, string>> { new Dictionary<string, string> { { "key", "scene" }, { "value", "0" } } };
                AddOutput(outputDevice);
                fLayout.RemoveFromParent();
                LogicMethod.RemoveAllView();
                LogicMethod.CurrLogicMethod.RemoveAllView();
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            };
            });
        }
        /// <summary>
        /// 添加安防
        /// </summary>
        public void SecurityMethod(FrameLayout frameLayout, bool edit=false, int index1=-1)
        {
            List<string> stateList = new List<string>();
            if (edit&& index1 != -1) {
                Output output = Logic.currlogic.output[index1];
                var security = LogicMethod.CurrLogicMethod.GetSecurity(output.sid);
                stateList.Add(security.name);
            }
            var securityList = LogicMethod.CurrLogicMethod.GetSecurityList();
            List<string> nameList = new List<string>();
            for (int i = 0; i < securityList.Count; i++)
            {
                var security = securityList[i];
                nameList.Add(security.name);
            }
            PublicInterface publicInterface = new PublicInterface();
            publicInterface.FrameOrVv(frameLayout, nameList, stateList, StringId.addSecurityLogic,(index) =>
            {
                var securitySelecetd = securityList[index];
                Output outputDevice = new Output();
                outputDevice.target_type = "3";
                outputDevice.sid = securitySelecetd.sid;
                //没啥作用,为了发送数据格式统一;
                outputDevice.status = new List<Dictionary<string, string>> { new Dictionary<string, string> { { "key", "security" }, { "value", "0" } } };
                AddOutput(outputDevice,true);
                LogicMethod.CurrLogicMethod.RemoveAllView();
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
                MainPage.BasePageView.PageIndex = MainPage.BasePageView.ChildrenCount - 1;
            });
        }
        /// <summary>
        /// 延时时间方法
        /// </summary>
@@ -194,13 +188,13 @@
            if (edit)
            {
                Output output = Logic.currlogic.output[index];
                if (output.target_type == "3")
                if (output.target_type == "4")
                {
                    List<Dictionary<string, string>> dicList = output.status as List<Dictionary<string, string>>;
                    foreach (var dic in dicList)
                    {
                        string timeValue = dic["value"];
                        int hIndex = timePointView.GetValueIndex(timeValue, 0, 1, timePointView.GethIntList0());
                        int hIndex = timePointView.GetValueIndex(timeValue, 0, 1, timePointView.GethIntList());
                        int mIndex = timePointView.GetValueIndex(timeValue, 1, 0, timePointView.GetmIntList());
                        //更新初始状态
                        timePointView.mUIPickerView.setCurrentItems(hIndex, mIndex, 0);
@@ -225,11 +219,11 @@
                    return;
                }
                Output outputTime= new Output();
                outputTime.sid = LogicMethod.NewSid();
                outputTime.target_type = "3";
                outputTime.sid = LogicMethod.CurrLogicMethod.NewSid();
                outputTime.target_type = "4";
                Dictionary<string, string> dic = new Dictionary<string, string>();
                LogicMethod.dictionary(dic, "key", "delay");
                LogicMethod.dictionary(dic, "value", timepoint);
                LogicMethod.CurrLogicMethod.dictionary(dic, "key", "delay");
                LogicMethod.CurrLogicMethod.dictionary(dic, "value", timepoint);
                outputTime.status.Add(dic);
                if (edit)
                {
@@ -244,7 +238,7 @@
                    AddOutput(outputTime);
                }
                fLayout.RemoveFromParent();
                LogicMethod.RemoveAllView();
                LogicMethod.CurrLogicMethod.RemoveAllView();
                AddLogic addLogic = new AddLogic();
                MainPage.BasePageView.AddChidren(addLogic);
                addLogic.Show();
@@ -252,23 +246,34 @@
            };
        }
        /// <summary>
        /// 添加目标
        /// </summary>
        /// <param name="target"></param>
        private void AddOutput(Output target)
        /// <param name="bool_if">表示启用不同条件</param>
        private void AddOutput(Output target,bool bool_if=false)
        {
            int indexValue = -1;
            for (int i = 0; i < Logic.currlogic.output.Count; i++)
            {
                if (Logic.currlogic.output[i].sid == target.sid)
                if (bool_if)
                {
                    indexValue = i;
                    break;
                    ///安防允许一种
                    if (Logic.currlogic.output[i].target_type == target.target_type)
                    {
                        indexValue = i;
                        break;
                    }
                }
                else
                {
                    if (Logic.currlogic.output[i].sid == target.sid)
                    {
                        indexValue = i;
                        break;
                    }
                }
            }
            if (indexValue != -1)
            {
                Logic.currlogic.output.RemoveAt(indexValue);