Exemplo n.º 1
0
        /// <summary>
        /// 依據傳入的工作站取得可使用機台清單
        /// </summary>
        /// <param name="operationName">工作站名稱</param>
        public static List <EquipmentInfo> GetEquipmentListByOperationName(string operationName)
        {
            //清除機台清單
            List <EquipmentInfo> equipmentList = new List <EquipmentInfo>();

            //取得批號目前的工作站資料
            var operationData = OperationInfo.GetOperationByName(operationName);

            if (operationData == null)
            {
                //[00171]工作站:{0}不存在!!
                throw new Exception(TextMessage.Error.T00171(operationName));
            }

            //確認工作站是否有啟用使用機台的功能
            if (operationData.EQUIPFLAG == "Y")
            {
                //依據工作站找出歸屬的機台群組清單
                List <OperationResourceInfoEx> resourceDataList = OperationResourceInfoEx.GetDataByOperSID(operationData.OperationSID);

                if (resourceDataList.Count > 0)
                {
                    #region 取得該工作站可使用的所有機台資料
                    foreach (var resourceData in resourceDataList)
                    {
                        if (resourceData.ResourceType == "Group")
                        {
                            //如果資源類別為Group,則找出此機台群組內的所有機台資訊
                            var equipGroupData = EquipmentGroupInfo.GetEquipmentGroupByID(resourceData.ResourceID);

                            //用群組SID找出在該群組下的工作站
                            List <EquipGroupEquipInfoEx> eqGroupDataList = EquipGroupEquipInfoEx.GetEquipGroupByGroupSID(equipGroupData.ID);

                            if (eqGroupDataList.Count > 0)
                            {
                                foreach (var eqGroupData in eqGroupDataList)
                                {
                                    //取得機台資訊
                                    var equipmentData = EquipmentInfo.GetEquipmentByName(eqGroupData.EquipmentName);

                                    //如果機台資料不為NULL才要確認是否己經加入清單內
                                    if (equipmentData != null)
                                    {
                                        //確認是否已經加入機台清單
                                        if (equipmentList.Contains(equipmentData) == false)
                                        {
                                            equipmentList.Add(equipmentData);
                                        }
                                    }
                                }
                            }
                        }
                        else if (resourceData.ResourceType == "Equip")
                        {
                            //如果資源類別為Equip,則加入此機台資訊
                            var equipmentData = EquipmentInfo.GetEquipmentByID(resourceData.ResourceID);

                            //如果機台資料不為NULL才要確認是否己經加入清單內
                            if (equipmentData != null)
                            {
                                //確認是否已經加入機台清單
                                if (equipmentList.Contains(equipmentData) == false)
                                {
                                    equipmentList.Add(equipmentData);
                                }
                            }
                        }
                        else if (resourceData.ResourceType == "Type")
                        {
                            //如果資源類別為Type,則加入所有此Type的機台資訊
                            var equipmentTypeData  = EquipmentTypeInfo.GetEquipmentTypeByID(resourceData.ResourceID);
                            var equipmentDatalList = EquipmentInfo.GetEquipmentsByType(equipmentTypeData);

                            foreach (var equipmentData in equipmentDatalList)
                            {
                                //確認是否已經加入機台清單
                                if (equipmentList.Contains(equipmentData) == false)
                                {
                                    equipmentList.Add(equipmentData);
                                }
                            }
                        }
                    }
                    #endregion
                }
            }

            //以機台名稱排序
            equipmentList.Sort(p => p.EquipmentName);

            return(equipmentList);
        }