using System; using System.Collections.Generic; using System.Linq; using System.Text; using EAS.Services; using SOH.Entities; using SOH.Data; using EAS.Data; using EAS.Data.Linq; using EAS.Data.ORM; using EAS.Data.Access; using System.Data.Linq.SqlClient; using System.Data; using SOH.Entities.DTO; using System.Threading; using System.IO; using System.Drawing; using System.Drawing.Imaging; using System.Net; namespace SOH.BLL { [ServiceBind(typeof(IPingAn))] [ServiceObject("平安业务")] public class PingAnBll : IPingAn { public string Get_Http(string url, int timeout, string parm) { string strResult = ""; try { //创建请求 HttpWebRequest myReq = (HttpWebRequest)HttpWebRequest.Create(url); //请求响应时间 myReq.Timeout = timeout; //得到响应对象 HttpWebResponse myRes = (HttpWebResponse)myReq.GetResponse(); //获取流 Stream myStream = myRes.GetResponseStream(); //读取字符 StreamReader sr = new StreamReader(myStream, Encoding.UTF8); StringBuilder sb = new StringBuilder(); while (-1 != sr.Peek()) { sb.Append(sr.ReadLine()); } strResult = sb.ToString(); } catch (Exception exp) { strResult = "错误:" + exp.Message; } return strResult; } public string postFileMessage(string strUrl, List postParaList) { try { string responseContent = ""; var memStream = new MemoryStream(); HttpWebRequest webRequest = (HttpWebRequest)HttpWebRequest.Create(strUrl); //var webRequest = (HttpWebRequest)WebRequest.Create(strUrl); // 边界符 var boundary = "---------------" + DateTime.Now.Ticks.ToString("x"); // 边界符 var beginBoundary = Encoding.ASCII.GetBytes("--" + boundary + "\r\n"); // 最后的结束符 var endBoundary = Encoding.ASCII.GetBytes("--" + boundary + "--\r\n"); memStream.Write(beginBoundary, 0, beginBoundary.Length); // 设置属性 webRequest.Method = "POST"; webRequest.Timeout = 10000; webRequest.ContentType = "multipart/form-data; boundary=" + boundary; for (int i = 0; i < postParaList.Count; i++) { PostDateClass temp = postParaList[i]; if (temp.Type == 1) { var fileStream = new FileStream(temp.Value, FileMode.Open, FileAccess.Read); // 写入文件 const string filePartHeader = "Content-Disposition: form-data; name=\"{0}\"; filename=\"{1}\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n"; var header = string.Format(filePartHeader, temp.Prop, temp.Value); var headerbytes = Encoding.UTF8.GetBytes(header); memStream.Write(headerbytes, 0, headerbytes.Length); var buffer = new byte[1024]; int bytesRead; // =0 while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0) { memStream.Write(buffer, 0, bytesRead); } string end = "\r\n"; headerbytes = Encoding.UTF8.GetBytes(end); memStream.Write(headerbytes, 0, headerbytes.Length); fileStream.Close(); } else if (temp.Type == 0) { // 写入字符串的Key var stringKeyHeader = "Content-Disposition: form-data; name=\"{0}\"" + "\r\n\r\n{1}\r\n"; var header = string.Format(stringKeyHeader, temp.Prop, temp.Value); var headerbytes = Encoding.UTF8.GetBytes(header); memStream.Write(headerbytes, 0, headerbytes.Length); } if (i != postParaList.Count - 1) memStream.Write(beginBoundary, 0, beginBoundary.Length); else // 写入最后的结束边界符 memStream.Write(endBoundary, 0, endBoundary.Length); } webRequest.ContentLength = memStream.Length; var requestStream = webRequest.GetRequestStream(); memStream.Position = 0; var tempBuffer = new byte[memStream.Length]; memStream.Read(tempBuffer, 0, tempBuffer.Length); memStream.Close(); requestStream.Write(tempBuffer, 0, tempBuffer.Length); requestStream.Close(); using (HttpWebResponse res = (HttpWebResponse)webRequest.GetResponse()) { using (Stream resStream = res.GetResponseStream()) { byte[] buffer = new byte[1024]; int read; try { while ((read = resStream.Read(buffer, 0, buffer.Length)) > 0) { responseContent += Encoding.UTF8.GetString(buffer, 0, read); } } catch (Exception e) { } } res.Close(); } return responseContent; } catch (Exception e) { } return null; } public DataTable GetPaGrgzb(string xm, string sfzh, string dh,string tjrq) { using (var db = new DbEntities()) { //db.pa_yysqs //string sql1 = "select * from t_grgzb where xm='" + xm + "' and sfzh='" + sfzh + "' and dh='" + dh + "' and tjrq>='"+tjrq+"' and hfbz=1 and tmztz>5 order by tjrq desc"; string sql1 = "select * from t_grgzb where xm='" + xm + "' and sfzh='" + sfzh + "' and tjrq>='" + tjrq + "' and tmztz>5 order by tjrq desc"; //string sql1 = "select * from t_grgzb where xm='" + xm + "' and sfzh='" + sfzh + "' and tmztz>5 order by tjrq desc"; DataTable dt = db.DataAccessor.QueryDataTable(sql1); return dt; } } public DataTable GetPaTtgzb(string xm, string sfzh, string dh,string tjrq) { using (var db = new DbEntities()) { //db.pa_yysqs string sql1 = "select * from t_ttgzb where xm='" + xm + "' and sfzh='" + sfzh + "' and tjrq>='"+ tjrq + "' and tmztz>5 order by tjrq desc"; //string sql1 = "select * from t_ttgzb where xm='" + xm + "' and sfzh='" + sfzh + "' and tmztz>5 order by tjrq desc"; DataTable dt = db.DataAccessor.QueryDataTable(sql1); return dt; } } public pa_yysq Djhx(string hospitalOrderId, string orderId,string captcha) { using (DbEntities db = new DbEntities()) { var yysq = db.pa_yysqs.FirstOrDefault(g => g.hospitalOrderId == hospitalOrderId && g.orderId== orderId); yysq.orderState = "03"; yysq.captcha = captcha; yysq.status = "201"; yysq.tjrq = DateTime.Now; db.pa_yysqs.Update(yysq); return yysq; } } public void Bgsc(string orderId) { using (DbEntities db = new DbEntities()) { var yysq = db.pa_yysqs.FirstOrDefault(g => g.orderId == orderId); yysq.status = "202"; //报告已上传 db.pa_yysqs.Update(yysq); } } public string GetPaYysqList(string sfz, string xm,string sjh, DateTime dt1, DateTime dt2,string fddm) { using (DbEntities db = new DbEntities()) { var data = from d in db.pa_yysqs select new { hospitalOrderId = d.hospitalOrderId, orderId = d.orderId, jgmc = fddm=="1"?"德州天瑞健康体检有限公司汇金门诊部": "淄博天瑞健康体检有限公司汇金门诊部", appointmentTime = d.appointmentTime, tjrq = d.tjrq, orderState = (d.orderState == "01") ? "预约已确认" : "预约待确认", status = d.status, customerName = d.customerName, customerIdentityNo = d.customerIdentityNo, phone = d.phone, isVip = d.isVip, hasAuthorized = d.hasAuthorized, medicalStatus = d.medicalStatus == "01" ? "男" : (d.medicalStatus == "02" ? "未婚女" : "已婚女 "), customerBirthday = d.customerBirthday, packageDisplayName = d.packageDisplayName, companyName = d.companyName, captcha=d.captcha, customerIdentityType=d.customerIdentityType }; if (!string.IsNullOrEmpty(xm)) { data = data.Where(t => t.customerName.Contains(xm)); } if (!string.IsNullOrEmpty(sfz)) { data = data.Where(t => t.customerIdentityNo == sfz); } if (!string.IsNullOrEmpty(sjh)) { data = data.Where(t => t.phone == sjh); } if (dt1 != DateTime.MinValue && dt2 != DateTime.MinValue) { data = data.Where(t => t.tjrq >= Convert.ToDateTime(dt1) && t.tjrq <= Convert.ToDateTime(dt2)); //data = data.Where(t => t.tjrq > dt1 && t.tjrq < dt2); } return Newtonsoft.Json.JsonConvert.SerializeObject(data); } } } }