Example #1
0
        /// <summary> 获取层压机信息 </summary>
        /// <param name="lotNumber">批次号</param>
        /// <returns></returns>
        public LotAttribute GetLaminator(string lotNumber)
        {
            LotAttribute LotAttribute = null;       //批次属性
            Equipment    Equipment    = null;       //批次设备

            //获取批次属性
            using (LotAttributeServiceClient client = new LotAttributeServiceClient())
            {
                PagingConfig cfg = new PagingConfig()
                {
                    PageNo   = 0,
                    PageSize = 1,
                    Where    = string.Format("Key.LotNumber='{0}' AND Key.AttributeName ='LayerEquipmentNo'", lotNumber)
                };
                MethodReturnResult <IList <LotAttribute> > result = client.Get(ref cfg);
                if (result.Code <= 0 && result.Data != null && result.Data.Count > 0)
                {
                    LotAttribute = result.Data[0];

                    //获取批次设备
                    Equipment = GetEquipment(LotAttribute.AttributeValue);

                    if (Equipment != null)
                    {
                        LotAttribute.AttributeValue = Equipment.Name;
                    }
                    else
                    {
                        LotAttribute.AttributeValue = LotAttribute.AttributeValue;
                    }
                }
            }
            return(LotAttribute);
        }
Example #2
0
        /// <summary> 获取层压机信息 </summary>
        /// <param name="lotNumber">批次号</param>
        /// <returns></returns>
        public LotAttribute GetLaminator(string lotNumber)
        {
            LotAttribute LotAttribute = null;

            using (LotAttributeServiceClient client = new LotAttributeServiceClient())
            {
                PagingConfig cfg = new PagingConfig()
                {
                    PageNo   = 0,
                    PageSize = 1,
                    Where    = string.Format("Key.LotNumber='{0}' AND Key.AttributeName ='LayerEquipmentNo'", lotNumber)
                };
                MethodReturnResult <IList <LotAttribute> > result = client.Get(ref cfg);
                if (result.Code <= 0 && result.Data != null && result.Data.Count > 0)
                {
                    LotAttribute = result.Data[0];

                    if (LotAttribute.AttributeValue == "EMCY2001")
                    {
                        LotAttribute.AttributeValue = "102B-1#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY2002")
                    {
                        LotAttribute.AttributeValue = "102B-2#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY2003")
                    {
                        LotAttribute.AttributeValue = "102B-3#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY2004")
                    {
                        LotAttribute.AttributeValue = "102B-4#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY2005")
                    {
                        LotAttribute.AttributeValue = "102B-5#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY2006")
                    {
                        LotAttribute.AttributeValue = "102B-6#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY2007")
                    {
                        LotAttribute.AttributeValue = "102B-7#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY2008")
                    {
                        LotAttribute.AttributeValue = "102B-8#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY2009")
                    {
                        LotAttribute.AttributeValue = "102B-9#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY2010")
                    {
                        LotAttribute.AttributeValue = "102B-10#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY1001")
                    {
                        LotAttribute.AttributeValue = "102A-1#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY1002")
                    {
                        LotAttribute.AttributeValue = "102A-2#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY1003")
                    {
                        LotAttribute.AttributeValue = "102A-3#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY1004")
                    {
                        LotAttribute.AttributeValue = "102A-4#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY1005")
                    {
                        LotAttribute.AttributeValue = "102A-5#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY1006")
                    {
                        LotAttribute.AttributeValue = "102A-6#";
                    }
                    else if (LotAttribute.AttributeValue == "EMCY1007")
                    {
                        LotAttribute.AttributeValue = "102A-7#";
                    }
                    else if (LotAttribute.AttributeValue == "")
                    {
                        LotAttribute.AttributeValue = "null";
                    }
                }
                else
                {
                    result.Data = null;
                }
                return(LotAttribute);
            }
        }
Example #3
0
        /// <summary>
        /// 将图片数据上传到MES中。
        /// </summary>
        /// <param name="element">图片设备配置。</param>
        /// <returns>true:转置成功。false:转置失败。</returns>
        public bool Execute(ImageDeviceElement element)
        {
            try
            {
                //获取源文件夹路径。
                string sourcePath = this.GetSourcePath(element);
                if (string.IsNullOrEmpty(sourcePath))
                {
                    EventLog.WriteEntry(EVENT_SOURCE_NAME
                                        , string.Format("获取 {0} 源文件夹路径失败。", element.Name)
                                        , EventLogEntryType.Error);
                    return(false);
                }
                //获取目标文件夹路径。
                string sourceRootPath = element.SourcePathRoot.TrimEnd(Path.DirectorySeparatorChar);
                string targetRootPath = element.TargetPathRoot.TrimEnd(Path.DirectorySeparatorChar);
                //string targetPath = sourcePath.Replace(sourceRootPath, targetRootPath);
                string targetPath = this.GetTargetPath(element);

                if (Directory.Exists(targetPath) == false)
                {
                    EventLog.WriteEntry(EVENT_SOURCE_NAME
                                        , string.Format("{0} 目标文件夹路径({1})不存在。", element.Name, targetPath)
                                        , EventLogEntryType.Warning);
                    Directory.CreateDirectory(targetPath);
                }
                //获取源文件夹下的未移转图片。
                DirectoryInfo diSourcePath  = new DirectoryInfo(sourcePath);
                string        searchPattern = string.Format("*.{0}", element.FileExtensionName);
                FileInfo[]    fileInfos     = diSourcePath.GetFiles(searchPattern, SearchOption.AllDirectories);
                DateTime      dtMaxTime     = DateTime.MinValue;
                //移除最新的更新时间问题

                /*
                 * using (ClientConfigAttributeServiceClient client = new ClientConfigAttributeServiceClient())
                 * {
                 *  MethodReturnResult<ClientConfigAttribute> rst = client.Get(new ClientConfigAttributeKey()
                 *  {
                 *      ClientName = element.Name,
                 *      AttributeName = string.Format("{0}ImageDateTime", element.Type)
                 *  });
                 *  if (rst.Code <= 0 && rst.Data != null)
                 *  {
                 *      dtMaxTime = DateTime.Parse(rst.Data.Value);
                 *  }
                 *  client.Close();
                 * }
                 * var lnq = from item in fileInfos
                 *        where item.LastWriteTime > dtMaxTime
                 *        orderby item.LastWriteTime
                 *        select item;
                 */
                //遍历文件夹文件。
                IList <LotAttribute> lstLotAttribute = new List <LotAttribute>();
                foreach (FileInfo fiItem in fileInfos)
                {
                    string targetFileName = fiItem.FullName.Replace(sourcePath, targetPath);
                    Directory.CreateDirectory(Path.GetDirectoryName(targetFileName));
                    //复制源文件到目标文件夹下。
                    File.Copy(fiItem.FullName, targetFileName, true);
                    dtMaxTime = fiItem.LastWriteTime.AddMilliseconds(1);
                    #region  //更新批次属性数据。
                    try
                    {
                        string lotNumber = fiItem.Name.Replace(fiItem.Extension, string.Empty).ToUpper().Split('_', '-')[0];
                        lotNumber = lotNumber.Trim();
                        string attributeName  = string.Format("{0}ImagePath", element.Type);
                        string attributeValue = targetFileName.Replace(targetRootPath, element.HttpPathRoot);
                        attributeValue = attributeValue.Replace('\\', '/');
                        LotAttribute obj = new LotAttribute()
                        {
                            Key = new LotAttributeKey()
                            {
                                LotNumber     = lotNumber,
                                AttributeName = attributeName
                            },
                            AttributeValue = attributeValue,
                            Editor         = "system",
                            EditTime       = DateTime.Now
                        };
                        using (LotAttributeServiceClient client = new LotAttributeServiceClient())
                        {
                            MethodReturnResult result = client.Modify(obj);
                            if (result.Code > 0)
                            {
                                EventLog.WriteEntry(EVENT_SOURCE_NAME
                                                    , string.Format("{0}:{1} {2}", element.Name, fiItem.FullName, result.Message)
                                                    , EventLogEntryType.Warning);
                                client.Close();
                                continue;
                            }
                            client.Close();
                        }
                    }
                    catch (Exception ex)
                    {
                        EventLog.WriteEntry(EVENT_SOURCE_NAME
                                            , string.Format("{0}:{1} {2}", element.Name, fiItem.FullName, ex.Message)
                                            , EventLogEntryType.Error);
                        System.Threading.Thread.Sleep(500);
                        return(false);
                    }
                    #endregion

                    #region //进行原文件的后续处理。
                    int count = 0;
                    while (count < 5)
                    {
                        count++;
                        try
                        {
                            //如设置删除源文件,则删除。
                            if (element.IsDeleteSourceFile)
                            {
                                File.Delete(fiItem.FullName);
                            }
                            else
                            {//否则,移动到LocalFiles下。
                             //string copyFilePath = sourcePath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar + "LocalFiles";
                             //if (Directory.Exists(copyFilePath) == false)
                             //{
                             //    Directory.CreateDirectory(copyFilePath);
                             //}
                             //string copyFileName = fiItem.FullName.Replace(sourcePath, copyFilePath);
                             //File.Copy(fiItem.FullName, copyFileName,true);
                             //File.Delete(fiItem.FullName);
                            }
                            break;
                        }
                        catch (Exception ex)
                        {
                            EventLog.WriteEntry(EVENT_SOURCE_NAME
                                                , string.Format("{0}:{1} {2}", element.Name, fiItem.FullName, ex.Message)
                                                , EventLogEntryType.Error);
                            System.Threading.Thread.Sleep(500);
                            continue;
                        }
                    }
                    #endregion

                    #region 更新ClientConfig的最新更新时间

                    /*
                     * using (ClientConfigServiceClient client = new ClientConfigServiceClient())
                     * {
                     *  MethodReturnResult<ClientConfig> rst = client.Get(element.Name);
                     *  if (rst.Data == null)
                     *  {
                     *      ClientConfig obj = new ClientConfig()
                     *      {
                     *          ClientType = EnumClientType.Other,
                     *          CreateTime = DateTime.Now,
                     *          Creator = "system",
                     *          Description = string.Empty,
                     *          Editor = "system",
                     *          EditTime = DateTime.Now,
                     *          IPAddress = element.Name,
                     *          Key = element.Name,
                     *          LocationName = null
                     *      };
                     *      client.Add(obj);
                     *  }
                     *  client.Close();
                     * }
                     * using (ClientConfigAttributeServiceClient client = new ClientConfigAttributeServiceClient())
                     * {
                     *  ClientConfigAttribute obj = null;
                     *  ClientConfigAttributeKey ccaKey = new ClientConfigAttributeKey()
                     *  {
                     *      ClientName = element.Name,
                     *      AttributeName = string.Format("{0}ImageDateTime",element.Type)
                     *  };
                     *  MethodReturnResult<ClientConfigAttribute> rst = client.Get(ccaKey);
                     *  if (rst.Code <= 0 && rst.Data != null)
                     *  {
                     *      obj = rst.Data;
                     *  }
                     *  if (obj != null)
                     *  {
                     *      obj.Value = dtMaxTime.ToString("yyyy-MM-dd HH:mm:ss.fff");
                     *      obj.Editor = "system";
                     *      obj.EditTime = DateTime.Now;
                     *      client.Modify(obj);
                     *  }
                     *  else
                     *  {
                     *      obj = new ClientConfigAttribute()
                     *      {
                     *          Key = ccaKey,
                     *          Value = dtMaxTime.ToString("yyyy-MM-dd HH:mm:ss.fff"),
                     *          Editor = "system",
                     *          EditTime = DateTime.Now
                     *      };
                     *      client.Add(obj);
                     *  }
                     *  client.Close();
                     * }
                     */
                    #endregion
                }
            }
            catch (Exception ex)
            {
                EventLog.WriteEntry(EVENT_SOURCE_NAME
                                    , string.Format("{0}:{1}", element.Name, ex.Message)
                                    , EventLogEntryType.Error);
                return(false);
            }
            return(true);
        }
Example #4
0
        /// <summary>
        /// 将图片数据上传到MES中。
        /// </summary>
        /// <param name="element">图片设备配置。</param>
        /// <returns>true:转置成功。false:转置失败。</returns>
        public void Execute(ImageDeviceElement element)
        {
            bool   blFindFiles          = false;
            bool   blTransferDataResult = true;
            string strTransferDataMsg   = "";

            try
            {
                //获取源文件夹路径。
                string sourcePath = this.GetSourcePath(element);
                if (string.IsNullOrEmpty(sourcePath))
                {
                    blTransferDataResult = false;
                    strTransferDataMsg   = string.Format("获取 {0} 源文件夹路径失败。", element.Name);
                }
                //获取目标文件夹路径。
                string sourceRootPath = element.SourcePathRoot.TrimEnd(Path.DirectorySeparatorChar);
                string targetRootPath = element.TargetPathRoot.TrimEnd(Path.DirectorySeparatorChar);
                //string targetPath = sourcePath.Replace(sourceRootPath, targetRootPath);
                string targetPath = this.GetTargetPath(element);

                if (Directory.Exists(targetPath) == false)
                {
                    Directory.CreateDirectory(targetPath);
                }
                //获取源文件夹下的未移转图片。
                DirectoryInfo diSourcePath  = new DirectoryInfo(sourcePath);
                string        searchPattern = string.Format("*.{0}", element.FileExtensionName);
                FileInfo[]    fileInfos     = diSourcePath.GetFiles(searchPattern, SearchOption.AllDirectories);
                if (fileInfos != null && fileInfos.Length > 0)
                {
                    blFindFiles = true;
                }
                DateTime dtMaxTime = DateTime.MinValue;
                //遍历文件夹文件。
                int maxNumberForLoop = 5;
                int nIndexOfFile     = 0;
                if (fileInfos.Length > maxNumberForLoop)
                {
                    SortAsFileCreationTime(ref fileInfos);
                }
                IList <LotAttribute> lstLotAttribute = new List <LotAttribute>();
                foreach (FileInfo fiItem in fileInfos)
                {
                    if (nIndexOfFile > maxNumberForLoop)
                    {
                        break;
                    }
                    nIndexOfFile = nIndexOfFile + 1;

                    string targetFileName = fiItem.FullName.Replace(sourcePath, targetPath);
                    Directory.CreateDirectory(Path.GetDirectoryName(targetFileName));

                    #region  //更新批次属性数据。
                    try
                    {
                        bool blFlag = true;
                        //复制源文件到目标文件夹下。
                        // blFlag = this.MoveFile(element, fiItem.FullName, targetFileName);
                        string lotNumber = "";

                        if (blFlag)
                        {
                            #endregion

                            #region //更新 Lot属性
                            lotNumber = fiItem.Name.Replace(fiItem.Extension, string.Empty).ToUpper().Split('_', '-')[0];
                            lotNumber = lotNumber.Trim();

                            #region//获取批次所在工序及状态
                            using (LotQueryServiceClient client = new LotQueryServiceClient())
                            {
                                PagingConfig cfg = new PagingConfig()
                                {
                                    Where   = string.Format("LOT_NUMBER = '{0} '", lotNumber),
                                    OrderBy = "EditTime Desc"
                                };
                                MethodReturnResult <IList <LotTransaction> > result = client.GetTransaction(ref cfg);
                                if (result.Code <= 0 && result.Data != null && result.Data.Count > 0 && result.Data[0].RouteStepName == "功率测试" && result.Data[0].Activity == EnumLotActivity.TrackOut)
                                {
                                    string attributeName  = string.Format("{0}ImagePath", element.Type);
                                    string attributeValue = targetFileName.Replace(targetRootPath, element.HttpPathRoot);
                                    attributeValue = attributeValue.Replace('\\', '/');

                                    //获取批次属性是否已存在EL3的属性,如果不存在,则更新EL3图片属性
                                    using (LotAttributeServiceClient client2 = new LotAttributeServiceClient())
                                    {
                                        PagingConfig cfg1 = new PagingConfig()
                                        {
                                            Where   = string.Format("Key.LotNumber = '{0}'and Key.AttributeName='ELImagePath'", lotNumber),
                                            OrderBy = "EditTime Desc"
                                        };
                                        MethodReturnResult <IList <LotAttribute> > result2 = client.GetAttribute(ref cfg1);
                                        if (result2.Code <= 0 && result2.Data != null && result2.Data.Count > 0)
                                        {
                                            blFlag = this.MoveFile(element, fiItem.FullName, targetFileName);
                                            FileInfo[] fileInfos1 = diSourcePath.GetFiles(searchPattern, SearchOption.AllDirectories);
                                            foreach (FileInfo fiItem1 in fileInfos1)
                                            {
                                                if (nIndexOfFile > maxNumberForLoop)
                                                {
                                                    break;
                                                }
                                                nIndexOfFile = nIndexOfFile + 1;

                                                targetFileName = fiItem1.FullName.Replace(sourcePath, targetPath);
                                                Directory.CreateDirectory(Path.GetDirectoryName(targetFileName));
                                                File.Delete(fiItem1.FullName);
                                            }
                                            attributeValue = targetFileName.Replace(targetRootPath, element.HttpPathRoot);
                                            LotAttribute obj = new LotAttribute()
                                            {
                                                Key = new LotAttributeKey()
                                                {
                                                    LotNumber     = lotNumber,
                                                    AttributeName = attributeName
                                                },
                                                AttributeValue = attributeValue,
                                                Editor         = "system",
                                                EditTime       = DateTime.Now
                                            };
                                            using (LotAttributeServiceClient client1 = new LotAttributeServiceClient())
                                            {
                                                MethodReturnResult result1 = client1.Modify(obj);
                                                if (result.Code > 0)
                                                {
                                                    strTransferDataMsg = string.Format("更新批次号{0}错误:{1}", lotNumber, result.Message);
                                                    LogMessage(false, element.Type + ":" + strTransferDataMsg);
                                                    client.Close();
                                                }
                                                else
                                                {
                                                    LogMessage(true, element.Type + ":" + lotNumber);
                                                }
                                                client.Close();
                                            }
                                        }
                                        else
                                        {
                                            LotAttribute obj = new LotAttribute()
                                            {
                                                Key = new LotAttributeKey()
                                                {
                                                    LotNumber     = lotNumber,
                                                    AttributeName = attributeName
                                                },
                                                AttributeValue = attributeValue,
                                                Editor         = "system",
                                                EditTime       = DateTime.Now
                                            };
                                            using (LotAttributeServiceClient client1 = new LotAttributeServiceClient())
                                            {
                                                MethodReturnResult result1 = client1.Modify(obj);
                                                if (result.Code > 0)
                                                {
                                                    strTransferDataMsg = string.Format("更新批次号{0}错误:{1}", lotNumber, result.Message);
                                                    LogMessage(false, element.Type + ":" + strTransferDataMsg);
                                                    client.Close();
                                                }
                                                else
                                                {
                                                    LogMessage(true, element.Type + ":" + lotNumber);
                                                }
                                                client.Close();
                                            }
                                            blFlag = this.MoveFile(element, fiItem.FullName, targetFileName);
                                            File.Delete(fiItem.FullName);
                                        }
                                    }
                                }
                                else
                                {
                                    result.Message     = "组件批次不在功率测试出站";
                                    strTransferDataMsg = string.Format("批次号{0}错误:{1}", lotNumber, result.Message);
                                    blFlag             = this.MoveFile(element, fiItem.FullName, targetFileName);
                                    File.Delete(fiItem.FullName);
                                }

                                #endregion
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        LogMessage(false, element.Type + ":" + ex.Message);
                    }
                    #endregion
                }
            }
            catch (Exception ex)
            {
                blTransferDataResult = false;
                LogMessage(false, element.Type + ":" + ex.Message);
            }

            if (blFindFiles == false)
            {
                strTransferDataMsg = "";
                LogMessage(true, element.Type + ":" + strTransferDataMsg);
            }
        }