VmDateItem.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using VberZero.Tools.StringModel;
  2. namespace VberAdmin.Web.Models.Search;
  3. public class VmDateItem
  4. {
  5. public VmDateItem(int interval = 30, string formatter = "YYYY-MM-DD", bool isAutoApply = true)
  6. {
  7. Interval = interval;
  8. Formatter = formatter;
  9. IsAutoApply = isAutoApply;
  10. }
  11. public VmDateItem(string formatter, bool isAutoApply = true) : this(30, formatter, isAutoApply)
  12. {
  13. Formatter = formatter;
  14. IsAutoApply = isAutoApply;
  15. }
  16. public bool IsAutoApply { get; set; }
  17. public string Value { get; set; }
  18. private int _interval;
  19. public int Interval
  20. {
  21. get => _interval > 0 ? _interval : 30;
  22. set => _interval = value;
  23. }
  24. public string Formatter { get; set; }
  25. public string IsAutoApplyStr => IsAutoApply ? "true" : "false";
  26. public string EndDate => GetDateStr();
  27. public string StartDate => GetDateStr(1);
  28. private string GetDateStr(int type = 0)
  29. {
  30. if (Value.Empty())
  31. {
  32. return type == 0
  33. ? DateTime.Today.ToString("yyyy-MM-dd")
  34. : DateTime.Today.AddDays(0 - Interval).ToString("yyyy-MM-dd");
  35. }
  36. string str = "";
  37. try
  38. {
  39. ; string[] arrDate = Value.Split(new[] { '@' }, StringSplitOptions.RemoveEmptyEntries);
  40. if (type == 0)
  41. {
  42. return Convert.ToDateTime(arrDate[0]).ToString("yyyy-MM-dd");
  43. }
  44. if (arrDate.Length > 1)
  45. {
  46. return Convert.ToDateTime(arrDate[1]).ToString("yyyy-MM-dd");
  47. }
  48. return Convert.ToDateTime(arrDate[0]).AddDays(0 - Interval).ToString("yyyy-MM-dd");
  49. }
  50. catch
  51. {
  52. //
  53. }
  54. return str;
  55. }
  56. }