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
|
}
|
}
|