From 8730d5366de2412391d7604ac0add5ce238cb0e0 Mon Sep 17 00:00:00 2001 From: falcon <9504402@qq.com> Date: Fri, 1 Mar 2019 15:52:36 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90HIS=E8=B0=83=E7=94=A8webservi?= =?UTF-8?q?ce?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj | 3 ++ WebSiteCode/Cmdjy/Cmdjy/Dal/DjyDbContext.cs | 2 +- .../Cmdjy/Dal/Wappers/HisDrugInfoWapper.cs | 18 +++++++ .../Dal/Wappers/HisPrescriptyInfoWapper.cs | 15 ++++++ .../Cmdjy/Cmdjy/ws/HisInterface.asmx.cs | 53 +++++++++++++++---- 5 files changed, 80 insertions(+), 11 deletions(-) create mode 100644 WebSiteCode/Cmdjy/Cmdjy/Dal/Wappers/HisDrugInfoWapper.cs create mode 100644 WebSiteCode/Cmdjy/Cmdjy/Dal/Wappers/HisPrescriptyInfoWapper.cs diff --git a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj index 89d6643..2736737 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj +++ b/WebSiteCode/Cmdjy/Cmdjy/Cmdjy.csproj @@ -153,6 +153,8 @@ + + @@ -211,6 +213,7 @@ + diff --git a/WebSiteCode/Cmdjy/Cmdjy/Dal/DjyDbContext.cs b/WebSiteCode/Cmdjy/Cmdjy/Dal/DjyDbContext.cs index 7bec3ac..4f01cbb 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/Dal/DjyDbContext.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/Dal/DjyDbContext.cs @@ -13,7 +13,7 @@ namespace Cmdjy.Dal public partial class DjyDbContext:DbContext { public DjyDbContext() : base("DjyDbContext") { - Database.SetInitializer(null); + //Database.SetInitializer(null); } } /// diff --git a/WebSiteCode/Cmdjy/Cmdjy/Dal/Wappers/HisDrugInfoWapper.cs b/WebSiteCode/Cmdjy/Cmdjy/Dal/Wappers/HisDrugInfoWapper.cs new file mode 100644 index 0000000..b312a8b --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Dal/Wappers/HisDrugInfoWapper.cs @@ -0,0 +1,18 @@ +namespace Cmdjy.Dal.Wappers +{ + /// + /// 药品信息墙纸 + /// + public class HisDrugInfoWapper:Dal.Tables.HisDrugInfo + { + public HisDrugInfoWapper(ws.HisDrugInfo s) { + if(s == null) return; + foreach(var p in s.GetType().GetProperties()) { + var tp = this.GetType().GetProperty(p.Name); + if(tp != null && tp.CanWrite && p.CanRead) { + tp.SetValue(this,p.GetValue(s)); + } + } + } + } +} \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/Dal/Wappers/HisPrescriptyInfoWapper.cs b/WebSiteCode/Cmdjy/Cmdjy/Dal/Wappers/HisPrescriptyInfoWapper.cs new file mode 100644 index 0000000..96ea15d --- /dev/null +++ b/WebSiteCode/Cmdjy/Cmdjy/Dal/Wappers/HisPrescriptyInfoWapper.cs @@ -0,0 +1,15 @@ +namespace Cmdjy.Dal.Wappers +{ + public class HisPrescriptyInfoWapper:Dal.Tables.HisPrescriptionInfo + { + public HisPrescriptyInfoWapper(ws.HisPrescriptionInfo s) { + if(s == null) return; + foreach(var p in s.GetType().GetProperties()) { + var tp = this.GetType().GetProperty(p.Name); + if(tp != null && tp.CanWrite && p.CanRead) { + tp.SetValue(this,p.GetValue(s)); + } + } + } + } +} \ No newline at end of file diff --git a/WebSiteCode/Cmdjy/Cmdjy/ws/HisInterface.asmx.cs b/WebSiteCode/Cmdjy/Cmdjy/ws/HisInterface.asmx.cs index 90d230a..aba98f2 100644 --- a/WebSiteCode/Cmdjy/Cmdjy/ws/HisInterface.asmx.cs +++ b/WebSiteCode/Cmdjy/Cmdjy/ws/HisInterface.asmx.cs @@ -4,6 +4,9 @@ using System.Linq; using System.Web; using System.Web.Services; using Newtonsoft.Json; +using Cmdjy.Dal; +using Cmdjy.Dal.Wappers; +using System.Data.Entity; namespace Cmdjy.ws { @@ -20,21 +23,51 @@ namespace Cmdjy.ws [WebMethod(Description = "医疗机构上传处方信息")] public string PostPrescriptionInfo(HisPrescriptionInfo info) { - var json = JsonConvert.SerializeObject(info); - var result = new HisPrescriptionResult { - Code = ResultCode.Success,PrescriptionId = "1", - Msg = json, - }; + HisPrescriptionResult result = null; + using(var db = new DjyDbContext()) { + var en = new HisPrescriptyInfoWapper(info) as Dal.Tables.HisPrescriptionInfo; + en.RawAddress = this.Context.Request.UserHostAddress; + en.CreateDatetime = DateTime.Now; + db.Entry(en).State = EntityState.Added; + try { + db.SaveChanges(); + result = new HisPrescriptionResult { + Code = ResultCode.Success,PrescriptionId = en.Id.ToString(), + Msg = "保存成功", + }; + } + catch(Exception ex) { + result = new HisPrescriptionResult { + Code = ResultCode.Exception,PrescriptionId = "0", + Msg = ex.ToString(), + }; + } + } return JsonConvert.SerializeObject(result); } [WebMethod(Description = "医疗机构上传药品信息")] public string PostDrugInfo(HisDrugInfo info) { - var json = JsonConvert.SerializeObject(info); - var result = new HisDrugResult { - Code = ResultCode.Success,DrugId = "1", - Msg = json, - }; + HisDrugResult result = null; + using(var db = new DjyDbContext()) { + var en = new HisDrugInfoWapper(info) as Dal.Tables.HisDrugInfo; + en.RawAddress = this.Context.Request.UserHostAddress; + en.CreateDatetime = DateTime.Now; + db.Entry(en).State = EntityState.Added; + try { + db.SaveChanges(); + result = new HisDrugResult { + Code = ResultCode.Success,DrugId = en.Id.ToString(), + Msg = "保存成功", + }; + } + catch(Exception ex) { + result = new HisDrugResult { + Code = ResultCode.Exception,DrugId = "0", + Msg = ex.ToString(), + }; + } + } return JsonConvert.SerializeObject(result); } }