public ActionResult Index(FormCollection forms) { Expression <Func <storage, bool> > exp = ExpressionUtils.True <storage>(); if (!string.IsNullOrEmpty(forms["prod_name"])) { var name = forms["prod_name"]; var prod_id = new LinqHelper().Db.product.Where(pro => pro.prod_name == name).Select(pp => pp.prod_id).FirstOrDefault(); exp = ExpressionUtils.And <storage>(exp, d => d.stk_prod_id == prod_id); } if (!string.IsNullOrEmpty(forms["stk_warehouse"])) { exp = ExpressionUtils.And <storage>(exp, d => d.stk_warehouse.Contains(forms["stk_warehouse"])); } int curPage = int.Parse(forms["curPage"]); storage searchEntity = new storage(); product empProduct = new product(); UpdateModel <product>(empProduct); UpdateModel <storage>(searchEntity); searchEntity.product = empProduct; ViewData["pagerHelper"] = new PageHelper <storage>(new LinqHelper().Db.storage.Where(exp.Compile()).ToList(), curPage, 3); return(View(searchEntity)); }
public ActionResult Index(FormCollection forms) { int curPage = int.Parse(forms["curPage"]); Expression <Func <cst_lost, bool> > expression = null; expression = ExpressionUtils.True <cst_lost>(); if (!string.IsNullOrEmpty(forms["lst_cust_name"])) { expression = ExpressionUtils.And <cst_lost>(expression, l => l.lst_cust_name.Contains(forms["lst_cust_name"])); } if (!string.IsNullOrEmpty(forms["lst_cust_manager_name"])) { expression = ExpressionUtils.And <cst_lost>(expression, l => l.lst_cust_manager_name.Contains(forms["lst_cust_manager_name"])); } if (int.TryParse(forms["lst_status"], out int status)) { expression = ExpressionUtils.And <cst_lost>(expression, l => l.lst_status == status); } var list = new LinqHelper().Db.cst_lost.Where(expression.Compile()).ToList(); cst_lost searchEntity = new cst_lost(); UpdateModel <cst_lost>(searchEntity); ViewData["pagerHelper"] = new PageHelper <cst_lost>(list, curPage, 3); ViewData["cstStatus"] = new SelectList(new bas_dictService().GetDictsByType("客户流失状态"), "dict_value", "dict_item"); return(View(searchEntity)); }
public void AndTestSuccess() { var data = GetValues(); Expression <Func <Helper, bool> > firstCondition = x => x.Value == 5; Expression <Func <Helper, bool> > secondCondition = y => y.Value2 == 0; var and = ExpressionUtils.And(firstCondition, secondCondition); var result = data.AsQueryable().Where(and).ToArray(); Assert.AreEqual(result.Length, 1); Assert.AreEqual(result[0].Value, 5); Assert.AreEqual(result[0].Value2, 0); }
public ActionResult ServiceDispose(FormCollection forms) { Expression <Func <cst_service, bool> > exp = null; int curPage = int.Parse(forms["curPage"]); exp = Search(forms); exp = ExpressionUtils.And <cst_service>(exp, s => s.svr_status == "已分配"); var list = new LinqHelper().Db.cst_service.Where(exp.Compile()).ToList(); cst_service searchEntity = new cst_service(); searchEntity.svr_status = "已分配"; UpdateModel <cst_service>(searchEntity); ViewData["pagerHelper"] = new PageHelper <cst_service>(list, curPage, 3); //服务类型 ViewData["serviceType"] = new SelectList(new bas_dictService().GetDictsByType("服务类型"), "dict_value", "dict_item"); //客服经理 ViewData["userList"] = new SelectList(new sys_userService().GetAllWaiter(), "usr_id", "usr_name"); ViewData["date1"] = forms["date1"]; ViewData["date2"] = forms["date2"]; var l = new LinqHelper().Db.cst_customer.Where(c => true); List <SelectListItem> selectLists = new List <SelectListItem>(); foreach (var item in l) { selectLists.Add(new SelectListItem { Text = item.cust_name, Value = item.cust_name }); } ViewData["cst_name"] = selectLists; return(View(searchEntity)); }
/// <summary> /// 搜索条件拼接 /// </summary> /// <param name="forms"></param> /// <returns></returns> Expression <Func <cst_service, bool> > Search(FormCollection forms) { Expression <Func <cst_service, bool> > exp = null; exp = ExpressionUtils.True <cst_service>(); if (!string.IsNullOrEmpty(forms["svr_cust_name"])) { exp = ExpressionUtils.And <cst_service>(exp, s => s.svr_cust_name.Contains(forms["svr_cust_name"])); } if (!string.IsNullOrEmpty(forms["svr_type"])) { exp = ExpressionUtils.And <cst_service>(exp, s => s.svr_type == (forms["svr_type"])); } if (!string.IsNullOrEmpty(forms["svr_title"])) { exp = ExpressionUtils.And <cst_service>(exp, s => s.svr_title.Contains(forms["svr_title"])); } if (DateTime.TryParse(forms["date1"], out DateTime date1) && DateTime.TryParse(forms["date2"], out DateTime date2)) { exp = ExpressionUtils.And <cst_service>(exp, s => s.svr_create_date >= date1 && s.svr_create_date <= date2); } return(exp); }
public ActionResult Index(FormCollection forms) { Expression <Func <product, bool> > exp = ExpressionUtils.True <product>(); if (!string.IsNullOrEmpty(forms["prod_name"])) { exp = ExpressionUtils.And <product>(exp, d => d.prod_name.Contains(forms["prod_name"])); } if (!string.IsNullOrEmpty(forms["prod_type"])) { exp = ExpressionUtils.And <product>(exp, d => d.prod_type.Contains(forms["prod_type"])); } if (!string.IsNullOrEmpty(forms["prod_batch"])) { exp = ExpressionUtils.And <product>(exp, d => d.prod_batch.Contains(forms["prod_batch"])); } int curPage = int.Parse(forms["curPage"]); product searchEntity = new product(); UpdateModel <product>(searchEntity); ViewData["pagerHelper"] = new PageHelper <product>(new LinqHelper().Db.product.Where(exp.Compile()).ToList(), curPage, 3); return(View(searchEntity)); }
public ActionResult Index(FormCollection forms) { Expression <Func <bas_dict, bool> > exp = ExpressionUtils.True <bas_dict>(); if (!string.IsNullOrEmpty(forms["dict_type"])) { exp = ExpressionUtils.And <bas_dict>(exp, d => d.dict_type == (forms["dict_type"])); } if (!string.IsNullOrEmpty(forms["dict_item"])) { exp = ExpressionUtils.And <bas_dict>(exp, d => d.dict_item == (forms["dict_item"])); } if (!string.IsNullOrEmpty(forms["dict_value"])) { exp = ExpressionUtils.And <bas_dict>(exp, d => d.dict_value == (forms["dict_value"])); } int curPage = int.Parse(forms["curPage"]); bas_dict searchEntity = new bas_dict(); UpdateModel <bas_dict>(searchEntity); ViewData["pagerHelper"] = new PageHelper <bas_dict>(new LinqHelper().Db.bas_dict.Where(exp.Compile()).ToList(), curPage, 3); return(View(searchEntity)); }
public void AndTestParameter2Null() { Expression <Func <Helper, bool> > where = x => x.Value == 5; var lst = ExpressionUtils.And(where, null); }
public ActionResult Index(FormCollection forms) { //拼接条件 Expression <Func <cst_customer, bool> > expression = null; int curPage = int.Parse(forms["curPage"]); var cust_no1 = forms["cust_no"]; var cust_name1 = forms["cust_name"]; var cust_manager_name1 = forms["cust_manager_name"]; var cust_level1 = forms["cust_level"]; var cust_region1 = forms["cust_region"]; //存储搜索条件 Cst_Custom_ViewModel searchEntity = new Cst_Custom_ViewModel { cust_no = cust_no1, cust_name = cust_name1, cust_manager_name = cust_manager_name1, cust_level = cust_level1, cust_region = cust_region1 }; //进行条件拼接 //if (string.IsNullOrEmpty(cust_no1) && string.IsNullOrEmpty(cust_name1) // && string.IsNullOrEmpty(cust_manager_name1) && string.IsNullOrEmpty(cust_level1)) //{ expression = ExpressionUtils.True <cst_customer>(); //} if (!string.IsNullOrEmpty(cust_no1)) { expression = ExpressionUtils.And <cst_customer>(expression, f => f.cust_no.Contains(cust_no1)); } if (!string.IsNullOrEmpty(cust_name1)) { expression = ExpressionUtils.And <cst_customer>(expression, f => f.cust_name.Contains(cust_name1)); } if (!string.IsNullOrEmpty(cust_manager_name1)) { expression = ExpressionUtils.And <cst_customer>(expression, f => f.cust_manager_name.Contains(cust_manager_name1)); } if (!string.IsNullOrEmpty(cust_region1)) { expression = ExpressionUtils.And <cst_customer>(expression, f => f.cust_region == cust_region1); } if (!string.IsNullOrEmpty(cust_level1)) { var r = int.TryParse(cust_level1, out int i) ? i : -1; expression = ExpressionUtils.And <cst_customer>(expression, f => f.cust_level == i); } var compileExp = expression.Compile(); //最后使用拼接条件 ViewData["pagerHelper"] = new PageHelper <cst_customer>(new LinqHelper().Db.cst_customer.Where(compileExp).ToList(), curPage, 3); ViewData["region"] = new SelectList(new bas_dictService().GetDictsByType("地区"), "dict_value", "dict_item"); ViewData["level"] = new SelectList(new bas_dictService().GetDictsByType("客户等级"), "dict_value", "dict_item"); return(View(searchEntity)); }