Ejemplo n.º 1
0
        public void Init()
        {
            //string host = "127.0.0.1";
            //   port = "6000";
            ds        = dsHandle.GetDataSet(@"Extractvalue(通讯参数, '/root/ip') As 仪器IP, Extractvalue(通讯参数, '/root/port') As 端口, Extractvalue(通讯参数, '/root/role') As 接收角色,
                                    Extractvalue(通讯参数, '/root/host') As 主机IP", "检验仪器", "id = '" + strInstrumentID + "'");
            ip        = ds.Tables[0].Rows[0]["仪器IP"].ToString();
            port      = ds.Tables[0].Rows[0]["端口"].ToString();
            role      = ds.Tables[0].Rows[0]["接收角色"].ToString();
            host_ip   = ds.Tables[0].Rows[0]["主机IP"].ToString();
            role      = role == "" ? "S" : (role.Replace("1", "S").Replace("2", "C"));
            ds        = dsHandle.GetDataSet(@"解析类型,通讯程序名,名称,备注,Extractvalue(接收规则, '/root/data_type') As data_type, Extractvalue(接收规则, '/root/data_begin') As data_begin, 
                                       Extractvalue(接收规则, '/root/data_end') As data_end, Extractvalue(接收规则, '/root/start_cmd') As start_cmd, 
                                       Extractvalue(接收规则, '/root/end_cmd') As end_cmd, Extractvalue(接收规则, '/root/ack_all') As ack_all, 
                                       Extractvalue(接收规则, '/root/ack_term') As ack_term, Extractvalue(接收规则, '/root/decode_mode') As decode_mode, 
                                       Extractvalue(接收规则, '/root/begin_bits') As begin_bits, Extractvalue(接收规则, '/root/end_bits') As end_bits", "检验仪器", "id = '" + strInstrumentID + "'");
            dataType  = ds.Tables[0].Rows[0]["data_type"].ToString();
            databegin = ds.Tables[0].Rows[0]["data_begin"].ToString();
            dataend   = ds.Tables[0].Rows[0]["data_end"].ToString();
            //inBegin = ds.Tables[0].Rows[0][3].ToString();
            //inEnd = ds.Tables[0].Rows[0][4].ToString();
            decode_mode     = ds.Tables[0].Rows[0]["decode_mode"].ToString();
            SubBegin        = ds.Tables[0].Rows[0]["begin_bits"].ToString();
            SubEnd          = ds.Tables[0].Rows[0]["end_bits"].ToString();
            ACK_term        = ds.Tables[0].Rows[0]["ack_term"].ToString();
            ACK_all         = ds.Tables[0].Rows[0]["ack_all"].ToString();
            CommProgramName = ds.Tables[0].Rows[0]["通讯程序名"].ToString();
            strDeviceName   = ds.Tables[0].Rows[0]["名称"].ToString();
            RemarkContent   = ds.Tables[0].Rows[0]["备注"].ToString();
            try
            {
                obj      = ObjectReflection.CreateObject(CommProgramName.Substring(0, CommProgramName.IndexOf(".dll")));
                IResolve = obj as IDataResolve;
                IResolve.GetRules(strInstrumentID);
            }
            catch (Exception exobj)
            {
                writeLog.Write(strDeviceName, exobj.Message, "log");
                return;
            }

            //通过线程去提取数据
            System.Threading.ParameterizedThreadStart ParStart = new System.Threading.ParameterizedThreadStart(Start);
            System.Threading.Thread threadSocket = new System.Threading.Thread(ParStart);
            object socketListen = strError;

            threadSocket.Start(socketListen);

            //Start();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 反射动态执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void AutoExecute(object sender, EventArgs e)
        {
            Write_Log wl = new Write_Log();

            try
            {
                string strResult   = "";
                string strReserved = "";
                string strCmd      = "";
                string strSource   = sqlstr + "|" + conStr + "|" + databasetype + "|" + parastr; //SQL语句+连接串+数据库类型+其他参数

                string[] s = RemarkContent.Trim().Split(new char[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
                MessageBox.Show("string[] s = RemarkContent.Trim().Split(new char[]{'|'},StringSplitOptions.RemoveEmptyEntries);" + ":" + s.ToString());
                if (s.Length > 0)
                {
                    for (int i = 0; i < s.Length; i++)
                    {
                        MessageBox.Show("s[i].Split(':')[1]" + ":" + s[i].Split(':')[1]);
                        if (s[i].IndexOf("targetDeviceID") != -1 && !string.IsNullOrEmpty(s[i].Split(':')[1]))
                        {
                            IResolve.ParseResult(strSource, ref strResult, ref s[i].Split(':')[1], ref strCmd);
                        }
                    }
                }
                else
                {
                    IResolve.ParseResult(strSource, ref strResult, ref strReserved, ref strCmd);
                }
            }
            catch (Exception ex)
            {
                wl.Write(ex.Message.ToString(), "log");
            }
        }
Ejemplo n.º 3
0
 /// <summary>
 /// 获取MySql数据表
 /// </summary>
 /// <param name="sqlstr">sql语句</param>
 /// <returns></returns>
 public static System.Data.DataTable GetDataTable(string sqlstr)
 {
     try
     {
         string cs = cnnStr;//source();
         System.Data.DataTable dataTable = new System.Data.DataTable();
         using (MySQLConnection connection = new MySQLConnection(cs))
         {
             connection.Open();
             new MySQLDataAdapter(sqlstr, connection).Fill(dataTable);
             connection.Close();
         }
         return(dataTable);
     }
     catch (Exception ex)
     {
         wg.Write("log", "MySQL错误:" + ex.ToString());
         return(null);
     }
 }
Ejemplo n.º 4
0
        /// <summary>
        /// 反射动态执行
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void AutoExecute(object sender, EventArgs e)
        {
            Write_Log wl = new Write_Log();

            try
            {
                string strResult   = "";
                string strReserved = "";
                string strCmd      = "";
                string strSource   = sqlstr + "|" + conStr + "|" + databasetype + "|" + parastr;   //SQL语句+连接串+数据库类型+其他参数
                IResolve.ParseResult(strSource, ref strResult, ref strReserved, ref strCmd);
            }
            catch (Exception ex)
            {
                wl.Write(ex.Message.ToString(), "log");
            }
        }
Ejemplo n.º 5
0
        public void AutoExecute(object sender, EventArgs e)
        {
            Write_Log wl = new Write_Log();

            try
            {
                string strResult   = "";
                string strReserved = "";
                string strCmd      = "";
                //wl.Write(DateTime.Now.ToString()+" AUTO  \r\n", "log");
                string str = @"AAAI10P190000000139501072020111342013000090007011407005287849514403230901029013444501450931641340464000000000000000100000120500782550271930162360000000000000000000000000000000000000000000000000000000000001003004008014022029037045053057060059057057053049045045044041041038039039040038037038038037035033031033031031029031031031032031034033036036038039038036035034034034034035038041041042044043045044044045047050051055056060066067069073078080087092097104110112119131133139147152162171178184195203208217220226230229232238245249254253253255254250251249249248250251250245241241240242239239234231227219213203201193193190184180176172163156146141132125116114108106105101099094088084080074069063060056054050047046043041037035032030029027025024022021021019016014013012013011011010010009008008007007006006007007007006006005005004004004004004004004004004004004003004003003003002002002002002002002002002002003003002003003003003003003003003003000000000000000000000000000000000000000000000000000000000000000000000000000001001002003004004005005005005004004003003003002002002003003003004005006006008009012014017022025031038047057069080093107124141156172188201214227237241248253254255255253248242235226218207198185177169159151144138132128120116113109106102099096094091089085083081079077075073069069066063060058057054053050047045043039037035031029028026025023021019018016015013013012012012012011011010009008008008007007006006006006005005005004004004004004004003003004003003003003003003003003003002002002002002002003002003003002003002002002002002002001001001001001001001001001001001001001001001001001001001001001001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001002003005007010014018022028035042050061072085098112126139152163175184194202211220229235242247253254255253252249246242238236235233231231231229228228228226225224223221220219218219221219218217217213210205200194188184180176173169166164163160157156156156156157158160162164166167169170171172173172171169167164161158155151148145143141139136133131129126124121118116114112111109108107106104103100097095094091089087086085085084083082081079077074072069067065064062060058057055053051049047046045045044044045046047048049050051053052052051051051051050049049049048048046045044044043042041041041042043044045047048050050051051051050049047045042040038037035034032030029028026024021019018018017017017018019020020021021021021021021021021021021";
                // IResolve.ParseResult(str, ref strResult, ref strReserved, ref strCmd);
                // IResolve.ParseResult("", ref strResult, ref strReserved, ref strCmd);
                // System.Windows.Forms.MessageBox.Show("dd");


                string[] s = RemarkContent.Trim().Split('|');
                if (s.Length > 0 && !string.IsNullOrEmpty(RemarkContent))
                {
                    for (int i = 0; i < s.Length; i++)
                    {
                        if (s[i].IndexOf("targetDeviceID") != -1 && !string.IsNullOrEmpty(s[i].Split(':')[1]))
                        {
                            IResolve.ParseResult(str, ref strResult, ref s[i].Split(':')[1], ref strCmd);
                        }
                    }
                }
                else
                {
                    IResolve.ParseResult(str, ref strResult, ref strReserved, ref strCmd);
                }
            }
            catch (Exception ex)
            {
                wl.Write(ex.Message.ToString(), "log");
            }
        }
Ejemplo n.º 6
0
        //1指定单个样本条码查询
        public DataTable GetSampleInfo(string sampleNO)
        {
            string sql = "";

            if (sampleNO.Length > 0)
            {
                sql = sqlstart + @" And j.样本条码 = '" + sampleNO.Trim() + "'" + sqlend;
            }

            writelog.Write("sqllog", sql, "log");
            DataTable dt = OracleHelper.GetDataTable(sql);

            if (dt != null && dt.Rows.Count > 0)
            {
                return(dt);
            }
            else
            {
                return(null);
            }
        }
Ejemplo n.º 7
0
        /// <summary>
        /// 保存标准检验结果到数据库
        /// </summary>
        public void SaveTextResult(string DeviceID, string ResultVale, List <string> GraphVale, DataRow drSampleNO)
        {
            aItem       = ResultVale.Split('|');
            blnAuditing = false;

            /*
             * GetUpperBound可以获取数组的最高下标。
             * GetLowerBound可以获取数组的最低下标。
             * string[,] myStrArr2=new string[,]{{"油","盐"},{"围城","晨露"},{"毛毛熊","Snoopy"}};
             * for(int i=myStrArr2.GetLowerBound(0);i<=myStrArr2.GetUpperBound(0);i++)
             * {
             * for(int i=myStrArr2.GetLowerBound(1);i<=myStrArr2.GetUpperBound(1);i++)
             * {
             * //处理每一个元素
             * }
             * }
             * 0表示二维数组的第一维,1表示数组的第二维
             */
            if (aItem.GetUpperBound(0) < 5)
            {
                return;
            }
            strData     = aItem[0];
            strSampleNO = aItem[1].Split('^')[0] != null?Convert.ToInt32(aItem[1].Split('^')[0]).ToString() : null;

            strSampleType = aItem[1].Split('^')[1];
            strBarCode    = aItem[1].Split('^')[2];
            strSample     = aItem[3];

            strBeginDate  = Convert.ToDateTime(strData).ToString("yyyy-MM-dd");
            strEndDate    = Convert.ToDateTime(strData).ToString("yyyy-MM-dd") + " 23:59:59";
            strDeviceName = OracleHelper.GetDataTable("select max(名称) from 检验仪器 where id='" + DeviceID + "'").Rows[0][0].ToString();
            if (String.IsNullOrEmpty(strBarCode))
            {
                blnQryWithSampleNO = true;
            }
            else
            {
                dsTemp = dsHandle.GetDataSet(@"j.id,申请来源,j.性别,年龄数字|| 年龄单位 as 年龄,i.出生日期,样本类型,j.记录状态", "检验记录 j,个人信息 i", "j.个人id=i.id(+) and 合并id is null and 仪器id='" + DeviceID + "' and 样本条码='" + strBarCode + "'");
                if (dsTemp.Tables[0].Rows.Count != 0)
                {
                    blnQryWithSampleNO = false;
                }
                else
                {
                    blnQryWithSampleNO = true;
                }
            }
            if (blnQryWithSampleNO)
            {
                dsTemp = dsHandle.GetDataSet(@"j.id,申请来源,j.性别,年龄数字|| 年龄单位 as 年龄,i.出生日期,样本类型,j.记录状态", "检验记录 j,个人信息 i", "j.个人id=i.id(+) and 仪器id='" + DeviceID + "' and 合并id is null and 样本序号='" + strSampleNO + "' and 核收时间 between to_date('" + strBeginDate + "','yyyy-mm-dd') and to_date('" + strEndDate + "','yyyy-MM-dd hh24:mi:ss')");
            }
            if (dsTemp == null)
            {
                writeLog.Write(strDeviceName, "dsTemp数据集为空,不保存该条数据的记录!错误查看最外层的log文件,程序自动回滚!", "log"); return;
            }
            blnWaif = false;
            if (dsTemp.Tables[0].Rows.Count == 0)    //如果未找到标本,则插入一条无主样本
            {
                blnWaif = true;
                OracleParameter[] parms = new OracleParameter[]
                {
                    new OracleParameter("机构id_In", OracleType.VarChar),
                    new OracleParameter("Id_In", OracleType.VarChar),
                    new OracleParameter("申请来源_In", OracleType.Int32),
                    new OracleParameter("单据性质_In", OracleType.Int32),
                    new OracleParameter("采集方式id_In", OracleType.VarChar),
                    new OracleParameter("样本类型_In", OracleType.VarChar),
                    new OracleParameter("样本序号_In", OracleType.VarChar),
                    new OracleParameter("核收时间_In", OracleType.DateTime),
                    new OracleParameter("仪器id_In", OracleType.VarChar)
                };
                strSampleId    = dsHandle.GetDataSet("max(机构id) as 机构id,newid", "检验仪器", "id='" + DeviceID + "'").Tables[0].Rows[0][1].ToString();
                parms[0].Value = dsHandle.GetDataSet("max(机构id) as 机构id,newid", "检验仪器", "id='" + DeviceID + "'").Tables[0].Rows[0][0].ToString();
                parms[1].Value = strSampleId;
                parms[2].Value = 0;
                parms[3].Value = 0;
                parms[4].Value = null;
                parms[5].Value = strSample;
                parms[6].Value = strSampleNO;
                parms[7].Value = Convert.ToDateTime(strData);
                parms[8].Value = DeviceID;
                OracleHelper.RunProcedure("p_检验记录_Insert", parms, ref strError);
                if (strError != "")
                {
                    writeLog.Write(strDeviceName, "执行<p_检验记录_insert>错误:" + strError, "log");
                }
                else
                {
                    writeLog.Write(strDeviceName, DateTime.Now.ToString() + "写入无主样本!\r\n检验id=" + strSampleId + ",标本号=" + strSampleNO + ",仪器id=" + DeviceID, "log");
                }
            }
            else
            {
                strSampleId = dsTemp.Tables[0].Rows[0]["id"].ToString();
                strSex      = dsTemp.Tables[0].Rows[0]["性别"].ToString();
                strAge      = dsTemp.Tables[0].Rows[0]["年龄"].ToString();
                strState    = dsTemp.Tables[0].Rows[0]["记录状态"].ToString();
                strSample   = dsTemp.Tables[0].Rows[0]["样本类型"].ToString();
                blnAuditing = dsTemp.Tables[0].Rows[0]["记录状态"].ToString() == "4";
                strBirth    = dsTemp.Tables[0].Rows[0]["出生日期"].ToString();

                writeLog.Write(strDeviceName, DateTime.Now.ToString() + "找到样本!\r\n检验id=" + strSampleId + ",标本号=" + strSampleNO + ",仪器id=" + DeviceID, "log");
            }
            if (!blnAuditing)     //未审核标本则更新检查结果
            {
                strResult = "";
                Int32 j;
                for (j = 5; j <= aItem.GetUpperBound(0); ++j)
                {
                    if (aItem[j].Contains("^"))
                    {
                        strResult = strResult + "|" + aItem[j].Split('^')[0].ToString() + "," + aItem[j].Split('^')[1].ToString();
                    }
                }
                if (strResult != "")
                {
                    strResult = strResult.Substring(1);
                    OracleParameter[] parms = new OracleParameter[]
                    {
                        new OracleParameter("记录id_In", OracleType.VarChar),
                        new OracleParameter("仪器id_In", OracleType.VarChar),
                        new OracleParameter("检验时间_In", OracleType.DateTime),
                        new OracleParameter("样本类型_In", OracleType.VarChar),
                        new OracleParameter("性别_In", OracleType.Int32),
                        new OracleParameter("出生日期_In", OracleType.DateTime),
                        new OracleParameter("检验指标_In", OracleType.VarChar),
                        new OracleParameter("备注_In", OracleType.VarChar)
                    };
                    parms[0].Value = strSampleId;
                    parms[1].Value = DeviceID;
                    parms[2].Value = Convert.ToDateTime(aItem[0].ToString());
                    parms[3].Value = strSample;
                    parms[4].Value = strSex == "男" ? 1 : (strSex == "女" ? 2 : 0);
                    parms[5].Value = strBirth == "" ? null : strBirth;
                    parms[6].Value = strResult;
                    //因调用p_检验普通结果_Batchupdate会将“检验备注”清空,固需传入以前检验备注的值
                    parms[7].Value = OracleHelper.GetOracleValue("select 检验备注 from 检验记录 where ID = '" + strSampleId + "'");    //检验备注
                    // OracleHelper.RunProcedure("p_检验普通结果_batup_bs330e", parms, ref strError);
                    OracleHelper.RunProcedure("p_检验普通结果_batchupdate", parms, ref strError);
                    if (!String.IsNullOrEmpty(strError))
                    {
                        writeLog.Write(strDeviceName, "执行<p_检验普通结果_Batchupdate>:" + strError, "log");
                        writeLog.Write(strDeviceName, "  parms[0]:" + strSampleId, "log");
                        writeLog.Write(strDeviceName, "  parms[1]:" + DeviceID, "log");
                        writeLog.Write(strDeviceName, "  parms[2]:" + Convert.ToDateTime(aItem[0].ToString()), "log");
                        writeLog.Write(strDeviceName, "  parms[3]:" + strSample, "log");
                        writeLog.Write(strDeviceName, "  parms[4]:" + (strSex == "男" ? 1 : (strSex == "女" ? 2 : 0)), "log");
                        writeLog.Write(strDeviceName, "  parms[5]:" + (strBirth == "" ? null : strBirth), "log");
                        writeLog.Write(strDeviceName, "  parms[6]:" + strResult, "log");
                    }
                    else
                    {
                        writeLog.Write(strDeviceName, DateTime.Now.ToString() + "更新检验结果!\r\n检验id=" + strSampleId + ",标本号=" + strSampleNO + ",仪器id=" + DeviceID + ",结果:" + strResult, "log");
                        SaveResult.Appstr = strSampleId;

                        if (GraphVale != null && GraphVale.Count > 0)
                        {
                            OracleHelper.SaveImage(strSampleId, GraphVale);
                        }
                    }
                }
            }
        }
Ejemplo n.º 8
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();
            }
        }
Ejemplo n.º 9
0
 /// <summary>
 /// 得到执行时间的值
 /// </summary>
 /// <returns></returns>
 public Double ReadRuntime()
 {
     try
     {
         string Return_Value; Double Dresult = 1;
         System.Windows.Forms.Form.CheckForIllegalCrossThreadCalls = false;//线程处理后的错误处理控件任然可以赋值
         Return_Value = INIExists("SOLVESET.INI");
         if (!String.IsNullOrEmpty(Return_Value))
         {
             writeLog.Write(DateTime.Now.ToString() + "返回SOLVESET.INI文件中执行时间的结果值:" + Return_Value, "log");
         }
         StringBuilder objStrBd = new StringBuilder(256);
         GetPrivateProfileString("EQUIPMENT", "RUNTIME", "", objStrBd, 256, FileName);
         execution_time = objStrBd.ToString();
         if (string.IsNullOrEmpty(execution_time))
         {
             return(0);
         }
         string[] multiplyby = execution_time.Split(new char[] { '*' }, StringSplitOptions.RemoveEmptyEntries);//乘以
         for (int i = 0; i < multiplyby.Length; i++)
         {
             Dresult = Convert.ToDouble(multiplyby[i]) * Dresult;
         }
         return(Dresult);
     }
     catch (Exception e)
     {
         writeLog.Write("返回SOLVESET.INI文件报错:" + e.Message, "log");
         return(0);
     }
 }
Ejemplo n.º 10
0
        private IDataResolve IResolve;                        //定义数据解析接口

        /// <summary>
        /// 服务启动时调用
        /// </summary>
        /// <param name="DeviceId">仪器ID</param>
        public void Start(string DeviceId)
        {
            status  = "open";
            recvStr = "";
            ds      = dsHandle.GetDataSet(@"解析类型,通讯程序名,备注,Extractvalue(通讯参数,'/root/port') As Port, Extractvalue(通讯参数, '/root/speed') As Speed, 
                                     Extractvalue(通讯参数, '/root/data_bits') As Data_Bits,Extractvalue(通讯参数,'/root/stop_bits') As Stop_Bits, 
                                     Extractvalue(通讯参数, '/root/check_mode') As Check_Mode,Extractvalue(接收规则, '/root/buffer_in') As Buffer_In, 
                                     Extractvalue(接收规则, '/root/buffer_out') As Buffer_Out,名称", "检验仪器", "id='" + DeviceId + "'");

            port            = ds.Tables[0].Rows[0]["port"].ToString();
            speed           = ds.Tables[0].Rows[0]["speed"].ToString();
            data_bits       = ds.Tables[0].Rows[0]["data_bits"].ToString();
            stop_bits       = ds.Tables[0].Rows[0]["stop_bits"].ToString();
            check_mode      = ds.Tables[0].Rows[0]["check_mode"].ToString();
            buffer_in       = ds.Tables[0].Rows[0]["buffer_in"].ToString();
            buffer_out      = ds.Tables[0].Rows[0]["buffer_out"].ToString();
            strDeviceName   = ds.Tables[0].Rows[0]["名称"].ToString();
            resolveType     = ds.Tables[0].Rows[0]["解析类型"].ToString();
            CommProgramName = ds.Tables[0].Rows[0]["通讯程序名"].ToString();
            RemarkContent   = ds.Tables[0].Rows[0]["备注"].ToString();
            if (resolveType == "1")
            {
                IResolve = resString;
            }
            else
            {
                try
                {
                    obj      = ObjectReflection.CreateObject(CommProgramName.Substring(0, CommProgramName.IndexOf(".dll")));
                    IResolve = obj as IDataResolve;
                    IResolve.GetRules(DeviceId);
                }
                catch (Exception exobj)
                {
                    writelog.Write(strDeviceName, exobj.Message, "log");
                    return;
                }
            }
            if (port == "")
            {
                strError = "检验数据接收或检验串口通讯未设置!";
                writelog.Write(strDeviceName, strError, "log");
                return;
            }
            /// <summary>
            /// 打开COM口
            /// </summary>
            try
            {
                SpCom.PortName = "COM" + port;                          //端口号
                SpCom.BaudRate = Convert.ToInt32(speed);                //波特率
                if (check_mode == "N")
                {
                    SpCom.Parity = Parity.None;                       //校验位
                }
                if (check_mode == "O")
                {
                    SpCom.Parity = Parity.Odd;
                }
                if (check_mode == "E")
                {
                    SpCom.Parity = Parity.Even;
                }
                if (check_mode == "S")
                {
                    SpCom.Parity = Parity.Space;
                }
                if (check_mode == "M")
                {
                    SpCom.Parity = Parity.Mark;
                }
                SpCom.DataBits = Convert.ToInt32(data_bits);               //数据位长度
                if (stop_bits == "1")
                {
                    SpCom.StopBits = StopBits.One;                       //停止位
                }
                if (stop_bits == "2")
                {
                    SpCom.StopBits = StopBits.Two;
                }
                SpCom.Handshake = Handshake.None;

                SpCom.DtrEnable = true;
                SpCom.RtsEnable = true;
                if (string.IsNullOrEmpty(buffer_in) || string.IsNullOrEmpty(buffer_out))
                {
                    SpCom.ReadBufferSize  = 2048;
                    SpCom.WriteBufferSize = 1024;
                }
                else
                {
                    SpCom.ReadBufferSize  = Convert.ToInt32(buffer_in);
                    SpCom.WriteBufferSize = Convert.ToInt32(buffer_out);
                }
            }
            catch (Exception exsz)
            {
                writelog.Write(strDeviceName, "通讯参数设置错误:" + exsz.Message, "log");
            }

            try
            {
                SpCom.Open();
                writelog.Write(strDeviceName, "打开串口!", "log");
            }
            catch (Exception ex)
            {
                strError = "没有找到串口,请先打开串口!" + ex.Message;
                writelog.Write(strDeviceName, strError, "log");
                return;
            }

            ds = dsHandle.GetDataSet(@"Extractvalue(接收规则, '/root/data_type') As data_type, Extractvalue(接收规则, '/root/data_begin') As data_begin, 
                                       Extractvalue(接收规则, '/root/data_end') As data_end, Extractvalue(接收规则, '/root/start_cmd') As start_cmd, 
                                       Extractvalue(接收规则, '/root/end_cmd') As end_cmd, Extractvalue(接收规则, '/root/ack_all') As ack_all, 
                                       Extractvalue(接收规则, '/root/ack_term') As ack_term, Extractvalue(接收规则, '/root/decode_mode') As decode_mode, 
                                       Extractvalue(接收规则, '/root/begin_bits') As begin_bits, Extractvalue(接收规则, '/root/end_bits') As end_bits",
                                     "检验仪器", "id = '" + DeviceId + "'");
            if (ds.Tables[0].Rows.Count == 0)
            {
                strError = "未设置检验数据接收设置!";
                writelog.Write(strDeviceName, strError, "log");
            }
            data_type  = ds.Tables[0].Rows[0]["data_type"].ToString();
            data_begin = ds.Tables[0].Rows[0]["data_begin"].ToString();
            data_end   = ds.Tables[0].Rows[0]["data_end"].ToString();
            //inbegin = ds.Tables[0].Rows[0][5].ToString();
            //inend = ds.Tables[0].Rows[0][6].ToString();
            decode_mode = ds.Tables[0].Rows[0]["decode_mode"].ToString();
            begin_bits  = ds.Tables[0].Rows[0]["begin_bits"].ToString();
            end_bits    = ds.Tables[0].Rows[0]["end_bits"].ToString();
            ACK_all     = ds.Tables[0].Rows[0]["ack_all"].ToString();
            ACK_term    = ds.Tables[0].Rows[0]["ack_term"].ToString();

            resString.strDetype        = decode_mode;
            resString.strInstrument_id = DeviceId;
            resString.strSubBegin      = begin_bits;
            resString.strSubEnd        = end_bits;
            resString.strDataBegin     = data_begin;
            resString.strDataEnd       = data_end;
            resString.strACK_all       = ACK_all;
            resString.strACK_term      = ACK_term;
            resString.GetRules(DeviceId);
            resString.listInputResult = new List <string>();

            //SpCom_DataReceived(null, null);//可以在ParseResult直接写死的字符串检查

            ParameterizedThreadStart ParStart = new ParameterizedThreadStart(ListenThread);

            thread = new Thread(ParStart);
            thread.Start();
            SpCom.DataReceived          += new SerialDataReceivedEventHandler(SpCom_DataReceived);//委托,把SerialDataReceivedEventHandler(SpCom_DataReceived)委托给DataReceived
            SpCom.ReceivedBytesThreshold = 1;
        }
Ejemplo n.º 11
0
        public DataSet GetDataSet(string column, string tablename, string strwhere)
        {
            using (OracleConnection _connection = new OracleConnection(OracleHelper.GetConnectionstring()))
            {
                writelog = new Write_Log();
                DataSet ds     = new DataSet();
                string  sqlstr = "select " + column + " from " + tablename;
                if (!String.IsNullOrEmpty(strwhere))
                {
                    sqlstr = sqlstr + " where " + strwhere;
                }
                try
                {
                    _connection.Open();
                    OracleDataAdapter da = new OracleDataAdapter();
                    da.SelectCommand = new OracleCommand(sqlstr, _connection);
                    da.Fill(ds);
                }
                catch (Exception ex)
                {
                    writelog.Write("填充数据时出错!" + ex.Message + System.Environment.NewLine + sqlstr, "log");
                    return(null);
                }
                finally {
                    _connection.Close();
                    _connection.Dispose();
                }

                writelog = null;
                return(ds);
            }



            //writelog = new Write_Log();
            //if (ConnectDB.con.State != ConnectionState.Open)
            //{
            //    init = new ConnectDB();
            //    strError = init.DBConnect();
            //    if (!string.IsNullOrEmpty(strError))
            //    {
            //        writelog.Write(strError, "log");
            //        return null;
            //    }
            //}


            //string sqlstr = "select " + column + " from " + tablename;
            //if (!String.IsNullOrEmpty(strwhere))
            //{
            //    sqlstr = sqlstr + " where " + strwhere;
            //}
            ////writelog.Write(sqlstr, "log");

            //DataSet ds = new DataSet();
            //writelog.Write("1连接状态:" + ConnectDB.con.State.ToString() + "\r\n 连接字符串:" + ConnectDB.con.ConnectionString, "log");
            //OracleDataAdapter ada = new OracleDataAdapter(sqlstr, ConnectDB.con);

            //try
            //{
            //    writelog.Write("2连接状态:"+ConnectDB.con.State.ToString()+"\r\n 连接字符串:"+ ConnectDB.con.ConnectionString, "log");
            //    ada.Fill(ds, tablename);
            //}
            //catch (Exception ex)
            //{

            //    writelog.Write("填充数据时出错!" + ex.Message + System.Environment.NewLine + sqlstr, "log");
            //    return null;
            //}

            ////init.DisConnectDB(ConnectDB.con);
            //init = null;
            //writelog = null;
            //return ds;
        }
Ejemplo n.º 12
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);
        }
Ejemplo n.º 13
0
        /// <summary>
        /// 提取数据
        /// </summary>
        public void Start()
        {
            try
            {
                conDB.Open();
            }
            catch (Exception e)
            {
                writeLog.Write("数据库连接失败!" + e.Message, "log");
                strError = "数据库连接失败!" + e.Message;
                return;
            }
            if (conDB.State != ConnectionState.Open)
            {
                return;
            }

            DataTable dtSample  = OracleHelper.GetDataTable(@"select   wm_concat(样本序号) 样本序号
                                                                                          from 检验记录
                                                                                          where id in (select 记录id from 检验普通结果 where 结果标志 is not null)
                                                                                                   and 仪器id = '" + strInstrumentID + @"'
                                                                                                   and to_char(核收时间, 'yyyy-mm-dd') = to_char(sysdate, 'yyyy-mm-dd')");
            string    _sampleNo = dtSample.Rows[0]["样本序号"].ToString();

            if (string.IsNullOrEmpty(sqlstr))
            {
                sqlstr = @"SELECT dDate, nSid, sItem, fConc, sConc
                                  FROM Result
                                 where Format(dDate, \""yyyy-mm-dd\"") = Format(date() - 1, \""yyyy-mm-dd\"")
                                   and nSid not in (parameter)
                                 order by nsid";
            }
            sqlstr   = sqlstr.Replace("parameter", _sampleNo == "" ? "-1" : _sampleNo);//替换样本号
            dsResult = new DataSet();
            try
            {
                OleDbDataAdapter ada = new OleDbDataAdapter(sqlstr, conDB);
                ada.Fill(dsResult, "Table");
            }
            catch (System.Data.OleDb.OleDbException sqlex)
            {
                strError = sqlex.Message;
                writeLog.Write(strError, "log");
                return;
            }
            catch (Exception ex)
            {
                strError = ex.Message;
                writeLog.Write(strError, "log");
                return;
            }
            finally
            {
                conDB.Close();
            }
            object socketListen = strError;

            GetResult(strError, null);
            aTimer.Elapsed  += new ElapsedEventHandler(GetResult);
            aTimer.Interval  = 10000;
            aTimer.AutoReset = true;
            aTimer.Enabled   = true;
        }