| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 | 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<RecipeEditManager>    {        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<Tuple<string, int>> 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<string, int>;                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<Tuple<string, int>>)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<string, int> 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<string, int> 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;        }    }}
 |