string JTJFResultStatToStr(JTJResult jtjResult)
        {
            string str = string.Empty;

            switch (jtjResult.result)
            {
            case JTJResult.JTJF_STAT_PLUS:
                str = "阳性";
                break;

            case JTJResult.JTJF_STAT_MINUS:
                str = "阴性";
                break;

            case JTJResult.JTJF_STAT_INVALID:
                str = "无效";
                break;

            //case JTJResult.JTJF_STAT_Lee:
            //    str = "有效";
            //    break;
            default:
                str = "错误";
                break;
            }
            return(str);
        }
        private JTJResult CalJTJFResult(byte CValue, byte TValue, DYJTJItemPara mItem)
        {
            JTJResult jtjResult = new JTJResult();

            if (CValue <= mItem.InvalidC)
            {
                //C线不显色为无效
                jtjResult.result = JTJResult.JTJF_STAT_INVALID;
            }
            else
            {
                switch (mItem.Method)
                {
                //定性消线
                case DYJTJItemPara.METHOD_DXXX:
                {
                    double a = TValue;
                    double f = mItem.dlt.A0 + mItem.dlt.A1 * a + mItem.dlt.A2 * a * a + mItem.dlt.A3 * a * a * a;
                    jtjResult.density = f = mItem.dlt.B0 * f + mItem.dlt.B1;

                    if (TValue <= mItem.dxxx.PlusT)
                    {
                        jtjResult.result = JTJResult.JTJF_STAT_PLUS;
                    }
                    else if (TValue > mItem.dxxx.MinusT)
                    {
                        jtjResult.result = JTJResult.JTJF_STAT_MINUS;
                    }
                }
                break;

                case DYJTJItemPara.METHOD_DXBS:
                {
                    double a = TValue;
                    double f = mItem.dlt.A0 + mItem.dlt.A1 * a + mItem.dlt.A2 * a * a + mItem.dlt.A3 * a * a * a;
                    jtjResult.density = f = mItem.dlt.B0 * f + mItem.dlt.B1;
                    if (TValue < CValue)        // 阳性
                    {
                        jtjResult.result = JTJResult.JTJF_STAT_PLUS;
                    }
                    else
                    {
                        jtjResult.result = JTJResult.JTJF_STAT_MINUS;
                    }
                }
                break;

                case DYJTJItemPara.METHOD_DLT:
                {
                    double a = TValue;
                    double f = mItem.dlt.A0 + mItem.dlt.A1 * a + mItem.dlt.A2 * a * a + mItem.dlt.A3 * a * a * a;
                    jtjResult.density = f = mItem.dlt.B0 * f + mItem.dlt.B1;
                    if (f > mItem.dlt.Limit)
                    {
                        jtjResult.result = JTJResult.JTJF_STAT_PLUS;
                    }
                    else
                    {
                        jtjResult.result = JTJResult.JTJF_STAT_MINUS;
                    }
                }
                break;

                case DYJTJItemPara.METHOD_DLTC:
                {
                    double a = CValue == 0 ? 1 : TValue * 1.0 / CValue;
                    double f = mItem.dltc.A0 + mItem.dltc.A1 * a + mItem.dltc.A2 * a * a + mItem.dltc.A3 * a * a * a;
                    jtjResult.density = f = mItem.dltc.B0 * f + mItem.dltc.B1;
                    if (f > mItem.dltc.Limit)
                    {
                        jtjResult.result = JTJResult.JTJF_STAT_PLUS;
                    }
                    else
                    {
                        jtjResult.result = JTJResult.JTJF_STAT_MINUS;
                    }
                }

                break;
                }
            }
            return(jtjResult);
        }
        private void ShowResult()
        {
            int sampleNum = _item.SampleNum;
            // 画出灰度曲线
            List <Canvas>  canvases                = UIUtils.GetChildObjects <Canvas>(WrapPanelChannel, "canvas");
            List <TextBox> listTextBoxGray         = UIUtils.GetChildObjects <TextBox>(WrapPanelChannel, "textBoxGrayValue");
            List <TextBox> listTextBoxDetectResult = UIUtils.GetChildObjects <TextBox>(WrapPanelChannel, "textBoxDetectResult");
            List <TextBox> listJudgmentRes         = UIUtils.GetChildObjects <TextBox>(WrapPanelChannel, "textJugmentResult");
            List <TextBox> listStandValue          = UIUtils.GetChildObjects <TextBox>(WrapPanelChannel, "textStandValue");

            _listJudmentValue = listJudgmentRes;
            int    num = 0;
            double val = 0;

            for (int i = 0; i < Global.deviceHole.SxtCount; ++i)
            {
                if (_item.Hole[i].Use)
                {
                    int nLineWidth = 5;
                    int TOffset    = WeitiaoCT(_listGrayValues[i], _helpBoxes[i].TLineOffset, nLineWidth);
                    int COffset    = WeitiaoCT(_listGrayValues[i], _helpBoxes[i].CLineOffset, nLineWidth);

                    int TValue = 0;
                    // 向前数5格
                    for (int n = 0; n < nLineWidth; ++n)
                    {
                        TValue += _listGrayValues[i][TOffset - n];
                    }
                    TValue /= nLineWidth;
                    int CValue = 0;
                    for (int n = 0; n < nLineWidth; ++n)
                    {
                        CValue += _listGrayValues[i][COffset - n];
                    }
                    CValue /= nLineWidth;
                    DrawGrayCurve(canvases[i], _listGrayValues[i], COffset, TOffset);
                    if (cValues[i] > 0 || tValues[i] > 0)
                    {
                        CValue = cValues[i] / nLineWidth;
                        TValue = tValues[i] / nLineWidth;
                    }
                    JTJResult jtjResult = CalJTJFResult((byte)CValue, (byte)TValue, _item);
                    listTextBoxGray[i].Text = "C(" + CValue + ") T(" + TValue + ")";
                    string   str = string.Empty;
                    string[] UnqualifiedValue = new string[4];
                    str = JTJFResultStatToStr(jtjResult);
                    UnqualifiedValue = TestResultConserve.UnqualifiedOrQualified("0", _item.Hole[i].SampleName, _item.Name);

                    //定性消线
                    if (_item.Method == DYJTJItemPara.METHOD_DXXX)
                    {
                        val = 0;
                        if (str == "阳性")
                        {
                            _listJudmentValue[i].Text = "阳性";
                            listJudgmentRes[i].Text   = "不合格";
                            UnqualifiedValue[0]       = "不合格";
                        }
                        else if (str == "阴性")
                        {
                            _listJudmentValue[i].Text = "阴性";
                            listJudgmentRes[i].Text   = "合格";
                            UnqualifiedValue[0]       = "合格";
                        }
                        else
                        {
                            _listJudmentValue[i].Text = "无效";
                            listJudgmentRes[i].Text   = "无效";
                            UnqualifiedValue[0]       = "无效";
                        }
                    }
                    //2016年10月13日 wenj
                    //新版本判定方法:Abs(C-T)≥Abs_X时 C≥T阳性 C<T阴性;Abs(C-T)<Abs_X时 SexIdx=0阴性 =1阳性 =2可疑
                    //2017年10月12日 wenj 最新版比色法判定方法:C/T≤Abs_X 阴性
                    else if (_item.Method == DYJTJItemPara.METHOD_DXBS)
                    {
                        val = 0;
                        //综合C值<15则无效
                        //if (CValue > 15)
                        if (CValue > _item.InvalidC)
                        {
                            double ctAbs = (double)CValue / (double)TValue;
                            val = ctAbs;
                            if (ctAbs <= _item.dxbs.Abs_X)
                            {
                                _listJudmentValue[i].Text = str = "阴性";
                                listJudgmentRes[i].Text   = "合格";
                                UnqualifiedValue[0]       = "合格";
                            }
                            else
                            {
                                _listJudmentValue[i].Text = str = "阳性";
                                listJudgmentRes[i].Text   = "不合格";
                                UnqualifiedValue[0]       = "不合格";
                            }
                        }
                        else
                        {
                            _listJudmentValue[i].Text       = str = "无效";
                            _listJudmentValue[i].FontWeight = FontWeights.Bold;
                            _listJudmentValue[i].Foreground = new SolidColorBrush(Color.FromRgb(255, 0, 0));
                            listJudgmentRes[i].Text         = "无效";
                            listJudgmentRes[i].FontWeight   = FontWeights.Bold;
                            listJudgmentRes[i].Foreground   = new SolidColorBrush(Color.FromRgb(255, 0, 0));
                            UnqualifiedValue[0]             = "无效";
                        }
                    }
                    //2017年6月25日 wenj 新增 定性比色法(T/C) T/C≤Abs_X为阳性,T/C>Abs_X为阴性
                    else if (_item.Method == DYJTJItemPara.METHOD_DXBS_TC)
                    {
                        val = 0;
                        if (CValue > _item.InvalidC)
                        {
                            float ctAbs = (float)TValue / CValue;
                            val = ctAbs;
                            if (ctAbs <= _item.dxbs.Abs_X)
                            {
                                _listJudmentValue[i].Text = str = "阳性";
                                listJudgmentRes[i].Text   = "不合格";
                                UnqualifiedValue[0]       = "不合格";
                            }
                            else
                            {
                                _listJudmentValue[i].Text = str = "阴性";
                                listJudgmentRes[i].Text   = "合格";
                                UnqualifiedValue[0]       = "合格";
                            }
                        }
                        else
                        {
                            _listJudmentValue[i].Text = str = "无效";
                            listJudgmentRes[i].Text   = "无效";
                            UnqualifiedValue[0]       = "无效";
                        }
                    }
                    //else
                    //{
                    //    str = String.Format("{0:F3}", jtjResult.density);
                    //    //UnqualifiedValue = TestResultConserve.UnqualifiedOrQualified(str, _item.Hole[i].SampleName, _item.Name);
                    //    _listJudmentValue[i].Text = str;
                    //    listJudgmentRes[i].Text = str;
                    //    listStandValue[i].Text = Convert.ToString(UnqualifiedValue[2]);
                    //}

                    UnqualifiedValue = UnqualifiedOrQualified(str);

                    if (!_listJudmentValue[i].Text.Trim().Equals("合格"))
                    {
                        _listJudmentValue[i].Foreground = new SolidColorBrush(Colors.Red);
                    }

                    //判定合格不合格
                    listTextBoxDetectResult[i].Text = str;
                    _listDetectResult.Add(str); // 检测结果,要么是阴阳性,要么是浓度值。

                    _CheckValue[(num > 0 ? (i - num) : i), 0]  = String.Format("{0:D2}", (i + 1));
                    _CheckValue[(num > 0 ? (i - num) : i), 1]  = "胶体金";
                    _CheckValue[(num > 0 ? (i - num) : i), 2]  = _item.Name;
                    _CheckValue[(num > 0 ? (i - num) : i), 3]  = _methodToString[_item.Method];
                    _CheckValue[(num > 0 ? (i - num) : i), 4]  = str;
                    _CheckValue[(num > 0 ? (i - num) : i), 5]  = _item.Unit;
                    _CheckValue[(num > 0 ? (i - num) : i), 6]  = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    _CheckValue[(num > 0 ? (i - num) : i), 7]  = LoginWindow._userAccount.UserName;
                    _CheckValue[(num > 0 ? (i - num) : i), 8]  = string.IsNullOrEmpty(_item.Hole[i].SampleName) ? string.Empty : _item.Hole[i].SampleName;
                    _CheckValue[(num > 0 ? (i - num) : i), 9]  = UnqualifiedValue[0];
                    _CheckValue[(num > 0 ? (i - num) : i), 10] = Convert.ToString(UnqualifiedValue[2]);
                    _CheckValue[(num > 0 ? (i - num) : i), 11] = String.Format("{0:D5}", sampleNum++);
                    _CheckValue[(num > 0 ? (i - num) : i), 12] = Convert.ToString(UnqualifiedValue[1]);
                    _CheckValue[(num > 0 ? (i - num) : i), 13] = _item.Hole[i].TaskName ?? string.Empty;
                    _CheckValue[(num > 0 ? (i - num) : i), 14] = string.IsNullOrEmpty(_item.Hole[i].CompanyName) ? string.Empty : _item.Hole[i].CompanyName;
                    _CheckValue[(num > 0 ? (i - num) : i), 15] = string.IsNullOrEmpty(_item.Hole[i].SampleId) ? string.Empty : _item.Hole[i].SampleId;
                    _CheckValue[(num > 0 ? (i - num) : i), 16] = _item.Hole[i].ProduceCompany;

                    //经营户
                    //DataTable dtblB = opr.GetAsDataTable("Ks_Business", string.Format(" ID = '{0}'", _item.Hole[i].CompanyCode), out errMsg);
                    //if (dtblB != null && dtblB.Rows.Count > 0)
                    //{
                    //    _CheckValue[(num > 0 ? (i - num) : i), 17] = dtblB.Rows[0]["IdentityCard"].ToString();
                    //    _CheckValue[(num > 0 ? (i - num) : i), 18] = dtblB.Rows[0]["TWNum"].ToString();
                    //    _CheckValue[(num > 0 ? (i - num) : i), 19] = dtblB.Rows[0]["TWNume"].ToString();
                    //}
                    DataTable dtblB = opr.GetAsDataTable("Ks_Business", string.Format(" ID = '{0}'", _item.Hole[i].CompanyCode), out errMsg);
                    if (dtblB != null && dtblB.Rows.Count > 0)
                    {
                        _CheckValue[(num > 0 ? (i - num) : i), 17] = dtblB.Rows[0]["IdentityCard"].ToString();
                        _CheckValue[(num > 0 ? (i - num) : i), 18] = dtblB.Rows[0]["TWNum"].ToString();
                        _CheckValue[(num > 0 ? (i - num) : i), 19] = dtblB.Rows[0]["TWNume"].ToString();
                        dtblB = opr.GetAsDataTable("ks_AreaMarket", string.Format(" LicenseNo = '{0}'", dtblB.Rows[0]["LicenseNo"].ToString()), out errMsg);
                        if (dtblB != null && dtblB.Rows.Count > 0)
                        {
                            _CheckValue[(num > 0 ? (i - num) : i), 14] = dtblB.Rows[0]["MarketName"].ToString() + "|" +
                                                                         dtblB.Rows[0]["LicenseNo"].ToString() + "|" + GetMarketType(dtblB.Rows[0]["MarketRef"].ToString());
                        }
                    }
                    else
                    {
                        dtblB = opr.GetAsDataTable("ks_AreaMarket", string.Format(" LicenseNo = '{0}'", _item.Hole[i].CompanyCode), out errMsg);
                        if (dtblB != null && dtblB.Rows.Count > 0)
                        {
                            _CheckValue[(num > 0 ? (i - num) : i), 14] = dtblB.Rows[0]["MarketName"].ToString() + "|" +
                                                                         dtblB.Rows[0]["LicenseNo"].ToString() + "|" + GetMarketType(dtblB.Rows[0]["MarketRef"].ToString());
                        }
                    }
                    //样品品类
                    _CheckValue[(num > 0 ? (i - num) : i), 20] = _item.Hole[i].SampleCode;
                    _CheckValue[(num > 0 ? (i - num) : i), 21] = _item.Hole[i].SampleName;

                    //项目
                    DataTable dtblC = opr.GetAsDataTable("Ks_CheckItem", string.Format(" ItemName = '{0}'", _item.Name), out errMsg);
                    if (dtblC != null && dtblC.Rows.Count > 0)
                    {
                        _CheckValue[(num > 0 ? (i - num) : i), 22] = dtblC.Rows[0]["ParentCode"].ToString();
                        _CheckValue[(num > 0 ? (i - num) : i), 23] = dtblC.Rows[0]["ItemCode"].ToString();
                    }
                    else
                    {
                        dtblC = opr.GetAsDataTable("Ks_CheckItem", string.Format(" ParentName = '{0}'", _item.Name), out errMsg);
                        if (dtblC != null && dtblC.Rows.Count > 0)
                        {
                            _CheckValue[(num > 0 ? (i - num) : i), 22] = dtblC.Rows[0]["ParentCode"].ToString();
                            _CheckValue[(num > 0 ? (i - num) : i), 23] = dtblC.Rows[0]["ItemCode"].ToString();
                        }
                    }
                }
                else
                {
                    num += 1;
                    _listStrRecord.Add(null);
                    _listDetectResult.Add(null);
                }
            }
        }