wei
2021-08-27 eda3fb873e59544ff36301b51e05aef64f87b0f9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class Security : FrameLayout
    {
        public Security()
        {
            Tag = "Logic";
        }
        public void Show()
        {
 
            LogicView.TopView topView = new LogicView.TopView();
            this.AddChidren(topView.FLayoutView());
            topView.clickBackBtn.MouseUpEventHandler += (e, sen) =>
            {
                RemoveFromParent();
            };
            topView.topNameBtn.TextID = StringId.addSecurityLogic;
 
            VerticalScrolViewLayout viewLayout = new VerticalScrolViewLayout
            {
                Y = Application.GetRealHeight(64),
                Width = Application.GetRealWidth(LogicView.TextSize.view375),
                Height = Application.GetRealHeight(LogicView.TextSize.view667 - 64),
                BackgroundColor = CSS.CSS_Color.viewMiddle,
            };
            this.AddChidren(viewLayout);
            var securityList = LogicMethod.CurrLogicMethod.GetSecurityList();
            for (int i = 0; i < securityList.Count; i++)
            {
                var security = securityList[i];
                LogicView.SelectTypeView securityView = new LogicView.SelectTypeView();
                securityView.btnText.Text = security.name;
                securityView.btnIcon.UnSelectedImagePath = "LogicIcon/security.png";
                viewLayout.AddChidren(securityView.FLayoutView());
                securityView.btnClick.MouseUpEventHandler += (sen, e) =>
                {
                    SecurityMethod(this, security.sid);
                };
            }
 
        }
 
      
        /// <summary>
        /// 添加安防
        /// </summary>
        public void SecurityMethod(FrameLayout frameLayout,string sid, bool edit = false, int index1 = -1)
        {
            string stateStr = "";
            if (edit && index1 != -1)
            {
                Output output = Logic.currlogic.output[index1];
                sid = output.sid;
                for (int i = 0; i < output.status.Count; i++)
                {
                    var dic = output.status[i];
                    if (dic.ContainsKey("value"))
                    {
                        if (dic["value"] == "enable")
                        {
                            stateStr = Language.StringByID(StringId.bufang);
 
                        }
                        else
                        {
                            stateStr = Language.StringByID(StringId.chefang);
                        }
                    }
                }
            }
            PublicInterface conditionView = new PublicInterface();
            var strList = conditionView.GetViewList("security");
            conditionView.SingleSelectionShow(frameLayout, strList, Language.StringByID(StringId.addSecurityLogic), stateStr
         , (stateValue) =>
         {
 
             string selecttionMode = "";
             if (stateValue == Language.StringByID(StringId.bufang))
             {
                 selecttionMode = "enable";
             }
             else
             {
                 selecttionMode = "disable";
             }
             //封装数据
             Output outputDevice = new Output();
             outputDevice.target_type = "3";
             outputDevice.sid = sid;
             outputDevice.status = new List<Dictionary<string, string>> { new Dictionary<string, string> { { "key", "security" }, { "value", selecttionMode } } };
             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>
        /// <param name="target"></param>
        /// <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 (bool_if)
                {
                    ///安防允许一种
                    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);
                Logic.currlogic.output.Insert(indexValue, target);
            }
            else
            {
                Logic.currlogic.output.Add(target);
            }
 
        }
    }
}