WaferHistoryDBViewModel.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.ComponentModel;
  5. using System.Data;
  6. using System.Linq;
  7. using System.Windows.Forms;
  8. using System.Windows.Input;
  9. using MECF.Framework.Common.CommonData;
  10. using MECF.Framework.Common.DataCenter;
  11. using OpenSEMI.ClientBase;
  12. using OpenSEMI.ClientBase.Command;
  13. using SciChart.Core.Extensions;
  14. namespace VirgoUI.Client.Models.DataLog.WaferHistory
  15. {
  16. public class WaferHistoryDBViewModel : BaseModel
  17. {
  18. public WaferHistoryDBViewModel()
  19. {
  20. SelectionChangedCommand = new BaseCommand<WaferHistoryItem>(SelectionChanged);
  21. QueryCommand = new BaseCommand<object>(QueryLots);
  22. ToChartCommand = new BaseCommand<object>(GoToChart);
  23. HistoryData = new ObservableCollection<LazyTreeItem<WaferHistoryItem>>();
  24. InitTime();
  25. }
  26. private ObservableCollection<LazyTreeItem<WaferHistoryItem>> _historyData;
  27. public ObservableCollection<LazyTreeItem<WaferHistoryItem>> HistoryData
  28. {
  29. get { return _historyData; }
  30. set
  31. {
  32. _historyData = value;
  33. NotifyOfPropertyChange("HistoryData");
  34. }
  35. }
  36. private WaferHistoryItem _selectedItem;
  37. public WaferHistoryItem SelectedItem
  38. {
  39. get { return _selectedItem; }
  40. set
  41. {
  42. _selectedItem = value;
  43. NotifyOfPropertyChange("SelectedItem");
  44. }
  45. }
  46. private ObservableCollection<WaferHistoryLot> _lots = new ObservableCollection<WaferHistoryLot>();
  47. public ObservableCollection<WaferHistoryLot> Lots
  48. {
  49. get { return _lots; }
  50. set
  51. {
  52. _lots = value;
  53. NotifyOfPropertyChange("Lots");
  54. }
  55. }
  56. private ObservableCollection<WaferHistoryWafer> _wafers = new ObservableCollection<WaferHistoryWafer>();
  57. public ObservableCollection<WaferHistoryWafer> Wafers
  58. {
  59. get { return _wafers; }
  60. set
  61. {
  62. _wafers = value;
  63. NotifyOfPropertyChange("Wafers");
  64. }
  65. }
  66. private ObservableCollection<WaferHistoryMovement> _movements = new ObservableCollection<WaferHistoryMovement>();
  67. public ObservableCollection<WaferHistoryMovement> Movements
  68. {
  69. get { return _movements; }
  70. set
  71. {
  72. _movements = value;
  73. NotifyOfPropertyChange("Movements");
  74. }
  75. }
  76. private WaferHistoryRecipe _recipe;
  77. public WaferHistoryRecipe Recipe
  78. {
  79. get { return _recipe; }
  80. set
  81. {
  82. _recipe = value;
  83. NotifyOfPropertyChange("Recipe");
  84. }
  85. }
  86. public ObservableCollection<WaferHistoryRecipe> _recipes = new ObservableCollection<WaferHistoryRecipe>();
  87. public ObservableCollection<WaferHistoryRecipe> Recipes
  88. {
  89. get { return _recipes; }
  90. set
  91. {
  92. _recipes = value;
  93. NotifyOfPropertyChange("Recipes");
  94. }
  95. }
  96. private DateTime _searchBeginTime;
  97. public DateTime SearchBeginTime
  98. {
  99. get { return _searchBeginTime; }
  100. set
  101. {
  102. _searchBeginTime = value;
  103. NotifyOfPropertyChange("SearchBeginTime");
  104. }
  105. }
  106. private DateTime _searchEndTime;
  107. public DateTime SearchEndTime
  108. {
  109. get { return _searchEndTime; }
  110. set
  111. {
  112. _searchEndTime = value;
  113. NotifyOfPropertyChange("SearchEndTime");
  114. }
  115. }
  116. private string keyWord;
  117. private WaferHistoryDBView view;
  118. public string KeyWord
  119. {
  120. get { return keyWord; }
  121. set
  122. {
  123. keyWord = value;
  124. NotifyOfPropertyChange("KeyWord");
  125. }
  126. }
  127. public ICommand SelectionChangedCommand { get; set; }
  128. public ICommand QueryCommand { get; set; }
  129. public ICommand ToChartCommand { get; set; }
  130. void InitTime()
  131. {
  132. SearchBeginTime = DateTime.Now.Date;
  133. SearchEndTime = DateTime.Now.Date.AddDays(1).Date;
  134. }
  135. void QueryLots(object e)
  136. {
  137. this.SearchBeginTime = this.view.wfTimeFrom.Value;
  138. this.SearchEndTime = this.view.wfTimeTo.Value;
  139. if (SearchBeginTime > SearchEndTime)
  140. {
  141. MessageBox.Show("Time range invalid, start time should be early than end time");
  142. return;
  143. }
  144. Lots = new ObservableCollection<WaferHistoryLot>(QueryLot(SearchBeginTime, SearchEndTime, KeyWord));//.OrderByDescending(lot => lot.StartTime).ToArray();
  145. HistoryData.Clear();
  146. var lotsItem = new WaferHistoryItem() { Name = "Lots", };
  147. var root = new LazyTreeItem<WaferHistoryItem>(lotsItem, x => LoadSubItem(x));
  148. root.SubItems = new ObservableCollection<LazyTreeItem<WaferHistoryItem>>(Lots.Select(x => new LazyTreeItem<WaferHistoryItem>(new WaferHistoryItem() { ID = x.ID, Name = x.Name, StartTime = x.StartTime, EndTime = x.EndTime, Type = WaferHistoryItemType.Lot }, LoadSubItem)));
  149. root.IsExpanded = true;
  150. HistoryData.Add(root);
  151. SelectedItem = lotsItem;
  152. }
  153. /// <summary>
  154. /// Notify chart page to prepare datas
  155. /// </summary>
  156. /// <param name="o"></param>
  157. void GoToChart(object o)
  158. {
  159. WaferHistoryItem item = o as WaferHistoryItem;
  160. if (o is WaferHistoryLot waferLot)
  161. {
  162. item.Type = WaferHistoryItemType.Lot;
  163. SelectionChanged(item);
  164. WaferHistoryItem selectItem = null;
  165. foreach (var root in HistoryData)
  166. {
  167. foreach (var subroot in root.SubItems)
  168. {
  169. var data = subroot.Data as WaferHistoryItem;
  170. if (data != null && data.Name != null && data.Name == item.Name)
  171. {
  172. selectItem = data;
  173. subroot.IsExpanded = true;
  174. break;
  175. }
  176. }
  177. if (selectItem != null)
  178. break;
  179. }
  180. }
  181. else if (o is WaferHistoryWafer wafer)
  182. {
  183. item.Type = WaferHistoryItemType.Wafer;
  184. //导航切换到chart页面
  185. BaseApp.Instance.SwitchPage("DataLog", "ProcessHistory", wafer);
  186. return;
  187. }
  188. else if (o is WaferHistoryRecipe)
  189. {
  190. item.Type = WaferHistoryItemType.Recipe;
  191. }
  192. else if (o is string name)
  193. {
  194. var query = _recipes.FirstOrDefault(t => t.Recipe == name);
  195. if (query is null) return;
  196. WaferHistoryWafer wafer1 = new WaferHistoryWafer();
  197. wafer1.StartTime = query.StartTime;
  198. wafer1.EndTime = query.EndTime;
  199. BaseApp.Instance.SwitchPage("DataLog", "ProcessHistory", wafer1);
  200. }
  201. else if (o is DateTime startTime)
  202. {
  203. var query = _recipes.FirstOrDefault(t => t.StartTime.CompareTo(startTime) == 0);
  204. if (query is null) return;
  205. WaferHistoryWafer wafer1 = new WaferHistoryWafer();
  206. wafer1.StartTime = query.StartTime;
  207. wafer1.EndTime = query.EndTime;
  208. BaseApp.Instance.SwitchPage("DataLog", "ProcessHistory", wafer1);
  209. }
  210. //
  211. //WaferHistoryRecipe chartQuery = null;
  212. //if (o is string name)
  213. //{
  214. // var query = _recipes.FirstOrDefault(t => t.Recipe == name);
  215. // if (query is null) return;
  216. // chartQuery = query;
  217. //}
  218. //if (o is WaferHistoryLot waferLot)
  219. //{
  220. // DateTime start = waferLot.StartTime;
  221. // double.TryParse(waferLot.Duration, out double duration);
  222. // DateTime end = start.AddSeconds(duration);
  223. // chartQuery = new WaferHistoryRecipe() { StartTime = start, EndTime = end, /*Chamber = waferLot.CarrierID */};
  224. //}
  225. //else if (o is WaferHistoryWafer wafer)
  226. //{
  227. // chartQuery = new WaferHistoryRecipe() { StartTime = wafer.StartTime, EndTime = wafer.EndTime/*,Chamber = waferLot.CarrierID*/ };
  228. //}
  229. //导航切换到chart页面
  230. //BaseApp.Instance.SwitchPage("DataLog", "DataHistory", chartQuery);
  231. }
  232. public List<WaferHistoryLot> QueryLot(DateTime from, DateTime to, string key)
  233. {
  234. List<WaferHistoryLot> result = new List<WaferHistoryLot>();
  235. string sql = $"SELECT * FROM \"lot_data\" where \"start_time\" >= '{from:yyyy/MM/dd HH:mm:ss.fff}' and \"start_time\" <= '{to:yyyy/MM/dd HH:mm:ss.fff}' ";
  236. if (!string.IsNullOrWhiteSpace(key))
  237. sql += $" and lower(\"name\") like '%{key.ToLower()}%'";
  238. sql += "order by \"start_time\" ASC;";
  239. //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  240. //{
  241. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  242. if (dbData != null && dbData.Rows.Count > 0)
  243. {
  244. for (int i = 0; i < dbData.Rows.Count; i++)
  245. {
  246. WaferHistoryLot item = new WaferHistoryLot();
  247. string name = dbData.Rows[i]["name"].ToString();
  248. string time = "";
  249. item.WaferCount = (int)dbData.Rows[i]["total_wafer_count"];
  250. item.ID = dbData.Rows[i]["guid"].ToString();
  251. if (!dbData.Rows[i]["start_time"].Equals(DBNull.Value))
  252. {
  253. item.StartTime = ((DateTime)dbData.Rows[i]["start_time"]);
  254. time = item.StartTime.ToString("yyyy-MM-dd HH:mm:ss");
  255. }
  256. if (!dbData.Rows[i]["end_time"].Equals(DBNull.Value))
  257. {
  258. item.EndTime = ((DateTime)dbData.Rows[i]["end_time"]);
  259. }
  260. item.InputPort = dbData.Rows[i]["input_port"].ToString();
  261. item.Name = $"{name}-{time}";
  262. item.LotID = $"{name}";
  263. result.Add(item);
  264. }
  265. }
  266. //}));
  267. return result;
  268. }
  269. public List<WaferHistoryWafer> QueryLotWafer(WaferHistoryItem whItem)
  270. {
  271. List<WaferHistoryWafer> result = new List<WaferHistoryWafer>();
  272. //string sql = $"select data.*,process_data.process_status from (SELECT * FROM wafer_data,lot_wafer_data where lot_wafer_data.lot_data_guid = '{lotGuid}' and lot_wafer_data.wafer_data_guid = wafer_data.guid order by wafer_data.create_time ASC; as data )" +
  273. // $" LEFT JOIN process_data ON process_data.wafer_data_guid=data.wafer_id";
  274. string sql = $"SELECT wafer_data.*,lot_wafer_data.*,process_data.process_status as status FROM wafer_data LEFT JOIN lot_wafer_data ON lot_wafer_data.wafer_data_guid = wafer_data.guid " +
  275. $"LEFT JOIN process_data ON process_data.wafer_data_guid = wafer_data.guid where lot_wafer_data.lot_data_guid = '{whItem.ID}' order by wafer_data.create_time ASC";
  276. Wafers.Clear();
  277. //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  278. //{
  279. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  280. Dictionary<string, int> itemPtr = new Dictionary<string, int>();
  281. List<string> itemNameList = new List<string>();
  282. if (dbData != null && dbData.Rows.Count > 0)
  283. {
  284. for (int i = 0; i < dbData.Rows.Count; i++)
  285. {
  286. WaferHistoryWafer item = new WaferHistoryWafer();
  287. item.ID = dbData.Rows[i]["guid"].ToString();
  288. if (!itemPtr.ContainsKey(item.ID))
  289. {
  290. itemPtr.Add(item.ID, 0);
  291. }
  292. var itemLoadPort = dbData.Rows[i]["create_station"].ToString();
  293. var itemSlot = dbData.Rows[i]["create_slot"].ToString();
  294. //item.CarrierID = dbData.Rows[i]["rfid"].ToString();
  295. item.LotID = dbData.Rows[i]["lot_id"].ToString();
  296. item.SlotID = dbData.Rows[i]["create_slot"].ToString();
  297. var itemWaferID = dbData.Rows[i]["wafer_id"].ToString();
  298. item.Sequence = dbData.Rows[i]["sequence_name"].ToString();
  299. item.Status = dbData.Rows[i]["status"].ToString();
  300. sql = $"SELECT * FROM \"wafer_move_history\" where \"wafer_data_guid\" = '{item.ID}' and \"arrive_time\" >= '{whItem.StartTime:yyyy/MM/dd HH:mm:ss.fff}' and \"arrive_time\" <= '{whItem.EndTime:yyyy/MM/dd HH:mm:ss.fff}' order by \"arrive_time\" ASC limit 1000;";
  301. DataTable dbDataMovement = QueryDataClient.Instance.Service.QueryData(sql);
  302. if (dbDataMovement != null && dbDataMovement.Rows.Count >= 2 && dbDataMovement.Rows.Count > itemPtr[item.ID])
  303. {
  304. item.StartTime = (DateTime)dbDataMovement.Rows[itemPtr[item.ID]]["arrive_time"];
  305. for (int j = itemPtr[item.ID]; j < dbDataMovement.Rows.Count; j++)
  306. {
  307. if (dbDataMovement.Rows[j]["station"].ToString().StartsWith("LP"))
  308. {
  309. item.EndTime = (DateTime)dbDataMovement.Rows[j]["arrive_time"];
  310. itemPtr[item.ID] = j + 1;
  311. break;
  312. }
  313. }
  314. }
  315. else
  316. {
  317. if (!dbData.Rows[i]["create_time"].Equals(DBNull.Value))
  318. {
  319. item.StartTime = ((DateTime)dbData.Rows[i]["create_time"]);
  320. }
  321. if (!dbData.Rows[i]["delete_time"].Equals(DBNull.Value))
  322. item.EndTime = ((DateTime)dbData.Rows[i]["delete_time"]);
  323. }
  324. item.Name = $"{itemLoadPort} - {itemSlot} - {itemWaferID}";
  325. item.Type = WaferHistoryItemType.Wafer;
  326. if (!itemNameList.Contains(item.Name))
  327. {
  328. Wafers.Add(item);
  329. result.Add(item);
  330. itemNameList.Add(item.Name);
  331. }
  332. }
  333. }
  334. //}));
  335. return result;
  336. }
  337. public List<WaferHistoryRecipe> QueryWaferRecipe(WaferHistoryItem whItem)
  338. {
  339. List<WaferHistoryRecipe> result = new List<WaferHistoryRecipe>();
  340. string sql = $"SELECT * FROM \"process_data\" where \"wafer_data_guid\" = '{whItem.ID}'and \"process_begin_time\" >= '{whItem.StartTime:yyyy/MM/dd HH:mm:ss.fff}' and \"process_begin_time\" <= '{whItem.EndTime:yyyy/MM/dd HH:mm:ss.fff}' order by \"process_begin_time\" ASC;";
  341. Recipes.Clear();
  342. //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  343. //{
  344. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  345. if (dbData != null && dbData.Rows.Count > 0)
  346. {
  347. for (int i = 0; i < dbData.Rows.Count; i++)
  348. {
  349. WaferHistoryRecipe item = new WaferHistoryRecipe();
  350. item.ID = dbData.Rows[i]["guid"].ToString();
  351. var itemName = dbData.Rows[i]["recipe_name"].ToString();
  352. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  353. item.StartTime = (DateTime)dbData.Rows[i]["process_begin_time"];
  354. if (dbData.Rows[i].Table.Columns.Contains("process_end_time") && !dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  355. item.EndTime = (DateTime)dbData.Rows[i]["process_end_time"];
  356. if (dbData.Rows[i].Table.Columns.Contains("recipe_setting_time") && !dbData.Rows[i]["recipe_setting_time"].Equals(DBNull.Value))
  357. item.SettingTime = dbData.Rows[i]["recipe_setting_time"].ToString();
  358. item.ActualTime = item.Duration;
  359. item.Recipe = itemName;
  360. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  361. item.Name = itemName;
  362. item.Type = WaferHistoryItemType.Recipe;
  363. Recipes.Add(item);
  364. result.Add(item);
  365. }
  366. }
  367. //}));
  368. return result;
  369. }
  370. public List<WaferHistoryMovement> QueryWaferMovement(WaferHistoryItem whItem)
  371. {
  372. List<WaferHistoryMovement> result = new List<WaferHistoryMovement>();
  373. string sql = $"SELECT * FROM \"wafer_move_history\" where \"wafer_data_guid\" = '{whItem.ID}'and \"arrive_time\" >= '{whItem.StartTime:yyyy/MM/dd HH:mm:ss.fff}' and \"arrive_time\" <= '{whItem.EndTime:yyyy/MM/dd HH:mm:ss.fff}' order by \"arrive_time\" ASC limit 1000;";
  374. Movements.Clear();
  375. //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  376. //{
  377. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  378. if (dbData != null && dbData.Rows.Count > 0)
  379. {
  380. for (int i = 0; i < dbData.Rows.Count - 1; i++)
  381. {
  382. WaferHistoryMovement item = new WaferHistoryMovement();
  383. item.Source = $"station : {dbData.Rows[i]["station"]} slot : {dbData.Rows[i]["slot"]}";
  384. item.Destination = $"station : {dbData.Rows[i + 1]["station"]} slot : {dbData.Rows[i + 1]["slot"]}";
  385. item.InTime = dbData.Rows[i]["arrive_time"].ToString();
  386. result.Add(item);
  387. Movements.Add(item);
  388. }
  389. }
  390. //}));
  391. return result;
  392. }
  393. public WaferHistoryRecipe QueryRecipe(WaferHistoryItem whItem)
  394. {
  395. WaferHistoryRecipe result = new WaferHistoryRecipe();
  396. string sql = $"SELECT * FROM \"process_data\" where \"guid\" = '{whItem.ID}'and \"process_begin_time\" >= '{whItem.StartTime:yyyy/MM/dd HH:mm:ss.fff}' and \"process_begin_time\" <= '{whItem.EndTime:yyyy/MM/dd HH:mm:ss.fff}';";
  397. //Application.Current.Dispatcher.BeginInvoke(new Action(() =>
  398. //{
  399. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  400. if (dbData != null && dbData.Rows.Count > 0)
  401. {
  402. for (int i = 0; i < dbData.Rows.Count; i++)
  403. {
  404. WaferHistoryRecipe item = new WaferHistoryRecipe();
  405. item.ID = dbData.Rows[i]["guid"].ToString();
  406. var itemName = dbData.Rows[i]["recipe_name"].ToString();
  407. if (!dbData.Rows[i]["process_begin_time"].Equals(DBNull.Value))
  408. item.StartTime = (DateTime)dbData.Rows[i]["process_begin_time"];
  409. if (!dbData.Rows[i]["process_end_time"].Equals(DBNull.Value))
  410. item.EndTime = (DateTime)dbData.Rows[i]["process_end_time"];
  411. if (dbData.Rows[i].Table.Columns.Contains("recipe_setting_time") && !dbData.Rows[i]["recipe_setting_time"].Equals(DBNull.Value))
  412. item.SettingTime = dbData.Rows[i]["recipe_setting_time"].ToString();
  413. item.ActualTime = item.Duration;
  414. item.Recipe = itemName;
  415. item.Chamber = dbData.Rows[i]["process_in"].ToString();
  416. item.Name = itemName;
  417. item.Type = WaferHistoryItemType.Recipe;
  418. result = item;
  419. }
  420. }
  421. sql = $"SELECT * FROM \"recipe_step_data\" where \"process_data_guid\" = '{whItem.ID}' and \"step_begin_time\" >= '{whItem.StartTime:yyyy/MM/dd HH:mm:ss.fff}' and \"step_begin_time\" <= '{whItem.EndTime:yyyy/MM/dd HH:mm:ss.fff}' order by step_number ASC;";
  422. dbData = QueryDataClient.Instance.Service.QueryData(sql);
  423. List<RecipeStep> steps = new List<RecipeStep>();
  424. if (dbData != null && dbData.Rows.Count > 0)
  425. {
  426. for (int i = 0; i < dbData.Rows.Count; i++)
  427. {
  428. RecipeStep item = new RecipeStep();
  429. item.No = int.Parse(dbData.Rows[i]["step_number"].ToString());
  430. item.Name = dbData.Rows[i]["step_name"].ToString();
  431. if (!dbData.Rows[i]["step_begin_time"].Equals(DBNull.Value))
  432. item.StartTime = (DateTime)dbData.Rows[i]["step_begin_time"];
  433. if (!dbData.Rows[i]["step_end_time"].Equals(DBNull.Value))
  434. item.EndTime = (DateTime)dbData.Rows[i]["step_end_time"];
  435. item.ActualTime = item.EndTime.CompareTo(item.StartTime) <= 0 ? "" : item.EndTime.Subtract(item.StartTime).TotalSeconds.ToString();
  436. item.SettingTime = dbData.Rows[i]["step_time"].ToString();
  437. steps.Add(item);
  438. }
  439. }
  440. sql = $"SELECT * FROM \"step_fdc_data\" where \"process_data_guid\" = '{whItem.ID}' and \"create_time\" >= '{whItem.StartTime:yyyy/MM/dd HH:mm:ss.fff}' and \"create_time\" <= '{whItem.EndTime:yyyy/MM/dd HH:mm:ss.fff}'order by step_number ASC;";
  441. dbData = QueryDataClient.Instance.Service.QueryData(sql);
  442. List<RecipeStepFdcData> fdcs = new List<RecipeStepFdcData>();
  443. if (dbData != null && dbData.Rows.Count > 0)
  444. {
  445. for (int i = 0; i < dbData.Rows.Count; i++)
  446. {
  447. RecipeStepFdcData item = new RecipeStepFdcData();
  448. item.StepNumber = int.Parse(dbData.Rows[i]["step_number"].ToString());
  449. item.Name = dbData.Rows[i]["parameter_name"].ToString();
  450. foreach (var name in _mapGasNameKey)
  451. {
  452. if (item.Name.Contains(name.Value) && _mapGasNameValue.ContainsKey(name.Key))
  453. item.Name = item.Name.Replace(name.Value, (string)_mapGasNameValue[name.Key]);
  454. }
  455. if (!dbData.Rows[i]["sample_count"].Equals(DBNull.Value))
  456. item.SampleCount = (int)dbData.Rows[i]["sample_count"];
  457. if (!dbData.Rows[i]["setpoint"].Equals(DBNull.Value))
  458. item.SetPoint = (float)dbData.Rows[i]["setpoint"];
  459. if (!dbData.Rows[i]["min_value"].Equals(DBNull.Value))
  460. item.MinValue = (float)dbData.Rows[i]["min_value"];
  461. if (!dbData.Rows[i]["max_value"].Equals(DBNull.Value))
  462. item.MaxValue = (float)dbData.Rows[i]["max_value"];
  463. if (!dbData.Rows[i]["std_value"].Equals(DBNull.Value))
  464. item.StdValue = (float)dbData.Rows[i]["std_value"];
  465. if (!dbData.Rows[i]["mean_value"].Equals(DBNull.Value))
  466. item.MeanValue = (float)dbData.Rows[i]["mean_value"];
  467. fdcs.Add(item);
  468. }
  469. }
  470. result.Steps = steps;
  471. result.Fdcs = fdcs;
  472. Recipe = result;
  473. return result;
  474. }
  475. private void SelectionChanged(WaferHistoryItem item)
  476. {
  477. switch (item.Type)
  478. {
  479. case WaferHistoryItemType.Lot:
  480. QueryLotWafer(item);
  481. break;
  482. case WaferHistoryItemType.Wafer:
  483. QueryWaferRecipe(item);
  484. QueryWaferMovement(item);
  485. break;
  486. case WaferHistoryItemType.Recipe:
  487. QueryRecipe(item);
  488. break;
  489. default:
  490. break;
  491. }
  492. SelectedItem = item;
  493. }
  494. protected List<LazyTreeItem<WaferHistoryItem>> LoadSubItem(WaferHistoryItem item)
  495. {
  496. switch (item.Type)
  497. {
  498. case WaferHistoryItemType.Lot:
  499. var wafers = QueryLotWafer(item);
  500. return wafers.Select(x => new LazyTreeItem<WaferHistoryItem>(x, y => LoadSubItem(y))).OrderBy(s => s.Data.StartTime).ToList();
  501. case WaferHistoryItemType.Wafer:
  502. var recipes = QueryWaferRecipe(item);
  503. return recipes.Select(x => new LazyTreeItem<WaferHistoryItem>(x, y => LoadSubItem(y))).OrderBy(s => s.Data.StartTime).ToList();
  504. default:
  505. break;
  506. }
  507. return new List<LazyTreeItem<WaferHistoryItem>> { };
  508. }
  509. protected override void OnViewLoaded(object _view)
  510. {
  511. base.OnViewLoaded(_view);
  512. this.view = (WaferHistoryDBView)_view;
  513. this.view.wfTimeFrom.Value = this.SearchBeginTime;
  514. this.view.wfTimeTo.Value = this.SearchEndTime;
  515. QueryLots(new object());
  516. SelectionChanged(SelectedItem);
  517. }
  518. private Dictionary<string, object> _mapGasNameValue = new Dictionary<string, object>();
  519. private Dictionary<string, string> _mapGasNameKey = new Dictionary<string, string>()
  520. {
  521. {"PMA.MfcGas1.GasName", "PMA.IoMfc.MfcGas1"},
  522. {"PMA.MfcGas2.GasName", "PMA.IoMfc.MfcGas2"},
  523. {"PMA.MfcGas3.GasName", "PMA.IoMfc.MfcGas3"},
  524. {"PMA.MfcGas4.GasName", "PMA.IoMfc.MfcGas4"},
  525. {"PMA.MfcGas5.GasName", "PMA.IoMfc.MfcGas5"},
  526. {"PMB.MfcGas1.GasName", "PMB.IoMfc.MfcGas1"},
  527. {"PMB.MfcGas2.GasName", "PMB.IoMfc.MfcGas2"},
  528. {"PMB.MfcGas3.GasName", "PMB.IoMfc.MfcGas3"},
  529. {"PMB.MfcGas4.GasName", "PMB.IoMfc.MfcGas4"},
  530. {"PMB.MfcGas5.GasName", "PMB.IoMfc.MfcGas5"},
  531. };
  532. protected override void OnActivate()
  533. {
  534. base.OnActivate();
  535. _mapGasNameValue = QueryDataClient.Instance.Service.PollConfig(_mapGasNameKey.Keys);
  536. }
  537. }
  538. public class LazyTreeItem<T> : INotifyPropertyChanged where T : ITreeItem<T>, new()
  539. {
  540. private LazyTreeItem<T> dummyChild;
  541. private T data;
  542. private Func<T, List<LazyTreeItem<T>>> loader;
  543. private LazyTreeItem()
  544. {
  545. data = new T();
  546. data.ID = Guid.NewGuid().ToString();
  547. }
  548. public LazyTreeItem(T data, Func<T, List<LazyTreeItem<T>>> loader)
  549. {
  550. this.data = data;
  551. this.loader = loader;
  552. dummyChild = new LazyTreeItem<T>();
  553. SubItems = new ObservableCollection<LazyTreeItem<T>>();
  554. SubItems.Add(dummyChild);
  555. }
  556. public T Data
  557. {
  558. get
  559. {
  560. return data;
  561. }
  562. }
  563. public ObservableCollection<LazyTreeItem<T>> SubItems
  564. {
  565. get; set;
  566. }
  567. private bool isExpanded;
  568. public event PropertyChangedEventHandler PropertyChanged;
  569. private void OnPropertyChanged(string name)
  570. {
  571. if (PropertyChanged != null)
  572. {
  573. PropertyChanged.Invoke(this, new PropertyChangedEventArgs(name));
  574. }
  575. }
  576. public bool HasDummyChild
  577. {
  578. get { return SubItems.Count == 1 && SubItems.First().data.ID == dummyChild.data.ID; }
  579. }
  580. public bool IsExpanded
  581. {
  582. get { return isExpanded; }
  583. set
  584. {
  585. if (value != isExpanded)
  586. {
  587. isExpanded = value;
  588. OnPropertyChanged("IsExpanded");
  589. }
  590. if (HasDummyChild)
  591. {
  592. SubItems.Remove(dummyChild);
  593. var items = loader(data);
  594. items.ForEachDo(x => SubItems.Add(x));
  595. }
  596. }
  597. }
  598. }
  599. }