ProcessDataRecorder.cs 18 KB

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