DataLogManager.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Data;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using Aitex.Core.RT.DBCore;
  8. using Aitex.Core.RT.Event;
  9. using Aitex.Core.RT.Log;
  10. using Aitex.Core.UI.ControlDataContext;
  11. using Aitex.Core.Util;
  12. using Aitex.Triton160.Common;
  13. using Aitex.Triton160.RT.Routine.Process;
  14. namespace Aitex.Triton160.RT.Module
  15. {
  16. class DataLogManager : Singleton<DataLogManager>
  17. {
  18. /*
  19. * CREATE TABLE public."RecipeRunHistory"
  20. (
  21. "RecipeRunGuid" text NOT NULL,
  22. "SusceptorId" text,
  23. "ProcessBeginTime" timestamp without time zone,
  24. "ProcessEndTime" timestamp without time zone,
  25. "ProcessIn" text,
  26. "RecipeName" text,
  27. "SusceptorStatus" text,
  28. "UserDefinedId" text,
  29. "Description" text,
  30. "WafersOnSusceptor" text,
  31. CONSTRAINT "RecipeRunHistory_pkey" PRIMARY KEY ("RecipeRunGuid")
  32. )
  33. *
  34. */
  35. public List<string> GetHistoryRecipeList(DateTime begin, DateTime end)
  36. {
  37. List<string> result = new List<string>();
  38. string sql = string.Format("SELECT * FROM \"RecipeRunHistory\" where \"ProcessBeginTime\" >= '{0}' and \"ProcessBeginTime\" <= '{1}' order by \"ProcessBeginTime\" ASC;",
  39. begin.ToString("yyyy/MM/dd HH:mm:ss.fff"), end.ToString("yyyy/MM/dd HH:mm:ss.fff"));
  40. DataSet ds = DB.ExecuteDataset(sql);
  41. if (ds == null)
  42. return result;
  43. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  44. {
  45. string recipe = ds.Tables[0].Rows[i]["RecipeName"].ToString();
  46. if (!result.Contains(recipe))
  47. result.Add(recipe);
  48. }
  49. ds.Clear();
  50. return result;
  51. }
  52. public List<DataLogItem> GetHistoryDataLogList(DateTime from, DateTime to, string recipeName, string lotName)
  53. {
  54. List<DataLogItem> result = new List<DataLogItem>();
  55. try
  56. {
  57. string sql =
  58. string.Format(
  59. "SELECT * FROM \"RecipeRunHistory\" where \"ProcessBeginTime\" >= '{0}' and \"ProcessBeginTime\" <= '{1}' {2} {3} order by \"ProcessBeginTime\" ASC;",
  60. from.ToString("yyyy/MM/dd HH:mm:ss.fff"), to.ToString("yyyy/MM/dd HH:mm:ss.fff"),
  61. string.IsNullOrEmpty(recipeName) ? "" : string.Format(" and \"RecipeName\" = '{0}'", recipeName),
  62. string.IsNullOrEmpty(lotName) ? "" : string.Format(" and position('{0}' in \"SusceptorId\") >0" , lotName));
  63. DataSet ds = DB.ExecuteDataset(sql);
  64. if (ds == null)
  65. return result;
  66. for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
  67. {
  68. result.Add(new DataLogItem()
  69. {
  70. RecipeRunGuid =
  71. ds.Tables[0].Rows[i]["RecipeRunGuid"] is DBNull
  72. ? ""
  73. : ds.Tables[0].Rows[i]["RecipeRunGuid"].ToString(),
  74. ProcessBeginTime =
  75. ds.Tables[0].Rows[i]["ProcessBeginTime"] is DBNull
  76. ? ""
  77. : ds.Tables[0].Rows[i]["ProcessBeginTime"].ToString(),
  78. ProcessEndTime =
  79. ds.Tables[0].Rows[i]["ProcessEndTime"] is DBNull
  80. ? ""
  81. : ds.Tables[0].Rows[i]["ProcessEndTime"].ToString(),
  82. RecipeName =
  83. ds.Tables[0].Rows[i]["RecipeName"] is DBNull
  84. ? ""
  85. : ds.Tables[0].Rows[i]["RecipeName"].ToString(),
  86. LotName =
  87. ds.Tables[0].Rows[i]["SusceptorId" +
  88. ""] is DBNull
  89. ? ""
  90. : ds.Tables[0].Rows[i]["SusceptorId"].ToString(),
  91. DataLogName =
  92. ds.Tables[0].Rows[i]["UserDefinedId"] is DBNull
  93. ? ""
  94. : ds.Tables[0].Rows[i]["UserDefinedId"].ToString(),
  95. RecipeResult =
  96. ds.Tables[0].Rows[i]["SusceptorStatus"] is DBNull
  97. ? ""
  98. : ds.Tables[0].Rows[i]["SusceptorStatus"].ToString()
  99. });
  100. }
  101. ds.Clear();
  102. }catch( Exception ex)
  103. {
  104. LOG.Write(ex);
  105. }
  106. return result;
  107. }
  108. public List<HistoryDataItem> GetHistoryData(IEnumerable<string> keys, string recipeRunGuid)
  109. {
  110. List<HistoryDataItem> result = new List<HistoryDataItem>();
  111. try
  112. {
  113. string sql = string.Format("SELECT * FROM \"RecipeRunHistory\" where \"RecipeRunGuid\" = '{0}'",
  114. recipeRunGuid);
  115. DataSet ds = DB.ExecuteDataset(sql);
  116. if (ds == null)
  117. return result;
  118. if (ds.Tables[0].Rows.Count == 0)
  119. return result;
  120. object from = ds.Tables[0].Rows[0]["ProcessBeginTime"];
  121. if (from is DBNull)
  122. {
  123. LOG.Write(string.Format("{0} not set start time", recipeRunGuid));
  124. return result;
  125. }
  126. DateTime begin = (DateTime) from;
  127. object to = ds.Tables[0].Rows[0]["ProcessEndTime"];
  128. if (to is DBNull)
  129. {
  130. to = new DateTime(begin.Year, begin.Month, begin.Day, 23, 59, 59, 999);
  131. }
  132. DateTime end = (DateTime) to;
  133. sql = "select time AS InternalTimeStamp";
  134. foreach (var dataId in keys)
  135. {
  136. sql += "," + string.Format("\"{0}\"", dataId);
  137. }
  138. sql += string.Format(" from \"{0}\" where time > {1} and time <= {2} order by time asc LIMIT 2000;",
  139. begin.ToString("yyyyMMdd") + "." + ModuleName.System, begin.Ticks, end.Ticks);
  140. DataSet dataSet = DB.ExecuteDataset(sql);
  141. if (dataSet == null)
  142. return result;
  143. if (dataSet.Tables.Count == 0 || dataSet.Tables[0].Rows.Count == 0)
  144. return result;
  145. DateTime dt = new DateTime();
  146. Dictionary<int, string> colName = new Dictionary<int, string>();
  147. for (int colNo = 0; colNo < dataSet.Tables[0].Columns.Count; colNo++)
  148. colName.Add(colNo, dataSet.Tables[0].Columns[colNo].ColumnName);
  149. for (int rowNo = 0; rowNo < dataSet.Tables[0].Rows.Count; rowNo++)
  150. {
  151. var row = dataSet.Tables[0].Rows[rowNo];
  152. for (int i = 0; i < dataSet.Tables[0].Columns.Count; i++)
  153. {
  154. HistoryDataItem data = new HistoryDataItem();
  155. if (i == 0)
  156. {
  157. long ticks = (long) row[i];
  158. dt = new DateTime(ticks);
  159. continue;
  160. }
  161. else
  162. {
  163. string dataId = colName[i];
  164. if (row[i] is DBNull || row[i] == null)
  165. {
  166. data.dateTime = dt;
  167. data.dbName = colName[i];
  168. data.value = 0;
  169. }
  170. else if (row[i] is bool)
  171. {
  172. data.dateTime = dt;
  173. data.dbName = colName[i];
  174. data.value = (bool) row[i] ? 1 : 0;
  175. }
  176. else
  177. {
  178. data.dateTime = dt;
  179. data.dbName = colName[i];
  180. data.value = float.Parse(row[i].ToString());
  181. }
  182. }
  183. result.Add(data);
  184. }
  185. }
  186. dataSet.Clear();
  187. }catch(Exception ex)
  188. {
  189. LOG.Write(ex);
  190. }
  191. return result;
  192. }
  193. }
  194. }