WaferHolderViewModel.cs 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924
  1. using Aitex.Core.Common;
  2. using Aitex.Core.RT.DataCenter;
  3. using Aitex.Core.RT.Routine;
  4. using Aitex.Core.UI.MVVM;
  5. using Aitex.Core.Utilities;
  6. using MECF.Framework.Common.CommonData;
  7. using MECF.Framework.Common.DataCenter;
  8. using MECF.Framework.Common.DBCore;
  9. using MECF.Framework.Common.Equipment;
  10. using MECF.Framework.Common.OperationCenter;
  11. using MECF.Framework.Common.SubstrateTrackings;
  12. using MECF.Framework.Common.WaferHolder;
  13. using OpenSEMI.ClientBase;
  14. using CyberX8_MainPages.Model;
  15. using Prism.Common;
  16. using Prism.Mvvm;
  17. using System;
  18. using System.Collections.Generic;
  19. using System.Collections.ObjectModel;
  20. using System.Linq;
  21. using System.Text;
  22. using System.Threading.Tasks;
  23. using System.Windows;
  24. using System.Windows.Input;
  25. using Unity;
  26. using WPF.Themes.UserControls;
  27. using MECF.Framework.Common.Layout;
  28. using MECF.Framework.Common.Utilities;
  29. using Aitex.Core.UI.ControlDataContext;
  30. using System.Reflection;
  31. using System.Windows.Threading;
  32. using Aitex.Core.Util;
  33. using Aitex.Core.RT.Log;
  34. namespace CyberX8_MainPages.ViewModels
  35. {
  36. public class WaferHolderViewModel : BindableBase
  37. {
  38. #region 局部变量
  39. /// <summary>
  40. /// buffer数据
  41. /// </summary>
  42. private ObservableCollection<WaferHolderBufferData> _bufferDatas = null;
  43. /// <summary>
  44. /// 未使用的载具
  45. /// </summary>
  46. private ObservableCollection<WaferHolderInfo> _unusedWaferHoders = null;
  47. /// <summary>
  48. /// 选择数据
  49. /// </summary>
  50. private WaferHolderBufferData _selectedBufferData = null;
  51. /// <summary>
  52. /// 选择未使用数据
  53. /// </summary>
  54. private WaferHolderInfo _selectedUnusedWaferHolderInfo = null;
  55. /// <summary>
  56. /// csr 类型集合
  57. /// </summary>
  58. private List<string> _crsTypeLst = null;
  59. /// <summary>
  60. /// Wafer尺寸集合
  61. /// </summary>
  62. private List<string> _waferSizeLst = null;
  63. /// <summary>
  64. /// 临时数据
  65. /// </summary>
  66. private WaferHolderBufferData _tmpWaferHolderBufferData = null;
  67. /// <summary>
  68. /// 化学液集合
  69. /// </summary>
  70. private List<string> _chemistryLst = null;
  71. /// <summary>
  72. /// Location位置集合
  73. /// </summary>
  74. private List<string> _locationLst = new List<string>();
  75. /// <summary>
  76. /// Reservoir集合
  77. /// </summary>
  78. private List<string> _reservoirLst = new List<string>();
  79. /// <summary>
  80. /// 是否编辑
  81. /// </summary>
  82. private bool _isEdit = false;
  83. /// <summary>
  84. /// 是否编辑Current Location
  85. /// </summary>
  86. private bool _isLocationEdit = false;
  87. /// <summary>
  88. /// 是否启用SaveandCancel按钮
  89. /// </summary>
  90. private bool _isSaveandCancelEdit = false;
  91. /// <summary>
  92. /// 操作
  93. /// </summary>
  94. /// <summary>
  95. /// 操作
  96. /// </summary>
  97. private string operation = "";
  98. /// <summary>
  99. /// 是否编辑载具Id
  100. /// </summary>
  101. private bool _isEditWaferHolderId = false;
  102. /// <summary>
  103. /// 定时器
  104. /// </summary>
  105. DispatcherTimer _timer;
  106. /// <summary>
  107. /// 查询后台数据集合
  108. /// </summary>
  109. private List<string> _rtDataKeys = new List<string>();
  110. /// <summary>
  111. /// rt查询key数值字典
  112. /// </summary>
  113. private Dictionary<string, object> _rtDataValueDic = new Dictionary<string, object>();
  114. /// <summary>
  115. /// ProcessTransporter是否Busy
  116. /// </summary>
  117. private bool _isProcessTransBusy;
  118. /// <summary>
  119. /// LoaderTransporter是否Busy
  120. /// </summary>
  121. private bool _isLoaderTransBusy;
  122. /// <summary>
  123. /// 是否在Auto模式下
  124. /// </summary>
  125. private bool _isAutoMode;
  126. #endregion
  127. #region 属性
  128. public List<string> CrsTypeLst
  129. {
  130. get { return _crsTypeLst; }
  131. set { SetProperty(ref _crsTypeLst, value); }
  132. }
  133. public List<string> WaferSizeLst
  134. {
  135. get { return _waferSizeLst; }
  136. set { SetProperty(ref _waferSizeLst, value); }
  137. }
  138. public List<string> ChemistryLst
  139. {
  140. get { return _chemistryLst; }
  141. set { SetProperty(ref _chemistryLst, value); }
  142. }
  143. /// <summary>
  144. /// Location位置集合
  145. /// </summary>
  146. public List<string> LocationLst
  147. {
  148. get { return _locationLst; }
  149. set { SetProperty(ref _locationLst, value); }
  150. }
  151. public ObservableCollection<WaferHolderBufferData> BufferDatas
  152. {
  153. get { return _bufferDatas; }
  154. set
  155. {
  156. SetProperty(ref _bufferDatas, value);
  157. }
  158. }
  159. /// <summary>
  160. /// 未使用载具
  161. /// </summary>
  162. public ObservableCollection<WaferHolderInfo> UnusedWaferHolders
  163. {
  164. get { return _unusedWaferHoders; }
  165. set
  166. {
  167. SetProperty(ref _unusedWaferHoders, value);
  168. }
  169. }
  170. /// <summary数据>
  171. /// 选择
  172. /// </summary>
  173. public WaferHolderBufferData SelectedBufferData
  174. {
  175. get { return _selectedBufferData; }
  176. set
  177. {
  178. if(_selectedBufferData==null||(value!=null&&value.Id!=_selectedBufferData.Id))
  179. {
  180. BufferDataSelectedChanged(value);
  181. }
  182. SetProperty(ref _selectedBufferData, value);
  183. }
  184. }
  185. /// <summary数据>
  186. /// 选择未使用的载具
  187. /// </summary>
  188. public WaferHolderInfo SelectedUnusedWaferHolderInfo
  189. {
  190. get { return _selectedUnusedWaferHolderInfo; }
  191. set
  192. {
  193. SetProperty(ref _selectedUnusedWaferHolderInfo, value);
  194. }
  195. }
  196. /// <summary>
  197. /// 临时数据
  198. /// </summary>
  199. public WaferHolderBufferData TmpBufferData
  200. {
  201. get { return _tmpWaferHolderBufferData; }
  202. set { SetProperty(ref _tmpWaferHolderBufferData, value); }
  203. }
  204. /// <summary>
  205. /// 是否编辑
  206. /// </summary>
  207. public bool IsEdit
  208. {
  209. get { return _isEdit; }
  210. set
  211. {
  212. if(!value)
  213. {
  214. IsEditWaferHolderId = false;
  215. }
  216. SetProperty(ref _isEdit, value);
  217. }
  218. }
  219. /// <summary>
  220. /// 是否编辑Current Location
  221. /// </summary>
  222. public bool IsLocationEdit
  223. {
  224. get { return _isLocationEdit; }
  225. set
  226. {
  227. SetProperty(ref _isLocationEdit, value);
  228. }
  229. }
  230. /// <summary>
  231. /// 是否启用Save和Cancel
  232. /// </summary>
  233. public bool IsSaveandCancelEdit
  234. {
  235. get { return _isSaveandCancelEdit; }
  236. set
  237. {
  238. SetProperty(ref _isSaveandCancelEdit, value);
  239. }
  240. }
  241. /// <summary>
  242. /// 是否编辑载具Id
  243. /// </summary>
  244. public bool IsEditWaferHolderId
  245. {
  246. get { return _isEditWaferHolderId; }
  247. set { SetProperty(ref _isEditWaferHolderId, value); }
  248. }
  249. #endregion
  250. #region 按钮事件
  251. [IgnorePropertyChange]
  252. public ICommand EnableCommand
  253. {
  254. get;
  255. private set;
  256. }
  257. [IgnorePropertyChange]
  258. public ICommand DisableCommand
  259. {
  260. get;
  261. private set;
  262. }
  263. /// <summary>
  264. /// 增加
  265. /// </summary>
  266. public ICommand AddCommand
  267. { get; private set; }
  268. /// <summary>
  269. /// 编辑
  270. /// </summary>
  271. public ICommand EditCommand
  272. { get; private set; }
  273. /// <summary>
  274. /// 保存
  275. /// </summary>
  276. public ICommand SaveCommand { get; private set; }
  277. /// <summary>
  278. /// 取消
  279. /// </summary>
  280. public ICommand CancelCommand { get; private set; }
  281. /// <summary>
  282. /// 移至Loader
  283. /// </summary>
  284. public ICommand MoveToLoaderCommand { get; private set; }
  285. /// <summary>
  286. /// 移出Loader
  287. /// </summary>
  288. public ICommand MoveFromLoaderCommand { get; private set; }
  289. /// <summary>
  290. /// 移除
  291. /// </summary>
  292. public ICommand RemoveCommand { get; private set; }
  293. /// <summary>
  294. /// MoveLocation
  295. /// </summary>
  296. public ICommand MoveLocationCommand { get; private set; }
  297. #endregion
  298. /// <summary>
  299. /// 构造函数
  300. /// </summary>
  301. public WaferHolderViewModel()
  302. {
  303. EnableCommand = new DelegateCommand<object>(EnableAction);
  304. DisableCommand=new DelegateCommand<object>(DisableAction);
  305. AddCommand=new DelegateCommand<object>(AddAction);
  306. EditCommand = new DelegateCommand<object>(EditAction);
  307. SaveCommand=new DelegateCommand<object>(SaveAction);
  308. CancelCommand=new DelegateCommand<object>(CancelAction);
  309. MoveToLoaderCommand = new DelegateCommand<object>(MoveToLoaderAction);
  310. MoveFromLoaderCommand = new DelegateCommand<object>(MoveFromLoaderAction);
  311. RemoveCommand = new DelegateCommand<object>(RemoveAction);
  312. MoveLocationCommand = new DelegateCommand<object>(MoveLocationAction);
  313. //Wafer尺寸集合
  314. WaferSizeLst = new List<string>();
  315. WaferSizeLst.Add("100");
  316. WaferSizeLst.Add("150");
  317. WaferSizeLst.Add("200");
  318. //化学液集合
  319. string chemistryContent = QueryDataClient.Instance.Service.GetConfig($"System.ChemistryList").ToString();
  320. if (!string.IsNullOrEmpty(chemistryContent))
  321. {
  322. ChemistryLst = chemistryContent.Split(',').ToList();
  323. }
  324. //CrsType集合
  325. string crstypeContent = QueryDataClient.Instance.Service.GetConfig($"System.LSType").ToString();
  326. if(!string.IsNullOrEmpty(crstypeContent))
  327. {
  328. _crsTypeLst = crstypeContent.Split(',').ToList();
  329. }
  330. //Location集合
  331. List<string> _rtDataKeys = new List<string>();
  332. _rtDataKeys.Add("System.LayoutCellItems");
  333. var _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  334. if (_rtDataValueDic != null)
  335. {
  336. //获取ProcessCell列表
  337. LocationLst= CommonFunction.GetValue<List<string>>(_rtDataValueDic, "System.LayoutCellItems");
  338. }
  339. }
  340. /// <summary>
  341. /// 加载数据
  342. /// </summary>
  343. public void LoadData(string systemName)
  344. {
  345. if (_timer == null)
  346. {
  347. _timer = new DispatcherTimer();
  348. _timer.Interval = TimeSpan.FromMilliseconds(200);
  349. _timer.Tick += Timer_Tick;
  350. }
  351. _timer.Start();
  352. _rtDataKeys.Clear();
  353. _rtDataKeys.Add($"Transporter1.IsBusy");
  354. _rtDataKeys.Add($"Transporter2.IsBusy");
  355. _rtDataKeys.Add("System.IsAutoMode");
  356. }
  357. /// <summary>
  358. /// 定时器执行
  359. /// </summary>
  360. /// <param name="sender"></param>
  361. /// <param name="e"></param>
  362. private void Timer_Tick(object sender, EventArgs e)
  363. {
  364. if (_rtDataKeys.Count != 0)
  365. {
  366. _rtDataValueDic = QueryDataClient.Instance.Service.PollData(_rtDataKeys);
  367. if (_rtDataValueDic != null)
  368. {
  369. _isProcessTransBusy = CommonFunction.GetValue<bool>(_rtDataValueDic, $"Transporter1.IsBusy");
  370. _isLoaderTransBusy = CommonFunction.GetValue<bool>(_rtDataValueDic, $"Transporter2.IsBusy");
  371. _isAutoMode = CommonFunction.GetValue<bool>(_rtDataValueDic, $"System.IsAutoMode");
  372. }
  373. }
  374. }
  375. /// <summary>
  376. /// 加载载具数据
  377. /// </summary>
  378. public void LoadWaferHolderDatas()
  379. {
  380. BufferDatas = new ObservableCollection<WaferHolderBufferData>();
  381. for (int i = 1; i <= 16; i++)
  382. {
  383. BufferDatas.Add(new WaferHolderBufferData() { Id = i });
  384. }
  385. List<WaferHolderInfo> waferHolderInfos = WaferHolderDataClient.Instance.Service.GetAllWaferHolderDatas();
  386. UpdateWaferHolderBufferDatas(waferHolderInfos);
  387. GetUnusedWaferHolderData(waferHolderInfos);
  388. IsEdit = false;
  389. IsSaveandCancelEdit = false;
  390. IsLocationEdit = false;
  391. }
  392. /// <summary>
  393. /// 更新buffer数据
  394. /// </summary>
  395. /// <param name="waferHolderInfos"></param>
  396. private void UpdateWaferHolderBufferDatas(List<WaferHolderInfo> waferHolderInfos)
  397. {
  398. for (int i=0;i< BufferDatas.Count;i++)
  399. {
  400. WaferHolderInfo holderInfo= waferHolderInfos.Find(O => O.BufferId == BufferDatas[i].Id && !string.IsNullOrEmpty(O.CurrentLocation));
  401. if(holderInfo != null)
  402. {
  403. SwitchWaferInfoToWaferHolderBufferData(holderInfo, BufferDatas[i]);
  404. }
  405. }
  406. }
  407. /// <summary>
  408. /// 获取未使用载具数据
  409. /// </summary>
  410. /// <param name="waferHolderInfos"></param>
  411. private void GetUnusedWaferHolderData(List<WaferHolderInfo> waferHolderInfos)
  412. {
  413. UnusedWaferHolders = new ObservableCollection<WaferHolderInfo>();
  414. UnusedWaferHolders.AddRange(waferHolderInfos.FindAll(O => string.IsNullOrEmpty(O.CurrentLocation)));
  415. }
  416. /// <summary>
  417. /// 检验选择
  418. /// </summary>
  419. /// <returns></returns>
  420. private bool CheckSelection()
  421. {
  422. if (_selectedBufferData == null)
  423. {
  424. MessageBox.Show("please select one data", "Check", MessageBoxButton.OK, MessageBoxImage.Error);
  425. return false;
  426. }
  427. if (string.IsNullOrEmpty(SelectedBufferData.WaferHolderId))
  428. {
  429. MessageBox.Show("empty data", "Check", MessageBoxButton.OK, MessageBoxImage.Error);
  430. return false;
  431. }
  432. return true;
  433. }
  434. /// <summary>
  435. /// 启用事件
  436. /// </summary>
  437. /// <param name="param"></param>
  438. private void EnableAction(object param)
  439. {
  440. if(!CheckSelection())
  441. {
  442. return;
  443. }
  444. int result= WaferHolderDataClient.Instance.Service.UpdateWaferHolderEnable(SelectedBufferData.WaferHolderId, true);
  445. if(result!=0)
  446. {
  447. SelectedBufferData.Enabled = "True";
  448. }
  449. }
  450. /// <summary>
  451. /// 启用事件
  452. /// </summary>
  453. /// <param name="param"></param>
  454. private void DisableAction(object param)
  455. {
  456. if (!CheckSelection())
  457. {
  458. return;
  459. }
  460. int result= WaferHolderDataClient.Instance.Service.UpdateWaferHolderEnable(SelectedBufferData.WaferHolderId, false);
  461. if(result!=0)
  462. {
  463. SelectedBufferData.Enabled = "False";
  464. }
  465. }
  466. /// <summary>
  467. /// 新增
  468. /// </summary>
  469. /// <param name="param"></param>
  470. private void AddAction(object param)
  471. {
  472. if (_selectedBufferData == null)
  473. {
  474. MessageBox.Show("please select one data", "Add", MessageBoxButton.OK, MessageBoxImage.Error);
  475. return;
  476. }
  477. if (!string.IsNullOrEmpty(SelectedBufferData.WaferHolderId))
  478. {
  479. MessageBox.Show("data exist,can not add operation", "Add", MessageBoxButton.OK, MessageBoxImage.Error);
  480. return;
  481. }
  482. IsEditWaferHolderId = true;
  483. operation = "Add";
  484. InitialWaferHolderBuffer();
  485. IsEdit = true;
  486. IsSaveandCancelEdit = true;
  487. }
  488. /// <summary>
  489. /// 初始数据
  490. /// </summary>
  491. private void InitialWaferHolderBuffer()
  492. {
  493. if(SelectedBufferData==null)
  494. {
  495. return;
  496. }
  497. TmpBufferData = new WaferHolderBufferData();
  498. TmpBufferData.Enabled = "True";
  499. TmpBufferData.Id = SelectedBufferData.Id;
  500. TmpBufferData.CrsATotalUses = "0";
  501. TmpBufferData.CrsAUsesSincePadClean = "0";
  502. TmpBufferData.CrsAUsesSinceSealClean = "0";
  503. TmpBufferData.CrsBTotalUses = "0";
  504. TmpBufferData.CrsBUsesSincePadClean = "0";
  505. TmpBufferData.CrsBUsesSinceSealClean = "0";
  506. TmpBufferData.TotalDummyWafers = "0";
  507. TmpBufferData.TotalProductWafers = "0";
  508. TmpBufferData.TotalUses = "0";
  509. }
  510. /// <summary>
  511. /// 编辑
  512. /// </summary>
  513. /// <param name="param"></param>
  514. private void EditAction(object param)
  515. {
  516. if (!CheckSelection())
  517. {
  518. return;
  519. }
  520. if(string.IsNullOrEmpty(SelectedBufferData.WaferHolderId))
  521. {
  522. MessageBox.Show("empty data","Edit",MessageBoxButton.OK,MessageBoxImage.Error);
  523. return;
  524. }
  525. operation= "edit";
  526. IsEdit = true;
  527. IsSaveandCancelEdit = true;
  528. }
  529. /// <summary>
  530. /// 检验
  531. /// </summary>
  532. /// <returns></returns>
  533. private bool Validation(out string reason)
  534. {
  535. reason = "";
  536. if (string.IsNullOrEmpty(TmpBufferData.WaferHolderId))
  537. {
  538. reason = "WS Id is Empty";
  539. return false;
  540. }
  541. if(string.IsNullOrEmpty(TmpBufferData.CrsType))
  542. {
  543. reason = "LS Type is Empty";
  544. return false;
  545. }
  546. if (string.IsNullOrEmpty(TmpBufferData.WaferSize))
  547. {
  548. reason = "Wafer Size is empty";
  549. return false;
  550. }
  551. if (string.IsNullOrEmpty(TmpBufferData.CrsAId))
  552. {
  553. reason = "LS-A Id is empty";
  554. return false;
  555. }
  556. if (string.IsNullOrEmpty(TmpBufferData.CrsBId))
  557. {
  558. reason = "LS-B Id is empty";
  559. return false;
  560. }
  561. if (TmpBufferData.CrsAId == TmpBufferData.CrsBId)
  562. {
  563. reason = "The LS Id of A and B can not be the same";
  564. return false;
  565. }
  566. if (string.IsNullOrEmpty(TmpBufferData.Chemistry))
  567. {
  568. reason = "Chemistry is empty";
  569. return false;
  570. }
  571. for (int i = 0; i < BufferDatas.Count; i++)
  572. {
  573. if ( BufferDatas[i].Id != TmpBufferData.Id && (TmpBufferData.CrsAId == BufferDatas[i].CrsAId || TmpBufferData.CrsAId == BufferDatas[i].CrsBId))
  574. {
  575. reason = "LS-A Id is already exist";
  576. return false;
  577. }
  578. if ( BufferDatas[i].Id != TmpBufferData.Id && (TmpBufferData.CrsBId == BufferDatas[i].CrsBId || TmpBufferData.CrsBId == BufferDatas[i].CrsAId) )
  579. {
  580. reason = "LS-B Id is already exist";
  581. return false;
  582. }
  583. }
  584. TmpBufferData.TotalDummyWafers = string.IsNullOrEmpty(TmpBufferData.TotalDummyWafers) ? "0" : TmpBufferData.TotalDummyWafers;
  585. TmpBufferData.TotalUses = string.IsNullOrEmpty(TmpBufferData.TotalUses) ? "0" : TmpBufferData.TotalUses;
  586. TmpBufferData.TotalProductWafers = string.IsNullOrEmpty(TmpBufferData.TotalProductWafers) ? "0" : TmpBufferData.TotalProductWafers;
  587. TmpBufferData.CrsATotalUses = string.IsNullOrEmpty(TmpBufferData.CrsATotalUses) ? "0" : TmpBufferData.CrsATotalUses;
  588. TmpBufferData.CrsAUsesSincePadClean = string.IsNullOrEmpty(TmpBufferData.CrsAUsesSincePadClean) ? "0" : TmpBufferData.CrsAUsesSincePadClean;
  589. TmpBufferData.CrsAUsesSinceSealClean = string.IsNullOrEmpty(TmpBufferData.CrsAUsesSinceSealClean) ? "0" : TmpBufferData.CrsAUsesSinceSealClean;
  590. TmpBufferData.CrsBTotalUses = string.IsNullOrEmpty(TmpBufferData.CrsBTotalUses) ? "0" : TmpBufferData.CrsBTotalUses;
  591. TmpBufferData.CrsBUsesSincePadClean = string.IsNullOrEmpty(TmpBufferData.CrsBUsesSincePadClean) ? "0" : TmpBufferData.CrsBUsesSincePadClean;
  592. TmpBufferData.CrsBUsesSinceSealClean = string.IsNullOrEmpty(TmpBufferData.CrsBUsesSinceSealClean) ? "0" : TmpBufferData.CrsBUsesSinceSealClean;
  593. if(!CheckWaferHolderId())
  594. {
  595. reason = "WS Id exist";
  596. return false;
  597. }
  598. return true;
  599. }
  600. /// <summary>
  601. /// 检验载具唯 一性
  602. /// </summary>
  603. /// <returns></returns>
  604. private bool CheckWaferHolderId()
  605. {
  606. string waferHolderId = TmpBufferData.WaferHolderId;
  607. for(int i=0;i<BufferDatas.Count;i++)
  608. {
  609. if (waferHolderId == BufferDatas[i].WaferHolderId)
  610. {
  611. if (BufferDatas[i].Id != TmpBufferData.Id)
  612. {
  613. return false;
  614. }
  615. }
  616. }
  617. for(int i=0;i<UnusedWaferHolders.Count;i++)
  618. {
  619. if (waferHolderId == UnusedWaferHolders[i].Id)
  620. {
  621. return false;
  622. }
  623. }
  624. return true;
  625. }
  626. /// <summary>
  627. /// 保存
  628. /// </summary>
  629. /// <param name="param"></param>
  630. public void SaveAction(object param)
  631. {
  632. bool validation = Validation(out var reason);
  633. if(!validation)
  634. {
  635. WPFMessageBox.ShowError(reason);
  636. return;
  637. }
  638. WaferHolderInfo info = WaferHolderBuferDataConvertToWaferHolderInfo();
  639. int result = 0;
  640. if(operation=="Add")
  641. {
  642. info.BufferId = SelectedBufferData.Id;
  643. if(info.CurrentLocation == null)
  644. {
  645. info.CurrentLocation = $"Buffer{info.BufferId}";
  646. }
  647. info.WaferAId = $"{info.Id}.01";
  648. info.WaferBId = $"{info.Id}.02";
  649. info.WaferAType = (int)WaferType.Assit;
  650. info.WaferBType = (int)WaferType.Assit;
  651. TmpBufferData.CurrentLocation = info.CurrentLocation;
  652. result= WaferHolderDataClient.Instance.Service.AddWaferHolderData(SelectedBufferData.Id, info);
  653. }else if(operation == "MoveLocation")
  654. {
  655. //判断能否更新位置
  656. if (!string.IsNullOrEmpty(SelectedBufferData.CurrentLocation) && !string.IsNullOrEmpty(info.CurrentLocation))
  657. {
  658. if (!_isLoaderTransBusy && !_isProcessTransBusy && !_isAutoMode)
  659. {
  660. info.WaferAId = $"{info.Id}.01";
  661. info.WaferBId = $"{info.Id}.02";
  662. info.WaferAType = (int)WaferType.Assit;
  663. info.WaferBType = (int)WaferType.Assit;
  664. result = WaferHolderDataClient.Instance.Service.UpdateWaferHolderData(SelectedBufferData.WaferHolderId, info,true);
  665. InvokeClient.Instance.Service.DoOperation($"WaferHolder.TransferWaferHolder", $"{SelectedBufferData.CurrentLocation}", $"{info.CurrentLocation}");
  666. }
  667. else if (_isAutoMode)
  668. {
  669. SelectedBufferData.SwitchData(TmpBufferData);
  670. MessageBox.Show("Auto mode can't do this operation", "Save", MessageBoxButton.OK, MessageBoxImage.Error);
  671. }
  672. else
  673. {
  674. SelectedBufferData.SwitchData(TmpBufferData);
  675. MessageBox.Show("Loader or Process Transporter is in Busy state", "Save", MessageBoxButton.OK, MessageBoxImage.Error);
  676. }
  677. }
  678. }
  679. else
  680. {
  681. //todo edit
  682. info.BufferId = SelectedBufferData.Id;
  683. info.WaferAId = $"{info.Id}.01";
  684. info.WaferBId = $"{info.Id}.02";
  685. info.WaferAType = (int)WaferType.Assit;
  686. info.WaferBType = (int)WaferType.Assit;
  687. result = WaferHolderDataClient.Instance.Service.UpdateWaferHolderData(SelectedBufferData.WaferHolderId, info, true);
  688. }
  689. if (result > 0)
  690. {
  691. SetSelectedWaferHolderData();
  692. }
  693. IsEdit = false;
  694. IsLocationEdit = false;
  695. IsSaveandCancelEdit = false;
  696. operation = "";
  697. }
  698. /// <summary>
  699. /// 取消
  700. /// </summary>
  701. /// <param name="param"></param>
  702. public void CancelAction(object param)
  703. {
  704. if(operation=="Add")
  705. {
  706. TmpBufferData = new WaferHolderBufferData();
  707. }
  708. else
  709. {
  710. TmpBufferData = SelectedBufferData.Clone();
  711. }
  712. IsEdit = false;
  713. IsSaveandCancelEdit = false;
  714. IsLocationEdit= false;
  715. }
  716. /// <summary>
  717. /// 移入
  718. /// </summary>
  719. /// <param name="param"></param>
  720. public void MoveToLoaderAction(object param)
  721. {
  722. if(SelectedUnusedWaferHolderInfo==null)
  723. {
  724. MessageBox.Show("please select one unused data", "Move To Buffer", MessageBoxButton.OK, MessageBoxImage.Error);
  725. return;
  726. }
  727. if(SelectedBufferData==null)
  728. {
  729. MessageBox.Show("please select one data", "Edit", MessageBoxButton.OK, MessageBoxImage.Error);
  730. return;
  731. }
  732. if (!string.IsNullOrEmpty(SelectedBufferData.WaferHolderId))
  733. {
  734. MessageBox.Show("data exist,can not move operation", "Edit", MessageBoxButton.OK, MessageBoxImage.Error);
  735. return;
  736. }
  737. if (MessageBox.Show("do you want to move selected wafer shuttle to buffer", "Move To Buffer", MessageBoxButton.YesNoCancel, MessageBoxImage.Question) == MessageBoxResult.Yes)
  738. {
  739. SelectedUnusedWaferHolderInfo.CurrentLocation = $"Buffer{SelectedBufferData.Id}";
  740. SelectedUnusedWaferHolderInfo.BufferId = SelectedBufferData.Id;
  741. int result = WaferHolderDataClient.Instance.Service.UpdateWaferHolderData(SelectedUnusedWaferHolderInfo.Id, SelectedUnusedWaferHolderInfo,true);
  742. if (result != 0)
  743. {
  744. SwitchWaferInfoToWaferHolderBufferData(SelectedUnusedWaferHolderInfo, SelectedBufferData);
  745. BufferDataSelectedChanged(SelectedBufferData);
  746. UnusedWaferHolders.Remove(SelectedUnusedWaferHolderInfo);
  747. SelectedUnusedWaferHolderInfo = null;
  748. }
  749. }
  750. }
  751. /// <summary>
  752. /// 移出
  753. /// </summary>
  754. /// <param name="param"></param>
  755. public void MoveFromLoaderAction(object param)
  756. {
  757. if(!CheckSelection())
  758. {
  759. return;
  760. }
  761. if (MessageBox.Show("do you want to move out selected wafer shuttle from buffer", "Move From Buffer", MessageBoxButton.YesNoCancel, MessageBoxImage.Question) == MessageBoxResult.Yes)
  762. {
  763. WaferHolderInfo info = WaferHolderBuferDataConvertToWaferHolderInfo();
  764. string preLocation = info.CurrentLocation;
  765. info.CurrentLocation = "";
  766. int result = WaferHolderDataClient.Instance.Service.UpdateWaferHolderData(SelectedBufferData.WaferHolderId, info, true);
  767. if (result != 0)
  768. {
  769. TmpBufferData = new WaferHolderBufferData();
  770. TmpBufferData.Id = SelectedBufferData.Id;
  771. TmpBufferData.SwitchData(SelectedBufferData);
  772. UnusedWaferHolders.Add(info);
  773. }
  774. }
  775. }
  776. /// <summary>
  777. /// 移除
  778. /// </summary>
  779. /// <param name="param"></param>
  780. public void RemoveAction(object param)
  781. {
  782. if (SelectedUnusedWaferHolderInfo == null)
  783. {
  784. MessageBox.Show("please select one unused data", "Edit", MessageBoxButton.OK, MessageBoxImage.Error);
  785. return;
  786. }
  787. if (MessageBox.Show("do you want to remove selected unused wafer shuttle","remove",MessageBoxButton.YesNoCancel,MessageBoxImage.Question)==MessageBoxResult.Yes)
  788. {
  789. int result = WaferHolderDataClient.Instance.Service.DeleteWaferHolderData(SelectedUnusedWaferHolderInfo.Id);
  790. if (result != 0)
  791. {
  792. UnusedWaferHolders.Remove(SelectedUnusedWaferHolderInfo);
  793. SelectedUnusedWaferHolderInfo = null;
  794. }
  795. }
  796. }
  797. /// <summary>
  798. /// 编辑CurrentLocation
  799. /// </summary>
  800. /// <param name="param"></param>
  801. private void MoveLocationAction(object param)
  802. {
  803. if (!CheckSelection())
  804. {
  805. return;
  806. }
  807. if (string.IsNullOrEmpty(SelectedBufferData.WaferHolderId))
  808. {
  809. MessageBox.Show("empty data", "Move Location", MessageBoxButton.OK, MessageBoxImage.Error);
  810. return;
  811. }
  812. operation = "MoveLocation";
  813. IsLocationEdit = true;
  814. IsSaveandCancelEdit = true;
  815. }
  816. /// <summary>
  817. /// 数据切换
  818. /// </summary>
  819. /// <param name="waferHolderBufferData"></param>
  820. public void BufferDataSelectedChanged(WaferHolderBufferData waferHolderBufferData)
  821. {
  822. TmpBufferData=waferHolderBufferData.Clone();
  823. IsEdit = false;
  824. IsLocationEdit = false;
  825. IsSaveandCancelEdit = false;
  826. }
  827. /// <summary>
  828. /// 数据转换
  829. /// </summary>
  830. /// <returns></returns>
  831. private WaferHolderInfo WaferHolderBuferDataConvertToWaferHolderInfo()
  832. {
  833. WaferHolderInfo info = new WaferHolderInfo();
  834. info.Id = TmpBufferData.WaferHolderId;
  835. info.CrsType = TmpBufferData.CrsType;
  836. info.WaferSize = int.Parse(TmpBufferData.WaferSize);
  837. info.Chemistry = TmpBufferData.Chemistry;
  838. info.TotalUses = int.Parse(TmpBufferData.TotalUses);
  839. info.TotalDummyWafers = int.Parse(TmpBufferData.TotalDummyWafers);
  840. info.TotalProductWafers = int.Parse(TmpBufferData.TotalProductWafers);
  841. info.CrsAId = TmpBufferData.CrsAId;
  842. info.CrsATotalUses =int.Parse(TmpBufferData.CrsATotalUses);
  843. info.CrsAUsesSincePadClean = int.Parse(TmpBufferData.CrsAUsesSincePadClean);
  844. info.CrsAUsesSinceSealClean = int.Parse(TmpBufferData.CrsAUsesSinceSealClean);
  845. info.CrsBId = TmpBufferData.CrsBId;
  846. info.CrsBTotalUses = int.Parse(TmpBufferData.CrsBTotalUses);
  847. info.CrsBUsesSincePadClean = int.Parse(TmpBufferData.CrsBUsesSincePadClean);
  848. info.CrsBUsesSinceSealClean = int.Parse(TmpBufferData.CrsBUsesSinceSealClean);
  849. info.Enabled =bool.Parse(TmpBufferData.Enabled);
  850. info.CurrentLocation = TmpBufferData.CurrentLocation;
  851. info.Status = info.Enabled ? WaferHolderStatus.Normal : WaferHolderStatus.Disabled;
  852. return info;
  853. }
  854. /// <summary>
  855. /// 交换载具数据至载具Buffer数据
  856. /// </summary>
  857. /// <param name="info"></param>
  858. /// <param name="data"></param>
  859. private void SwitchWaferInfoToWaferHolderBufferData(WaferHolderInfo info,WaferHolderBufferData data)
  860. {
  861. data.CrsType = info.CrsType;
  862. data.WaferHolderId = info.Id;
  863. data.CrsType = info.CrsType;
  864. data.Chemistry = info.Chemistry;
  865. data.WaferSize = info.WaferSize.ToString();
  866. data.Enabled = info.Enabled.ToString();
  867. data.TotalUses = info.TotalUses.ToString();
  868. data.CrsAId = info.CrsAId;
  869. data.CrsATotalUses = info.CrsATotalUses.ToString();
  870. data.CrsAUsesSincePadClean = info.CrsAUsesSincePadClean.ToString();
  871. data.CrsAUsesSinceSealClean = info.CrsAUsesSinceSealClean.ToString();
  872. data.CrsBId = info.CrsBId;
  873. data.CrsBTotalUses = info.CrsBTotalUses.ToString();
  874. data.CrsBUsesSincePadClean = info.CrsBUsesSincePadClean.ToString();
  875. data.CrsBUsesSinceSealClean = info.CrsBUsesSinceSealClean.ToString();
  876. data.TotalDummyWafers = info.TotalDummyWafers.ToString();
  877. data.TotalProductWafers = info.TotalProductWafers.ToString();
  878. data.CurrentLocation = info.CurrentLocation;
  879. }
  880. /// <summary>
  881. /// 将临时变量赋值
  882. /// </summary>
  883. private void SetSelectedWaferHolderData()
  884. {
  885. SelectedBufferData.Id = TmpBufferData.Id;
  886. SelectedBufferData.WaferHolderId = TmpBufferData.WaferHolderId;
  887. SelectedBufferData.Chemistry = TmpBufferData.Chemistry;
  888. SelectedBufferData.CrsType = TmpBufferData.CrsType;
  889. SelectedBufferData.WaferSize = TmpBufferData.WaferSize;
  890. SelectedBufferData.TotalUses = TmpBufferData.TotalUses;
  891. SelectedBufferData.TotalProductWafers = TmpBufferData.TotalProductWafers;
  892. SelectedBufferData.TotalDummyWafers = TmpBufferData.TotalDummyWafers;
  893. SelectedBufferData.CrsAId = TmpBufferData.CrsAId;
  894. SelectedBufferData.CrsATotalUses = TmpBufferData.CrsATotalUses;
  895. SelectedBufferData.CrsAUsesSincePadClean = TmpBufferData.CrsBUsesSincePadClean;
  896. SelectedBufferData.CrsAUsesSinceSealClean = TmpBufferData.CrsAUsesSinceSealClean;
  897. SelectedBufferData.CrsBId = TmpBufferData.CrsBId;
  898. SelectedBufferData.CrsBTotalUses = TmpBufferData.CrsBTotalUses;
  899. SelectedBufferData.CrsBUsesSincePadClean = TmpBufferData.CrsBUsesSincePadClean;
  900. SelectedBufferData.CrsBUsesSinceSealClean = TmpBufferData.CrsBUsesSinceSealClean;
  901. SelectedBufferData.Enabled = TmpBufferData.Enabled;
  902. SelectedBufferData.CurrentLocation = TmpBufferData.CurrentLocation;
  903. }
  904. }
  905. }