JobMoveHistoryRecorder.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using Aitex.Core.RT.DBCore;
  5. using Aitex.Core.RT.Log;
  6. using Aitex.Sorter.Common;
  7. using MECF.Framework.Common.CommonData;
  8. using SciChart.Core.Extensions;
  9. namespace MECF.Framework.Common.DBCore
  10. {
  11. /*
  12. *
  13. guid text NOT NULL,
  14. wafer_data_guid text,
  15. arrive_time timestamp without time zone,
  16. station timestamp without time zone,
  17. slot text,
  18. status text,
  19. CONSTRAINT wafer_move_history_pkey PRIMARY KEY (guid)
  20. *
  21. *
  22. *
  23. *
  24. */
  25. public class JobMoveHistoryRecorder
  26. {
  27. public static void JobArrived(string jobGuid, string stationName)
  28. {
  29. string sql = string.Format("INSERT INTO \"job_move_history\"(\"job_guid\", \"arrive_time\", \"station\")VALUES ('{0}', '{1}', '{2}');",
  30. jobGuid,
  31. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  32. stationName);
  33. DB.Insert(sql);
  34. }
  35. public static void JobLeft(string jobGuid, string stationName)
  36. {
  37. string sql = string.Format(
  38. "UPDATE \"job_move_history\" SET \"leave_time\"='{1}' WHERE \"job_guid\"='{0}' AND \"station\"='{2}' AND \"leave_time\" is null ;",
  39. jobGuid,
  40. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  41. stationName);
  42. DB.Insert(sql);
  43. }
  44. public static List<HistoryJobMoveData> QueryJobMovement(string jobGuid)
  45. {
  46. List<HistoryJobMoveData> result = new List<HistoryJobMoveData>();
  47. try
  48. {
  49. if (jobGuid.IsNullOrEmpty())
  50. return result;
  51. string sql = string.Format(
  52. "SELECT * FROM \"job_move_history\" WHERE \"job_guid\"='{0}';",
  53. jobGuid);
  54. DataSet ds = DB.ExecuteDataset(sql);
  55. if (ds == null)
  56. return result;
  57. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  58. {
  59. HistoryJobMoveData ev = new HistoryJobMoveData();
  60. ev.JobGuid = ds.Tables[0].Rows[i]["job_guid"].ToString();
  61. ev.Station = ds.Tables[0].Rows[i]["station"].ToString();
  62. if (!ds.Tables[0].Rows[i]["arrive_time"].Equals(DBNull.Value))
  63. ev.ArriveTime = ((DateTime)ds.Tables[0].Rows[i]["arrive_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  64. if (!ds.Tables[0].Rows[i]["leave_time"].Equals(DBNull.Value))
  65. ev.LeaveTime = ((DateTime)ds.Tables[0].Rows[i]["leave_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  66. result.Add(ev);
  67. }
  68. }
  69. catch (Exception ex)
  70. {
  71. LOG.WriteExeption(ex);
  72. }
  73. return result;
  74. }
  75. public static List<HistoryJobMoveData> QueryJobMovement(string jobGuid, string stationName)
  76. {
  77. List<HistoryJobMoveData> result = new List<HistoryJobMoveData>();
  78. try
  79. {
  80. string sql = string.Format(
  81. "SELECT * FROM \"job_move_history\" WHERE \"job_guid\"='{0}' AND \"station\"='{1}' ;",
  82. jobGuid,
  83. stationName);
  84. DataSet ds = DB.ExecuteDataset(sql);
  85. if (ds == null)
  86. return result;
  87. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  88. {
  89. HistoryJobMoveData ev = new HistoryJobMoveData();
  90. ev.JobGuid = ds.Tables[0].Rows[i]["job_guid"].ToString();
  91. ev.Station = ds.Tables[0].Rows[i]["station"].ToString();
  92. if (!ds.Tables[0].Rows[i]["arrive_time"].Equals(DBNull.Value))
  93. ev.ArriveTime =
  94. ((DateTime)ds.Tables[0].Rows[i]["arrive_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  95. if (!ds.Tables[0].Rows[i]["leave_time"].Equals(DBNull.Value))
  96. ev.LeaveTime =
  97. ((DateTime)ds.Tables[0].Rows[i]["leave_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  98. result.Add(ev);
  99. }
  100. }
  101. catch (Exception ex)
  102. {
  103. LOG.WriteExeption(ex);
  104. }
  105. return result;
  106. }
  107. public static List<HistoryJobMoveData> QueryJobMovementBysql(string sql)
  108. {
  109. List<HistoryJobMoveData> result = new List<HistoryJobMoveData>();
  110. try
  111. {
  112. DataSet ds = DB.ExecuteDataset(sql);
  113. if (ds == null)
  114. return result;
  115. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  116. {
  117. HistoryJobMoveData ev = new HistoryJobMoveData();
  118. ev.JobGuid = ds.Tables[0].Rows[i]["job_guid"].ToString();
  119. ev.Station = ds.Tables[0].Rows[i]["station"].ToString();
  120. if (!ds.Tables[0].Rows[i]["arrive_time"].Equals(DBNull.Value))
  121. ev.ArriveTime =
  122. ((DateTime)ds.Tables[0].Rows[i]["arrive_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  123. if (!ds.Tables[0].Rows[i]["leave_time"].Equals(DBNull.Value))
  124. ev.LeaveTime =
  125. ((DateTime)ds.Tables[0].Rows[i]["leave_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  126. result.Add(ev);
  127. }
  128. }
  129. catch (Exception ex)
  130. {
  131. LOG.WriteExeption(ex);
  132. }
  133. return result;
  134. }
  135. }
  136. }