RecipeStepDeleteDialogViewModel.cs 2.2 KB

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