ProcessDataRecorder.cs 18 KB

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