/// <summary> /// 分页查询患者信息 /// </summary> /// <param name="pagination">分页参数</param> /// <param name="keyword">关键字(透析号,姓名,病历号)</param> /// <returns></returns> public async Task <IActionResult> GetGridJson(BasePagedInput input) { var pagination = input.pagination.ToJObject().ToObject <Pagination>(); pagination.sidx = "F_PY asc"; var keyword = input.keyword; var data = new { rows = (await _patientApp.GetList(pagination, keyword)).Select(t => new { t.F_Id, t.F_Name, t.F_DialysisNo, t.F_RecordNo, t.F_PatientNo, t.F_Gender, t.F_BirthDay, F_AgeStr = t.F_BirthDay == null ? "" : ((DateTime.Now - t.F_BirthDay.ToDate()).TotalDays.ToInt() / 365).ToString() + "岁", t.F_Charges, t.F_InsuranceNo, t.F_IdNo, t.F_MaritalStatus, t.F_IdealWeight, t.F_Height, t.F_DialysisStartTime, t.F_PrimaryDisease, t.F_Diagnosis, t.F_Address, t.F_InsuranceType, t.F_Contacts, t.F_Contacts2, t.F_Trasfer, t.F_PhoneNo, t.F_PhoneNo2, t.F_BloodAbo, t.F_BloodRh, t.F_Tp, t.F_Hiv, t.F_HBsAg, t.F_HBsAb, t.F_HBcAb, t.F_HBeAg, t.F_HBeAb, t.F_HCVAb, F_BeInfected = "+".Equals(t.F_Tp) || "+".Equals(t.F_Hiv) || "+".Equals(t.F_HBsAg) || "+".Equals(t.F_HBeAg) || "+".Equals(t.F_HBeAb),//阳性患者判断规则 t.F_MedicalHistory, t.F_CardNo, t.F_PY, F_HeadIcon = t.F_HeadIcon ?? "" }), total = pagination.total, page = pagination.page, records = pagination.records }; return(Ok(data)); }
public BasePagedList <Message> GetPagedListMessageByProfile(Profile profile, BasePagedInput input) { var result = _messageRepository.GetPagedListByProfile(profile, input); result.Records.ForEach(n => { n.Person = _profileRepository.GetPersonById(n.PersonId); }); return(result); }
public ActionResult GetMessage(BasePagedInput input, int profileId) { return(Json(_profileService.GetPagedListMessageByProfile(_profileService.GetProfileById(profileId), input), JsonRequestBehavior.AllowGet)); }
public BasePagedList <Message> GetPagedListByProfile(Profile profile, BasePagedInput input) { var result = Context.Messages.Where(n => n.PersonId == profile.Id).OrderByDescending(n => n.CreateDate).PagedQueryable(input); return(result); }
public ActionResult Get(BasePagedInput model) { var name = model.Schema; if (name.EndsWith("s")) { name = name.Substring(0, name.Length - 1); } var manager = Activator.CreateInstance(SqlUnitOfWork.DbContext.GetType()) as DbContext; var propertyInfo = SqlUnitOfWork.DbContext.GetType().GetProperty(name + "s"); var modelType = propertyInfo.PropertyType.GenericTypeArguments[0]; var command = _unitOfWork.GetContext().Database.Connection.CreateCommand(); command.CommandText = "select " + model.Schema + ".* from " + model.Schema; if (!string.IsNullOrEmpty(model.Sorting)) { var property = modelType.GetProperty(model.Sorting); if (property != null) { if (property.GetCustomAttributes(true).Any(n => n.GetType() == typeof(ReferenceAttribute))) { var referenceAttribute = property.GetCustomAttributes(true).OfType <ReferenceAttribute>().FirstOrDefault(); if (referenceAttribute != null) { var propertyType = modelType.GetProperty(referenceAttribute.PropertyName).PropertyType; switch (referenceAttribute.Type) { case ReferenceAttribute.ReferenceType.EntityFramework: if (propertyType.GenericTypeArguments.Length > 0) { propertyType = propertyType.GenericTypeArguments[0]; command.CommandText += " LEFT OUTER JOIN " + propertyType.Name + "s ON " + model.Schema + ".Id" + " = " + propertyType.Name + "s." + modelType.Name + "_Id"; } else { command.CommandText += " LEFT OUTER JOIN " + propertyType.Name + "s ON " + model.Schema + "." + model.Sorting + " = " + propertyType.Name + "s.Id"; } model.Sorting = propertyType.Name + "s." + referenceAttribute.SortBy; break; case ReferenceAttribute.ReferenceType.UmbracoDocumentType: break; } } } } command.CommandText = command.CommandText + " Order by " + model.Sorting + " " + model.SortingType; } _unitOfWork.GetContext().Database.Connection.Open(); var reader = command.ExecuteReader(); List <object> list = new List <object>(); var countRecord = 0; while (reader.Read()) { if ( !(countRecord >= (model.PageCurrent) && countRecord < (model.PageCurrent + model.PageSize))) { countRecord++; continue; } countRecord++; Dictionary <string, object> dictionary = new Dictionary <string, object>(); for (int i = 0; i < reader.FieldCount; i++) { var typeProperty = modelType.GetProperty(reader.GetName(i)); if (typeProperty != null) { if (typeProperty.GetCustomAttributes(true).Any(n => n.GetType() == typeof(ReferenceAttribute))) { var referenceAttribute = typeProperty.GetCustomAttributes(true).OfType <ReferenceAttribute>().FirstOrDefault(); if (referenceAttribute != null) { var propertyType = modelType.GetProperty(referenceAttribute.PropertyName); switch (referenceAttribute.Type) { case ReferenceAttribute.ReferenceType.EntityFramework: var reference = propertyType.PropertyType.Name; if (!reference.EndsWith("s")) { reference = propertyType.PropertyType.Name + "s"; } var dbSet = SqlUnitOfWork.DbContext.GetType().GetProperty(reference).GetValue(manager); var sqlQuery = dbSet.GetType().GetMethod("SqlQuery").Invoke(dbSet, new object[] { "select * from " + reference + " where Id='" + reader[i] + "'", new string[] { "" } }) as IEnumerable; var listReference = new List <object>(); if (sqlQuery != null) { foreach (var data in sqlQuery) { listReference.Add(data); } } if (listReference.Count == 1) { dictionary.Add(propertyType.Name, listReference.FirstOrDefault()); } else { dictionary.Add(propertyType.Name, listReference); } break; case ReferenceAttribute.ReferenceType.UmbracoDocumentType: var database = Activator.CreateInstance(SqlUnitOfWork.DbContext.GetType()) as DbContext; if (database != null) { var commandMap = database.Database.Connection.CreateCommand(); var query = new UmbracoQueryAdapter().QueryString("cmsContentXml.xml", "cmsContentXml", "Where nodeid= '" + reader[i] + "'", "", "", ""); commandMap.CommandText = query; database.Database.Connection.Open(); var readerReferenceTypeReader = commandMap.ExecuteReader(); var obj = Activator.CreateInstance(propertyType.PropertyType); var dictionaryTempReference = new Dictionary <string, PropertyInfo>(); foreach (var property in propertyType.PropertyType.GetProperties()) { if (!dictionaryTempReference.ContainsKey(property.Name)) { dictionaryTempReference.Add(property.Name, property); } } while (readerReferenceTypeReader.Read()) { var xElement = XElement.Parse(readerReferenceTypeReader[0].ToString()); foreach (var key in dictionaryTempReference) { if (key.Key.Equals("Id")) { var xAttribute = xElement.Attribute("id"); if (xAttribute != null) { key.Value.SetValue(obj, Convert.ChangeType(xAttribute.Value, key.Value.PropertyType)); } } else { var element = xElement.Element(key.Key[0].ToString().ToLower() + key.Key.Substring(1)); if (element != null) { key.Value.SetValue(obj, Convert.ChangeType(element.Value, key.Value.PropertyType)); } } } dictionary.Add(propertyType.Name, obj); } database.Database.Connection.Close(); } break; } } } } dictionary.Add(reader.GetName(i), reader[i]); } list.Add(dictionary); } reader.Dispose(); _unitOfWork.GetContext().Database.Connection.Close(); return(Json(new BasePagedList <object>() { PageSize = model.PageSize, PageCurrent = model.PageCurrent, TotalRecordCount = countRecord, Result = "OK", Records = list, IsLast = model.PageCurrent == Convert.ToInt16(Math.Ceiling(Convert.ToDouble(countRecord) / Convert.ToDouble(model.PageSize))) }, JsonRequestBehavior.AllowGet)); }
public static BasePagedList <T> PagedQueryable <T>(this IQueryable <T> context, BasePagedInput input) where T : class, IBaseEntity { try { if (input.PageCurrent == 0) { input.PageCurrent = 1; } if (input.PageSize == 0) { input.PageSize = 10; } IEnumerable <T> list = null; if (!(context is IOrderedQueryable <T>)) { list = context.OrderBy(n => n.Id) .Skip(input.PageSize * (input.PageCurrent - 1)) .Take(input.PageSize); } else { list = ((IOrderedQueryable <T>)context) .Skip(input.PageSize * (input.PageCurrent - 1)) .Take(input.PageSize); } var count = context.Count(); return(new BasePagedList <T>() { PageSize = input.PageSize, PageCurrent = input.PageCurrent, Records = list.ToList(), TotalRecordCount = count, IsLast = input.PageCurrent == Convert.ToInt16(Math.Ceiling(Convert.ToDouble(count) / Convert.ToDouble(input.PageSize))) }); } catch (Exception e) { throw; } }