RecipeStepDeleteDialogViewModel.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using MECF.Framework.UI.Client.CenterViews.Editors.Recipe;
  2. using System.Collections.Generic;
  3. using System.Collections.ObjectModel;
  4. using System.Linq;
  5. using FurnaceUI.Models;
  6. using MECF.Framework.UI.Client.ClientBase;
  7. using OpenSEMI.ClientBase;
  8. using System.Windows;
  9. namespace FurnaceUI.Views.Recipes
  10. {
  11. public class RecipeStepDeleteDialogViewModel:FurnaceUIViewModelBase
  12. {
  13. public RecipeDataBase Recipe { get; set; }
  14. private ObservableCollection<Step> _newSteps = new ObservableCollection<Step>();
  15. public ObservableCollection<Step> NewSteps
  16. {
  17. get
  18. {
  19. if (Recipe != null && Recipe.Steps != null)
  20. {
  21. _newSteps.Clear();
  22. Recipe.Steps.Where(x => !x.Name.ToLower().Contains("standby") && !x.Name.ToLower().Contains("end")).ToList().ForEach(s => _newSteps.Add(s));
  23. return _newSteps;
  24. }
  25. else
  26. {
  27. return null;
  28. }
  29. }
  30. }
  31. public RecipeStepDeleteDialogViewModel(RecipeDataBase CurrentRecipe)
  32. {
  33. Recipe = CurrentRecipe;
  34. }
  35. public void DeleteSteps()
  36. {
  37. if (DialogButton.No == DialogBox.ShowDialog(DialogButton.Yes | DialogButton.No,
  38. DialogType.CONFIRM,
  39. $"Make sure to delete the selected step?"))
  40. {
  41. return;
  42. }
  43. List<Step> test = new List<Step>();
  44. ObservableCollection<Step> TempSteps = Recipe.Steps;
  45. test = TempSteps.Where(x => x.IsChecked == true).ToList();
  46. foreach (var item in test)
  47. {
  48. Recipe.Steps.Remove(item);
  49. }
  50. Step step = Recipe.Steps.FirstOrDefault(x => x.Name == "Standby");
  51. for (int i = 0; i < Recipe.Steps.Count; i++)
  52. {
  53. if (step == null)
  54. {
  55. Recipe.Steps[i].StepNo = i + 1;
  56. }
  57. else
  58. {
  59. Recipe.Steps[i].StepNo = i;
  60. }
  61. }
  62. ((Window)GetView()).DialogResult = true;
  63. }
  64. }
  65. }