ProcessHistoryTwoViewModel.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472
  1. using Aitex.Core.RT.Log;
  2. using Aitex.Sorter.Common;
  3. using Caliburn.Micro;
  4. using Caliburn.Micro.Core;
  5. using MECF.Framework.Common.CommonData;
  6. using MECF.Framework.Common.CommonData.EnumData;
  7. using MECF.Framework.Common.DataCenter;
  8. using MECF.Framework.Common.Utilities;
  9. using MECF.Framework.UI.Client.CenterViews.DataLogs.Event;
  10. using MECF.Framework.UI.Client.ClientBase;
  11. using OpenSEMI.ClientBase;
  12. using OpenSEMI.ClientBase.Command;
  13. using SciChart.Charting.Common.Extensions;
  14. using SciChart.Core.Extensions;
  15. using System;
  16. using System.Collections.Generic;
  17. using System.Collections.ObjectModel;
  18. using System.ComponentModel;
  19. using System.Data;
  20. using System.Diagnostics.Eventing.Reader;
  21. using System.Linq;
  22. using System.Windows.Forms;
  23. using System.Windows.Input;
  24. namespace MECF.Framework.UI.Client.CenterViews.DataLogs.ProcessHistory
  25. {
  26. public class ProcessHistoryTwoViewModel : UiViewModelBase
  27. {
  28. public ProcessHistoryTwoViewModel()
  29. {
  30. QueryCommand = new BaseCommand<object>(QueryLots);
  31. BatchDetailCommand = new BaseCommand<object>(BatchDetail);
  32. ProcessDetailCommand = new BaseCommand<object>(ProcessDetail);
  33. ProcessExportCommand = new BaseCommand<object>(ProcessExport);
  34. ExportProcessTableCommand = new BaseCommand<object>(ExportProcessTable);
  35. ProcessJobInfoCommand = new BaseCommand<object>(ProcessJobInfo);
  36. // DisplayGraphCommand = new BaseCommand<object>(DisplayGraph);
  37. InitTime();
  38. }
  39. public ObservableCollection<ProcessHistoryLot> ProcessHistoryLots { get; set; } = new ObservableCollection<ProcessHistoryLot>();
  40. private int _processHistoryLotSelectIndex;
  41. public int ProcessHistoryLotSelectIndex
  42. {
  43. get => _processHistoryLotSelectIndex;
  44. set
  45. {
  46. _processHistoryLotSelectIndex = value;
  47. NotifyOfPropertyChange(nameof(ProcessHistoryLotSelectIndex));
  48. }
  49. }
  50. private DateTime _searchBeginTime;
  51. public DateTime SearchBeginTime
  52. {
  53. get { return _searchBeginTime; }
  54. set
  55. {
  56. _searchBeginTime = value;
  57. NotifyOfPropertyChange("SearchBeginTime");
  58. }
  59. }
  60. private DateTime _searchEndTime;
  61. public DateTime SearchEndTime
  62. {
  63. get { return _searchEndTime; }
  64. set
  65. {
  66. _searchEndTime = value;
  67. NotifyOfPropertyChange("SearchEndTime");
  68. }
  69. }
  70. private string keyWord;
  71. public string KeyWord
  72. {
  73. get { return keyWord; }
  74. set
  75. {
  76. keyWord = value;
  77. NotifyOfPropertyChange("KeyWord");
  78. }
  79. }
  80. private ProcessHistoryTwoView view;
  81. public ICommand QueryCommand { get; set; }
  82. public ICommand BatchDetailCommand { get; set; }
  83. public ICommand ProcessDetailCommand { get; set; }
  84. public ICommand ProcessExportCommand { get; set; }
  85. public ICommand ExportProcessTableCommand { get; set; }
  86. public ICommand ProcessJobInfoCommand { get; set; }
  87. // public ICommand DisplayGraphCommand { get; set; }
  88. protected override void OnViewLoaded(object _view)
  89. {
  90. base.OnViewLoaded(_view);
  91. this.view = (ProcessHistoryTwoView)_view;
  92. this.view.wfTimeFrom.Content = this.SearchBeginTime;
  93. this.view.wfTimeTo.Content = this.SearchEndTime;
  94. QueryLots(new object());
  95. if (ProcessHistoryLots != null && ProcessHistoryLots.FirstOrDefault() != null)
  96. {
  97. ProcessHistoryLots.FirstOrDefault().IsChecked = true;
  98. }
  99. }
  100. void InitTime()
  101. {
  102. SearchBeginTime = DateTime.Now.Date;
  103. SearchEndTime = DateTime.Now.Date.AddDays(1).Date;
  104. }
  105. void QueryLots(object e)
  106. {
  107. this.SearchBeginTime = Convert.ToDateTime(this.view.wfTimeFrom.Content);
  108. this.SearchEndTime = Convert.ToDateTime(this.view.wfTimeTo.Content);
  109. if (SearchBeginTime > SearchEndTime)
  110. {
  111. MessageBox.Show("Time range invalid, start time should be early than end time");
  112. return;
  113. }
  114. ProcessHistoryLots.Clear();
  115. QueryLot(SearchBeginTime, SearchEndTime, KeyWord);//.OrderByDescending(lot => lot.StartTime).ToArray();
  116. }
  117. void BatchDetail(object o)
  118. {
  119. if (ProcessHistoryLotSelectIndex != -1 && ProcessHistoryLots.Count > 0)
  120. {
  121. DateTime startTime = ProcessHistoryLots[ProcessHistoryLotSelectIndex].StartTime;
  122. DateTime endTime = ProcessHistoryLots[ProcessHistoryLotSelectIndex].EndTime;
  123. var batchID = ProcessHistoryLots[ProcessHistoryLotSelectIndex].BatchID;
  124. List<string> layoutData = ProcessHistoryLots[ProcessHistoryLotSelectIndex].LayoutData.Split(',').ToList();
  125. List<string> waferData = ProcessHistoryLots[ProcessHistoryLotSelectIndex].WaferData.Split(',').ToList();
  126. var windowManager = IoC.Get<IWindowManager>();
  127. BatchDetailViewModel batchDetailViewModel = new BatchDetailViewModel(startTime, endTime, batchID, layoutData, layoutData.Count, waferData);
  128. (windowManager as WindowManager)?.ShowDialogWithTitle(batchDetailViewModel, null, "Batch Detail");
  129. }
  130. else
  131. {
  132. var windowManager = IoC.Get<IWindowManager>();
  133. BatchDetailViewModel batchDetailViewModel = new BatchDetailViewModel();
  134. (windowManager as WindowManager)?.ShowDialogWithTitle(batchDetailViewModel, null, "Batch Detail");
  135. }
  136. }
  137. public void SelectDate(string SelectType)
  138. {
  139. var windowManager = Caliburn.Micro.Core.IoC.Get<Caliburn.Micro.IWindowManager>();
  140. if (SelectType == "Start")
  141. {
  142. this.SearchBeginTime = Convert.ToDateTime(this.view.wfTimeFrom.Content);
  143. SelectDateViewModel selectdateViewModel = new SelectDateViewModel(SearchBeginTime);
  144. var result = (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(selectdateViewModel, null, "Start Time");
  145. if (result == true)
  146. {
  147. this.view.wfTimeFrom.Content = selectdateViewModel.SearchDate;
  148. }
  149. }
  150. else
  151. {
  152. this.SearchEndTime = Convert.ToDateTime(this.view.wfTimeTo.Content);
  153. SelectDateViewModel selectdateViewModel = new SelectDateViewModel(SearchEndTime);
  154. var result = (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(selectdateViewModel, null, "End Time");
  155. if (result == true)
  156. {
  157. this.view.wfTimeTo.Content = selectdateViewModel.SearchDate;
  158. }
  159. }
  160. }
  161. void ProcessDetail(object o)
  162. {
  163. //if (ProcessHistoryLots.Count > 0)
  164. //{
  165. var windowManager = IoC.Get<IWindowManager>();
  166. var param = ProcessHistoryLots.Where(x => x.IsChecked).ToList();
  167. object processDetailViewModel = new ProcessDetailViewModel<double>(param);
  168. (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(processDetailViewModel, null, "Process Detail");
  169. //}
  170. }
  171. void ProcessJobInfo(object o)
  172. {
  173. var windowManager = IoC.Get<IWindowManager>();
  174. var param = ProcessHistoryLots.Where(x => x.IsChecked).FirstOrDefault();
  175. ProcessDetailV2ViewModel processDetailViewModel = new ProcessDetailV2ViewModel();
  176. processDetailViewModel.PJInfo = param;
  177. processDetailViewModel.TableCount = ProcessHistoryLots.Count;
  178. processDetailViewModel.SelectItemIndex = ProcessHistoryLots.IndexOf(param) + 1;
  179. (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(processDetailViewModel, null, "ProcessJob Info");
  180. }
  181. void ExportProcessTable(object o)
  182. {
  183. try
  184. {
  185. if (ProcessHistoryLots == null || ProcessHistoryLots.Count == 0)
  186. {
  187. MessageBox.Show($"Table is null");
  188. }
  189. Microsoft.Win32.SaveFileDialog dlg = new Microsoft.Win32.SaveFileDialog();
  190. dlg.DefaultExt = ".xlsx"; // Default file extension
  191. dlg.FileName = $"Process_{SearchBeginTime.ToString("yyyy_MM_dd_HH_mm_ss")}~{SearchEndTime.ToString("yyyy_MM_dd_HH_mm_ss")}";
  192. dlg.Filter = "Excel数据表格文件(*.xlsx)|*.xlsx"; // Filter files by extension
  193. Nullable<bool> result = dlg.ShowDialog();// Show open file dialog box
  194. if (result == true) // Process open file dialog box results
  195. {
  196. System.Data.DataSet ds = new System.Data.DataSet();
  197. SaveStepsToTable(ds);
  198. if (!ExcelHelper.ExportToExcel(dlg.FileName, ds, out string reason, true, false))
  199. {
  200. MessageBox.Show($"Export failed, {reason}");
  201. return;
  202. }
  203. MessageBox.Show($"Export succeed, file save as {dlg.FileName}");
  204. }
  205. }
  206. catch (Exception ex)
  207. {
  208. LOG.Write(ex);
  209. MessageBox.Show("导出 Process Table发生错误", "导出失败");
  210. }
  211. }
  212. private void SaveStepsToTable(System.Data.DataSet ds)
  213. {
  214. ds.Tables.Add(new System.Data.DataTable("Process"));
  215. ds.Tables[0].Columns.Add("StartTime");
  216. ds.Tables[0].Columns.Add("EndTime");
  217. ds.Tables[0].Columns.Add("BatchId");
  218. ds.Tables[0].Columns.Add("JobName");
  219. ds.Tables[0].Columns.Add("RecipeName");
  220. ds.Tables[0].Columns.Add("LayoutName");
  221. ds.Tables[0].Columns.Add("Form");
  222. ds.Tables[0].Columns.Add("Wafer");
  223. foreach (var item in ProcessHistoryLots)
  224. {
  225. var row = ds.Tables[0].NewRow();
  226. row["BatchId"] = item.BatchID + " ";
  227. row["JobName"] = item.JobName;
  228. row["RecipeName"] = item.RecipeName;
  229. row["Form"] = item.Form;
  230. row["StartTime"] = item.StartTime;
  231. row["EndTime"] = item.EndTime;
  232. row["Wafer"] = item.WaferCount;
  233. row["LayoutName"] = item.LayoutName;
  234. ds.Tables[0].Rows.Add(row);
  235. }
  236. }
  237. public void SelectChangedHandle(object obj)
  238. {
  239. if (obj != null && obj is ProcessHistoryLot)
  240. {
  241. var item = obj as ProcessHistoryLot;
  242. item.IsChecked = true;
  243. }
  244. }
  245. void ProcessExport(object o)
  246. {
  247. var windowManager = IoC.Get<IWindowManager>();
  248. var param = ProcessHistoryLots.Where(x => x.IsChecked).ToList();
  249. object processExportViewModel = new ProcessExportAllViewModel<double>(param);
  250. (windowManager as Caliburn.Micro.WindowManager)?.ShowDialogWithTitle(processExportViewModel, null, "Process Export");
  251. }
  252. //void DisplayGraph(object o)
  253. //{
  254. // ClientApp.Instance.SwitchPage("DataLog", "DataHistory", null);
  255. //}
  256. public void QueryLot(DateTime from, DateTime to, string key)
  257. {
  258. string sql = $"SELECT * FROM \"pj_data\" where \"start_time\" >= '{from:yyyy/MM/dd HH:mm:ss.fff}' and \"start_time\" <= '{to:yyyy/MM/dd HH:mm:ss.fff}' order by \"start_time\" DESC;";
  259. if (!string.IsNullOrWhiteSpace(key)) sql += string.Format(" and lower(\"batch_id\")='{0}' ", key.ToLower());
  260. DataTable dbData = QueryDataClient.Instance.Service.QueryData(sql);
  261. if (dbData != null && dbData.Rows.Count > 0)
  262. {
  263. for (int i = 0; i < dbData.Rows.Count; i++)
  264. {
  265. ProcessHistoryLot item = new ProcessHistoryLot();
  266. item.PjId = dbData.Rows[i]["guid"].ToString();
  267. item.BatchID = dbData.Rows[i]["batch_id"].ToString();
  268. item.JobName = dbData.Rows[i]["job_name"].ToString();
  269. item.RecipeName = dbData.Rows[i]["recipe_name"].ToString();
  270. item.LayoutName = dbData.Rows[i]["layout_name"].ToString();
  271. item.LayoutData = dbData.Rows[i]["layout_data"].ToString();
  272. item.WaferData = dbData.Rows[i]["wafer_data"].ToString();
  273. item.Form = dbData.Rows[i]["form"].ToString();
  274. if (!dbData.Rows[i]["total_wafer_count"].Equals(DBNull.Value))
  275. {
  276. item.WaferCount = (int)dbData.Rows[i]["total_wafer_count"];
  277. }
  278. if (!dbData.Rows[i]["start_time"].Equals(DBNull.Value))
  279. {
  280. item.StartTime = (DateTime)dbData.Rows[i]["start_time"];
  281. }
  282. if (!dbData.Rows[i]["end_time"].Equals(DBNull.Value))
  283. {
  284. item.EndTime = (DateTime)dbData.Rows[i]["end_time"];
  285. }
  286. ProcessHistoryLots.Add(item);
  287. }
  288. }
  289. }
  290. }
  291. public class ProcessHistoryLot : NotifiableItem
  292. {
  293. private bool _IsChecked;
  294. public bool IsChecked
  295. {
  296. get => _IsChecked;
  297. set
  298. {
  299. _IsChecked = value;
  300. InvokePropertyChanged(nameof(IsChecked));
  301. }
  302. }
  303. private string _pjId;
  304. public string PjId
  305. {
  306. get => _pjId;
  307. set
  308. {
  309. _pjId = value;
  310. InvokePropertyChanged(nameof(PjId));
  311. }
  312. }
  313. private string _batchID;
  314. public string BatchID
  315. {
  316. get => _batchID;
  317. set
  318. {
  319. _batchID = value;
  320. InvokePropertyChanged(nameof(BatchID));
  321. }
  322. }
  323. private string _jobName;
  324. public string JobName
  325. {
  326. get => _jobName;
  327. set
  328. {
  329. _jobName = value;
  330. InvokePropertyChanged(nameof(JobName));
  331. }
  332. }
  333. private string _recipeName;
  334. public string RecipeName
  335. {
  336. get => _recipeName;
  337. set
  338. {
  339. _recipeName = value;
  340. InvokePropertyChanged(nameof(RecipeName));
  341. }
  342. }
  343. private string _layoutName;
  344. public string LayoutName
  345. {
  346. get => _layoutName;
  347. set
  348. {
  349. _layoutName = value;
  350. InvokePropertyChanged(nameof(LayoutName));
  351. }
  352. }
  353. private string _layoutData;
  354. public string LayoutData
  355. {
  356. get => _layoutData;
  357. set
  358. {
  359. _layoutData = value;
  360. InvokePropertyChanged(nameof(LayoutData));
  361. }
  362. }
  363. private string _waferData;
  364. public string WaferData
  365. {
  366. get => _waferData;
  367. set
  368. {
  369. _waferData = value;
  370. InvokePropertyChanged(nameof(WaferData));
  371. }
  372. }
  373. private string _form;
  374. public string Form
  375. {
  376. get => _form;
  377. set
  378. {
  379. _form = value;
  380. InvokePropertyChanged(nameof(Form));
  381. }
  382. }
  383. private DateTime _startTime;
  384. public DateTime StartTime
  385. {
  386. get => _startTime;
  387. set
  388. {
  389. _startTime = value;
  390. InvokePropertyChanged(nameof(StartTime));
  391. }
  392. }
  393. private DateTime _endTime;
  394. public DateTime EndTime
  395. {
  396. get => _endTime;
  397. set
  398. {
  399. _endTime = value;
  400. InvokePropertyChanged(nameof(EndTime));
  401. }
  402. }
  403. private int _waferCount;
  404. public int WaferCount
  405. {
  406. get => _waferCount;
  407. set
  408. {
  409. _waferCount = value;
  410. InvokePropertyChanged(nameof(WaferCount));
  411. }
  412. }
  413. public DateTime ProcessStartTime { get; set; }
  414. public DateTime ProcessEndTime { get; set; }
  415. public RecipeTypeEnum RecipeType { get; set; }
  416. public RecipeExecEntryEnum RecipeExecEntry { get; set; }
  417. }
  418. }