private void button2_Click(object sender, EventArgs e) { if (dgvOper.SelectedRows.Count == 1) { #region 发送HL7 string HL7IPaddress = ConfigurationManager.AppSettings["HL7IPaddress"]; List <QueryMzjldDto> list = (List <QueryMzjldDto>)dgvOper.DataSource; QueryMzjldDto model = list[dgvOper.CurrentRow.Index]; string message = Hl7Bll.AppendHL7stringOperConfig(model.Patid, "0001", "admin"); LogHelp.SaveLogHL7(message); // if (UserFunction.PingHost(HL7IPaddress)) if (true) { if (message.Length > 0) { string HL7port = ConfigurationManager.AppSettings["HL7port"]; SenderRoutingLib.SocketSender send = new SenderRoutingLib.SocketSender(); object objResult; int iResult = 0; int count = 1; if (count < 10) { new System.Threading.Thread(o => { for (int i = 0; i < count; i++) { objResult = send.Send(message, HL7IPaddress, HL7port.ToInt32()); string ack = objResult == null ? string.Empty : objResult.ToString(); if (ack.Contains("AA")) { iResult++; LogHelp.SaveLogHL7(string.Format("\r\n成功条数:{0} \r\n结束时间:{1}", iResult.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); } else { iResult++; LogHelp.SaveLogHL7(string.Format("\r\n消息处理失败原因:{0} \r\n结束时间:{1}", ack, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); } } }).Start(); } } else { LogHelp.SaveLogHL7(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " IP地址或端口错误"); } } #endregion } }
private void btnAll_Click(object sender, EventArgs e) { foreach (DataGridViewRow item in dgvOper.Rows) { #region 发送HL7 string HL7IPaddress = ConfigurationManager.AppSettings["HL7IPaddress"]; string message = Hl7Bll.AppendHL7stringOperConfig(item.Cells["patid"].Value.ToString(), item.Cells["userNo"].Value.ToString(), item.Cells["ap1"].Value.ToString()); LogHelp.SaveLogHL7(message); // if (UserFunction.PingHost(HL7IPaddress)) if (true) { if (message.Length > 0) { string HL7port = ConfigurationManager.AppSettings["HL7port"]; SenderRoutingLib.SocketSender send = new SenderRoutingLib.SocketSender(); object objResult; int iResult = 0; int count = 1; if (count < 10) { new System.Threading.Thread(o => { for (int i = 0; i < count; i++) { objResult = send.Send(message, HL7IPaddress, HL7port.ToInt32()); string ack = objResult == null ? string.Empty : objResult.ToString(); if (ack.Contains("AA")) { iResult++; LogHelp.SaveLogHL7(string.Format("\r\n成功条数:{0} \r\n结束时间:{1}", iResult.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); } else { iResult++; LogHelp.SaveLogHL7(string.Format("\r\n消息处理失败原因:{0} \r\n结束时间:{1}", ack, DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"))); } } }).Start(); } } else { LogHelp.SaveLogHL7(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " IP地址或端口错误"); } } #endregion } }