using Aitex.Core.RT.ConfigCenter; using Aitex.Core.RT.DataCenter; using Aitex.Core.RT.OperationCenter; using Aitex.Core.Util; using MECF.Framework.Common.CommonData; using MECF.Framework.Common.DBCore; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace MECF.Framework.Common.RecipeCenter { public class RecipeEditManager : Singleton { public string CurrentRecipeName { get; set; } public int CurrentStepID { get; set; } public string CurrentStepName { get; set; } public bool IsEnablePrevious { get; set; } public bool IsEnableNext { get; set; } public List> StepNames { get; set; } public void Initialize() { DATA.Subscribe("RecipeEdit", "CurrentRecipeName", () => CurrentRecipeName); DATA.Subscribe("RecipeEdit", "CurrentStepName", () => CurrentStepName); DATA.Subscribe("RecipeEdit", "CurrentStepID", () => CurrentStepID); DATA.Subscribe("RecipeEdit", "IsEnablePrevious", () => IsEnablePrevious); DATA.Subscribe("RecipeEdit", "IsEnableNext", () => IsEnableNext); DATA.Subscribe("RecipeEdit", "StepNames", () => StepNames); OP.Subscribe("SetCurrentRecipeName", SetCurrentRecipeName); OP.Subscribe("SetCurrentStepName", SetCurrentStepName); OP.Subscribe("SetRecipeSteps", SetRecipeSteps); OP.Subscribe("SetPreviousStep", SetPreviousStep); OP.Subscribe("SetNextStep", SetNextStep); OP.Subscribe("SetRecipeEditHistory", SetRecipeEditHistory); } private bool SetRecipeEditHistory(string arg1, object[] arg2) { if (arg2 != null && arg2.Count() > 0) { var recipeHistory = (RecipeHistory)arg2[0]; RecipeEditHistoryRecorder.SaveRecipeHistory(recipeHistory); } return true; } private bool SetCurrentRecipeName(string arg1, object[] arg2) { if (arg2 != null && arg2.Count() > 0) { CurrentRecipeName = (string)arg2[0]; } return true; } private bool SetCurrentStepName(string arg1, object[] arg2) { if (arg2 != null && arg2.Count() > 0) { var arg = arg2[0] as Tuple; CurrentStepName = arg.Item1; CurrentStepID = arg.Item2; if (StepNames != null && StepNames.Count > 0) { if (StepNames.Count < 2) { IsEnablePrevious = false; IsEnableNext = false; } else if (StepNames[0].Item2 >= CurrentStepID) { IsEnablePrevious = false; IsEnableNext = true; } else if (StepNames[StepNames.Count - 1].Item2 <= CurrentStepID) { IsEnablePrevious = true; IsEnableNext = false; } else { IsEnablePrevious = true; IsEnableNext = true; } } } return true; } private bool SetRecipeSteps(string arg1, object[] arg2) { if (arg2 != null && arg2.Count() > 0) { StepNames = (List>)arg2[0]; if (StepNames == null || StepNames.Count < 2) { IsEnablePrevious = false; IsEnableNext = false; } else { IsEnablePrevious = false; IsEnableNext = true; } } return true; } private bool SetPreviousStep(string arg1, object[] arg2) { if (StepNames == null && StepNames.Count < 2) { IsEnablePrevious = false; IsEnableNext = false; } else { int temp = CurrentStepID - 1; while (temp > -1) { Tuple tuple = StepNames.Where(x => x.Item2 == temp).FirstOrDefault(); if (tuple != null) { CurrentStepName = tuple.Item1; CurrentStepID = tuple.Item2; if (temp == 0) { IsEnablePrevious = false; } else { IsEnablePrevious = true; IsEnableNext = true; } break; } temp--; } } return true; } private bool SetNextStep(string arg1, object[] arg2) { if (StepNames == null && StepNames.Count < 2) { IsEnablePrevious = false; IsEnableNext = false; } else { int temp = CurrentStepID + 1; while (temp < StepNames.Count) { Tuple tuple = StepNames.Where(x => x.Item2 == temp).FirstOrDefault(); if (tuple != null) { CurrentStepName = tuple.Item1; CurrentStepID = tuple.Item2; if (temp == StepNames.Count) { IsEnableNext = false; } else { IsEnablePrevious = true; IsEnableNext = true; } break; } temp++; } } return true; } } }