/// <summary>
        /// 显示Review窗口
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btReview_Click(object sender, EventArgs e)
        {
            FormDLAFReview formReview = new FormDLAFReview();

            formReview.ShowDialog();
        }
        //DLAFDetectResultTransfer _detectResultTransfer = new DLAFDetectResultTransfer();
        //受到自定义消息
        public void OnCustomizeMsg(string msgCategory, object[] msgParams)
        {
            fmTips.AddOneTips("工站消息Categoty:" + msgCategory);
            BeginInvoke(new Action(() => {
                if (msgCategory == CMC_ShowJFImage) //显示一个IJFImage对象
                {
                    object ob;
                    IJFImage ij = msgParams[0] as IJFImage;
                    if (null == ij)
                    {
                        fmTips.AddOneTips("消息参数IJFImage == null");
                        return;
                    }
                    int err = ij.GenHalcon(out ob);
                    if (err != 0)
                    {
                        fmTips.AddOneTips("参数IJFImage.GenHalcon 出错:" + ij.GetErrorInfo(err));
                        return;
                    }
                    htWindowControl1.DispImage(ob as HObject);
                }
                else if (msgCategory == CMC_ShowHO)//显示一个Halcon对象
                {
                    htWindowControl1.DispImage(msgParams[0] as HObject);
                }
                else if (CMC_StartNewPiece == msgCategory)
                {
                    rchRDetectInfo.Text = "";
                    string pieceID      = msgParams[0] as string;
                    rchRDetectInfo.AppendText(DateTime.Now.ToString("HH:mm:ss.fff") + " " + msgParams[0] + " 开始检测,PieceID = pieceID");
                    //_detectResultTransfer.SetPieceID(pieceID);
                    for (int i = 0; i < _currRecipe.RowNumber; i++)
                    {
                        for (int j = 0; j < _currRecipe.ColumnNumber * _currRecipe.BlockNumber; j++)
                        {
                            mappCtrl.SetDieState(i, j, "未检测");
                        }
                    }
                    _lstInspectData.Clear();
                }
                else if (msgCategory == CMC_InspectResult) //一个FOV的检测结果
                {
                    IJFImage[] orgImgs      = msgParams[0] as IJFImage[];
                    DlafFovDetectResult fdr = (msgParams[1] as DlafFovDetectResult); //.Clone();
                    int imgIndex2Show       = 0;
                    if (_isShowRealtimeDetectImg)                                    //需要实时显示图像
                    {
                        string taskName2Show = cbTaskImgShow.Text;
                        if (!string.IsNullOrEmpty(taskName2Show))
                        {
                            for (int i = 0; i < fdr.TaskNames.Length; i++)
                            {
                                if (fdr.TaskNames[i] == taskName2Show)
                                {
                                    imgIndex2Show = i;
                                    break;
                                }
                            }
                        }

                        //if (null != fdr.WireRegion) //老版本的数据显示功能
                        //{
                        //    htWindowControl1.ColorName = "green"; //金线为绿色显示
                        //    if(null != _hoOrgImgShowing)
                        //    {
                        //        _hoOrgImgShowing.Dispose();
                        //        _hoOrgImgShowing = null;

                        //    }

                        //    Object ob;
                        //    orgImgs[imgIndex2Show].GenHalcon(out ob);
                        //    _hoOrgImgShowing = ob as HObject;
                        //    htWindowControl1.RefreshWindow(_hoOrgImgShowing, fdr.WireRegion, "fit");
                        //}
                        //if (null != fdr.DetectIterms && fdr.DetectIterms.Count > 0)
                        //{
                        //    htWindowControl1.ColorName = "yellow"; //其他成功检测项显示为黄色
                        //    foreach (HObject ho in fdr.DetectIterms.Values)
                        //        htWindowControl1.DispRegion(ho);
                        //}

                        //if(null != fdr.DiesErrorRegions)
                        //{
                        //    htWindowControl1.ColorName = "red"; //错误区域显示为红色
                        //    foreach(HObject[] errorRegions in fdr.DiesErrorRegions)
                        //        if(null != errorRegions)
                        //            foreach(HObject ho in errorRegions)
                        //                htWindowControl1.DispRegion(ho);
                        //}


                        //新数据结构的显示
                        if (null != _hoOrgImgShowing)
                        {
                            _hoOrgImgShowing.Dispose();
                            _hoOrgImgShowing = null;
                        }

                        Object ob;
                        if (0 != orgImgs[imgIndex2Show].GenHalcon(out ob)) //图像转化出错
                        {
                            htWindowControl1.ClearHWindow();
                        }
                        else
                        {
                            _hoOrgImgShowing = (HObject)ob;
                            htWindowControl1.RefreshWindow(_hoOrgImgShowing, null, "fit"); //显示图片
                        }

                        //显示各检测项
                        if (!fdr.IsDetectSuccess || null == fdr.DieInspectResults)
                        {
                            return;
                        }

                        HObject errRegion = null;//所有错误区域
                        HOperatorSet.GenEmptyRegion(out errRegion);


                        HObject bondRegion = null; //焊点
                        HOperatorSet.GenEmptyRegion(out bondRegion);
                        HObject wireRegion = null;
                        HOperatorSet.GenEmptyRegion(out wireRegion);
                        HObject epoxyRegion = null;
                        HOperatorSet.GenEmptyRegion(out epoxyRegion);

                        bool _isShowAllItem = !chkJustShowNG.Checked;
                        foreach (InspectResultItem[] dieItems in fdr.DieInspectResults)
                        {
                            foreach (InspectResultItem item in dieItems)
                            {
                                if (!item.IsDetectOK())
                                {
                                    HOperatorSet.ConcatObj(errRegion, item.ResultRegion, out errRegion);
                                }
                                if (!_isShowAllItem)
                                {
                                    continue;
                                }

                                switch (item.InspectCategoty)
                                {
                                case InspectResultItem.Categoty.Frame:
                                    break;

                                case InspectResultItem.Categoty.IC:
                                    break;

                                case InspectResultItem.Categoty.Bond:
                                    HOperatorSet.ConcatObj(bondRegion, item.ResultRegion, out bondRegion);
                                    break;

                                case InspectResultItem.Categoty.Wire:
                                    HOperatorSet.ConcatObj(wireRegion, item.ResultRegion, out wireRegion);
                                    break;

                                case InspectResultItem.Categoty.Epoxy:
                                    HOperatorSet.ConcatObj(epoxyRegion, item.ResultRegion, out epoxyRegion);
                                    break;
                                }
                            }
                        }
                        if (_isShowAllItem)
                        {
                            htWindowControl1.ColorName = "green";
                            htWindowControl1.DispRegion(wireRegion);
                            htWindowControl1.ColorName = "yellow";
                            htWindowControl1.DispRegion(bondRegion);
                            htWindowControl1.ColorName = "blue";
                            htWindowControl1.DispRegion(epoxyRegion);
                        }
                        htWindowControl1.ColorName = "red";
                        htWindowControl1.DispRegion(errRegion);
                    }


                    if (fdr.DetectDiesImages != null)
                    {
                        foreach (HObject ho in fdr.DetectDiesImages)
                        {
                            ho.Dispose();
                        }
                    }


                    ///错误信息显示
                    StringBuilder sbInfo = new StringBuilder();
                    sbInfo.AppendLine("Fov:" + fdr.FovName + " 检测结果:");
                    if (!fdr.IsDetectSuccess)
                    {
                        sbInfo.AppendLine("图像检测失败,ErrorInfo:" + fdr.DetectErrorInfo);
                    }
                    else
                    {
                        if (fdr.IsFovOK)
                        {
                            sbInfo.AppendLine("检测结果: OK");
                        }
                        else
                        {
                            for (int i = 0; i < fdr.DetectDiesRows.Length; i++)
                            {
                                if (fdr.IsDieOK(i))
                                {
                                    sbInfo.AppendLine("Row-" + fdr.ICRow + " Col-" + fdr.ICCol + " Die-" + i + " OK");
                                }
                                else
                                {
                                    sbInfo.AppendLine("Row-" + fdr.ICRow + " Col-" + fdr.ICCol + " Die-" + i + " NG  错误信息:");
                                    int[] errors = fdr.DiesErrorCodes[i];
                                    //for(int j = 0; j < errors.Length;j++)
                                    //    sbInfo.AppendLine("ErrCode:" + errors[j] + " Info:" + InspectNode.DieErrorDescript(errors[j]) + "In Task:" + fdr.DiesErrorTaskNames[i][j]);
                                }
                            }
                        }
                    }


                    fmTips.AddOneTips(sbInfo.ToString());
                    rchRDetectInfo.AppendText(sbInfo.ToString());

                    //将Fov检测项填入表格
                    dgvDetectItems.Rows.Clear();
                    if (null != fdr.DieInspectResults)
                    {
                        bool _isShowAllItems = !chkJustShowNG.Checked;


                        int dieIndex = 0;
                        int dieCount = fdr.CurrColCount * fdr.CurrRowCount;
                        if (dieCount <= 0)//Fov只是Die的一部分
                        {
                            dieCount = 1;
                        }
                        //表格行 : Die/检测项/检测结果/检测标准数据/检测结果数据/备注
                        for (dieIndex = 0; dieIndex < dieCount; dieIndex++)
                        {
                            if (!fdr.IsDetectSuccess) //视觉算子出错
                            {
                                DataGridViewRow row = new DataGridViewRow();

                                DataGridViewTextBoxCell dieIndexCell = new DataGridViewTextBoxCell();
                                dieIndexCell.Style.BackColor         = Color.Red;
                                dieIndexCell.Value = dieIndex + 1;
                                row.Cells.Add(dieIndexCell);


                                DataGridViewTextBoxCell detectItemCell = new DataGridViewTextBoxCell();
                                detectItemCell.Value           = "---";
                                detectItemCell.Style.ForeColor = Color.Red;
                                row.Cells.Add(detectItemCell);

                                DataGridViewTextBoxCell dieErrorCell = new DataGridViewTextBoxCell();
                                dieErrorCell.Value           = "检测出错:" + fdr.DetectErrorInfo;
                                dieErrorCell.Style.ForeColor = Color.Red;
                                row.Cells.Add(dieErrorCell);



                                DataGridViewTextBoxCell dieDetectVelCell = new DataGridViewTextBoxCell();
                                dieDetectVelCell.Value           = "---";
                                dieDetectVelCell.Style.ForeColor = Color.Red;
                                row.Cells.Add(dieDetectVelCell);


                                DataGridViewTextBoxCell dieRefVelCell = new DataGridViewTextBoxCell();
                                dieRefVelCell.Value           = "---";
                                dieRefVelCell.Style.ForeColor = Color.Red;
                                row.Cells.Add(dieRefVelCell);

                                DataGridViewTextBoxCell dieRemarksCell = new DataGridViewTextBoxCell();
                                string rowColInfo              = "Die:" + (dieIndex + 1) + " 行:" + (dieIndex / dieCount + 1) + " 列:" + (dieIndex % dieCount + 1);
                                dieRemarksCell.Value           = rowColInfo;
                                dieRemarksCell.Style.ForeColor = Color.Red;
                                row.Cells.Add(dieRemarksCell);


                                dgvDetectItems.Rows.Add(row);
                            }
                            else //检测成功,列出每个检测项
                            {
                                for (int i = 0; i < fdr.DieInspectResults[dieIndex].Length; i++)
                                {
                                    if (!_isShowAllItems && fdr.DieInspectResults[dieIndex][i].IsDetectOK())
                                    {
                                        continue;
                                    }
                                    DataGridViewRow row = new DataGridViewRow();
                                    Color txtColor      = Color.DarkGreen;
                                    if (!DlafFovDetectResult.IsInspectItemsOK(fdr.DieInspectResults[dieIndex]))
                                    {
                                        txtColor = Color.DarkRed;
                                    }
                                    DataGridViewTextBoxCell dieIndexCell = new DataGridViewTextBoxCell();
                                    dieIndexCell.Style.ForeColor         = txtColor;
                                    dieIndexCell.Value = dieIndex + 1;
                                    row.Cells.Add(dieIndexCell);

                                    DataGridViewTextBoxCell detectItemCell = new DataGridViewTextBoxCell();
                                    detectItemCell.Value           = fdr.DieInspectResults[dieIndex][i].InspectID;
                                    detectItemCell.Style.ForeColor = fdr.DieInspectResults[dieIndex][i].IsDetectOK() ? Color.DarkGreen : Color.DarkRed;
                                    row.Cells.Add(detectItemCell);

                                    DataGridViewTextBoxCell dieErrorCell = new DataGridViewTextBoxCell();
                                    dieErrorCell.Value           = string.Join(" ", fdr.DieInspectResults[dieIndex][i].ErrorTexts);
                                    dieErrorCell.Style.ForeColor = fdr.DieInspectResults[dieIndex][i].IsDetectOK() ? Color.DarkGreen : Color.DarkRed;
                                    row.Cells.Add(dieErrorCell);


                                    DataGridViewTextBoxCell dieRefVelCell = new DataGridViewTextBoxCell();
                                    dieRefVelCell.Value = fdr.DieInspectResults[dieIndex][i].QualifiedDescript;
                                    //dieRefVelCell.Style.ForeColor = fdr.DieInspectResults[dieIndex][i].IsDetectOK() ? Color.DarkGreen : Color.DarkRed;
                                    row.Cells.Add(dieRefVelCell);


                                    DataGridViewTextBoxCell dieDetectVelCell = new DataGridViewTextBoxCell();
                                    dieDetectVelCell.Value = fdr.DieInspectResults[dieIndex][i].ResultDescript;
                                    row.Cells.Add(dieDetectVelCell);

                                    DataGridViewTextBoxCell dieRemarksCell = new DataGridViewTextBoxCell();
                                    string rowColInfo    = "Die:" + (dieIndex + 1) + " 行:" + (dieIndex / dieCount + 1) + " 列:" + (dieIndex % dieCount + 1);
                                    dieRemarksCell.Value = rowColInfo;
                                    row.Cells.Add(dieRemarksCell);


                                    dgvDetectItems.Rows.Add(row);
                                }
                            }
                        }
                    }
                }
                else if (CMC_DieResults == msgCategory)
                {
                    InspectionData[] inspDatas = msgParams[0] as InspectionData[];
                    if (null == inspDatas)
                    {
                        return;
                    }
                    _lstInspectData.AddRange(inspDatas);
                    foreach (InspectionData inspData in inspDatas)
                    {
                        mappCtrl.SetDieState(inspData.RowIndex, inspData.ColumnIndex, inspData.InspectionResult == InspectionResults.OK ? "合格" : "不合格");
                    }
                }
                else if (CMC_PieceFinished == msgCategory)
                {
                    bool isOnLineReview        = (bool)JFHubCenter.Instance.SystemCfg.GetItemValue("在线复判");
                    string recipeID            = msgParams[0] as string;
                    string lotID               = msgParams[1] as string;
                    string pieceID             = msgParams[2] as string;
                    string inspectResultFolder = msgParams[3] as string;
                    string pictureFolder       = msgParams[4] as string;
                    rchRDetectInfo.AppendText(DateTime.Now.ToString("HH:mm:ss.fff") + " " + recipeID + " 检测完成");
                    if (!isOnLineReview)
                    {
                        fmTips.AddOneTips(msgParams[0] + " 检测完成");
                    }
                    else
                    {
                        FormDLAFReview fm = new FormDLAFReview();
                        fm.SetReviewParam(recipeID, lotID, pieceID, inspectResultFolder + "\\" + recipeID + ".db", pictureFolder);
                        fm.ShowDialog();
                        JFHubCenter.Instance.DataPool.SetItemValue("检测工站:在线复判完成", true);
                    }
                }
                else
                {
                }
            }));
        }