ProcessDataRecorder.cs 19 KB

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