Global.asax.cs 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789
  1. using System;
  2. using System.Globalization;
  3. using System.Net;
  4. using System.ServiceModel.Activation;
  5. using System.Timers;
  6. using System.Web;
  7. using System.Web.Routing;
  8. using Curtain.DataAccess;
  9. using Curtain.Extension.ExObjectConvert;
  10. using Curtain.Log;
  11. using Dongke.IBOSS.PRD.Basics.BaseResources;
  12. using Dongke.IBOSS.PRD.Basics.DataAccess;
  13. using Dongke.IBOSS.PRD.Basics.Library;
  14. using Dongke.IBOSS.PRD.WCF.Contracts;
  15. using Dongke.IBOSS.PRD.WCF.ExHGS3QRS;
  16. using Dongke.IBOSS.PRD.WCF.Services;
  17. namespace Dongke.IBOSS.PRD.WCF.WebHosting
  18. {
  19. public class Global : HttpApplication
  20. {
  21. protected void Application_Start(object sender, EventArgs e)
  22. {
  23. Logger.DefaultLogDirectory = "Log";
  24. InitService();
  25. // 更改连接串
  26. INIUtility ini = INIUtility.Instance(INIUtility.IniFile.Config);
  27. DataManager.ConnectionString = string.Format(DataManager.ConnectionStringFormat,
  28. ini.ReadIniData("DBSetting", "DBIP"),
  29. ini.ReadIniData("DBSetting", "DBPort"),
  30. ini.ReadIniData("DBSetting", "SID"),
  31. ini.ReadIniData("DBSetting", "DBUser"),
  32. Encryption.DecryptDES(ini.ReadIniData("DBSetting", "DBPassword"), Constant.S_ENCRYPTION_KEY)
  33. );
  34. DataManager.ConnectionStringReport = DataManager.ConnectionString;
  35. try
  36. {
  37. string DBIP = ini.ReadIniData("DBSettingReport", "DBIP");
  38. if (!string.IsNullOrWhiteSpace(DBIP))
  39. {
  40. DataManager.ConnectionStringReport = string.Format(DataManager.ConnectionStringFormat,
  41. DBIP,
  42. ini.ReadIniData("DBSettingReport", "DBPort"),
  43. ini.ReadIniData("DBSettingReport", "SID"),
  44. ini.ReadIniData("DBSettingReport", "DBUser"),
  45. Encryption.DecryptDES(ini.ReadIniData("DBSettingReport", "DBPassword"), Constant.S_ENCRYPTION_KEY)
  46. );
  47. }
  48. }
  49. catch
  50. {
  51. }
  52. DataAccess.DefaultDataBaseType = Curtain.DataAccess.DataBaseType.Oracle;
  53. DataAccess.DefaultConnectionString = DataManager.ConnectionString;
  54. // SAP接口自动调用
  55. InitSAP_HEGII();
  56. }
  57. private void InitService()
  58. {
  59. // 此处处理需要进行映射的服务类
  60. /* ServiceRoute实体
  61. * 第一个参数为客户端调用终结点地址的名称
  62. * 第二个参数固定写法
  63. * 第三个参数为终结点调用对应的服务类
  64. */
  65. RouteTable.Routes.Add
  66. (
  67. new ServiceRoute
  68. (
  69. "DKService/PDAModuleService", new WebServiceHostFactory(), typeof(PDAModuleService)
  70. )
  71. );
  72. RouteTable.Routes.Add
  73. (
  74. new ServiceRoute
  75. (
  76. "DKService/DKIBOSSPRDService", new WebServiceHostFactory(), typeof(DKIBOSSPRDService)
  77. )
  78. );
  79. RouteTable.Routes.Add
  80. (
  81. new ServiceRoute
  82. (
  83. "DKService/CommonModuleService", new WebServiceHostFactory(), typeof(CommonModuleService)
  84. )
  85. );
  86. RouteTable.Routes.Add
  87. (
  88. new ServiceRoute
  89. (
  90. "DKService/SystemModuleService", new WebServiceHostFactory(), typeof(SystemModuleService)
  91. )
  92. );
  93. RouteTable.Routes.Add
  94. (
  95. new ServiceRoute
  96. (
  97. "DKService/HRModuleService", new WebServiceHostFactory(), typeof(HRModuleService)
  98. )
  99. );
  100. RouteTable.Routes.Add
  101. (
  102. new ServiceRoute
  103. (
  104. "DKService/PCModuleService", new WebServiceHostFactory(), typeof(PCModuleService)
  105. )
  106. );
  107. RouteTable.Routes.Add
  108. (
  109. new ServiceRoute
  110. (
  111. "DKService/PMModuleService", new WebServiceHostFactory(), typeof(PMModuleService)
  112. )
  113. );
  114. RouteTable.Routes.Add
  115. (
  116. new ServiceRoute
  117. (
  118. "DKService/TATModuleService", new WebServiceHostFactory(), typeof(TATModuleService)
  119. )
  120. );
  121. RouteTable.Routes.Add
  122. (
  123. new ServiceRoute
  124. (
  125. "DKService/ReportModuleService", new WebServiceHostFactory(), typeof(ReportModuleService)
  126. )
  127. );
  128. RouteTable.Routes.Add
  129. (
  130. new ServiceRoute
  131. (
  132. "DKService/WCFTestService", new WebServiceHostFactory(), typeof(WCFTestService)
  133. )
  134. );
  135. RouteTable.Routes.Add
  136. (
  137. new ServiceRoute
  138. (
  139. "DKService/CMNModuleService", new WebServiceHostFactory(), typeof(CMNModuleService)
  140. )
  141. );
  142. RouteTable.Routes.Add
  143. (
  144. new ServiceRoute
  145. (
  146. "DKService/PMModuleServiceNew", new WebServiceHostFactory(), typeof(PMModuleServiceNew)
  147. )
  148. );
  149. RouteTable.Routes.Add
  150. (
  151. new ServiceRoute
  152. (
  153. "DKService/PCModuleServiceNew", new WebServiceHostFactory(), typeof(PCModuleServiceNew)
  154. )
  155. );
  156. RouteTable.Routes.Add
  157. (
  158. new ServiceRoute
  159. (
  160. "DKService/PAMModuleService", new WebServiceHostFactory(), typeof(PAMModuleService)
  161. )
  162. );
  163. RouteTable.Routes.Add
  164. (
  165. new ServiceRoute
  166. (
  167. "DKService/PublicModuleService", new WebServiceHostFactory(), typeof(PublicModuleService)
  168. )
  169. );
  170. RouteTable.Routes.Add
  171. (
  172. new ServiceRoute
  173. (
  174. "DKService/SmartDeviceService", new WebServiceHostFactory(), typeof(SmartDeviceService)
  175. )
  176. );
  177. RouteTable.Routes.Add
  178. (
  179. new ServiceRoute
  180. (
  181. "DKService/ExHGS3QR", new WebServiceHostFactory(), typeof(ExHGS3QR)
  182. )
  183. );
  184. RouteTable.Routes.Add
  185. (
  186. new ServiceRoute
  187. (
  188. "DKService/SAPDataService", new WebServiceHostFactory(), typeof(SAPDataService)
  189. )
  190. );
  191. RouteTable.Routes.Add
  192. (
  193. new ServiceRoute
  194. (
  195. "DKService/PPModuleService", new WebServiceHostFactory(), typeof(PPModuleService)
  196. )
  197. );
  198. }
  199. #region SAP_HEGII
  200. private class TimerLocker
  201. {
  202. public string LockerName = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffffff");
  203. }
  204. private static Timer SAP_HEGII_Timer = null;
  205. private static TimerLocker Timer_Loker = null;
  206. private static bool Timer_doing = false;
  207. public static void InitSAP_HEGII()
  208. {
  209. try
  210. {
  211. INIUtility ini = INIUtility.Instance(INIUtility.IniFile.SAP_HEGII);
  212. // 下次开始时间
  213. string SAP_ING = ini.ReadIniData("SAP_HEGII", "SAP_ING");
  214. if (SAP_ING != "1")
  215. {
  216. OutputLog.TraceLog(LogPriority.Information,
  217. "Global",
  218. "Application_Start - InitSAP_HEGII",
  219. "Timer not Started",
  220. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  221. return;
  222. }
  223. //if (string.IsNullOrWhiteSpace(interval))
  224. //{
  225. // return;
  226. //}
  227. double intt = 60000;
  228. //if (!double.TryParse(interval, out intt) || intt < 30000)
  229. //{
  230. // intt = 60000;
  231. //}
  232. Timer_Loker = new TimerLocker();
  233. SAP_HEGII_Timer = new Timer();
  234. SAP_HEGII_Timer.Interval = intt;
  235. SAP_HEGII_Timer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
  236. SAP_HEGII_Timer.AutoReset = true;
  237. SAP_HEGII_Timer.Enabled = true;
  238. OutputLog.TraceLog(LogPriority.Information,
  239. "Global",
  240. "Application_Start - InitSAP_HEGII",
  241. "Timer Started : " + Timer_Loker.LockerName + " - " + intt,
  242. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  243. }
  244. catch (Exception ex)
  245. {
  246. OutputLog.TraceLog(LogPriority.Error,
  247. "Global",
  248. "InitSAP_HEGII",
  249. ex.ToString(),
  250. LocalPath.LogExePath + "SAP_HEGII\\Error_");
  251. }
  252. }
  253. private static void OnTimedEvent(object source, ElapsedEventArgs e)
  254. {
  255. if (Timer_doing)
  256. {
  257. return;
  258. }
  259. try
  260. {
  261. Timer_doing = true;
  262. lock (Timer_Loker)
  263. {
  264. // 当前时间
  265. IDBConnection oracleConn = ClsDbFactory.CreateDBConnection(Basics.DataAccess.DataBaseType.ORACLE, DataManager.ConnectionString);
  266. DateTime dateTimeNow = Convert.ToDateTime(oracleConn.GetSqlResultToObj("SELECT SYSDATE FROM DUAL"));
  267. oracleConn.Close();
  268. DateTime ndate;
  269. INIUtility ini = INIUtility.Instance(INIUtility.IniFile.SAP_HEGII);
  270. #region 报工_1001
  271. string nextDate_BG_1001 = ini.ReadIniData("SAP_HEGII", "NextDate_BG_1001");
  272. string strInterval_BG_1001 = ini.ReadIniData("SAP_HEGII", "Interval_BG_1001");
  273. if (!string.IsNullOrWhiteSpace(nextDate_BG_1001) && !string.IsNullOrWhiteSpace(strInterval_BG_1001) &&
  274. DateTime.TryParseExact(nextDate_BG_1001, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate) && ndate <= dateTimeNow)
  275. {
  276. // 间隔时间(分钟)
  277. int interva_BG_1001 = strInterval_BG_1001.ToInt32();
  278. DateTime nextDateINI_BG_1001 = ndate.AddMinutes(interva_BG_1001);
  279. while (nextDateINI_BG_1001 <= dateTimeNow)
  280. {
  281. nextDateINI_BG_1001 = nextDateINI_BG_1001.AddMinutes(interva_BG_1001);
  282. }
  283. // 更新下次执行时间
  284. ini.WriteIniData("SAP_HEGII", "NextDate_BG_1001", nextDateINI_BG_1001.ToString("yyyy-MM-dd HH:mm"));
  285. OutputLog.TraceLog(LogPriority.Information,
  286. "Global2",
  287. "OnTimedEvent begin: ",
  288. "SyncSap5000 报工_1001 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  289. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  290. + $" -[{interva_BG_1001}]" + nextDateINI_BG_1001.ToString("yyyy-MM-dd HH:mm:ss"),
  291. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  292. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP5000("1001", ndate);
  293. OutputLog.TraceLog(LogPriority.Information,
  294. "Global2",
  295. "OnTimedEvent end",
  296. "SyncSap5000 报工_1001 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  297. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  298. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  299. }
  300. #endregion
  301. #region 报工_10,20,30,40
  302. string nextDate_BG = ini.ReadIniData("SAP_HEGII", "NextDate_BG");
  303. string strInterval_BG = ini.ReadIniData("SAP_HEGII", "Interval_BG");
  304. if (!string.IsNullOrWhiteSpace(nextDate_BG) && !string.IsNullOrWhiteSpace(strInterval_BG) &&
  305. DateTime.TryParseExact(nextDate_BG, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate) && ndate <= dateTimeNow)
  306. {
  307. // 间隔时间(分钟)
  308. int interva_BG = strInterval_BG.ToInt32();
  309. DateTime nextDateINI_BG = ndate.AddMinutes(interva_BG);
  310. while (nextDateINI_BG <= dateTimeNow)
  311. {
  312. nextDateINI_BG = nextDateINI_BG.AddMinutes(interva_BG);
  313. }
  314. // 更新下次执行时间
  315. ini.WriteIniData("SAP_HEGII", "NextDate_BG", nextDateINI_BG.ToString("yyyy-MM-dd HH:mm"));
  316. OutputLog.TraceLog(LogPriority.Information,
  317. "Global2",
  318. "OnTimedEvent begin: ",
  319. "SyncSap5000 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  320. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  321. + $" -[{interva_BG}]" + nextDateINI_BG.ToString("yyyy-MM-dd HH:mm:ss"),
  322. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  323. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP5000("10,20,30,40", ndate);
  324. OutputLog.TraceLog(LogPriority.Information,
  325. "Global2",
  326. "OnTimedEvent end",
  327. "SyncSap5000 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  328. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  329. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  330. }
  331. #endregion
  332. #region 报工_50
  333. string nextDate_BG_50 = ini.ReadIniData("SAP_HEGII", "NextDate_BG_50");
  334. string strInterval_BG_50 = ini.ReadIniData("SAP_HEGII", "Interval_BG_50");
  335. if (!string.IsNullOrWhiteSpace(nextDate_BG_50) && !string.IsNullOrWhiteSpace(strInterval_BG_50) &&
  336. DateTime.TryParseExact(nextDate_BG_50, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate) && ndate <= dateTimeNow)
  337. {
  338. // 间隔时间(分钟)
  339. int interva_BG_50 = strInterval_BG_50.ToInt32();
  340. DateTime nextDateINI_BG_50 = ndate.AddMinutes(interva_BG_50);
  341. while (nextDateINI_BG_50 <= dateTimeNow)
  342. {
  343. nextDateINI_BG_50 = nextDateINI_BG_50.AddMinutes(interva_BG_50);
  344. }
  345. // 更新下次执行时间
  346. ini.WriteIniData("SAP_HEGII", "NextDate_BG_50", nextDateINI_BG_50.ToString("yyyy-MM-dd HH:mm"));
  347. OutputLog.TraceLog(LogPriority.Information,
  348. "Global2",
  349. "OnTimedEvent begin: ",
  350. "SyncSap5000 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  351. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  352. + $" -[{interva_BG_50}]" + nextDateINI_BG_50.ToString("yyyy-MM-dd HH:mm:ss"),
  353. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  354. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP5000("50", ndate);
  355. OutputLog.TraceLog(LogPriority.Information,
  356. "Global2",
  357. "OnTimedEvent end",
  358. "SyncSap5000 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  359. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  360. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  361. }
  362. #endregion
  363. #region 报工_60,55
  364. string nextDate_BG_60 = ini.ReadIniData("SAP_HEGII", "NextDate_BG_60");
  365. string strInterval_BG_60 = ini.ReadIniData("SAP_HEGII", "Interval_BG_60");
  366. if (!string.IsNullOrWhiteSpace(nextDate_BG_60) && !string.IsNullOrWhiteSpace(strInterval_BG_60) &&
  367. DateTime.TryParseExact(nextDate_BG_60, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate) && ndate <= dateTimeNow)
  368. {
  369. // 间隔时间(分钟)
  370. int interva_BG_60 = strInterval_BG_60.ToInt32();
  371. DateTime nextDateINI_BG_60 = ndate.AddMinutes(interva_BG_60);
  372. while (nextDateINI_BG_60 <= dateTimeNow)
  373. {
  374. nextDateINI_BG_60 = nextDateINI_BG_60.AddMinutes(interva_BG_60);
  375. }
  376. // 更新下次执行时间
  377. ini.WriteIniData("SAP_HEGII", "NextDate_BG_60", nextDateINI_BG_60.ToString("yyyy-MM-dd HH:mm"));
  378. OutputLog.TraceLog(LogPriority.Information,
  379. "Global2",
  380. "OnTimedEvent begin: ",
  381. "SyncSap5000 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  382. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  383. + $" -[{interva_BG_60}]" + nextDateINI_BG_60.ToString("yyyy-MM-dd HH:mm:ss"),
  384. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  385. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP5000("55,60", ndate);
  386. OutputLog.TraceLog(LogPriority.Information,
  387. "Global2",
  388. "OnTimedEvent end",
  389. "SyncSap5000 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  390. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  391. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  392. }
  393. #endregion
  394. #region 移库
  395. string nextDate_YK = ini.ReadIniData("SAP_HEGII", "NextDate_YK");
  396. string strInterval_YK = ini.ReadIniData("SAP_HEGII", "Interval_YK");
  397. if (!string.IsNullOrWhiteSpace(nextDate_YK) && !string.IsNullOrWhiteSpace(strInterval_YK) &&
  398. DateTime.TryParseExact(nextDate_YK, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate) && ndate <= dateTimeNow)
  399. {
  400. // 间隔时间(分钟)
  401. int interva_YK = strInterval_YK.ToInt32();
  402. DateTime nextDateINI_YK = ndate.AddMinutes(interva_YK);
  403. while (nextDateINI_YK <= dateTimeNow)
  404. {
  405. nextDateINI_YK = nextDateINI_YK.AddMinutes(interva_YK);
  406. }
  407. // 更新下次执行时间
  408. ini.WriteIniData("SAP_HEGII", "NextDate_YK", nextDateINI_YK.ToString("yyyy-MM-dd HH:mm"));
  409. OutputLog.TraceLog(LogPriority.Information,
  410. "Global2",
  411. "OnTimedEvent begin: ",
  412. "BGYKToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  413. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  414. + $" -[{interva_YK}]" + nextDateINI_YK.ToString("yyyy-MM-dd HH:mm:ss"),
  415. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  416. Service.SAPHegiiDataService.SAPDataLogic.BGYKToSAP(ndate, ndate);
  417. OutputLog.TraceLog(LogPriority.Information,
  418. "Global2",
  419. "OnTimedEvent end",
  420. "BGYKToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  421. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  422. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  423. }
  424. #endregion
  425. #region 跨车间作业
  426. string nextDate_KCJ = ini.ReadIniData("SAP_HEGII", "NextDate_KCJ");
  427. //string strInterval_KCJ = ini.ReadIniData("SAP_HEGII", "Interval_KCJ");
  428. if (!string.IsNullOrWhiteSpace(nextDate_KCJ) &&
  429. DateTime.TryParseExact(nextDate_KCJ, "yyyy-MM-dd", null, DateTimeStyles.None, out ndate) && ndate <= dateTimeNow)
  430. {
  431. // 间隔时间(分钟)
  432. //int interva_KCJ = strInterval_KCJ.ToInt32();
  433. DateTime nextDateINI_KCJ = ndate.AddMonths(1);
  434. while (nextDateINI_KCJ <= dateTimeNow)
  435. {
  436. nextDateINI_KCJ = nextDateINI_KCJ.AddMonths(1);
  437. }
  438. // 更新下次执行时间
  439. ini.WriteIniData("SAP_HEGII", "NextDate_KCJ", nextDateINI_KCJ.ToString("yyyy-MM-dd"));
  440. OutputLog.TraceLog(LogPriority.Information,
  441. "Global2",
  442. "OnTimedEvent begin: ",
  443. "CrossWorkshopToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  444. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  445. + $" -[{1}]" + nextDateINI_KCJ.ToString("yyyy-MM-dd HH:mm:ss"),
  446. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  447. Service.SAPHegiiDataService.SAPDataLogic.CrossWorkshopToSAP(ndate, ndate);
  448. OutputLog.TraceLog(LogPriority.Information,
  449. "Global2",
  450. "OnTimedEvent end",
  451. "CrossWorkshopToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  452. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  453. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  454. }
  455. #endregion
  456. #region 商标变更
  457. string nextDate_SBBG = ini.ReadIniData("SAP_HEGII", "NextDate_SBBG");
  458. string strInterval_SBBG = ini.ReadIniData("SAP_HEGII", "Interval_SBBG");
  459. if (!string.IsNullOrWhiteSpace(nextDate_SBBG) && !string.IsNullOrWhiteSpace(strInterval_SBBG) &&
  460. DateTime.TryParseExact(nextDate_SBBG, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate) && ndate <= dateTimeNow)
  461. {
  462. // 间隔时间(分钟)
  463. int interva_SBBG = strInterval_SBBG.ToInt32();
  464. DateTime nextDateINI_SBBG = ndate.AddMinutes(interva_SBBG);
  465. while (nextDateINI_SBBG <= dateTimeNow)
  466. {
  467. nextDateINI_SBBG = nextDateINI_SBBG.AddMinutes(interva_SBBG);
  468. }
  469. // 更新下次执行时间
  470. ini.WriteIniData("SAP_HEGII", "nextDate_SBBG", nextDateINI_SBBG.ToString("yyyy-MM-dd HH:mm"));
  471. OutputLog.TraceLog(LogPriority.Information,
  472. "Global2",
  473. "OnTimedEvent begin: ",
  474. "SyncSap5000 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  475. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  476. + $" -[{interva_SBBG}]" + nextDateINI_SBBG.ToString("yyyy-MM-dd HH:mm:ss"),
  477. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  478. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP5000SBBG( ndate);
  479. OutputLog.TraceLog(LogPriority.Information,
  480. "Global2",
  481. "OnTimedEvent end",
  482. "SyncSap5000 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  483. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  484. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  485. }
  486. #endregion
  487. #region 商标变更插入同步表
  488. string nextDate_SBBG_I = ini.ReadIniData("SAP_HEGII", "NextDate_SBBG_I");
  489. string strInterval_SBBG_I = ini.ReadIniData("SAP_HEGII", "Interval_SBBG_I");
  490. if (!string.IsNullOrWhiteSpace(nextDate_SBBG_I) && !string.IsNullOrWhiteSpace(strInterval_SBBG_I) &&
  491. DateTime.TryParseExact(nextDate_SBBG_I, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate) && ndate <= dateTimeNow)
  492. {
  493. // 间隔时间(分钟)
  494. int interva_SBBG_I = strInterval_SBBG_I.ToInt32();
  495. DateTime nextDateINI_SBBG_I = ndate.AddMinutes(interva_SBBG_I);
  496. while (nextDateINI_SBBG_I <= dateTimeNow)
  497. {
  498. nextDateINI_SBBG_I = nextDateINI_SBBG_I.AddMinutes(interva_SBBG_I);
  499. }
  500. // 更新下次执行时间
  501. ini.WriteIniData("SAP_HEGII", "nextDate_SBBG_I", nextDateINI_SBBG_I.ToString("yyyy-MM-dd HH:mm"));
  502. OutputLog.TraceLog(LogPriority.Information,
  503. "Global2",
  504. "OnTimedEvent begin: ",
  505. "SyncSap5000 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  506. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  507. + $" -[{interva_SBBG_I}]" + nextDateINI_SBBG_I.ToString("yyyy-MM-dd HH:mm:ss"),
  508. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  509. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP5000SBBGInsert(ndate);
  510. OutputLog.TraceLog(LogPriority.Information,
  511. "Global2",
  512. "OnTimedEvent end",
  513. "SyncSap5000 : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  514. + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  515. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  516. }
  517. #endregion
  518. //2022年9月23日13:06:25 添加时间限制,10月1号零点10分不再传输原接口产量数据
  519. //DateTime setTime = new DateTime(2022, 10, 1, 0, 10, 0);
  520. // 下次开始时间
  521. //string nextDate = ini.ReadIniData("SAP_HEGII", "NextDate");
  522. //string strInterval = ini.ReadIniData("SAP_HEGII", "Interval");
  523. #region 原报工(注销)
  524. //if (dateTimeNow < setTime
  525. // && !string.IsNullOrWhiteSpace(nextDate) && !string.IsNullOrWhiteSpace(strInterval))
  526. //{
  527. // ndate = DateTime.ParseExact(nextDate, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture);
  528. // DateTime.TryParseExact(nextDate, "yyyy-MM-dd HH:mm", CultureInfo.InvariantCulture, DateTimeStyles.None, out ndate);
  529. // if (ndate != null && ndate <= dateTimeNow)
  530. // {
  531. // // 间隔时间(分钟)
  532. // int interval = strInterval.ToInt32();
  533. // DateTime nextDateINI = ndate.AddMinutes(interval);
  534. // while (nextDateINI <= dateTimeNow)
  535. // {
  536. // nextDateINI = nextDateINI.AddMinutes(interval);
  537. // }
  538. // // 更新下次执行时间
  539. // ini.WriteIniData("SAP_HEGII", "NextDate", nextDateINI.ToString("yyyy-MM-dd HH:mm"));
  540. // string funCode = ini.ReadIniData("SAP_HEGII", "FunCode");
  541. // OutputLog.TraceLog(LogPriority.Information,
  542. // "Global2",
  543. // "OnTimedEvent begin: " + funCode,
  544. // "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  545. // + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  546. // + $" -[{interval}]" + nextDateINI.ToString("yyyy-MM-dd HH:mm:ss"),
  547. // LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  548. // Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(ndate, funCode, ndate);
  549. // OutputLog.TraceLog(LogPriority.Information,
  550. // "Global2",
  551. // "OnTimedEvent end",
  552. // "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  553. // + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  554. // LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  555. // }
  556. //}
  557. #endregion
  558. #region 50(注销)
  559. //string nextDate50 = ini.ReadIniData("SAP_HEGII", "NextDate50");
  560. //string strInterval50 = ini.ReadIniData("SAP_HEGII", "Interval50");
  561. ////2022年9月23日13:06:25 添加时间限制,10月1号零点10分不再传输原接口产量数据
  562. //if (dateTimeNow < setTime &&
  563. // !string.IsNullOrWhiteSpace(nextDate50) && !string.IsNullOrWhiteSpace(strInterval50) &&
  564. // DateTime.TryParseExact(nextDate50, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate) &&
  565. //ndate <= dateTimeNow)
  566. //{
  567. // // 间隔时间(分钟)
  568. // int interval50 = strInterval50.ToInt32();
  569. // DateTime nextDateINI50 = ndate.AddMinutes(interval50);
  570. // while (nextDateINI50 <= dateTimeNow)
  571. // {
  572. // nextDateINI50 = nextDateINI50.AddMinutes(interval50);
  573. // }
  574. // // 更新下次执行时间
  575. // ini.WriteIniData("SAP_HEGII", "NextDate50", nextDateINI50.ToString("yyyy-MM-dd HH:mm"));
  576. // string funCode = "50";
  577. // OutputLog.TraceLog(LogPriority.Information,
  578. // "Global2",
  579. // "OnTimedEvent begin: " + funCode,
  580. // "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  581. // + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + $" -date:" + ndate.ToString("yyyy-MM-dd HH:mm:ss")
  582. // + $" -[{interval50}]" + nextDateINI50.ToString("yyyy-MM-dd HH:mm:ss"),
  583. // LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  584. // Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(ndate, funCode, ndate);
  585. // OutputLog.TraceLog(LogPriority.Information,
  586. // "Global2",
  587. // "OnTimedEvent end",
  588. // "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  589. // + " - " + dateTimeNow.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  590. // LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  591. //}
  592. #endregion
  593. #region 6002(注销)
  594. /*
  595. string nextDate6002 = ini.ReadIniData("SAP_HEGII", "NextDate6002");
  596. if (!string.IsNullOrWhiteSpace(nextDate6002))
  597. {
  598. if (DateTime.TryParseExact(nextDate6002, "yyyy-MM-dd HH:mm", null, DateTimeStyles.None, out ndate))
  599. {
  600. //DateTime date = e.SignalTime; //DateTime.Now;
  601. DateTime date = DateTime.Now;
  602. if (ndate <= date)
  603. {
  604. //ini.WriteIniData("SAP_HEGII", "NextDate6002", date.AddHours(1).ToString("yyyy-MM-dd HH:")+ ndate.ToString("mm"));
  605. ini.WriteIniData("SAP_HEGII", "NextDate6002", date.AddMinutes(20).ToString("yyyy-MM-dd HH:mm"));
  606. string funCode = "6002"; // ini.ReadIniData("SAP_HEGII", "FunCode");
  607. OutputLog.TraceLog(LogPriority.Information,
  608. "Global",
  609. "OnTimedEvent begin: " + funCode,
  610. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  611. + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  612. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  613. Service.SAPHegiiDataService.SAPDataLogic.AutoWorkDataToSAP(date, funCode);
  614. OutputLog.TraceLog(LogPriority.Information,
  615. "Global",
  616. "OnTimedEvent end",
  617. "AutoWorkDataToSAP : " + Timer_Loker.LockerName + " - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss")
  618. + " - " + date.ToString("yyyy-MM-dd HH:mm:ss") + " - " + ndate.ToString("yyyy-MM-dd HH:mm:ss"),
  619. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  620. }
  621. }
  622. }
  623. */
  624. #endregion
  625. }
  626. }
  627. catch (Exception ex)
  628. {
  629. OutputLog.TraceLog(LogPriority.Error,
  630. "Global",
  631. "OnTimedEvent - " + e.SignalTime.ToString("yyyy-MM-dd HH:mm:ss"),
  632. ex.ToString(),
  633. LocalPath.LogExePath + "SAP_HEGII\\Error_");
  634. }
  635. finally
  636. {
  637. Timer_doing = false;
  638. }
  639. }
  640. #endregion
  641. protected void Session_Start(object sender, EventArgs e)
  642. {
  643. }
  644. protected void Application_BeginRequest(object sender, EventArgs e)
  645. {
  646. }
  647. protected void Application_AuthenticateRequest(object sender, EventArgs e)
  648. {
  649. }
  650. protected void Application_Error(object sender, EventArgs e)
  651. {
  652. //try
  653. //{
  654. // Logger.Error(
  655. //}
  656. //catch
  657. //{
  658. //}
  659. }
  660. protected void Session_End(object sender, EventArgs e)
  661. {
  662. }
  663. protected void Application_End(object sender, EventArgs e)
  664. {
  665. try
  666. {
  667. SAP_HEGII_Timer?.Dispose();
  668. SAP_HEGII_Timer = null;
  669. string lockerName = Timer_Loker?.LockerName;
  670. Timer_Loker = null;
  671. if (!string.IsNullOrEmpty(lockerName))
  672. {
  673. OutputLog.TraceLog(LogPriority.Information,
  674. "Global",
  675. "Application_End",
  676. "Timer End : " + lockerName,
  677. LocalPath.LogExePath + "SAP_HEGII\\Timer_");
  678. }
  679. }
  680. catch (Exception)
  681. {
  682. }
  683. Rework();
  684. }
  685. /// <summary>
  686. /// 唤醒当前应用
  687. /// </summary>
  688. public static void Rework()
  689. {
  690. //iis会回收这个定时任务,这边在回收的时候触发一个请求,5秒后来再次唤醒该服务
  691. System.Threading.Thread.Sleep(5000);
  692. try
  693. {
  694. WebRequest myWebRequest = WebRequest.Create("http://localhost:5679/");
  695. WebResponse myWebResponse = myWebRequest.GetResponse();
  696. myWebResponse.GetResponseStream();
  697. myWebResponse.Close();
  698. }
  699. catch (Exception)
  700. {
  701. }
  702. }
  703. }
  704. }