0701-触发条件 WaitCallback ThreadPool.QueueUserWorkItem

本文详细介绍了WPF中的五种触发器:Trigger、DataTrigger、MultiTrigger、MultiDataTrigger和EventTrigger,以及如何使用它们来改变控件的外观和行为。同时,还讲解了如何使用样式继承和类型标记扩展来简化样式设置。

WPF定义了五种Trigger来作为触发条件,分别是:Trigger,DataTrigger,MultiTrigger,MultiDataTrigger,EventTrigger,他们的触发条件分别是:

  1. Trigger:以控件的属性作为触发条件,如前面的IsMouseOver为True的时候触发。
  2. DataTrigger:以控件DataContext的属性作为触发条件。
  3. MultiTrigger:以控件的多个属性作为触发条件。
  4. MultiDataTrigger:以控件DataContext的多个属性作为触发条件。
  5. EventTrigger:以RoutedEvent作为触发条件,当指定的路由事件Raise时触发。

使用TargetType属性限定该样式可以引用的对象

样式设置BasedOn特性来使用此类样式继承

使用类型标记扩展来隐式的设置键名,样式会自动应用与整个元素树的所有TextBlock上   x:Key="{x:Type TextBlock}"

Styles are always built as resources

Style="{x:Null}"

Border 是一个装饰的控件,此控件绘制一个边框、一个背景,在 Border 中只能有一个子控件,但它的子控件是可以包含多个子控件的Border 的几个生要的属性:

Background:此WPF Border属性设置 Border 用来绘制背景的 Brush 对象。

BorderBrush:此属性设置 Border 用来绘制边框的 Brush 对象。

BorderThickness:此属性设置 Border 边框的宽度,此属性是一个 Thickness 对象, Thickness 是一个 struct 类型的对象,使用 Thickness 对象可以设置边框每一边的线条的宽度。

CornerRadius:此WPF Border属性设置 Border 的每一个角圆的半径,此属性是一个 CornerRadius 对象,CornerRadius 是一个struct 类型的对象。

Padding:此WPF Border属性设置 Border 里的内容与边框的之间的间隔,此属性是一个 Thickness 对象,可以使用此对象为每一边的间隔进行设置。
 

与犯罪的战争:坏家伙的全盛时代/修罗场 阿修罗

 

Infrastructure  InteractionRequestedEventArgs

 

wpf 打印 https://blog.youkuaiyun.com/duanzi_peng/article/details/14118937

 

 

            string stringURL = "http://localhost:8080/GetCSharpRequest";
            
            //创建一个HTTP请求
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(stringURL);
            //Post请求方式
            request.Method = "POST";
            //内容类型
            request.ContentType ="application/octet-stream";

            //设置参数,并进行url编码
            string paraUrlCoded = System.Web.HttpUtility.UrlEncode("param");
            paraUrlCoded += "=" + System.Web.HttpUtility.UrlEncode(json);

            byte[] payload;
            //将json字符串转换为字节
            payload = Encoding.UTF8.GetBytes(paraUrlCoded);
            //设置请求的ContentLength
            request.ContentLength = payload.Length;
            //发送请求,获取请求流
            Stream writer;
            try
            {
                writer = request.GetRequestStream();
            }
            catch (Exception)
            {
                writer = null;
                Console.WriteLine("链接服务器失败");
            }
            //将请求参数写入流
            writer.Write(payload, 0, payload.Length);
            writer.Close();
            
            string strValue = "";
            HttpWebResponse response;
            try
            {
                response = (HttpWebResponse)request.GetResponse();
            }
            catch (WebException e)
            {
                response = e.Response as HttpWebResponse;
            }

            Stream s = response.GetResponseStream();
            StreamReader sr = new StreamReader(s, Encoding.UTF8);
            StringBuilder sb = new StringBuilder();
            sb.Append(sr.ReadToEnd());
            strValue = sb.ToString();
            Console.WriteLine("响应结果:{0}", strValue);
 

 

using Com.Huancare.Medical.Lis.Communication.ProtocolBase.Serial; using NetworkClient.Entities; using System; using System.Collections.Generic; using System.Data; using System.IO.Ports; using System.Linq; using System.Text; using System.Threading; using System.Timers; namespace Com.Huancare.Medical.Lis.Communication.Protocol.Serial { /// <summary> /// 曾口中心卫生院 /// 尿检机 曼特诺matenu US200 /// </summary> public class SerialUS200Svr : SerialSvrReceiveData { byte[] btBuffer = new byte[1024]; int iCurrentIndex = 0; private string strHosEquipID; private string strHosID; private string strPortName; private DataTable dtChannelAndValue = null; StringBuilder sbCache = new StringBuilder(); /// <summary> /// 记时器 /// </summary> System.Timers.Timer timer = new System.Timers.Timer(300); // 0.3s public SerialUS200Svr(string strPortName, int iBaudRate, int iDataBits, StopBits stopBits, Parity parity, int iBufferSize, string strShakeHands, string strReply, string strEndShakeHands, string strEndReply) : base(strPortName, iBaudRate, iDataBits, stopBits, parity, iBufferSize, strShakeHands, strReply, strEndShakeHands, strEndReply) { this.strPortName = strPortName; timer.Elapsed += new System.Timers.ElapsedEventHandler(SaveData); timer.AutoReset = false; InitChannelAndValue(); } private void InitChannelAndValue() { dtChannelAndValue = new DataTable(); dtChannelAndValue.Columns.Add("PaperType", typeof(string)); dtChannelAndValue.Columns.Add("ChannelName", typeof(string)); dtChannelAndValue.Columns.Add("RowIndex", typeof(int)); dtChannelAndValue.Columns.Add("ValueIndex", typeof(int)); dtChannelAndValue.Columns.Add("Value", typeof(string)); int iValueIndex = 0; int iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "URO", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "URO", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "URO", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "URO", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "URO", iValueIndex, iRowIndex++, "3+"); iValueIndex = 1; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "BIL", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "BIL", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "BIL", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "BIL", iValueIndex, iRowIndex++, "3+"); iValueIndex = 2; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "KET", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "KET", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "KET", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "KET", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "KET", iValueIndex, iRowIndex++, "3+"); iValueIndex = 3; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "BLD", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "BLD", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "BLD", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "BLD", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "BLD", iValueIndex, iRowIndex++, "3+"); iValueIndex = 4; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "3+"); dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "3+"); dtChannelAndValue.Rows.Add("02", "PRD", iValueIndex, iRowIndex++, "4+"); iValueIndex = 5; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "NIT", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "NIT", iValueIndex, iRowIndex++, "+"); iValueIndex = 6; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "LEU", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "LEU", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "LEU", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "LEU", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "LEU", iValueIndex, iRowIndex++, "3+"); iValueIndex = 7; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "-"); dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "+-"); dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "1+"); dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "2+"); dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "3+"); dtChannelAndValue.Rows.Add("02", "GLU", iValueIndex, iRowIndex++, "4+"); iValueIndex = 8; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.030"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.025"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.020"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.015"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.010"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.005"); dtChannelAndValue.Rows.Add("02", "SG", iValueIndex, iRowIndex++, "1.000"); iValueIndex = 9; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "4.5"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "5.0"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "5.5"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "6.0"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "6.5"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "7.0"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "7.5"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "8.0"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "8.5"); dtChannelAndValue.Rows.Add("02", "PH", iValueIndex, iRowIndex++, "9.0"); iValueIndex = 10; iRowIndex = 0; dtChannelAndValue.Rows.Add("02", "VC", iValueIndex, iRowIndex++, "6.0"); dtChannelAndValue.Rows.Add("02", "VC", iValueIndex, iRowIndex++, "3.0"); dtChannelAndValue.Rows.Add("02", "VC", iValueIndex, iRowIndex++, "1.4"); dtChannelAndValue.Rows.Add("02", "VC", iValueIndex, iRowIndex++, "0.6"); dtChannelAndValue.Rows.Add("02", "VC", iValueIndex, iRowIndex++, "0"); } protected override void PacketReceived(byte[] btRecData, string strHosEquipID, string strHosID) { try { this.strHosEquipID = strHosEquipID; this.strHosID = strHosID; if (btRecData[0] == 0x41) iCurrentIndex = 0;//开始标志 Array.Copy(btRecData, 0, btBuffer, iCurrentIndex, btRecData.Length); iCurrentIndex += btRecData.Length; if (btRecData[btRecData.Length - 1] == 0x42)//结束标志 { iCurrentIndex = 0; } timer.Enabled = false; this.strHosEquipID = strHosEquipID; this.strHosID = strHosID; sbCache.Append(Encoding.ASCII.GetString(btRecData)); timer.Enabled = true; } catch (Exception) { } } private void SaveData(object sender, System.Timers.ElapsedEventArgs e) { string strRecData = ""; lock (this) { strRecData = sbCache.ToString(); sbCache.Remove(0, sbCache.Length); } ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProcessReceiveData), strRecData); } private void ThreadProcessReceiveData(object objRecString) { string strPackets = objRecString.ToString(); try { //string strRecData = ExtractLowest(strPackets.Replace(" ", "")); string strRecData = strPackets.Replace(" ", ""); string strSave = ""; strSave += strRecData.Substring(1, 6);//上机号 strSave += "|"; //报文中没有年份和秒 strSave += DateTime.Now.Year.ToString().Substring(0, 2) + strRecData.Substring(7, 10) + "01";//上机时间 strSave += "|"; //00 URS-8 传送数据的倒数第二位至第五位为随机数无效 //01 URS-10 传送数据的倒数第二位至第三位为随机数无效 //02 F11-2 传送数据的倒数第二位无效 //03 URS-11 传送数据与试纸使用顺序相同 string strPaperType = strRecData.Substring(17, 2);//试纸类型 //00 旧制(E) //01 旧制(+-) //02 SI制(E) //03 SI制(+-) string strUnitType = strRecData.Substring(19, 2);//单位 string strValues = strRecData.Substring(21, 12);//结果 int iIndex = 0; for (int i = 0; i < strValues.Length; i++) { string strVal = strValues.Substring(i, 1); DataRow dtRow = this.GetUS200TableValue(strPaperType, iIndex++, strVal); if (dtRow != null) { string strChannelName = dtRow["ChannelName"].ToString();//通道号 string strChannelValue = dtRow["Value"].ToString();//通道号 strSave += strChannelName; strSave += ":"; strSave += strChannelValue; strSave += ";"; } } strSave += "|"; //btRecData = System.Text.Encoding.Default.GetBytes(strSave); string strOptMsg = SaveReceiveData.SaveReceivePacked(this.strHosID, this.strHosEquipID, strSave); base.OnReceiveDatas(this.strHosEquipID, strPortName, new ReceiveDatasEventArgs(Encoding.UTF8.GetBytes(strSave), strOptMsg)); } catch (Exception ex) { base.OnReceiveDatas(this.strHosEquipID, strPortName, new ReceiveDatasEventArgs(Encoding.UTF8.GetBytes(strPackets), ex.Message)); } } /// <summary> /// 根据试纸类型 顺序 值索引 查询对应的结果值 /// </summary> /// <param name="strPaperType">试纸类型</param> /// <param name="iIndex">顺序 即行号</param> /// <param name="strValIndex">值索引</param> /// <returns></returns> private DataRow GetUS200TableValue(string strPaperType, int iIndex, string strValIndex) { DataRow dtRowRet = null; try { if (dtChannelAndValue == null) this.InitChannelAndValue(); dtRowRet = dtChannelAndValue.Select("PaperType = '" + strPaperType + "' And RowIndex = " + iIndex + " And ValueIndex = '" + strValIndex + "'")[0]; } catch (Exception) { } return dtRowRet; } //static string ExtractLowest(string hexString) //{ // //string result = ""; // //for (int i = 0; i < hexString.Length; i += 2) // //{ // // string pair = hexString.Substring(i, 2); // // int value = Convert.ToInt32(pair, 16); // // result += Convert.ToString(value % 10, 16); // 取最低值 // //} // //return result; //} } }
08-07
public frmManualJob(bool ClickEnable) { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); //if (System.Configuration.ConfigurationManager.AppSettings["CoordinatorName"].Contains("508M"))//508M ,abort job不显示 if (NAURA.ConfigurationManager.ConfigurationManager.ToolCoordinatorDll == NAURA.ConfigurationManager.CoordinatorDll.Coordinator508M)//508M ,abort job不显示 { this.btnAbortJob1.Visible = this.btnAbortJob2.Visible = false; this.btnEndJob1.Size = new Size(this.btnStartJob1.Width, this.btnStartJob1.Height); this.btnEndJob2.Size = new Size(this.btnStartJob2.Width, this.btnStartJob2.Height); } GetAllInitInfo(this.Controls[0]); showconfig = ModuleConfig.GetIns(); if (ClickEnable == true) { this.cycleNum.Enabled = false; this.cmbhaltlot.Enabled = false; } this.jobInfo1 = new JobDetailInfo("job1"); this.jobInfo2 = new JobDetailInfo("job2"); this.currentJobInfo = this.jobInfo1; //if (Globals.getHandle().SoftType.ToString() == "APE") //{200的最多2个并且一直有 //} //reg = new Regex(@"^([0-9]{1,15})$"); reg = new Regex(@"^([0-9]{1,3})$"); this.ctcNode = CtcValueManager.GetIns(); this.currJobLst = new ArrayList(); taskmanager = TaskManager.GetIns(); routemanager = new RouteManager(); ReData = new RemoteDataChange(); this.modconfig = ModuleConfig.GetIns();//修改人:牧净艳,修改原因:单例类,修改时间:2023-4-6 myNode_TM = NodeConInfo.GetIns().MyNode_TM; ThreadPool.QueueUserWorkItem(new WaitCallback(initpoll)); RefreshControlSafely.SetControlViewByWfrCount(this.jobLsvLeft, this.modconfig.LP1WfrCount);//added by mujy for 支持不同片槽总数 RefreshControlSafely.SetControlViewByWfrCount(this.job1Lsv, this.modconfig.LP2WfrCount);//added by mujy for 支持不同片槽总数 // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // this.taskList = new List<ITaskInfo>(); }解释一下这段代码
07-21
using Com.Huancare.Medical.Lis.Communication.ProtocolBase.Serial; using System; using System.Collections.Generic; using System.IO.Ports; using System.Linq; using System.Text; using System.Threading; namespace Com.Huancare.Medical.Lis.Communication.Protocol.Serial { /// <summary> /// 尿液分析仪Mission U120 /// </summary> class SerialMissionU120 : SerialSvrReceiveData { /// <summary> /// 计时器 /// </summary> System.Timers.Timer timer = new System.Timers.Timer(3000); // 1s private string strHosID; private string strHosEquipID; private string strPortName; public SerialMissionU120(string strPortName, int iBaudRate, int iDataBits, StopBits stopBits, Parity parity, int iBufferSize, string strShakeHands, string strReply, string strEndShakeHands, string strEndReply) : base(strPortName, iBaudRate, iDataBits, stopBits, parity, iBufferSize, strShakeHands, strReply, strEndShakeHands, strEndReply) { this.strPortName = strPortName; timer.Elapsed += new System.Timers.ElapsedEventHandler(SaveData); timer.AutoReset = false; } StringBuilder sbCache = new StringBuilder(); private SerialPort _port; protected override void PacketReceived(byte[] btRecData, string strHosEquipID, string strHosID) { timer.Enabled = false; this.strHosID = strHosID; this.strHosEquipID = strHosEquipID; sbCache.Append(Encoding.ASCII.GetString(btRecData)); timer.Enabled = true; } private void SaveData(object sender, System.Timers.ElapsedEventArgs e) { string strRecData = ""; lock (this) { strRecData = sbCache.ToString(); sbCache.Remove(0, sbCache.Length); } ThreadPool.QueueUserWorkItem(new WaitCallback(ThreadProcessReceiveData), strRecData); } private void ThreadProcessReceiveData(object objRecString) { string strOptMsg = ""; string ReceiveData = objRecString.ToString(); string SampleId = ""; string SampleDate = ""; string SampleAE = ""; string SampleValue = ""; StringBuilder Sb = new StringBuilder(); try { string[] rcvarr = ReceiveData.Split(new string[] { "\r\n" }, StringSplitOptions.RemoveEmptyEntries); string SampleNum = System.Text.RegularExpressions.Regex.Replace(rcvarr[2], @"[^0-9]+", "");//第一行字符串只保留数字 SampleId = SampleNum.Substring(0, 6);//截取长度为6,样本号 SampleDate = DateTime.Now.ToString("yyyyMMddHHmmss"); Sb.Append(SampleId).Append("|").Append(SampleDate).Append("|"); for (int i = 3; i < rcvarr.Length; i++) { string[] arr = rcvarr[i].Split(new string[] { " " , "\t"}, StringSplitOptions.RemoveEmptyEntries); if (arr.Length >= 2) { SampleAE = arr[0];//通道号 SampleValue = arr[1];//检验结果 Sb.Append(SampleAE).Append(":").Append(SampleValue).Append(";"); } } Sb.Append("|"); strOptMsg = SaveReceiveData.SaveReceivePacked(this.strHosID, this.strHosEquipID, Sb.ToString()); OnReceiveDatas(this.strHosEquipID, strPortName, new ReceiveDatasEventArgs(Encoding.UTF8.GetBytes(Sb.ToString()), strOptMsg)); Sb.Remove(0, Sb.Length); } catch (Exception ex) { strOptMsg += ex.Message; OnReceiveDatas(this.strHosEquipID, strPortName, new ReceiveDatasEventArgs(Encoding.UTF8.GetBytes(objRecString.ToString()), strOptMsg)); } } } }
最新发布
08-30
using Com.Huancare.Medical.Lis.Communication.ProtocolBase.Tcp; using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Timers; namespace Com.Huancare.Medical.Lis.Communication.Protocol.Tcp { /// <summary> /// sematy全自动干式生化分析 /// </summary> internal class SvrSMT : TcpSvrReceiveData { private string iPort; /// <summary> /// 开始字节 /// </summary> private byte byteStart = 0x0B; /// <summary> /// 换行(回车)字节 /// </summary> private byte byteEnter = 0x0D; /// <summary> /// 结束字节 /// </summary> private byte byteEnd = 0x1C; private string strHosID; private string strHosEquipID; private string strPort; private System.Timers.Timer timer = new System.Timers.Timer(3000.0); private StringBuilder sbCache = new StringBuilder(); public SvrSMT(string strHostIp, int iPort, int numConnections, int bufferSize) : base(strHostIp, iPort, numConnections, bufferSize) { this.strPort = iPort.ToString(); this.timer.Elapsed += new ElapsedEventHandler(this.SaveData); this.timer.AutoReset = false; } protected override void PacketReceived(byte[] btRecData, string strHosEquipID, string strHosID) { try { string strRecData = System.Text.Encoding.Default.GetString(btRecData); string[] strSplit = new string[] { "\r" }; string strNo = strRecData.Split(strSplit, StringSplitOptions.None)[0].Split('|')[9]; base.SetReturnData(ReceiveSucc(strNo)); } catch { } this.timer.Enabled = false; this.strHosID = strHosID; this.strHosEquipID = strHosEquipID; //this.sbCache.Append(CommonConfig.ENCODING_GB2312.GetString(btRecData)); this.sbCache.Append(Encoding.UTF8.GetString(btRecData)); this.timer.Enabled = true; } private void SaveData(object sender, ElapsedEventArgs e) { string state = ""; Monitor.Enter(this); try { state = this.sbCache.ToString(); this.sbCache.Remove(0, this.sbCache.Length); } finally { Monitor.Exit(this); } ThreadPool.QueueUserWorkItem(new WaitCallback(this.ThreadProcessReceiveData), state); } private void ThreadProcessReceiveData(object data) { string text = data.ToString(); string text2 = ""; string strOptMsg = ""; StringBuilder stringBuilder = new StringBuilder(); string SampleId = ""; string SampleDate = ""; string SampleAE = ""; string SampleValue = ""; try { string[] sampleSplit = text.Split(new string[] { " MSH" }, StringSplitOptions.RemoveEmptyEntries); foreach (var item in sampleSplit) { string[] array = item.Split(new string[] { "\r", "\n" }, StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < array.Length; i++) { string text3 = array[i]; if (text3.IndexOf("OBR") > -1) { string[] strObr = text3.Split(new string[] { "|" }, StringSplitOptions.None); SampleId = strObr[3]; SampleDate = strObr[7]; stringBuilder.Append(SampleId).Append("|").Append(SampleDate).Append("|"); } if (text3.IndexOf("OBX") > -1) { string[] strObx = text3.Split(new string[] { "|" }, StringSplitOptions.None); SampleAE = strObx[4]; SampleValue = strObx[5]; stringBuilder.Append(SampleAE).Append(":").Append(SampleValue).Append(";"); } } stringBuilder.Append("|"); strOptMsg = SaveReceiveData.SaveReceivePacked(this.strHosID, this.strHosEquipID, stringBuilder.ToString()); base.OnReceiveDatas(this.strHosEquipID, this.strPort, new ReceiveDatasEventArgs(Encoding.UTF8.GetBytes(stringBuilder.ToString()), strOptMsg)); stringBuilder.Remove(0, stringBuilder.Length); } } catch (Exception ex) { base.OnReceiveDatas(this.strHosEquipID, this.strPort, new ReceiveDatasEventArgs(Encoding.UTF8.GetBytes(stringBuilder.ToString()), strOptMsg)); strOptMsg = ex.Message; } } private readonly string MSH_Format = @"MSH|^~\&|||||{0}||ACK^R01|{1}|P|2.3.1||||0||UTF8|||"; private readonly string MSA_Format = @"MSA|AA|{0}|Message accepted|||0|"; private byte[] ReceiveSucc(string msgContorlID) { string strMSH = string.Format(MSH_Format, DateTime.Now.ToString("yyyyMMddHHmmss"), msgContorlID); byte[] byteMSH = System.Text.Encoding.ASCII.GetBytes(strMSH); byte[] byteTmp = new byte[byteMSH.Length + 2]; byteTmp[0] = byteStart; Array.Copy(byteMSH, 0, byteTmp, 1, byteMSH.Length); byteTmp[byteTmp.Length - 1] = byteEnter; byteMSH = byteTmp; string strMSA = string.Format(MSA_Format, msgContorlID); byte[] byteMSA = System.Text.Encoding.ASCII.GetBytes(strMSA); byteTmp = new byte[byteMSH.Length + byteMSA.Length + 3]; Array.Copy(byteMSH, 0, byteTmp, 0, byteMSH.Length); Array.Copy(byteMSA, 0, byteTmp, byteMSH.Length, byteMSA.Length); byteTmp[byteTmp.Length - 3] = byteEnter; byteTmp[byteTmp.Length - 2] = byteEnd; byteTmp[byteTmp.Length - 1] = byteEnter; return byteTmp; } } }分析代码逻辑
08-29
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值