模糊查询
上面用到的查询叫模糊查询,怎么模糊呢!就是你给的条件的范围内都会一起查询出来,如果要精确,那么就给查询加条件,应该可以到谋一个的数据。
function edfesafed() {
//获取查询条件
var BeHospitalized = $("#BeHospitalized").val();
var startTime = $("#startTime").val();
var finishTime = $("#finishTime").val();
var Costategorys = $("#Costategorys").val();
var EmployeeName = $("#UEmployeeName").val();
var PrintState = $("#PrintState").val();
var ClinicalCenterName = $("#ClinicalCenterName").val();
判断获取到的值如果等于空””或者undefined,就会赋值等于0
if (Costategorys == “” || Costategorys == undefined) {
Costategorys = 0;
}
if (EmployeeName == “” || EmployeeName == undefined) {
EmployeeName = 0;
}
if (PrintState == “” || PrintState == undefined) {
PrintState = 0;
}
if (ClinicalCenterName == “” || ClinicalCenterName == undefined) {
ClinicalCenterName = 0;
}
//表格数据重载
这个是layui表格方法渲染,也可以用layui表格自动渲染,俩者都差不多
tabPatientSurface.reload({
url: ‘selectBeHospdg’,
where: {
BeHospitalized: BeHospitalized,startTime: startTime,finishTime: finishTime,
Costategorys: Costategorys,EmployeeName: EmployeeName,PrintState: PrintState,
ClinicalCenterName: ClinicalCenterName
}
})
}
然后传到控制器进行查询:
public ActionResult selectBeHospdg(string BeHospitalized, string startTime,string finishTime,int Costategorys,int EmployeeName,int PrintState,int ClinicalCenterName, LayuiTablePage layuiTablePage)
{
List listDoctorAdvicDetail = (from tbDoctorAdvicDetail in myModel.PW_DoctorAdvicDetail
join tbDoctorAdvice in myModel.PW_DoctorAdvice on tbDoctorAdvicDetail.DoctorAdviceID equals tbDoctorAdvice.DoctorAdviceID
join tbAdmissionForm in myModel.PW_AdmissionForm on tbDoctorAdvice.AdmissionFormID equals tbAdmissionForm.AdmissionFormID
join tbPatientSurface in myModel.PW_PatientSurface on tbAdmissionForm.PatientSurfaceID equals tbPatientSurface.PatientSurfaceID
join tbBedNumber in myModel.PW_BedNumber on tbAdmissionForm.BedNumberID equals tbBedNumber.BedNumberID
join tbEmployee in myModel.PW_Employee on tbAdmissionForm.EmployeeID equals tbEmployee.EmployeeID
join tbClinicalCenter in myModel.PW_ClinicalCenter on tbAdmissionForm.ClinicalCenterID equals tbClinicalCenter.ClinicalCenterID
join tbDrug in myModel.PW_Drug on tbDoctorAdvicDetail.DrugID equals tbDrug.DrugID
join tbDrugCost in myModel.PW_DrugCost on tbDrug.DrugCostID equals tbDrugCost.DrugCostID
join tbReturnPremiumState in myModel.PW_ReturnPremiumState on tbDoctorAdvicDetail.ReturnPremiumStateID equals tbReturnPremiumState.ReturnPremiumStateID
join tbCostategorys in myModel.PW_Costategorys on tbDoctorAdvicDetail.CostategorysID equals tbCostategorys.CostategorysID
join tbPrintState in myModel.PW_PrintState on tbDoctorAdvice.PrintStateID equals tbPrintState.PrintStateID
where tbDoctorAdvice.Arrearagefalse
select new studentVo
{
CostategorysID = tbCostategorys.CostategorysID,
DoctorAdvicDetailID = tbDoctorAdvicDetail.DoctorAdvicDetailID,
Contents = tbDoctorAdvicDetail.Contents,
EnjoinTim = tbDoctorAdvice.EnjoinTim,
DrugName = tbDrug.DrugName,
Specification3 = tbDrug.Specification3,
Comment1 = tbDrug.Comment1,
Unit = tbDrugCost.Unit,
UnitPrice = tbDrugCost.UnitPrice,
Quantity = tbDrugCost.Quantity,
EmployeeName = tbEmployee.EmployeeName,
ClinicalCenterName = tbClinicalCenter.ClinicalCenterName,
ReturnPremiumState = tbReturnPremiumState.ReturnPremiumState,
ReturnPremiumStateID = tbReturnPremiumState.ReturnPremiumStateID,
BeHospitalized=tbAdmissionForm.BeHospitalized,
PatientName=tbPatientSurface.PatientName,
BedNumber=tbBedNumber.BedNumber,
Coding4=tbDrug.Coding4,
PrintStateID=tbPrintState.PrintStateID,
PrintState =tbPrintState.PrintState,
Costategorys=tbCostategorys.Costategorys,
EmployeeID=tbEmployee.EmployeeID,
ClinicalCenterID=tbClinicalCenter.ClinicalCenterID
}).ToList();
这里条件筛选 Lambda表达式 运算符=>,左边是参数,右边是表达式或者语句
if (!string.IsNullOrEmpty(startTime) && !string.IsNullOrEmpty(finishTime))
{
listDoctorAdvicDetail = listDoctorAdvicDetail.Where(a => a.EnjoinTim >= Convert.ToDateTime(startTime) && a.EnjoinTim <= Convert.ToDateTime(finishTime)).ToList();
}
if (Costategorys>0)
{
listDoctorAdvicDetail = listDoctorAdvicDetail.Where(a => a.CostategorysIDCostategorys).ToList();
}
if (!string.IsNullOrEmpty(BeHospitalized))
{
listDoctorAdvicDetail = listDoctorAdvicDetail.Where(a => a.BeHospitalized.Contains(BeHospitalized) || a.BeHospitalized.Contains(BeHospitalized)).ToList();
}
if (EmployeeName>0)
{
listDoctorAdvicDetail = listDoctorAdvicDetail.Where(a => a.EmployeeIDEmployeeName).ToList();
}
if (PrintState>0)
{
listDoctorAdvicDetail = listDoctorAdvicDetail.Where(a => a.PrintStateIDPrintState).ToList();
}
if (ClinicalCenterName>0)
{
listDoctorAdvicDetail = listDoctorAdvicDetail.Where(a => a.ClinicalCenterID == ClinicalCenterName).ToList();
}
int totalRow = listDoctorAdvicDetail.Count();
List dbDoctorAdvicDetail= listDoctorAdvicDetail
.Skip(layuiTablePage.GetStartIndex())
.Take(layuiTablePage.limit)
.ToList();
LayuiTableData layuiTableData = new LayuiTableData();
layuiTableData.count = totalRow;
layuiTableData.data = dbDoctorAdvicDetail;
return Json(layuiTableData, JsonRequestBehavior.AllowGet);
}
其实模糊查询和多条件查询是差不多的,差别在哪呢,自己去找,哈哈