tzy
2021-05-14 0fa1534827bd21d763216550d11006fc1441c6cb
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using Shared;
using HDL_ON.UI.CSS;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace HDL_ON.Stan
{
    /// <summary>
    /// 底部选择一个月内的一些日期的控件,不需要加到父控件,InitControl执行初始化
    /// </summary>
    public class BottomSomeDaySelectControl : BottomDialogCommon
    {
        #region ■ 变量声明___________________________
 
        /// <summary>
        /// 结束事件(0:点击了取消  1:点击了确定,参数是选择的日)
        /// </summary>
        public Action<int, List<int>> FinishEvent = null;
        /// <summary>
        /// 目前选择的日期
        /// </summary>
        private List<int> listSelectDay = new List<int>();
        /// <summary>
        /// 目标月份
        /// </summary>
        private int targetMonth = 0;
 
        #endregion
 
        #region ■ 初始化_____________________________
 
        /// <summary>
        /// 底部选择一个月内的一些日期的控件,不需要加到父控件,InitControl执行初始化
        /// </summary>
        /// <param name="i_title">标题</param>
        /// <param name="clickBackClose">点击背景时,是否关闭弹窗</param>
        /// <param name="i_month">显示执行月的日期,设置为0时,默认显示31天</param>
        public BottomSomeDaySelectControl(string i_title = "", bool clickBackClose = true, int i_month = 0)
        {
            base.ClickBackClose = clickBackClose;
            base.StrTitle = i_title;
            base.RowCount = 5;
            this.targetMonth = i_month;
        }
 
        /// <summary>
        /// 初始化控件
        /// </summary>
        /// <param name="listSelect">默认选择(日)</param>
        public void InitControl(List<int> listSelect)
        {
            //已经初始化
            if (base.btnCancel != null) { return; }
 
            this.listSelectDay.AddRange(listSelect);
            //初始化底层控件
            var frameWhiteBack = base.InitBaseControl();
 
            //取消
            base.btnCancel.ButtonClickEvent += (sender, e) =>
            {
                base.Close();
                this.FinishEvent?.Invoke(0, null);
                this.FinishEvent = null;
            };
            //确认
            base.btnConfirm.ButtonClickEvent += (sender, e) =>
            {
                //有选择了才能点确认
                if (this.listSelectDay.Count>0)
                {
                    base.Close();
 
                    //小的在前,大的在后
                    var listDay = new List<int>();
                    for (int i = 1; i <= 31; i++)
                    {
                        if (listSelectDay.Contains(i) == false) { continue; }
                        listDay.Add(i);
                    }
                    this.FinishEvent?.Invoke(1, listDay);
                    this.FinishEvent = null;
                }
            };
            //初始化日期列表控件
            this.InitDayListControl(frameWhiteBack);
        }
 
        /// <summary>
        /// 初始化日期列表控件
        /// </summary>
        private void InitDayListControl(NormalFrameLayout frameWhiteBack)
        {
            //获取显示的天数
            var dayCount = this.GetDayCount();
            //初始X轴16
            int xxValue = Application.GetRealWidth(16);
            //初始Y轴58
            int yyValue = Application.GetRealHeight(68);
            for (int i = 1; i <= dayCount; i++)
            {
                int intDay = i;
                var btnContr = new NormalViewControl(Application.GetRealWidth(30), Application.GetRealWidth(30), false);
                btnContr.X = xxValue;
                btnContr.Y = yyValue;
                btnContr.Radius = (uint)Application.GetRealWidth(15);
                btnContr.Text = intDay.ToString();
                btnContr.TextAlignment = TextAlignment.Center;
                btnContr.TextColor = CSS_Color.FirstLevelTitleColor;
                btnContr.SelectedTextColor = CSS_Color.MainBackgroundColor;
                btnContr.SelectedBackgroundColor = CSS_Color.MainColor;
                btnContr.BackgroundColor = CSS_Color.viewTranslucence;
                frameWhiteBack.AddChidren(btnContr);
 
                //换到下一行(每7个一行)
                if (i % 7 == 0)
                {
                    xxValue = Application.GetRealWidth(16);
                    //上下间距为10
                    yyValue = btnContr.Bottom + Application.GetRealHeight(10);
                }
                else
                {
                    //左右间距为16
                    xxValue = btnContr.Right + Application.GetRealWidth(16);
                }
                btnContr.ButtonClickEvent += (sender, e) =>
                {
                    btnContr.IsSelected = !btnContr.IsSelected;
                    if (btnContr.IsSelected == true)
                    {
                        //添加缓存
                        this.listSelectDay.Add(intDay);
                    }
                    else
                    {
                        //移除缓存
                        this.listSelectDay.Remove(intDay);
                    }
                };
                //是否初始选择
                btnContr.IsSelected = this.listSelectDay.Contains(intDay);
            }
        }
 
        #endregion
 
        #region ■ 一般方法___________________________
 
        /// <summary>
        /// 获取天数
        /// </summary>
        /// <returns></returns>
        private int GetDayCount()
        {
            if (this.targetMonth < 1 || this.targetMonth > 12) { return 31; }
 
            int two = DateTime.IsLeapYear(DateTime.Now.Year) == true ? 29 : 28;
            int[] arry = new int[] { 31, two, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
 
            return arry[this.targetMonth - 1];
        }
 
        /// <summary>
        /// 关闭界面
        /// </summary>
        public override void Close()
        {
            base.Close();
            this.FinishEvent = null;
        }
 
        #endregion
    }
}