Exemplo n.º 1
0
        /// <summary>
        ///     '设备标准接口
        //'功能:解析数据
        //'参数:
        //'strSource:要解析的原始串
        //'strResult:返回的检验结果(各仪器解析程序必须按以下标准组织结果)
        //'   每组检验结果以||分隔,元素之间以|分隔
        //'   第0个元素:检验时间
        //'   第1个元素:样本序号(标本号^条码号^样本类型)
        //'   第2个元素:检验人
        //'   第3个元素:标本
        //'   第4个元素:预留
        //'   从第5个元素开始为检验结果,每2个元素表示一个检验项目。
        //'       如:第5i个元素为检验项目,第5i+1个元素为检验结果
        //'strReserved:最后不能完成解析的原始串,需要返回作后续处理
        //'strCmd:如果需要,可返回向设备发送的命令
        //'补充图像的方式:
        //'                   1.图像数据跟随指标数据后,使用回车换行符来分隔。
        //'                   2.有多个图像数据时使用"^"来分隔
        //'                   3.单个图像数据格式: 图像画法 0=直方图  1=散点图
        //'                     a) 直方图: 图像名称;图像画法(0=直方图  1=散点图);X1;X2;X3;X4;X5...
        //'                     b) 散点图: 图像名称;图像画法(0=直方图  1=散点图):
        //'                        例:00000100001000010000100010;00000100001000010000100010;
        //'                        说明:1.散点图以点阵方式保存每一行使用分号来分隔.
        //'                             2.有多少个分号就有多少行
        //'                             3.每一行有多少个点由每一行的长度来确定
        //'                             3.画图的方向是从最上边向下画,如有65*65的图就是从65行开始画(最上边开始画)



        /// <summary>
        /// 设备标准接口[解析数据]
        /// </summary>
        /// <param name="strSource">原始字符串</param>
        /// <param name="strResult">
        /// 返回的检验结果(各仪器解析程序必须按以下标准组织结果)
        //'   每组检验结果以||分隔,元素之间以|分隔
        //'   第0个元素:检验时间
        //'   第1个元素:样本序号(标本号^条码号^样本类型)
        //'   第2个元素:检验人
        //'   第3个元素:标本
        //'   第4个元素:预留
        //'   从第5个元素开始为检验结果,每2个元素表示一个检验项目。
        //'       如:第5i个元素为检验项目,第5i+1个元素为检验结果</param>
        /// <param name="strReserved">最后不能完成解析的原始串,需要返回作后续处理</param>
        /// <param name="strCmd">如果需要,可返回向设备发送的命令</param>
        public void ParseResult(string strSource, ref string strResult, ref string strReserved, ref string strCmd)
        {
            string  channel          = "0";
            string  testItemID       = "";
            string  result           = "";
            decimal CONVERSION_RATIO = 0;
            decimal DECIMAL_LEVEL    = 2;
            string  ParString        = "";
            string  SingleResult     = "";
            string  ResultString     = "";
            string  UnknownResult    = ""; //未知项目
            string  TempCmd          = "";

            DataSet ds_GraphChannel = new DataSet();
            DataSet dsGUID          = new DataSet();
            DataSet dsTestItem      = new DataSet();

            string TestResultInfo = "";

            strReserved = "";
            strResult   = "";
            strCmd      = "";
            //原始串为空、开始字符为空、结束字符为空时退出
            if (String.IsNullOrEmpty(strSource))
            {
                return;
            }
            if (String.IsNullOrEmpty(StrChange(strDataBegin)) || String.IsNullOrEmpty(StrChange(strDataEnd)))
            {
                writelog.Write(strDevice, !String.IsNullOrEmpty(strDataBegin) ? "开始字符未设置!" : "结束字符未设置", "log");
                strReserved = strSource;
                return;
            }
            else if (strSource.IndexOf(StrChange(strDataBegin)) == -1 || strSource.IndexOf(StrChange(strDataEnd)) == -1)
            //原始串不是一条安装结果数据时退出
            {
                strReserved = strSource;
                return;
            }

            writelog.Write(strDevice, strSource, "raw"); //原始串日志
            TempCmd = StrChange(strACK_term);
            if (!String.IsNullOrEmpty(StrChange(strACK_all)))
            {
                strCmd = StrChange(strACK_all);
            }
            else if (strSource.IndexOf(TempCmd) >= 0 && !String.IsNullOrEmpty(TempCmd))
            {
                //返回条件应答
                Init_COM ic = new Init_COM();
                strCmd = ic.GetCmd(strSource, TempCmd);
            }
            if (strSubEnd == @"\n")
            {
                strSubEnd = ((char)10).ToString();
            }
            saveResult = new SaveResult();

            #region 通过结束符分段解析
            while (strSource.IndexOf(StrChange(strDataEnd)) >= 0)
            {   //通过结束符分段解析
                ResultString = strSource.Substring(strSource.IndexOf(StrChange(strDataBegin)) + StrChange(strDataBegin).Length, strSource.IndexOf(StrChange(strDataEnd)));
                strSource    = strSource.Substring(strSource.IndexOf(StrChange(strDataEnd)) + StrChange(strDataEnd).Length);
                if (String.IsNullOrEmpty(ResultString))
                {
                    return;
                }
                TestResultValue = "";
                UnknownResult   = "";
                //初始化
                init();
                //writelog.Write("ResultString" + ResultString, "log");
                //writelog.Write("strdetype" + strdetype, "log");
                if (strDetype == "1") //单帧
                {
                    begin = -1;
                    end   = ResultString.Length;
                }
                else if (strDetype == "2") //多帧
                {                          //根据多帧开始位计算开始位置
                    if (string.IsNullOrEmpty(strSubBegin))
                    {
                        begin = -1;
                    }
                    else
                    {
                        if (strSubBegin.IndexOf('<') >= 0 && strSubBegin.IndexOf('>') >= 0)
                        {
                            if (strSubBegin == "<10>")
                            {
                                begin = ResultString.IndexOf("\n");
                            }
                            else
                            {
                                begin = ResultString.IndexOf((char)int.Parse(strSubBegin.Replace("<", "").Replace(">", "")));
                            }
                        }
                        else
                        {
                            begin = ResultString.IndexOf(strSubBegin);
                        }
                    }//根据多帧结束位计算结束位置
                    if (strSubEnd.IndexOf('<') >= 0 && strSubEnd.IndexOf('>') >= 0)
                    {
                        if (begin == -1)
                        {
                            end = ResultString.IndexOf((char)int.Parse(strSubEnd.Replace("<", "").Replace(">", "")));
                        }
                        else
                        {
                            end = ResultString.IndexOf((char)int.Parse(strSubEnd.Replace("<", "").Replace(">", "")), begin);
                        }
                    }
                    else
                    {
                        end = ResultString.IndexOf(strSubEnd, begin);
                    }
                }

                subString = ResultString;
                #region 分段取数据
                while (true)
                {
                    //分段取数据
                    if (String.IsNullOrEmpty(strSubBegin) && begin != -1)
                    {
                        begin = begin - 1;
                    }
                    ParString = subString.Substring(begin + 1, end - begin - 1);  //本次解析数据
                    if (DrTestTimeField == null && string.IsNullOrEmpty(strTestTime))
                    {
                        strTestTime = dsHandle.GetDataSet("to_char(sysdate,'yyyy-MM-dd HH24:mi:ss')", "dual", "").Tables[0].Rows[0][0].ToString();
                    }
                    //检验日期不为空
                    #region :获取检验日期、样本号
                    if (DrTestTimeField != null && string.IsNullOrEmpty(strTestTime))
                    {
                        //检验日期标识不为空
                        if (DrTestTimeSignField != null)
                        {
                            if (GetDate(ParString, DrTestTimeSignField).Trim() == DrTestTimeSignField["sign"].ToString())
                            {
                                strTestTime = GetDate(ParString, DrTestTimeField).Trim();
                            }
                        }
                        else
                        {
                            strTestTime = GetDate(ParString, DrTestTimeField).Trim();
                        }
                        //writelog.Write("strTestTime" + strTestTime, "log");
                        if (!String.IsNullOrEmpty(strTestTime))
                        {
                            dsGUID = dsHandle.GetDataSet("to_char(sysdate,'yyyy')", "dual", "");
                            //先将时间转换为yyyyMMddHHmmss格式
                            try
                            {
                                if (DrTestTimeField["FORMAT"].ToString() == "yyyyMMddHHmm")
                                {
                                    strTestTime = strTestTime + "00";
                                }
                                else if (DrTestTimeField["FORMAT"].ToString() == "yyyyMMdd")
                                {
                                    strTestTime = strTestTime + dsHandle.GetDataSet("to_char(sysdate,'HH24miss')", "dual", "").Tables[0].Rows[0][0].ToString();
                                }
                                else if (DrTestTimeField["FORMAT"].ToString() == "yyMMdd")
                                {
                                    strTestTime = dsGUID.Tables[0].Rows[0][0].ToString().Substring(0, 2) + strTestTime + dsHandle.GetDataSet("to_char(sysdate,'HH24miss')", "dual", "").Tables[0].Rows[0][0].ToString();
                                }
                                else if (DrTestTimeField["FORMAT"].ToString() == "yyMMddHHmm")
                                {
                                    strTestTime = dsGUID.Tables[0].Rows[0][0].ToString().Substring(0, 2) + strTestTime + "00";
                                }
                                else if (DrTestTimeField["FORMAT"].ToString() == "yyMMddHHmmss")
                                {
                                    strTestTime = dsGUID.Tables[0].Rows[0][0].ToString().Substring(0, 2) + strTestTime;
                                }
                                else if (DrTestTimeField["FORMAT"].ToString() == "MMddHHmmss")
                                {
                                    strTestTime = dsGUID.Tables[0].Rows[0][0].ToString().Substring(0, 4) + strTestTime;
                                }
                                else if (DrTestTimeField["FORMAT"].ToString() == "MMddyyHHmm")
                                {
                                    strTestTime = dsGUID.Tables[0].Rows[0][0].ToString().Substring(0, 2) + strTestTime.Substring(4, 2) + strTestTime.Substring(0, 4) + strTestTime.Substring(6, 4) + "00";
                                }
                                else if (DrTestTimeField["FORMAT"].ToString() == "yyyy-MM-dd")
                                {
                                    strTestTime = Convert.ToDateTime(strTestTime).ToString("yyyy-MM-dd");                                                            //+ dsHandle.GetDataSet("to_char(sysdate,'HH24miss')", "dual", "").Tables[0].Rows[0][0].ToString();
                                }
                                else if (DrTestTimeField["FORMAT"].ToString() == "dd/MM/yy HH[h]mm[mn]dd[s]")
                                {
                                    strTestTime = dsGUID.Tables[0].Rows[0][0].ToString().Substring(0, 2) + strTestTime.Substring(6, 2) + strTestTime.Substring(3, 2) + strTestTime.Substring(0, 2) + strTestTime.Substring(9, 2) + strTestTime.Substring(14, 2) + strTestTime.Substring(20, 2);
                                }
                                else if (DrTestTimeField["FORMAT"].ToString() == "HHmmssyyMMdd")
                                {
                                    strTestTime = dsGUID.Tables[0].Rows[0][0].ToString().Substring(0, 2) + strTestTime.Substring(6, 6) + strTestTime.Substring(0, 6);
                                }
                                //writelog.Write("strTestTime" + strTestTime, "log");
                                if (DrTestTimeField["FORMAT"].ToString() != "yyyy-MM-dd HH:mm:ss")
                                {
                                    /*------0621调试去掉------*/
                                    //strTestTime = strTestTime.Substring(0, 4) + "-" + strTestTime.Substring(4, 2) + "-" + strTestTime.Substring(6, 2) + " " + strTestTime.Substring(8, 2) + ":" + strTestTime.Substring(10, 2) + ":" + strTestTime.Substring(12, 2);
                                }
                            }
                            catch (Exception e)
                            {
                                writelog.Write(strDevice, "解析检验时间出错:" + e.Message + "(请在[检验仪器]-[规则设置]-[解析规则]中检查项目【检验日期】)", "log");
                                return;
                            }
                        }
                    }

                    //常规样本号不为空
                    if (DrSampleNoField != null && string.IsNullOrEmpty(strSampleNo))
                    {
                        if (DrSampleNoSignField != null)
                        {
                            if (GetDate(ParString, DrSampleNoSignField).Trim() == DrSampleNoSignField["sign"].ToString())
                            {
                                strSampleNo = GetDate(ParString, DrSampleNoField).Trim();
                            }
                        }
                        else
                        {
                            strSampleNo = GetDate(ParString, DrSampleNoField).Trim();
                        }
                    }
                    #endregion ;
                    //writelog.Write("strSampleNo" + strSampleNo, "log");
                    //样本类型
                    #region :获取样本类型、条码号、检验人、标本
                    if (DrSampleTypeField == null)
                    {
                        strSampleType = "0";
                    }
                    //writelog.Write("strSampleType" + ParString, "log");
                    if (DrSampleTypeField != null && string.IsNullOrEmpty(strSampleType))
                    {
                        if (DrSampleTypeSignField != null)
                        {
                            if (GetDate(ParString, DrSampleTypeSignField).Trim() == DrSampleTypeSignField["sign"].ToString())
                            {
                                strSampleType = GetDate(ParString, DrSampleTypeField).Trim();
                            }
                        }
                        else
                        {
                            strSampleType = GetDate(ParString, DrSampleTypeField).Trim();
                        }
                        //writelog.Write("strSampleType" + strSampleType, "log");
                        if (!string.IsNullOrEmpty(strSampleType))
                        {
                            if (!string.IsNullOrEmpty(DrSampleTypeField["devset"].ToString()))
                            {
                                for (int k = 0; k < DrSampleTypeField["devset"].ToString().Split(';').Length; k++)
                                {
                                    //writelog.Write(DrSampleTypeField["devset"].ToString().Split(';')[k].ToString(), "log");
                                    if (DrSampleTypeField["devset"].ToString().Split(';')[k].ToString().ToUpper() == strSampleType.ToUpper() && k == 0)
                                    {
                                        strSampleType = "0";
                                    }
                                    if (DrSampleTypeField["devset"].ToString().Split(';')[k].ToString().ToUpper() == strSampleType.ToUpper() && k == 1)
                                    {
                                        strSampleType = "1";
                                    }
                                    //质控暂时不处理
                                    //if (DrSampleTypeField["devset"].ToString().Split(';')[k].ToString() == strSampleType && k == 2) strSampleType = "-2";
                                }
                            }
                        }
                    }

                    //writelog.Write("strSampleType" + strSampleType, "log");
                    //条码号
                    if (DrBarCodeField != null && string.IsNullOrEmpty(strBarCode))
                    {
                        if (DrBarCodeSignField != null)
                        {
                            if (GetDate(ParString, DrBarCodeSignField).Trim() == DrBarCodeSignField["sign"].ToString())
                            {
                                strBarCode = GetDate(ParString, DrBarCodeField).Trim();
                            }
                        }
                        else
                        {
                            strBarCode = GetDate(ParString, DrBarCodeField).Trim();
                        }
                    }
                    //检验人
                    strOperator = "";

                    //标本名称
                    if (DrSpecimenField == null)
                    {
                        StrSpecimen = "标本";
                    }
                    if (DrSpecimenField != null && string.IsNullOrEmpty(StrSpecimen))
                    {
                        if (DrSpecimenSignField != null)
                        {
                            if (GetDate(ParString, DrSpecimenSignField).Trim() == DrSpecimenSignField["sign"].ToString())
                            {
                                StrSpecimen = GetDate(ParString, DrSpecimenField).Trim();
                            }
                        }
                        else
                        {
                            StrSpecimen = GetDate(ParString, DrSampleTypeField).Trim();
                        }
                    }
                    #endregion ;
                    ResultFlag = true;
                    //结果标识不为空
                    if (DrResultSignField != null)
                    {
                        if (GetDate(ParString, DrResultSignField).Trim() != DrResultSignField["sign"].ToString())
                        {
                            ResultFlag = false;
                        }
                    }
                    #region :解析结果值
                    if (ResultFlag == true)
                    {
                        string ChannelType;     //0-普通结果;1-直方图;2-散点图;3-直方图界标;4-散点图界标;5-BASE64
                        if (DrResultInfoField != null)
                        {
                            TestResultInfo = GetDate(ParString, DrResultInfoField);
                        }
                        else
                        {
                            TestResultInfo = ParString;
                        }
                        while (true)
                        {
                            if (DrSingleResultField != null)
                            {
                                SingleResult = GetDate(TestResultInfo, DrSingleResultField);
                            }
                            else
                            {
                                SingleResult = TestResultInfo;
                            }
                            //writelog.Write(SingleResult, "log");
                            if (DrChannelField != null)//取通道号
                            {
                                channel = GetDate(SingleResult, DrChannelField);
                                if (!string.IsNullOrEmpty(channel))
                                {
                                    if (channel.Substring(channel.Length - 1) == "/")
                                    {
                                        channel = channel.Substring(0, channel.Length - 1);
                                    }
                                }
                            }
                            else
                            {
                                //结果值开始位为1,表明没有通道号,通道号从1开始累加
                                channel = (Convert.ToInt32(channel) + 1).ToString();
                            }
                            #region :根据通道号查询项目组成结果串
                            if (!string.IsNullOrEmpty(channel))
                            {
                                //FindRow = ds_ItemChannel.Tables[0].Select("通道编码 = '" + channel.Trim() + "'");
                                FindRow = tItemChannel.Select("通道编码='" + channel.Trim() + "'");
                                if (FindRow.Length == 0) //无普通结果则查找图像能道,无图像通道则更新通道类型为空
                                {
                                    //FindRow = ds_GraphChannel.Tables[0].Select("通道编码 = '" + channel.Trim() + "'");
                                    //if (FindRow.Length == 0) ChannelType = "";//无指标
                                    //else
                                    //{
                                    //    ChannelType = FindRow[0]["GRAPH_TYPE"].ToString();
                                    //}
                                    ChannelType = null;
                                }
                                else
                                {
                                    testItemID = FindRow[0]["项目id"].ToString();
                                    //CONVERSION_RATIO = Convert.ToDecimal(FindRow[0]["换算比"].ToString());
                                    //DECIMAL_LEVEL = Convert.ToDecimal(FindRow[0]["小数位数"].ToString());
                                    ChannelType = "0"; //普通结果
                                }
                                //是通道
                                if (!String.IsNullOrEmpty(ChannelType))
                                {
                                    result          = GetDate(SingleResult, DrResultField).Trim();
                                    TestResultValue = TestResultValue + testItemID + "^" + result.Trim() + "|";
                                    //writelog.Write(result, "log");
                                    //if (ChannelType == "0" && tItemChannel.Select("通道编码='"+channel+"'")[0]["结果类型"].ToString() == "1")//定性普通结果根据换算比、加算值重新计算结果
                                    //{
                                    //    result = GetNewResult(CONVERSION_RATIO, DECIMAL_LEVEL, result).Trim();
                                    //    TestResultValue = TestResultValue + testItemID + "^" + result.Trim() + "|";
                                    //}
                                }
                                else
                                {   //记录未知项目
                                    UnknownResult = UnknownResult + channel + "|" + GetDate(SingleResult, DrResultField).Trim() + "|";
                                }
                            }
                            #endregion ;
                            if (TestResultInfo == SingleResult)
                            {
                                break;
                            }
                            if (String.IsNullOrEmpty(SingleResult))
                            {
                                break;
                            }
                            if (String.IsNullOrEmpty(DrSingleResultField["separated_first"].ToString()) && String.IsNullOrEmpty(DrSingleResultField["separated_second"].ToString()))
                            {
                                TestResultInfo = TestResultInfo.Substring(TestResultInfo.IndexOf(SingleResult) + SingleResult.Length);//.TrimStart();
                            }
                            else
                            {
                                TestResultInfo = TestResultInfo.Substring(TestResultInfo.IndexOf(SingleResult) + SingleResult.Length + DrSingleResultField["separated_first"].ToString().Length);
                            }
                        }
                    }
                    #endregion ;
                    if (subString.Length == end)
                    {
                        break;
                    }
                    subString = subString.Substring(end + 1);
                    if (String.IsNullOrEmpty(subString))
                    {
                        break;
                    }
                    if (strSubBegin.IndexOf('<') >= 0 && strSubBegin.IndexOf('>') >= 0)
                    {
                        if (strSubBegin == "<10>")
                        {
                            begin = ResultString.IndexOf("\n");
                        }
                        begin = subString.IndexOf((char)int.Parse(strSubBegin.Replace("<", "").Replace(">", "")));
                    }
                    else
                    {
                        begin = subString.IndexOf(strSubBegin);
                    }
                    if (begin == -1)
                    {
                        begin = 0;
                    }
                    if (strSubEnd.IndexOf('<') >= 0 && strSubEnd.IndexOf('>') >= 0)
                    {
                        if (strSubEnd == "<13>")
                        {
                            end = ResultString.IndexOf("\r");
                        }
                        end = subString.IndexOf((char)int.Parse(strSubEnd.Replace("<", "").Replace(">", "")), begin);
                    }
                    else
                    {
                        end = subString.IndexOf(strSubEnd, begin);
                    }
                    if (end == -1)
                    {
                        end = subString.Length;
                    }
                }
                #endregion  //分段解析结束

                strReserved = strSource;
                //strSampleType--是否资控;strBarCode条码;strOperator检验人;StrSpecimen标本类型
                //strTestTime检验时间|strSampleNo标本号^strSampleType标本类型^strBarCode条码(样本序号)|strOperator检验人|StrSpecimen标本类型|是否质控|检验结果
                TestResultValue = strTestTime + "|" + strSampleNo + "^" + strSampleType + "^" + strBarCode + "|" + strOperator + "|" + StrSpecimen + "|" + "|" + TestResultValue;
                writelog.Write(strDevice, "解析结果: " + TestResultValue, "result");
                if (!String.IsNullOrEmpty(UnknownResult))
                {
                    writelog.Write(strDevice, "未知项目:" + UnknownResult, "result");                                      //日志写入未知项目
                }
                if (!string.IsNullOrEmpty(strSampleNo) || !string.IsNullOrEmpty(strBarCode))
                {
                    //ListImagePosition = new List<string>();
                    //ListImagePosition.Add(@"D:\新建文件夹\二院仪器数据\picture200908190075\0002\F0011.jpg;D:\新建文件夹\二院仪器数据\picture200908190075\0002\F0012.jpg");
                    //if (ListImagePosition.Count > i)
                    //{
                    //    for (int j = 0; j < ListImagePosition[i].Split(';').Length; j++)
                    //        TestGraph.Add(ListImagePosition[i].Split(';')[j].ToString());
                    //}
                    saveResult.SaveTextResult(strInstrument_id, TestResultValue, TestGraph, DrSampleNoField);
                    if (ImmediatelyUpdate)
                    {
                        saveResult.UpdateData();
                    }
                }
            }
            #endregion
            if (!ImmediatelyUpdate)
            {
                saveResult.UpdateData();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// type 调用类型
        /// 0 - 初始化
        /// 1 - 连接
        /// 9 - 断开
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public string CallDll(string para)
        {
            writeLog = new Write_Log();
            dsHandle = new DataSetHandle();
            ds       = new DataSet();

            string strInstrumentID   = "";
            string strMicroPlateID   = "";
            string strSampleNO       = "";
            string strSampleID       = "";
            string strCallSource     = "";
            string strInstrumentKind = "";
            string strPara           = "";
            string strType           = "";
            string strReadBatch      = "";
            string strDeviceId       = "";

            strInstrumentID = "";
            strType         = "";
            strMicroPlateID = "";
            strSampleID     = "";
            strSampleNO     = "";
            strCallSource   = "";

            if (boolRun)
            {
                return(strError);
            }

            Dictionary <string, string> para_dic = new Dictionary <string, string>();

            string[] para_value = para.Split(';');
            foreach (string para_col in para_value)
            {
                if (string.IsNullOrEmpty(para_col))
                {
                    break;
                }
                string[] tmp = para_col.Split('=');
                para_dic.Add(tmp[0].ToUpper(), tmp[1]);
            }
            strPara = "";
            //仪器ID
            if (para.ToUpper().IndexOf("TEST_INSTRUMENT_ID=") >= 0)
            {
                strInstrumentID = para_dic["TEST_INSTRUMENT_ID"];
                strPara         = strPara + "TEST_INSTRUMENT_ID=" + strInstrumentID + ";";
            }
            //类型
            if (para.ToUpper().IndexOf("TYPE=") >= 0)
            {
                strType = para_dic["TYPE"];
                strPara = strPara + "TYPE=" + strType + ";";
            }


            //检验标本ID
            if (para.ToUpper().IndexOf("TEST_SAMPLE_ID=") >= 0)
            {
                strSampleID = para_dic["TEST_SAMPLE_ID"];
                strPara     = strPara + "TEST_SAMPLE_ID=" + strSampleID + ";";
            }
            //标本ID
            if (para.ToUpper().IndexOf("SAMPLE_NO=") >= 0)
            {
                strSampleNO = para_dic["SAMPLE_NO"];
                if (!string.IsNullOrEmpty(strSampleNO))
                {
                    strPara = strPara + "SAMPLE_NO=" + strSampleNO + ";";
                }
            }
            //调用来源
            if (para.ToUpper().IndexOf("CALL_SOURCE=") >= 0)
            {
                strCallSource = para_dic["CALL_SOURCE"];
                strPara       = strPara + "CALL_SOURCE=" + strCallSource + ";";
            }
            //单个读取
            if (para.ToUpper().IndexOf("READ_BATCH=") >= 0)
            {
                strReadBatch = para_dic["READ_BATCH"];
                strPara      = strPara + "READ_BATCH=" + strReadBatch + ";";
            }

            if (ConnectDB.con.State != ConnectionState.Open)
            {
                ConnectDB init = new ConnectDB();
                init.DBConnect();
            }
            //处理一台电脑解析多个数据
            for (int j = 0; j < strInstrumentID.Split(',').Length; j++)
            {
                strDeviceId = strInstrumentID.Split(',')[j];
                ds          = dsHandle.GetDataSet("通讯类型,名称", "检验仪器", "ID = '" + strDeviceId + "'");
                if (ds == null || ds.Tables[0].Rows.Count == 0)
                {
                    strError = "未找到Id[" + strDeviceId + "]的仪器";
                    writeLog.Write(strError, "log");
                    break;
                }
                strCommType   = ds.Tables[0].Rows[0]["通讯类型"].ToString();
                strDeviceName = ds.Tables[0].Rows[0]["名称"].ToString();

                //strCallSource = "1";
                //BH调用exe
                if (strCallSource == "1")
                {
                    int WINDOW_HANDLER = FindWindow(null, @"解析程序");
                    if (WINDOW_HANDLER == 0)
                    //if (WINDOW_HANDLER.Equals(IntPtr.Zero))
                    {
                        strError = "解析程序未运行!";
                        MessageBox.Show(strError, "导入数据", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        writeLog.Write(strDeviceName, strError, "log");
                        break;
                    }
                    else
                    {
                        byte[] sarr = System.Text.Encoding.Default.GetBytes(strPara);
                        int    len  = sarr.Length;

                        COPYDATASTRUCT cds;
                        cds.dwData = (IntPtr)1000;
                        cds.lpData = strPara;
                        cds.cbData = len + 1;
                        SendMessage(WINDOW_HANDLER, WM_COPYDATA, 0, ref cds);
                    }
                }
                else
                {
                    if (strCommType == "1")
                    {
                        #region  时运行
                        if (strType != "9")
                        {
                            if (!dictionary_initDll_COM.ContainsKey(strDeviceName))
                            {
                                Init_COM initDll_COM = new Init_COM();


                                if (string.IsNullOrEmpty(initDll_COM.strSampleID) && !string.IsNullOrEmpty(strSampleID))
                                {
                                    initDll_COM.strSampleID = strSampleID;
                                }
                                if (string.IsNullOrEmpty(initDll_COM.strInstrumentID) && !string.IsNullOrEmpty(strInstrumentID))
                                {
                                    initDll_COM.strInstrumentID = strInstrumentID.Split(',')[j];
                                }
                                dictionary_initDll_COM.Add(strDeviceName, initDll_COM);
                            }
                        }
                        if (strType == "0")
                        {
                            //initDll_COM.Start(strDeviceId);
                            foreach (Init_COM item in dictionary_initDll_COM.Values)
                            {
                                if (string.IsNullOrEmpty(item.status))
                                {
                                    item.Start(strDeviceId);
                                }
                            }
                        }
                        else if (strType == "9")
                        {
                            //initDll_COM.Stop();
                            foreach (Init_COM item in dictionary_initDll_COM.Values)
                            {
                                item.Stop();
                                strError = item.strError;
                            }
                            dictionary_initDll_COM.Clear();
                        }
                        #endregion
                    }
                    else if (strCommType == "2")
                    {
                        if (initDll_TCP == null)
                        {
                            initDll_TCP = new Init_TCP();
                            initDll_TCP.strInstrumentID = strInstrumentID.Split(',')[j];
                        }
                        if (strType == "0")
                        {
                            initDll_TCP.Init();
                        }
                        else if (strType == "9")
                        {
                            initDll_TCP.Stop();
                        }
                        strError = initDll_TCP.strError;
                    }
                    //xt 数据库类型支持多个同时应用
                    else if (strCommType == "3")
                    {
                        if (initDll_DB == null)
                        {
                            initDll_DB = new Init_DB();
                            initDll_DB.strInstrumentID = strInstrumentID.Split(',')[j];
                            initDll_DB.strTestNO       = strSampleNO;
                            initDll_DB.Init();

                            #region  时运行
                            //if (strType != "9")
                            //{
                            //    if (!dictionary_initDll_DB.ContainsKey(strDeviceName))
                            //    {
                            //        initDll_DB = new Init_DB();


                            //        if (string.IsNullOrEmpty(initDll_DB.strTestNO) && !string.IsNullOrEmpty(strSampleID))
                            //        {
                            //            initDll_DB.strTestNO = strSampleID;
                            //        }
                            //        if (string.IsNullOrEmpty(initDll_DB.strInstrumentID) && !string.IsNullOrEmpty(strInstrumentID))
                            //        {
                            //            initDll_DB.strInstrumentID = strInstrumentID.Split(',')[j];
                            //        }
                            //        dictionary_initDll_DB.Add(strDeviceName, initDll_DB);
                            //    }

                            //}
                            //if (strType == "0")
                            //{
                            //    //initDll_COM.Start(strDeviceId);
                            //    foreach (Init_DB item in dictionary_initDll_DB.Values)
                            //    {
                            //        if (string.IsNullOrEmpty(item.status))
                            //            item.Init(strDeviceId);
                            //    }

                            //}
                            //else if (strType == "9")
                            //{
                            //    //initDll_COM.Stop();
                            //    foreach (Init_DB item in dictionary_initDll_DB.Values)
                            //    {

                            //        item.Stop();
                            //        strError = item.strError;

                            //    }
                            //    dictionary_initDll_DB.Clear();
                            //}
                            #endregion
                        }
                        strError = initDll_DB.strError;
                    }
                    else if (strCommType == "4")
                    {
                        if (initDll_TXT == null)
                        {
                            initDll_TXT = new Init_TXT();
                        }
                        initDll_TXT.strInstrumentID = strInstrumentID.Split(',')[j];
                        initDll_TXT.bnReadBatch     = (strReadBatch == "1" ? true : false);
                        initDll_TXT.Start();
                        strError = initDll_TXT.strError;
                    }
                    else
                    {
                        strError = "未设置仪器的通讯类型!";
                    }
                    if (strType == "9")
                    {
                        if (ConnectDB.con.State == ConnectionState.Open)
                        {
                            ConnectDB init = new ConnectDB();
                            init.DisConnectDB(ConnectDB.con);
                        }
                    }
                }
                if (!String.IsNullOrEmpty(strError))
                {
                    writeLog.Write(strDeviceName, strError, "log");
                }
            }
            return(strError);
        }