JobMoveHistoryRecorder.cs 4.7 KB

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