using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Services; using System.Data.SqlClient; using System.Data.OleDb; using System.Data; using Newtonsoft.Json; namespace TiJianFuWu { /// /// NFJY 的摘要说明 /// [WebService(Namespace = "http://tempuri.org/")] [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.ComponentModel.ToolboxItem(false)] // 若要允许使用 ASP.NET AJAX 从脚本中调用此 Web 服务,请取消注释以下行。 // [System.Web.Script.Services.ScriptService] public class NFJY : System.Web.Services.WebService { private static SqlConnection connection; string[] xs = new string[] { "欧阳", "太史", "端木", "上官", "司马", "东方", "独孤", "南宫", "万俟", "闻人", "夏侯", "诸葛", "尉迟", "公羊", "赫连", "澹台", "皇甫", "宗政", "濮阳", "公冶", "太叔", "申屠", "公孙", "慕容", "仲孙", "钟离", "长孙", "宇文", "司徒", "鲜于", "司空", "闾丘", "子车", "亓官", "司寇", "巫马", "公西", "颛孙", "壤驷", "公良", "漆雕", "乐正", "宰父", "谷梁", "拓跋", "夹谷", "轩辕", "令狐", "段干", "百里", "呼延", "东郭", "南门", "羊舌", "微生", "公户", "公玉", "公仪", "梁丘", "公仲", "公上", "公门", "公山", "公坚", "左丘", "公伯", "西门", "公祖", "第五", "公乘", "贯丘", "公皙", "南荣", "东里", "东宫", "仲长", "子书", "子桑", "即墨", "达奚", "褚师", "吴铭", }; [WebMethod] public string GetModel(string tm) { string message = ""; string XingMing = ""; string Sex = ""; string Age = ""; if(!string.IsNullOrEmpty(tm)) { string sql = "select * from t_ttgzb where tm="+tm; DataTable dt = GetDataSet(sql); if(dt.Rows.Count!=0) { XingMing= GetName(dt.Rows[0]["xm"].ToString(),Convert.ToInt32(dt.Rows[0]["xb"])); Sex = dt.Rows[0]["xb"].ToString() == "0" ? "男" : "女"; Age = dt.Rows[0]["nl"].ToString(); sql = "select a.ksmc as '检查科室',b.jcxmmc as '检查项目',c.jg as '结果',b.dw as '单位',b.ckxx as '参考下限',b.cksx as '参考上限'from t_tjjg c,t_ks a,t_jcxm b where " + " c.xmbm=b.jcxmbm and b.ksbm=a.ksbm and c.tm =" + tm; DataTable jcxmDt = GetDataSet(sql); return Newtonsoft.Json.JsonConvert.SerializeObject(new { XingMing = XingMing, Sex = Sex, Age = Age ,Data= jcxmDt }); } else { sql = "select * from t_grgzb where tm=" + tm; dt = GetDataSet(sql); if(dt.Rows.Count!=0) { XingMing= GetName(dt.Rows[0]["xm"].ToString(), Convert.ToInt32(dt.Rows[0]["xb"])); Sex = dt.Rows[0]["xb"].ToString()=="0"?"男":"女"; Age = dt.Rows[0]["nl"].ToString(); sql = "select a.ksmc as '检查科室',b.jcxmmc as '检查项目',c.jg as '结果',b.dw as '单位',b.ckxx as '参考下限',b.cksx as '参考上限'from t_tjjg c,t_ks a,t_jcxm b where " + " c.xmbm=b.jcxmbm and b.ksbm=a.ksbm and c.tm =" + tm; DataTable jcxmDt = GetDataSet(sql); return Newtonsoft.Json.JsonConvert.SerializeObject(new { XingMing = XingMing, Sex = Sex, Age = Age, Data = jcxmDt }); } else { message = "无效条码号!"; } } }else { message = "条码号不能为空!"; } return message; } public string GetName(string xm,int xb) { string newXm = ""; if (Array.IndexOf(xs, xm.Substring(0, 2)) == -1) { if (xb == 1) { newXm = xm.Substring(0, 1) + "女士"; } else { newXm = xm.Substring(0, 1) + "先生"; } } else { for (int i = 0; i < xs.Length; i++) { if (xm.Substring(0, 2).Equals(xs[i])) { if (xb == 1) { newXm = xs[i] + "女士"; } else { newXm = xs[i] + "先生"; } } } } return newXm; } public static SqlConnection Connection { get { string con = ""; //System.Configuration.Configuration cm = System.Configuration.ConfigurationManager.OpenExeConfiguration(AppDomain.CurrentDomain.BaseDirectory + "\\local.ext"); //con = cm.AppSettings.Settings["zbbodycheck"].Value; con = System.Configuration.ConfigurationManager.ConnectionStrings["tjconn"].ConnectionString; if (connection == null) { connection = new SqlConnection(con); connection.Open(); } else if (connection.State == System.Data.ConnectionState.Closed) { connection.Open(); } else if (connection.State == System.Data.ConnectionState.Broken) { connection.Close(); connection.Open(); } return connection; } } public static DataTable GetDataSet(string safeSql) { DataSet ds = new DataSet(); SqlCommand cmd = new SqlCommand(safeSql, Connection); SqlDataAdapter da = new SqlDataAdapter(cmd); da.Fill(ds); return ds.Tables[0]; } } }