FunGetFdm.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System;
  2. using IwbZero.Expr;
  3. using IwbZero.ToolCommon.StringModel;
  4. namespace IwbZero.ExprFunctions.Functions
  5. {
  6. /// <summary>
  7. /// 获取日期(年-月-01)
  8. /// </summary>
  9. public class FunGetFdm:IIwbFunction
  10. {
  11. public string Invoke(ExprObject exprObj)
  12. {
  13. DateTime now = DateTime.Now;
  14. int num = now.Year;
  15. now = DateTime.Now;
  16. int num2 = now.Month;
  17. ExprObject child = exprObj.GetChild(0);
  18. if (child != null)
  19. {
  20. ExprTypes exprTypes = EvalExpr.GetExprTypes(child);
  21. if (exprTypes == ExprTypes.Date || exprTypes == ExprTypes.String)
  22. {
  23. DateTime dateTime = child.Expr.StrToDt();
  24. num = dateTime.Year;
  25. num2 = dateTime.Month;
  26. }
  27. else
  28. {
  29. num = child.Expr.ValI();
  30. if (num == 0)
  31. {
  32. now = DateTime.Now;
  33. num = now.Year;
  34. }
  35. child = exprObj.GetChild(2);
  36. if (child != null)
  37. {
  38. num2 = child.Expr.ValI();
  39. }
  40. if (num2 == 0)
  41. {
  42. now = DateTime.Now;
  43. num2 = now.Month;
  44. }
  45. }
  46. }
  47. return $"{num}-{num2}-01";
  48. }
  49. }
  50. }