ProcessDataRecorder.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  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.Core.UI.ControlDataContext;
  7. using Aitex.Sorter.Common;
  8. using MECF.Framework.Common.CommonData;
  9. using MECF.Framework.Common.Equipment;
  10. namespace MECF.Framework.Common.DBCore
  11. {
  12. public class ProcessDataRecorder
  13. {
  14. public static void Start(string guid, string recipeName )
  15. {
  16. string sql = string.Format(
  17. "INSERT INTO \"process_data\"(\"guid\", \"process_begin_time\", \"recipe_name\" )VALUES ('{0}', '{1}', '{2}' );",
  18. guid,
  19. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  20. recipeName );
  21. DB.Insert(sql);
  22. }
  23. public static void Start(string guid, string recipeName, string waferDataGuid, string processIn)
  24. {
  25. string sql = string.Format(
  26. "INSERT INTO \"process_data\"(\"guid\", \"process_begin_time\", \"recipe_name\" , \"wafer_data_guid\", \"process_in\" )VALUES ('{0}', '{1}', '{2}', '{3}', '{4}' );",
  27. guid,
  28. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  29. recipeName,
  30. waferDataGuid,
  31. processIn);
  32. DB.Insert(sql);
  33. }
  34. public static void Start(string guid, string recipeName, string waferDataGuid, string processIn,string lotID,string slotID)
  35. {
  36. string sql = string.Format(
  37. "INSERT INTO \"process_data\"(\"guid\", \"process_begin_time\", \"recipe_name\" , \"wafer_data_guid\", \"process_in\", \"lot_id\", \"slot_id\" )VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}' );",
  38. guid,
  39. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  40. recipeName,
  41. waferDataGuid,
  42. processIn,
  43. lotID,
  44. string.IsNullOrEmpty(slotID) ? "" : (int.Parse(slotID) + 1).ToString());
  45. DB.Insert(sql);
  46. }
  47. public static void UpdateStatus(string guid, string status)
  48. {
  49. string sql = string.Format(
  50. "UPDATE \"process_data\" SET \"process_status\"='{0}' WHERE \"guid\"='{1}';",
  51. status,
  52. guid);
  53. DB.Insert(sql);
  54. }
  55. public static void UpdateRecipeSettingTime(string guid, float time)
  56. {
  57. string sql = string.Format(
  58. "UPDATE \"process_data\" SET \"recipe_setting_time\"='{0}' WHERE \"guid\"='{1}';",
  59. time,
  60. guid);
  61. DB.Insert(sql);
  62. }
  63. public static void UpdateStatus(string guid, string status, string chamber)
  64. {
  65. string sql = string.Format(
  66. "UPDATE \"process_data\" SET \"process_status\"='{0}' WHERE \"guid\"='{1}' and \"process_in\"='{2}';",
  67. status, guid, chamber);
  68. DB.Insert(sql);
  69. }
  70. public static void End(string guid, string status)
  71. {
  72. string sql = string.Format(
  73. "UPDATE \"process_data\" SET \"process_end_time\"='{0}',\"process_status\"='{1}' WHERE \"guid\"='{2}';",
  74. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  75. status,
  76. guid);
  77. DB.Insert(sql);
  78. }
  79. public static void End(string guid, string status, string chamber)
  80. {
  81. string sql = string.Format(
  82. "UPDATE \"process_data\" SET \"process_end_time\"='{0}',\"process_status\"='{1}' WHERE \"guid\"='{2}' and \"process_in\"='{3}';",
  83. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"), status, guid, chamber);
  84. DB.Insert(sql);
  85. }
  86. public static void End(string guid)
  87. {
  88. string sql = string.Format(
  89. "UPDATE \"process_data\" SET \"process_end_time\"='{0}' WHERE \"guid\"='{1}';",
  90. DateTime.Now.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  91. guid);
  92. DB.Insert(sql);
  93. }
  94. public static void StepStart(string recipeGuid, int stepNumber, string stepName, float stepTime)
  95. {
  96. string guid = Guid.NewGuid().ToString();
  97. string sql = $"INSERT INTO \"recipe_step_data\"(\"guid\", \"step_begin_time\", \"step_name\" , \"step_time\", \"process_data_guid\", \"step_number\")VALUES ('{guid}', '{DateTime.Now:yyyy/MM/dd HH:mm:ss.fff}', '{stepName}', '{stepTime}', '{recipeGuid}', '{stepNumber}' );";
  98. //System.Diagnostics.Trace.WriteLine(sql);
  99. DB.Insert(sql);
  100. }
  101. public static void StepEnd(string recipeGuid, int stepNumber, List<FdcDataItem> stepData = null)
  102. {
  103. string sql = $"UPDATE \"recipe_step_data\" SET \"step_end_time\"='{DateTime.Now:yyyy/MM/dd HH:mm:ss.fff}' WHERE \"process_data_guid\"='{recipeGuid}' and \"step_number\"='{stepNumber}';";
  104. DB.Insert(sql);
  105. if (stepData != null && stepData.Count > 0)
  106. {
  107. foreach (var item in stepData)
  108. {
  109. sql = $"INSERT INTO \"step_fdc_data\"(\"process_data_guid\", \"create_time\", \"step_number\" , \"parameter_name\", \"sample_count\", \"min_value\", \"max_value\", \"setpoint\", \"std_value\", \"mean_value\")VALUES ('{recipeGuid}', '{DateTime.Now:yyyy/MM/dd HH:mm:ss.fff}', '{stepNumber}', '{item.Name}', '{item.SampleCount}', '{item.MinValue}', '{item.MaxValue}', '{item.SetPoint}', '{item.StdValue}', '{item.MeanValue}' );";
  110. DB.Insert(sql);
  111. }
  112. }
  113. }
  114. public static void RecordPrecess(string guid, DateTime startTime, DateTime endTime, string recipeName,string status, string waferDataGuid, string processIn, string lotID, string slotID)
  115. {
  116. string sql = string.Format(
  117. "INSERT INTO \"process_data\"(\"guid\", \"process_begin_time\",\"process_end_time\", \"recipe_name\" ,\"process_status\", \"wafer_data_guid\", \"process_in\", \"lot_id\", \"slot_id\" )VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}','{7}' ,'{8}');",
  118. guid,
  119. startTime.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  120. endTime.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  121. recipeName,
  122. status,
  123. waferDataGuid,
  124. processIn,
  125. lotID,
  126. string.IsNullOrEmpty(slotID) ? "" : (int.Parse(slotID) + 1).ToString());
  127. DB.Insert(sql);
  128. }
  129. public List<string> GetHistoryRecipeList(DateTime begin, DateTime end)
  130. {
  131. List<string> result = new List<string>();
  132. string sql = string.Format("SELECT * FROM \"RecipeRunHistory\" where \"ProcessBeginTime\" >= '{0}' and \"ProcessBeginTime\" <= '{1}' order by \"ProcessBeginTime\" ASC;",
  133. begin.ToString("yyyy/MM/dd HH:mm:ss.fff"), end.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  134. DataSet ds = DB.ExecuteDataset(sql);
  135. if (ds == null)
  136. return result;
  137. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  138. {
  139. string recipe = ds.Tables[0].Rows[i]["RecipeName"].ToString();
  140. if (!result.Contains(recipe))
  141. result.Add(recipe);
  142. }
  143. ds.Clear();
  144. return result;
  145. }
  146. public static List<HistoryProcessData> QueryDBProcess(string sql)
  147. {
  148. List<HistoryProcessData> result = new List<HistoryProcessData>();
  149. try
  150. {
  151. DataSet ds = DB.ExecuteDataset(sql);
  152. if (ds == null)
  153. return result;
  154. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  155. {
  156. HistoryProcessData ev = new HistoryProcessData();
  157. ev.RecipeName = ds.Tables[0].Rows[i]["recipe_name"].ToString();
  158. ev.Result = ds.Tables[0].Rows[i]["process_status"].ToString();
  159. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  160. if (!ds.Tables[0].Rows[i]["process_begin_time"].Equals(DBNull.Value))
  161. ev.StartTime = ((DateTime)ds.Tables[0].Rows[i]["process_begin_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  162. if (!ds.Tables[0].Rows[i]["process_end_time"].Equals(DBNull.Value))
  163. ev.EndTime = ((DateTime)ds.Tables[0].Rows[i]["process_end_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  164. result.Add(ev);
  165. }
  166. }
  167. catch (Exception ex)
  168. {
  169. LOG.WriteExeption(ex);
  170. }
  171. return result;
  172. }
  173. public static List<HistoryDataItem> GetHistoryDataFromStartToEnd(IEnumerable<string> keys, DateTime begin, DateTime end, string module)
  174. {
  175. List<HistoryDataItem> result = new List<HistoryDataItem>();
  176. try
  177. {
  178. DateTime begintime = new DateTime(begin.Year, begin.Month, begin.Day, begin.Hour, begin.Minute, begin.Second, begin.Millisecond);
  179. DateTime endtime = new DateTime(begin.Year, begin.Month, end.Day, end.Hour, end.Minute, end.Second, end.Millisecond);
  180. string sql = "select time AS InternalTimeStamp";
  181. foreach (var dataId in keys)
  182. {
  183. sql += "," + string.Format("\"{0}\"", dataId);
  184. }
  185. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 86400;",
  186. begin.ToString("yyyyMMdd") + "." + module, begintime.Ticks, endtime.Ticks);
  187. DataSet dataSet = DB.ExecuteDataset(sql);
  188. if (dataSet == null)
  189. return result;
  190. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  191. return result;
  192. DateTime dt = new DateTime();
  193. Dictionary<int, string> colName = new Dictionary<int, string>();
  194. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  195. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  196. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  197. {
  198. var row = dataSet.Tables[0].Rows[rowNo];
  199. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  200. {
  201. HistoryDataItem data = new HistoryDataItem();
  202. if (i == 0)
  203. {
  204. long ticks = (long)row[i];
  205. dt = new DateTime(ticks);
  206. continue;
  207. }
  208. else
  209. {
  210. string dataId = colName[i];
  211. if (row[i] is DBNull || row[i] == null)
  212. {
  213. data.dateTime = dt;
  214. data.dbName = colName[i];
  215. data.value = 0;
  216. }
  217. else if (row[i] is bool)
  218. {
  219. data.dateTime = dt;
  220. data.dbName = colName[i];
  221. data.value = (bool)row[i] ? 1 : 0;
  222. }
  223. else
  224. {
  225. data.dateTime = dt;
  226. data.dbName = colName[i];
  227. data.value = float.Parse(row[i].ToString());
  228. }
  229. }
  230. result.Add(data);
  231. }
  232. }
  233. dataSet.Clear();
  234. }
  235. catch (Exception ex)
  236. {
  237. LOG.WriteExeption(ex);
  238. }
  239. return result;
  240. }
  241. public static List<HistoryDataItem> GetOneDayHistoryData(IEnumerable<string> keys, DateTime begin, string module)
  242. {
  243. List<HistoryDataItem> result = new List<HistoryDataItem>();
  244. try
  245. {
  246. DateTime begintime = new DateTime(begin.Year, begin.Month, begin.Day, 0, 0, 0, 0);
  247. DateTime endtime = new DateTime(begin.Year, begin.Month, begin.Day, 23, 59, 59, 999);
  248. string sql = "select time AS InternalTimeStamp";
  249. foreach (var dataId in keys)
  250. {
  251. sql += "," + string.Format("\"{0}\"", dataId);
  252. }
  253. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 86400;",
  254. begin.ToString("yyyyMMdd") + "." + module, begintime.Ticks, endtime.Ticks);
  255. DataSet dataSet = DB.ExecuteDataset(sql);
  256. if (dataSet == null)
  257. return result;
  258. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  259. return result;
  260. DateTime dt = new DateTime();
  261. Dictionary<int, string> colName = new Dictionary<int, string>();
  262. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  263. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  264. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  265. {
  266. var row = dataSet.Tables[0].Rows[rowNo];
  267. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  268. {
  269. HistoryDataItem data = new HistoryDataItem();
  270. if (i == 0)
  271. {
  272. long ticks = (long)row[i];
  273. dt = new DateTime(ticks);
  274. continue;
  275. }
  276. else
  277. {
  278. string dataId = colName[i];
  279. if (row[i] is DBNull || row[i] == null)
  280. {
  281. data.dateTime = dt;
  282. data.dbName = colName[i];
  283. data.value = 0;
  284. }
  285. else if (row[i] is bool)
  286. {
  287. data.dateTime = dt;
  288. data.dbName = colName[i];
  289. data.value = (bool)row[i] ? 1 : 0;
  290. }
  291. else
  292. {
  293. data.dateTime = dt;
  294. data.dbName = colName[i];
  295. data.value = float.Parse(row[i].ToString());
  296. }
  297. }
  298. result.Add(data);
  299. }
  300. }
  301. dataSet.Clear();
  302. }
  303. catch (Exception ex)
  304. {
  305. LOG.WriteExeption(ex);
  306. }
  307. return result;
  308. }
  309. public static List<HistoryDataItem> GetHistoryData(IEnumerable<string> keys, string recipeRunGuid, string module)
  310. {
  311. List<HistoryDataItem> result = new List<HistoryDataItem>();
  312. try
  313. {
  314. string sql = string.Format("SELECT * FROM \"process_data\" where \"guid\" = '{0}'",
  315. recipeRunGuid);
  316. DataSet ds = DB.ExecuteDataset(sql);
  317. if (ds == null)
  318. return result;
  319. if (ds.Tables[0].Rows.Count == 0)
  320. return result;
  321. object from = ds.Tables[0].Rows[0]["process_begin_time"];
  322. if (from is DBNull)
  323. {
  324. //LOG.Write(string.Format("{0} not set start time", recipeRunGuid));
  325. return result;
  326. }
  327. DateTime begin = (DateTime)from;
  328. begin = begin.AddSeconds(-10);
  329. object to = ds.Tables[0].Rows[0]["process_end_time"];
  330. if (to is DBNull)
  331. {
  332. to = new DateTime(begin.Year, begin.Month, begin.Day, 23, 59, 59, 999);
  333. }
  334. DateTime end = (DateTime)to;
  335. end = end.AddSeconds(10);
  336. sql = "select time AS InternalTimeStamp";
  337. foreach (var dataId in keys)
  338. {
  339. sql += "," + string.Format("\"{0}\"", dataId);
  340. }
  341. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 2000;",
  342. begin.ToString("yyyyMMdd") + "." + module, begin.Ticks, end.Ticks);
  343. DataSet dataSet = DB.ExecuteDataset(sql);
  344. if (dataSet == null)
  345. return result;
  346. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  347. return result;
  348. DateTime dt = new DateTime();
  349. Dictionary<int, string> colName = new Dictionary<int, string>();
  350. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  351. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  352. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  353. {
  354. var row = dataSet.Tables[0].Rows[rowNo];
  355. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  356. {
  357. HistoryDataItem data = new HistoryDataItem();
  358. if (i == 0)
  359. {
  360. long ticks = (long)row[i];
  361. dt = new DateTime(ticks);
  362. continue;
  363. }
  364. else
  365. {
  366. string dataId = colName[i];
  367. if (row[i] is DBNull || row[i] == null)
  368. {
  369. data.dateTime = dt;
  370. data.dbName = colName[i];
  371. data.value = 0;
  372. }
  373. else if (row[i] is bool)
  374. {
  375. data.dateTime = dt;
  376. data.dbName = colName[i];
  377. data.value = (bool)row[i] ? 1 : 0;
  378. }
  379. else
  380. {
  381. data.dateTime = dt;
  382. data.dbName = colName[i];
  383. data.value = float.Parse(row[i].ToString());
  384. }
  385. }
  386. result.Add(data);
  387. }
  388. }
  389. dataSet.Clear();
  390. }
  391. catch (Exception ex)
  392. {
  393. LOG.WriteExeption(ex);
  394. }
  395. return result;
  396. }
  397. }
  398. }