You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.8 KiB

  1. 
  2. namespace CounsellorBL.BLStructure
  3. {
  4. using CounsellorBL.Helper;
  5. using MonumentDefine;
  6. using Newtonsoft.Json;
  7. using Newtonsoft.Json.Linq;
  8. using OT.COM.LogisticsUtil;
  9. using SoldierData.EnterprizeV4;
  10. using System;
  11. using System.Collections.Generic;
  12. public class ScheduleRange
  13. {
  14. public DateTime Start { get; set; }
  15. public DateTime End { get; set; }
  16. public static string ParseLogStartEnd(string i_sTarget, JArray i_jaData, out ScheduleRange o_srResult,
  17. [System.Runtime.CompilerServices.CallerLineNumber] int i_nCodeLine = 0,
  18. [System.Runtime.CompilerServices.CallerMemberName] string i_sMemberName = "",
  19. [System.Runtime.CompilerServices.CallerFilePath] string i_sSourcePath = "")
  20. {
  21. string sMsg = null;
  22. int nStartLim = 14;
  23. if (SystemSettingHelper.GetSetting(BLWording.LOG_RANGE, out tb_sys_system_setting sResult) == null &&
  24. Int32.TryParse(sResult.key_value, out int nStartSetting))
  25. {
  26. nStartLim = nStartSetting;
  27. }
  28. DateTime dtToday = DateTime.Now.Date;
  29. DateTime dtLim = dtToday.AddDays(-1 * nStartLim);
  30. ScheduleRange sr = new ScheduleRange() { Start = dtLim, End = dtToday.AddYears(1) };
  31. try
  32. {
  33. do
  34. {
  35. if (i_jaData == null || i_jaData.Count == 0)
  36. {
  37. sMsg = MessageWording.PARAM_NOT_EXPECTED;
  38. break;
  39. }
  40. Dictionary<string, object> dicWhere = i_jaData[0][BLWording.WHEREDATA].ToObject<Dictionary<string, object>>();
  41. if (dicWhere.ContainsKey(i_sTarget + "_start") && DateTime.TryParse(dicWhere[i_sTarget + "_start"].ToString(), out DateTime dtParsed) && dtParsed > sr.Start)
  42. {
  43. sr.Start = dtParsed;
  44. }
  45. if (dicWhere.ContainsKey(i_sTarget + "_end") && DateTime.TryParse(dicWhere[i_sTarget + "_end"].ToString(), out DateTime dtParsed2) && dtParsed2 > dtLim)
  46. {
  47. sr.End = dtParsed2;
  48. }
  49. // End Add 1
  50. sr.End = sr.End.AddDays(1);
  51. }
  52. while (false);
  53. }
  54. catch (Exception ex)
  55. {
  56. LogHelper.DBLog(Util.GetLastExceptionMsg(ex), i_nCodeLine, i_sMemberName, i_sSourcePath);
  57. sMsg = $"{nameof(ParseLogStartEnd)} unknwon exception. i_jaData={JsonConvert.SerializeObject(i_jaData)}. Call from {i_sMemberName} {i_sSourcePath}({i_nCodeLine}).";
  58. #if DEBUG
  59. System.Diagnostics.Debug.WriteLine(sMsg);
  60. #endif
  61. }
  62. o_srResult = sr;
  63. return sMsg;
  64. }
  65. }
  66. }