Global.asax 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. <%@ Application Language="C#" %>
  2. <%@ Import Namespace="Curtain.DataAccess" %>
  3. <%@ Import Namespace="Curtain.Log" %>
  4. <%@ Import Namespace="DK.XuWei.WebMes" %>
  5. <script runat="server">
  6. // 定时器
  7. System.Timers.Timer tr = null;
  8. void Application_Start(object sender, EventArgs e)
  9. {
  10. // 在应用程序启动时运行的代码
  11. string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
  12. DataAccess.DefaultParameterType = SQLParameterType.CDA;
  13. DataAccess.DefaultDataBaseType = Curtain.DataAccess.DataBaseType.Oracle;
  14. DataAccess.DefaultConnectionString = connStr;
  15. string timerLoadFlag = ConfigurationManager.AppSettings["TimerLoadFlag"].ToString();
  16. if ("1".Equals(timerLoadFlag))
  17. {
  18. Logger.Debug("定时器启动");
  19. // 设置定时器
  20. tr_Load();
  21. }
  22. }
  23. //定时器任务 自动生成包装单=============================
  24. void tr_Load()
  25. {
  26. Logger.Debug("$$$定时器已启动$$$");
  27. //取刷新时间
  28. //int refreshTime = Convert.ToInt32(Application["WareHouseRefreshTime"]);
  29. //设置timer
  30. tr = new System.Timers.Timer(60000);
  31. tr.Elapsed += new System.Timers.ElapsedEventHandler(tr_RollingDailyPlan);
  32. tr.Enabled = true;
  33. tr.AutoReset = true;
  34. }
  35. void tr_RollingDailyPlan(object sender, EventArgs e)
  36. {
  37. DateTime day = DateTime.Now;
  38. string currTime = System.DateTime.Now.ToString("HH:mm");
  39. //Logger.Debug("当前时间:" + currTime);
  40. // 01:00触发 erp物料主数据
  41. if ("01:00".Equals(currTime))
  42. {
  43. string message = string.Empty;
  44. Logger.Debug("更新erp物料主数据:定时触发开始");
  45. message = SapMaterialCode.SyncSapMaterialCode();
  46. Logger.Debug("更新erp物料主数据:定时触发结束,结果:" + message);
  47. }
  48. }
  49. void Application_End(object sender, EventArgs e)
  50. {
  51. // 在应用程序关闭时运行的代码
  52. Logger.Debug("$$$定时器被关闭$$$");
  53. if (tr != null)
  54. {
  55. tr.Dispose();
  56. }
  57. // 重新唤醒当前应用
  58. ReworkHttp.Rework();
  59. }
  60. void Application_Error(object sender, EventArgs e)
  61. {
  62. // 在出现未处理的错误时运行的代码
  63. Exception error = Server.GetLastError().GetBaseException();
  64. if (error != null)
  65. {
  66. //记录日志
  67. Logger.Error(error);
  68. //输出错误信息
  69. HttpContext.Current.Response.Write(new JsonResult(JsonStatus.otherError).ToJson());
  70. }
  71. Server.ClearError();
  72. }
  73. void Session_Start(object sender, EventArgs e)
  74. {
  75. // 在新会话启动时运行的代码
  76. }
  77. void Session_End(object sender, EventArgs e)
  78. {
  79. // 在会话结束时运行的代码。
  80. // 注意: 只有在 Web.config 文件中的 sessionstate 模式设置为
  81. // InProc 时,才会引发 Session_End 事件。如果会话模式设置为 StateServer
  82. // 或 SQLServer,则不引发该事件。
  83. }
  84. </script>