陈嘉乐
2020-12-11 0414d9754bc61b5e496930ff184ede647ab4cc3a
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
using System;
using System.Collections.Generic;
using Shared;
namespace HDL_ON.UI.UI2.Intelligence.Automation
{
    public class PublicInterface
    {
        /// <summary>
        /// 单选择
        /// </summary>
        /// <param name="frameLayout">父控件</param>
        /// <param name="list">显示数据源</param>
        /// <param name="titleText"></param>
        /// <param name="stateText">之前状态文本</param>
        /// <param name="action">返回值</param>
        public void SingleSelectionShow(FrameLayout frameLayout, List<string> list, string titleText, string stateText, Action<string> action)
        {
            LogicView.DateView view = new LogicView.DateView();
            view.btnTitle.Text = titleText;
            view.FLayoutView(frameLayout, list.Count);
            view.btnCancel.MouseUpEventHandler += (sender, e) =>
            {
                //移除fLayout界面
                frameLayout.RemoveFromParent();
            };
            ///定义一个Btn记录选中状态
            Button checkBtn = new Button
            {
                Tag = "unknown",
            };
            for (int i = 0; i < list.Count; i++)
            {
                string str = list[i];
                LogicView.CheckView checkView = new LogicView.CheckView();
                checkView.frameLayout.Y = Application.GetRealHeight(56 + 50 * i);
                view.frameLayout.AddChidren(checkView.FLayoutView());
                checkView.btnText.Text = str;
                checkView.btnClick.Tag = str;//标记
 
                if (stateText == str)
                {
                    //显示之前的选中状态
                    checkBtn.IsSelected = false;
                    checkView.btnCheckIcon.IsSelected = true;
                    checkBtn = checkView.btnCheckIcon;
                    checkBtn.Tag = checkView.btnClick.Tag.ToString();
                }
                //点击事件
                checkView.btnClick.MouseUpEventHandler += (sender1, e1) =>
                {
                    checkBtn.IsSelected = false;
                    checkView.btnCheckIcon.IsSelected = true;
                    checkBtn = checkView.btnCheckIcon;
                    checkBtn.Tag = checkView.btnClick.Tag.ToString();
                };
 
            }
            view.btnConfirm.MouseUpEventHandler += (sender1, e1) =>
            {
                if (checkBtn.Tag.ToString() == "unknown")
                {
                    return;
                }
                action(checkBtn.Tag.ToString());
                //移除fLayout界面
                frameLayout.RemoveFromParent();
            };
 
        }
        /// <summary>
        /// 多选择
        /// </summary>
        /// <param name="frameLayout">父控件</param>
        /// <param name="list">显示数据源</param>
        /// <param name="titleText"></param>
        /// <param name="stateTextList">之前状态文本</param>
        /// <param name="action">返回值</param>
        public void MultiSelectShow(FrameLayout frameLayout, List<string> list, string titleText, List<string> stateTextList, Action<List<string>> action)
        {
            LogicView.DateView view = new LogicView.DateView();
            view.btnTitle.Text = titleText;
            view.FLayoutView(frameLayout, list.Count);
            view.btnCancel.MouseUpEventHandler += (sender, e) =>
            {
                //移除fLayout界面
                view.frameLayout.RemoveFromParent();
            };
            for (int i = 0; i < list.Count; i++)
            {
                string str = list[i];
                LogicView.CheckView checkView = new LogicView.CheckView();
                checkView.frameLayout.Y = Application.GetRealHeight(56 + 50 * i);
                view.frameLayout.AddChidren(checkView.FLayoutView());
                checkView.btnText.Text = str;
                checkView.btnClick.Tag = str;//标记
 
                if (stateTextList.Contains(str))
                {
                    //显示之前的选中状态
                    checkView.btnCheckIcon.IsSelected = true;
                }
                //点击事件
                checkView.btnClick.MouseUpEventHandler += (sender1, e1) =>
                {
 
                    string clickIndex = checkView.btnClick.Tag.ToString();
                    checkView.btnClick.IsSelected = !checkView.btnClick.IsSelected;
                    if (checkView.btnClick.IsSelected)
                    {
                        checkView.btnCheckIcon.IsSelected = true;
                        if (!stateTextList.Contains(clickIndex))
                        {
                            //添加选中数据
                            stateTextList.Add(clickIndex);
                        }
                    }
                    else
                    {
                        checkView.btnCheckIcon.IsSelected = false;
                        if (stateTextList.Contains(clickIndex))
                        {
                            //移除选中数据
                            stateTextList.Remove(clickIndex);
                        }
                    }
 
                };
 
            }
            view.btnConfirm.MouseUpEventHandler += (sender1, e1) =>
            {
                if (stateTextList.Count == 0)
                {
                    return;
                }
                action(stateTextList);
                //移除fLayout界面
                frameLayout.RemoveFromParent();
            };
 
        }
 
 
    }
}