| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- using VberZero.Tools.StringModel;
- namespace VberAdmin.Web.Models.Search;
- public class VmDateItem
- {
- public VmDateItem(int interval = 30, string formatter = "YYYY-MM-DD", bool isAutoApply = true)
- {
- Interval = interval;
- Formatter = formatter;
- IsAutoApply = isAutoApply;
- }
- public VmDateItem(string formatter, bool isAutoApply = true) : this(30, formatter, isAutoApply)
- {
- Formatter = formatter;
- IsAutoApply = isAutoApply;
- }
- public bool IsAutoApply { get; set; }
- public string Value { get; set; }
- private int _interval;
- public int Interval
- {
- get => _interval > 0 ? _interval : 30;
- set => _interval = value;
- }
- public string Formatter { get; set; }
- public string IsAutoApplyStr => IsAutoApply ? "true" : "false";
- public string EndDate => GetDateStr();
- public string StartDate => GetDateStr(1);
- private string GetDateStr(int type = 0)
- {
- if (Value.Empty())
- {
- return type == 0
- ? DateTime.Today.ToString("yyyy-MM-dd")
- : DateTime.Today.AddDays(0 - Interval).ToString("yyyy-MM-dd");
- }
- string str = "";
- try
- {
- ; string[] arrDate = Value.Split(new[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
- if (type == 0)
- {
- return Convert.ToDateTime(arrDate[0]).ToString("yyyy-MM-dd");
- }
- if (arrDate.Length > 1)
- {
- return Convert.ToDateTime(arrDate[1]).ToString("yyyy-MM-dd");
- }
- return Convert.ToDateTime(arrDate[0]).AddDays(0 - Interval).ToString("yyyy-MM-dd");
- }
- catch
- {
- //
- }
- return str;
- }
- }
|