ProcessDataRecorder.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475
  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 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\" , \"wafer_data_guid\", \"process_in\", \"lot_id\", \"slot_id\" )VALUES ('{0}', '{1}', '{2}', '{3}', '{4}', '{5}', '{6}','{7}' );",
  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. waferDataGuid,
  123. processIn,
  124. lotID,
  125. string.IsNullOrEmpty(slotID) ? "" : (int.Parse(slotID) + 1).ToString());
  126. DB.Insert(sql);
  127. }
  128. public List<string> GetHistoryRecipeList(DateTime begin, DateTime end)
  129. {
  130. List<string> result = new List<string>();
  131. string sql = string.Format("SELECT * FROM \"RecipeRunHistory\" where \"ProcessBeginTime\" >= '{0}' and \"ProcessBeginTime\" <= '{1}' order by \"ProcessBeginTime\" ASC;",
  132. begin.ToString("yyyy/MM/dd HH:mm:ss.fff"), end.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  133. DataSet ds = DB.ExecuteDataset(sql);
  134. if (ds == null)
  135. return result;
  136. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  137. {
  138. string recipe = ds.Tables[0].Rows[i]["RecipeName"].ToString();
  139. if (!result.Contains(recipe))
  140. result.Add(recipe);
  141. }
  142. ds.Clear();
  143. return result;
  144. }
  145. public static List<HistoryProcessData> QueryDBProcess(string sql)
  146. {
  147. List<HistoryProcessData> result = new List<HistoryProcessData>();
  148. try
  149. {
  150. DataSet ds = DB.ExecuteDataset(sql);
  151. if (ds == null)
  152. return result;
  153. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  154. {
  155. HistoryProcessData ev = new HistoryProcessData();
  156. ev.RecipeName = ds.Tables[0].Rows[i]["recipe_name"].ToString();
  157. ev.Result = ds.Tables[0].Rows[i]["process_status"].ToString();
  158. ev.Guid = ds.Tables[0].Rows[i]["guid"].ToString();
  159. if (!ds.Tables[0].Rows[i]["process_begin_time"].Equals(DBNull.Value))
  160. ev.StartTime = ((DateTime)ds.Tables[0].Rows[i]["process_begin_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  161. if (!ds.Tables[0].Rows[i]["process_end_time"].Equals(DBNull.Value))
  162. ev.EndTime = ((DateTime)ds.Tables[0].Rows[i]["process_end_time"]).ToString("yyyy/MM/dd HH:mm:ss.fff");
  163. result.Add(ev);
  164. }
  165. }
  166. catch (Exception ex)
  167. {
  168. LOG.WriteExeption(ex);
  169. }
  170. return result;
  171. }
  172. public static List<HistoryDataItem> GetHistoryDataFromStartToEnd(IEnumerable<string> keys, DateTime begin, DateTime end, string module)
  173. {
  174. List<HistoryDataItem> result = new List<HistoryDataItem>();
  175. try
  176. {
  177. DateTime begintime = new DateTime(begin.Year, begin.Month, begin.Day, begin.Hour, begin.Minute, begin.Second, begin.Millisecond);
  178. DateTime endtime = new DateTime(begin.Year, begin.Month, end.Day, end.Hour, end.Minute, end.Second, end.Millisecond);
  179. string sql = "select time AS InternalTimeStamp";
  180. foreach (var dataId in keys)
  181. {
  182. sql += "," + string.Format("\"{0}\"", dataId);
  183. }
  184. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 86400;",
  185. begin.ToString("yyyyMMdd") + "." + module, begintime.Ticks, endtime.Ticks);
  186. DataSet dataSet = DB.ExecuteDataset(sql);
  187. if (dataSet == null)
  188. return result;
  189. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  190. return result;
  191. DateTime dt = new DateTime();
  192. Dictionary<int, string> colName = new Dictionary<int, string>();
  193. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  194. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  195. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  196. {
  197. var row = dataSet.Tables[0].Rows[rowNo];
  198. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  199. {
  200. HistoryDataItem data = new HistoryDataItem();
  201. if (i == 0)
  202. {
  203. long ticks = (long)row[i];
  204. dt = new DateTime(ticks);
  205. continue;
  206. }
  207. else
  208. {
  209. string dataId = colName[i];
  210. if (row[i] is DBNull || row[i] == null)
  211. {
  212. data.dateTime = dt;
  213. data.dbName = colName[i];
  214. data.value = 0;
  215. }
  216. else if (row[i] is bool)
  217. {
  218. data.dateTime = dt;
  219. data.dbName = colName[i];
  220. data.value = (bool)row[i] ? 1 : 0;
  221. }
  222. else
  223. {
  224. data.dateTime = dt;
  225. data.dbName = colName[i];
  226. data.value = float.Parse(row[i].ToString());
  227. }
  228. }
  229. result.Add(data);
  230. }
  231. }
  232. dataSet.Clear();
  233. }
  234. catch (Exception ex)
  235. {
  236. LOG.WriteExeption(ex);
  237. }
  238. return result;
  239. }
  240. public static List<HistoryDataItem> GetOneDayHistoryData(IEnumerable<string> keys, DateTime begin, string module)
  241. {
  242. List<HistoryDataItem> result = new List<HistoryDataItem>();
  243. try
  244. {
  245. DateTime begintime = new DateTime(begin.Year, begin.Month, begin.Day, 0, 0, 0, 0);
  246. DateTime endtime = new DateTime(begin.Year, begin.Month, begin.Day, 23, 59, 59, 999);
  247. string sql = "select time AS InternalTimeStamp";
  248. foreach (var dataId in keys)
  249. {
  250. sql += "," + string.Format("\"{0}\"", dataId);
  251. }
  252. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 86400;",
  253. begin.ToString("yyyyMMdd") + "." + module, begintime.Ticks, endtime.Ticks);
  254. DataSet dataSet = DB.ExecuteDataset(sql);
  255. if (dataSet == null)
  256. return result;
  257. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  258. return result;
  259. DateTime dt = new DateTime();
  260. Dictionary<int, string> colName = new Dictionary<int, string>();
  261. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  262. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  263. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  264. {
  265. var row = dataSet.Tables[0].Rows[rowNo];
  266. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  267. {
  268. HistoryDataItem data = new HistoryDataItem();
  269. if (i == 0)
  270. {
  271. long ticks = (long)row[i];
  272. dt = new DateTime(ticks);
  273. continue;
  274. }
  275. else
  276. {
  277. string dataId = colName[i];
  278. if (row[i] is DBNull || row[i] == null)
  279. {
  280. data.dateTime = dt;
  281. data.dbName = colName[i];
  282. data.value = 0;
  283. }
  284. else if (row[i] is bool)
  285. {
  286. data.dateTime = dt;
  287. data.dbName = colName[i];
  288. data.value = (bool)row[i] ? 1 : 0;
  289. }
  290. else
  291. {
  292. data.dateTime = dt;
  293. data.dbName = colName[i];
  294. data.value = float.Parse(row[i].ToString());
  295. }
  296. }
  297. result.Add(data);
  298. }
  299. }
  300. dataSet.Clear();
  301. }
  302. catch (Exception ex)
  303. {
  304. LOG.WriteExeption(ex);
  305. }
  306. return result;
  307. }
  308. public static List<HistoryDataItem> GetHistoryData(IEnumerable<string> keys, string recipeRunGuid, string module)
  309. {
  310. List<HistoryDataItem> result = new List<HistoryDataItem>();
  311. try
  312. {
  313. string sql = string.Format("SELECT * FROM \"process_data\" where \"guid\" = '{0}'",
  314. recipeRunGuid);
  315. DataSet ds = DB.ExecuteDataset(sql);
  316. if (ds == null)
  317. return result;
  318. if (ds.Tables[0].Rows.Count == 0)
  319. return result;
  320. object from = ds.Tables[0].Rows[0]["process_begin_time"];
  321. if (from is DBNull)
  322. {
  323. //LOG.Write(string.Format("{0} not set start time", recipeRunGuid));
  324. return result;
  325. }
  326. DateTime begin = (DateTime)from;
  327. begin = begin.AddSeconds(-10);
  328. object to = ds.Tables[0].Rows[0]["process_end_time"];
  329. if (to is DBNull)
  330. {
  331. to = new DateTime(begin.Year, begin.Month, begin.Day, 23, 59, 59, 999);
  332. }
  333. DateTime end = (DateTime)to;
  334. end = end.AddSeconds(10);
  335. sql = "select time AS InternalTimeStamp";
  336. foreach (var dataId in keys)
  337. {
  338. sql += "," + string.Format("\"{0}\"", dataId);
  339. }
  340. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 2000;",
  341. begin.ToString("yyyyMMdd") + "." + module, begin.Ticks, end.Ticks);
  342. DataSet dataSet = DB.ExecuteDataset(sql);
  343. if (dataSet == null)
  344. return result;
  345. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  346. return result;
  347. DateTime dt = new DateTime();
  348. Dictionary<int, string> colName = new Dictionary<int, string>();
  349. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  350. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  351. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  352. {
  353. var row = dataSet.Tables[0].Rows[rowNo];
  354. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  355. {
  356. HistoryDataItem data = new HistoryDataItem();
  357. if (i == 0)
  358. {
  359. long ticks = (long)row[i];
  360. dt = new DateTime(ticks);
  361. continue;
  362. }
  363. else
  364. {
  365. string dataId = colName[i];
  366. if (row[i] is DBNull || row[i] == null)
  367. {
  368. data.dateTime = dt;
  369. data.dbName = colName[i];
  370. data.value = 0;
  371. }
  372. else if (row[i] is bool)
  373. {
  374. data.dateTime = dt;
  375. data.dbName = colName[i];
  376. data.value = (bool)row[i] ? 1 : 0;
  377. }
  378. else
  379. {
  380. data.dateTime = dt;
  381. data.dbName = colName[i];
  382. data.value = float.Parse(row[i].ToString());
  383. }
  384. }
  385. result.Add(data);
  386. }
  387. }
  388. dataSet.Clear();
  389. }
  390. catch (Exception ex)
  391. {
  392. LOG.WriteExeption(ex);
  393. }
  394. return result;
  395. }
  396. }
  397. }