Standby.cs 2.0 KB
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DeviceLibrary
{
    public class StandbyManager
    {
        /// <summary>
        /// 待机位
        /// </summary>
        public List<string> Station;
        private const int Station_CNT = 3;

        public StandbyManager()
        {
            Station = new List<string>();
            Station.AddRange(new string[Station_CNT]);
        }
        /// <summary>
        /// 在空的待机位添加占用小车
        /// </summary>
        /// <param name="standName">占用待机位的名称</param>
        /// <returns></returns>
        public bool AddOccupyInfo(string standName)
        {
            if (standName.Equals(""))
                return false;

            int i = Station.FindIndex(s => (s == null || s.Equals("")));
            if (i > -1)
            {
                Station[i] = standName;
                return true;
            }
            return false;
        }
        /// <summary>
        /// 清除占用信息
        /// </summary>
        /// <param name="standName"></param>
        /// <returns></returns>
        public bool DelOccupyInfo(string standName)
        {
            if (standName.Equals(""))
                return false;
            int i = Station.FindIndex(s => s != null && s.Equals(standName));
            if (i > -1)
            {
                Station[i] = "";
                return true;
            }
            return false;
        }

        public void ClearAllInfo()
        {
            if (Station != null && Station.Count > 0)
            {
                Station.Clear();
                Station = new List<string>();
                Station.AddRange(new string[Station_CNT]);
            }

        }
        public string GetInfoByID(int index)
        {
            if (Station ==null ||index<0 || index >= Station_CNT || Station[index] ==null)
                return "";
            else
                return Station[index];
        }
    }

}