RecipeDataRecorder.cs 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using Aitex.Core.RT.DBCore;
  6. using Aitex.Core.RT.Log;
  7. using Aitex.Core.UI.ControlDataContext;
  8. using Aitex.Sorter.Common;
  9. using MECF.Framework.Common.Equipment;
  10. namespace MECF.Framework.Common.DBCore
  11. {
  12. public class RecipeDataRecorder
  13. {
  14. public static void RecipeStart(string guid, string waferDataGuid, string recipeName, string settingTime, string chamber)
  15. {
  16. string sql = string.Format(
  17. "INSERT INTO \"recipe_data\"(\"guid\", \"wafer_data_guid\", \"recipe_begin_time\", \"recipe_name\", \"recipe_setting_time\" , \"chamber\" )VALUES ('{0}', '{1}', '{2}' , '{3}', '{4}', '{5}' );",
  18. guid,
  19. waferDataGuid,
  20. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  21. recipeName,
  22. settingTime,
  23. chamber);
  24. DB.Insert(sql);
  25. }
  26. public static void RecipeEnd(string guid)
  27. {
  28. string sql = string.Format(
  29. "UPDATE \"recipe_data\" SET \"recipe_end_time\"='{0}' WHERE \"guid\"='{1}';",
  30. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  31. guid);
  32. DB.Insert(sql);
  33. }
  34. public static void RecipeStepStart(string guid, int recipeStepNo, string recipeStepName, string settingTime)
  35. {
  36. string sql = string.Format(
  37. "INSERT INTO \"recipe_step_data\"(\"guid\", \"recipe_step_no\", \"recipe_step_name\", \"recipe_step_setting_time\" , \"recipe_step_begin_time\")VALUES ('{0}', '{1}', '{2}' , '{3}', '{4}' );",
  38. guid,
  39. recipeStepNo,
  40. recipeStepName,
  41. settingTime,
  42. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  43. DB.Insert(sql);
  44. }
  45. public static void RecipeStepEnd(string guid, int recipeStepNo)
  46. {
  47. string sql = string.Format(
  48. "UPDATE \"recipe_step_data\" SET \"recipe_step_end_time\"='{0}' WHERE \"guid\"='{1}' AND \"recipe_step_no\"='{2}';",
  49. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  50. guid,
  51. recipeStepNo);
  52. DB.Insert(sql);
  53. }
  54. public static WaferHistoryRecipe GetWaferHistoryRecipe(string id)
  55. {
  56. WaferHistoryRecipe result = new WaferHistoryRecipe();
  57. try
  58. {
  59. string sql = string.Format("SELECT * FROM \"recipe_data\" where \"guid\" = '{0}' limit 1000;", id);
  60. DataSet dataSet = DB.ExecuteDataset(sql);
  61. if (dataSet == null)
  62. return result;
  63. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  64. return result;
  65. for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
  66. {
  67. result.ID = dataSet.Tables[0].Rows[i]["guid"].ToString();
  68. result.Type = WaferHistoryItemType.Recipe;
  69. result.Chamber = dataSet.Tables[0].Rows[i]["chamber"].ToString();
  70. result.SettingTime = dataSet.Tables[0].Rows[i]["recipe_setting_time"].ToString();
  71. if (!dataSet.Tables[0].Rows[i]["recipe_begin_time"].Equals(DBNull.Value))
  72. result.StartTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["recipe_begin_time"].ToString());
  73. if (!dataSet.Tables[0].Rows[i]["recipe_end_time"].Equals(DBNull.Value))
  74. result.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["recipe_end_time"].ToString());
  75. result.ActualTime = result.EndTime.CompareTo(result.StartTime) <= 0 ? "" : result.EndTime.Subtract(result.StartTime).ToString();
  76. result.Recipe = dataSet.Tables[0].Rows[i]["recipe_name"].ToString();
  77. result.Name = dataSet.Tables[0].Rows[i]["recipe_name"].ToString();
  78. result.Steps = GetRecipeStepInfoList(id);
  79. }
  80. }
  81. catch (Exception e)
  82. {
  83. LOG.Write(e);
  84. }
  85. return result;
  86. }
  87. public static List<WaferHistoryWafer> GetWaferHistoryWafers(string id)
  88. {
  89. List<WaferHistoryWafer> result = new List<WaferHistoryWafer>();
  90. try
  91. {
  92. string sql = string.Format("SELECT * FROM \"wafer_data\" where \"carrier_data_guid\" = '{0}' and \"lot_id\" <> '' order by \"wafer_id\" ASC limit 1000;", id);
  93. DataSet dataSet = DB.ExecuteDataset(sql);
  94. if (dataSet == null)
  95. return result;
  96. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  97. return result;
  98. for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
  99. {
  100. WaferHistoryWafer item = new WaferHistoryWafer();
  101. item.ID = dataSet.Tables[0].Rows[i]["guid"].ToString();
  102. item.Type = WaferHistoryItemType.Wafer;
  103. item.Name = dataSet.Tables[0].Rows[i]["wafer_id"].ToString();
  104. if (!dataSet.Tables[0].Rows[i]["sequence_name"].Equals(DBNull.Value))
  105. {
  106. item.ProcessJob = dataSet.Tables[0].Rows[i]["sequence_name"].ToString();
  107. }
  108. if (!dataSet.Tables[0].Rows[i]["create_time"].Equals(DBNull.Value))
  109. item.StartTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["create_time"].ToString());
  110. if (!dataSet.Tables[0].Rows[i]["delete_time"].Equals(DBNull.Value))
  111. item.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["delete_time"].ToString());
  112. result.Add(item);
  113. }
  114. }
  115. catch (Exception e)
  116. {
  117. LOG.Write(e);
  118. }
  119. return result;
  120. }
  121. private static List<RecipeStep> GetRecipeStepInfoList(string guid)
  122. {
  123. List<RecipeStep> result = new List<RecipeStep>();
  124. DataSet recipeStepDataSet = DB.ExecuteDataset(string.Format("SELECT * FROM \"recipe_step_data\" where \"guid\" = '{0}' limit 1000;", guid));
  125. if (recipeStepDataSet != null && recipeStepDataSet.Tables.Count != 0 && recipeStepDataSet.Tables[0].Rows.Count != 0)
  126. {
  127. for (int i = 0; i < recipeStepDataSet.Tables[0].Rows.Count; i++)
  128. {
  129. RecipeStep rs = new RecipeStep();
  130. rs.No = int.Parse(recipeStepDataSet.Tables[0].Rows[i]["recipe_step_no"].ToString());
  131. rs.Name = recipeStepDataSet.Tables[0].Rows[i]["recipe_step_name"].ToString();
  132. rs.SettingTime = recipeStepDataSet.Tables[0].Rows[i]["recipe_step_setting_time"].ToString();
  133. if (!recipeStepDataSet.Tables[0].Rows[i]["recipe_step_begin_time"].Equals(DBNull.Value))
  134. rs.StartTime = DateTime.Parse(recipeStepDataSet.Tables[0].Rows[i]["recipe_step_begin_time"].ToString());
  135. if (!recipeStepDataSet.Tables[0].Rows[i]["recipe_step_end_time"].Equals(DBNull.Value))
  136. rs.EndTime = DateTime.Parse(recipeStepDataSet.Tables[0].Rows[i]["recipe_step_end_time"].ToString());
  137. rs.ActualTime = rs.EndTime.CompareTo(rs.StartTime) <= 0 ? "" : rs.EndTime.Subtract(rs.StartTime).ToString();
  138. result.Add(rs);
  139. }
  140. }
  141. return result;
  142. }
  143. public static List<WaferHistoryRecipe> GetWaferHistoryRecipes(string id)
  144. {
  145. List<WaferHistoryRecipe> result = new List<WaferHistoryRecipe>();
  146. try
  147. {
  148. string sql = string.Format("SELECT * FROM \"process_data\" where \"wafer_data_guid\" = '{0}' limit 1000;", id);
  149. DataSet dataSet = DB.ExecuteDataset(sql);
  150. if (dataSet == null)
  151. return result;
  152. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  153. return result;
  154. for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
  155. {
  156. result.Add(GetWaferHistoryRecipe(dataSet.Tables[0].Rows[i]["guid"].ToString()));
  157. }
  158. }
  159. catch (Exception e)
  160. {
  161. LOG.Write(e);
  162. }
  163. return result;
  164. }
  165. public static List<WaferHistorySecquence> GetWaferHistorySecquences(string id)
  166. {
  167. List<WaferHistorySecquence> result = new List<WaferHistorySecquence>();
  168. try
  169. {
  170. string sql = string.Format("SELECT * FROM \"wafer_data\" where \"guid\" = '{0}' and \"lot_id\" <> '' order by \"wafer_id\" ASC limit 1000;", id);
  171. DataSet dataSet = DB.ExecuteDataset(sql);
  172. if (dataSet == null)
  173. return result;
  174. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  175. return result;
  176. int index = 0;
  177. try
  178. {
  179. sql = string.Format("SELECT * FROM \"wafer_move_history\" where \"wafer_data_guid\" = '{0}' order by \"arrive_time\" ASC limit 1000;", id);
  180. DataSet dataSeta = DB.ExecuteDataset(sql);
  181. if (dataSeta.Tables.Count == 0 || dataSeta.Tables[0].Rows.Count == 0)
  182. return result;
  183. for (int i = 0; i < dataSeta.Tables[0].Rows.Count; i++)
  184. {
  185. if (dataSeta.Tables[0].Rows[i]["station"].ToString() == "Cassette")
  186. {
  187. index = i + 1;
  188. break;
  189. }
  190. if (i == dataSeta.Tables[0].Rows.Count - 1)
  191. index = i + 1;
  192. }
  193. if (dataSeta.Tables[0].Rows.Count % index > 0)
  194. index = dataSeta.Tables[0].Rows.Count / index + 1;
  195. else
  196. index = dataSeta.Tables[0].Rows.Count / index;
  197. }
  198. catch (Exception e)
  199. {
  200. LOG.Write(e);
  201. }
  202. for (int i = 0; i < index; i++)
  203. {
  204. result.Add(GetWaferHistorySecquence(id, dataSet.Tables[0].Rows[0]["sequence_name"].ToString(),i));
  205. }
  206. }
  207. catch (Exception e)
  208. {
  209. LOG.Write(e);
  210. }
  211. return result;
  212. }
  213. public static WaferHistorySecquence GetWaferHistorySecquence(string id,string SecquenceName,int count)
  214. {
  215. WaferHistorySecquence result = new WaferHistorySecquence();
  216. try
  217. {
  218. string sql = string.Format("SELECT * FROM \"wafer_move_history\" where \"wafer_data_guid\" = '{0}' order by \"arrive_time\" ASC limit 1000;", id);
  219. DataSet dataSet = DB.ExecuteDataset(sql);
  220. if (dataSet == null)
  221. return result;
  222. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  223. return result;
  224. int index = 0;
  225. for (int i = 0; i < dataSet.Tables[0].Rows.Count; i++)
  226. {
  227. if (dataSet.Tables[0].Rows[i]["station"].ToString() == "Cassette")
  228. {
  229. index = i;
  230. break;
  231. }
  232. if (i == dataSet.Tables[0].Rows.Count - 1)
  233. index = i;
  234. }
  235. for (int i = 0; i < dataSet.Tables[0].Rows.Count;)
  236. {
  237. i = count > 0 ? index * count + count - 1: index * count + count;
  238. result.SecquenceName = SecquenceName;
  239. result.Recipe = SecquenceName;
  240. result.SecQuenceStartTime = dataSet.Tables[0].Rows[i]["arrive_time"].ToString();
  241. result.StartTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["arrive_time"].ToString());
  242. i = index * count + count;
  243. i += index;
  244. if (i >= dataSet.Tables[0].Rows.Count)
  245. {
  246. result.SecQuenceEndTime = dataSet.Tables[0].Rows[dataSet.Tables[0].Rows.Count - 1]["arrive_time"].ToString();
  247. result.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[dataSet.Tables[0].Rows.Count - 1]["arrive_time"].ToString());
  248. }
  249. else
  250. {
  251. result.SecQuenceEndTime = dataSet.Tables[0].Rows[i]["arrive_time"].ToString();
  252. result.EndTime = DateTime.Parse(dataSet.Tables[0].Rows[i]["arrive_time"].ToString());
  253. }
  254. result.ActualTime = result.EndTime.CompareTo(result.StartTime) <= 0 ? "" : result.EndTime.Subtract(result.StartTime).ToString();
  255. break;
  256. }
  257. }
  258. catch (Exception e)
  259. {
  260. LOG.Write(e);
  261. }
  262. return result;
  263. }
  264. }
  265. }